GLSLT Template compiler library
Project description
glslt
glslt is the main library that supports the GLSL Template compiler transforms. If you are
building a system that relies on transforming GLSLT code, you'll want to interact with this
library directly instead of the command-line interface provided by glsltc
.
Usage
Rust crate
The glslt crate manipulates syntax trees generated by the glsl-lang crate.
use glslt::glsl_lang::{ast::*, parse::IntoParseBuilderExt};
use glslt::transform::{Unit, TransformUnit};
let glsl_src = r#"
float sdf3d(in vec3 p);
float colort();
float sdSphere(vec3 p, float r) {
return length(p) - r;
}
float opElongate(in sdf3d primitive, in colort C, in vec3 p, in colort D, in vec3 h) {
vec3 q = p - clamp(p, -h, h);
return C() * primitive(q) * D();
}
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
float sz = 5.;
fragColor = vec4(vec3(opElongate(sdSphere(_p, sz), 1.0, vec3(fragCoord, 0.), 2.0, vec3(1., 2., 3.))), 1.0);
}
"#;
// Parse the GLSLT source code
let tu: TranslationUnit = glsl_src
.builder()
.context(&glslt::parse::make_parse_context(None))
.parse()
.expect("failed to parse GLSLT source")
.0;
// Create the transform unit
let mut unit = Unit::new();
// Parse declarations
for decl in tu.0.into_iter() {
unit.parse_external_declaration(decl).expect("failed to parse declaration");
}
// Generate the result
let tu = unit.into_translation_unit().expect("failed to generate output");
// Transpile the syntax tree to GLSL source
let mut output_src = String::new();
glsl_lang::transpiler::glsl::show_translation_unit(
&mut output_src,
&tu,
glsl_lang::transpiler::glsl::FormattingState::default(),
).expect("failed to generate GLSL");
Python library
If you installed the glslt library via pip install glslt
or maturin develop
, you may use the Python interface to the GLSLT compiler.
import glslt
# Parse the `sdf.glsl` file with `my-glsl-lib/include` being a system include
# directory for #include resolution
translation_unit = glslt.parse_files(["sdf.glsl"], ["my-glsl-lib/include"])
# Create a new minimizing transform unit
unit = glslt.MinUnit()
# Add the parsed declarations to the transform unit
unit.add_unit(translation_unit)
# Get the output of the transform
result = unit.to_translation_unit(["mainImage"])
# Print the GLSL code
print(result.to_glsl())
Author
Alixinne alixinne@pm.me
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
glslt-0.7.4.tar.gz
(26.4 kB
view hashes)
Built Distributions
Close
Hashes for glslt-0.7.4-cp310-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cbdba8abcbd148f9e1a05629119926a9995d4d3b25bab4f76f09cf2fabc43c8d |
|
MD5 | ace7020bf479fb4cea21de33d79bc5f6 |
|
BLAKE2b-256 | 9c46931e3d57b332c90d2d54bb473e9c504f27c0748fb9f3da3fdb951bb474bd |
Close
Hashes for glslt-0.7.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 657698db3452a99df125ce7c582684327bdd6fa196119f166df6580aa6f6cbcc |
|
MD5 | ab7650310aebf20624e00beaf76fae6a |
|
BLAKE2b-256 | 542405657e9284b2848a1658b7d05e4c4d3fc288cb6d2ca29b7de71af62882df |
Close
Hashes for glslt-0.7.4-cp39-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | edf44112dccc93a7474691d7322e899dd055391b00b0adfdbc13207ed83ea33c |
|
MD5 | 59f6e51761a9e2897c23879aa308e7ad |
|
BLAKE2b-256 | fa645f35f0a47e6b6a008daaa554e4693b9f68acd4df3760bce79b0647c6c5a3 |
Close
Hashes for glslt-0.7.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 931c74473989099c1b8b9cf5366568f737e416ca0fe3207748c2dd901de9aa25 |
|
MD5 | 0243f99a0248ff3149bcd2e69aa609ad |
|
BLAKE2b-256 | cf814b17a599ff17e63d2db5705cc4ff7e5d3a7ab19e9cb5a2b177e830b6db10 |
Close
Hashes for glslt-0.7.4-cp38-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f0dcc354ed34f4405a9fbeeca1e5486f0646635ac799a819e99b5697a45ca75 |
|
MD5 | 198302a1edef6323be2389f21b8424fb |
|
BLAKE2b-256 | 053616cf6312aea024bfc2172ccf0cf5ecffeddf1af4a3cdc2c8eaba8f1cc0af |
Close
Hashes for glslt-0.7.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 181d4fd875e424328bf031d5680186476c30f407ec2b7231224017d0010ed26d |
|
MD5 | 27a544cfe671a0f89e954d27f62f24bb |
|
BLAKE2b-256 | f8a43054601424b8d548ef8d6808a1db51364dca3d845f7a1c3505688c656d9e |
Close
Hashes for glslt-0.7.4-cp37-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2286b2493b7cd588cd0fe75b0941f0535d5ab99891f575e1421f1c92d28d883f |
|
MD5 | 16307747bfe6ea43084e83b3ccb01a4f |
|
BLAKE2b-256 | 4fda9d43a7eed1c026e6319b99f8f338f5bdfa4cefef4a17239af04a0e73a858 |
Close
Hashes for glslt-0.7.4-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 794081ca76bbc2221292871ee48fc56562a884dbffdc342d42ca4711972178bd |
|
MD5 | 60d48767a99ed01aee083bfd78adb37a |
|
BLAKE2b-256 | eb0b20907689f881d17160ef925b254e74bbd61c69e524f59233464b77975f2e |