7个版本

0.3.0-pre.32022年10月19日
0.3.0-pre.22022年9月30日
0.3.0-pre.12022年1月19日
0.2.0 2018年12月11日
0.1.2 2018年12月2日

图形API 中排名第 168

Download history 2999/week @ 2024-03-17 3075/week @ 2024-03-24 1687/week @ 2024-03-31 1834/week @ 2024-04-07 2766/week @ 2024-04-14 1844/week @ 2024-04-21 1413/week @ 2024-04-28 1079/week @ 2024-05-05 7/week @ 2024-05-12 1293/week @ 2024-05-19 1471/week @ 2024-05-26 1686/week @ 2024-06-02 3873/week @ 2024-06-09 2419/week @ 2024-06-16 1267/week @ 2024-06-23 413/week @ 2024-06-30

每月下载量 7,994

MIT 协议

37KB
725

🥽 shader-prepper

Crates.io Docs

shader-prepper 是一个着色器包含解析器和爬虫器。它主要针对GLSL,因为GLSL本身不提供内置的包含指令支持。

此crate不实现完整的C样式的预处理器,只实现 #include 扫描。其他指令则直接复制到展开的代码中,以便后续由着色器编译器处理。

API支持用户驱动的包含文件提供者,这允许自定义虚拟文件系统、包含路径,并允许构建系统跟踪依赖关系。

源文件不是合并在一起,而是作为SourceChunk的Vec返回。如果需要一个单独的字符串,可以使用源字符串的join。否则,可以将单个块传递给图形API,然后SourceChunk中的源信息可以重新映射编译器的错误回原始代码。

示例

struct FileIncludeProvider;
impl shader_prepper::IncludeProvider for FileIncludeProvider {
    type IncludeContext = ();

    fn get_include(
        &mut self,
        path: &str,
        _context: &Self::IncludeContext,
    ) -> Result<(String, Self::IncludeContext), crate::BoxedIncludeProviderError> {
        Ok((std::fs::read_to_string(path)?, ()))
    }
}

// ...

let chunks = shader_prepper::process_file("myfile.glsl", &mut FileIncludeProvider, ());

许可证:MIT

依赖关系

~0.3–1.3MB
~27K SLoC