From 1ac5a3f0643a761d2d9e217883da73ad993a91b9 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Tue, 30 Aug 2011 15:41:00 +0200 Subject: 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 --- .../com/jogamp/opengl/util/glsl/ShaderState.java | 25 +++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'src/jogl/classes/com/jogamp/opengl/util/glsl') 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,25 +63,41 @@ 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. */ @@ -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) { -- cgit v1.2.3