com.jme.scene.state
Class GLSLShaderObjectsState

java.lang.Object
  extended by com.jme.scene.state.RenderState
      extended by com.jme.scene.state.GLSLShaderObjectsState
All Implemented Interfaces:
Savable
Direct Known Subclasses:
JOGLShaderObjectsState, LWJGLShaderObjectsState

public abstract class GLSLShaderObjectsState
extends RenderState

Implementation of the GL_ARB_shader_objects extension.

Author:
Thomas Hourdel, Rikard Herlitz (MrCoder)

Nested Class Summary
 
Nested classes/interfaces inherited from class com.jme.scene.state.RenderState
RenderState.StateType
 
Field Summary
protected  java.lang.String fragShader
           
protected  Geometry geom
          The Geometry this shader currently operates on during rendering
protected static boolean glslSupported
           
protected static boolean glslSupportedDetected
           
protected  boolean needSendShader
           
protected  java.util.HashMap<java.lang.String,ShaderVariable> shaderAttributes
          Storage for shader attribute values
protected  GLSLShaderDataLogic shaderDataLogic
          Optional logic for setting shadervariables based on the current geom
protected  java.util.HashMap<java.lang.String,ShaderVariable> shaderUniforms
          Storage for shader uniform values
protected  java.lang.String vertShader
           
 
Fields inherited from class com.jme.scene.state.RenderState
QUICK_COMPARE, RS_BLEND, RS_CLIP, RS_COLORMASK_STATE, RS_CULL, RS_FOG, RS_FRAGMENT_PROGRAM, RS_GLSL_SHADER_OBJECTS, RS_LIGHT, RS_MATERIAL, RS_MAX_STATE, RS_SHADE, RS_STENCIL, RS_TEXTURE, RS_VERTEX_PROGRAM, RS_WIREFRAME, RS_ZBUFFER
 
Constructor Summary
GLSLShaderObjectsState()
           
 
Method Summary
 void checkAttributeSizeLimits()
          Check if we are keeping the size limits in terms of attribute locations on the card.
 void checkUniformSizeLimits()
          Check if we are keeping the size limits in terms of uniform locations on the card.
abstract  void cleanup()
          Frees the memory and invalidates the shader handle
 void clearAttributes()
          clearAttributes clears all attribute values from this state.
 void clearUniforms()
          clearUniforms clears all uniform values from this state.
 ShaderVariable getAttributeByName(java.lang.String attributeName)
          Retrieves a shader attribute by name.
 java.lang.Class<? extends GLSLShaderObjectsState> getClassTag()
           
 java.lang.String getFragmentShader()
          Gets the currently loaded fragment shader.
 java.util.Collection<ShaderVariable> getShaderAttributes()
          Gets all shader attribute variables.
 java.util.Collection<ShaderVariable> getShaderUniforms()
          Gets all shader uniforms variables.
 RenderState.StateType getStateType()
          getStateType returns the type RenderState.StateType.GLSLShaderObjects
 int getType()
          Deprecated. As of 2.0, use RenderState.getStateType() instead.
 ShaderVariable getUniformByName(java.lang.String uniformName)
          Retrieves a shader uniform by name.
 java.lang.String getVertexShader()
          Gets the currently loaded vertex shader.
static boolean isSupported()
          isSupported determines if the ARB_shader_objects extension is supported by current graphics configuration.
protected  java.nio.ByteBuffer load(java.io.InputStream in)
          Load an URL and grab content into a ByteBuffer.
 void load(java.io.InputStream vert, java.io.InputStream frag)
          load loads the shader object from the specified file.
 void load(java.lang.String vert, java.lang.String frag)
          load loads the shader object from the specified string.
 void load(java.net.URL vert, java.net.URL frag)
          load loads the shader object from the specified file.
static void overrideSupport(boolean use)
          Overide setting of glsl support.
 void read(JMEImporter e)
           
static void resetSupport()
          Reset glsl support to driver-detected setting.
