glslt


Nameglslt JSON
Version 0.7.2 PyPI version JSON
download
home_pagehttps://github.com/vtavernier/glslt
SummaryGLSLT Template compiler library
upload_time2023-11-05 15:33:52
maintainer
docs_urlNone
authorVincent Tavernier <v.tavernier@pm.me>
requires_python
licenseMIT
keywords glslt glsl language parser template
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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](https://github.com/vtavernier/glsl-lang).

```rust
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.

```python
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 <v.tavernier@pm.me>


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/vtavernier/glslt",
    "name": "glslt",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "glslt,glsl,language,parser,template",
    "author": "Vincent Tavernier <v.tavernier@pm.me>",
    "author_email": "Vincent Tavernier <v.tavernier@pm.me>",
    "download_url": "https://files.pythonhosted.org/packages/e3/06/779e5b9d47b3e014fd36a4e57a7d2813b2290c92295e97b4daf2201a81c2/glslt-0.7.2.tar.gz",
    "platform": null,
    "description": "# glslt\n\nglslt is the main library that supports the GLSL Template compiler transforms. If you are\nbuilding a system that relies on transforming GLSLT code, you'll want to interact with this\nlibrary directly instead of the command-line interface provided by `glsltc`.\n\n## Usage\n\n### Rust crate\n\nThe glslt crate manipulates syntax trees generated by the [glsl-lang\ncrate](https://github.com/vtavernier/glsl-lang).\n\n```rust\nuse glslt::glsl_lang::{ast::*, parse::IntoParseBuilderExt};\nuse glslt::transform::{Unit, TransformUnit};\n\nlet glsl_src = r#\"\nfloat sdf3d(in vec3 p);\nfloat colort();\n\nfloat sdSphere(vec3 p, float r) {\n    return length(p) - r;\n}\n\nfloat opElongate(in sdf3d primitive, in colort C, in vec3 p, in colort D, in vec3 h) {\n    vec3 q = p - clamp(p, -h, h);\n    return C() * primitive(q) * D();\n}\n\nvoid mainImage(out vec4 fragColor, in vec2 fragCoord) {\n    float sz = 5.;\n    fragColor = vec4(vec3(opElongate(sdSphere(_p, sz), 1.0, vec3(fragCoord, 0.), 2.0, vec3(1., 2., 3.))), 1.0);\n}\n\"#;\n\n// Parse the GLSLT source code\nlet tu: TranslationUnit = glsl_src\n    .builder()\n    .context(&glslt::parse::make_parse_context(None))\n    .parse()\n    .expect(\"failed to parse GLSLT source\")\n    .0;\n\n// Create the transform unit\nlet mut unit = Unit::new();\n\n// Parse declarations\nfor decl in tu.0.into_iter() {\n    unit.parse_external_declaration(decl).expect(\"failed to parse declaration\");\n}\n\n// Generate the result\nlet tu = unit.into_translation_unit().expect(\"failed to generate output\");\n\n// Transpile the syntax tree to GLSL source\nlet mut output_src = String::new();\nglsl_lang::transpiler::glsl::show_translation_unit(\n    &mut output_src,\n    &tu,\n    glsl_lang::transpiler::glsl::FormattingState::default(),\n).expect(\"failed to generate GLSL\");\n```\n\n### Python library\n\nIf you installed the glslt library via `pip install glslt` or `maturin\ndevelop`, you may use the Python interface to the GLSLT compiler.\n\n```python\nimport glslt\n\n# Parse the `sdf.glsl` file with `my-glsl-lib/include` being a system include\n# directory for #include resolution\ntranslation_unit = glslt.parse_files([\"sdf.glsl\"], [\"my-glsl-lib/include\"])\n\n# Create a new minimizing transform unit\nunit = glslt.MinUnit()\n\n# Add the parsed declarations to the transform unit\nunit.add_unit(translation_unit)\n\n# Get the output of the transform\nresult = unit.to_translation_unit([\"mainImage\"])\n\n# Print the GLSL code\nprint(result.to_glsl())\n```\n\n## Author\n\nVincent Tavernier <v.tavernier@pm.me>\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "GLSLT Template compiler library",
    "version": "0.7.2",
    "project_urls": {
        "Homepage": "https://github.com/vtavernier/glslt",
        "Source Code": "https://github.com/vtavernier/glslt.git"
    },
    "split_keywords": [
        "glslt",
        "glsl",
        "language",
        "parser",
        "template"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1b88986a4cdd252bed0a4382d66ec11538b5bc6486cccd5c62e09c9926c4aa7a",
                "md5": "f889708a48088966aa3a0d8d9cdbb2b3",
                "sha256": "9f309bf95aeb6aa7e0b4dfb0912d78ed495e5bddf5b795b2232f9beb22b647c4"
            },
            "downloads": -1,
            "filename": "glslt-0.7.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "has_sig": false,
            "md5_digest": "f889708a48088966aa3a0d8d9cdbb2b3",
            "packagetype": "bdist_wheel",
            "python_version": "cp310",
            "requires_python": null,
            "size": 1683883,
            "upload_time": "2023-11-05T15:33:38",
            "upload_time_iso_8601": "2023-11-05T15:33:38.487704Z",
            "url": "https://files.pythonhosted.org/packages/1b/88/986a4cdd252bed0a4382d66ec11538b5bc6486cccd5c62e09c9926c4aa7a/glslt-0.7.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5e1c4b272aab962e5f9f4678113c013366b302811aba7d3874a0d0cec7935f84",
                "md5": "9ef8b67b66a85aab245800d83c2bd725",
                "sha256": "0e715c18d736f3e6a5e8764b7d42d71899762657e8aca1189dc0b76496305fb2"
            },
            "downloads": -1,
            "filename": "glslt-0.7.2-cp310-none-win_amd64.whl",
            "has_sig": false,
            "md5_digest": "9ef8b67b66a85aab245800d83c2bd725",
            "packagetype": "bdist_wheel",
            "python_version": "cp310",
            "requires_python": null,
            "size": 1595498,
            "upload_time": "2023-11-05T15:33:40",
            "upload_time_iso_8601": "2023-11-05T15:33:40.139582Z",
            "url": "https://files.pythonhosted.org/packages/5e/1c/4b272aab962e5f9f4678113c013366b302811aba7d3874a0d0cec7935f84/glslt-0.7.2-cp310-none-win_amd64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0b41bcef04672845d449ad44dc4a88a519fddeb7a6e5ed3bc486f2d4c929b959",
                "md5": "99e4703e909c4d8517450184bc389b5b",
                "sha256": "8005e64169f1622f8144842d26fdc6fd03637aaeb5422c9b76fb4c9ea45591e6"
            },
            "downloads": -1,
            "filename": "glslt-0.7.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "has_sig": false,
            "md5_digest": "99e4703e909c4d8517450184bc389b5b",
            "packagetype": "bdist_wheel",
            "python_version": "cp37",
            "requires_python": null,
            "size": 1683907,
            "upload_time": "2023-11-05T15:33:42",
            "upload_time_iso_8601": "2023-11-05T15:33:42.137863Z",
            "url": "https://files.pythonhosted.org/packages/0b/41/bcef04672845d449ad44dc4a88a519fddeb7a6e5ed3bc486f2d4c929b959/glslt-0.7.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "57ff918f95974d2c078bd2f4dbfccde011276129212bf10f00bd0bab3198a754",
                "md5": "2b8f613292f3c5563dd1b106f25dbee8",
                "sha256": "8039c5fc37a037191f3dfc7c63e4f066e1f633b5c48d8089fd15ebd87066972b"
            },
            "downloads": -1,
            "filename": "glslt-0.7.2-cp37-none-win_amd64.whl",
            "has_sig": false,
            "md5_digest": "2b8f613292f3c5563dd1b106f25dbee8",
            "packagetype": "bdist_wheel",
            "python_version": "cp37",
            "requires_python": null,
            "size": 1595142,
            "upload_time": "2023-11-05T15:33:43",
            "upload_time_iso_8601": "2023-11-05T15:33:43.579639Z",
            "url": "https://files.pythonhosted.org/packages/57/ff/918f95974d2c078bd2f4dbfccde011276129212bf10f00bd0bab3198a754/glslt-0.7.2-cp37-none-win_amd64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "97049e50b814d173d5423d383cb5a4262b3b2c252823415e90328c37a83412b7",
                "md5": "e5f5b8fb2ed8bb5fb85b3633420df269",
                "sha256": "f55f43c27d174ff895f09bf887a27c61e2aa30461ff170fca66f5a31ee41c07d"
            },
            "downloads": -1,
            "filename": "glslt-0.7.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "has_sig": false,
            "md5_digest": "e5f5b8fb2ed8bb5fb85b3633420df269",
            "packagetype": "bdist_wheel",
            "python_version": "cp38",
            "requires_python": null,
            "size": 1684700,
            "upload_time": "2023-11-05T15:33:45",
            "upload_time_iso_8601": "2023-11-05T15:33:45.029251Z",
            "url": "https://files.pythonhosted.org/packages/97/04/9e50b814d173d5423d383cb5a4262b3b2c252823415e90328c37a83412b7/glslt-0.7.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d548df5abb391004246982c3169f707493b0249a0185f665c257fb8e8c211258",
                "md5": "6149ac5e58ff8cf7fa782996215d9816",
                "sha256": "49cf7f54436019b536f3bb483748d440659f5236630c4bc499c56fe95d268b57"
            },
            "downloads": -1,
            "filename": "glslt-0.7.2-cp38-none-win_amd64.whl",
            "has_sig": false,
            "md5_digest": "6149ac5e58ff8cf7fa782996215d9816",
            "packagetype": "bdist_wheel",
            "python_version": "cp38",
            "requires_python": null,
            "size": 1595473,
            "upload_time": "2023-11-05T15:33:46",
            "upload_time_iso_8601": "2023-11-05T15:33:46.851458Z",
            "url": "https://files.pythonhosted.org/packages/d5/48/df5abb391004246982c3169f707493b0249a0185f665c257fb8e8c211258/glslt-0.7.2-cp38-none-win_amd64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4c1b32adaa1cb4ef796977c67bd5a676824e2082bbc629175ed7473a1e16867e",
                "md5": "2e870e029fc8c7301c63a3d683661e18",
                "sha256": "c9b65672a6e6c952fdae1cb907fda825b93a8a49258f098724355384bff53633"
            },
            "downloads": -1,
            "filename": "glslt-0.7.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "has_sig": false,
            "md5_digest": "2e870e029fc8c7301c63a3d683661e18",
            "packagetype": "bdist_wheel",
            "python_version": "cp39",
            "requires_python": null,
            "size": 1683698,
            "upload_time": "2023-11-05T15:33:48",
            "upload_time_iso_8601": "2023-11-05T15:33:48.921265Z",
            "url": "https://files.pythonhosted.org/packages/4c/1b/32adaa1cb4ef796977c67bd5a676824e2082bbc629175ed7473a1e16867e/glslt-0.7.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "89ad750b8cd1c1af5a3e16293ebc375fe227741321925b76b55a09a61bd58811",
                "md5": "14f89454a659d2533f851b31a74c2bfd",
                "sha256": "7d9ef44d27552eb4cf1fefa7d67f099eb3f5620c31f456df11391b4a05c9b603"
            },
            "downloads": -1,
            "filename": "glslt-0.7.2-cp39-none-win_amd64.whl",
            "has_sig": false,
            "md5_digest": "14f89454a659d2533f851b31a74c2bfd",
            "packagetype": "bdist_wheel",
            "python_version": "cp39",
            "requires_python": null,
            "size": 1595723,
            "upload_time": "2023-11-05T15:33:50",
            "upload_time_iso_8601": "2023-11-05T15:33:50.710347Z",
            "url": "https://files.pythonhosted.org/packages/89/ad/750b8cd1c1af5a3e16293ebc375fe227741321925b76b55a09a61bd58811/glslt-0.7.2-cp39-none-win_amd64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e306779e5b9d47b3e014fd36a4e57a7d2813b2290c92295e97b4daf2201a81c2",
                "md5": "09973dc4196a412b2e56439737ca2e5c",
                "sha256": "82a3297d549568f05ba405c4131aa4c776b95a9901c0504192f7641a368196c7"
            },
            "downloads": -1,
            "filename": "glslt-0.7.2.tar.gz",
            "has_sig": false,
            "md5_digest": "09973dc4196a412b2e56439737ca2e5c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 26877,
            "upload_time": "2023-11-05T15:33:52",
            "upload_time_iso_8601": "2023-11-05T15:33:52.299919Z",
            "url": "https://files.pythonhosted.org/packages/e3/06/779e5b9d47b3e014fd36a4e57a7d2813b2290c92295e97b4daf2201a81c2/glslt-0.7.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-05 15:33:52",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "vtavernier",
    "github_project": "glslt",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "glslt"
}
        
Elapsed time: 0.13530s