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_lang::ast::*;
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 = glslt::parse::parse_source_default(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_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.5.0.tar.gz
(28.3 kB
view hashes)
Built Distributions
Close
Hashes for glslt-0.5.0-cp39-cp39-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e677809380dde81cbeeb81e1470406e79c8d6a061261c17fdac1d4d8ee53e011 |
|
MD5 | f2c4398c3feb7a5deaf59243b8824885 |
|
BLAKE2b-256 | 2cd42ff8c9d6f8495c7caa86f7e096e2fd176ce60378b7fdcf4a84d6217ae858 |
Close
Hashes for glslt-0.5.0-cp38-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 057ce0defd1f390102a3962df2923f9dcc565afdfad4ba5a5b581114a22f3f9e |
|
MD5 | 167be7b5cad2b5498a73be114f435526 |
|
BLAKE2b-256 | 54c9c71255fd26c4ad345d0038a6ebb3a7b629154ef775380f71d862d8c90b07 |
Close
Hashes for glslt-0.5.0-cp38-cp38-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2152b18442edaa11fa1bd5e6ccb13192dceb916b53c58869a60c35c30dfb5e57 |
|
MD5 | 1a9161177c5fc33863636ac65fd2bee5 |
|
BLAKE2b-256 | c7eca683f39787913304cabc43f7643cba6dfacf282a3f6a2528425dbe8b1a79 |
Close
Hashes for glslt-0.5.0-cp37-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c31629aa9ec3cd5ccab525dfd6be85d3cf16f4ab6061b5ceb7222b4ba5cb86af |
|
MD5 | 97ef7e8d28840f7c15d233a9d6edd346 |
|
BLAKE2b-256 | 191b4781b4ae319074bdffcaf17da41f3610f0d46d764f9a672021dc5e26dffc |
Close
Hashes for glslt-0.5.0-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8a848765f010c7018577e54bffcd929118e35697acf84f6230ed191c4f4068d0 |
|
MD5 | 3bbe0920fdeb89d1bc63f779f5c997df |
|
BLAKE2b-256 | 93a4f82c2824252a745c8adc2749c6deabf40ee86818424ed3be0efac356fdfa |
Close
Hashes for glslt-0.5.0-cp36-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c3ea69adfe056cbfc3837438f851e1361cf7ce0ad5b49bb987d42723e884c533 |
|
MD5 | 763f86ce4831da59b3929cdb9aea124b |
|
BLAKE2b-256 | a6462de88922e0838ae5fc94bd53e01a05c4cded0149502bdfc25a5f6ac4f0e8 |
Close
Hashes for glslt-0.5.0-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 93092283c09913127bfd4af0b27cf9e17029f9676a8e94d233afe5b41cddef5e |
|
MD5 | b00ee2072d9f79f273066737a005a3a3 |
|
BLAKE2b-256 | 299c4a3c527ca8c1a327cf9149517070b6780179f0cf99897cff3726de8d2241 |
Close
Hashes for glslt-0.5.0-cp35-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d6239410ae5f4e0ad7a084670120e9ae5e37e0a91218d12fc5df5efddda1aaa3 |
|
MD5 | 105f16a521ffd214c1449fa72611f729 |
|
BLAKE2b-256 | bae925303c107c9b72f0e0b70f421a9fbda5668aa915d73437794de1bfd1c7a9 |
Close
Hashes for glslt-0.5.0-cp35-cp35m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e0a6bd53752d72d976807c7e706819911320ae079b2dc36e2a254365a3a6fb26 |
|
MD5 | 7c7b919d4c71368587f520260d49cab9 |
|
BLAKE2b-256 | dd28306ac3cace5115e4b36d0ece228cfd185764e76ca8a2e9f225d9a51321dd |