No project description provided
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 glsltcc
.
Usage
Rust crate
The glslt crate manipulates syntax trees generated by the glsl crate (note that the fork currently used is https://github.com/vtavernier/glsl/tree/dev/).
use glslt::glsl::parser::Parse;
use glslt::glsl::syntax::*;
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 GLSL source code
let tu = TranslationUnit::parse(glsl_src).expect("failed to parse GLSLT source");
// Create the transform unit
let mut unit = Unit::new();
// Parse declarations
for decl in (tu.0).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::transpiler::glsl::show_translation_unit(
&mut output_src,
&tu,
glsl::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.4.3.tar.gz
(25.5 kB
view hashes)
Built Distributions
Close
Hashes for glslt-0.4.3-cp39-cp39-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a220fd4c00cec658a3f3c8c1a50611ee61d6d9f93397300ba294bfb3ee0b525f |
|
MD5 | f09a8c3bbef12ede3d39e262a5bdcade |
|
BLAKE2b-256 | 9eb146a9061166592e5b448d7d4f3e0627038f0694fbbba0e9f19e15f6af504a |
Close
Hashes for glslt-0.4.3-cp38-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1dbf1956c190ac0f8c6aea3657b35270c1aaecd2fcd14f797db69bedee00093b |
|
MD5 | 82da5eeff2bebcadc1e5f5ba3dc7a0fa |
|
BLAKE2b-256 | abe3d5fde9a6eafaa62cfd8b3b075ed58585eb03fc0df8d26ca0e638bc57d278 |
Close
Hashes for glslt-0.4.3-cp38-cp38-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 92316d83140267395bea70c790bf3df0b55d06129219868d166e9b956cb3218f |
|
MD5 | f5c64e6223ffeb3c918e092f4d5ec0c7 |
|
BLAKE2b-256 | 5775c0fc1204f7773b0e644e8985937eacf9b37b444ad3fff58c8055d3a7347b |
Close
Hashes for glslt-0.4.3-cp37-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 375b79de8d4c8b11db2885e4fccd71d28915fbcc7cd06fcec7fa5bf6a7070df3 |
|
MD5 | 1c890dba6ee0ff514754cc47a1f8a899 |
|
BLAKE2b-256 | 55ae1c5c11a1a8e9b6809e5161c0622633fe88cbaa2dcbca5356dbb7028eb23c |
Close
Hashes for glslt-0.4.3-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dc85883337217a010de5897e6dc28b3ec2f451f1160c733b07f5d21847190368 |
|
MD5 | ecc248b776ebe0e99f87de20e0bb512c |
|
BLAKE2b-256 | 0c07fcf76c1555ac51e273f7fe34bea9ab6d3d3edb8aa20ae141d8802bb9065b |
Close
Hashes for glslt-0.4.3-cp36-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f162a15ceb53e84305d8d50a953c7fbd666598ee954363c9cadc1ded62fa2950 |
|
MD5 | 68b91f8d4893815388973e301ff7ca9e |
|
BLAKE2b-256 | 8cffecd662ff7200bbb97d088d2e9fee88dd51d07b20fe6ccf06d80d53433417 |
Close
Hashes for glslt-0.4.3-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b87f974d840ca26a01fa97c5ca39dd364a0313e3e6505a04b88c6e04d4ac63e0 |
|
MD5 | 5bebb8d490a2af2c231e2a2d51dfd009 |
|
BLAKE2b-256 | 1cd95f635449bd0a7c26d8a852c01d61a35df64d9a3b41f69ada165ea345d22a |
Close
Hashes for glslt-0.4.3-cp35-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 514178b345c9f724d56b99ce77d11d88bc807e14275e6e9c937546a7821fe50a |
|
MD5 | be13d85aec4e53d731459408fb940bca |
|
BLAKE2b-256 | defda3a430e05a90fe2b2a2d64e90839eb951cfb4719254480d2f05171185a33 |
Close
Hashes for glslt-0.4.3-cp35-cp35m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 41a8a0f273fc0b39223d14efdda2cae3df6d0469de481a355068ba164bd18caf |
|
MD5 | 3ed45cce9d99f83b1e9b790a93863825 |
|
BLAKE2b-256 | 8b27f97909598eecf36ba556e538e705197046d9c1ae48ab9262b4905d271e0a |