Package com.github.tommyettinger.textra
Class TextureArrayShaderCompiler
java.lang.Object
com.github.tommyettinger.textra.TextureArrayShaderCompiler
Allows processing fragment shaders to use an unrolled loop for use in Texture Array Batches, and compiling those
shaders with the right size for
Mostly taken from Hyperlap2D's GitHub repo. Originally licensed under Apache 2.0, like TextraTypist and libGDX.
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe String that indicates a fragment shader needs processing to receive an unrolled loop in its source.static intWill be modified when aTextureArrayPolygonSpriteBatchorTextureArrayCpuPolygonSpriteBatchis constructed for the first time, typically in create(). -
Method Summary
Modifier and TypeMethodDescriptionstatic com.badlogic.gdx.graphics.glutils.ShaderProgramcompileShader(com.badlogic.gdx.files.FileHandle vertex, com.badlogic.gdx.files.FileHandle fragment) Processes the text offragmentwithprocessArrayTextureShader(String)and returns a new ShaderProgram constructed from the given shader source FileHandles.static com.badlogic.gdx.graphics.glutils.ShaderProgramcompileShader(String vertex, String fragment) ProcessesfragmentwithprocessArrayTextureShader(String)and returns a new ShaderProgram constructed from the given shader source Strings.static StringprocessArrayTextureShader(String fragment) Takes a fragment shader source String and, if it containsGET_TEXTURE_FROM_ARRAY_PLACEHOLDER, replaces that text with code for an unrolled loop sized based onMAX_TEXTURE_UNIT.
-
Field Details
-
MAX_TEXTURE_UNIT
public static int MAX_TEXTURE_UNITWill be modified when aTextureArrayPolygonSpriteBatchorTextureArrayCpuPolygonSpriteBatchis 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
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 offragmentwithprocessArrayTextureShader(String)and returns a new ShaderProgram constructed from the given shader source FileHandles.- Parameters:
vertex- a vertex shader source in a FileHandlefragment- 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) ProcessesfragmentwithprocessArrayTextureShader(String)and returns a new ShaderProgram constructed from the given shader source Strings.- Parameters:
vertex- a vertex shader source Stringfragment- a fragment shader source String- Returns:
- a new ShaderProgram using vertex and the processed fragment
-
processArrayTextureShader
Takes a fragment shader source String and, if it containsGET_TEXTURE_FROM_ARRAY_PLACEHOLDER, replaces that text with code for an unrolled loop sized based onMAX_TEXTURE_UNIT.- Parameters:
fragment- a fragment shader source String- Returns:
fragment, potentially after modifications
-