Class TextureArrayShaderCompiler

java.lang.Object
com.github.tommyettinger.textra.TextureArrayShaderCompiler

public final class TextureArrayShaderCompiler extends Object
Allows processing fragment shaders to use an unrolled loop for use in Texture Array Batches, and compiling those shaders with the right size for MAX_TEXTURE_UNIT. Typically, a TextureArrayPolygonSpriteBatch or TextureArrayCpuPolygonSpriteBatch must be constructed in create() before this class can be used. Constructing one of those Batches will set MAX_TEXTURE_UNIT based on the current GPU's actual capability, which is needed before any shaders can be processed correctly.
Mostly taken from Hyperlap2D's GitHub repo. Originally licensed under Apache 2.0, like TextraTypist and libGDX.
  • Field Details

    • MAX_TEXTURE_UNIT

      public static int MAX_TEXTURE_UNIT
      Will be modified when a TextureArrayPolygonSpriteBatch or TextureArrayCpuPolygonSpriteBatch is constructed for the first time, typically in create(). Before one of those Batches has been created, this class is effectively not usable.
    • GET_TEXTURE_FROM_ARRAY_PLACEHOLDER

      public static final String GET_TEXTURE_FROM_ARRAY_PLACEHOLDER
      The String that indicates a fragment shader needs processing to receive an unrolled loop in its source.
      See Also:
  • Method Details

    • compileShader

      public static com.badlogic.gdx.graphics.glutils.ShaderProgram compileShader(com.badlogic.gdx.files.FileHandle vertex, com.badlogic.gdx.files.FileHandle fragment)
      Processes the text of fragment with processArrayTextureShader(String) and returns a new ShaderProgram constructed from the given shader source FileHandles.
      Parameters:
      vertex - a vertex shader source in a FileHandle
      fragment - a fragment shader source in a FileHandle
      Returns:
      a new ShaderProgram using vertex and the processed fragment
    • compileShader

      public static com.badlogic.gdx.graphics.glutils.ShaderProgram compileShader(String vertex, String fragment)
      Processes fragment with processArrayTextureShader(String) and returns a new ShaderProgram constructed from the given shader source Strings.
      Parameters:
      vertex - a vertex shader source String
      fragment - a fragment shader source String
      Returns:
      a new ShaderProgram using vertex and the processed fragment
    • processArrayTextureShader

      public static String processArrayTextureShader(String fragment)
      Takes a fragment shader source String and, if it contains GET_TEXTURE_FROM_ARRAY_PLACEHOLDER, replaces that text with code for an unrolled loop sized based on MAX_TEXTURE_UNIT.
      Parameters:
      fragment - a fragment shader source String
      Returns:
      fragment, potentially after modifications