aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/com
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2011-08-30 15:41:00 +0200
committerSven Gothel <[email protected]>2011-08-30 15:41:00 +0200
commit1ac5a3f0643a761d2d9e217883da73ad993a91b9 (patch)
tree60f013931bb8414149909fb1146f5b4f086fed3c /src/jogl/classes/com
parent736d1c5d27e0cee36993f74dca787aefd3df7d18 (diff)
ShaderState Usage/Test: Add setShaderState(GL) for pre-use attachment to the GL context ; GLArrayDataClient-GLSL: Check if ShaderState is attached.
ShaderState Usage/Test: Add setShaderState(GL) for pre-use attachment to the GL context - test cases utilize ShaderState before useProgram() was invoked, hence we need an API entry to attach the ShaderState explictly GLArrayDataClient-GLSL: Check if ShaderState is attached. - catch error case of non bound ShaderState to GL context
Diffstat (limited to 'src/jogl/classes/com')
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/GLArrayDataClient.java10
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderState.java25
2 files changed, 29 insertions, 6 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataClient.java b/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataClient.java
index ee9a21095..99500adfb 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataClient.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/GLArrayDataClient.java
@@ -158,7 +158,15 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData
// init/generate VBO name if not done yet
init_vbo(gl);
}
- final Object ext = usesGLSL ? ShaderState.getShaderState(gl) : null ;
+ final Object ext;
+ if(usesGLSL) {
+ ext = ShaderState.getShaderState(gl);
+ if(null == ext) {
+ throw new GLException("A ShaderState must be bound to the GL context, use 'ShaderState.setShaderState(gl)'");
+ }
+ } else {
+ ext = null;
+ }
if(enable) {
glArrayHandler.syncData(gl, true, ext);
glArrayHandler.enableState(gl, true, ext);
diff --git a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderState.java b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderState.java
index 36abd9d4d..aa9a73bdd 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderState.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderState.java
@@ -63,26 +63,42 @@ public class ShaderState {
*
* @see com.jogamp.opengl.util.glsl.ShaderState#useProgram(GL2ES2, boolean)
* @see com.jogamp.opengl.util.glsl.ShaderState#getShaderState(GL)
+ * @see com.jogamp.opengl.util.glsl.ShaderState#setShaderState(GL)
* @see com.jogamp.opengl.util.glsl.ShaderState#getCurrentShaderState()
*/
- public static synchronized ShaderState getCurrentShaderState() {
+ public static ShaderState getCurrentShaderState() {
return getShaderState(GLContext.getCurrentGL());
}
/**
- * Fetches the shader state from the GL object's GLContext
+ * Gets the shader state attached to the GL object's GLContext
*
* @param gl the GL object referencing the GLContext
*
* @see com.jogamp.opengl.util.glsl.ShaderState#useProgram(GL2ES2, boolean)
* @see com.jogamp.opengl.util.glsl.ShaderState#getShaderState(GL)
+ * @see com.jogamp.opengl.util.glsl.ShaderState#setShaderState(GL)
* @see com.jogamp.opengl.util.glsl.ShaderState#getCurrentShaderState()
*/
- public static synchronized ShaderState getShaderState(GL gl) {
+ public static ShaderState getShaderState(GL gl) {
return (ShaderState) gl.getContext().getAttachedObject(currentStateKey);
}
/**
+ * Attaches the shader state to the GL object's GLContext
+ *
+ * @param gl the GL object referencing the GLContext
+ *
+ * @see com.jogamp.opengl.util.glsl.ShaderState#useProgram(GL2ES2, boolean)
+ * @see com.jogamp.opengl.util.glsl.ShaderState#getShaderState(GL)
+ * @see com.jogamp.opengl.util.glsl.ShaderState#setShaderState(GL)
+ * @see com.jogamp.opengl.util.glsl.ShaderState#getCurrentShaderState()
+ */
+ public final ShaderState setShaderState(GL gl) {
+ return (ShaderState) gl.getContext().attachObject(currentStateKey, this);
+ }
+
+ /**
* Returns the attached user object for the given name to this ShaderState.
*/
public final Object getAttachedObject(String name) {
@@ -141,8 +157,7 @@ public class ShaderState {
public synchronized void useProgram(GL2ES2 gl, boolean on) throws GLException {
if(null==shaderProgram) { throw new GLException("No program is attached"); }
if(on) {
- // update the current ShaderState to the TLS ..
- gl.getContext().attachObject(currentStateKey, this);
+ setShaderState(gl);
if(shaderProgram.linked()) {
shaderProgram.useProgram(gl, true);
if(resetAllShaderData) {