Class TLspShaderProgram
- Direct Known Subclasses:
TLspSimpleShaderProgram
- Since:
- 2012.0
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new shader program.TLspShaderProgram(boolean aDestroyShaders) Creates a new shader program. -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(TLspShader aShader) Adds a shader to this shader program.voidattachShaders(ILcdGL aGL) Attaches the shaders to this program.voidbind(ILcdGLDrawable aGLDrawable) Binds this GL resource for use with the givenILcdGLDrawable.voiddestroy(ILcdGLDrawable aGLDrawable) Destroys the OpenGL resource so that it becomes no longer available nor valid to use.voiddisableVertexAttribArray(ILcdGL aGL, String aName) Disables the vertex attribute array associated with the given name.intgetAttribLocation(ILcdGL aGL, String aName) Gets the location associated with the given name for a vertex attributelonggetBytes()Gets the estimated number of bytes this resource occupies in GPU memory.intgetID()protected ArrayList<TLspShader> intgetUniformLocation(ILcdGL aGL, String aName) Gets the location associated with the given name for a uniform variablevoidLink the shader program.voidsetUniformData(ILcdGL aGL, String aName, boolean aValue) Sets the uniform value.voidsetUniformData(ILcdGL aGL, String aName, double aValue) Sets the uniform value.voidsetUniformData(ILcdGL aGL, String aName, float aValue) Sets the uniform value.voidsetUniformData(ILcdGL aGL, String aName, float aValue1, float aValue2) Sets the value of thevec2uniform with given name.voidsetUniformData(ILcdGL aGL, String aName, float aValue1, float aValue2, float aValue3) Sets the value of thevec3uniform with given name.voidsetUniformData(ILcdGL aGL, String aName, float aValue1, float aValue2, float aValue3, float aValue4) Sets the value of thevec4uniform with given name.voidsetUniformData(ILcdGL aGL, String aName, int aValue) Sets the uniform value.voidsetUniformData(ILcdGL aGL, String aName, int aValue1, int aValue2) Sets the value of theivec2uniform with given name.voidsetUniformData(ILcdGL aGL, String aName, int aValue1, int aValue2, int aValue3) Sets the value of theivec3uniform with given name.voidsetUniformData(ILcdGL aGL, String aName, int aValue1, int aValue2, int aValue3, int aValue4) Sets the value of theivec4uniform with given name.voidsetUniformData(ILcdGL aGL, String aName, int nbComponents, FloatBuffer aValues) Sets the uniform values.voidsetUniformData(ILcdGL aGL, String aName, int nbComponents, IntBuffer aValues) Sets the uniform values.voidsetUniformMatrixData(ILcdGL aGL, String aName, int aDimension, boolean aTranspose, FloatBuffer aValues) Sets the uniform matrix.voidsetUniformMatrixData(ILcdGL aGL, String aName, int nbMatrices, int aDimension, boolean aTranspose, FloatBuffer aValues) voidsetVertexAttribArray(ILcdGL aGL, String aName, int aNbComponents, int aType, boolean aNormalize, int aStride, Buffer aDirectBuffer) Sets the vertex attribute pointer for the given vertex attribute.voidsetVertexAttribData(ILcdGL aGL, String aName, double aValue) Sets the vertex attribute.voidsetVertexAttribData(ILcdGL aGL, String aName, float aValue) Sets the vertex attribute.voidsetVertexAttribData(ILcdGL aGL, String aName, int nbComponents, DoubleBuffer aValues) Sets the vertex attribute values.voidsetVertexAttribData(ILcdGL aGL, String aName, int nbComponents, FloatBuffer aValues) Sets the vertex attribute values.voidsetVertexAttribData(ILcdGL aGL, String aName, int nbComponents, ShortBuffer aValues) Sets the vertex attribute values.voidsetVertexAttribData(ILcdGL aGL, String aName, short aValue) Sets the vertex attribute.voidunbind(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, eachTLspShaderProgrammanages the lifetime of its associatedTLspShaderobjects: the program destroys the shaders when it is destroyed itself. SettingaDestroyShaderstofalsedisables 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()==-1IllegalStateException- whendestroywas previously called on this shader program.
-
attachShaders
Attaches the shaders to this program.- Parameters:
aGL- the ILcdGL object- Throws:
IllegalStateException- whendestroywas previously called on this shader program.
-
link
Link the shader program.- Parameters:
aGL- the ILcdGL object- Throws:
IllegalStateException- whendestroywas previously called on this shader program.
-
bind
Description copied from class:ALspGLResourceBinds 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
destroyimplementation callssuper.destroy, a runtime exception will be thrown when calling this method.- Overrides:
bindin classALspGLResource- Parameters:
aGLDrawable- the GL drawable in which this resource is to be bound
-
unbind
Description copied from class:ALspGLResourceUnbinds 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
destroyimplementation callssuper.destroy, a runtime exception will be thrown when calling this method.- Overrides:
unbindin classALspGLResource- Parameters:
aGLDrawable- the drawable from which the GL resource should be unbound
-
getID
public int getID() -
getShaders
-
destroy
Description copied from class:ALspGLResourceDestroys 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
removeit from the GL resource cache.Extensions of this class should preferably call
super.destroy. Doing so will add extra error checking in thebindandunbindmethods, to make sure that no destroyed resources are used during painting (this may lead to native crashes).- Overrides:
destroyin classALspGLResource- Parameters:
aGLDrawable- the drawable this resource is used for
-
getBytes
public long getBytes()Description copied from class:ALspGLResourceGets the estimated number of bytes this resource occupies in GPU memory.- Specified by:
getBytesin 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 thevec2uniform 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 thevec2uniform with given nameaValue2- the second coordinate of thevec2uniform with given name- Throws:
IllegalStateException- when the shader program is not in use
-
setUniformData
Sets the value of thevec3uniform 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 thevec3uniform with given nameaValue2- the second coordinate of thevec3uniform with given nameaValue3- the third coordinate of thevec3uniform 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 thevec4uniform 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 thevec4uniform with given nameaValue2- the second coordinate of thevec4uniform with given nameaValue3- the third coordinate of thevec4uniform with given nameaValue4- the fourth coordinate of thevec4uniform 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 theivec2uniform 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 theivec2uniform with given nameaValue2- the second coordinate of theivec2uniform with given name- Throws:
IllegalStateException- when the shader program is not in use
-
setUniformData
Sets the value of theivec3uniform 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 theivec3uniform with given nameaValue2- the second coordinate of theivec3uniform with given nameaValue3- the third coordinate of theivec3uniform 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 theivec4uniform 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 theivec4uniform with given nameaValue2- the second coordinate of theivec4uniform with given nameaValue3- the third coordinate of theivec4uniform with given nameaValue4- the fourth coordinate of theivec4uniform 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
-