Class TLspShaderProgram
- Direct Known Subclasses:
TLspSimpleShaderProgram
- Since:
- 2012.0
-
Constructor Summary
ConstructorDescriptionCreates a new shader program.TLspShaderProgram
(boolean aDestroyShaders) Creates a new shader program. -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(TLspShader aShader) Adds a shader to this shader program.void
attachShaders
(ILcdGL aGL) Attaches the shaders to this program.void
bind
(ILcdGLDrawable aGLDrawable) Binds this GL resource for use with the givenILcdGLDrawable
.void
destroy
(ILcdGLDrawable aGLDrawable) Destroys the OpenGL resource so that it becomes no longer available nor valid to use.void
disableVertexAttribArray
(ILcdGL aGL, String aName) Disables the vertex attribute array associated with the given name.int
getAttribLocation
(ILcdGL aGL, String aName) Gets the location associated with the given name for a vertex attributelong
getBytes()
Gets the estimated number of bytes this resource occupies in GPU memory.int
getID()
protected ArrayList
<TLspShader> int
getUniformLocation
(ILcdGL aGL, String aName) Gets the location associated with the given name for a uniform variablevoid
Link the shader program.void
setUniformData
(ILcdGL aGL, String aName, boolean aValue) Sets the uniform value.void
setUniformData
(ILcdGL aGL, String aName, double aValue) Sets the uniform value.void
setUniformData
(ILcdGL aGL, String aName, float aValue) Sets the uniform value.void
setUniformData
(ILcdGL aGL, String aName, float aValue1, float aValue2) Sets the value of thevec2
uniform with given name.void
setUniformData
(ILcdGL aGL, String aName, float aValue1, float aValue2, float aValue3) Sets the value of thevec3
uniform with given name.void
setUniformData
(ILcdGL aGL, String aName, float aValue1, float aValue2, float aValue3, float aValue4) Sets the value of thevec4
uniform with given name.void
setUniformData
(ILcdGL aGL, String aName, int aValue) Sets the uniform value.void
setUniformData
(ILcdGL aGL, String aName, int aValue1, int aValue2) Sets the value of theivec2
uniform with given name.void
setUniformData
(ILcdGL aGL, String aName, int aValue1, int aValue2, int aValue3) Sets the value of theivec3
uniform with given name.void
setUniformData
(ILcdGL aGL, String aName, int aValue1, int aValue2, int aValue3, int aValue4) Sets the value of theivec4
uniform with given name.void
setUniformData
(ILcdGL aGL, String aName, int nbComponents, FloatBuffer aValues) Sets the uniform values.void
setUniformData
(ILcdGL aGL, String aName, int nbComponents, IntBuffer aValues) Sets the uniform values.void
setUniformMatrixData
(ILcdGL aGL, String aName, int aDimension, boolean aTranspose, FloatBuffer aValues) Sets the uniform matrix.void
setUniformMatrixData
(ILcdGL aGL, String aName, int nbMatrices, int aDimension, boolean aTranspose, FloatBuffer aValues) 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.void
setVertexAttribData
(ILcdGL aGL, String aName, double aValue) Sets the vertex attribute.void
setVertexAttribData
(ILcdGL aGL, String aName, float aValue) Sets the vertex attribute.void
setVertexAttribData
(ILcdGL aGL, String aName, int nbComponents, DoubleBuffer aValues) Sets the vertex attribute values.void
setVertexAttribData
(ILcdGL aGL, String aName, int nbComponents, FloatBuffer aValues) Sets the vertex attribute values.void
setVertexAttribData
(ILcdGL aGL, String aName, int nbComponents, ShortBuffer aValues) Sets the vertex attribute values.void
setVertexAttribData
(ILcdGL aGL, String aName, short aValue) Sets the vertex attribute.void
unbind
(ILcdGLDrawable aGLDrawable) Unbinds this GL resource from the givenILcdGLDrawable
.Methods inherited from class com.luciad.view.lightspeed.services.glcache.ALspGLResource
getSourceString, isBound, toString
-
Constructor Details
-
TLspShaderProgram
public TLspShaderProgram()Creates a new shader program. -
TLspShaderProgram
public TLspShaderProgram(boolean aDestroyShaders) Creates a new shader program. By default, eachTLspShaderProgram
manages the lifetime of its associatedTLspShader
objects: the program destroys the shaders when it is destroyed itself. SettingaDestroyShaders
tofalse
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:- immediately destroy the shaders after calling
attachShaders(com.luciad.view.opengl.binding.ILcdGL)
- share shaders with other programs, and destroy them when they are no longer used by any programs
- Parameters:
aDestroyShaders
- whether the shaders should be destroyed when this program is destroyed
- immediately destroy the shaders after calling
-
-
Method Details
-
add
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
- whendestroy
was previously called on this shader program.
-
attachShaders
Attaches the shaders to this program.- Parameters:
aGL
- the ILcdGL object- Throws:
IllegalStateException
- whendestroy
was previously called on this shader program.
-
link
Link the shader program.- Parameters:
aGL
- the ILcdGL object- Throws:
IllegalStateException
- whendestroy
was previously called on this shader program.
-
bind
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 invokesuper.bind()
, as this is required for the correct behavior ofALspGLResource.isBound()
.If this resource was already destroyed and the
destroy
implementation callssuper.destroy
, a runtime exception will be thrown when calling this method.- Overrides:
bind
in classALspGLResource
- Parameters:
aGLDrawable
- the GL drawable in which this resource is to be bound
-
unbind
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 ofALspGLResource.bind(com.luciad.view.opengl.binding.ILcdGLDrawable)
. Inheriting classes must also always invokesuper.unbind()
, as this is required for the correct behavior ofALspGLResource.isBound()
.If this resource was already destroyed and the
destroy
implementation callssuper.destroy
, a runtime exception will be thrown when calling this method.- Overrides:
unbind
in classALspGLResource
- Parameters:
aGLDrawable
- the drawable from which the GL resource should be unbound
-
getID
public int getID() -
getShaders
-
destroy
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 thebind
andunbind
methods, to make sure that no destroyed resources are used during painting (this may lead to native crashes).- Overrides:
destroy
in classALspGLResource
- 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 classALspGLResource
- Returns:
- the estimated number of bytes
-
setUniformData
Sets the uniform value. This method silently returns if there is no uniform variable with the given name.- Parameters:
aGL
- the ILcdGL objectaName
- the name of the uniform variableaValue
- the value associated with the given name- Throws:
IllegalStateException
- when the shader program is not in use
-
setUniformData
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 objectaName
- the name of the uniform variableaValue
- the value associated with the given name- Throws:
IllegalStateException
- when the shader program is not in use
-
setUniformData
Sets the uniform value. This method silently returns if there is no uniform variable with the given name.- Parameters:
aGL
- the ILcdGL objectaName
- the name of the uniform variableaValue
- the value associated with the given name- Throws:
IllegalStateException
- when the shader program is not in use
-
setUniformData
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 objectaName
- the name of the uniform variableaValue
- the value associated with the given name- Throws:
IllegalStateException
- when the shader program is not in use
-
setUniformData
Sets the uniform values. This method silently returns if there is no uniform variable with the given name.- Parameters:
aGL
- the ILcdGL objectaName
- the name of the uniform variablenbComponents
- the number of components in the float bufferaValues
- the values associated with the given name- Throws:
IllegalStateException
- when the shader program is not in use
-
setUniformData
Sets the value of thevec2
uniform with given name. This method silently returns if there is no uniform variable with the given name.- Parameters:
aGL
- the ILcdGL objectaName
- the name of the uniform variableaValue1
- the first coordinate of thevec2
uniform with given nameaValue2
- the second coordinate of thevec2
uniform with given name- Throws:
IllegalStateException
- when the shader program is not in use
-
setUniformData
Sets the value of thevec3
uniform with given name. This method silently returns if there is no uniform variable with the given name.- Parameters:
aGL
- the ILcdGL objectaName
- the name of the uniform variableaValue1
- the first coordinate of thevec3
uniform with given nameaValue2
- the second coordinate of thevec3
uniform with given nameaValue3
- the third coordinate of thevec3
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 thevec4
uniform with given name. This method silently returns if there is no uniform variable with the given name.- Parameters:
aGL
- the ILcdGL objectaName
- the name of the uniform variableaValue1
- the first coordinate of thevec4
uniform with given nameaValue2
- the second coordinate of thevec4
uniform with given nameaValue3
- the third coordinate of thevec4
uniform with given nameaValue4
- the fourth coordinate of thevec4
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 objectaName
- the name of the uniform variableaDimension
- 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 orderaValues
- the values associated with the given name- Throws:
IllegalStateException
- when the shader program is not in use
-
setUniformData
Sets the value of theivec2
uniform with given name. This method silently returns if there is no uniform variable with the given name.- Parameters:
aGL
- the ILcdGL objectaName
- the name of the uniform variableaValue1
- the first coordinate of theivec2
uniform with given nameaValue2
- the second coordinate of theivec2
uniform with given name- Throws:
IllegalStateException
- when the shader program is not in use
-
setUniformData
Sets the value of theivec3
uniform with given name. This method silently returns if there is no uniform variable with the given name.- Parameters:
aGL
- the ILcdGL objectaName
- the name of the uniform variableaValue1
- the first coordinate of theivec3
uniform with given nameaValue2
- the second coordinate of theivec3
uniform with given nameaValue3
- the third coordinate of theivec3
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 theivec4
uniform with given name. This method silently returns if there is no uniform variable with the given name.- Parameters:
aGL
- the ILcdGL objectaName
- the name of the uniform variableaValue1
- the first coordinate of theivec4
uniform with given nameaValue2
- the second coordinate of theivec4
uniform with given nameaValue3
- the third coordinate of theivec4
uniform with given nameaValue4
- the fourth coordinate of theivec4
uniform with given name- Throws:
IllegalStateException
- when the shader program is not in use
-
setUniformData
Sets the uniform values. This method silently returns if there is no uniform variable with the given name.- Parameters:
aGL
- the ILcdGL objectaName
- the name of the uniform variablenbComponents
- the number of components in the integer bufferaValues
- the values associated with the given name- Throws:
IllegalStateException
- when the shader program is not in use
-
setVertexAttribData
Sets the vertex attribute. This method silently returns if there is no vertex attribute with the given name.- Parameters:
aGL
- the ILcdGL objectaName
- the name of the vertex attributeaValue
- the value associated with the given name- Throws:
IllegalStateException
- when the shader program is not in use
-
setVertexAttribData
Sets the vertex attribute. This method silently returns if there is no vertex attribute with the given name.- Parameters:
aGL
- the ILcdGL objectaName
- the name of the vertex attributeaValue
- the value associated with the given name- Throws:
IllegalStateException
- when the shader program is not in use
-
setVertexAttribData
Sets the vertex attribute. This method silently returns if there is no vertex attribute with the given name.- Parameters:
aGL
- the ILcdGL objectaName
- the name of the vertex attributeaValue
- the value associated with the given name- Throws:
IllegalStateException
- when the shader program is not in use
-
setVertexAttribData
Sets the vertex attribute values. This method silently returns if there is no vertex attribute with the given name.- Parameters:
aGL
- the ILcdGL objectaName
- the name of the vertex attributenbComponents
- the number of components in the float bufferaValues
- the values associated with the given name- Throws:
IllegalStateException
- when the shader program is not in useIllegalArgumentException
-if nbComponents<=0 || nbComponents>4
-
setVertexAttribData
Sets the vertex attribute values. This method silently returns if there is no vertex attribute with the given name.- Parameters:
aGL
- the ILcdGL objectaName
- the name of the vertex attributenbComponents
- the number of components in the float bufferaValues
- the values associated with the given name- Throws:
IllegalStateException
- when the shader program is not in useIllegalArgumentException
-if nbComponents<=0 || nbComponents>4</code>
-
setVertexAttribData
Sets the vertex attribute values. This method silently returns if there is no vertex attribute with the given name.- Parameters:
aGL
- the ILcdGL objectaName
- the name of the vertex attributenbComponents
- the number of components in the float bufferaValues
- the values associated with the given name- Throws:
IllegalStateException
- when the shader program is not in useIllegalArgumentException
-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 objectaName
- the name of the vertex attributeaNbComponents
- the number of components per vertex attribute. Must be 1,2,3 or 4.aType
- the data type of each componentaNormalize
- specifies whether fixed-point data values should be normalizedaStride
- specifies the byte offset between consecutive attributesaDirectBuffer
- the buffer containing the data, must be a direct buffer- See Also:
-
disableVertexAttribArray
Disables the vertex attribute array associated with the given name.- Parameters:
aGL
- the ILcdGL objectaName
- the name of the vertex attribute- See Also:
-
getUniformLocation
Gets the location associated with the given name for a uniform variable- Parameters:
aGL
- the ILcdGL objectaName
- 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
Gets the location associated with the given name for a vertex attribute- Parameters:
aGL
- the ILcdGL objectaName
- 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
-