|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.java.joglutils.msg.misc.Shader
public class Shader
Represents an OpenGL shader program object, which can be constructed from the source code for a vertex shader, a fragment shader, or both. Contains convenience methods for enabling/disabling shader state.
Usage example:
String source = "uniform sampler2D myTex;" + "void main(void)" + "{" + " vec4 src = texture2D(myTex, gl_TexCoord[0].st);" + " gl_FragColor = src.bgra;" + // swizzle! "}"; Shader shader = new Shader(source); shader.setUniform("myTex", 0); // myTex will be on texture unit 0 ... shader.enable(); texture.enable(); texture.bind(); ... texture.disable(); shader.disable(); };
Constructor Summary | |
---|---|
Shader(String fragmentCode)
Creates a new shader program object and compiles/links the provided fragment shader code into that object. |
|
Shader(String vertexCode,
String fragmentCode)
Creates a new shader program object and compiles/links the provided vertex shader and fragment shader code into that object. |
Method Summary | |
---|---|
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 |
getProgramObject()
Returns the underlying OpenGL program object handle for this fragment shader. |
void |
setUniform(String name,
float f0)
Sets the uniform variable of the given name with the provided float value. |
void |
setUniform(String name,
float f0,
float f1)
Sets the uniform variable of the given name with the provided float values. |
void |
setUniform(String name,
float f0,
float f1,
float f2)
Sets the uniform variable of the given name with the provided float values. |
void |
setUniform(String name,
float f0,
float f1,
float f2,
float f3)
Sets the uniform variable of the given name with the provided float values. |
void |
setUniform(String name,
int i0)
Sets the uniform variable of the given name with the provided integer value. |
void |
setUniform(String name,
int i0,
int i1)
Sets the uniform variable of the given name with the provided integer values. |
void |
setUniform(String name,
int i0,
int i1,
int i2)
Sets the uniform variable of the given name with the provided integer values. |
void |
setUniform(String name,
int i0,
int i1,
int i2,
int i3)
Sets the uniform variable of the given name with the provided integer values. |
void |
setUniformArray1f(String name,
int count,
float[] vals,
int off)
Sets the uniform array variable of the given name with the provided float array values. |
void |
setUniformArray1i(String name,
int count,
int[] vals,
int off)
Sets the uniform array variable of the given name with the provided int array values. |
void |
setUniformArray2f(String name,
int count,
float[] vals,
int off)
Sets the uniform array variable of the given name with the provided float array values. |
void |
setUniformArray2i(String name,
int count,
int[] vals,
int off)
Sets the uniform array variable of the given name with the provided int array values. |
void |
setUniformArray3f(String name,
int count,
float[] vals,
int off)
Sets the uniform array variable of the given name with the provided float array values. |
void |
setUniformArray3i(String name,
int count,
int[] vals,
int off)
Sets the uniform array variable of the given name with the provided int array values. |
void |
setUniformArray4f(String name,
int count,
float[] vals,
int off)
Sets the uniform array variable of the given name with the provided float array values. |
void |
setUniformArray4i(String name,
int count,
int[] vals,
int off)
Sets the uniform array variable of the given name with the provided int array values. |
void |
setUniformMatrices2f(String name,
int count,
boolean transpose,
float[] vals,
int off)
Sets the uniform matrix (or matrix array) variable of the given name with the provided matrix values. |
void |
setUniformMatrices3f(String name,
int count,
boolean transpose,
float[] vals,
int off)
Sets the uniform matrix (or matrix array) variable of the given name with the provided matrix values. |
void |
setUniformMatrices4f(String name,
int count,
boolean transpose,
float[] vals,
int off)
Sets the uniform matrix (or matrix array) variable of the given name with the provided matrix values. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Shader(String fragmentCode) throws javax.media.opengl.GLException
fragmentCode
- a String
representing the fragment shader
source code to be compiled and linked
javax.media.opengl.GLException
- if no OpenGL context was current or if any
OpenGL-related errors occurredpublic Shader(String vertexCode, String fragmentCode) throws javax.media.opengl.GLException
vertexCode
- a String
representing the vertex shader
source code to be compiled and linked; this may be null if only a
fragment shader is going to be neededfragmentCode
- a String
representing the fragment shader
source code to be compiled and linked; this may be null if only a
vertex shader is going to be needed
javax.media.opengl.GLException
- if no OpenGL context was current or if any
OpenGL-related errors occurredMethod Detail |
---|
public int getProgramObject()
public void enable() throws javax.media.opengl.GLException
javax.media.opengl.GLException
- if no OpenGL context was current or if any
OpenGL-related errors occurredpublic void disable() throws javax.media.opengl.GLException
javax.media.opengl.GLException
- if no OpenGL context was current or if any
OpenGL-related errors occurredpublic void dispose() throws javax.media.opengl.GLException
javax.media.opengl.GLException
- if no OpenGL context was current or if any
OpenGL-related errors occurredpublic void setUniform(String name, int i0) throws javax.media.opengl.GLException
name
- the name of the uniform variable to be seti0
- the first uniform parameter
javax.media.opengl.GLException
- if no OpenGL context was current or if any
OpenGL-related errors occurredpublic void setUniform(String name, int i0, int i1) throws javax.media.opengl.GLException
name
- the name of the uniform variable to be seti0
- the first uniform parameteri1
- the second uniform parameter
javax.media.opengl.GLException
- if no OpenGL context was current or if any
OpenGL-related errors occurredpublic void setUniform(String name, int i0, int i1, int i2) throws javax.media.opengl.GLException
name
- the name of the uniform variable to be seti0
- the first uniform parameteri1
- the second uniform parameteri2
- the third uniform parameter
javax.media.opengl.GLException
- if no OpenGL context was current or if any
OpenGL-related errors occurredpublic void setUniform(String name, int i0, int i1, int i2, int i3) throws javax.media.opengl.GLException
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 parameter
javax.media.opengl.GLException
- if no OpenGL context was current or if any
OpenGL-related errors occurredpublic void setUniform(String name, float f0) throws javax.media.opengl.GLException
name
- the name of the uniform variable to be setf0
- the first uniform parameter
javax.media.opengl.GLException
- if no OpenGL context was current or if any
OpenGL-related errors occurredpublic void setUniform(String name, float f0, float f1) throws javax.media.opengl.GLException
name
- the name of the uniform variable to be setf0
- the first uniform parameterf1
- the second uniform parameter
javax.media.opengl.GLException
- if no OpenGL context was current or if any
OpenGL-related errors occurredpublic void setUniform(String name, float f0, float f1, float f2) throws javax.media.opengl.GLException
name
- the name of the uniform variable to be setf0
- the first uniform parameterf1
- the second uniform parameterf2
- the third uniform parameter
javax.media.opengl.GLException
- if no OpenGL context was current or if any
OpenGL-related errors occurredpublic void setUniform(String name, float f0, float f1, float f2, float f3) throws javax.media.opengl.GLException
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 parameter
javax.media.opengl.GLException
- if no OpenGL context was current or if any
OpenGL-related errors occurredpublic void setUniformArray1i(String name, int count, int[] vals, int off) throws javax.media.opengl.GLException
name
- the name of the uniform variable to be setcount
- the number of int elements in the arrayvals
- the array values to be setoff
- the offset into the vals array
javax.media.opengl.GLException
- if no OpenGL context was current or if any
OpenGL-related errors occurredpublic void setUniformArray2i(String name, int count, int[] vals, int off) throws javax.media.opengl.GLException
name
- the name of the uniform variable to be setcount
- the number of ivec2 elements in the arrayvals
- the array values to be setoff
- the offset into the vals array
javax.media.opengl.GLException
- if no OpenGL context was current or if any
OpenGL-related errors occurredpublic void setUniformArray3i(String name, int count, int[] vals, int off) throws javax.media.opengl.GLException
name
- the name of the uniform variable to be setcount
- the number of ivec3 elements in the arrayvals
- the array values to be setoff
- the offset into the vals array
javax.media.opengl.GLException
- if no OpenGL context was current or if any
OpenGL-related errors occurredpublic void setUniformArray4i(String name, int count, int[] vals, int off) throws javax.media.opengl.GLException
name
- the name of the uniform variable to be setcount
- the number of ivec4 elements in the arrayvals
- the array values to be setoff
- the offset into the vals array
javax.media.opengl.GLException
- if no OpenGL context was current or if any
OpenGL-related errors occurredpublic void setUniformArray1f(String name, int count, float[] vals, int off) throws javax.media.opengl.GLException
name
- the name of the uniform variable to be setcount
- the number of float elements in the arrayvals
- the array values to be setoff
- the offset into the vals array
javax.media.opengl.GLException
- if no OpenGL context was current or if any
OpenGL-related errors occurredpublic void setUniformArray2f(String name, int count, float[] vals, int off) throws javax.media.opengl.GLException
name
- the name of the uniform variable to be setcount
- the number of vec2 elements in the arrayvals
- the array values to be setoff
- the offset into the vals array
javax.media.opengl.GLException
- if no OpenGL context was current or if any
OpenGL-related errors occurredpublic void setUniformArray3f(String name, int count, float[] vals, int off) throws javax.media.opengl.GLException
name
- the name of the uniform variable to be setcount
- the number of vec3 elements in the arrayvals
- the array values to be setoff
- the offset into the vals array
javax.media.opengl.GLException
- if no OpenGL context was current or if any
OpenGL-related errors occurredpublic void setUniformArray4f(String name, int count, float[] vals, int off) throws javax.media.opengl.GLException
name
- the name of the uniform variable to be setcount
- the number of vec4 elements in the arrayvals
- the array values to be setoff
- the offset into the vals array
javax.media.opengl.GLException
- if no OpenGL context was current or if any
OpenGL-related errors occurredpublic void setUniformMatrices2f(String name, int count, boolean transpose, float[] vals, int off) throws javax.media.opengl.GLException
name
- the name of the uniform variable to be setcount
- the number of 2x2 matrices (mat2 elements) in the arraytranspose
- if false, each matrix is assumed to be suppplied in
column major order; otherwise assumed to be supplied in row major ordervals
- the matrix values to be setoff
- the offset into the vals array
javax.media.opengl.GLException
- if no OpenGL context was current or if any
OpenGL-related errors occurredpublic void setUniformMatrices3f(String name, int count, boolean transpose, float[] vals, int off) throws javax.media.opengl.GLException
name
- the name of the uniform variable to be setcount
- the number of 3x3 matrices (mat3 elements) in the arraytranspose
- if false, each matrix is assumed to be suppplied in
column major order; otherwise assumed to be supplied in row major ordervals
- the matrix values to be setoff
- the offset into the vals array
javax.media.opengl.GLException
- if no OpenGL context was current or if any
OpenGL-related errors occurredpublic void setUniformMatrices4f(String name, int count, boolean transpose, float[] vals, int off) throws javax.media.opengl.GLException
name
- the name of the uniform variable to be setcount
- the number of 4x4 matrices (mat4 elements) in the arraytranspose
- if false, each matrix is assumed to be suppplied in
column major order; otherwise assumed to be supplied in row major ordervals
- the matrix values to be setoff
- the offset into the vals array
javax.media.opengl.GLException
- if no OpenGL context was current or if any
OpenGL-related errors occurred
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |