diff options
author | Sven Gothel <[email protected]> | 2012-04-09 05:36:33 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2012-04-09 05:36:33 +0200 |
commit | ca14c6b3d5e53f6eda31ab6112b6b1705c5b31e5 (patch) | |
tree | 9445b46793de1334c23b03a63d6b4e84fe4aa327 /src/jogl/classes/com/jogamp/opengl/util | |
parent | 1ab2108279ede3b646ad2d410fd16368393c174e (diff) |
ShaderUtil: isProgramValid() -> isProgramLinkStatusValid() + isProgramExecStatusValid()
isProgramValid() was testing whether the linkx status is valid
and whether the executable environment is valid for the shader, see glValidateProgram().
glValidateProgram() may fail on some implementations in some circumstances (APX2500 and Tegra2)
and indeed require all resources are set for execution of the shader program (glDraw*).
This is not a requirement for issueing useProgram(), hence removed this test
and made it available explicit for debugging purposes: isProgramExecStatusValid().
Diffstat (limited to 'src/jogl/classes/com/jogamp/opengl/util')
-rw-r--r-- | src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderProgram.java | 16 | ||||
-rw-r--r-- | src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderUtil.java | 68 |
2 files changed, 42 insertions, 42 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderProgram.java b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderProgram.java index 22c582865..14ea7d2b8 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderProgram.java +++ b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderProgram.java @@ -214,7 +214,7 @@ public class ShaderProgram { gl.glLinkProgram(shaderProgram); - programLinked = ShaderUtil.isProgramValid(gl, shaderProgram, System.err); + programLinked = ShaderUtil.isProgramLinkStatusValid(gl, shaderProgram, System.err); if ( programLinked && shaderWasInUse ) { useProgram(gl, true); } @@ -250,7 +250,7 @@ public class ShaderProgram { // Link the program gl.glLinkProgram(shaderProgram); - programLinked = ShaderUtil.isProgramValid(gl, shaderProgram, System.err); + programLinked = ShaderUtil.isProgramLinkStatusValid(gl, shaderProgram, System.err); return programLinked; } @@ -284,9 +284,17 @@ public class ShaderProgram { return toString(null).toString(); } + /** + * Performs {@link GL2ES2#glValidateProgram(int)} via {@link ShaderUtil#isProgramExecStatusValid(GL, int, PrintStream)}. + * @see ShaderUtil#isProgramExecStatusValid(GL, int, PrintStream) + **/ + public synchronized boolean validateProgram(GL2ES2 gl, PrintStream verboseOut) { + return ShaderUtil.isProgramExecStatusValid(gl, shaderProgram, verboseOut); + } + public synchronized void useProgram(GL2ES2 gl, boolean on) { - if(!programLinked) throw new GLException("Program is not linked"); - if(programInUse==on) return; + if(!programLinked) { throw new GLException("Program is not linked"); } + if(programInUse==on) { return; } gl.glUseProgram(on?shaderProgram:0); programInUse = on; } diff --git a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderUtil.java b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderUtil.java index 51f62a886..bd4ba45c4 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderUtil.java +++ b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderUtil.java @@ -45,13 +45,11 @@ public class ShaderUtil { static abstract class Impl { public abstract String getShaderInfoLog(GL gl, int shaderObj); public abstract String getProgramInfoLog(GL gl, int programObj); - public abstract boolean isShaderStatusValid(GL gl, int shaderObj, int name); public abstract boolean isShaderStatusValid(GL gl, int shaderObj, int name, PrintStream verboseOut); - public abstract boolean isShaderStatusValid(GL gl, IntBuffer shaders, int name); public abstract boolean isShaderStatusValid(GL gl, IntBuffer shaders, int name, PrintStream verboseOut); public abstract boolean isProgramStatusValid(GL gl, int programObj, int name); - public abstract boolean isProgramValid(GL gl, int programObj); - public abstract boolean isProgramValid(GL gl, int programObj, PrintStream verboseOut); + public abstract boolean isProgramLinkStatusValid(GL gl, int programObj, PrintStream verboseOut); + public abstract boolean isProgramExecStatusValid(GL gl, int programObj, PrintStream verboseOut); public abstract void createShader(GL gl, int type, IntBuffer shaders); public abstract Set<Integer> getShaderBinaryFormats(GL gl); public abstract boolean isShaderCompilerAvailable(GL gl); @@ -103,10 +101,6 @@ public class ShaderUtil { return new String(infoLogBytes, 0, charsWritten[0]); } - public boolean isShaderStatusValid(GL _gl, int shaderObj, int name) { - return isShaderStatusValid(_gl, shaderObj, name, null); - } - public boolean isShaderStatusValid(GL _gl, int shaderObj, int name, PrintStream verboseOut) { GL2ES2 gl = _gl.getGL2ES2(); int[] ires = new int[1]; @@ -119,10 +113,6 @@ public class ShaderUtil { return res; } - public boolean isShaderStatusValid(GL _gl, IntBuffer shaders, int name) { - return isShaderStatusValid(_gl, shaders, name, null); - } - public boolean isShaderStatusValid(GL _gl, IntBuffer shaders, int name, PrintStream verboseOut) { boolean res = true; for (int i = shaders.position(); i < shaders.limit(); i++) { @@ -139,11 +129,7 @@ public class ShaderUtil { return ires[0]==1; } - public boolean isProgramValid(GL _gl, int programObj) { - return isProgramValid(_gl, programObj, null); - } - - public boolean isProgramValid(GL _gl, int programObj, PrintStream verboseOut) { + public boolean isProgramLinkStatusValid(GL _gl, int programObj, PrintStream verboseOut) { GL2ES2 gl = _gl.getGL2ES2(); if(!gl.glIsProgram(programObj)) { if(null!=verboseOut) { @@ -157,15 +143,17 @@ public class ShaderUtil { } return false; } - if ( !gl.isGLES2() || isShaderCompilerAvailable(gl) ) { - // failed on APX2500 (ES2.0, no compiler) for valid programs - gl.glValidateProgram(programObj); - if(!isProgramStatusValid(gl, programObj, GL2ES2.GL_VALIDATE_STATUS)) { - if(null!=verboseOut) { - verboseOut.println("Program validation failed: "+programObj+"\n\t"+ getProgramInfoLog(gl, programObj)); - } - return false; + return true; + } + + public boolean isProgramExecStatusValid(GL _gl, int programObj, PrintStream verboseOut) { + GL2ES2 gl = _gl.getGL2ES2(); + gl.glValidateProgram(programObj); + if(!isProgramStatusValid(gl, programObj, GL2ES2.GL_VALIDATE_STATUS)) { + if(null!=verboseOut) { + verboseOut.println("Program validation failed: "+programObj+"\n\t"+ getProgramInfoLog(gl, programObj)); } + return false; } return true; } @@ -379,18 +367,10 @@ public class ShaderUtil { return getImpl(gl).getProgramInfoLog(gl, programObj); } - public static boolean isShaderStatusValid(GL gl, int shaderObj, int name) { - return getImpl(gl).isShaderStatusValid(gl, shaderObj, name); - } - public static boolean isShaderStatusValid(GL gl, int shaderObj, int name, PrintStream verboseOut) { return getImpl(gl).isShaderStatusValid(gl, shaderObj, name, verboseOut); } - public static boolean isShaderStatusValid(GL gl, IntBuffer shaders, int name) { - return getImpl(gl).isShaderStatusValid(gl, shaders, name); - } - public static boolean isShaderStatusValid(GL gl, IntBuffer shaders, int name, PrintStream verboseOut) { return getImpl(gl).isShaderStatusValid(gl, shaders, name, verboseOut); } @@ -399,12 +379,24 @@ public class ShaderUtil { return getImpl(gl).isProgramStatusValid(gl, programObj, name); } - public static boolean isProgramValid(GL gl, int programObj) { - return getImpl(gl).isProgramValid(gl, programObj); + public static boolean isProgramLinkStatusValid(GL gl, int programObj, PrintStream verboseOut) { + return getImpl(gl).isProgramLinkStatusValid(gl, programObj, verboseOut); } - - public static boolean isProgramValid(GL gl, int programObj, PrintStream verboseOut) { - return getImpl(gl).isProgramValid(gl, programObj, verboseOut); + + /** + * Performs {@link GL2ES2#glValidateProgram(int)} + * <p> + * One shall only call this method while debugging and only if all required + * resources by the shader are set. + * </p> + * <p> + * Note: It is possible that a working shader program will fail validation. + * This has been experienced on NVidia APX2500 and Tegra2. + * </p> + * @see GL2ES2#glValidateProgram(int) + **/ + public static boolean isProgramExecStatusValid(GL gl, int programObj, PrintStream verboseOut) { + return getImpl(gl).isProgramExecStatusValid(gl, programObj, verboseOut); } public static void createShader(GL gl, int type, IntBuffer shaders) { |