A shader program encapsulates a vertex and fragment shader pair linked to form a shader program.
After construction a ShaderProgram can be used to draw Mesh. To make the GPU use a specific ShaderProgram the programs
ShaderProgram#bind() method must be used which effectively binds the program.
When a ShaderProgram is bound one can set uniforms, vertex attributes and attributes as needed via the respective methods.
A ShaderProgram must be disposed via a call to ShaderProgram#dispose() when it is no longer needed
ShaderPrograms are managed. In case the OpenGL context is lost all shaders get invalidated and have to be reloaded. This happens on Android when a user switches to another application or receives an incoming call. Managed ShaderPrograms are automatically reloaded when the OpenGL context is recreated so you don't have to do this manually.
| Modifier and Type | Field and Description |
|---|---|
| private String[] | attributeNames
attribute names |
| private final ObjectIntMap | attributes
attribute lookup |
| private final ObjectIntMap | attributeSizes
attribute sizes |
| private final ObjectIntMap | attributeTypes
attribute types |
| public static final String | BINORMAL_ATTRIBUTE
default name for binormal attribute |
| public static final String | BONEWEIGHT_ATTRIBUTE
default name for boneweight attribute |
| public static final String | COLOR_ATTRIBUTE
default name for color attributes |
| private int | fragmentShaderHandle
fragment shader handle |
| private final String | fragmentShaderSource
fragment shader source |
| pack-priv static final IntBuffer | |
| private boolean | invalidated
whether this shader was invalidated |
| private boolean | isCompiled
whether this program compiled successfully |
| private String | log
the log |
| private final FloatBuffer | matrix
matrix float buffer |
| public static final String | NORMAL_ATTRIBUTE
default name for normal attributes |
| pack-priv IntBuffer | |
| public static boolean | pedantic
flag indicating whether attributes & uniforms must be present at all times |
| public static final String | POSITION_ATTRIBUTE
default name for position attributes |
| public static String | prependFragmentCode
code that is always added to every fragment shader code, typically used to inject a #version line. |
| public static String | prependVertexCode
code that is always added to the vertex shader code, typically used to inject a #version line. |
| private int | program
program handle |
| private int | refCount
reference count |
| private static final ObjectMap | shaders
the list of currently available shaders |
| public static final String | TANGENT_ATTRIBUTE
default name for tangent attribute |
| public static final String | TEXCOORD_ATTRIBUTE
default name for texcoords attributes, append texture unit number |
| pack-priv IntBuffer | |
| private String[] | uniformNames
uniform names |
| private final ObjectIntMap | uniforms
uniform lookup |
| private final ObjectIntMap | uniformSizes
uniform sizes |
| private final ObjectIntMap | uniformTypes
uniform types |
| private int | vertexShaderHandle
vertex shader handle |
| private final String | vertexShaderSource
vertex shader source |
| Access | Constructor and Description |
|---|---|
| public | ShaderProgram(String
the vertex shader vertexShader, String the fragment shader fragmentShader)Constructs a new ShaderProgram and immediately compiles it. |
| public |
| Modifier and Type | Method and Description |
|---|---|
| private void | |
| public void | |
| public void | |
| private void | |
| public static void | |
| private void | compileShaders(String vertexShader, String fragmentShader)
Loads and compiles the shaders, creates a new program and links the shaders. |
| protected int | |
| public void | disableVertexAttribute(String
the vertex attribute name name)Disables the vertex attribute with the given name |
| public void | |
| public void | dispose()
Implements com. Disposes all resources associated with this shader. |
| public void | enableVertexAttribute(String
the vertex attribute name name)Enables the vertex attribute with the given name |
| public void | |
| public void | |
| private int | |
| private void | |
| private int | |
| public int | |
| private void | |
| public int | getAttributeLocation(String
the name of the attribute name)Returns: the location of the attribute or -1. |
| public String[] | |
| public int | |
| public int | getAttributeType(String
the name of the attribute name)Returns: the type of the attribute, one of |
| public String | |
| public int | |
| public String | |
| public static String | |
| public static int | |
| public int | |
| public String[] | |
| public int | |
| public int | getUniformType(String
the name of the uniform name)Returns: the type of the uniform, one of |
| public String | |
| public boolean | hasAttribute(String
the name of the attribute name)Returns: whether the attribute is available in the shader |
| public boolean | hasUniform(String
the name of the uniform name)Returns: whether the uniform is available in the shader |
| public static void | invalidateAllShaderPrograms(Application app)
Invalidates all shaders so the next time they are used new handles are generated |
| public boolean | |
| private int | |
| private int | |
| public void | setAttributef(String
the name of the attribute name, float the first value value1, float the second value value2, float the third value value3, float the fourth value value4)Sets the given attribute |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | setUniformf(String
the name of the uniform name, float the value value)Sets the uniform with the given name. |
| public void | |
| public void | setUniformf(String
the name of the uniform name, float the first value value1, float the second value value2)Sets the uniform with the given name. |
| public void | |
| public void | setUniformf(String
the name of the uniform name, float the first value value1, float the second value value2, float the third value value3)Sets the uniform with the given name. |
| public void | |
| public void | setUniformf(String
the name of the uniform name, float the first value value1, float the second value value2, float the third value value3, float the fourth value value4)Sets the uniform with the given name. |
| public void | |
| public void | setUniformf(String
the name of the uniform name, Vector2 x and y as the first and second values respectively values)Sets the uniform with the given name. |
| public void | |
| public void | setUniformf(String
the name of the uniform name, Vector3 x, y and z as the first, second and third values respectively values)Sets the uniform with the given name. |
| public void | |
| public void | setUniformf(String
the name of the uniform name, Vector4 x, y, z, and w as the first, second, third, and fourth values respectively values)Sets the uniform with the given name. |
| public void | |
| public void | setUniformf(String
the name of the uniform name, Color r, g, b and a as the first through fourth values respectively values)Sets the uniform with the given name. |
| public void | |
| public void | setUniformi(String
the name of the uniform name, int the value value)Sets the uniform with the given name. |
| public void | |
| public void | setUniformi(String
the name of the uniform name, int the first value value1, int the second value value2)Sets the uniform with the given name. |
| public void | |
| public void | setUniformi(String
the name of the uniform name, int the first value value1, int the second value value2, int the third value value3)Sets the uniform with the given name. |
| public void | |
| public void | setUniformi(String
the name of the uniform name, int the first value value1, int the second value value2, int the third value value3, int the fourth value value4)Sets the uniform with the given name. |
| public void | |
| public void | setUniformMatrix(String
the name of the uniform name, Matrix4 the matrix matrix)Sets the uniform matrix with the given name. |
| public void | setUniformMatrix(String
the name of the uniform name, Matrix4 the matrix matrix, boolean whether the matrix should be transposed transpose)Sets the uniform matrix with the given name. |
| public void | |
| public void | |
| public void | setUniformMatrix(String
the name of the uniform name, Matrix3 the matrix matrix)Sets the uniform matrix with the given name. |
| public void | setUniformMatrix(String
the name of the uniform name, Matrix3 the matrix matrix, boolean whether the uniform matrix should be transposed transpose)Sets the uniform matrix with the given name. |
| public void | |
| public void | |
| public void | setUniformMatrix3fv(String
the name of the uniform name, FloatBuffer buffer containing the matrix data buffer, int count, boolean whether the uniform matrix should be transposed transpose)Sets an array of uniform matrices with the given name. |
| public void | setUniformMatrix4fv(String
the name of the uniform name, FloatBuffer buffer containing the matrix data buffer, int count, boolean whether the uniform matrix should be transposed transpose)Sets an array of uniform matrices with the given name. |
| public void | |
| public void | |
| public void | setVertexAttribute(String
the attribute name name, int the number of components, must be >= 1 and <= 4 size, int 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 type, boolean whether fixed point data should be normalized. Will not work on the desktop normalize, int the stride in bytes between successive attributes stride, Buffer the buffer containing the vertex attributes. buffer)Sets the vertex attribute with the given name. |
| public void | |
| public void | setVertexAttribute(String
the attribute name name, int the number of components, must be >= 1 and <= 4 size, int 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 type, boolean whether fixed point data should be normalized. Will not work on the desktop normalize, int the stride in bytes between successive attributes stride, int byte offset into the vertex buffer object bound to GL20.GL_ARRAY_BUFFER. offset)Sets the vertex attribute with the given name. |
| public void |