protected abstract  void sendToGL(java.nio.ByteBuffer vertexByteBuffer, java.nio.ByteBuffer fragmentByteBuffer)
          Loads the shader object.
 void setAttributePointer(java.lang.String name, int size, boolean normalized, boolean unsigned, int stride, java.nio.ByteBuffer data)
          Set an attribute pointer value for this shader object.
 void setAttributePointer(java.lang.String name, int size, boolean normalized, boolean unsigned, int stride, java.nio.IntBuffer data)
          Set an attribute pointer value for this shader object.
 void setAttributePointer(java.lang.String name, int size, boolean normalized, boolean unsigned, int stride, java.nio.ShortBuffer data)
          Set an attribute pointer value for this shader object.
 void setAttributePointer(java.lang.String name, int size, boolean normalized, int stride, java.nio.FloatBuffer data)
          Set an attribute pointer value for this shader object.
 void setGeometry(Geometry geom)
           
 void setShaderDataLogic(GLSLShaderDataLogic shaderDataLogic)
          Logic to handle setting geom-specific data to a shader before rendering
 void setUniform(java.lang.String name, boolean value)
          Set an uniform value for this shader object.
 void setUniform(java.lang.String name, boolean value1, boolean value2)
          Set an uniform value for this shader object.
 void setUniform(java.lang.String name, boolean value1, boolean value2, boolean value3)
          Set an uniform value for this shader object.
 void setUniform(java.lang.String name, boolean value1, boolean value2, boolean value3, boolean value4)
          Set an uniform value for this shader object.
 void setUniform(java.lang.String name, ColorRGBA value)
          Set an uniform value for this shader object.
 void setUniform(java.lang.String name, float value)
          Set an uniform value for this shader object.
 void setUniform(java.lang.String name, float[] value, boolean rowMajor)
          Set an uniform value for this shader object.
 void setUniform(java.lang.String name, float value1, float value2)
          Set an uniform value for this shader object.
 void setUniform(java.lang.String name, float value1, float value2, float value3)
          Set an uniform value for this shader object.
 void setUniform(java.lang.String name, float value1, float value2, float value3, float value4)
          Set an uniform value for this shader object.
 void setUniform(java.lang.String name, int value)
          Set an uniform value for this shader object.
 void setUniform(java.lang.String name, int value1, int value2)
          Set an uniform value for this shader object.
 void setUniform(java.lang.String name, int value1, int value2, int value3)
          Set an uniform value for this shader object.
 void setUniform(java.lang.String name, int value1, int value2, int value3, int value4)
          Set an uniform value for this shader object.
 void setUniform(java.lang.String name, Matrix3f value, boolean rowMajor)
          Set an uniform value for this shader object.
 void setUniform(java.lang.String name, Matrix4f[] values, boolean rowMajor)
          Set an uniform value for this shader object.
 void setUniform(java.lang.String name, Matrix4f value, boolean rowMajor)
          Set an uniform value for this shader object.
 void setUniform(java.lang.String name, Quaternion value)
          Set an uniform value for this shader object.
 void setUniform(java.lang.String name, Vector2f value)
          Set an uniform value for this shader object.
 void setUniform(java.lang.String name, Vector3f value)
          Set an uniform value for this shader object.
 void write(JMEExporter e)
           
 
Methods inherited from class com.jme.scene.state.RenderState
apply, createStateRecord, extract, isEnabled, needsRefresh, setEnabled, setNeedsRefresh, setQuickCompares
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

shaderUniforms

protected java.util.HashMap<java.lang.String,ShaderVariable> shaderUniforms
Storage for shader uniform values


shaderAttributes

protected java.util.HashMap<java.lang.String,ShaderVariable> shaderAttributes
Storage for shader attribute values


shaderDataLogic

protected GLSLShaderDataLogic shaderDataLogic
Optional logic for setting shadervariables based on the current geom


geom

protected Geometry geom
The Geometry this shader currently operates on during rendering


glslSupported

protected static boolean glslSupported

glslSupportedDetected

protected static boolean glslSupportedDetected

needSendShader

protected boolean needSendShader

