|
JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java (public API).
|
ShaderState allows to sharing data between shader programs, while updating the attribute and uniform locations when switching. More...
Public Member Functions | |
| ShaderState () | |
| boolean | verbose () |
| void | setVerbose (final boolean v) |
| final Object | getAttachedObject (final String name) |
| Returns the attached user object for the given name to this ShaderState. More... | |
| final Object | attachObject (final String name, final Object obj) |
| Attach user object for the given name to this ShaderState. More... | |
| final Object | detachObject (final String name) |
| synchronized void | useProgram (final GL2ES2 gl, final boolean on) throws GLException |
| Turns the shader program on or off. More... | |
| boolean | linked () |
| boolean | inUse () |
| synchronized boolean | attachShaderProgram (final GL2ES2 gl, final ShaderProgram prog, final boolean enable) throws GLException |
| Attach or switch a shader program. More... | |
| ShaderProgram | shaderProgram () |
| synchronized void | destroy (final GL2ES2 gl) |
Calls release(gl, true, true, true). More... | |
| synchronized void | releaseAllData (final GL2ES2 gl) |
Calls release(gl, false, false, false). More... | |
| synchronized void | release (final GL2ES2 gl, final boolean destroyBoundAttributes, final boolean destroyShaderProgram, final boolean destroyShaderCode) |
| int | getCachedAttribLocation (final String name) |
| Gets the cached location of a shader attribute. More... | |
| GLArrayData | getAttribute (final String name) |
| Get the previous cached vertex attribute data. More... | |
| boolean | isActiveAttribute (final GLArrayData attribute) |
| void | ownAttribute (final GLArrayData attribute, final boolean own) |
Binds or unbinds the GLArrayData lifecycle to this ShaderState. More... | |
| boolean | ownsAttribute (final GLArrayData attribute) |
| void | bindAttribLocation (final GL2ES2 gl, final int location, final String name) |
| Binds a shader attribute to a location. More... | |
| void | bindAttribLocation (final GL2ES2 gl, final int location, final GLArrayData data) |
Binds a shader GLArrayData attribute to a location. More... | |
| int | getAttribLocation (final GL2ES2 gl, final String name) |
Gets the location of a shader attribute with given name. More... | |
| int | getAttribLocation (final GL2ES2 gl, final GLArrayData data) |
| Validates and returns the location of a shader attribute. More... | |
| final boolean | isVertexAttribArrayEnabled (final String name) |
| final boolean | isVertexAttribArrayEnabled (final GLArrayData data) |
| boolean | enableVertexAttribArray (final GL2ES2 gl, final String name) |
| Enables a vertex attribute array. More... | |
| boolean | enableVertexAttribArray (final GL2ES2 gl, final GLArrayData data) |
Enables a vertex attribute array, usually invoked by GLArrayDataEditable#enableBuffer(GL, boolean). More... | |
| boolean | disableVertexAttribArray (final GL2ES2 gl, final String name) |
| Disables a vertex attribute array. More... | |
| boolean | disableVertexAttribArray (final GL2ES2 gl, final GLArrayData data) |
| Disables a vertex attribute array. More... | |
| boolean | vertexAttribPointer (final GL2ES2 gl, final GLArrayData data) |
Set the GLArrayData vertex attribute data, if it's location is valid, i.e. More... | |
| void | releaseAllAttributes (final GL2ES2 gl) |
| Releases all mapped vertex attribute data, disables all enabled attributes and loses all indices. More... | |
| void | disableAllVertexAttributeArrays (final GL2ES2 gl, final boolean removeFromState) |
| Disables all vertex attribute arrays. More... | |
| final int | getCachedUniformLocation (final String name) |
| Gets the cached location of the shader uniform. More... | |
| void | ownUniform (final GLUniformData uniform) |
Bind the GLUniform lifecycle to this ShaderState. More... | |
| boolean | ownsUniform (final GLUniformData uniform) |
| final int | getUniformLocation (final GL2ES2 gl, final String name) |
Gets the location of a shader uniform with given name. More... | |
| int | getUniformLocation (final GL2ES2 gl, final GLUniformData data) |
| Validates and returns the location of a shader uniform. More... | |
| boolean | uniform (final GL2ES2 gl, final GLUniformData data) |
| Set the uniform data, if it's location is valid, i.e. More... | |
| GLUniformData | getUniform (final String name) |
| Get the uniform data, previously set. More... | |
| void | releaseAllUniforms (final GL2ES2 gl) |
| Releases all mapped uniform data and loses all indices. More... | |
| StringBuilder | toString (StringBuilder sb, final boolean alsoUnlocated) |
| String | toString () |
Static Public Attributes | |
| static final boolean | DEBUG |
ShaderState allows to sharing data between shader programs, while updating the attribute and uniform locations when switching.
This allows seamless switching of programs using almost same data but performing different artifacts.
A used ShaderState is attached to the current GL context and can be retrieved via getShaderState(GL).
Definition at line 60 of file ShaderState.java.
| com.jogamp.opengl.util.glsl.ShaderState.ShaderState | ( | ) |
Definition at line 68 of file ShaderState.java.
| final Object com.jogamp.opengl.util.glsl.ShaderState.attachObject | ( | final String | name, |
| final Object | obj | ||
| ) |
Attach user object for the given name to this ShaderState.
Returns the previously set object or null.
Definition at line 88 of file ShaderState.java.
| synchronized boolean com.jogamp.opengl.util.glsl.ShaderState.attachShaderProgram | ( | final GL2ES2 | gl, |
| final ShaderProgram | prog, | ||
| final boolean | enable | ||
| ) | throws GLException |
Attach or switch a shader program.
Attaching a shader program the first time, as well as switching to another program on the fly, while managing all attribute and uniform data.
[Re]sets all data and use program in case of a program switch.
Use program, useProgram(GL2ES2, boolean), if enable is true.
| GLException | if program was not linked and linking fails |
Definition at line 159 of file ShaderState.java.
| void com.jogamp.opengl.util.glsl.ShaderState.bindAttribLocation | ( | final GL2ES2 | gl, |
| final int | location, | ||
| final GLArrayData | data | ||
| ) |
Binds a shader GLArrayData attribute to a location.
Multiple names can be bound to one location. The value will be cached and can be retrieved via getCachedAttribLocation(String) and getAttribute(String)before or after linking. The GLArrayData's location will be set as well.
| GLException | if no program is attached |
| GLException | if the program is already linked |
Definition at line 370 of file ShaderState.java.
| void com.jogamp.opengl.util.glsl.ShaderState.bindAttribLocation | ( | final GL2ES2 | gl, |
| final int | location, | ||
| final String | name | ||
| ) |
Binds a shader attribute to a location.
Multiple names can be bound to one location. The value will be cached and can be retrieved via getCachedAttribLocation(String) before or after linking.
| GLException | if no program is attached |
| GLException | if the program is already linked |
Definition at line 348 of file ShaderState.java.
| synchronized void com.jogamp.opengl.util.glsl.ShaderState.destroy | ( | final GL2ES2 | gl | ) |
Calls release(gl, true, true, true).
Definition at line 218 of file ShaderState.java.
| final Object com.jogamp.opengl.util.glsl.ShaderState.detachObject | ( | final String | name | ) |
| name | name of the mapped object to detach |
Definition at line 97 of file ShaderState.java.
| void com.jogamp.opengl.util.glsl.ShaderState.disableAllVertexAttributeArrays | ( | final GL2ES2 | gl, |
| final boolean | removeFromState | ||
| ) |
Disables all vertex attribute arrays.
Their enabled stated will be removed from this state only if 'removeFromState' is true.
This method purpose is more for debugging.
Definition at line 706 of file ShaderState.java.
| boolean com.jogamp.opengl.util.glsl.ShaderState.disableVertexAttribArray | ( | final GL2ES2 | gl, |
| final GLArrayData | data | ||
| ) |
Disables a vertex attribute array.
This method uses the GLArrayData's location if set and is the preferred alternative to disableVertexAttribArray(GL2ES2, String). If data location is unset it will be retrieved via getAttribLocation(GL2ES2, GLArrayData) set and cached in this state.
Even if the attribute is not found in the current shader, it is removed from this state enabled list.
| GLException | if no program is attached |
| GLException | if the program is not linked and no location was cached. |
Definition at line 620 of file ShaderState.java.
| boolean com.jogamp.opengl.util.glsl.ShaderState.disableVertexAttribArray | ( | final GL2ES2 | gl, |
| final String | name | ||
| ) |
Disables a vertex attribute array.
This method retrieves the the location via getAttribLocation(GL2ES2, GLArrayData) hence disableVertexAttribArray(GL2ES2, GLArrayData) shall be preferred.
Even if the attribute is not found in the current shader, it is removed from this state enabled list.
| GLException | if no program is attached |
| GLException | if the program is not linked and no location was cached. |
Definition at line 595 of file ShaderState.java.
| boolean com.jogamp.opengl.util.glsl.ShaderState.enableVertexAttribArray | ( | final GL2ES2 | gl, |
| final GLArrayData | data | ||
| ) |
Enables a vertex attribute array, usually invoked by GLArrayDataEditable#enableBuffer(GL, boolean).
This method uses the GLArrayData's location if set and is the preferred alternative to enableVertexAttribArray(GL2ES2, String). If data location is unset it will be retrieved via getAttribLocation(GL2ES2, GLArrayData) set and cached in this state.
Even if the attribute is not found in the current shader, it is marked enabled in this state.
| GLException | if the program is not linked and no location was cached. |
Definition at line 545 of file ShaderState.java.
| boolean com.jogamp.opengl.util.glsl.ShaderState.enableVertexAttribArray | ( | final GL2ES2 | gl, |
| final String | name | ||
| ) |
Enables a vertex attribute array.
This method retrieves the the location via getAttribLocation(GL2ES2, GLArrayData) hence enableVertexAttribArray(GL2ES2, GLArrayData) shall be preferred.
Even if the attribute is not found in the current shader, it is marked enabled in this state.
| GLException | if the program is not linked and no location was cached. |
Definition at line 519 of file ShaderState.java.
| final Object com.jogamp.opengl.util.glsl.ShaderState.getAttachedObject | ( | final String | name | ) |
Returns the attached user object for the given name to this ShaderState.
Definition at line 78 of file ShaderState.java.
| int com.jogamp.opengl.util.glsl.ShaderState.getAttribLocation | ( | final GL2ES2 | gl, |
| final GLArrayData | data | ||
| ) |
Validates and returns the location of a shader attribute.
Uses either the cached value getCachedAttribLocation(String) if valid, or the GLSL queried via GL2ES2#glGetAttribLocation(int, String).
The location will be cached and set in the GLArrayData object.
| GLException | if no program is attached |
| GLException | if the program is not linked and no location was cached. |
Definition at line 436 of file ShaderState.java.
| int com.jogamp.opengl.util.glsl.ShaderState.getAttribLocation | ( | final GL2ES2 | gl, |
| final String | name | ||
| ) |
Gets the location of a shader attribute with given name.
Uses either the cached value getCachedAttribLocation(String) if valid, or the GLSL queried via GL2ES2#glGetAttribLocation(int, String).
The location will be cached.
| GLException | if no program is attached |
| GLException | if the program is not linked and no location was cached. |
Definition at line 396 of file ShaderState.java.
| GLArrayData com.jogamp.opengl.util.glsl.ShaderState.getAttribute | ( | final String | name | ) |
Get the previous cached vertex attribute data.
Definition at line 290 of file ShaderState.java.
| int com.jogamp.opengl.util.glsl.ShaderState.getCachedAttribLocation | ( | final String | name | ) |
Gets the cached location of a shader attribute.
Definition at line 270 of file ShaderState.java.
| final int com.jogamp.opengl.util.glsl.ShaderState.getCachedUniformLocation | ( | final String | name | ) |
Gets the cached location of the shader uniform.
Definition at line 818 of file ShaderState.java.
| GLUniformData com.jogamp.opengl.util.glsl.ShaderState.getUniform | ( | final String | name | ) |
Get the uniform data, previously set.
Definition at line 967 of file ShaderState.java.
| int com.jogamp.opengl.util.glsl.ShaderState.getUniformLocation | ( | final GL2ES2 | gl, |
| final GLUniformData | data | ||
| ) |
Validates and returns the location of a shader uniform.
Uses either the cached value getCachedUniformLocation(String) if valid, or the GLSL queried via GL2ES2#glGetUniformLocation(int, String).
The location will be cached and set in the GLUniformData object.
The current shader program (attachShaderProgram(GL2ES2, ShaderProgram)) must be in use (useProgram(GL2ES2, boolean)) !
| GLException | is the program is not linked |
Definition at line 907 of file ShaderState.java.
| final int com.jogamp.opengl.util.glsl.ShaderState.getUniformLocation | ( | final GL2ES2 | gl, |
| final String | name | ||
| ) |
Gets the location of a shader uniform with given name.
Uses either the cached value getCachedUniformLocation(String) if valid, or the GLSL queried via GL2ES2#glGetUniformLocation(int, String).
The location will be cached.
The current shader program (attachShaderProgram(GL2ES2, ShaderProgram)) must be in use (useProgram(GL2ES2, boolean)) !
| GLException | is the program is not linked |
Definition at line 869 of file ShaderState.java.
| boolean com.jogamp.opengl.util.glsl.ShaderState.inUse | ( | ) |
| boolean com.jogamp.opengl.util.glsl.ShaderState.isActiveAttribute | ( | final GLArrayData | attribute | ) |
| final boolean com.jogamp.opengl.util.glsl.ShaderState.isVertexAttribArrayEnabled | ( | final GLArrayData | data | ) |
GLArrayData attribute is enable Definition at line 476 of file ShaderState.java.
| final boolean com.jogamp.opengl.util.glsl.ShaderState.isVertexAttribArrayEnabled | ( | final String | name | ) |
Definition at line 468 of file ShaderState.java.
| boolean com.jogamp.opengl.util.glsl.ShaderState.linked | ( | ) |
| void com.jogamp.opengl.util.glsl.ShaderState.ownAttribute | ( | final GLArrayData | attribute, |
| final boolean | own | ||
| ) |
Binds or unbinds the GLArrayData lifecycle to this ShaderState.
If an attribute location is cached (ie bindAttribLocation(GL2ES2, int, String)) it is promoted to the GLArrayData instance.
The attribute will be destroyed with destroy(GL2ES2) and it's location will be reset when switching shader with attachShaderProgram(GL2ES2, ShaderProgram).
The data will not be transfered to the GPU, use vertexAttribPointer(GL2ES2, GLArrayData) additionally.
The data will also be associated with this ShaderState.
| attribute | the GLArrayData which lifecycle shall be managed |
| own | true if owning shall be performs, false if disowning. |
Definition at line 318 of file ShaderState.java.
| boolean com.jogamp.opengl.util.glsl.ShaderState.ownsAttribute | ( | final GLArrayData | attribute | ) |
Definition at line 331 of file ShaderState.java.
| boolean com.jogamp.opengl.util.glsl.ShaderState.ownsUniform | ( | final GLUniformData | uniform | ) |
| void com.jogamp.opengl.util.glsl.ShaderState.ownUniform | ( | final GLUniformData | uniform | ) |
Bind the GLUniform lifecycle to this ShaderState.
If a uniform location is cached it is promoted to the GLUniformData instance.
The attribute will be destroyed with destroy(GL2ES2) and it's location will be reset when switching shader with attachShaderProgram(GL2ES2, ShaderProgram).
The data will not be transfered to the GPU, use uniform(GL2ES2, GLUniformData) additionally.
| uniform | the GLUniformData which lifecycle shall be managed |
Definition at line 837 of file ShaderState.java.
| synchronized void com.jogamp.opengl.util.glsl.ShaderState.release | ( | final GL2ES2 | gl, |
| final boolean | destroyBoundAttributes, | ||
| final boolean | destroyShaderProgram, | ||
| final boolean | destroyShaderCode | ||
| ) |
Definition at line 239 of file ShaderState.java.
| void com.jogamp.opengl.util.glsl.ShaderState.releaseAllAttributes | ( | final GL2ES2 | gl | ) |
Releases all mapped vertex attribute data, disables all enabled attributes and loses all indices.
Definition at line 674 of file ShaderState.java.
| synchronized void com.jogamp.opengl.util.glsl.ShaderState.releaseAllData | ( | final GL2ES2 | gl | ) |
Calls release(gl, false, false, false).
Definition at line 230 of file ShaderState.java.
| void com.jogamp.opengl.util.glsl.ShaderState.releaseAllUniforms | ( | final GL2ES2 | gl | ) |
Releases all mapped uniform data and loses all indices.
Definition at line 975 of file ShaderState.java.
| void com.jogamp.opengl.util.glsl.ShaderState.setVerbose | ( | final boolean | v | ) |
| ShaderProgram com.jogamp.opengl.util.glsl.ShaderState.shaderProgram | ( | ) |
Definition at line 209 of file ShaderState.java.
| String com.jogamp.opengl.util.glsl.ShaderState.toString | ( | ) |
Definition at line 1070 of file ShaderState.java.
| StringBuilder com.jogamp.opengl.util.glsl.ShaderState.toString | ( | StringBuilder | sb, |
| final boolean | alsoUnlocated | ||
| ) |
| boolean com.jogamp.opengl.util.glsl.ShaderState.uniform | ( | final GL2ES2 | gl, |
| final GLUniformData | data | ||
| ) |
Set the uniform data, if it's location is valid, i.e.
≥ 0.
This method uses the GLUniformData's location if valid, i.e. ≥ 0.
If data's location is invalid, it will be retrieved via getUniformLocation(GL2ES2, GLUniformData), set and cached in this state.
Definition at line 945 of file ShaderState.java.
| synchronized void com.jogamp.opengl.util.glsl.ShaderState.useProgram | ( | final GL2ES2 | gl, |
| final boolean | on | ||
| ) | throws GLException |
Turns the shader program on or off.
| GLException | if no program is attached |
Definition at line 108 of file ShaderState.java.
| boolean com.jogamp.opengl.util.glsl.ShaderState.verbose | ( | ) |
Definition at line 71 of file ShaderState.java.
| boolean com.jogamp.opengl.util.glsl.ShaderState.vertexAttribPointer | ( | final GL2ES2 | gl, |
| final GLArrayData | data | ||
| ) |
Set the GLArrayData vertex attribute data, if it's location is valid, i.e.
≥ 0.
This method uses the GLArrayData's location if valid, i.e. ≥ 0.
If data's location is invalid, it will be retrieved via getAttribLocation(GL2ES2, GLArrayData), set and cached in this state.
| GLException | if no program is attached |
| GLException | if the program is not linked and no location was cached. |
Definition at line 645 of file ShaderState.java.
|
static |
Definition at line 61 of file ShaderState.java.