ShaderLibrary

class ShaderLibrary

Named GLSL sources, and the #include resolver that assembles them.

The module’s own shaders (acron/src/shading/shaders/) are compiled into the library at build time and registered under their file names (pbr_brdf.glsl, pbr.frag, …), so a C++ program needs no files on disk. A game or another module adds its own with set_source(), or adds a directory to the search path (looked up through the virtual file system when a name is not registered); a registered name wins over a file.

resolve() replaces every line #include "name" by that source, each source once (a later include of the same name is dropped, so every file behaves as if it had an include guard), and drops any #version line. assemble() then puts #version <v> core and the defines in front. No GL is involved: a test can check what a shader will be compiled from.

Inheritance diagram

digraph inheritance155bdac930 { bgcolor=transparent; rankdir=BT; size="8.0, 12.0"; "DTOOL_SUPER_BASE" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=11,height=0.25,shape=box,style=""]; "ShaderLibrary" [URL="acron.shading.ShaderLibrary.html#acron.shading.ShaderLibrary",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=11,height=0.25,shape=box,style="",target="_top",tooltip="/**"]; "DTOOL_SUPER_BASE" -> "ShaderLibrary" [arrowsize=0.75,style=""]; }
ShaderLibrary.assemble()

A complete shader source: #version <glsl_version> core, a SHADING_GLSL_VERSION define, the given define lines, then the resolved text.

assemble() with the sources of overlay (a LightingContext’s) in front of the library’s: a name the overlay has is taken from it.

static ShaderLibrary.get_global_ptr()

The process-wide library, with the module’s own sources registered.

ShaderLibrary.get_num_sources()
ShaderLibrary.get_search_path()

The directories searched (through the virtual file system) for a name that is not registered.

ShaderLibrary.get_source()

The text of a source: a registered one, or else a file of that name on the search path. Empty, with an error, if there is neither.

ShaderLibrary.get_source_name()

The registered names, in sorted order.

ShaderLibrary.has_source()

True if the name is registered (files on the search path don’t count).

ShaderLibrary.remove_source()

Unregisters a source. Returns false if there was none of that name.

ShaderLibrary.resolve()

The text with its includes pasted in (each source once) and any #version line dropped. A missing include becomes an #error line, so the compiler stops there with the name.

ShaderLibrary.set_source()

Registers (or replaces) a source under a name.