vertShader

protected java.lang.String vertShader

fragShader

protected java.lang.String fragShader
Constructor Detail

GLSLShaderObjectsState

public GLSLShaderObjectsState()
Method Detail

getVertexShader

public java.lang.String getVertexShader()
Gets the currently loaded vertex shader.

Returns:

getFragmentShader

public java.lang.String getFragmentShader()
Gets the currently loaded fragment shader.

Returns:

getShaderUniforms

public java.util.Collection<ShaderVariable> getShaderUniforms()
Gets all shader uniforms variables.

Returns:

getUniformByName

public ShaderVariable getUniformByName(java.lang.String uniformName)
Retrieves a shader uniform by name.

Parameters:
uniformName -
Returns:

getShaderAttributes

public java.util.Collection<ShaderVariable> getShaderAttributes()
Gets all shader attribute variables.

Returns:

getAttributeByName

public ShaderVariable getAttributeByName(java.lang.String attributeName)
Retrieves a shader attribute by name.

Parameters:
uniformName -
Returns:

setGeometry

public void setGeometry(Geometry geom)
Parameters:
geom -

setShaderDataLogic

public void setShaderDataLogic(GLSLShaderDataLogic shaderDataLogic)
Logic to handle setting geom-specific data to a shader before rendering

Parameters:
shaderDataLogic -

isSupported

public static boolean isSupported()
isSupported determines if the ARB_shader_objects extension is supported by current graphics configuration. This will only be valid if a renderer has been created.

Returns:
if ARB shader objects are supported

overrideSupport

public static void overrideSupport(boolean use)
Overide setting of glsl support.

Parameters:
use -

resetSupport

public static void resetSupport()
Reset glsl support to driver-detected setting.


setUniform

public void setUniform(java.lang.String name,
                       boolean value)
Set an uniform value for this shader object.

Parameters:
name - uniform variable to change
value - the new value

setUniform

public void setUniform(java.lang.String name,
                       int value)
Set an uniform value for this shader object.

Parameters:
name - uniform variable to change
value - the new value

setUniform

public void setUniform(java.lang.String name,
                       float value)
Set an uniform value for this shader object.

Parameters:
name - uniform variable to change
value - the new value

setUniform

public void setUniform(java.lang.String name,
                       boolean value1,
                       boolean value2)
Set an uniform value for this shader object.

Parameters:
name - uniform variable to change
value1 - the new value
value2 - the new value

setUniform

public void setUniform(java.lang.String name,
                       int value1,
                       int value2)
Set an uniform value for this shader object.

Parameters:
name - uniform variable to change
value1 - the new value
value2 - the new value

setUniform

public void setUniform(java.lang.String name,
                       float value1,
                       float value2)
Set an uniform value for this shader object.

Parameters:
name - uniform variable to change
value1 - the new value
value2 - the new value

setUniform

public void setUniform(java.lang.String name,
                       boolean value1,
                       boolean value2,
                       boolean value3)
Set an uniform value for this shader object.

Parameters:
name - uniform variable to change
value1 - the new value
value2 - the new value
value3 - the new value

setUniform

public void setUniform(java.lang.String name,
                       int value1,
                       int value2,
                       int value3)
Set an uniform value for this shader object.

Parameters:
name - uniform variable to change
value1 - the new value
value2 - the new value
value3 - the new value

setUniform

public void setUniform(java.lang.String name,
                       float value1,
                       float value2,
                       float value3)
Set an uniform value for this shader object.

Parameters:
name - uniform variable to change
value1 - the new value
value2 - the new value
value3 - the new value

setUniform

public void setUniform(java.lang.String name,
                       boolean value1,
                       boolean value2,
                       boolean value3,
                       boolean value4)
Set an uniform value for this shader object.

Parameters:
name - uniform variable to change
value1 - the new value
value2 - the new value
value3 - the new value
value4 - the new value

setUniform

public void setUniform(java.lang.String name,
                       int value1,
                       int value2,
                       int value3,
                       int value4)
Set an uniform value for this shader object.

