From a66acbec16c339db66d5f9242f44b3b539808b99 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Thu, 28 Apr 2011 08:12:26 +0200 Subject: ShaderState Switch Program: Only disable current program if no new one; Better toString formating --- .../com/jogamp/opengl/util/glsl/ShaderCode.java | 2 +- .../com/jogamp/opengl/util/glsl/ShaderProgram.java | 25 +++++++++----- .../com/jogamp/opengl/util/glsl/ShaderState.java | 38 +++++++++++----------- 3 files changed, 36 insertions(+), 29 deletions(-) (limited to 'src') diff --git a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderCode.java b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderCode.java index 20b032a41..c6a52a33e 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderCode.java +++ b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderCode.java @@ -245,7 +245,7 @@ public class ShaderCode { return id; } public String toString() { - StringBuffer buf = new StringBuffer("ShaderCode [id="+id+", type="+shaderTypeStr()+", valid="+valid+", shader: "); + StringBuffer buf = new StringBuffer("ShaderCode[id="+id+", type="+shaderTypeStr()+", valid="+valid+", shader: "); for(int i=0; i iter=allShaderCode.iterator(); iter.hasNext(); ) { - buf.append(iter.next()); - buf.append(" "); + sb.append(Platform.getNewline()).append(" ").append(iter.next()); } - buf.append("]"); - return buf.toString(); + sb.append("]"); + return sb; } - + + public String toString() { + return toString(null).toString(); + } + protected synchronized void useProgram(GL2ES2 gl, boolean on) { if(!programLinked) throw new GLException("Program is not linked"); if(programInUse==on) return; 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 f8fe987d7..a5290b958 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderState.java +++ b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderState.java @@ -43,6 +43,7 @@ import javax.media.opengl.GLUniformData; import jogamp.opengl.Debug; +import com.jogamp.common.os.Platform; import com.jogamp.common.util.IntObjectHashMap; import com.jogamp.opengl.util.GLArrayDataEditable; @@ -202,7 +203,11 @@ public class ShaderState { return; } prgInUse = shaderProgram.inUse(); - useProgram(gl, false); + + if(prgInUse && null == prog) { + // only disable if in use _and_ no new prog shall be used + useProgram(gl, false); + } resetAllShaderData = true; } @@ -936,34 +941,29 @@ public class ShaderState { sb = new StringBuilder(); } - sb.append("ShaderState["); - sb.append(shaderProgram.toString()); - sb.append(", enabledAttributes: ["); + sb.append("ShaderState[ "); + sb.append(Platform.getNewline()).append(" ").append(shaderProgram.toString()); + sb.append(Platform.getNewline()).append(" enabledAttributes ["); for(Iterator iter = enabledAttributes.iterator(); iter.hasNext(); ) { - sb.append("\n "); - sb.append((String)iter.next()); + sb.append(Platform.getNewline()).append(" ").append(iter.next()); } - sb.append("], activeAttributes ["); + sb.append(Platform.getNewline()).append(" ],").append(" activeAttributes ["); for(Iterator iter = activeAttribDataMap.values().iterator(); iter.hasNext(); ) { - sb.append("\n "); - sb.append(iter.next()); + sb.append(Platform.getNewline()).append(" ").append(iter.next()); } - sb.append("], managedAttributes ["); + sb.append(Platform.getNewline()).append(" ],").append(" managedAttributes ["); for(Iterator iter = managedAttributes.iterator(); iter.hasNext(); ) { - sb.append("\n "); - sb.append(iter.next()); + sb.append(Platform.getNewline()).append(" ").append(iter.next()); } - sb.append("], activeUniforms ["); + sb.append(Platform.getNewline()).append(" ],").append(" activeUniforms ["); for(Iterator iter=activeUniformDataMap.values().iterator(); iter.hasNext(); ) { - sb.append("\n "); - sb.append(iter.next()); + sb.append(Platform.getNewline()).append(" ").append(iter.next()); } - sb.append("], managedUniforms ["); + sb.append(Platform.getNewline()).append(" ],").append(" managedUniforms ["); for(Iterator iter = managedUniforms.iterator(); iter.hasNext(); ) { - sb.append("\n "); - sb.append(iter.next()); + sb.append(Platform.getNewline()).append(" ").append(iter.next()); } - sb.append("]"); + sb.append(Platform.getNewline()).append(" ]").append(Platform.getNewline()).append("]"); return sb; } -- cgit v1.2.3