Skip to main content

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

Alixinne alixinne@pm.me

Project details


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.7.6.tar.gz (26.4 kB view details)

Uploaded Source

Built Distributions

glslt-0.7.6-cp313-none-win_amd64.whl (1.6 MB view details)

Uploaded CPython 3.13Windows x86-64

glslt-0.7.6-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.13tmanylinux: glibc 2.17+ x86-64

glslt-0.7.6-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

glslt-0.7.6-cp312-none-win_amd64.whl (1.6 MB view details)

Uploaded CPython 3.12Windows x86-64

glslt-0.7.6-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

glslt-0.7.6-cp311-none-win_amd64.whl (1.6 MB view details)

Uploaded CPython 3.11Windows x86-64

glslt-0.7.6-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

glslt-0.7.6-cp310-none-win_amd64.whl (1.6 MB view details)

Uploaded CPython 3.10Windows x86-64

glslt-0.7.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

File details

Details for the file glslt-0.7.6.tar.gz.

File metadata

  • Download URL: glslt-0.7.6.tar.gz
  • Upload date:
  • Size: 26.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.3

File hashes

Hashes for glslt-0.7.6.tar.gz
Algorithm Hash digest
SHA256 44deb19c2e993854acb3f4cc8c204fb1ecc2d9d68a6b1fe86d2592d2830d5c12
MD5 e4165a7c4d695b26d87a1d133257d2f2
BLAKE2b-256 683d882c481d4090bf9e52aa749b7413ff7f1a373349c7f717b5a99d4e7dfb56

See more details on using hashes here.

File details

Details for the file glslt-0.7.6-cp313-none-win_amd64.whl.

File metadata

  • Download URL: glslt-0.7.6-cp313-none-win_amd64.whl
  • Upload date:
  • Size: 1.6 MB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.3

File hashes

Hashes for glslt-0.7.6-cp313-none-win_amd64.whl
Algorithm Hash digest
SHA256 08fd21a988eb8afa8081366981f284e5e4d7add653b4df45bd452a5e1f53c243
MD5 51727f237c5cdbf22ef242f88a525080
BLAKE2b-256 a9f660eb458604f94c9010e5806a7a4e3b214efce6ac2a07b99635685000a652

See more details on using hashes here.

File details

Details for the file glslt-0.7.6-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for glslt-0.7.6-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 114308dfb4b14091daf415c655e62fa1e6252efd331b7644393d1dde042f9112
MD5 47af7741fef765902bc71a0e4bd019cf
BLAKE2b-256 c5dd9830c53cfc81bc1ed12c555439e2f76ff64b3c8c1a70c281dea96484d023

See more details on using hashes here.

File details

Details for the file glslt-0.7.6-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for glslt-0.7.6-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6ce44e3c83e5cf8e12827cb33fc746e75d7e0fc31b812e8df3063182bc90f7b2
MD5 94634ba2187e3dcd793beceaa30392ea
BLAKE2b-256 e99d8acf83f61b0a960890d1ae612a870ac81fbe5f30f098a5d7230378e5179f

See more details on using hashes here.

File details

Details for the file glslt-0.7.6-cp312-none-win_amd64.whl.

File metadata

  • Download URL: glslt-0.7.6-cp312-none-win_amd64.whl
  • Upload date:
  • Size: 1.6 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.3

File hashes

Hashes for glslt-0.7.6-cp312-none-win_amd64.whl
Algorithm Hash digest
SHA256 8e2f7ea2db2a6fcc3ccb761f3d717aafde144f4420f07fabe67b6d3ec99b1c09
MD5 c1182111a1c2be8cf9c62804f2895495
BLAKE2b-256 6418c4e61efaeeeca830edada62a199ae3ad8bbb334318e71ac91aaa530a2a59

See more details on using hashes here.

File details

Details for the file glslt-0.7.6-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for glslt-0.7.6-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5612359c9acc769773e34d90a626b1255360a68c6bab731fe88f7f10e8346478
MD5 3e336753a4f51ad1a3aacbb0ff0c068f
BLAKE2b-256 4a5891f21e98a4dd1343b0b9c94c3152ee435566c8ad598f61cee00335de0bd1

See more details on using hashes here.

File details

Details for the file glslt-0.7.6-cp311-none-win_amd64.whl.

File metadata

  • Download URL: glslt-0.7.6-cp311-none-win_amd64.whl
  • Upload date:
  • Size: 1.6 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.3

File hashes

Hashes for glslt-0.7.6-cp311-none-win_amd64.whl
Algorithm Hash digest
SHA256 b3e25d7f7e17517d6767f92eb064247ffa72659cefa5126bf954e6318d8f534a
MD5 dfc1e8f71a91793ee6ac7b09a2868808
BLAKE2b-256 7c5ef42301291703b2059745a91d7da8063f6652fce9011c5f3df33bacc54627

See more details on using hashes here.

File details

Details for the file glslt-0.7.6-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for glslt-0.7.6-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f2ecca2176c8780200fb5b7022cd91c34baba383ba2c3a6f1283b4ec91d5edd2
MD5 74b775d34374da226e61dbaada94b1ed
BLAKE2b-256 c61fd7e6ff50b9a0e21639cd40f59913ff113e82fec0763acc0684850d691e41

See more details on using hashes here.

File details

Details for the file glslt-0.7.6-cp310-none-win_amd64.whl.

File metadata

  • Download URL: glslt-0.7.6-cp310-none-win_amd64.whl
  • Upload date:
  • Size: 1.6 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.3

File hashes

Hashes for glslt-0.7.6-cp310-none-win_amd64.whl
Algorithm Hash digest
SHA256 09ba3c056bb0c936772b0828c731c6cb9a8bd04c379cb9fa44d327171cf55a35
MD5 add4591ae10eea6dd7238e7bb08d9c3b
BLAKE2b-256 f0a6d9afa4669e70b31a9c63d9b99508186d4fc418f7a27369a1ed686d524ea2

See more details on using hashes here.

File details

Details for the file glslt-0.7.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for glslt-0.7.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1071b2dee3321268c90995d7f19f7e5815409d415d72cea50c9475332c028df2
MD5 49b1cc4cbce8cb5096498fd0e4422a5a
BLAKE2b-256 cc605c52d6c124e2b4179e437620dec0f9173734a6986c72ba8452352e59d1c2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page