Parameters:
name - uniform variable to change
value1 - the new value
value2 - the new value
value3 - the new value
value4 - the new value

setUniform

public void setUniform(java.lang.String name,
                       float value1,
                       float value2,
                       float value3,
                       float value4)
Set an uniform value for this shader object.

Parameters:
name - uniform variable to change
value1 - the new value
value2 - the new value
value3 - the new value
value4 - the new value

setUniform

public void setUniform(java.lang.String name,
                       Vector2f value)
Set an uniform value for this shader object.

Parameters:
name - uniform variable to change
value - the new value

setUniform

public void setUniform(java.lang.String name,
                       Vector3f value)
Set an uniform value for this shader object.

Parameters:
name - uniform variable to change
value - the new value

setUniform

public void setUniform(java.lang.String name,
                       ColorRGBA value)
Set an uniform value for this shader object.

Parameters:
name - uniform variable to change
value - the new value

setUniform

public void setUniform(java.lang.String name,
                       Quaternion value)
Set an uniform value for this shader object.

Parameters:
name - uniform variable to change
value - the new value

setUniform

public void setUniform(java.lang.String name,
                       float[] value,
                       boolean rowMajor)
Set an uniform value for this shader object.

Parameters:
name - uniform variable to change
value - the new value (a float buffer of size 4)
rowMajor - true if is this in row major order

setUniform

public void setUniform(java.lang.String name,
                       Matrix3f value,
                       boolean rowMajor)
Set an uniform value for this shader object.

Parameters:
name - uniform variable to change
value - the new value
rowMajor - true if is this in row major order

setUniform

public void setUniform(java.lang.String name,
                       Matrix4f value,
                       boolean rowMajor)
Set an uniform value for this shader object.

Parameters:
name - uniform variable to change
value - the new value
rowMajor - true if is this in row major order

setUniform

public void setUniform(java.lang.String name,
                       Matrix4f[] values,
                       boolean rowMajor)
Set an uniform value for this shader object.

Parameters:
name - uniform variable to change
value - the new value
rowMajor - true if is this in row major order

clearUniforms

public void clearUniforms()
clearUniforms clears all uniform values from this state.


setAttributePointer

public void setAttributePointer(java.lang.String name,
                                int size,
                                boolean normalized,
                                int stride,
                                java.nio.FloatBuffer data)
Set an attribute pointer value for this shader object.

Parameters:
name - attribute variable to change
size - Specifies the number of values for each element of the generic vertex attribute array. Must be 1, 2, 3, or 4.
normalized - Specifies whether fixed-point data values should be normalized or converted directly as fixed-point values when they are accessed.
stride - Specifies the byte offset between consecutive attribute values. If stride is 0 (the initial value), the attribute values are understood to be tightly packed in the array.
data - The actual data to use as attribute pointer

setAttributePointer

public void setAttributePointer(java.lang.String name,
                                int size,
                                boolean normalized,
                                boolean unsigned,
                                int stride,
                                java.nio.ByteBuffer data)
Set an attribute pointer value for this shader object.

Parameters:
name - attribute variable to change
size - Specifies the number of values for each element of the generic vertex attribute array. Must be 1, 2, 3, or 4.
normalized - Specifies whether fixed-point data values should be normalized or converted directly as fixed-point values when they are accessed.
unsigned - Specifies wheter the data is signed or unsigned
stride - Specifies the byte offset between consecutive attribute values. If stride is 0 (the initial value), the attribute values are understood to be tightly packed in the array.
data - The actual data to use as attribute pointer

setAttributePointer

public void setAttributePointer(java.lang.String name,
                                int size,
                                boolean normalized,
                                boolean unsigned,
                                int stride,
                                java.nio.IntBuffer data)
Set an attribute pointer value for this shader object.

Parameters:
name - attribute variable to change
size - Specifies the number of values for each element of the generic vertex attribute array. Must be 1, 2, 3, or 4.
normalized - Specifies whether fixed-point data values should be normalized or converted directly as fixed-point values when they are accessed.
unsigned - Specifies wheter the data is signed or unsigned
stride - Specifies the byte offset between consecutive attribute values. If stride is 0 (the initial value), the attribute values are understood to be tightly packed in the array.
data - The actual data to use as attribute pointer

