diff options
Diffstat (limited to 'src/jogl/classes/com/jogamp/opengl')
-rw-r--r-- | src/jogl/classes/com/jogamp/opengl/util/GLArrayDataClient.java | 10 | ||||
-rw-r--r-- | src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderState.java | 25 |
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) { |