Class ShaderPreprocessor

java.lang.Object
lol.trq.helios.shader.ShaderPreprocessor

public final class ShaderPreprocessor extends Object
Expands #include directives and injects defines, keeping line numbers traceable.

The output starts with #version, then one #define per define, then the source. Each file gets a GLSL source-string number, and #line directives mark every switch between files, so a driver error such as 0(12) or 0:12 names the file and line through ShaderPreprocessor.Preprocessed.describe(String).

#include "name" resolves relative to the including file; #include <name> from the root. A file is included at most once per shader; an include cycle is an error. Helios has one dialect, GLSL 4.10 core: the output always declares #version 410 core, an entry file may repeat exactly that line, and any other #version is an error.

  • Field Details

    • VERSION_LINE

      public static final String VERSION_LINE
      The one GLSL version every Helios shader uses.
      See Also:
  • Constructor Details

    • ShaderPreprocessor

      public ShaderPreprocessor(SourceResolver resolver)
      Creates a preprocessor.
      Parameters:
      resolver - loads source files by name
  • Method Details

    • process

      public ShaderPreprocessor.Preprocessed process(String entry, Map<String,String> defines)
      Expands a shader.
      Parameters:
      entry - the name of the entry file
      defines - defines to inject, by name; a null or empty value defines the name alone
      Returns:
      the expanded source and its file table
      Throws:
      ShaderException - if a file is missing, an include cycles, or a define name is invalid