Class GLSLShaderObjectsState

java.lang.Object
com.ardor3d.renderer.state.RenderState
com.ardor3d.renderer.state.GLSLShaderObjectsState
All Implemented Interfaces:
Savable

public class GLSLShaderObjectsState extends RenderState
Implementation of the GL_ARB_shader_objects extension.
  • Field Details

    • _shaderUniforms

      protected List<ShaderVariable> _shaderUniforms
      Storage for shader uniform values
    • _shaderAttributes

      protected List<ShaderVariable> _shaderAttributes
      Storage for shader attribute values
    • _vertShader

      protected ByteBuffer _vertShader
    • _fragShader

      protected ByteBuffer _fragShader
    • _geomShader

      protected ByteBuffer _geomShader
    • _tessControlShader

      protected ByteBuffer _tessControlShader
    • _tessEvalShader

      protected ByteBuffer _tessEvalShader
    • _compShader

      protected ByteBuffer _compShader
    • _shaderDataLogic

      public GLSLShaderDataLogic _shaderDataLogic
      Optional logic for setting shadervariables based on the current geom. Note: If this object does not implement Savable, it will be ignored during write.
    • _mesh

      public Mesh _mesh
      The Mesh this shader currently operates on during rendering
    • _needSendShader

      public boolean _needSendShader
    • _programID

      public int _programID
      OpenGL id for this program. *
    • _vertexShaderID

      public int _vertexShaderID
      OpenGL id for the attached vertex shader.
    • _fragmentShaderID

      public int _fragmentShaderID
      OpenGL id for the attached fragment shader.
    • _geometryShaderID

      public int _geometryShaderID
      OpenGL id for the attached geometry shader.
    • _tessellationControlShaderID

      public int _tessellationControlShaderID
      OpenGL id for the attached tessellation control shader.
    • _tessellationEvaluationShaderID

      public int _tessellationEvaluationShaderID
      OpenGL id for the attached tessellation evaluation shader.
    • _computeShaderID

      public int _computeShaderID
      OpenGL id for the attached compute shader.
    • _vertexShaderName

      public String _vertexShaderName
      optional name for our vertex shader, used for debugging details.
    • _fragmentShaderName

      public String _fragmentShaderName
      optional name for our fragment shader, used for debugging details.
    • _geometryShaderName

      public String _geometryShaderName
      optional name for our geometry shader, used for debugging details.
    • _tessellationControlShaderName

      public String _tessellationControlShaderName
      optional name for our tessellation control shader, used for debugging details.
    • _tessellationEvaluationShaderName

      public String _tessellationEvaluationShaderName
      optional name for our tessellation evaluation shader, used for debugging details.
    • _computeShaderName

      public String _computeShaderName
      optional name for our compute shader, used for debugging details.
  • Constructor Details

    • GLSLShaderObjectsState

      public GLSLShaderObjectsState()
  • Method Details

    • getVertexShader

      public ByteBuffer getVertexShader()
      Gets the currently loaded vertex shader.
      Returns:
      the currently loaded vertex shader
    • getFragmentShader

      public ByteBuffer getFragmentShader()
      Gets the currently loaded fragment shader.
      Returns:
      the currently loaded fragment shader
    • getGeometryShader

      public ByteBuffer getGeometryShader()
      Gets the currently loaded geometry shader.
      Returns:
      the currently loaded geometry shader
    • getTessellationControlShader

      public ByteBuffer getTessellationControlShader()
      Gets the currently loaded tessellation control shader.
      Returns:
      the currently loaded tessellation control shader
    • getTessellationEvaluationShader

      public ByteBuffer getTessellationEvaluationShader()
      Gets the currently loaded tessellation evaluation shader.
      Returns:
      the currently loaded tessellation evaluation shader
    • getComputeShader

      public ByteBuffer getComputeShader()
      Gets the currently loaded compute shader.
      Returns:
      the currently loaded compute shader
    • setVertexShader

      public void setVertexShader(InputStream stream) throws IOException
      Throws:
      IOException
    • setVertexShader

      public void setVertexShader(InputStream stream, String name) throws IOException
      Throws:
      IOException
    • setFragmentShader

      public void setFragmentShader(InputStream stream) throws IOException
      Throws:
      IOException
    • setFragmentShader

      public void setFragmentShader(InputStream stream, String name) throws IOException
      Throws:
      IOException
    • setGeometryShader

      public void setGeometryShader(InputStream stream) throws IOException
      Throws:
      IOException
    • setGeometryShader

      public void setGeometryShader(InputStream stream, String name) throws IOException
      Throws:
      IOException
    • setTessellationControlShader

      public void setTessellationControlShader(InputStream stream) throws IOException
      Throws:
      IOException
    • setTessellationControlShader

      public void setTessellationControlShader(InputStream stream, String name) throws IOException
      Throws:
      IOException
    • setTessellationEvaluationShader

      public void setTessellationEvaluationShader(InputStream stream) throws IOException
      Throws:
      IOException
    • setTessellationEvaluationShader

      public void setTessellationEvaluationShader(InputStream stream, String name) throws IOException
      Throws:
      IOException
    • setComputeShader

      public void setComputeShader(InputStream stream) throws IOException
      Throws:
      IOException
    • setComputeShader

      public void setComputeShader(InputStream stream, String name) throws IOException
      Throws:
      IOException
    • load

      protected ByteBuffer load(InputStream in) throws IOException
      Throws:
      IOException
    • setVertexShader

      public void setVertexShader(ByteBuffer shader)
      Set the contents for our vertex shader
      Parameters:
      shader - the shader contents.
    • setVertexShader

      public void setVertexShader(ByteBuffer shader, String name)
      Set the contents for our vertex shader
      Parameters:
      shader - the shader contents.
      name - a label for this shader, displayer upon shader errors.
    • setFragmentShader

      public void setFragmentShader(ByteBuffer shader)
      Set the contents for our fragment shader
      Parameters:
      shader - the shader contents.
    • setFragmentShader

      public void setFragmentShader(ByteBuffer shader, String name)
      Set the contents for our fragment shader
      Parameters:
      shader - the shader contents.
      name - a label for this shader, displayer upon shader errors.
    • setGeometryShader

      public void setGeometryShader(ByteBuffer shader)
      Set the contents for our geometry shader
      Parameters:
      shader - the shader contents.
    • setGeometryShader

      public void setGeometryShader(ByteBuffer shader, String name)
      Set the contents for our geometry shader
      Parameters:
      shader - the shader contents.
      name - a label for this shader, displayer upon shader errors.
    • setTessellationControlShader

      public void setTessellationControlShader(ByteBuffer shader)
      Set the contents for our tessellation control shader
      Parameters:
      shader - the shader contents.
    • setTessellationControlShader

      public void setTessellationControlShader(ByteBuffer shader, String name)
      Set the contents for our tessellation control shader
      Parameters:
      shader - the shader contents.
      name - a label for this shader, displayer upon shader errors.
    • setTessellationEvaluationShader

      public void setTessellationEvaluationShader(ByteBuffer shader)
      Set the contents for our tessellation evaluation shader
      Parameters:
      shader - the shader contents.
    • setTessellationEvaluationShader

      public void setTessellationEvaluationShader(ByteBuffer shader, String name)
      Set the contents for our tessellation evaluation shader
      Parameters:
      shader - the shader contents.
      name - a label for this shader, displayer upon shader errors.
    • setComputeShader

      public void setComputeShader(ByteBuffer shader)
      Set the contents for our compute shader
      Parameters:
      shader - the shader contents.
    • setComputeShader

      public void setComputeShader(ByteBuffer shader, String name)
      Set the contents for our compute shader
      Parameters:
      shader - the shader contents.
      name - a label for this shader, displayer upon shader errors.
    • setVertexShader

      public void setVertexShader(String shader)
      Set the contents for our vertex shader
      Parameters:
      shader - the shader contents.
    • setVertexShader

      public void setVertexShader(String shader, String name)
      Set the contents for our vertex shader
      Parameters:
      shader - the shader contents.
      name - a label for this shader, displayer upon shader errors.
    • setFragmentShader

      public void setFragmentShader(String shader)
      Set the contents for our fragment shader
      Parameters:
      shader - the shader contents.
    • setFragmentShader

      public void setFragmentShader(String shader, String name)
      Set the contents for our fragment shader
      Parameters:
      shader - the shader contents.
      name - a label for this shader, displayer upon shader errors.
    • setGeometryShader

      public void setGeometryShader(String shader)
      Set the contents for our geometry shader
      Parameters:
      shader - the shader contents.
    • setGeometryShader

      public void setGeometryShader(String shader, String name)
      Set the contents for our geometry shader
      Parameters:
      shader - the shader contents.
      name - a label for this shader, displayer upon shader errors.
    • setTessellationControlShader

      public void setTessellationControlShader(String shader)
      Set the contents for our tessellation control shader
      Parameters:
      shader - the shader contents.
    • setTessellationControlShader

      public void setTessellationControlShader(String shader, String name)
      Set the contents for our tessellation control shader
      Parameters:
      shader - the shader contents.
      name - a label for this shader, displayer upon shader errors.
    • setTessellationEvaluationShader

      public void setTessellationEvaluationShader(String shader)
      Set the contents for our tessellation evaluation shader
      Parameters:
      shader - the shader contents.
    • setTessellationEvaluationShader

      public void setTessellationEvaluationShader(String shader, String name)
      Set the contents for our tessellation evaluation shader
      Parameters:
      shader - the shader contents.
      name - a label for this shader, displayer upon shader errors.
    • setComputeShader

      public void setComputeShader(String shader)
      Set the contents for our compute shader
      Parameters:
      shader - the shader contents.
    • setComputeShader

      public void setComputeShader(String shader, String name)
      Set the contents for our compute shader
      Parameters:
      shader - the shader contents.
      name - a label for this shader, displayer upon shader errors.
    • getShaderUniforms

      public List<ShaderVariable> getShaderUniforms()
      Gets all shader uniforms variables.
      Returns:
      all shader uniforms variables
    • getUniformByName

      public ShaderVariable getUniformByName(String uniformName)
      Retrieves a shader uniform by name.
      Parameters:
      uniformName - the name of the shader uniform
      Returns:
      the shader uniform
    • getShaderAttributes

      public List<ShaderVariable> getShaderAttributes()
      Gets all shader attribute variables.
      Returns:
      all shader attribute variables
    • getAttributeByName

      public ShaderVariable getAttributeByName(String attributeName)
      Retrieves a shader attribute by name.
      Parameters:
      attributeName - the attribute name
      Returns:
      the shader attribute
    • setMesh

      public void setMesh(Mesh mesh)
      Parameters:
      mesh - the mesh
    • setShaderDataLogic

      public void setShaderDataLogic(GLSLShaderDataLogic shaderDataLogic)
      Logic to handle setting mesh-specific data to a shader before rendering
      Parameters:
      shaderDataLogic - the mesh-specific data logic
    • getShaderDataLogic

      public GLSLShaderDataLogic getShaderDataLogic()
    • isUseAttributeVBO

      public boolean isUseAttributeVBO()
    • setUseAttributeVBO

      public void setUseAttributeVBO(boolean useAttributeVBO)
      Parameters:
      useAttributeVBO - if true, and we support VBO, we'll use VBO for shader attributes.
    • setUniform

      public void setUniform(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(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(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(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(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(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(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(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(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(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(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(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(String name, FloatBuffer value, int size)
      Set an uniform value for this shader object.
      Parameters:
      name - uniform variable to change
      value - the new float data
      size - the number of components per entry (must be 1, 2, 3, or 4)
    • setUniform

      public void setUniform(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(String name, IntBuffer value)
      Set an uniform value for this shader object.
      Parameters:
      name - uniform variable to change
      value - the new value
    • setUniform

      public void setUniform(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(String name, ReadOnlyVector2 value)
      Set an uniform value for this shader object.
      Parameters:
      name - uniform variable to change
      value - the new value
    • setUniform

      public void setUniform(String name, ReadOnlyVector3 value)
      Set an uniform value for this shader object.
      Parameters:
      name - uniform variable to change
      value - the new value
    • setUniform

      public void setUniform(String name, ReadOnlyVector4 value)
      Set an uniform value for this shader object.
      Parameters:
      name - uniform variable to change
      value - the new value
    • setUniform

      public void setUniform(String name, ReadOnlyColorRGBA value)
      Set an uniform value for this shader object.
      Parameters:
      name - uniform variable to change
      value - the new value
    • setUniform

      public void setUniform(String name, ReadOnlyQuaternion value)
      Set an uniform value for this shader object.
      Parameters:
      name - uniform variable to change
      value - the new value
    • setUniform

      public void setUniform(String name, ReadOnlyMatrix3 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(String name, ReadOnlyMatrix4 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
    • setUniformMatrix4

      public void setUniformMatrix4(String name, FloatBuffer value)
      Set an uniform value for this shader object.
      Parameters:
      name - uniform Matrix4 variable to change
      value - the new value, assumed row major
    • setUniform

      public void setUniform(String name, ReadOnlyMatrix4[] values, boolean rowMajor)
      Set an uniform value for this shader object.
      Parameters:
      name - uniform variable to change
      values - the new values
      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(String name, int size, boolean normalized, int stride, FloatBufferData 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
    • setAttributePointerMatrix

      public void setAttributePointerMatrix(String name, int size, boolean normalized, FloatBufferData data)
      Set an attribute pointer value for this shader object.
      Parameters:
      name - attribute variable to change
      size - the number of rows and cols in the matrix. Must be 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.
      data - The actual data to use as attribute pointer
    • setAttributePointer

      public void setAttributePointer(String name, int size, boolean normalized, boolean unsigned, int stride, ByteBufferData 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(String name, int size, boolean normalized, boolean unsigned, int stride, IntBufferData 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(String name, int size, boolean normalized, boolean unsigned, int stride, ShortBufferData 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 RenderState.StateType getType()
      Specified by:
      getType in class RenderState
      Returns:
      An statetype enum value for the subclass.
      See Also:
    • checkAttributeSizeLimits

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

      public void write(OutputCapsule capsule) throws IOException
      Specified by:
      write in interface Savable
      Overrides:
      write in class RenderState
      Throws:
      IOException
    • read

      public void read(InputCapsule capsule) throws IOException
      Specified by:
      read in interface Savable
      Overrides:
      read in class RenderState
      Throws:
      IOException
    • createStateRecord

      public StateRecord createStateRecord(ContextCapabilities caps)
      Specified by:
      createStateRecord in class RenderState