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(); };
disposerRecord
Modifier and Type | Method and Description |
---|---|
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.
|
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.
|
void |
setConstant(String name,
float f0)
Sets the uniform variable of the given name with the provided
float value.
|
void |
setConstant(String name,
float f0,
float f1)
Sets the uniform variable of the given name with the provided
float values.
|
void |
setConstant(String name,
float f0,
float f1,
float f2)
Sets the uniform variable of the given name with the provided
float values.
|
void |
setConstant(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(String name,
int i0)
Sets the uniform variable of the given name with the provided
integer value.
|
void |
setConstant(String name,
int i0,
int i1)
Sets the uniform variable of the given name with the provided
integer values.
|
void |
setConstant(String name,
int i0,
int i1,
int i2)
Sets the uniform variable of the given name with the provided
integer values.
|
void |
setConstant(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(String name,
FloatBuffer buf,
int off,
int count)
Sets the uniform array variable of the given name with the provided
float array values.
|
void |
setConstants(String name,
IntBuffer buf,
int off,
int count)
Sets the uniform array variable of the given name with the provided
int array values.
|
void |
setMatrix(String name,
float[] buf)
Sets the uniform matrix variable of the given name with the provided
float array values.
|
public int getProgramObject()
public int getMaxTexCoordIndex()
public boolean isPixcoordUsed()
public void enable() throws RuntimeException
enable
in interface Shader
RuntimeException
- if no OpenGL context was current or if any
OpenGL-related errors occurredpublic void disable() throws RuntimeException
disable
in interface Shader
RuntimeException
- if no OpenGL context was current or if any
OpenGL-related errors occurredpublic boolean isValid()
Shader
public void setConstant(String name, int i0) throws RuntimeException
setConstant
in interface Shader
name
- the name of the uniform variable to be seti0
- the first uniform parameterRuntimeException
- if no OpenGL context was current or if any
OpenGL-related errors occurredpublic void setConstant(String name, int i0, int i1) throws RuntimeException
setConstant
in interface Shader
name
- the name of the uniform variable to be seti0
- the first uniform parameteri1
- the second uniform parameterRuntimeException
- if no OpenGL context was current or if any
OpenGL-related errors occurredpublic void setConstant(String name, int i0, int i1, int i2) throws 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 parameterRuntimeException
- if no OpenGL context was current or if any
OpenGL-related errors occurredpublic void setConstant(String name, int i0, int i1, int i2, int i3) throws 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 parameterRuntimeException
- if no OpenGL context was current or if any
OpenGL-related errors occurredpublic void setConstant(String name, float f0) throws RuntimeException
setConstant
in interface Shader
name
- the name of the uniform variable to be setf0
- the first uniform parameterRuntimeException
- if no OpenGL context was current or if any
OpenGL-related errors occurredpublic void setConstant(String name, float f0, float f1) throws RuntimeException
setConstant
in interface Shader
name
- the name of the uniform variable to be setf0
- the first uniform parameterf1
- the second uniform parameterRuntimeException
- if no OpenGL context was current or if any
OpenGL-related errors occurredpublic void setConstant(String name, float f0, float f1, float f2) throws 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 parameterRuntimeException
- if no OpenGL context was current or if any
OpenGL-related errors occurredpublic void setConstant(String name, float f0, float f1, float f2, float f3) throws 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 parameterRuntimeException
- if no OpenGL context was current or if any
OpenGL-related errors occurredpublic void setConstants(String name, IntBuffer buf, int off, int count) throws 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 arrayRuntimeException
- if no OpenGL context was current or if any
OpenGL-related errors occurredpublic void setConstants(String name, FloatBuffer buf, int off, int count) throws 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 arrayRuntimeException
- if no OpenGL context was current or if any
OpenGL-related errors occurredpublic void setMatrix(String name, float[] buf) throws RuntimeException
name
- the name of the uniform variable to be setbuf
- the matrix values to be setRuntimeException
- if no OpenGL context was current or if any
OpenGL-related errors occurredpublic void dispose() throws RuntimeException
dispose
in interface GraphicsResource
dispose
in class BaseGraphicsResource
RuntimeException
- if no OpenGL context was current or if any
OpenGL-related errors occurredCopyright © 2020. All rights reserved.