#glsl #proc-macro #opengl #spir-v #parser

nightly glsl-quasiquote

glsl!过程宏,提供glslcrate的伪引用

15个版本 (8个稳定版)

7.0.0 2023年12月22日
6.0.1 2023年12月19日
6.0.0 2020年12月7日
5.0.0 2020年7月27日
0.3.0 2018年11月21日

#5 in #open-gl

BSD-3-Clause

350KB
10K SLoC

Build Status crates.io docs.rs License

GLSL伪引用。

此crate导出一个过程宏:glsl!。它通过允许你直接使用语法将GLSL源代码嵌入Rust中来实现伪引用

#![feature(proc_macro_hygiene)]

use glsl::syntax::TranslationUnit;
use glsl_quasiquote::glsl;

let tu: TranslationUnit = glsl!{
  // your GLSL code here
  void main() {
  }
};

glsl!宏直接接受GLSL代码。然后你可以编写纯GLSL。特别地,从版本0.2开始,该宏接受纯GLSLpragma(包括#version#extension)。

glsl!过程宏在编译时解析为TranslationUnit,允许你直接操作GLSLAST。有关更多信息,请查看glslcrate。

入门

将以下内容添加到你的Cargo.toml依赖中

glsl = "1"
glsl-quasiquote = "1"

然后,你目前需要一个nightly编译器并启用以下功能

#![feature(proc_macro_hygiene)]

然后,根据你是否使用2018版

非2018版

extern crate glsl;
#[macro_use] extern crate glsl_quasiquote;

2018版

use glsl_quasiquote::glsl;

特殊警告和注意事项

由于Rust词法分析器的性质,标记开始处的点(.)不属于标记。例如,.3被重新解释为.3(两个标记)。如果你尝试用.3表示数字0.3,这将导致解析错误。虽然glsl接受它,但此crate不接受。这种限制是由于过程宏中Rust如何解析输入造成的,并且不太可能改变。

依赖项

~1MB
~21K SLoC