public class ES2Shader extends BaseGraphicsResource implements Shader
Usage example:
String source = "uniform sampler2D myTex;" + "void main(void)" + "{" + " vec4 src = texture2D(myTex, gl_TexCoord[0].st);" + " gl_FragColor = src.bgra;" + // swizzle! "}"; ES2Shader shader = new ES2Shader(source); shader.setConstant("myTex", 0); // myTex will be on texture unit 0 ... shader.enable(); texture.enable(); texture.bind(); ... texture.disable(); shader.disable(); };
Modifier and Type | Class and Description |
---|---|
private static class |
ES2Shader.ES2ShaderDisposerRecord |
private static class |
ES2Shader.Uniform |
Modifier and Type | Field and Description |
---|---|
private ES2Context |
context |
private float[] |
currentMatrix |
private boolean |
isPixcoordUsed |
private int |
maxTexCoordIndex |
private int |
programID
The handle to the OpenGL shader program object.
|
private java.util.Map<java.lang.String,ES2Shader.Uniform> |
uniforms |
private boolean |
valid |
disposerRecord
Modifier | Constructor and Description |
---|---|
private |
ES2Shader(ES2Context context,
int programID,
int vertexShaderID,
int[] fragmentShaderID,
java.util.Map<java.lang.String,java.lang.Integer> samplers,
int maxTexCoordIndex,
boolean isPixcoordUsed) |
Modifier and Type | Method and Description |
---|---|
(package private) static ES2Shader |
createFromSource(ES2Context context,
java.lang.String vert,
java.io.InputStream frag,
java.util.Map<java.lang.String,java.lang.Integer> samplers,
java.util.Map<java.lang.String,java.lang.Integer> attributes,
int maxTexCoordIndex,
boolean isPixcoordUsed) |
(package private) static ES2Shader |
createFromSource(ES2Context context,
java.lang.String vert,
java.lang.String[] frag,
java.util.Map<java.lang.String,java.lang.Integer> samplers,
java.util.Map<java.lang.String,java.lang.Integer> attributes,
int maxTexCoordIndex,
boolean isPixcoordUsed) |
void |
disable()
Disables this shader program in the current GL context's state.
|
void |
dispose()
Disposes the native resources used by this program object.
|
void |
enable()
Enables this shader program in the current GL context's state.
|
int |
getMaxTexCoordIndex()
Returns the maximum texcoord index referenced by this shader program.
|
int |
getProgramObject()
Returns the underlying OpenGL program object handle for this fragment
shader.
|
private ES2Shader.Uniform |
getUniform(java.lang.String name) |
boolean |
isPixcoordUsed()
Returns true if this shader uses the special pixcoord variable,
otherwise returns false
|
boolean |
isValid()
Returns whether this shader is valid and can be used for rendering.
|
(package private) static java.lang.String |
readStreamIntoString(java.io.InputStream in) |
void |
setConstant(java.lang.String name,
float f0)
Sets the uniform variable of the given name with the provided
float value.
|
void |
setConstant(java.lang.String name,
float f0,
float f1)
Sets the uniform variable of the given name with the provided
float values.
|
void |
setConstant(java.lang.String name,
float f0,
float f1,
float f2)
Sets the uniform variable of the given name with the provided
float values.
|
void |
setConstant(java.lang.String name,
float f0,
float f1,
float f2,
float f3)
Sets the uniform variable of the given name with the provided
float values.
|
void |
setConstant(java.lang.String name,
int i0)
Sets the uniform variable of the given name with the provided
integer value.
|
void |
setConstant(java.lang.String name,
int i0,
int i1)
Sets the uniform variable of the given name with the provided
integer values.
|
void |
setConstant(java.lang.String name,
int i0,
int i1,
int i2)
Sets the uniform variable of the given name with the provided
integer values.
|
void |
setConstant(java.lang.String name,
int i0,
int i1,
int i2,
int i3)
Sets the uniform variable of the given name with the provided
integer values.
|
void |
setConstants(java.lang.String name,
java.nio.FloatBuffer buf,
int off,
int count)
Sets the uniform array variable of the given name with the provided
float array values.
|
void |
setConstants(java.lang.String name,
java.nio.IntBuffer buf,
int off,
int count)
Sets the uniform array variable of the given name with the provided
int array values.
|
void |
setMatrix(java.lang.String name,
float[] buf)
Sets the uniform matrix variable of the given name with the provided
float array values.
|
private int programID
private final ES2Context context
private final java.util.Map<java.lang.String,ES2Shader.Uniform> uniforms
private final int maxTexCoordIndex
private final boolean isPixcoordUsed
private boolean valid
private float[] currentMatrix
private ES2Shader(ES2Context context, int programID, int vertexShaderID, int[] fragmentShaderID, java.util.Map<java.lang.String,java.lang.Integer> samplers, int maxTexCoordIndex, boolean isPixcoordUsed) throws java.lang.RuntimeException
java.lang.RuntimeException
static ES2Shader createFromSource(ES2Context context, java.lang.String vert, java.lang.String[] frag, java.util.Map<java.lang.String,java.lang.Integer> samplers, java.util.Map<java.lang.String,java.lang.Integer> attributes, int maxTexCoordIndex, boolean isPixcoordUsed)
static ES2Shader createFromSource(ES2Context context, java.lang.String vert, java.io.InputStream frag, java.util.Map<java.lang.String,java.lang.Integer> samplers, java.util.Map<java.lang.String,java.lang.Integer> attributes, int maxTexCoordIndex, boolean isPixcoordUsed)
static java.lang.String readStreamIntoString(java.io.InputStream in)
public int getProgramObject()
public int getMaxTexCoordIndex()
public boolean isPixcoordUsed()
private ES2Shader.Uniform getUniform(java.lang.String name)
public void enable() throws java.lang.RuntimeException
public void disable() throws java.lang.RuntimeException
public boolean isValid()
Shader
public void setConstant(java.lang.String name, int i0) throws java.lang.RuntimeException
setConstant
in interface Shader
name
- the name of the uniform variable to be seti0
- the first uniform parameterjava.lang.RuntimeException
- if no OpenGL context was current or if any
OpenGL-related errors occurredpublic void setConstant(java.lang.String name, int i0, int i1) throws java.lang.RuntimeException
setConstant
in interface Shader
name
- the name of the uniform variable to be seti0
- the first uniform parameteri1
- the second uniform parameterjava.lang.RuntimeException
- if no OpenGL context was current or if any
OpenGL-related errors occurredpublic void setConstant(java.lang.String name, int i0, int i1, int i2) throws java.lang.RuntimeException
setConstant
in interface Shader
name
- the name of the uniform variable to be seti0
- the first uniform parameteri1
- the second uniform parameteri2
- the third uniform parameterjava.lang.RuntimeException
- if no OpenGL context was current or if any
OpenGL-related errors occurredpublic void setConstant(java.lang.String name, int i0, int i1, int i2, int i3) throws java.lang.RuntimeException
setConstant
in interface Shader
name
- the name of the uniform variable to be seti0
- the first uniform parameteri1
- the second uniform parameteri2
- the third uniform parameteri3
- the fourth uniform parameterjava.lang.RuntimeException
- if no OpenGL context was current or if any
OpenGL-related errors occurredpublic void setConstant(java.lang.String name, float f0) throws java.lang.RuntimeException
setConstant
in interface Shader
name
- the name of the uniform variable to be setf0
- the first uniform parameterjava.lang.RuntimeException
- if no OpenGL context was current or if any
OpenGL-related errors occurredpublic void setConstant(java.lang.String name, float f0, float f1) throws java.lang.RuntimeException
setConstant
in interface Shader
name
- the name of the uniform variable to be setf0
- the first uniform parameterf1
- the second uniform parameterjava.lang.RuntimeException
- if no OpenGL context was current or if any
OpenGL-related errors occurredpublic void setConstant(java.lang.String name, float f0, float f1, float f2) throws java.lang.RuntimeException
setConstant
in interface Shader
name
- the name of the uniform variable to be setf0
- the first uniform parameterf1
- the second uniform parameterf2
- the third uniform parameterjava.lang.RuntimeException
- if no OpenGL context was current or if any
OpenGL-related errors occurredpublic void setConstant(java.lang.String name, float f0, float f1, float f2, float f3) throws java.lang.RuntimeException
setConstant
in interface Shader
name
- the name of the uniform variable to be setf0
- the first uniform parameterf1
- the second uniform parameterf2
- the third uniform parameterf3
- the fourth uniform parameterjava.lang.RuntimeException
- if no OpenGL context was current or if any
OpenGL-related errors occurredpublic void setConstants(java.lang.String name, java.nio.IntBuffer buf, int off, int count) throws java.lang.RuntimeException
setConstants
in interface Shader
name
- the name of the uniform variable to be setbuf
- the array values to be setoff
- the offset into the vals arraycount
- the number of ivec4 elements in the arrayjava.lang.RuntimeException
- if no OpenGL context was current or if any
OpenGL-related errors occurredpublic void setConstants(java.lang.String name, java.nio.FloatBuffer buf, int off, int count) throws java.lang.RuntimeException
setConstants
in interface Shader
name
- the name of the uniform variable to be setbuf
- the array values to be setcount
- the number of vec4 elements in the arrayoff
- the offset into the vals arrayjava.lang.RuntimeException
- if no OpenGL context was current or if any
OpenGL-related errors occurredpublic void setMatrix(java.lang.String name, float[] buf) throws java.lang.RuntimeException
name
- the name of the uniform variable to be setbuf
- the matrix values to be setjava.lang.RuntimeException
- if no OpenGL context was current or if any
OpenGL-related errors occurredpublic void dispose() throws java.lang.RuntimeException
dispose
in interface GraphicsResource
dispose
in class BaseGraphicsResource
java.lang.RuntimeException
- if no OpenGL context was current or if any
OpenGL-related errors occurred