Class ShaderPreDefinitions

java.lang.Object
foundry.veil.api.client.render.shader.definition.ShaderPreDefinitions

public class ShaderPreDefinitions extends Object

Manages pre-defined variables and data in java that can be applied to shaders.

Regular definitions are added with define(String), define(String, String), and set(String, String). These schedule a shader recompilation every time they are set so shaders can remain up-to-date.

  • Constructor Details

    • ShaderPreDefinitions

      public ShaderPreDefinitions()
      Creates a new set of predefinitions.
  • Method Details

    • addListener

      public void addListener(Consumer<String> definitionCallback)
      Adds a listener for when a change happens.
      Parameters:
      definitionCallback - The callback for when definitions change or null to ignore changes
    • define

      public void define(String name)
      Sets the value of a definition pair. If the value has changed, all shaders depending on it will recompile.
      Parameters:
      name - The name of the definition to set
    • define

      public void define(String name, @Nullable @Nullable String definition)
      Sets the value of a definition pair. If the value has changed, all shaders depending on it will recompile.
      Parameters:
      name - The name of the definition to set
      definition - The value to associate with it or null to only add #define name
    • set

      public void set(String name, String definition)
      Sets the value of a definition pair. If the value has changed, all shaders depending on it will recompile.
      Parameters:
      name - The name of the definition to set
      definition - The value to associate with it
    • defineStatic

      public void defineStatic(String name)
      Sets a definition added to all shaders. These should be treated as static final variables.
      Parameters:
      name - The name of the definition to set
    • defineStatic

      public void defineStatic(String name, @Nullable @Nullable String definition)
      Sets a definition added to all shaders. These should be treated as static final variables.
      Parameters:
      name - The name of the definition to set
      definition - The value to associate with it or null to only add #define name
    • setStatic

      public void setStatic(String name, String definition)
      Sets a definition added to all shaders. These should be treated as static final variables.
      Parameters:
      name - The name of the definition to set
      definition - The value to associate with it
    • remove

      public void remove(String name)
      Removes the definition with the specified name.
      Parameters:
      name - The name of the definition to remove
    • addStaticDefinitions

      public void addStaticDefinitions(Consumer<String> definitionConsumer)
      Adds definitions that never change during runtime. This is for constants, like a debug flag.
      Parameters:
      definitionConsumer - The consumer for definition lines
    • getDefinition

      @Nullable public @Nullable String getDefinition(String name)
      Retrieves a definition by name.
      Parameters:
      name - The name of the definition
      Returns:
      The definition with that name or null if it doesn't exist
    • getDefinitions

      public Map<String,String> getDefinitions()
      Returns:
      A view of all definitions