diff options
author | Sven Gothel <[email protected]> | 2009-06-12 13:01:31 +0000 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2009-06-12 13:01:31 +0000 |
commit | b45fff547049103287ba4a6b0f7b635013b81298 (patch) | |
tree | 7c3fd007ed693dffefd37df7e2bc79ef1205bafd /src/jogl/classes/com/sun | |
parent | e4e5516064376384fe83a5bb94aa30f90a683aee (diff) |
GLSL ShaderUtil: Use TLS to make it thread safe
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/branches/JOGL_2_SANDBOX@1934 232f8b59-042b-4e1e-8c03-345bb8c30851
Diffstat (limited to 'src/jogl/classes/com/sun')
-rw-r--r-- | src/jogl/classes/com/sun/opengl/util/glsl/ShaderState.java | 21 | ||||
-rw-r--r-- | src/jogl/classes/com/sun/opengl/util/glsl/ShaderUtil.java | 6 |
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; } |