Class ExtShaderProgram

java.lang.Object
gaiasky.util.gdx.shader.ExtShaderProgram
All Implemented Interfaces:
com.badlogic.gdx.utils.Disposable
Direct Known Subclasses:
TessellationShaderProgram

public class ExtShaderProgram extends Object implements com.badlogic.gdx.utils.Disposable
  • Field Details Link icon

    • POSITION_ATTRIBUTE Link icon

      public static final String POSITION_ATTRIBUTE
      Default name for position attributes.
      See Also:
    • COLOR_ATTRIBUTE Link icon

      public static final String COLOR_ATTRIBUTE
      Default name for color attributes.
      See Also:
    • NORMAL_ATTRIBUTE Link icon

      public static final String NORMAL_ATTRIBUTE
      Default name for normal attribute.
      See Also:
    • TEXCOORD_ATTRIBUTE Link icon

      public static final String TEXCOORD_ATTRIBUTE
      Default name for texture coordinates attributes, append texture unit number.
      See Also:
    • pedantic Link icon

      public static boolean pedantic
      Flag indicating whether attributes invalid input: '&' uniforms must be present at all times.
    • prependVertexCode Link icon

      public static String prependVertexCode
      Code that is always added to the vertex shader code, typically used to inject a #version line. Note that this is added as-is, you should include a newline (`\n`) if needed.
    • prependGeometryCode Link icon

      public static String prependGeometryCode
      Code that is always added to the geometry shader code, typically used to inject a #version line. Note that this is added as-is, you should include a newline (`\n`) if needed.
    • prependFragmentCode Link icon

      public static String prependFragmentCode
      Code that is always added to every fragment shader code, typically used to inject a #version line. Note that this is added as-is, you should include a newline (`\n`) if needed.
    • params Link icon

      protected IntBuffer params
      Int buffer for parameters.
    • type Link icon

      protected IntBuffer type
      Int buffer for types.
    • log Link icon

      protected String log
      The log.
    • name Link icon

      protected String name
      The shader name, if any.
    • isCompiled Link icon

      protected boolean isCompiled
      Whether this program compiled successfully.
    • isLazy Link icon

      protected boolean isLazy
      Whether lazy loading is activated for this shader.
    • isDisposed Link icon

      protected boolean isDisposed
      Whether this program has been disposed.
    • uniforms Link icon

      protected com.badlogic.gdx.utils.ObjectIntMap<String> uniforms
      Uniform lookup.
    • uniformTypes Link icon

      protected com.badlogic.gdx.utils.ObjectIntMap<String> uniformTypes
      Uniform types.
    • uniformSizes Link icon

      protected com.badlogic.gdx.utils.ObjectIntMap<String> uniformSizes
      Uniform sizes.
    • uniformNames Link icon

      protected String[] uniformNames
      Uniform names.
    • attributes Link icon

      protected com.badlogic.gdx.utils.ObjectIntMap<String> attributes
      Attribute lookup.
    • attributeTypes Link icon

      protected com.badlogic.gdx.utils.ObjectIntMap<String> attributeTypes
      Attribute types.
    • attributeSizes Link icon

      protected com.badlogic.gdx.utils.ObjectIntMap<String> attributeSizes
      Attribute sizes.
    • attributeNames Link icon

      protected String[] attributeNames
      Attribute names.
    • program Link icon

      protected int program
      Program handle.
    • vertexShaderHandle Link icon

      protected int vertexShaderHandle
      Vertex shader handle.
    • fragmentShaderHandle Link icon

      protected int fragmentShaderHandle
      Fragment shader handle.
    • vertexShaderSource Link icon

      protected String vertexShaderSource
      Vertex shader source.
    • geometryShaderSource Link icon

      protected String geometryShaderSource
      Geometry shader source.
    • fragmentShaderSource Link icon

      protected String fragmentShaderSource
      Fragment shader source.
    • vertexShaderFile Link icon

      protected String vertexShaderFile
    • geometryShaderFile Link icon

      protected String geometryShaderFile
    • fragmentShaderFile Link icon

      protected String fragmentShaderFile
    • invalidated Link icon

      protected boolean invalidated
      Whether this shader was invalidated.
  • Constructor Details Link icon

    • ExtShaderProgram Link icon

      public ExtShaderProgram()
    • ExtShaderProgram Link icon

      public ExtShaderProgram(String vertexFile, String fragmentFile, String vertexShaderCode, String fragmentShaderCode)
    • ExtShaderProgram Link icon

      public ExtShaderProgram(String vertexFile, String geometryFile, String fragmentFile, String vertexShaderCode, String geometryShaderCode, String fragmentShaderCode)
    • ExtShaderProgram Link icon

      public ExtShaderProgram(String name, String vertexFile, String geometryFile, String fragmentFile, String vertexShaderCode, String geometryShaderCode, String fragmentShaderCode)
    • ExtShaderProgram Link icon

      public ExtShaderProgram(String name, String vertexFile, String fragmentFile, String vertexShaderCode, String fragmentShaderCode)
    • ExtShaderProgram Link icon

      public ExtShaderProgram(String name, String vertexFile, String fragmentFile, String vertexShaderCode, String fragmentShaderCode, boolean lazyLoading)
      Constructs a new ShaderProgram and immediately compiles it.
      Parameters:
      name - The shader name, if any.
      vertexFile - The vertex shader file.
      fragmentFile - The fragment shader file.
      vertexShaderCode - The vertex shader code.
      fragmentShaderCode - The fragment shader code.
      lazyLoading - Whether to use lazy loading, only preparing the data without actually compiling the shaders.
    • ExtShaderProgram Link icon

      public ExtShaderProgram(String name, String vertexFile, String geometryFile, String fragmentFile, String vertexShaderCode, String geometryShaderCode, String fragmentShaderCode, boolean lazyLoading)
      Constructs a new ShaderProgram and immediately compiles it.
      Parameters:
      name - The shader name, if any.
      vertexFile - The vertex shader file.
      geometryFile - The geometry shader file.
      fragmentFile - The fragment shader file.
      vertexShaderCode - The vertex shader code.
      geometryShaderCode - The geometry shader code.
      fragmentShaderCode - The fragment shader code.
      lazyLoading - Whether to use lazy loading, only preparing the data without actually compiling the shaders.
    • ExtShaderProgram Link icon

      public ExtShaderProgram(String vertexShader, String fragmentShader)
      Constructs a new ShaderProgram and immediately compiles it.
      Parameters:
      vertexShader - The vertex shader code.
      fragmentShader - The fragment shader code.
    • ExtShaderProgram Link icon

      public ExtShaderProgram(com.badlogic.gdx.files.FileHandle vertexShader, com.badlogic.gdx.files.FileHandle fragmentShader)
  • Method Details Link icon

    • invalidateAllShaderPrograms Link icon

      public static void invalidateAllShaderPrograms(com.badlogic.gdx.Application app)
      Invalidates all shaders so the next time they are used new handles are generated
      Parameters:
      app - The application.
    • clearAllShaderPrograms Link icon

      public static void clearAllShaderPrograms(com.badlogic.gdx.Application app)
    • getManagedStatus Link icon

      public static String getManagedStatus()
    • getNumManagedShaderPrograms Link icon

      public static int getNumManagedShaderPrograms()
      Returns:
      the number of managed shader programs currently loaded
    • initializeLocalAssets Link icon

      protected void initializeLocalAssets()
    • compile Link icon

      public void compile()
    • createProgram Link icon

      protected int createProgram()
    • getLog Link icon

      public String getLog()
      Returns:
      the log info for the shader compilation and program linking stage. The shader needs to be bound for this method to have an effect.
    • isCompiled Link icon

      public boolean isCompiled()
      Returns:
      whether this program compiled successfully.
    • isLazy Link icon

      public boolean isLazy()
      Returns:
      whether this program has lazy loading activated.
    • fetchAttributeLocation Link icon

      protected int fetchAttributeLocation(String name)
    • fetchUniformLocation Link icon

      protected int fetchUniformLocation(String name)
    • fetchUniformLocation Link icon

      public int fetchUniformLocation(String name, boolean pedantic)
    • setUniformi Link icon

      public void setUniformi(String name, int value)
      Sets the uniform with the given name. The ExtShaderProgram must be bound for this to work.
      Parameters:
      name - the name of the uniform
      value - the value
    • setUniformi Link icon

      public void setUniformi(int location, int value)
    • setUniformi Link icon

      public void setUniformi(String name, int value1, int value2)
      Sets the uniform with the given name. The ExtShaderProgram must be bound for this to work.
      Parameters:
      name - the name of the uniform
      value1 - the first value
      value2 - the second value
    • setUniformi Link icon

      public void setUniformi(int location, int value1, int value2)
    • setUniformi Link icon

      public void setUniformi(String name, int value1, int value2, int value3)
      Sets the uniform with the given name. The ExtShaderProgram must be bound for this to work.
      Parameters:
      name - the name of the uniform
      value1 - the first value
      value2 - the second value
      value3 - the third value
    • setUniformi Link icon

      public void setUniformi(int location, int value1, int value2, int value3)
    • setUniformi Link icon

      public void setUniformi(String name, int value1, int value2, int value3, int value4)
      Sets the uniform with the given name. The ExtShaderProgram must be bound for this to work.
      Parameters:
      name - the name of the uniform
      value1 - the first value
      value2 - the second value
      value3 - the third value
      value4 - the fourth value
    • setUniformi Link icon

      public void setUniformi(int location, int value1, int value2, int value3, int value4)
    • setUniformf Link icon

      public void setUniformf(String name, float value)
      Sets the uniform with the given name. The ExtShaderProgram must be bound for this to work.
      Parameters:
      name - the name of the uniform
      value - the value
    • setUniformf Link icon

      public void setUniformf(int location, float value)
    • setUniformf Link icon

      public void setUniformf(String name, float value1, float value2)
      Sets the uniform with the given name. The ExtShaderProgram must be bound for this to work.
      Parameters:
      name - the name of the uniform
      value1 - the first value
      value2 - the second value
    • setUniformf Link icon

      public void setUniformf(int location, float value1, float value2)
    • setUniformf Link icon

      public void setUniformf(String name, float value1, float value2, float value3)
      Sets the uniform with the given name. The ExtShaderProgram must be bound for this to work.
      Parameters:
      name - the name of the uniform
      value1 - the first value
      value2 - the second value
      value3 - the third value
    • setUniformf Link icon

      public void setUniformf(int location, float value1, float value2, float value3)
    • setUniformf Link icon

      public void setUniformf(String name, float value1, float value2, float value3, float value4)
      Sets the uniform with the given name. The ExtShaderProgram must be bound for this to work.
      Parameters:
      name - the name of the uniform
      value1 - the first value
      value2 - the second value
      value3 - the third value
      value4 - the fourth value
    • setUniformf Link icon

      public void setUniformf(int location, float value1, float value2, float value3, float value4)
    • setUniform1fv Link icon

      public void setUniform1fv(String name, float[] values, int offset, int length)
    • setUniform1fv Link icon

      public void setUniform1fv(int location, float[] values, int offset, int length)
    • setUniform2fv Link icon

      public void setUniform2fv(String name, float[] values, int offset, int length)
    • setUniform2fv Link icon

      public void setUniform2fv(int location, float[] values, int offset, int length)
    • setUniform3fv Link icon

      public void setUniform3fv(String name, float[] values, int offset, int length)
    • setUniform3fv Link icon

      public void setUniform3fv(int location, float[] values, int offset, int length)
    • setUniform4fv Link icon

      public void setUniform4fv(String name, float[] values, int offset, int length)
    • setUniform4fv Link icon

      public void setUniform4fv(int location, float[] values, int offset, int length)
    • setUniformMatrix Link icon

      public void setUniformMatrix(String name, com.badlogic.gdx.math.Matrix4 matrix)
      Sets the uniform matrix with the given name. The ExtShaderProgram must be bound for this to work.
      Parameters:
      name - the name of the uniform
      matrix - the matrix
    • setUniformMatrix Link icon

      public void setUniformMatrix(String name, com.badlogic.gdx.math.Matrix4 matrix, boolean transpose)
      Sets the uniform matrix with the given name. The ExtShaderProgram must be bound for this to work.
      Parameters:
      name - the name of the uniform
      matrix - the matrix
      transpose - whether the matrix should be transposed
    • setUniformMatrix Link icon

      public void setUniformMatrix(int location, com.badlogic.gdx.math.Matrix4 matrix)
    • setUniformMatrix Link icon

      public void setUniformMatrix(int location, com.badlogic.gdx.math.Matrix4 matrix, boolean transpose)
    • setUniformMatrix Link icon

      public void setUniformMatrix(String name, com.badlogic.gdx.math.Matrix3 matrix)
      Sets the uniform matrix with the given name. The ExtShaderProgram must be bound for this to work.
      Parameters:
      name - the name of the uniform
      matrix - the matrix
    • setUniformMatrix Link icon

      public void setUniformMatrix(String name, com.badlogic.gdx.math.Matrix3 matrix, boolean transpose)
      Sets the uniform matrix with the given name. The ExtShaderProgram must be bound for this to work.
      Parameters:
      name - the name of the uniform
      matrix - the matrix
      transpose - whether the uniform matrix should be transposed
    • setUniformMatrix Link icon

      public void setUniformMatrix(int location, com.badlogic.gdx.math.Matrix3 matrix)
    • setUniformMatrix Link icon

      public void setUniformMatrix(int location, com.badlogic.gdx.math.Matrix3 matrix, boolean transpose)
    • setUniformMatrix3fv Link icon

      public void setUniformMatrix3fv(String name, FloatBuffer buffer, int count, boolean transpose)
      Sets an array of uniform matrices with the given name. The ExtShaderProgram must be bound for this to work.
      Parameters:
      name - the name of the uniform
      buffer - buffer containing the matrix data
      transpose - whether the uniform matrix should be transposed
    • setUniformMatrix4fv Link icon

      public void setUniformMatrix4fv(String name, FloatBuffer buffer, int count, boolean transpose)
      Sets an array of uniform matrices with the given name. The ExtShaderProgram must be bound for this to work.
      Parameters:
      name - the name of the uniform
      buffer - buffer containing the matrix data
      transpose - whether the uniform matrix should be transposed
    • setUniformMatrix4fv Link icon

      public void setUniformMatrix4fv(int location, float[] values, int offset, int length)
    • setUniformMatrix4fv Link icon

      public void setUniformMatrix4fv(String name, float[] values, int offset, int length)
    • setUniformf Link icon

      public void setUniformf(String name, com.badlogic.gdx.math.Vector2 values)
      Sets the uniform with the given name. The ExtShaderProgram must be bound for this to work.
      Parameters:
      name - the name of the uniform
      values - x and y as the first and second values respectively
    • setUniformf Link icon

      public void setUniformf(int location, com.badlogic.gdx.math.Vector2 values)
    • setUniformf Link icon

      public void setUniformf(String name, com.badlogic.gdx.math.Vector3 values)
      Sets the uniform with the given name. The ExtShaderProgram must be bound for this to work.
      Parameters:
      name - the name of the uniform
      values - x, y and z as the first, second and third values respectively
    • setUniformf Link icon

      public void setUniformf(int location, com.badlogic.gdx.math.Vector3 values)
    • setUniformf Link icon

      public void setUniformf(String name, com.badlogic.gdx.graphics.Color values)
      Sets the uniform with the given name. The ExtShaderProgram must be bound for this to work.
      Parameters:
      name - the name of the uniform
      values - r, g, b and a as the first through fourth values respectively
    • setUniformf Link icon

      public void setUniformf(int location, com.badlogic.gdx.graphics.Color values)
    • setVertexAttribute Link icon

      public void setVertexAttribute(String name, int size, int type, boolean normalize, int stride, Buffer buffer)
      Sets the vertex attribute with the given name. The ExtShaderProgram must be bound for this to work.
      Parameters:
      name - the attribute name
      size - the number of components, must be >= 1 and invalid input: '<'= 4
      type - the type, must be one of GL20.GL_BYTE, GL20.GL_UNSIGNED_BYTE, GL20.GL_SHORT, GL20.GL_UNSIGNED_SHORT,GL20.GL_FIXED, or GL20.GL_FLOAT. GL_FIXED will not work on the desktop
      normalize - whether fixed point data should be normalized. Will not work on the desktop
      stride - the stride in bytes between successive attributes
      buffer - the buffer containing the vertex attributes.
    • setVertexAttribute Link icon

      public void setVertexAttribute(int location, int size, int type, boolean normalize, int stride, Buffer buffer)
    • setVertexAttribute Link icon

      public void setVertexAttribute(String name, int size, int type, boolean normalize, int stride, int offset)
      Sets the vertex attribute with the given name. The ExtShaderProgram must be bound for this to work.
      Parameters:
      name - the attribute name
      size - the number of components, must be >= 1 and invalid input: '<'= 4
      type - the type, must be one of GL20.GL_BYTE, GL20.GL_UNSIGNED_BYTE, GL20.GL_SHORT, GL20.GL_UNSIGNED_SHORT,GL20.GL_FIXED, or GL20.GL_FLOAT. GL_FIXED will not work on the desktop
      normalize - whether fixed point data should be normalized. Will not work on the desktop
      stride - the stride in bytes between successive attributes
      offset - byte offset into the vertex buffer object bound to GL20.GL_ARRAY_BUFFER.
    • setVertexAttribute Link icon

      public void setVertexAttribute(int location, int size, int type, boolean normalize, int stride, int offset)
    • begin Link icon

      public void begin()
      Makes OpenGL ES 2.0 use this vertex and fragment shader pair. When you are done with this shader you have to call end().
    • end Link icon

      public void end()
      Disables this shader. Must be called when one is done with the shader. Don't mix it with dispose, that will release the shader resources.
    • disableVertexAttribute Link icon

      public void disableVertexAttribute(String name)
      Disables the vertex attribute with the given name
      Parameters:
      name - the vertex attribute name
    • disableVertexAttribute Link icon

      public void disableVertexAttribute(int location)
    • enableVertexAttribute Link icon

      public void enableVertexAttribute(String name)
      Enables the vertex attribute with the given name
      Parameters:
      name - the vertex attribute name
    • enableVertexAttribute Link icon

      public void enableVertexAttribute(int location)
    • setAttributef Link icon

      public void setAttributef(String name, float value1, float value2, float value3, float value4)
      Sets the given attribute
      Parameters:
      name - the name of the attribute
      value1 - the first value
      value2 - the second value
      value3 - the third value
      value4 - the fourth value
    • fetchUniforms Link icon

      protected void fetchUniforms()
    • fetchAttributes Link icon

      protected void fetchAttributes()
    • hasAttribute Link icon

      public boolean hasAttribute(String name)
      Parameters:
      name - the name of the attribute
      Returns:
      whether the attribute is available in the shader
    • getAttributeType Link icon

      public int getAttributeType(String name)
      Parameters:
      name - the name of the attribute
      Returns:
      the type of the attribute, one of GL20.GL_FLOAT, GL20.GL_FLOAT_VEC2 etc.
    • getAttributeLocation Link icon

      public int getAttributeLocation(String name)
      Parameters:
      name - the name of the attribute
      Returns:
      the location of the attribute or -1.
    • getAttributeSize Link icon

      public int getAttributeSize(String name)
      Parameters:
      name - the name of the attribute
      Returns:
      the size of the attribute or 0.
    • hasUniform Link icon

      public boolean hasUniform(String name)
      Parameters:
      name - the name of the uniform
      Returns:
      whether the uniform is available in the shader
    • getUniformType Link icon

      public int getUniformType(String name)
      Parameters:
      name - the name of the uniform
      Returns:
      the type of the uniform, one of GL20.GL_FLOAT, GL20.GL_FLOAT_VEC2 etc.
    • getUniformLocation Link icon

      public int getUniformLocation(String name)
      Parameters:
      name - the name of the uniform
      Returns:
      the location of the uniform or -1.
    • getUniformSize Link icon

      public int getUniformSize(String name)
      Parameters:
      name - the name of the uniform
      Returns:
      the size of the uniform or 0.
    • getAttributes Link icon

      public String[] getAttributes()
      Returns:
      the attributes
    • getUniforms Link icon

      public String[] getUniforms()
      Returns:
      the uniforms
    • getVertexShaderSource Link icon

      public String getVertexShaderSource()
      Returns:
      the source of the vertex shader
    • getFragmentShaderSource Link icon

      public String getFragmentShaderSource()
      Returns:
      the source of the fragment shader
    • dispose Link icon

      public void dispose()
      Disposes all resources associated with this shader. Must be called when the shader is no longer used.
      Specified by:
      dispose in interface com.badlogic.gdx.utils.Disposable