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 vince.tavernier@gmail.com
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.6.3.tar.gz
(26.9 kB
view hashes)
Built Distributions
Close
Hashes for glslt-0.6.3-cp310-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b8ee7cd54f776f939563906123510e4ddbca0f7b38f8c0850c06e3c703af3939 |
|
MD5 | a6130f56292356b384d6f0e872ff1b92 |
|
BLAKE2b-256 | 3ff0cc9606a6ed220c8ac801553c169971bb3ce25f3b7654258aa1e2525aa6b5 |
Close
Hashes for glslt-0.6.3-cp310-cp310-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 99bb99fc8a22c211f0872f50b0a77173155a996544d10a5ed3bb69a356e358f8 |
|
MD5 | c88e51276fc5abe49024c06657c6c121 |
|
BLAKE2b-256 | 37dc2b91ee9821c9a28a45f49511efcc320cdc79799fed1eeea0e05cfd86ee07 |
Close
Hashes for glslt-0.6.3-cp39-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1182f36f98a73ba05836482aa379e87792edf3d8baef2951ef34f16a988a5c3d |
|
MD5 | dd691dbe7e7d2884e55c6f9166c4e2b4 |
|
BLAKE2b-256 | 139f4ef97f6eac952ddfc046faf7ca12f1835bedf19f532a8a123b8366aa778f |
Close
Hashes for glslt-0.6.3-cp39-cp39-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9b33297647f3567fed1e82bbe10f35c5dae1d353fa322f7500b0512e15cfdee8 |
|
MD5 | 859beb29f8b7bd4a929b4ebc396493f8 |
|
BLAKE2b-256 | 5fb1baa3ce1eb4be22ebb1c7af7c184f7506615a25790ba307dde14155960603 |
Close
Hashes for glslt-0.6.3-cp38-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a3f4d2d62f15d69509c1c6b4791bbda0d36b21f5ba5cc3b38d48643848272c04 |
|
MD5 | d9e11a5a80f00ee82b66e88d80494d3a |
|
BLAKE2b-256 | 54b3905860b3b73711cf44c3d9578c54622c508f5427dcefd3509a444e18557a |
Close
Hashes for glslt-0.6.3-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d0708c76ea787de28cd6596f26591663c2979406e09aa381d14c3239b7637e29 |
|
MD5 | c2c294cdf03ffca50fafa6bf9f5643df |
|
BLAKE2b-256 | 1abbd6715e2b703bc65cfddd958dbc83d884012aecb11251f286f584c6d7f927 |
Close
Hashes for glslt-0.6.3-cp37-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 412b4055e8b605bd3a67a2991c8ed8f9645e23c18d07cbfc69bf6826a40f8059 |
|
MD5 | 8cb4388536662eab57c649c1c80b5b1c |
|
BLAKE2b-256 | 6592ae82324715c82d864698dc7c10804af8ba40b14e2842eae20673dfabc35c |
Close
Hashes for glslt-0.6.3-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b4385aa6e601f05eda01577eaa5828acf30b50014d1c6514f0052529965a1779 |
|
MD5 | 6c85074a0d427f25d1cc0699c645fce9 |
|
BLAKE2b-256 | 1e5cdd170779d21a28c7b3ef15eb0b0c1c68e7dabf85c7556095ad1bce485768 |
Close
Hashes for glslt-0.6.3-cp36-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 60391fd81f551e890569548af1d01477fe0f9225c1d353db5bbe515262aad501 |
|
MD5 | 5e0d3573e0f30daa95602262c3a6dd0e |
|
BLAKE2b-256 | 2be73d27b5746a63710da44c5019c34575b09bd24e8e2d13bfd4b47d83fe5dc6 |
Close
Hashes for glslt-0.6.3-cp36-cp36m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3d90a2079d5957af4757c929831a3ceb6166cb7d1897521a92f855299740d7cb |
|
MD5 | 1daa5a99d1b391a11b275200a62fe3c0 |
|
BLAKE2b-256 | 4f827ad8ab2135bcac2539cb36741c2b604dbfe64eb681ebd8e52f6f0af5eed5 |