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.2.tar.gz
(16.5 kB
view hashes)
Built Distributions
glslt-0.4.2-cp38-none-win_amd64.whl
(687.4 kB
view hashes)
glslt-0.4.2-cp38-none-win32.whl
(630.3 kB
view hashes)
glslt-0.4.2-cp37-none-win_amd64.whl
(687.5 kB
view hashes)
glslt-0.4.2-cp37-none-win32.whl
(630.3 kB
view hashes)
glslt-0.4.2-cp35-none-win_amd64.whl
(687.5 kB
view hashes)
glslt-0.4.2-cp35-none-win32.whl
(630.4 kB
view hashes)
Close
Hashes for glslt-0.4.2-cp39-cp39-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6d7e622bea3d74198b2dba5fc2e18535cf20a3f51416c46c564d6abf342d0ea9 |
|
MD5 | d21a2ce3ea55278f8aab70bd6ff90563 |
|
BLAKE2b-256 | 36edecc12252d60190359167ce4d0493110eb20695d5cb38d09393e7ebd7b9ab |
Close
Hashes for glslt-0.4.2-cp39-cp39-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 79f93e1663c668daf0e6f8d5ffe06917b5e3e6097351484a4b34ac027a378ad1 |
|
MD5 | 557aef9a2b1e2609c710a8b5209b8809 |
|
BLAKE2b-256 | f98495c5acd9949052cc5593aa46f96594e3768c8aa94d2d260d8e8ca1f618d5 |
Close
Hashes for glslt-0.4.2-cp38-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 87aa30a9a5e4971871b655b767d3ad8292d06713843689821fbae6c3db0974a0 |
|
MD5 | 7d747d44f86f7c96440ec25e9bc251ec |
|
BLAKE2b-256 | d346a12f87ad0f0a06a8d0fe9395ccdb8f4a351c386619f0c8a88165717265b4 |
Close
Hashes for glslt-0.4.2-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 68a13255537ae450b6403c86824b95bcb03508eaf01ba58e382daca53f4d671d |
|
MD5 | b208d60362460a1c88b16b1ecb2d2719 |
|
BLAKE2b-256 | 25630ca4fa32401c07b5be3c90b166063f6732179f3e3d5491b4f3677dbc4009 |
Close
Hashes for glslt-0.4.2-cp38-cp38-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b7d97db418b9449aa9ee36c9294df9cc372d4d8f1fa5ad90a70efb5e7b58e676 |
|
MD5 | 2fd9fad9555339babdfa040511a70f4c |
|
BLAKE2b-256 | 76031d3a5e912a80838f608d887dda892da90367e43584f262ed77e86d829d68 |
Close
Hashes for glslt-0.4.2-cp37-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 766b4631603a2bdc48228548424602b60860aa82c79bed2cc603824c3cfa49e2 |
|
MD5 | 54e7fa7d16ca5f35d13d25bd1d2b98ee |
|
BLAKE2b-256 | c4fc4ce6818004650ced25960ddffc251566dcf7eca40e0e0edc7cae1cb6486e |
Close
Hashes for glslt-0.4.2-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a641cfab515bfb149631cfa6fcd422dabbf8964384dc1147122cb6f374871c53 |
|
MD5 | aea15f2c5d631a67b9f2424c619ba12a |
|
BLAKE2b-256 | 5f3c9d921d850082c2399303a77d7c7e204aba0c30d8fde6017f6f16531f9e3a |
Close
Hashes for glslt-0.4.2-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9945a8d68b3ee95fdaec8077c685393e24c6cf0d0e8347a63c7df6f9fc300ac2 |
|
MD5 | 9b71fcf4d0023af19075ff52dc66dd62 |
|
BLAKE2b-256 | 462f4bf2a70e5b54df0568b1cd6d767a298e2d040804d5512daeed53d15e1cc4 |
Close
Hashes for glslt-0.4.2-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3d656d198030b252f2d2ef9c8eaa2652dfa8932025868b041779bf104c81f183 |
|
MD5 | 0824087516911666c7cad7f6ea89341b |
|
BLAKE2b-256 | 7d946ef0fb7b73d8415bf80b9fa40dfaaa73f2e9e7f73421381aaf3f6fa7da0e |
Close
Hashes for glslt-0.4.2-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 368790672cb3ecbd73ca3d55d928879355d1c92f402fbbf209a3301ce5fe38de |
|
MD5 | c25c28fddc2483630f3c908831c2fa97 |
|
BLAKE2b-256 | 41ba2a3c4ce90d87946252a826d6f3bc572c7a70144c030d8fec1e4a9734be36 |
Close
Hashes for glslt-0.4.2-cp35-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 061a440b43db6cd027ecec4846b4b06e44226990c73939d18a6f2f6de3694e8c |
|
MD5 | ff8d1335546b8e7b355957e7753ee87a |
|
BLAKE2b-256 | 134e32fac0d827b7b2f4474fe08a04b0a7035fa8b81c8586e2185edd5bdcf029 |
Close
Hashes for glslt-0.4.2-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 416d0cfa5b56888954798167275201867dbc029b8881784ffdd337f4ef6ec96c |
|
MD5 | 6f0f88326f0f71f27a0bafe4a678bfd4 |
|
BLAKE2b-256 | 70a0fe9744d70d9708847898d7f8603209c5e228f954786f7152b31cf0391622 |
Close
Hashes for glslt-0.4.2-cp35-cp35m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ae4d5c55e7dce25dee9342b283e55a2a5a31fbd2d87977aeedd923834f7ebb2f |
|
MD5 | b40a1dce3a4d5c0fbea90942052b75fb |
|
BLAKE2b-256 | 99ee4f348c8928b76272e55f65ed1e3ff30b6c4adbe2cb948b0160f8ea24a86e |