Class TLspShaderProgram

java.lang.Object
com.luciad.view.lightspeed.services.glcache.ALspGLResource
com.luciad.view.lightspeed.util.opengl.glsl.TLspShaderProgram
Direct Known Subclasses:
TLspSimpleShaderProgram

public class TLspShaderProgram extends ALspGLResource
Base class for GLSL shader programs.
Since:
2012.0
  • Constructor Details

    • TLspShaderProgram

      public TLspShaderProgram()
      Creates a new shader program.
    • TLspShaderProgram

      public TLspShaderProgram(boolean aDestroyShaders)
      Creates a new shader program. By default, each TLspShaderProgram manages the lifetime of its associated TLspShader objects: the program destroys the shaders when it is destroyed itself. Setting aDestroyShaders to false disables this behavior, thus allowing shaders to be shared between different programs. Doing so leaves the responsibility for destroying the shaders to the user. For all added shaders you should either:
      Parameters:
      aDestroyShaders - whether the shaders should be destroyed when this program is destroyed
  • Method Details

    • add

      public void add(TLspShader aShader)
      Adds a shader to this shader program. If a shader is added multiple times, only one reference is stored.
      Parameters:
      aShader - the shader the shader to be added
      Throws:
      IllegalArgumentException - if aShader==null || aShader.getID()==-1
      IllegalStateException - when destroy was previously called on this shader program.
    • attachShaders

      public void attachShaders(ILcdGL aGL)
      Attaches the shaders to this program.
      Parameters:
      aGL - the ILcdGL object
      Throws:
      IllegalStateException - when destroy was previously called on this shader program.
    • link

      public void link(ILcdGL aGL)
      Link the shader program.
      Parameters:
      aGL - the ILcdGL object
      Throws:
      IllegalStateException - when destroy was previously called on this shader program.
    • bind

      public void bind(ILcdGLDrawable aGLDrawable)
      Description copied from class: ALspGLResource

      Binds this GL resource for use with the given ILcdGLDrawable. Implementations should override this method to perform the appropriate OpenGL call, e.g. glBindTexture(). Inheriting classes must also always invoke super.bind(), as this is required for the correct behavior of ALspGLResource.isBound().

      If this resource was already destroyed and the destroy implementation calls super.destroy, a runtime exception will be thrown when calling this method.

      Overrides:
      bind in class ALspGLResource
      Parameters:
      aGLDrawable - the GL drawable in which this resource is to be bound
    • unbind

      public void unbind(ILcdGLDrawable aGLDrawable)
      Description copied from class: ALspGLResource

      Unbinds this GL resource from the given ILcdGLDrawable. Implementations should override this method to perform whatever OpenGL calls are needed to undo the effects of ALspGLResource.bind(com.luciad.view.opengl.binding.ILcdGLDrawable). Inheriting classes must also always invoke super.unbind(), as this is required for the correct behavior of ALspGLResource.isBound().

      If this resource was already destroyed and the destroy implementation calls super.destroy, a runtime exception will be thrown when calling this method.

      Overrides:
      unbind in class ALspGLResource
      Parameters:
      aGLDrawable - the drawable from which the GL resource should be unbound
    • getID

      public int getID()
    • getShaders

      protected ArrayList<TLspShader> getShaders()
    • destroy

      public void destroy(ILcdGLDrawable aGLDrawable)
      Description copied from class: ALspGLResource

      Destroys the OpenGL resource so that it becomes no longer available nor valid to use.

      You should never call this yourself. The GL resource cache will automatically remove old resources. Alternatively, if you don't need the resource anymore, manually remove it from the GL resource cache.

      Extensions of this class should preferably call super.destroy. Doing so will add extra error checking in the bind and unbind methods, to make sure that no destroyed resources are used during painting (this may lead to native crashes).

      Overrides:
      destroy in class ALspGLResource
      Parameters:
      aGLDrawable - the drawable this resource is used for
    • getBytes

      public long getBytes()
      Description copied from class: ALspGLResource
      Gets the estimated number of bytes this resource occupies in GPU memory.
      Specified by:
      getBytes in class ALspGLResource
      Returns:
      the estimated number of bytes
    • setUniformData

      public void setUniformData(ILcdGL aGL, String aName, float aValue)
      Sets the uniform value.

      This method silently returns if there is no uniform variable with the given name.

      Parameters:
      aGL - the ILcdGL object
      aName - the name of the uniform variable
      aValue - the value associated with the given name
      Throws:
      IllegalStateException - when the shader program is not in use
    • setUniformData

      public void setUniformData(ILcdGL aGL, String aName, double aValue)
      Sets the uniform value. This is a conveniencie method: aValue is cast to a float before passing to ILcdGL.

      This method silently returns if there is no uniform variable with the given name.

      Parameters:
      aGL - the ILcdGL object
      aName - the name of the uniform variable
      aValue - the value associated with the given name
      Throws:
      IllegalStateException - when the shader program is not in use
    • setUniformData

      public void setUniformData(ILcdGL aGL, String aName, int aValue)
      Sets the uniform value.

      This method silently returns if there is no uniform variable with the given name.

      Parameters:
      aGL - the ILcdGL object
      aName - the name of the uniform variable
      aValue - the value associated with the given name
      Throws:
      IllegalStateException - when the shader program is not in use
    • setUniformData

      public void setUniformData(ILcdGL aGL, String aName, boolean aValue)
      Sets the uniform value. This is a convenience method: The boolean value is converted to 1 (true) or 0 (false) before setting as a uniform integer variable.

      This method silently returns if there is no uniform variable with the given name.

      Parameters:
      aGL - the ILcdGL object
      aName - the name of the uniform variable
      aValue - the value associated with the given name
      Throws:
      IllegalStateException - when the shader program is not in use
    • setUniformData

      public void setUniformData(ILcdGL aGL, String aName, int nbComponents, FloatBuffer aValues)
      Sets the uniform values.

      This method silently returns if there is no uniform variable with the given name.

      Parameters:
      aGL - the ILcdGL object
      aName - the name of the uniform variable
      nbComponents - the number of components in the float buffer
      aValues - the values associated with the given name
      Throws:
      IllegalStateException - when the shader program is not in use
    • setUniformData

      public void setUniformData(ILcdGL aGL, String aName, float aValue1, float aValue2)
      Sets the value of the vec2 uniform with given name.

      This method silently returns if there is no uniform variable with the given name.

      Parameters:
      aGL - the ILcdGL object
      aName - the name of the uniform variable
      aValue1 - the first coordinate of the vec2 uniform with given name
      aValue2 - the second coordinate of the vec2 uniform with given name
      Throws:
      IllegalStateException - when the shader program is not in use
    • setUniformData

      public void setUniformData(ILcdGL aGL, String aName, float aValue1, float aValue2, float aValue3)
      Sets the value of the vec3 uniform with given name.

      This method silently returns if there is no uniform variable with the given name.

      Parameters:
      aGL - the ILcdGL object
      aName - the name of the uniform variable
      aValue1 - the first coordinate of the vec3 uniform with given name
      aValue2 - the second coordinate of the vec3 uniform with given name
      aValue3 - the third coordinate of the vec3 uniform with given name
      Throws:
      IllegalStateException - when the shader program is not in use
    • setUniformData

      public void setUniformData(ILcdGL aGL, String aName, float aValue1, float aValue2, float aValue3, float aValue4)
      Sets the value of the vec4 uniform with given name.

      This method silently returns if there is no uniform variable with the given name.

      Parameters:
      aGL - the ILcdGL object
      aName - the name of the uniform variable
      aValue1 - the first coordinate of the vec4 uniform with given name
      aValue2 - the second coordinate of the vec4 uniform with given name
      aValue3 - the third coordinate of the vec4 uniform with given name
      aValue4 - the fourth coordinate of the vec4 uniform with given name
      Throws:
      IllegalStateException - when the shader program is not in use
    • setUniformMatrixData

      public void setUniformMatrixData(ILcdGL aGL, String aName, int nbMatrices, int aDimension, boolean aTranspose, FloatBuffer aValues)
    • setUniformMatrixData

      public void setUniformMatrixData(ILcdGL aGL, String aName, int aDimension, boolean aTranspose, FloatBuffer aValues)
      Sets the uniform matrix.

      This method silently returns if there is no uniform variable with the given name.

      Parameters:
      aGL - the ILcdGL object
      aName - the name of the uniform variable
      aDimension - the number of dimension of the matrix. Must be 2, 3 or 4.
      aTranspose - whether to transpose the matrix values. A value of 1 indicates that the matrix values are specified in row major order, zero is column major order
      aValues - the values associated with the given name
      Throws:
      IllegalStateException - when the shader program is not in use
    • setUniformData

      public void setUniformData(ILcdGL aGL, String aName, int aValue1, int aValue2)
      Sets the value of the ivec2 uniform with given name.

      This method silently returns if there is no uniform variable with the given name.

      Parameters:
      aGL - the ILcdGL object
      aName - the name of the uniform variable
      aValue1 - the first coordinate of the ivec2 uniform with given name
      aValue2 - the second coordinate of the ivec2 uniform with given name
      Throws:
      IllegalStateException - when the shader program is not in use
    • setUniformData

      public void setUniformData(ILcdGL aGL, String aName, int aValue1, int aValue2, int aValue3)
      Sets the value of the ivec3 uniform with given name.

      This method silently returns if there is no uniform variable with the given name.

      Parameters:
      aGL - the ILcdGL object
      aName - the name of the uniform variable
      aValue1 - the first coordinate of the ivec3 uniform with given name
      aValue2 - the second coordinate of the ivec3 uniform with given name
      aValue3 - the third coordinate of the ivec3 uniform with given name
      Throws:
      IllegalStateException - when the shader program is not in use
    • setUniformData

      public void setUniformData(ILcdGL aGL, String aName, int aValue1, int aValue2, int aValue3, int aValue4)
      Sets the value of the ivec4 uniform with given name.

      This method silently returns if there is no uniform variable with the given name.

      Parameters:
      aGL - the ILcdGL object
      aName - the name of the uniform variable
      aValue1 - the first coordinate of the ivec4 uniform with given name
      aValue2 - the second coordinate of the ivec4 uniform with given name
      aValue3 - the third coordinate of the ivec4 uniform with given name
      aValue4 - the fourth coordinate of the ivec4 uniform with given name
      Throws:
      IllegalStateException - when the shader program is not in use
    • setUniformData

      public void setUniformData(ILcdGL aGL, String aName, int nbComponents, IntBuffer aValues)
      Sets the uniform values.

      This method silently returns if there is no uniform variable with the given name.

      Parameters:
      aGL - the ILcdGL object
      aName - the name of the uniform variable
      nbComponents - the number of components in the integer buffer
      aValues - the values associated with the given name
      Throws:
      IllegalStateException - when the shader program is not in use
    • setVertexAttribData

      public void setVertexAttribData(ILcdGL aGL, String aName, float aValue)
      Sets the vertex attribute.

      This method silently returns if there is no vertex attribute with the given name.

      Parameters:
      aGL - the ILcdGL object
      aName - the name of the vertex attribute
      aValue - the value associated with the given name
      Throws:
      IllegalStateException - when the shader program is not in use
    • setVertexAttribData

      public void setVertexAttribData(ILcdGL aGL, String aName, double aValue)
      Sets the vertex attribute.

      This method silently returns if there is no vertex attribute with the given name.

      Parameters:
      aGL - the ILcdGL object
      aName - the name of the vertex attribute
      aValue - the value associated with the given name
      Throws:
      IllegalStateException - when the shader program is not in use
    • setVertexAttribData

      public void setVertexAttribData(ILcdGL aGL, String aName, short aValue)
      Sets the vertex attribute.

      This method silently returns if there is no vertex attribute with the given name.

      Parameters:
      aGL - the ILcdGL object
      aName - the name of the vertex attribute
      aValue - the value associated with the given name
      Throws:
      IllegalStateException - when the shader program is not in use
    • setVertexAttribData

      public void setVertexAttribData(ILcdGL aGL, String aName, int nbComponents, FloatBuffer aValues)
      Sets the vertex attribute values.

      This method silently returns if there is no vertex attribute with the given name.

      Parameters:
      aGL - the ILcdGL object
      aName - the name of the vertex attribute
      nbComponents - the number of components in the float buffer
      aValues - the values associated with the given name
      Throws:
      IllegalStateException - when the shader program is not in use
      IllegalArgumentException - if nbComponents<=0 || nbComponents>4
    • setVertexAttribData

      public void setVertexAttribData(ILcdGL aGL, String aName, int nbComponents, DoubleBuffer aValues)
      Sets the vertex attribute values.

      This method silently returns if there is no vertex attribute with the given name.

      Parameters:
      aGL - the ILcdGL object
      aName - the name of the vertex attribute
      nbComponents - the number of components in the float buffer
      aValues - the values associated with the given name
      Throws:
      IllegalStateException - when the shader program is not in use
      IllegalArgumentException - if nbComponents<=0 || nbComponents>4</code>
    • setVertexAttribData

      public void setVertexAttribData(ILcdGL aGL, String aName, int nbComponents, ShortBuffer aValues)
      Sets the vertex attribute values.

      This method silently returns if there is no vertex attribute with the given name.

      Parameters:
      aGL - the ILcdGL object
      aName - the name of the vertex attribute
      nbComponents - the number of components in the float buffer
      aValues - the values associated with the given name
      Throws:
      IllegalStateException - when the shader program is not in use
      IllegalArgumentException - if nbComponents <= 0 || nbComponents > 4
    • setVertexAttribArray

      public void setVertexAttribArray(ILcdGL aGL, String aName, int aNbComponents, int aType, boolean aNormalize, int aStride, Buffer aDirectBuffer)
      Sets the vertex attribute pointer for the given vertex attribute.
      Parameters:
      aGL - the ILcdGL object
      aName - the name of the vertex attribute
      aNbComponents - the number of components per vertex attribute. Must be 1,2,3 or 4.
      aType - the data type of each component
      aNormalize - specifies whether fixed-point data values should be normalized
      aStride - specifies the byte offset between consecutive attributes
      aDirectBuffer - the buffer containing the data, must be a direct buffer
      See Also:
    • disableVertexAttribArray

      public void disableVertexAttribArray(ILcdGL aGL, String aName)
      Disables the vertex attribute array associated with the given name.
      Parameters:
      aGL - the ILcdGL object
      aName - the name of the vertex attribute
      See Also:
    • getUniformLocation

      public int getUniformLocation(ILcdGL aGL, String aName)
      Gets the location associated with the given name for a uniform variable
      Parameters:
      aGL - the ILcdGL object
      aName - the name
      Returns:
      the location in the shader program associated with the given name or -1 if there is no uniform variable with the given name
    • getAttribLocation

      public int getAttribLocation(ILcdGL aGL, String aName)
      Gets the location associated with the given name for a vertex attribute
      Parameters:
      aGL - the ILcdGL object
      aName - the name
      Returns:
      the location in the shader program associated with the given name or -1 if there is no vertex attribute with the given name