codeanticode.glgraphics
Class GLSLShader

java.lang.Object
  extended by codeanticode.glgraphics.GLShader
      extended by codeanticode.glgraphics.GLSLShader
All Implemented Interfaces:
GLConstants

public class GLSLShader
extends GLShader

This class encapsulates a glsl shader. Based in the code by JohnG (http://www.hardcorepawn.com/)


Field Summary
 
Fields inherited from interface codeanticode.glgraphics.GLConstants
BACKGROUND_ALPHA, CG_CONTEXT, CG_EFFECT, CG_PROGRAM, COLOR, DOUBLE, FLOAT, FRAGMENT_PROGRAM, GEOMETRY_PROGRAM, GL_DEPTH_STENCIL, GL_DEPTH24_STENCIL8, GL_FRAME_BUFFER, GL_PIXEL_BUFFER, GL_RENDER_BUFFER, GL_TEXTURE_OBJECT, GL_UNSIGNED_INT_24_8, GL_VERTEX_BUFFER, GLGRAPHICS, GLSL_PROGRAM, GLSL_SHADER, IDENTITY_MATRIX, INVERSE_MATRIX, INVERSE_TRANSPOSE_MATRIX, LINE_ADJACENCY, LINEAR_MIPMAP_LINEAR, LINEAR_MIPMAP_NEAREST, LINEAR_SAMPLING, NEAREST_MIPMAP_LINEAR, NEAREST_MIPMAP_NEAREST, NEAREST_SAMPLING, SHADER_VAR_ARRAY, SHADER_VAR_FLOAT, SHADER_VAR_INT, SHADER_VAR_MAT2, SHADER_VAR_MAT3, SHADER_VAR_MAT4, SHADER_VAR_MODELVIEW_MAT, SHADER_VAR_MODELVIEW_PROJECTION_MAT, SHADER_VAR_PROJECTION_MAT, SHADER_VAR_TEXTURE_MAT, SHADER_VAR_TEXTURE_SAMPLER, SHADER_VAR_VEC2, SHADER_VAR_VEC3, SHADER_VAR_VEC4, TEX_BYTE, TEX_INT, TEX_NORM, TEX_ONEDIM, TEX_RECT, TRANSPOSE_MATRIX, TRIANGLE_ADJACENCY, VERTEX_PROGRAM
 
Constructor Summary
GLSLShader(processing.core.PApplet parent)
          Creates an instance of GLSLShader.
GLSLShader(processing.core.PApplet parent, java.lang.String vertexFN, java.lang.String fragmentFN)
          Creates a read-to-use instance of GLSLShader with vertex and fragment shaders
GLSLShader(processing.core.PApplet parent, java.lang.String vertexFN, java.lang.String geometryFN, java.lang.String fragmentFN)
          Creates a instance of GLSLShader with vertex, geometry and fragment shaders.
 
Method Summary
 void delete()
           
 int getAttribLocation(java.lang.String name)
          Returns the ID location of the attribute parameter given its name.
 int getMaxOutVertCount()
          Returns the maximum number of vertices that can be emitted by the geometry shader.
 int getUniformLocation(java.lang.String name)
          Returns the ID location of the uniform parameter given its name.
 boolean isInitialized()
          Returns true or false depending on whether the shader is initialized or not.
 void loadFragmentShader(java.lang.String file)
          Loads and compiles the fragment shader contained in file.
 void loadFragmentShader(java.net.URL url)
          Loads and compiles the fragment shader contained in the URL.
 void loadGeometryShader(java.lang.String file)
          Loads and compiles the geometry shader contained in file.
 void loadGeometryShader(java.net.URL url)
          Loads and compiles the geometry shader contained in the URL
 void loadVertexShader(java.lang.String file)
          Loads and compiles the vertex shader contained in file.
 void loadVertexShader(java.net.URL url)
          Loads and compiles the vertex shader contained in the URL.
 void setFloatAttribute(java.lang.String name, float x)
          Sets the float attribute with name to the given value
 void setFloatUniform(java.lang.String name, float x)
          Sets the float uniform with name to the given value
 void setIntUniform(java.lang.String name, int x)
          Sets the int uniform with name to the given value
 void setMatUniform(java.lang.String name, float m00, float m01, float m10, float m11)
          Sets the mat2 uniform with name to the given values
 void setMatUniform(java.lang.String name, float m00, float m01, float m02, float m10, float m11, float m12, float m20, float m21, float m22)
          Sets the mat3 uniform with name to the given values
 void setMatUniform(java.lang.String name, float m00, float m01, float m02, float m03, float m10, float m11, float m12, float m13, float m20, float m21, float m22, float m23, float m30, float m31, float m32, float m33)
          Sets the mat3 uniform with name to the given values
 void setTexUniform(java.lang.String name, GLTexture tex)
          Sets the texture uniform with the unit of tex is attached to at the moment of running the shader.
 void setTexUniform(java.lang.String name, int unit)
          Sets the texture uniform name with the texture unit to use in the said uniform.
 void setup()
          Links the shader program and validates it.
 void setupGeometryShader(int inGeoPrim, int outGeoPrim)
          Configures the geometry shader by setting the primitive types that it will take as input and return as output.
 void setupGeometryShader(int inGeoPrim, int outGeoPrim, int maxOutVert)
          Configures the geometry shader by setting the primitive types that it will take as input and return as output, and the maximum number of vertices that will generate.
 void setupGeometryShader(java.lang.String inGeoPrim, java.lang.String outGeoPrim)
          Configures the geometry shader by setting the primitive types that it will take as input and return as output, and the maximum number of vertices that will generate.
 void setupGeometryShader(java.lang.String inGeoPrim, java.lang.String outGeoPrim, int maxOutVert)
          Configures the geometry shader by setting the primitive types that it will take as input and return as output, and the maximum number of vertices that will generate.
 void setVecAttribute(java.lang.String name, float x, float y)
          Sets the vec2 attribute with name to the given values
 void setVecAttribute(java.lang.String name, float x, float y, float z)
          Sets the vec3 attribute with name to the given values
 void setVecAttribute(java.lang.String name, float x, float y, float z, float w)
          Sets the vec4 attribute with name to the given values
 void setVecUniform(java.lang.String name, float x, float y)
          Sets the vec2 uniform with name to the given values.
 void setVecUniform(java.lang.String name, float x, float y, float z)
          Sets the vec3 uniform with name to the given values.
 void setVecUniform(java.lang.String name, float x, float y, float z, float w)
          Sets the vec4 uniform with name to the given values.
 void start()
          Starts the execution of the shader program.
 void stop()
          Stops the execution of the shader program.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GLSLShader

public GLSLShader(processing.core.PApplet parent)
Creates an instance of GLSLShader.

Parameters:
parent - PApplet

GLSLShader

public GLSLShader(processing.core.PApplet parent,
                  java.lang.String vertexFN,
                  java.lang.String fragmentFN)
Creates a read-to-use instance of GLSLShader with vertex and fragment shaders

Parameters:
parent - PApplet
vertexFN - String
fragmentFN - String

GLSLShader

public GLSLShader(processing.core.PApplet parent,
                  java.lang.String vertexFN,
                  java.lang.String geometryFN,
                  java.lang.String fragmentFN)
Creates a instance of GLSLShader with vertex, geometry and fragment shaders. The geometry shader needs to be configured with setupGeometryShader.

Parameters:
parent - PApplet
vertexFN - String
geometryFN - String
fragmentFN - String
See Also:
setupGeometryShader
Method Detail

delete

public void delete()
Overrides:
delete in class GLShader

loadVertexShader

public void loadVertexShader(java.lang.String file)
Loads and compiles the vertex shader contained in file.

Specified by:
loadVertexShader in class GLShader
Parameters:
file - String

loadVertexShader

public void loadVertexShader(java.net.URL url)
Loads and compiles the vertex shader contained in the URL.

Specified by:
loadVertexShader in class GLShader
Parameters:
file - String

loadGeometryShader

public void loadGeometryShader(java.lang.String file)
Loads and compiles the geometry shader contained in file.

Specified by:
loadGeometryShader in class GLShader
Parameters:
file - String

loadGeometryShader

public void loadGeometryShader(java.net.URL url)
Loads and compiles the geometry shader contained in the URL

Specified by:
loadGeometryShader in class GLShader
Parameters:
url - URL

loadFragmentShader

public void loadFragmentShader(java.lang.String file)
Loads and compiles the fragment shader contained in file.

Specified by:
loadFragmentShader in class GLShader
Parameters:
file - String

loadFragmentShader

public void loadFragmentShader(java.net.URL url)
Loads and compiles the fragment shader contained in the URL.

Specified by:
loadFragmentShader in class GLShader
Parameters:
url - URL

setup

public void setup()
Links the shader program and validates it.

Specified by:
setup in class GLShader

getMaxOutVertCount

public int getMaxOutVertCount()
Returns the maximum number of vertices that can be emitted by the geometry shader.


isInitialized

public boolean isInitialized()
Returns true or false depending on whether the shader is initialized or not.

Specified by:
isInitialized in class GLShader

start

public void start()
Starts the execution of the shader program.

Specified by:
start in class GLShader

stop

public void stop()
Stops the execution of the shader program.

Specified by:
stop in class GLShader

setupGeometryShader

public void setupGeometryShader(int inGeoPrim,
                                int outGeoPrim)
Configures the geometry shader by setting the primitive types that it will take as input and return as output.

Parameters:
inGeoPrim - int
outGeoPrim - int

setupGeometryShader

public void setupGeometryShader(int inGeoPrim,
                                int outGeoPrim,
                                int maxOutVert)
Configures the geometry shader by setting the primitive types that it will take as input and return as output, and the maximum number of vertices that will generate.

Parameters:
inGeoPrim - int
outGeoPrim - int
maxNumOutVert - int

setupGeometryShader

public void setupGeometryShader(java.lang.String inGeoPrim,
                                java.lang.String outGeoPrim)
Configures the geometry shader by setting the primitive types that it will take as input and return as output, and the maximum number of vertices that will generate.

Parameters:
inGeoPrim - String
outGeoPrim - String

setupGeometryShader

public void setupGeometryShader(java.lang.String inGeoPrim,
                                java.lang.String outGeoPrim,
                                int maxOutVert)
Configures the geometry shader by setting the primitive types that it will take as input and return as output, and the maximum number of vertices that will generate.

Parameters:
inGeoPrim - String
outGeoPrim - String
maxNumOutVert - int

getAttribLocation

public int getAttribLocation(java.lang.String name)
Returns the ID location of the attribute parameter given its name.

Parameters:
name - String
Returns:
int

getUniformLocation

public int getUniformLocation(java.lang.String name)
Returns the ID location of the uniform parameter given its name.

Parameters:
name - String
Returns:
int

setTexUniform

public void setTexUniform(java.lang.String name,
                          int unit)
Sets the texture uniform name with the texture unit to use in the said uniform.

Parameters:
name - String
unit - int

setTexUniform

public void setTexUniform(java.lang.String name,
                          GLTexture tex)
Sets the texture uniform with the unit of tex is attached to at the moment of running the shader.

Parameters:
name - String
tex - GLTexture

setIntUniform

public void setIntUniform(java.lang.String name,
                          int x)
Sets the int uniform with name to the given value

Parameters:
name - String
x - int

setFloatUniform

public void setFloatUniform(java.lang.String name,
                            float x)
Sets the float uniform with name to the given value

Parameters:
name - String
x - float

setVecUniform

public void setVecUniform(java.lang.String name,
                          float x,
                          float y)
Sets the vec2 uniform with name to the given values.

Parameters:
nam - String
x - float
y - float

setVecUniform

public void setVecUniform(java.lang.String name,
                          float x,
                          float y,
                          float z)
Sets the vec3 uniform with name to the given values.

Parameters:
name - String
x - float
y - float
z - float

setVecUniform

public void setVecUniform(java.lang.String name,
                          float x,
                          float y,
                          float z,
                          float w)
Sets the vec4 uniform with name to the given values.

Parameters:
name - String
x - float
y - float
z - float
w - float

setMatUniform

public void setMatUniform(java.lang.String name,
                          float m00,
                          float m01,
                          float m10,
                          float m11)
Sets the mat2 uniform with name to the given values

Parameters:
name - String
m00 - float ...

setMatUniform

public void setMatUniform(java.lang.String name,
                          float m00,
                          float m01,
                          float m02,
                          float m10,
                          float m11,
                          float m12,
                          float m20,
                          float m21,
                          float m22)
Sets the mat3 uniform with name to the given values

Parameters:
name - String
m00 - float ...

setMatUniform

public void setMatUniform(java.lang.String name,
                          float m00,
                          float m01,
                          float m02,
                          float m03,
                          float m10,
                          float m11,
                          float m12,
                          float m13,
                          float m20,
                          float m21,
                          float m22,
                          float m23,
                          float m30,
                          float m31,
                          float m32,
                          float m33)
Sets the mat3 uniform with name to the given values

Parameters:
name - String
m00 - float ...

setFloatAttribute

public void setFloatAttribute(java.lang.String name,
                              float x)
Sets the float attribute with name to the given value

Parameters:
name - String
x - float

setVecAttribute

public void setVecAttribute(java.lang.String name,
                            float x,
                            float y)
Sets the vec2 attribute with name to the given values

Parameters:
name - String
float - x
float - y

setVecAttribute

public void setVecAttribute(java.lang.String name,
                            float x,
                            float y,
                            float z)
Sets the vec3 attribute with name to the given values

Parameters:
name - String
float - x
float - y
float - z

setVecAttribute

public void setVecAttribute(java.lang.String name,
                            float x,
                            float y,
                            float z,
                            float w)
Sets the vec4 attribute with name to the given values

Parameters:
name - String
float - x
float - y
float - z
float - w


processing library GLGraphics by Andres Colubri. (c) 2008-2011