ShaderCompiler/GlslToCpp.h file

GLSL-to-C++ fragment-shader transpiler for ShaderCompiler.

Turns a shader's lowered fragment GLSL — the very text the tool bakes into a generated header's <Program>_Fs string — into a plain C++ function the CPU software renderer can call once per pixel, so an effect runs in software exactly as its GLSL specifies instead of being hand-ported. The emitted function is written against the runtime library in nCine/Graphics/RHI/Software/SwShaderRuntime.h (vec2/vec3/vec4, the GLSL built-ins, the swTexture() sampler shim and packColor()).

The transpiler reuses the existing expression lexer (GlslExprTokenizer) and the shader preprocessor (Preprocessor, to resolve the baked variant define, drop the GL_ES block and strip #line) and grows a real per-statement/expression AST from the token stream. It supports a bounded subset: float/int/bool and vec/ivec/bvec types, in/out/uniform globals, local declarations, =/+=/-=/*=//= assignments, if/else, C-style for, return, the ternary operator, arithmetic/comparison/logical operators, member and read-swizzle access, constructors, built-in and user-helper calls. Anything outside the subset (matrices, arrays, derivatives such as dFdx/fwidth, texelFetch/textureSize, a read of any varying other than vTexCoords/vColor, or any fragment output besides COLOR — the software rasterizer renders to a single color target, no MRT) makes GlslToCppResult::Supported false with a reason and NO emitted code, so unsupported shaders are cleanly declined rather than mistranslated.

Namespaces

namespace ShaderCompiler

Classes

struct ShaderCompiler::SamplerBinding
A sampler uniform's texture-unit assignment, taken from the program's reflection.
struct ShaderCompiler::GlslInstanceMember
One scalar/vector member of the per-instance std140 block, with its baked byte offset.
struct ShaderCompiler::GlslToCppResult
Outcome of transpiling one fragment shader to C++.
class ShaderCompiler::GlslToCpp
Transpiles lowered fragment GLSL into a C++ software-renderer fragment function.