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.2.tar.gz
(26.9 kB
view hashes)
Built Distributions
Close
Hashes for glslt-0.6.2-cp310-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 109b8ce2af1596a6e9064b9dbb6be2791ff6c30874dac62de396500f7fc5d91e |
|
MD5 | ad43323de189fa1a0d9e598a3dc0d151 |
|
BLAKE2b-256 | 863679938c22c5d30ba8d31878fe5540ce0f73c197dea55ff63653808a375cab |
Close
Hashes for glslt-0.6.2-cp310-cp310-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 897bfd1556e1bd4ec8ce6bacc9c605b2817f57dec17fe016071cf27478377393 |
|
MD5 | a23947d7d88d43798a500151a5ed1a9c |
|
BLAKE2b-256 | 9c1a703de0be0cff261a521349944021c0da6c27ce17948ea086320bdd4a988f |
Close
Hashes for glslt-0.6.2-cp39-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6ad274c7684f1dbff6cc469950a715808f37ff63da1a76568ec620a5deadc1d2 |
|
MD5 | c4e5468621f330c64b658e032d6c9a78 |
|
BLAKE2b-256 | 3a410a60fdf19053b1ca7c5a5448995bc13a204edbb3989f03506410fef171e9 |
Close
Hashes for glslt-0.6.2-cp39-cp39-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 13592cbb5497dd4e7f1060e4a882f3f4e2d58c58bc7954fdf7948171950746a3 |
|
MD5 | e843c4111997467f67ed34fe0aec8cf6 |
|
BLAKE2b-256 | f9b989063692264a6163640315f73f49dad8c46ac4667050a481ec1716eccc07 |
Close
Hashes for glslt-0.6.2-cp38-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5c2db1cd165230826a2044dfe90efef6a2ef569e9de780c63b043cc6f1790e4d |
|
MD5 | 39be2a52dd31cc6cedac0693329e7efd |
|
BLAKE2b-256 | 7a2fcc3150a5696b9f3b50d9b9b6c192b3cc76db9ec2bcb52fc7bee0fa671ced |
Close
Hashes for glslt-0.6.2-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | efda9a0eba83e8010dae4877c51f4c5ed391cb5812f2e70e204b75de23c8efbd |
|
MD5 | 024fce975fda4940d9e7a7cb4f7277ec |
|
BLAKE2b-256 | 549ec2c5dec7349b1f8d4c2f369c61bf8c40ebfb04729c4c9478849ddfa71677 |
Close
Hashes for glslt-0.6.2-cp37-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 50de23189859f489c9ac79f14d53734042591039a60775a92a27921f57b919a1 |
|
MD5 | 32c6bfd7612da55f5d5face67f9d545e |
|
BLAKE2b-256 | 175f7ed00b1a91677820589f45a46ac8cfb420a4d2f985b2ffaa595857bd43f3 |
Close
Hashes for glslt-0.6.2-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3e2c9b87ad4990403ae9d9091a26dc881a4c43a00affd73b5a11667d2565c3b7 |
|
MD5 | aa76c6bd0c2d9bb9c9e2433a245e178f |
|
BLAKE2b-256 | c9fe9b31380c78324a29f36b74120eac93c5378feaa9ecda19a1d0d60932ac90 |
Close
Hashes for glslt-0.6.2-cp36-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 003489d2587397eadf026d687068162d25982b3a75931b41c0f1ea1be572471d |
|
MD5 | 99732a9a79065124f225b21831f97d42 |
|
BLAKE2b-256 | 4131e6e0d786fe7357cb3d86c7ef936c271a50ca490b1837bbe5c980b5cdd8cb |
Close
Hashes for glslt-0.6.2-cp36-cp36m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3468cb757a26ffbacb8832d1bd739bd3f0786febda274160617c5eda75ce0b4e |
|
MD5 | 255a4dfcf64406d4e0ad49415a6b1fa0 |
|
BLAKE2b-256 | 4d871bf2446a8aa6e249947445f5e24cd5e177278642e092d7c5fdaef358493c |