setAttributePointer

public void setAttributePointer(java.lang.String name,
                                int size,
                                boolean normalized,
                                boolean unsigned,
                                int stride,
                                java.nio.ShortBuffer data)
Set an attribute pointer value for this shader object.

Parameters:
name - attribute variable to change
size - Specifies the number of values for each element of the generic vertex attribute array. Must be 1, 2, 3, or 4.
normalized - Specifies whether fixed-point data values should be normalized or converted directly as fixed-point values when they are accessed.
unsigned - Specifies wheter the data is signed or unsigned
stride - Specifies the byte offset between consecutive attribute values. If stride is 0 (the initial value), the attribute values are understood to be tightly packed in the array.
data - The actual data to use as attribute pointer

clearAttributes

public void clearAttributes()
clearAttributes clears all attribute values from this state.


getType

public int getType()
Deprecated. As of 2.0, use RenderState.getStateType() instead.

Description copied from class: RenderState
Defined by the subclass, this returns an int identifying the renderstate. For example, RS_CULL or RS_TEXTURE.

Specified by:
getType in class RenderState
Returns:
RS_SHADER_OBJECTS
See Also:
RenderState.getType()

getStateType

public RenderState.StateType getStateType()
getStateType returns the type RenderState.StateType.GLSLShaderObjects

Specified by:
getStateType in class RenderState
Returns:
RenderState.StateType.GLSLShaderObjects
See Also:
RenderState.getStateType()

checkUniformSizeLimits

public void checkUniformSizeLimits()
Check if we are keeping the size limits in terms of uniform locations on the card.


checkAttributeSizeLimits

public void checkAttributeSizeLimits()
Check if we are keeping the size limits in terms of attribute locations on the card.


load

public void load(java.net.URL vert,
                 java.net.URL frag)
load loads the shader object from the specified file. The program must be in ASCII format. The implementation must convert the String into data compatible with the graphics library.

Parameters:
vert - text file containing the vertex shader object
frag - text file containing the fragment shader object

load

public void load(java.io.InputStream vert,
                 java.io.InputStream frag)
load loads the shader object from the specified file. The program must be in ASCII format. The implementation must convert the String into data compatible with the graphics library.

Parameters:
vert - The input stream from which the vertex shader can be read
frag - The input stream from which the fragment shader can be read

load

public void load(java.lang.String vert,
                 java.lang.String frag)
load loads the shader object from the specified string. The program must be in ASCII format. We delegate the loading to each implementation because we do not know in what format the underlying API wants the data.

Parameters:
vert - string containing the vertex shader object
frag - string containing the fragment shader object

write

public void write(JMEExporter e)
           throws java.io.IOException
Specified by:
write in interface Savable
Overrides:
write in class RenderState
Throws:
java.io.IOException

read

public void read(JMEImporter e)
          throws java.io.IOException
Specified by:
read in interface Savable
Overrides:
read in class RenderState
Throws:
java.io.IOException

getClassTag

public java.lang.Class<? extends GLSLShaderObjectsState> getClassTag()
Specified by:
getClassTag in interface Savable
Overrides:
getClassTag in class RenderState

sendToGL

protected abstract void sendToGL(java.nio.ByteBuffer vertexByteBuffer,
                                 java.nio.ByteBuffer fragmentByteBuffer)
Loads the shader object. Use null for an empty vertex or empty fragment shader.

Parameters:
vertexByteBuffer - vertex shader
fragmentByteBuffer - fragment shader
See Also:
load(java.net.URL, java.net.URL)

load

protected java.nio.ByteBuffer load(java.io.InputStream in)
Load an URL and grab content into a ByteBuffer.

Parameters:
in - The input stream to read
Returns:
the loaded url

cleanup

public abstract void cleanup()
Frees the memory and invalidates the shader handle