Package gaiasky.util.gdx.shader
Class ExtShaderProgram
java.lang.Object
gaiasky.util.gdx.shader.ExtShaderProgram
- All Implemented Interfaces:
com.badlogic.gdx.utils.Disposable
- Direct Known Subclasses:
TessellationShaderProgram
-
Field Summary
Modifier and TypeFieldDescriptionprotected String[]
Attribute names.protected com.badlogic.gdx.utils.ObjectIntMap
<String> Attribute lookup.protected com.badlogic.gdx.utils.ObjectIntMap
<String> Attribute sizes.protected com.badlogic.gdx.utils.ObjectIntMap
<String> Attribute types.protected ByteBuffer
Byte buffer to get binary shaders.static final String
Default name for color attributes.protected IntBuffer
Int for shader binary format.protected String
protected int
Fragment shader handle.protected String
Fragment shader source.protected String
protected String
Geometry shader source.protected IntBuffer
Aux integer buffer.protected boolean
Whether this shader was invalidated.protected boolean
Whether this program compiled successfully.protected boolean
Whether this program has been disposed.protected boolean
Whether lazy loading is activated for this shader.protected IntBuffer
Int for shader length.protected String
The log.protected String
The shader name, if any.static final String
Default name for normal attribute.protected IntBuffer
Int buffer for parameters.static boolean
Flag indicating whether attributes & uniforms must be present at all times.static final String
Default name for position attributes.static String
Code that is always added to every fragment shader code, typically used to inject a #version line.static String
Code that is always added to the geometry shader code, typically used to inject a #version line.static String
Code that is always added to the vertex shader code, typically used to inject a #version line.protected int
Program handle.static final String
Default name for texture coordinates attributes, append texture unit number.protected IntBuffer
Int buffer for types.protected String[]
Uniform names.protected com.badlogic.gdx.utils.ObjectIntMap
<String> Uniform lookup.protected com.badlogic.gdx.utils.ObjectIntMap
<String> Uniform sizes.protected com.badlogic.gdx.utils.ObjectIntMap
<String> Uniform types.protected String
protected int
Vertex shader handle.protected String
Vertex shader source. -
Constructor Summary
ConstructorDescriptionExtShaderProgram
(com.badlogic.gdx.files.FileHandle vertexShader, com.badlogic.gdx.files.FileHandle fragmentShader) ExtShaderProgram
(String name, com.badlogic.gdx.files.FileHandle vertexShader, com.badlogic.gdx.files.FileHandle fragmentShader) ExtShaderProgram
(String vertexShader, String fragmentShader) Constructs a new ShaderProgram and immediately compiles it.ExtShaderProgram
(String vertexFile, String fragmentFile, String vertexShaderCode, String fragmentShaderCode) ExtShaderProgram
(String name, String vertexFile, String fragmentFile, String vertexShaderCode, String fragmentShaderCode) ExtShaderProgram
(String name, String vertexFile, String fragmentFile, String vertexShaderCode, String fragmentShaderCode, boolean lazyLoading) Constructs a new ShaderProgram and immediately compiles it.ExtShaderProgram
(String vertexFile, String geometryFile, String fragmentFile, String vertexShaderCode, String geometryShaderCode, String fragmentShaderCode) ExtShaderProgram
(String name, String vertexFile, String geometryFile, String fragmentFile, String vertexShaderCode, String geometryShaderCode, String fragmentShaderCode) ExtShaderProgram
(String name, String vertexFile, String geometryFile, String fragmentFile, String vertexShaderCode, String geometryShaderCode, String fragmentShaderCode, boolean lazyLoading) Constructs a new shader program and immediately compiles it, if it is not lazy. -
Method Summary
Modifier and TypeMethodDescriptionvoid
begin()
Makes OpenGL ES 2.0 use this vertex and fragment shader pair.static void
clearAllShaderPrograms
(com.badlogic.gdx.Application app) void
void
disableVertexAttribute
(int location) void
disableVertexAttribute
(String name) Disables the vertex attribute with the given namevoid
dispose()
Disposes all resources associated with this shader.void
enableVertexAttribute
(int location) void
enableVertexAttribute
(String name) Enables the vertex attribute with the given namevoid
end()
Disables this shader.protected int
fetchAttributeLocation
(String name) protected void
protected int
fetchUniformLocation
(String name) int
fetchUniformLocation
(String name, boolean pedantic) protected void
int
getAttributeLocation
(String name) String[]
int
getAttributeSize
(String name) int
getAttributeType
(String name) getLog()
static String
getName()
static int
int
getUniformLocation
(String name) String[]
int
getUniformSize
(String name) int
getUniformType
(String name) boolean
hasAttribute
(String name) boolean
hasUniform
(String name) protected void
static void
invalidateAllShaderPrograms
(com.badlogic.gdx.Application app) Invalidates all shaders so the next time they are used new handles are generatedboolean
boolean
isLazy()
void
setAttributef
(String name, float value1, float value2, float value3, float value4) Sets the given attributevoid
setUniform1fv
(int location, float[] values, int offset, int length) void
setUniform1fv
(String name, float[] values, int offset, int length) void
setUniform2fv
(int location, float[] values, int offset, int length) void
setUniform2fv
(String name, float[] values, int offset, int length) void
setUniform3fv
(int location, float[] values, int offset, int length) void
setUniform3fv
(String name, float[] values, int offset, int length) void
setUniform4fv
(int location, float[] values, int offset, int length) void
setUniform4fv
(String name, float[] values, int offset, int length) void
setUniformf
(int location, float value) void
setUniformf
(int location, float value1, float value2) void
setUniformf
(int location, float value1, float value2, float value3) void
setUniformf
(int location, float value1, float value2, float value3, float value4) void
setUniformf
(int location, com.badlogic.gdx.graphics.Color values) void
setUniformf
(int location, com.badlogic.gdx.math.Vector2 values) void
setUniformf
(int location, com.badlogic.gdx.math.Vector3 values) void
setUniformf
(String name, float value) Sets the uniform with the given name.void
setUniformf
(String name, float value1, float value2) Sets the uniform with the given name.void
setUniformf
(String name, float value1, float value2, float value3) Sets the uniform with the given name.void
setUniformf
(String name, float value1, float value2, float value3, float value4) Sets the uniform with the given name.void
setUniformf
(String name, com.badlogic.gdx.graphics.Color values) Sets the uniform with the given name.void
setUniformf
(String name, com.badlogic.gdx.math.Vector2 values) Sets the uniform with the given name.void
setUniformf
(String name, com.badlogic.gdx.math.Vector3 values) Sets the uniform with the given name.void
setUniformi
(int location, int value) void
setUniformi
(int location, int value1, int value2) void
setUniformi
(int location, int value1, int value2, int value3) void
setUniformi
(int location, int value1, int value2, int value3, int value4) void
setUniformi
(String name, int value) Sets the uniform with the given name.void
setUniformi
(String name, int value1, int value2) Sets the uniform with the given name.void
setUniformi
(String name, int value1, int value2, int value3) Sets the uniform with the given name.void
setUniformi
(String name, int value1, int value2, int value3, int value4) Sets the uniform with the given name.void
setUniformMatrix
(int location, com.badlogic.gdx.math.Matrix3 matrix) void
setUniformMatrix
(int location, com.badlogic.gdx.math.Matrix3 matrix, boolean transpose) void
setUniformMatrix
(int location, com.badlogic.gdx.math.Matrix4 matrix) void
setUniformMatrix
(int location, com.badlogic.gdx.math.Matrix4 matrix, boolean transpose) void
setUniformMatrix
(String name, com.badlogic.gdx.math.Matrix3 matrix) Sets the uniform matrix with the given name.void
setUniformMatrix
(String name, com.badlogic.gdx.math.Matrix3 matrix, boolean transpose) Sets the uniform matrix with the given name.void
setUniformMatrix
(String name, com.badlogic.gdx.math.Matrix4 matrix) Sets the uniform matrix with the given name.void
setUniformMatrix
(String name, com.badlogic.gdx.math.Matrix4 matrix, boolean transpose) Sets the uniform matrix with the given name.void
setUniformMatrix3fv
(String name, FloatBuffer buffer, int count, boolean transpose) Sets an array of uniform matrices with the given name.void
setUniformMatrix4fv
(int location, float[] values, int offset, int length) void
setUniformMatrix4fv
(String name, float[] values, int offset, int length) void
setUniformMatrix4fv
(String name, FloatBuffer buffer, int count, boolean transpose) Sets an array of uniform matrices with the given name.void
setVertexAttribute
(int location, int size, int type, boolean normalize, int stride, int offset) void
setVertexAttribute
(int location, int size, int type, boolean normalize, int stride, Buffer buffer) void
setVertexAttribute
(String name, int size, int type, boolean normalize, int stride, int offset) Sets the vertex attribute with the given name.void
setVertexAttribute
(String name, int size, int type, boolean normalize, int stride, Buffer buffer) Sets the vertex attribute with the given name.static void
writeShader
(String name, String code) void
-
Field Details
-
POSITION_ATTRIBUTE
Default name for position attributes.- See Also:
-
COLOR_ATTRIBUTE
Default name for color attributes.- See Also:
-
NORMAL_ATTRIBUTE
Default name for normal attribute.- See Also:
-
TEXCOORD_ATTRIBUTE
Default name for texture coordinates attributes, append texture unit number.- See Also:
-
pedantic
public static boolean pedanticFlag indicating whether attributes & uniforms must be present at all times. -
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
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
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
Int buffer for parameters. -
type
Int buffer for types. -
len
Int for shader length. -
format
Int for shader binary format. -
intBuffer
Aux integer buffer. -
byteBuffer
Byte buffer to get binary shaders. -
log
The log. -
name
The shader name, if any. -
isCompiled
protected boolean isCompiledWhether this program compiled successfully. -
isLazy
protected boolean isLazyWhether lazy loading is activated for this shader. -
isDisposed
protected boolean isDisposedWhether this program has been disposed. -
uniforms
Uniform lookup. -
uniformTypes
Uniform types. -
uniformSizes
Uniform sizes. -
uniformNames
Uniform names. -
attributes
Attribute lookup. -
attributeTypes
Attribute types. -
attributeSizes
Attribute sizes. -
attributeNames
Attribute names. -
program
protected int programProgram handle. -
vertexShaderHandle
protected int vertexShaderHandleVertex shader handle. -
fragmentShaderHandle
protected int fragmentShaderHandleFragment shader handle. -
vertexShaderSource
Vertex shader source. -
geometryShaderSource
Geometry shader source. -
fragmentShaderSource
Fragment shader source. -
vertexShaderFile
-
geometryShaderFile
-
fragmentShaderFile
-
invalidated
protected boolean invalidatedWhether this shader was invalidated.
-
-
Constructor Details
-
ExtShaderProgram
public ExtShaderProgram() -
ExtShaderProgram
-
ExtShaderProgram
-
ExtShaderProgram
-
ExtShaderProgram
-
ExtShaderProgram
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
public ExtShaderProgram(String name, String vertexFile, String geometryFile, String fragmentFile, String vertexShaderCode, String geometryShaderCode, String fragmentShaderCode, boolean lazyLoading) Constructs a new shader program and immediately compiles it, if it is not lazy.- 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
Constructs a new ShaderProgram and immediately compiles it.- Parameters:
vertexShader
- The vertex shader code.fragmentShader
- The fragment shader code.
-
ExtShaderProgram
public ExtShaderProgram(com.badlogic.gdx.files.FileHandle vertexShader, com.badlogic.gdx.files.FileHandle fragmentShader) -
ExtShaderProgram
public ExtShaderProgram(String name, com.badlogic.gdx.files.FileHandle vertexShader, com.badlogic.gdx.files.FileHandle fragmentShader)
-
-
Method Details
-
invalidateAllShaderPrograms
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
public static void clearAllShaderPrograms(com.badlogic.gdx.Application app) -
getManagedStatus
-
getNumManagedShaderPrograms
public static int getNumManagedShaderPrograms()- Returns:
- the number of managed shader programs currently loaded
-
initializeLocalAssets
protected void initializeLocalAssets() -
getName
-
compile
-
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
public boolean isCompiled()- Returns:
- whether this program compiled successfully.
-
isLazy
public boolean isLazy()- Returns:
- whether this program has lazy loading activated.
-
fetchAttributeLocation
-
fetchUniformLocation
-
fetchUniformLocation
-
setUniformi
Sets the uniform with the given name. TheExtShaderProgram
must be bound for this to work.- Parameters:
name
- the name of the uniformvalue
- the value
-
setUniformi
public void setUniformi(int location, int value) -
setUniformi
Sets the uniform with the given name. TheExtShaderProgram
must be bound for this to work.- Parameters:
name
- the name of the uniformvalue1
- the first valuevalue2
- the second value
-
setUniformi
public void setUniformi(int location, int value1, int value2) -
setUniformi
Sets the uniform with the given name. TheExtShaderProgram
must be bound for this to work.- Parameters:
name
- the name of the uniformvalue1
- the first valuevalue2
- the second valuevalue3
- the third value
-
setUniformi
public void setUniformi(int location, int value1, int value2, int value3) -
setUniformi
Sets the uniform with the given name. TheExtShaderProgram
must be bound for this to work.- Parameters:
name
- the name of the uniformvalue1
- the first valuevalue2
- the second valuevalue3
- the third valuevalue4
- the fourth value
-
setUniformi
public void setUniformi(int location, int value1, int value2, int value3, int value4) -
setUniformf
Sets the uniform with the given name. TheExtShaderProgram
must be bound for this to work.- Parameters:
name
- the name of the uniformvalue
- the value
-
setUniformf
public void setUniformf(int location, float value) -
setUniformf
Sets the uniform with the given name. TheExtShaderProgram
must be bound for this to work.- Parameters:
name
- the name of the uniformvalue1
- the first valuevalue2
- the second value
-
setUniformf
public void setUniformf(int location, float value1, float value2) -
setUniformf
Sets the uniform with the given name. TheExtShaderProgram
must be bound for this to work.- Parameters:
name
- the name of the uniformvalue1
- the first valuevalue2
- the second valuevalue3
- the third value
-
setUniformf
public void setUniformf(int location, float value1, float value2, float value3) -
setUniformf
Sets the uniform with the given name. TheExtShaderProgram
must be bound for this to work.- Parameters:
name
- the name of the uniformvalue1
- the first valuevalue2
- the second valuevalue3
- the third valuevalue4
- the fourth value
-
setUniformf
public void setUniformf(int location, float value1, float value2, float value3, float value4) -
setUniform1fv
-
setUniform1fv
public void setUniform1fv(int location, float[] values, int offset, int length) -
setUniform2fv
-
setUniform2fv
public void setUniform2fv(int location, float[] values, int offset, int length) -
setUniform3fv
-
setUniform3fv
public void setUniform3fv(int location, float[] values, int offset, int length) -
setUniform4fv
-
setUniform4fv
public void setUniform4fv(int location, float[] values, int offset, int length) -
setUniformMatrix
Sets the uniform matrix with the given name. TheExtShaderProgram
must be bound for this to work.- Parameters:
name
- the name of the uniformmatrix
- the matrix
-
setUniformMatrix
Sets the uniform matrix with the given name. TheExtShaderProgram
must be bound for this to work.- Parameters:
name
- the name of the uniformmatrix
- the matrixtranspose
- whether the matrix should be transposed
-
setUniformMatrix
public void setUniformMatrix(int location, com.badlogic.gdx.math.Matrix4 matrix) -
setUniformMatrix
public void setUniformMatrix(int location, com.badlogic.gdx.math.Matrix4 matrix, boolean transpose) -
setUniformMatrix
Sets the uniform matrix with the given name. TheExtShaderProgram
must be bound for this to work.- Parameters:
name
- the name of the uniformmatrix
- the matrix
-
setUniformMatrix
Sets the uniform matrix with the given name. TheExtShaderProgram
must be bound for this to work.- Parameters:
name
- the name of the uniformmatrix
- the matrixtranspose
- whether the uniform matrix should be transposed
-
setUniformMatrix
public void setUniformMatrix(int location, com.badlogic.gdx.math.Matrix3 matrix) -
setUniformMatrix
public void setUniformMatrix(int location, com.badlogic.gdx.math.Matrix3 matrix, boolean transpose) -
setUniformMatrix3fv
Sets an array of uniform matrices with the given name. TheExtShaderProgram
must be bound for this to work.- Parameters:
name
- the name of the uniformbuffer
- buffer containing the matrix datatranspose
- whether the uniform matrix should be transposed
-
setUniformMatrix4fv
Sets an array of uniform matrices with the given name. TheExtShaderProgram
must be bound for this to work.- Parameters:
name
- the name of the uniformbuffer
- buffer containing the matrix datatranspose
- whether the uniform matrix should be transposed
-
setUniformMatrix4fv
public void setUniformMatrix4fv(int location, float[] values, int offset, int length) -
setUniformMatrix4fv
-
setUniformf
Sets the uniform with the given name. TheExtShaderProgram
must be bound for this to work.- Parameters:
name
- the name of the uniformvalues
- x and y as the first and second values respectively
-
setUniformf
public void setUniformf(int location, com.badlogic.gdx.math.Vector2 values) -
setUniformf
Sets the uniform with the given name. TheExtShaderProgram
must be bound for this to work.- Parameters:
name
- the name of the uniformvalues
- x, y and z as the first, second and third values respectively
-
setUniformf
public void setUniformf(int location, com.badlogic.gdx.math.Vector3 values) -
setUniformf
Sets the uniform with the given name. TheExtShaderProgram
must be bound for this to work.- Parameters:
name
- the name of the uniformvalues
- r, g, b and a as the first through fourth values respectively
-
setUniformf
public void setUniformf(int location, com.badlogic.gdx.graphics.Color values) -
setVertexAttribute
public void setVertexAttribute(String name, int size, int type, boolean normalize, int stride, Buffer buffer) Sets the vertex attribute with the given name. TheExtShaderProgram
must be bound for this to work.- Parameters:
name
- the attribute namesize
- the number of components, must be ≥ 1 and ≤ 4type
- 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 desktopnormalize
- whether fixed point data should be normalized. Will not work on the desktopstride
- the stride in bytes between successive attributesbuffer
- the buffer containing the vertex attributes.
-
setVertexAttribute
public void setVertexAttribute(int location, int size, int type, boolean normalize, int stride, Buffer buffer) -
setVertexAttribute
public void setVertexAttribute(String name, int size, int type, boolean normalize, int stride, int offset) Sets the vertex attribute with the given name. TheExtShaderProgram
must be bound for this to work.- Parameters:
name
- the attribute namesize
- the number of components, must be ≥ 1 and ≤ 4type
- 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 desktopnormalize
- whether fixed point data should be normalized. Will not work on the desktopstride
- the stride in bytes between successive attributesoffset
- byte offset into the vertex buffer object bound to GL20.GL_ARRAY_BUFFER.
-
setVertexAttribute
public void setVertexAttribute(int location, int size, int type, boolean normalize, int stride, int offset) -
begin
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 callend()
. -
end
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
Disables the vertex attribute with the given name- Parameters:
name
- the vertex attribute name
-
disableVertexAttribute
public void disableVertexAttribute(int location) -
enableVertexAttribute
Enables the vertex attribute with the given name- Parameters:
name
- the vertex attribute name
-
enableVertexAttribute
public void enableVertexAttribute(int location) -
setAttributef
Sets the given attribute- Parameters:
name
- the name of the attributevalue1
- the first valuevalue2
- the second valuevalue3
- the third valuevalue4
- the fourth value
-
fetchUniforms
protected void fetchUniforms() -
fetchAttributes
protected void fetchAttributes() -
hasAttribute
- Parameters:
name
- the name of the attribute- Returns:
- whether the attribute is available in the shader
-
getAttributeType
- Parameters:
name
- the name of the attribute- Returns:
- the type of the attribute, one of
GL20.GL_FLOAT
,GL20.GL_FLOAT_VEC2
etc.
-
getAttributeLocation
- Parameters:
name
- the name of the attribute- Returns:
- the location of the attribute or -1.
-
getAttributeSize
- Parameters:
name
- the name of the attribute- Returns:
- the size of the attribute or 0.
-
hasUniform
- Parameters:
name
- the name of the uniform- Returns:
- whether the uniform is available in the shader
-
getUniformType
- Parameters:
name
- the name of the uniform- Returns:
- the type of the uniform, one of
GL20.GL_FLOAT
,GL20.GL_FLOAT_VEC2
etc.
-
getUniformLocation
- Parameters:
name
- the name of the uniform- Returns:
- the location of the uniform or -1.
-
getUniformSize
- Parameters:
name
- the name of the uniform- Returns:
- the size of the uniform or 0.
-
getAttributes
- Returns:
- the attributes
-
getUniforms
- Returns:
- the uniforms
-
getVertexShaderSource
- Returns:
- the source of the vertex shader
-
getVertexShaderFileName
-
getGeometryShaderSource
- Returns:
- the source of the vertex shader
-
getGeometryShaderFileName
-
getFragmentShaderSource
- Returns:
- the source of the fragment shader
-
getFragmentShaderFileName
-
dispose
public void dispose()Disposes all resources associated with this shader. Must be called when the shader is no longer used.- Specified by:
dispose
in interfacecom.badlogic.gdx.utils.Disposable
-
writeShaders
public void writeShaders() -
writeShader
-