com.jogamp.opengl.util.glsl
public class ShaderState extends Object
Modifier and Type | Field and Description |
---|---|
static boolean |
DEBUG |
Constructor and Description |
---|
ShaderState() |
Modifier and Type | Method and Description |
---|---|
Object |
attachObject(int name,
Object obj)
Attach user object for the given name to this ShaderState.
|
Object |
attachObject(String name,
Object obj)
Attach user object for the given name to this ShaderState.
|
void |
attachShaderProgram(GL2ES2 gl,
ShaderProgram prog)
Attach or switch a shader program
|
void |
bindAttribLocation(GL2ES2 gl,
int location,
GLArrayData data)
Binds a shader
GLArrayData attribute to a location. |
void |
bindAttribLocation(GL2ES2 gl,
int location,
String name)
Binds a shader attribute to a location.
|
void |
destroy(GL2ES2 gl)
|
Object |
detachObject(int name) |
Object |
detachObject(String name) |
void |
disableAllVertexAttributeArrays(GL2ES2 gl,
boolean removeFromState)
Disables all vertex attribute arrays.
|
boolean |
disableVertexAttribArray(GL2ES2 gl,
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) . |
boolean |
disableVertexAttribArray(GL2ES2 gl,
String name)
Disables a vertex attribute array
This method retrieves the the location via
getAttribLocation(GL2ES2, GLArrayData)
hence disableVertexAttribArray(GL2ES2, GLArrayData) shall be preferred. |
boolean |
enableVertexAttribArray(GL2ES2 gl,
GLArrayData data)
Enables a vertex attribute array, usually invoked by
GLArrayDataEditable.enableBuffer(GL, boolean) . |
boolean |
enableVertexAttribArray(GL2ES2 gl,
String name)
Enables a vertex attribute array.
|
Object |
getAttachedObject(int name)
Returns the attached user object for the given name to this ShaderState.
|
Object |
getAttachedObject(String name)
Returns the attached user object for the given name to this ShaderState.
|
int |
getAttribLocation(GL2ES2 gl,
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. |
int |
getAttribLocation(GL2ES2 gl,
String name)
Gets 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. |
GLArrayData |
getAttribute(String name)
Get the previous cached vertex attribute data.
|
int |
getCachedAttribLocation(String name)
Gets the cached location of a shader attribute.
|
int |
getCachedUniformLocation(String name)
Gets the cached location of the shader uniform.
|
static ShaderState |
getCurrentShaderState()
Fetches the current shader state from this thread (TLS) current GLContext
|
static ShaderState |
getShaderState(GL gl)
Gets the shader state attached to the GL object's GLContext
|
GLUniformData |
getUniform(String name)
Get the uniform data, previously set.
|
int |
getUniformLocation(GL2ES2 gl,
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. |
int |
getUniformLocation(GL2ES2 gl,
String name)
Gets 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. |
boolean |
inUse() |
boolean |
isVertexAttribArrayEnabled(GLArrayData data) |
boolean |
isVertexAttribArrayEnabled(String name) |
boolean |
linked() |
void |
ownAttribute(GLArrayData attribute,
boolean own)
Binds or unbinds the
GLArrayData lifecycle to this ShaderState. |
boolean |
ownsAttribute(GLArrayData attribute) |
boolean |
ownsUniform(GLUniformData uniform) |
void |
ownUniform(GLUniformData uniform)
Bind the
GLUniform lifecycle to this ShaderState. |
void |
release(GL2ES2 gl,
boolean destroyBoundAttributes,
boolean releaseProgramToo,
boolean releaseShaderToo) |
void |
releaseAllAttributes(GL2ES2 gl)
Releases all mapped vertex attribute data,
disables all enabled attributes and loses all indices
|
void |
releaseAllData(GL2ES2 gl)
|
void |
releaseAllUniforms(GL2ES2 gl)
Releases all mapped uniform data
and loses all indices
|
ShaderState |
setShaderState(GL gl)
Attaches the shader state to the GL object's GLContext
|
void |
setVerbose(boolean v) |
ShaderProgram |
shaderProgram() |
String |
toString() |
StringBuilder |
toString(StringBuilder sb) |
boolean |
uniform(GL2ES2 gl,
GLUniformData data)
Set the uniform data.
|
void |
useProgram(GL2ES2 gl,
boolean on)
Turns the shader program on or off.
Puts this ShaderState to to the thread local storage (TLS), if on is true . |
boolean |
verbose() |
boolean |
vertexAttribPointer(GL2ES2 gl,
GLArrayData data)
Set the
GLArrayData vertex attribute data. |
public boolean verbose()
public void setVerbose(boolean v)
public static ShaderState getCurrentShaderState()
public static ShaderState getShaderState(GL gl)
gl
- the GL object referencing the GLContextuseProgram(GL2ES2, boolean)
,
getShaderState(GL)
,
setShaderState(GL)
,
getCurrentShaderState()
public final ShaderState setShaderState(GL gl)
gl
- the GL object referencing the GLContextuseProgram(GL2ES2, boolean)
,
getShaderState(GL)
,
setShaderState(GL)
,
getCurrentShaderState()
public final Object getAttachedObject(String name)
public final Object attachObject(String name, Object obj)
public final Object detachObject(String name)
name
- name of the mapped object to detachpublic final Object getAttachedObject(int name)
public final Object attachObject(int name, Object obj)
public final Object detachObject(int name)
public void useProgram(GL2ES2 gl, boolean on) throws GLException
on
is true
.GLException
- if no program is attacheduseProgram(GL2ES2, boolean)
,
getShaderState(GL)
,
getCurrentShaderState()
public boolean linked()
public boolean inUse()
public void attachShaderProgram(GL2ES2 gl, ShaderProgram prog) throws GLException
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 if linked in case of a 1st time attachment.
GLException
- if program was not linked and linking failspublic ShaderProgram shaderProgram()
public void destroy(GL2ES2 gl)
#glReleaseAllVertexAttributes
,
#glReleaseAllUniforms
,
release(GL2ES2, boolean, boolean, boolean)
public void releaseAllData(GL2ES2 gl)
#glReleaseAllVertexAttributes
,
#glReleaseAllUniforms
,
release(GL2ES2, boolean, boolean, boolean)
public void release(GL2ES2 gl, boolean destroyBoundAttributes, boolean releaseProgramToo, boolean releaseShaderToo)
#glReleaseAllVertexAttributes
,
#glReleaseAllUniforms
,
ShaderProgram.release(GL2ES2, boolean)
public int getCachedAttribLocation(String name)
bindAttribLocation(GL2ES2, int, String)
,
bindAttribLocation(GL2ES2, int, GLArrayData)
,
getAttribLocation(GL2ES2, String)
,
GL2ES2.glGetAttribLocation(int, String)
public GLArrayData getAttribute(String name)
ownAttribute(GLArrayData, boolean)
,
#glEnableVertexAttribArray
,
#glDisableVertexAttribArray
,
#glVertexAttribPointer
,
#getVertexAttribPointer
,
#glReleaseAllVertexAttributes
,
#glResetAllVertexAttributes
,
ShaderProgram#glReplaceShader
public void ownAttribute(GLArrayData attribute, boolean own)
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.
attribute
- the GLArrayData
which lifecycle shall be managedown
- true if owning shall be performs, false if disowning.bindAttribLocation(GL2ES2, int, String)
,
getAttribute(String)
public boolean ownsAttribute(GLArrayData attribute)
public void bindAttribLocation(GL2ES2 gl, int location, String name)
getCachedAttribLocation(String)
before or after linking.GLException
- if no program is attachedGLException
- if the program is already linkedGL2ES2.glBindAttribLocation(int, int, String)
,
getAttribLocation(GL2ES2, String)
,
getCachedAttribLocation(String)
public void bindAttribLocation(GL2ES2 gl, int location, GLArrayData data)
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 attachedGLException
- if the program is already linkedGL2ES2.glBindAttribLocation(int, int, String)
,
getAttribLocation(GL2ES2, String)
,
getCachedAttribLocation(String)
,
getAttribute(String)
public int getAttribLocation(GL2ES2 gl, String name)
getCachedAttribLocation(String)
if valid,
or the GLSL queried via GL2ES2.glGetAttribLocation(int, String)
.GLException
- if no program is attachedGLException
- if the program is not linked and no location was cached.getCachedAttribLocation(String)
,
bindAttribLocation(GL2ES2, int, GLArrayData)
,
bindAttribLocation(GL2ES2, int, String)
,
GL2ES2.glGetAttribLocation(int, String)
public int getAttribLocation(GL2ES2 gl, GLArrayData data)
getCachedAttribLocation(String)
if valid,
or the GLSL queried via GL2ES2.glGetAttribLocation(int, String)
.GLArrayData
object.GLException
- if no program is attachedGLException
- if the program is not linked and no location was cached.getCachedAttribLocation(String)
,
bindAttribLocation(GL2ES2, int, GLArrayData)
,
bindAttribLocation(GL2ES2, int, String)
,
GL2ES2.glGetAttribLocation(int, String)
,
getAttribute(String)
public final boolean isVertexAttribArrayEnabled(String name)
public final boolean isVertexAttribArrayEnabled(GLArrayData data)
GLArrayData
attribute is enablepublic boolean enableVertexAttribArray(GL2ES2 gl, String name)
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.#glEnableVertexAttribArray
,
#glDisableVertexAttribArray
,
#glVertexAttribPointer
,
#getVertexAttribPointer
public boolean enableVertexAttribArray(GL2ES2 gl, GLArrayData data)
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.#glEnableVertexAttribArray
,
#glDisableVertexAttribArray
,
#glVertexAttribPointer
,
#getVertexAttribPointer
,
GLArrayDataEditable.enableBuffer(GL, boolean)
public boolean disableVertexAttribArray(GL2ES2 gl, String name)
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 attachedGLException
- if the program is not linked and no location was cached.#glEnableVertexAttribArray
,
#glDisableVertexAttribArray
,
#glVertexAttribPointer
,
#getVertexAttribPointer
public boolean disableVertexAttribArray(GL2ES2 gl, GLArrayData data)
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 attachedGLException
- if the program is not linked and no location was cached.#glEnableVertexAttribArray
,
#glDisableVertexAttribArray
,
#glVertexAttribPointer
,
#getVertexAttribPointer
public boolean vertexAttribPointer(GL2ES2 gl, GLArrayData data)
GLArrayData
vertex attribute data.
This method uses the GLArrayData
's location if set.
If data location is unset it will be retrieved via getAttribLocation(GL2ES2, GLArrayData)
, set
and cached in this state.GLException
- if no program is attachedGLException
- if the program is not linked and no location was cached.#glEnableVertexAttribArray
,
#glDisableVertexAttribArray
,
#glVertexAttribPointer
,
#getVertexAttribPointer
public void releaseAllAttributes(GL2ES2 gl)
#glEnableVertexAttribArray
,
#glDisableVertexAttribArray
,
#glVertexAttribPointer
,
#getVertexAttribPointer
,
#glReleaseAllVertexAttributes
,
#glResetAllVertexAttributes
,
#glResetAllVertexAttributes
,
ShaderProgram#glReplaceShader
public void disableAllVertexAttributeArrays(GL2ES2 gl, boolean removeFromState)
#glEnableVertexAttribArray
,
#glDisableVertexAttribArray
,
#glVertexAttribPointer
,
#getVertexAttribPointer
,
#glReleaseAllVertexAttributes
,
#glResetAllVertexAttributes
,
#glResetAllVertexAttributes
,
ShaderProgram#glReplaceShader
public final int getCachedUniformLocation(String name)
public void ownUniform(GLUniformData uniform)
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 managedgetUniform(String)
public boolean ownsUniform(GLUniformData uniform)
public final int getUniformLocation(GL2ES2 gl, String name)
getCachedUniformLocation(String)
if valid,
or the GLSL queried via GL2ES2.glGetUniformLocation(int, String)
.
The current shader program (attachShaderProgram(GL2ES2, ShaderProgram)
)
must be in use (useProgram(GL2ES2, boolean)
) !
GLException
- is the program is not linked#glGetUniformLocation
,
GL2ES2.glGetUniformLocation(int, java.lang.String)
,
getUniformLocation(javax.media.opengl.GL2ES2, java.lang.String)
,
ShaderProgram#glReplaceShader
public int getUniformLocation(GL2ES2 gl, GLUniformData data)
getCachedUniformLocation(String)
if valid,
or the GLSL queried via GL2ES2.glGetUniformLocation(int, String)
.GLUniformData
object.
The current shader program (attachShaderProgram(GL2ES2, ShaderProgram)
)
must be in use (useProgram(GL2ES2, boolean)
) !
GLException
- is the program is not linked#glGetUniformLocation
,
GL2ES2.glGetUniformLocation(int, java.lang.String)
,
getUniformLocation(javax.media.opengl.GL2ES2, java.lang.String)
,
ShaderProgram#glReplaceShader
public boolean uniform(GL2ES2 gl, GLUniformData data)
data
- the GLUniforms's name must match the uniform one,
it's index will be set with the uniforms's location,
if found.GLException
- if the program is not in use#glGetUniformLocation
,
GL2ES2.glGetUniformLocation(int, java.lang.String)
,
GL2ES2.glUniform(javax.media.opengl.GLUniformData)
,
getUniformLocation(javax.media.opengl.GL2ES2, java.lang.String)
,
ShaderProgram#glReplaceShader
public GLUniformData getUniform(String name)
public void releaseAllUniforms(GL2ES2 gl)
public StringBuilder toString(StringBuilder sb)
Copyright 2010 JogAmp Community.