|
Sparkle 0.0.1
|
The idea behind Lumina is to abstract the GLSL from the user, using the langage as a sort of "script" The compiler will than take the script as input, and compute a file that will contain all the information available about this shader
The compiler now produces a single JSON document that contains every piece of information Sparkle needs to bind a shader. This keeps the artifact human readable, machine parsable, and easy to extend.
layouts is an ordered array of objects that describe every vertex attribute consumed by the shader.
Each entry contains:
framebuffers mirrors the layout structure but lists every color/depth attachment written by the fragment shader. Entries contain the layout location, output type, and generated name.
The textures array keeps the mapping between the identifier used in Lumina and the layout binding that GLSL uses. The compiler assigns a layout location (binding) to each declared texture in source order starting at 0; the GLSL uses this binding and the artifact mirrors it for the runtime. Each entry also carries the scope selected in the source file (constant or attribute), mirroring the as qualifier used during declaration.
See docs/lumina/compiled-artifact-example.json for a full sample artifact that exercises every field of the schema.
constants is a list of DataBlock declarations that were left at the default constant scope (explicit as constant works too). Bindings are not stored in the artifact anymore; only the total block size and the memory layout are emitted. The compiler evaluates the block body to decide the type:
Each members entry describes a field:
All offsets and sizes are emitted using OpenGL's standard layout rules: constant DataBlocks use std140 (UBO) while SSBO-backed blocks use std430. This means the values already include the implicit padding that GLSL expects, so you can forward them directly to your buffer builders without reapplying the layout rules.
This recursion lets the artifact represent arbitrarily deep structures without duplicating intermediate JSON blocks.
If the block needs a runtime-sized array, the emitted object also carries a dynamicArrayLayout entry that captures how the SSBO tail should be populated:
attributes follows the same structure as constants, but for DataBlocks declared with as attribute. Just like constant blocks, attribute DataBlocks default to UBO until they declare an unsized array, at which point the compiler switches the type to SSBO and emits the dynamicArrayLayout metadata described above. Attribute-scope DataBlocks are also limited to a single unsized array.
The compiled GLSL for each stage is embedded directly in shader.sources. Consumers can load vertex and fragment strings (and any future stages) without scanning the file for manual markers.