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.1.tar.gz
(16.5 kB
view hashes)
Built Distributions
glslt-0.4.1-cp38-none-win_amd64.whl
(682.2 kB
view hashes)
glslt-0.4.1-cp38-none-win32.whl
(624.8 kB
view hashes)
glslt-0.4.1-cp37-none-win_amd64.whl
(682.3 kB
view hashes)
glslt-0.4.1-cp37-none-win32.whl
(624.8 kB
view hashes)
glslt-0.4.1-cp35-none-win_amd64.whl
(682.4 kB
view hashes)
glslt-0.4.1-cp35-none-win32.whl
(624.9 kB
view hashes)
Close
Hashes for glslt-0.4.1-cp39-cp39-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9368f8ae8ac48ed83c8462cb307ad9a856bc3e5cf462d4fa0abacd3226db6a35 |
|
MD5 | 714dc261537936a3eb3014e6f3ae6787 |
|
BLAKE2b-256 | d4f625d8d5bd7d6b51c90e0e554e738113dbefc4993616ffc429279eaddf9b96 |
Close
Hashes for glslt-0.4.1-cp39-cp39-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e1959891b0141abeb7431b525b51bacb41fd464088cb6e70929fc08b292e9cfc |
|
MD5 | ccfd543220b5fa4a621fad7c731b6832 |
|
BLAKE2b-256 | fe0967bfbe68748c9d09b26d360d61babcd3f28d416c08be2a40a13d74116968 |
Close
Hashes for glslt-0.4.1-cp38-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5c7d1b53ae7a855d13013e496b9befb2c42f552d8f865792f260229f743e9c30 |
|
MD5 | af62ffb373d844dbb183da69dc5577c8 |
|
BLAKE2b-256 | 816a17a3b1229dbbb489c13448dbe24aa6e16751aef511f95407a06148e8d153 |
Close
Hashes for glslt-0.4.1-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2a519293fb662fa76338e3dfa403ecd178c6337f29ea61bb5a61b822823793df |
|
MD5 | dbff3ccd8401c3fcbaec4fa8a314e51e |
|
BLAKE2b-256 | b560d1922c7673905a4709e49eedb412612257fc37b03326f1dc545f8b3f8f6c |
Close
Hashes for glslt-0.4.1-cp38-cp38-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 93fd89077bcf233c9bc11a841ec7d21419d6d61ce6071528c2db6a8e3b793094 |
|
MD5 | 289d7904e69fe5323a2f26b260a2d16d |
|
BLAKE2b-256 | 0fd9f6d8dcf714439bd11d13e04f32ea938166f5333816114c1a92b52e16868b |
Close
Hashes for glslt-0.4.1-cp37-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1ab3ad98f91ab427d61fbe5bc4f2daa28254a579884a67a351e5ca0c35ac64b8 |
|
MD5 | f782d14d1a6ea22bc7e29f9627820afc |
|
BLAKE2b-256 | 93da07e2c0ccc898e65a4ff05c125d5d560e0cf8b73afd9af2309996552caac9 |
Close
Hashes for glslt-0.4.1-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e7830c2b641546b4b542c528f2a73d7367d65702b7b7149c75c2422ce13c9873 |
|
MD5 | a6dd8af6950d29b8a3898db021c4a7c4 |
|
BLAKE2b-256 | 2d14335cd6884d9a3a2e17b2b1e6cc193bf6e4aa9587438226ae5e0bb389c712 |
Close
Hashes for glslt-0.4.1-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5157bcb4b556eb758c62452ae09d75c5f75a14ed78be54f835aab14cd2288809 |
|
MD5 | f6c3cab28b241fc672d42b880ea0b572 |
|
BLAKE2b-256 | 26d5f9b4c208a466a132c42db09bd7d31258cac3b8a7a8b462c5632d910cc18d |
Close
Hashes for glslt-0.4.1-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9498d33a895017b96292c0fc2a90601046da000db3e5927c91bb49657f2bf09d |
|
MD5 | 282bbd13ac4e7448d230d6b7b6ebdae6 |
|
BLAKE2b-256 | 24a45b3b3c82965a1d61736340bc53c251ff27f30ea5f980710a56c32437f708 |
Close
Hashes for glslt-0.4.1-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f3643046df7d3d13150fecf757a7ad3618835d093b0841e87ab4d0c2919d99df |
|
MD5 | 8045e6e8c71a524a264f85d49a3d897e |
|
BLAKE2b-256 | 56588daf969c50a3cf6fb1b4251533296276503e0cc937da19184335bfb6b80d |
Close
Hashes for glslt-0.4.1-cp35-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f4adf482e217f67080a92fabb8b576f725e4913caf0072a7060c20163d1b2e3d |
|
MD5 | 744d5ef55baa4163a99be2ce3e23f7c2 |
|
BLAKE2b-256 | dd8dbf2e63e1de981b71e44781a2be28caa5bca707a8c9947dc6e06b126258da |
Close
Hashes for glslt-0.4.1-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 238ea041aa598bb6b2ee6fbd44fd7c94cbfb730275e8cca0053b235b0264759a |
|
MD5 | 3b1ce9f0da4a749114ed1d8affd7b045 |
|
BLAKE2b-256 | 7acd3e45ded0f481734cea3b2e543581a9a3c7efc588f4133803b58071680795 |
Close
Hashes for glslt-0.4.1-cp35-cp35m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 74921edc1f87523e2d52faa78ef0216bebf8203b07d031406a62fa1b27f97413 |
|
MD5 | 27f8885c2968949a2cd74adfd1a96aea |
|
BLAKE2b-256 | 2e9ba871ec4fc0e6b8b4925735c2bfd9dda70bef8838ba6164a5b68e332723bb |