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
Vincent Tavernier v.tavernier@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.2.tar.gz
(26.9 kB
view hashes)
Built Distributions
Close
Hashes for glslt-0.7.2-cp310-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e715c18d736f3e6a5e8764b7d42d71899762657e8aca1189dc0b76496305fb2 |
|
MD5 | 9ef8b67b66a85aab245800d83c2bd725 |
|
BLAKE2b-256 | 5e1c4b272aab962e5f9f4678113c013366b302811aba7d3874a0d0cec7935f84 |
Close
Hashes for glslt-0.7.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f309bf95aeb6aa7e0b4dfb0912d78ed495e5bddf5b795b2232f9beb22b647c4 |
|
MD5 | f889708a48088966aa3a0d8d9cdbb2b3 |
|
BLAKE2b-256 | 1b88986a4cdd252bed0a4382d66ec11538b5bc6486cccd5c62e09c9926c4aa7a |
Close
Hashes for glslt-0.7.2-cp39-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d9ef44d27552eb4cf1fefa7d67f099eb3f5620c31f456df11391b4a05c9b603 |
|
MD5 | 14f89454a659d2533f851b31a74c2bfd |
|
BLAKE2b-256 | 89ad750b8cd1c1af5a3e16293ebc375fe227741321925b76b55a09a61bd58811 |
Close
Hashes for glslt-0.7.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c9b65672a6e6c952fdae1cb907fda825b93a8a49258f098724355384bff53633 |
|
MD5 | 2e870e029fc8c7301c63a3d683661e18 |
|
BLAKE2b-256 | 4c1b32adaa1cb4ef796977c67bd5a676824e2082bbc629175ed7473a1e16867e |
Close
Hashes for glslt-0.7.2-cp38-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 49cf7f54436019b536f3bb483748d440659f5236630c4bc499c56fe95d268b57 |
|
MD5 | 6149ac5e58ff8cf7fa782996215d9816 |
|
BLAKE2b-256 | d548df5abb391004246982c3169f707493b0249a0185f665c257fb8e8c211258 |
Close
Hashes for glslt-0.7.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f55f43c27d174ff895f09bf887a27c61e2aa30461ff170fca66f5a31ee41c07d |
|
MD5 | e5f5b8fb2ed8bb5fb85b3633420df269 |
|
BLAKE2b-256 | 97049e50b814d173d5423d383cb5a4262b3b2c252823415e90328c37a83412b7 |
Close
Hashes for glslt-0.7.2-cp37-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8039c5fc37a037191f3dfc7c63e4f066e1f633b5c48d8089fd15ebd87066972b |
|
MD5 | 2b8f613292f3c5563dd1b106f25dbee8 |
|
BLAKE2b-256 | 57ff918f95974d2c078bd2f4dbfccde011276129212bf10f00bd0bab3198a754 |
Close
Hashes for glslt-0.7.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8005e64169f1622f8144842d26fdc6fd03637aaeb5422c9b76fb4c9ea45591e6 |
|
MD5 | 99e4703e909c4d8517450184bc389b5b |
|
BLAKE2b-256 | 0b41bcef04672845d449ad44dc4a88a519fddeb7a6e5ed3bc486f2d4c929b959 |