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.0.tar.gz
(15.9 kB
view hashes)
Built Distributions
glslt-0.4.0-cp38-none-win_amd64.whl
(473.0 kB
view hashes)
glslt-0.4.0-cp38-none-win32.whl
(437.3 kB
view hashes)
glslt-0.4.0-cp37-none-win_amd64.whl
(472.9 kB
view hashes)
glslt-0.4.0-cp37-none-win32.whl
(437.3 kB
view hashes)
glslt-0.4.0-cp35-none-win_amd64.whl
(473.0 kB
view hashes)
glslt-0.4.0-cp35-none-win32.whl
(437.4 kB
view hashes)
Close
Hashes for glslt-0.4.0-cp39-cp39-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 81b723b63e1fd85eb86cb40ccf029440487669672e9343e8fa9126fe5a734d56 |
|
MD5 | 7d1aa556e07e2c1615731a4814913f1e |
|
BLAKE2b-256 | edaf97f9fa90fad58f354bc6b26763f081ae4a22657a20ed4bd1459840abfbad |
Close
Hashes for glslt-0.4.0-cp39-cp39-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a610651c15ea7614ef3ec1d1809f4a2c332dab940098d9a920fc51b12c4d072a |
|
MD5 | 6ee5bd0abeabc69373a536e189200923 |
|
BLAKE2b-256 | 00e9fe1323719014d80f850684bf69168edaa9a39225d066b0ba5f1ebf65792b |
Close
Hashes for glslt-0.4.0-cp38-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0117a88ad73e9ad130d4bab0acbf76e9cde528254a2170f3eead9ca2a8d29af9 |
|
MD5 | e233f56f509df784c46eea43cd1e9120 |
|
BLAKE2b-256 | 7cb469a7eb3d61ca0b8e16155a2f82388ae750c1d42f8cd7e6b42993c5d466ab |
Close
Hashes for glslt-0.4.0-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 22f89341a7a8eca1e1d88305b305f79f730ec30da9e9128c0da91d0ee37c607a |
|
MD5 | 862bad35b35602ca4895ec3baff35857 |
|
BLAKE2b-256 | de79a391c34e177b7cffb43624582164b59de646cbf958099d791c3e868f5f3a |
Close
Hashes for glslt-0.4.0-cp38-cp38-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b4ad9018e464147b41da155f35865a221bc93c4cdf86bd18d1367ca298e4ad05 |
|
MD5 | 4e8000049e2f20f89de601e6bef57b59 |
|
BLAKE2b-256 | f4564c294fd4626f9b016596975a405743e1f668d806679256f4477ff7b1b9e7 |
Close
Hashes for glslt-0.4.0-cp37-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d540a491cedc7a82f85c07faf899116af9eb570f278a94e2905c252fa6f87200 |
|
MD5 | da8798b71c8890bce8b667a0fc05812c |
|
BLAKE2b-256 | 1c2f75f66113a7af4e762b922314f29a8ef90e8a5bb03c0ea3300fa1fe5737d5 |
Close
Hashes for glslt-0.4.0-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 38ce3a7cf6bcd1468cab1cf85be65420e4e0043d1a58211fec6dfba34e853b08 |
|
MD5 | fb2b47b1fb7e13df31247e70aa9f1bdd |
|
BLAKE2b-256 | 8f408dd926848b0661c5a0abf28b8beccaadd90a85f9bc3e96ff8b0f689e9e36 |
Close
Hashes for glslt-0.4.0-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0cd6b16a2f0d850b99ab9fdfc5bf8ac74878b61116aed9e42fe7557ea4c2857c |
|
MD5 | e8bd940f04d110dba7da069c27e970e1 |
|
BLAKE2b-256 | ea58d77f933aa1888451760314ccf61da5d6ee378a5eb49a5ef96b36d9a7de38 |
Close
Hashes for glslt-0.4.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 758691b19ae382ecccc9589276153a7de37319aae5c55d89c4854331b5f3e6dc |
|
MD5 | 94f1b1e321a650abfbab307b953366b9 |
|
BLAKE2b-256 | 1d486931b8cb4b103274beca41977a0b6e7ab82e229f4214cd3675d35dbedf82 |
Close
Hashes for glslt-0.4.0-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 25f35c2a21d5cad1f9508096f875f4e13e9081b647204763fadd11af93de385a |
|
MD5 | 500a105323add50f1696c49144fe5a35 |
|
BLAKE2b-256 | 17ba9729f392816c26a7be7f3ba3d899ccf3d27eda56d634d933b2152649f725 |
Close
Hashes for glslt-0.4.0-cp35-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 12cc8e418528667db016c64f8f562ea63daa705d13fe6c09ebc5bb2fdbf89fb7 |
|
MD5 | c7d7e8acbbeacf1234645b17a90f4a30 |
|
BLAKE2b-256 | 58058344130e73e43439ec484e1088cec2a68e321cc8929b835fe78bd680004e |
Close
Hashes for glslt-0.4.0-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e9e8af87ad183fa45fc9c29c9aafaad49a3a3ec11e47ec1d3457ef4f893895a2 |
|
MD5 | cc052cdb4a8afad34ff5dfbe1956ae8b |
|
BLAKE2b-256 | 30bbd5e0b6f0b0d1a54e378a283502b658deecb567a183a84d96fabc4e15dba2 |
Close
Hashes for glslt-0.4.0-cp35-cp35m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c5aceda232b5f0d910b6fc638017abf7e649ef5d43b81ceedef3c811f1f098b4 |
|
MD5 | efbeafd8dc4575400397af387a35e609 |
|
BLAKE2b-256 | 8685fbe84cfa8048c5b4287f4ec2fc53950c4c6186dad8bc0317930acd1adf78 |