public class TLspShaderProgram extends ALspGLResource
Constructor and Description |
---|
TLspShaderProgram()
Creates a new shader program.
|
TLspShaderProgram(boolean aDestroyShaders)
Creates a new shader program.
|
Modifier and Type | Method and Description |
---|---|
void |
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 given
ILcdGLDrawable . |
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 attribute
|
long |
getBytes()
Gets the estimated number of bytes this resource occupies
in GPU memory.
|
int |
getID() |
protected ArrayList<TLspShader> |
getShaders() |
int |
getUniformLocation(ILcdGL aGL,
String aName)
Gets the location associated with the given name for a uniform variable
|
void |
link(ILcdGL aGL)
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 the
vec2 uniform with given name. |
void |
setUniformData(ILcdGL aGL,
String aName,
float aValue1,
float aValue2,
float aValue3)
Sets the value of the
vec3 uniform with given name. |
void |
setUniformData(ILcdGL aGL,
String aName,
float aValue1,
float aValue2,
float aValue3,
float aValue4)
Sets the value of the
vec4 uniform with given name. |
void |
setUniformData(ILcdGL aGL,
String aName,
int aValue)
Sets the uniform value.
|
void |
setUniformData(ILcdGL aGL,
String aName,
int nbComponents,
FloatBuffer aValues)
Sets the uniform values.
|
void |
setUniformData(ILcdGL aGL,
String aName,
int aValue1,
int aValue2)
Sets the value of the
ivec2 uniform with given name. |
void |
setUniformData(ILcdGL aGL,
String aName,
int nbComponents,
IntBuffer aValues)
Sets the uniform values.
|
void |
setUniformData(ILcdGL aGL,
String aName,
int aValue1,
int aValue2,
int aValue3)
Sets the value of the
ivec3 uniform with given name. |
void |
setUniformData(ILcdGL aGL,
String aName,
int aValue1,
int aValue2,
int aValue3,
int aValue4)
Sets the value of the
ivec4 uniform with given name. |
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 given
ILcdGLDrawable . |
getSourceString, isBound, toString
public TLspShaderProgram()
public TLspShaderProgram(boolean aDestroyShaders)
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:
attachShaders(com.luciad.view.opengl.binding.ILcdGL)
aDestroyShaders
- whether the shaders should be destroyed when this program is destroyedpublic void add(TLspShader aShader)
aShader
- the shader the shader to be addedIllegalArgumentException
- if aShader==null || aShader.getID()==-1
IllegalStateException
- when destroy
was previously called on this shader program.public void attachShaders(ILcdGL aGL)
aGL
- the ILcdGL objectIllegalStateException
- when destroy
was previously called on this shader program.public void link(ILcdGL aGL)
aGL
- the ILcdGL objectIllegalStateException
- when destroy
was previously called on this shader program.public void bind(ILcdGLDrawable aGLDrawable)
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.
bind
in class ALspGLResource
aGLDrawable
- the GL drawable in which this resource is to be boundpublic void unbind(ILcdGLDrawable aGLDrawable)
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.
unbind
in class ALspGLResource
aGLDrawable
- the drawable from which the GL resource should be unboundpublic int getID()
protected ArrayList<TLspShader> getShaders()
public void destroy(ILcdGLDrawable aGLDrawable)
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).
destroy
in class ALspGLResource
aGLDrawable
- the drawable this resource is used forpublic long getBytes()
ALspGLResource
getBytes
in class ALspGLResource
public void setUniformData(ILcdGL aGL, String aName, float aValue)
aGL
- the ILcdGL objectaName
- the name of the uniform variableaValue
- the value associated with the given nameIllegalStateException
- when the shader program is not in usepublic void setUniformData(ILcdGL aGL, String aName, double aValue)
aGL
- the ILcdGL objectaName
- the name of the uniform variableaValue
- the value associated with the given nameIllegalStateException
- when the shader program is not in usepublic void setUniformData(ILcdGL aGL, String aName, int aValue)
aGL
- the ILcdGL objectaName
- the name of the uniform variableaValue
- the value associated with the given nameIllegalStateException
- when the shader program is not in usepublic void setUniformData(ILcdGL aGL, String aName, boolean aValue)
aGL
- the ILcdGL objectaName
- the name of the uniform variableaValue
- the value associated with the given nameIllegalStateException
- when the shader program is not in usepublic void setUniformData(ILcdGL aGL, String aName, int nbComponents, FloatBuffer aValues)
aGL
- the ILcdGL objectaName
- the name of the uniform variablenbComponents
- the number of components in the float bufferaValues
- the values associated with the given nameIllegalStateException
- when the shader program is not in usepublic void setUniformData(ILcdGL aGL, String aName, float aValue1, float aValue2)
vec2
uniform with given name.
This method silently returns if there is no uniform variable with the given name.aGL
- the ILcdGL objectaName
- the name of the uniform variableaValue1
- the first coordinate of the vec2
uniform with given nameaValue2
- the second coordinate of the vec2
uniform with given nameIllegalStateException
- when the shader program is not in usepublic void setUniformData(ILcdGL aGL, String aName, float aValue1, float aValue2, float aValue3)
vec3
uniform with given name.
This method silently returns if there is no uniform variable with the given name.aGL
- the ILcdGL objectaName
- the name of the uniform variableaValue1
- the first coordinate of the vec3
uniform with given nameaValue2
- the second coordinate of the vec3
uniform with given nameaValue3
- the third coordinate of the vec3
uniform with given nameIllegalStateException
- when the shader program is not in usepublic void setUniformData(ILcdGL aGL, String aName, float aValue1, float aValue2, float aValue3, float aValue4)
vec4
uniform with given name.
This method silently returns if there is no uniform variable with the given name.aGL
- the ILcdGL objectaName
- the name of the uniform variableaValue1
- the first coordinate of the vec4
uniform with given nameaValue2
- the second coordinate of the vec4
uniform with given nameaValue3
- the third coordinate of the vec4
uniform with given nameaValue4
- the fourth coordinate of the vec4
uniform with given nameIllegalStateException
- when the shader program is not in usepublic void setUniformMatrixData(ILcdGL aGL, String aName, int nbMatrices, int aDimension, boolean aTranspose, FloatBuffer aValues)
public void setUniformMatrixData(ILcdGL aGL, String aName, int aDimension, boolean aTranspose, FloatBuffer aValues)
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 nameIllegalStateException
- when the shader program is not in usepublic void setUniformData(ILcdGL aGL, String aName, int aValue1, int aValue2)
ivec2
uniform with given name.
This method silently returns if there is no uniform variable with
the given name.aGL
- the ILcdGL objectaName
- the name of the uniform variableaValue1
- the first coordinate of the ivec2
uniform with given nameaValue2
- the second coordinate of the ivec2
uniform with given nameIllegalStateException
- when the shader program is not in usepublic void setUniformData(ILcdGL aGL, String aName, int aValue1, int aValue2, int aValue3)
ivec3
uniform with given name.
This method silently returns if there is no uniform variable with
the given name.aGL
- the ILcdGL objectaName
- the name of the uniform variableaValue1
- the first coordinate of the ivec3
uniform with given nameaValue2
- the second coordinate of the ivec3
uniform with given nameaValue3
- the third coordinate of the ivec3
uniform with given nameIllegalStateException
- when the shader program is not in usepublic void setUniformData(ILcdGL aGL, String aName, int aValue1, int aValue2, int aValue3, int aValue4)
ivec4
uniform with given name.
This method silently returns if there is no uniform variable with
the given name.aGL
- the ILcdGL objectaName
- the name of the uniform variableaValue1
- the first coordinate of the ivec4
uniform with given nameaValue2
- the second coordinate of the ivec4
uniform with given nameaValue3
- the third coordinate of the ivec4
uniform with given nameaValue4
- the fourth coordinate of the ivec4
uniform with given nameIllegalStateException
- when the shader program is not in usepublic void setUniformData(ILcdGL aGL, String aName, int nbComponents, IntBuffer aValues)
aGL
- the ILcdGL objectaName
- the name of the uniform variablenbComponents
- the number of components in the integer bufferaValues
- the values associated with the given nameIllegalStateException
- when the shader program is not in usepublic void setVertexAttribData(ILcdGL aGL, String aName, float aValue)
aGL
- the ILcdGL objectaName
- the name of the vertex attributeaValue
- the value associated with the given nameIllegalStateException
- when the shader program is not in usepublic void setVertexAttribData(ILcdGL aGL, String aName, double aValue)
aGL
- the ILcdGL objectaName
- the name of the vertex attributeaValue
- the value associated with the given nameIllegalStateException
- when the shader program is not in usepublic void setVertexAttribData(ILcdGL aGL, String aName, short aValue)
aGL
- the ILcdGL objectaName
- the name of the vertex attributeaValue
- the value associated with the given nameIllegalStateException
- when the shader program is not in usepublic void setVertexAttribData(ILcdGL aGL, String aName, int nbComponents, FloatBuffer aValues)
aGL
- the ILcdGL objectaName
- the name of the vertex attributenbComponents
- the number of components in the float bufferaValues
- the values associated with the given nameIllegalStateException
- when the shader program is not in useIllegalArgumentException
- if nbComponents<=0 || nbComponents>4
public void setVertexAttribData(ILcdGL aGL, String aName, int nbComponents, DoubleBuffer aValues)
aGL
- the ILcdGL objectaName
- the name of the vertex attributenbComponents
- the number of components in the float bufferaValues
- the values associated with the given nameIllegalStateException
- when the shader program is not in useIllegalArgumentException
- if nbComponents<=0 || nbComponents>4</code>
public void setVertexAttribData(ILcdGL aGL, String aName, int nbComponents, ShortBuffer aValues)
aGL
- the ILcdGL objectaName
- the name of the vertex attributenbComponents
- the number of components in the float bufferaValues
- the values associated with the given nameIllegalStateException
- when the shader program is not in useIllegalArgumentException
- if nbComponents <= 0 || nbComponents > 4
public void setVertexAttribArray(ILcdGL aGL, String aName, int aNbComponents, int aType, boolean aNormalize, int aStride, Buffer aDirectBuffer)
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 bufferdisableVertexAttribArray(com.luciad.view.opengl.binding.ILcdGL, String)
,
ILcdGL.glEnableVertexAttribArray(int)
,
ILcdGL.glVertexAttribPointer(int, int, int, boolean, int, java.nio.Buffer)
public void disableVertexAttribArray(ILcdGL aGL, String aName)
aGL
- the ILcdGL objectaName
- the name of the vertex attributesetVertexAttribArray(com.luciad.view.opengl.binding.ILcdGL, String, int, int, boolean,
int, java.nio.Buffer)
public int getUniformLocation(ILcdGL aGL, String aName)
aGL
- the ILcdGL objectaName
- the namepublic int getAttribLocation(ILcdGL aGL, String aName)
aGL
- the ILcdGL objectaName
- the name