aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/jogl/classes/com/sun/opengl/util/glsl/ShaderState.java21
-rw-r--r--src/jogl/classes/com/sun/opengl/util/glsl/ShaderUtil.java6
2 files changed, 15 insertions, 12 deletions
diff --git a/src/jogl/classes/com/sun/opengl/util/glsl/ShaderState.java b/src/jogl/classes/com/sun/opengl/util/glsl/ShaderState.java
index 5acbff241..bab9ef4f3 100644
--- a/src/jogl/classes/com/sun/opengl/util/glsl/ShaderState.java
+++ b/src/jogl/classes/com/sun/opengl/util/glsl/ShaderState.java
@@ -20,16 +20,23 @@ public class ShaderState {
public void setVerbose(boolean v) { verbose=v; }
/**
- * Fetches the current shader state
+ * Fetches the current shader state from the thread local storage (TLS)
*
* @see javax.media.opengl.glsl.ShaderState#glUseProgram(GL2ES2, boolean)
* @see javax.media.opengl.glsl.ShaderState#getCurrent()
*/
- public static synchronized ShaderState getCurrent() { return currentShaderState; }
+ public static synchronized ShaderState getCurrent() {
+ GLContext current = GLContext.getCurrent();
+ if(null==current) {
+ throw new GLException("No context is current on this thread");
+ }
+ return (ShaderState) current.getAttachedObject(ShaderState.class.getName());
+ }
/**
- * Turns the shader program on
- * and set this ShaderState to current if on equals true
+ * Turns the shader program on or off.<br>
+ * Puts this ShaderState to to the thread local storage (TLS),
+ * if <code>on</code> is <code>true</code>.
*
* @see javax.media.opengl.glsl.ShaderState#glUseProgram(GL2ES2, boolean)
* @see javax.media.opengl.glsl.ShaderState#getCurrent()
@@ -41,9 +48,8 @@ public class ShaderState {
} else {
throw new GLException("No program is attached");
}
- if(currentShaderState!=this) {
- currentShaderState = this;
- }
+ // update the current ShaderState to the TLS ..
+ gl.getContext().putAttachedObject(ShaderState.class.getName(), this);
} else if(null!=shaderProgram) {
shaderProgram.glUseProgram(gl, false);
}
@@ -637,7 +643,6 @@ public class ShaderState {
protected HashMap vertexAttribMap2Data = new HashMap();
protected HashMap uniformMap2Idx = new HashMap();
protected HashMap uniformMap2Data = new HashMap();
- protected static ShaderState currentShaderState = null;
}
diff --git a/src/jogl/classes/com/sun/opengl/util/glsl/ShaderUtil.java b/src/jogl/classes/com/sun/opengl/util/glsl/ShaderUtil.java
index 8bac24b86..d1bb8b32b 100644
--- a/src/jogl/classes/com/sun/opengl/util/glsl/ShaderUtil.java
+++ b/src/jogl/classes/com/sun/opengl/util/glsl/ShaderUtil.java
@@ -388,12 +388,10 @@ public class ShaderUtil {
private static Impl getImpl(GL _gl) {
GL2ES2 gl = _gl.getGL2ES2();
GLContext context = gl.getContext();
- // Argument could be anything suitably unique
- String name = "com.sun.opengl.util.glsl.ShaderUtil.GL2ES2Impl";
- Impl impl = (Impl) context.getAttachedObject(name);
+ Impl impl = (Impl) context.getAttachedObject(ShaderUtil.class.getName());
if (impl == null) {
impl = new GL2ES2Impl();
- context.putAttachedObject(name, impl);
+ context.putAttachedObject(ShaderUtil.class.getName(), impl);
}
return impl;
}