ShaderCompiler::ShaderParser class

Parses and lowers the ".shader" input language.

Public static functions

static auto ParseDocuments(StringView content, std::vector<ShaderDocument>& documents, Diagnostic& diag) -> bool
static void SplitLines(StringView content, std::vector<SourceLine>& lines)
static void StripComments(std::vector<SourceLine>& lines)
static auto ExpandIncludes(String& content, StringView baseDir, const FileReader& reader, std::int32_t depth, String& error) -> bool
static auto BuildStageSource(const ShaderDocument& document, bool vertexStage, StringView define, bool softwareRenderer = false) -> String
static auto DirectoryOf(StringView path) -> String

Function documentation

static bool ShaderCompiler::ShaderParser::ParseDocuments(StringView content, std::vector<ShaderDocument>& documents, Diagnostic& diag)

Parses the whole (include-expanded) file content and lowers it into one or more ShaderDocuments. Custom-mode files (the default, no "shader_type" statement) produce exactly one document; "shader_type canvas_item;" files produce the primary document plus, when "batched <Name>;" is present, its batched twin.

static void ShaderCompiler::ShaderParser::SplitLines(StringView content, std::vector<SourceLine>& lines)

Splits raw file content into lines (handles CRLF/CR and backslash-newline continuations)

static void ShaderCompiler::ShaderParser::StripComments(std::vector<SourceLine>& lines)

Removes line comments and block comments in place (newlines and line numbering are preserved)

static bool ShaderCompiler::ShaderParser::ExpandIncludes(String& content, StringView baseDir, const FileReader& reader, std::int32_t depth, String& error)

Expands #include "relative/path" lines recursively (textually), relative to baseDir, reading files through reader (the offline tool passes a filesystem reader, the engine passes its own virtual filesystem). Runs on the raw text before parsing, so both reflection and the emitted sources see the included text inlined. As a consequence, line numbers in diagnostics refer to the include-expanded stream.

static String ShaderCompiler::ShaderParser::BuildStageSource(const ShaderDocument& document, bool vertexStage, StringView define, bool softwareRenderer = false)

Builds the compilable GLSL source of one stage (baked variant define + "#line 1" + shared prelude + stage body). "#ifdef/#ifndef SOFTWARE_RENDERER" conditionals (with an optional "#else" and the matching "#endif") are resolved here according to softwareRenderer, like the stage macros are at assembly time - the built sources never contain the macro itself. Every emission passes false (the default); only the offline GLSL-to-C++ software-fragment transpiler builds its input with true, so a shader can carry a cheaper software-renderer variant of a too-expensive fragment path without affecting any other backend's output.

static String ShaderCompiler::ShaderParser::DirectoryOf(StringView path)

Returns the directory part of path, or "." if it has none