Skip to main content

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


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 details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

glslt-0.5.0-cp39-cp39-manylinux2010_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.12+ x86-64

glslt-0.5.0-cp38-none-win_amd64.whl (1.2 MB view details)

Uploaded CPython 3.8Windows x86-64

glslt-0.5.0-cp38-cp38-manylinux2010_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.12+ x86-64

glslt-0.5.0-cp37-none-win_amd64.whl (1.2 MB view details)

Uploaded CPython 3.7Windows x86-64

glslt-0.5.0-cp37-cp37m-manylinux2010_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.7mmanylinux: glibc 2.12+ x86-64

glslt-0.5.0-cp36-none-win_amd64.whl (1.2 MB view details)

Uploaded CPython 3.6Windows x86-64

glslt-0.5.0-cp36-cp36m-manylinux2010_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.6mmanylinux: glibc 2.12+ x86-64

glslt-0.5.0-cp35-none-win_amd64.whl (1.2 MB view details)

Uploaded CPython 3.5Windows x86-64

glslt-0.5.0-cp35-cp35m-manylinux2010_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.5mmanylinux: glibc 2.12+ x86-64

File details

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

File metadata

  • Download URL: glslt-0.5.0.tar.gz
  • Upload date:
  • Size: 28.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.1.3 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

File hashes

Hashes for glslt-0.5.0.tar.gz
Algorithm Hash digest
SHA256 d26a986ac33c1c4cfc5a7d991ea9c4dc39f44d378537d4d6aeb49e6007d3dc53
MD5 26719601c3b2ed175216a989ebac948e
BLAKE2b-256 eb1d24c3633f6985aa89e80e365e6528b89daf498d5b73d6452062b05b75e9b1

See more details on using hashes here.

File details

Details for the file glslt-0.5.0-cp39-cp39-manylinux2010_x86_64.whl.

File metadata

  • Download URL: glslt-0.5.0-cp39-cp39-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 1.3 MB
  • Tags: CPython 3.9, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.1.3 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

File hashes

Hashes for glslt-0.5.0-cp39-cp39-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 e677809380dde81cbeeb81e1470406e79c8d6a061261c17fdac1d4d8ee53e011
MD5 f2c4398c3feb7a5deaf59243b8824885
BLAKE2b-256 2cd42ff8c9d6f8495c7caa86f7e096e2fd176ce60378b7fdcf4a84d6217ae858

See more details on using hashes here.

File details

Details for the file glslt-0.5.0-cp38-none-win_amd64.whl.

File metadata

  • Download URL: glslt-0.5.0-cp38-none-win_amd64.whl
  • Upload date:
  • Size: 1.2 MB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.1.3 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

File hashes

Hashes for glslt-0.5.0-cp38-none-win_amd64.whl
Algorithm Hash digest
SHA256 057ce0defd1f390102a3962df2923f9dcc565afdfad4ba5a5b581114a22f3f9e
MD5 167be7b5cad2b5498a73be114f435526
BLAKE2b-256 54c9c71255fd26c4ad345d0038a6ebb3a7b629154ef775380f71d862d8c90b07

See more details on using hashes here.

File details

Details for the file glslt-0.5.0-cp38-cp38-manylinux2010_x86_64.whl.

File metadata

  • Download URL: glslt-0.5.0-cp38-cp38-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 1.3 MB
  • Tags: CPython 3.8, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.1.3 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

File hashes

Hashes for glslt-0.5.0-cp38-cp38-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 2152b18442edaa11fa1bd5e6ccb13192dceb916b53c58869a60c35c30dfb5e57
MD5 1a9161177c5fc33863636ac65fd2bee5
BLAKE2b-256 c7eca683f39787913304cabc43f7643cba6dfacf282a3f6a2528425dbe8b1a79

See more details on using hashes here.

File details

Details for the file glslt-0.5.0-cp37-none-win_amd64.whl.

File metadata

  • Download URL: glslt-0.5.0-cp37-none-win_amd64.whl
  • Upload date:
  • Size: 1.2 MB
  • Tags: CPython 3.7, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.1.3 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

