glslt


Nameglslt JSON
Version 0.7.4 PyPI version JSON
download
home_pagehttps://github.com/alixinne/glslt
SummaryGLSLT Template compiler library
upload_time2024-08-19 22:56:05
maintainerNone
docs_urlNone
authorAlixinne <alixinne@pm.me>
requires_pythonNone
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/alixinne/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

Alixinne <alixinne@pm.me>


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/alixinne/glslt",
    "name": "glslt",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "glslt, glsl, language, parser, template",
    "author": "Alixinne <alixinne@pm.me>",
    "author_email": "Alixinne <alixinne@pm.me>",
    "download_url": "https://files.pythonhosted.org/packages/e0/1e/201f7de0b4126449b9e43eacd1760220bb6a0260d014002cddcd9d128a34/glslt-0.7.4.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/alixinne/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\nAlixinne <alixinne@pm.me>\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "GLSLT Template compiler library",
    "version": "0.7.4",
    "project_urls": {
        "Homepage": "https://github.com/alixinne/glslt",
        "Source Code": "https://github.com/alixinne/glslt.git"
    },
    "split_keywords": [
        "glslt",
        " glsl",
        " language",
        " parser",
        " template"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "542405657e9284b2848a1658b7d05e4c4d3fc288cb6d2ca29b7de71af62882df",
                "md5": "ab7650310aebf20624e00beaf76fae6a",
                "sha256": "657698db3452a99df125ce7c582684327bdd6fa196119f166df6580aa6f6cbcc"
            },
            "downloads": -1,
            "filename": "glslt-0.7.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "has_sig": false,
            "md5_digest": "ab7650310aebf20624e00beaf76fae6a",
            "packagetype": "bdist_wheel",
            "python_version": "cp310",
            "requires_python": null,
            "size": 1916713,
            "upload_time": "2024-08-19T22:55:51",
            "upload_time_iso_8601": "2024-08-19T22:55:51.637124Z",
            "url": "https://files.pythonhosted.org/packages/54/24/05657e9284b2848a1658b7d05e4c4d3fc288cb6d2ca29b7de71af62882df/glslt-0.7.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9c46931e3d57b332c90d2d54bb473e9c504f27c0748fb9f3da3fdb951bb474bd",
                "md5": "ace7020bf479fb4cea21de33d79bc5f6",
                "sha256": "cbdba8abcbd148f9e1a05629119926a9995d4d3b25bab4f76f09cf2fabc43c8d"
            },
            "downloads": -1,
            "filename": "glslt-0.7.4-cp310-none-win_amd64.whl",
            "has_sig": false,
            "md5_digest": "ace7020bf479fb4cea21de33d79bc5f6",
            "packagetype": "bdist_wheel",
            "python_version": "cp310",
            "requires_python": null,
            "size": 1534489,
            "upload_time": "2024-08-19T22:55:53",
            "upload_time_iso_8601": "2024-08-19T22:55:53.119793Z",
            "url": "https://files.pythonhosted.org/packages/9c/46/931e3d57b332c90d2d54bb473e9c504f27c0748fb9f3da3fdb951bb474bd/glslt-0.7.4-cp310-none-win_amd64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "eb0b20907689f881d17160ef925b254e74bbd61c69e524f59233464b77975f2e",
                "md5": "60d48767a99ed01aee083bfd78adb37a",
                "sha256": "794081ca76bbc2221292871ee48fc56562a884dbffdc342d42ca4711972178bd"
            },
            "downloads": -1,
            "filename": "glslt-0.7.4-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "has_sig": false,
            "md5_digest": "60d48767a99ed01aee083bfd78adb37a",
            "packagetype": "bdist_wheel",
            "python_version": "cp37",
            "requires_python": null,
            "size": 1918709,
            "upload_time": "2024-08-19T22:55:54",
            "upload_time_iso_8601": "2024-08-19T22:55:54.875324Z",
            "url": "https://files.pythonhosted.org/packages/eb/0b/20907689f881d17160ef925b254e74bbd61c69e524f59233464b77975f2e/glslt-0.7.4-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4fda9d43a7eed1c026e6319b99f8f338f5bdfa4cefef4a17239af04a0e73a858",
                "md5": "16307747bfe6ea43084e83b3ccb01a4f",
                "sha256": "2286b2493b7cd588cd0fe75b0941f0535d5ab99891f575e1421f1c92d28d883f"
            },
            "downloads": -1,
            "filename": "glslt-0.7.4-cp37-none-win_amd64.whl",
            "has_sig": false,
            "md5_digest": "16307747bfe6ea43084e83b3ccb01a4f",
            "packagetype": "bdist_wheel",
            "python_version": "cp37",
            "requires_python": null,
            "size": 1535004,
            "upload_time": "2024-08-19T22:55:56",
            "upload_time_iso_8601": "2024-08-19T22:55:56.525051Z",
            "url": "https://files.pythonhosted.org/packages/4f/da/9d43a7eed1c026e6319b99f8f338f5bdfa4cefef4a17239af04a0e73a858/glslt-0.7.4-cp37-none-win_amd64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f8a43054601424b8d548ef8d6808a1db51364dca3d845f7a1c3505688c656d9e",
                "md5": "27a544cfe671a0f89e954d27f62f24bb",
                "sha256": "181d4fd875e424328bf031d5680186476c30f407ec2b7231224017d0010ed26d"
            },
            "downloads": -1,
            "filename": "glslt-0.7.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "has_sig": false,
            "md5_digest": "27a544cfe671a0f89e954d27f62f24bb",
            "packagetype": "bdist_wheel",
            "python_version": "cp38",
            "requires_python": null,
            "size": 1918266,
            "upload_time": "2024-08-19T22:55:58",
            "upload_time_iso_8601": "2024-08-19T22:55:58.531382Z",
            "url": "https://files.pythonhosted.org/packages/f8/a4/3054601424b8d548ef8d6808a1db51364dca3d845f7a1c3505688c656d9e/glslt-0.7.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "053616cf6312aea024bfc2172ccf0cf5ecffeddf1af4a3cdc2c8eaba8f1cc0af",
                "md5": "198302a1edef6323be2389f21b8424fb",
                "sha256": "9f0dcc354ed34f4405a9fbeeca1e5486f0646635ac799a819e99b5697a45ca75"
            },
            "downloads": -1,
            "filename": "glslt-0.7.4-cp38-none-win_amd64.whl",
            "has_sig": false,
            "md5_digest": "198302a1edef6323be2389f21b8424fb",
            "packagetype": "bdist_wheel",
            "python_version": "cp38",
            "requires_python": null,
            "size": 1534782,
            "upload_time": "2024-08-19T22:56:00",
            "upload_time_iso_8601": "2024-08-19T22:56:00.223342Z",
            "url": "https://files.pythonhosted.org/packages/05/36/16cf6312aea024bfc2172ccf0cf5ecffeddf1af4a3cdc2c8eaba8f1cc0af/glslt-0.7.4-cp38-none-win_amd64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "cf814b17a599ff17e63d2db5705cc4ff7e5d3a7ab19e9cb5a2b177e830b6db10",
                "md5": "0243f99a0248ff3149bcd2e69aa609ad",
                "sha256": "931c74473989099c1b8b9cf5366568f737e416ca0fe3207748c2dd901de9aa25"
            },
            "downloads": -1,
            "filename": "glslt-0.7.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "has_sig": false,
            "md5_digest": "0243f99a0248ff3149bcd2e69aa609ad",
            "packagetype": "bdist_wheel",
            "python_version": "cp39",
            "requires_python": null,
            "size": 1917893,
            "upload_time": "2024-08-19T22:56:01",
            "upload_time_iso_8601": "2024-08-19T22:56:01.868026Z",
            "url": "https://files.pythonhosted.org/packages/cf/81/4b17a599ff17e63d2db5705cc4ff7e5d3a7ab19e9cb5a2b177e830b6db10/glslt-0.7.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "fa645f35f0a47e6b6a008daaa554e4693b9f68acd4df3760bce79b0647c6c5a3",
                "md5": "59f6e51761a9e2897c23879aa308e7ad",
                "sha256": "edf44112dccc93a7474691d7322e899dd055391b00b0adfdbc13207ed83ea33c"
            },
            "downloads": -1,
            "filename": "glslt-0.7.4-cp39-none-win_amd64.whl",
            "has_sig": false,
            "md5_digest": "59f6e51761a9e2897c23879aa308e7ad",
            "packagetype": "bdist_wheel",
            "python_version": "cp39",
            "requires_python": null,
            "size": 1534555,
            "upload_time": "2024-08-19T22:56:03",
            "upload_time_iso_8601": "2024-08-19T22:56:03.615891Z",
            "url": "https://files.pythonhosted.org/packages/fa/64/5f35f0a47e6b6a008daaa554e4693b9f68acd4df3760bce79b0647c6c5a3/glslt-0.7.4-cp39-none-win_amd64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e01e201f7de0b4126449b9e43eacd1760220bb6a0260d014002cddcd9d128a34",
                "md5": "b3da6fa9b697fc0cf2dd3d5e3f66a660",
                "sha256": "720bb42970b2cda83692ab580cb6d8a4a5de451dd5e33667c4525432cbb9764f"
            },
            "downloads": -1,
            "filename": "glslt-0.7.4.tar.gz",
            "has_sig": false,
            "md5_digest": "b3da6fa9b697fc0cf2dd3d5e3f66a660",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 26439,
            "upload_time": "2024-08-19T22:56:05",
            "upload_time_iso_8601": "2024-08-19T22:56:05.403284Z",
            "url": "https://files.pythonhosted.org/packages/e0/1e/201f7de0b4126449b9e43eacd1760220bb6a0260d014002cddcd9d128a34/glslt-0.7.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-19 22:56:05",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "alixinne",
    "github_project": "glslt",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "glslt"
}
        
Elapsed time: 0.29281s