File hashes

Hashes for glslt-0.5.0-cp37-none-win_amd64.whl
Algorithm Hash digest
SHA256 c31629aa9ec3cd5ccab525dfd6be85d3cf16f4ab6061b5ceb7222b4ba5cb86af
MD5 97ef7e8d28840f7c15d233a9d6edd346
BLAKE2b-256 191b4781b4ae319074bdffcaf17da41f3610f0d46d764f9a672021dc5e26dffc

See more details on using hashes here.

File details

Details for the file glslt-0.5.0-cp37-cp37m-manylinux2010_x86_64.whl.

File metadata

  • Download URL: glslt-0.5.0-cp37-cp37m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 1.3 MB
  • Tags: CPython 3.7m, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.1.3 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

File hashes

Hashes for glslt-0.5.0-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 8a848765f010c7018577e54bffcd929118e35697acf84f6230ed191c4f4068d0
MD5 3bbe0920fdeb89d1bc63f779f5c997df
BLAKE2b-256 93a4f82c2824252a745c8adc2749c6deabf40ee86818424ed3be0efac356fdfa

See more details on using hashes here.

File details

Details for the file glslt-0.5.0-cp36-none-win_amd64.whl.

File metadata

  • Download URL: glslt-0.5.0-cp36-none-win_amd64.whl
  • Upload date:
  • Size: 1.2 MB
  • Tags: CPython 3.6, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.1.3 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

File hashes

Hashes for glslt-0.5.0-cp36-none-win_amd64.whl
Algorithm Hash digest
SHA256 c3ea69adfe056cbfc3837438f851e1361cf7ce0ad5b49bb987d42723e884c533
MD5 763f86ce4831da59b3929cdb9aea124b
BLAKE2b-256 a6462de88922e0838ae5fc94bd53e01a05c4cded0149502bdfc25a5f6ac4f0e8

See more details on using hashes here.

File details

Details for the file glslt-0.5.0-cp36-cp36m-manylinux2010_x86_64.whl.

File metadata

  • Download URL: glslt-0.5.0-cp36-cp36m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 1.3 MB
  • Tags: CPython 3.6m, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.1.3 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

File hashes

Hashes for glslt-0.5.0-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 93092283c09913127bfd4af0b27cf9e17029f9676a8e94d233afe5b41cddef5e
MD5 b00ee2072d9f79f273066737a005a3a3
BLAKE2b-256 299c4a3c527ca8c1a327cf9149517070b6780179f0cf99897cff3726de8d2241

See more details on using hashes here.

File details

Details for the file glslt-0.5.0-cp35-none-win_amd64.whl.

File metadata

  • Download URL: glslt-0.5.0-cp35-none-win_amd64.whl
  • Upload date:
  • Size: 1.2 MB
  • Tags: CPython 3.5, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.1.3 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

File hashes

Hashes for glslt-0.5.0-cp35-none-win_amd64.whl
Algorithm Hash digest
SHA256 d6239410ae5f4e0ad7a084670120e9ae5e37e0a91218d12fc5df5efddda1aaa3
MD5 105f16a521ffd214c1449fa72611f729
BLAKE2b-256 bae925303c107c9b72f0e0b70f421a9fbda5668aa915d73437794de1bfd1c7a9

See more details on using hashes here.

File details

Details for the file glslt-0.5.0-cp35-cp35m-manylinux2010_x86_64.whl.

File metadata

  • Download URL: glslt-0.5.0-cp35-cp35m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 1.3 MB
  • Tags: CPython 3.5m, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.1.3 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

File hashes

Hashes for glslt-0.5.0-cp35-cp35m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 e0a6bd53752d72d976807c7e706819911320ae079b2dc36e2a254365a3a6fb26
MD5 7c7b919d4c71368587f520260d49cab9
BLAKE2b-256 dd28306ac3cace5115e4b36d0ece228cfd185764e76ca8a2e9f225d9a51321dd

See more details on using hashes here.

Supported by

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