diff options
author | Sven Gothel <[email protected]> | 2014-10-08 21:14:35 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2014-10-08 21:14:35 +0200 |
commit | ce8e9c7fb1ce9d2747a6014a86e759809a4c5c34 (patch) | |
tree | ba2cd83fc4d3efa852e845e38fcb72d9f052eb3a | |
parent | ac585daa624ec7e8bc747e6e4ef4e1c330f447b5 (diff) |
TestTessellationShader01GL4NEWT: Add robustness, i.e. case where tessellation failed to compile/link (on unsupported platforms)
-rw-r--r-- | make/scripts/tests.sh | 6 | ||||
-rw-r--r-- | src/test/com/jogamp/opengl/test/junit/jogl/demos/gl4/TessellationShader01aGLSL440CoreHardcoded.java (renamed from src/test/com/jogamp/opengl/test/junit/jogl/demos/gl4/TessellationShader01aGL4.java) | 52 | ||||
-rw-r--r-- | src/test/com/jogamp/opengl/test/junit/jogl/demos/gl4/TessellationShader01bGL4.java | 26 | ||||
-rw-r--r-- | src/test/com/jogamp/opengl/test/junit/jogl/demos/gl4/newt/TestTessellationShader01GL4NEWT.java | 4 |
4 files changed, 67 insertions, 21 deletions
diff --git a/make/scripts/tests.sh b/make/scripts/tests.sh index c153264ee..725a9a1a0 100644 --- a/make/scripts/tests.sh +++ b/make/scripts/tests.sh @@ -130,7 +130,7 @@ function jrun() { #D_ARGS="-Djogl.debug.GLBufferObjectTracker -Djogl.debug.GLArrayData -Djogl.debug.TraceGL -Djogl.debug.DebugGL" #D_ARGS="-Djogl.debug.GLSLCode" #D_ARGS="-Djogl.debug.GLSLCode -Djogl.debug.TraceGL" - #D_ARGS="-Djogl.debug.GLSLCode -Djogl.debug.DebugGL" + D_ARGS="-Djogl.debug.GLSLCode -Djogl.debug.DebugGL" #D_ARGS="-Djogl.debug.GLContext -Dnativewindow.debug.JAWT -Dnewt.debug.Window" #D_ARGS="-Dnativewindow.debug.JAWT -Djogl.debug.GLCanvas" #D_ARGS="-Dnativewindow.debug.JAWT -Djogamp.debug.TaskBase.TraceSource" @@ -434,7 +434,7 @@ function testawtswt() { #testnoawt com.jogamp.opengl.test.junit.jogl.demos.gl2.newt.TestGearsNEWT $* #testnoawt com.jogamp.opengl.test.junit.jogl.demos.gl2.newt.TestTeapotNEWT $* #testnoawt com.jogamp.opengl.test.junit.jogl.demos.gl3.newt.TestGeomShader01TextureGL3NEWT $* -#testnoawt com.jogamp.opengl.test.junit.jogl.demos.gl4.newt.TestTessellationShader01GL4NEWT $* +testnoawt com.jogamp.opengl.test.junit.jogl.demos.gl4.newt.TestTessellationShader01GL4NEWT $* # # av demos @@ -731,7 +731,7 @@ function testawtswt() { #testawt com.jogamp.opengl.test.junit.newt.TestListenerCom01AWT #testawt com.jogamp.opengl.test.junit.jogl.caps.TestMultisampleES1AWT $* #testnoawt com.jogamp.opengl.test.junit.jogl.caps.TestMultisampleES1NEWT $* -testnoawt com.jogamp.opengl.test.junit.jogl.caps.TestMultisampleES2NEWT $* +#testnoawt com.jogamp.opengl.test.junit.jogl.caps.TestMultisampleES2NEWT $* #testawt com.jogamp.opengl.test.junit.jogl.caps.TestTranslucencyAWT $* #testawt com.jogamp.opengl.test.junit.jogl.caps.TestTranslucencyNEWT $* #testnoawt com.jogamp.opengl.test.junit.newt.parenting.TestTranslucentChildWindowBug632NEWT $* diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl4/TessellationShader01aGL4.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl4/TessellationShader01aGLSL440CoreHardcoded.java index a5807a096..223eb1a14 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl4/TessellationShader01aGL4.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl4/TessellationShader01aGLSL440CoreHardcoded.java @@ -49,7 +49,7 @@ import com.jogamp.opengl.util.glsl.ShaderProgram; * @author Raymond L. Rivera, 2014 * @author Sven Gothel */ -public class TessellationShader01aGL4 implements GLEventListener { +public class TessellationShader01aGLSL440CoreHardcoded implements GLEventListener { private static final double ANIMATION_RATE = 950.0; private ShaderProgram program; @@ -60,6 +60,12 @@ public class TessellationShader01aGL4 implements GLEventListener { @Override public void init(final GLAutoDrawable auto) { + final GL4 gl = auto.getGL().getGL4(); + program = createProgram(auto); + if( null == program ) { + return; + } + final double theta = System.currentTimeMillis() / ANIMATION_RATE; vertexOffset = FloatBuffer.allocate(4); vertexOffset.put(0, (float)(Math.sin(theta) * 0.5f)); @@ -73,8 +79,6 @@ public class TessellationShader01aGL4 implements GLEventListener { backgroundColor.put(2, 0.25f); backgroundColor.put(3, 1.0f); - final GL4 gl = auto.getGL().getGL4(); - program = createProgram(auto); gl.glGenVertexArrays(vertexArray.length, vertexArray, 0); gl.glBindVertexArray(vertexArray[0]); gl.glPatchParameteri(GL4.GL_PATCH_VERTICES, 3); @@ -83,6 +87,9 @@ public class TessellationShader01aGL4 implements GLEventListener { @Override public void display(final GLAutoDrawable auto) { + if( null == program ) { + return; + } final GL4 gl = auto.getGL().getGL4(); final double value = System.currentTimeMillis() / ANIMATION_RATE; gl.glClearBufferfv(GL2ES3.GL_COLOR, 0, backgroundColor); @@ -95,6 +102,9 @@ public class TessellationShader01aGL4 implements GLEventListener { @Override public void dispose(final GLAutoDrawable auto) { + if( null == program ) { + return; + } final GL4 gl = auto.getGL().getGL4(); gl.glDeleteVertexArrays(vertexArray.length, vertexArray, 0); program.destroy(gl); @@ -157,9 +167,27 @@ public class TessellationShader01aGL4 implements GLEventListener { "} \n"; final ShaderCode vertexShader = createShader(gl, GL2ES2.GL_VERTEX_SHADER, vertexSource); + if( null == vertexShader ) { + return null; + } final ShaderCode tessCtrlShader = createShader(gl, GL4.GL_TESS_CONTROL_SHADER, tessCtrlSource); + if( null == tessCtrlShader ) { + vertexShader.destroy(gl); + return null; + } final ShaderCode tessEvalShader = createShader(gl, GL4.GL_TESS_EVALUATION_SHADER, tessEvalSource); + if( null == tessEvalShader ) { + vertexShader.destroy(gl); + tessCtrlShader.destroy(gl); + return null; + } final ShaderCode fragmentShader = createShader(gl, GL2ES2.GL_FRAGMENT_SHADER, fragmentSource); + if( null == fragmentShader ) { + vertexShader.destroy(gl); + tessCtrlShader.destroy(gl); + tessEvalShader.destroy(gl); + return null; + } final ShaderProgram program = new ShaderProgram(); @@ -170,10 +198,13 @@ public class TessellationShader01aGL4 implements GLEventListener { program.add(fragmentShader); program.link(gl, System.err); - if(!program.validateProgram(gl, System.out)) + if( !program.validateProgram(gl, System.out) ) { System.err.println("[error] Program linking failed."); - - return program; + program.destroy(gl); + return null; + } else { + return program; + } } private ShaderCode createShader(final GL4 gl, final int shaderType, final String source) { @@ -182,10 +213,13 @@ public class TessellationShader01aGL4 implements GLEventListener { final ShaderCode shader = new ShaderCode(shaderType, sources.length, sources); final boolean compiled = shader.compile(gl, System.err); - if (!compiled) + if (!compiled) { System.err.println("[error] Shader compilation failed."); - - return shader; + shader.destroy(gl); + return null; + } else { + return shader; + } } } diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl4/TessellationShader01bGL4.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl4/TessellationShader01bGL4.java index 7be26e400..bcf4fa6ca 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl4/TessellationShader01bGL4.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl4/TessellationShader01bGL4.java @@ -61,6 +61,12 @@ public class TessellationShader01bGL4 implements GLEventListener { @Override public void init(final GLAutoDrawable auto) { + final GL4 gl = auto.getGL().getGL4(); + program = createProgram(auto); + if( null == program ) { + return; + } + final double theta = System.currentTimeMillis() / ANIMATION_RATE; vertexOffset = FloatBuffer.allocate(4); vertexOffset.put(0, (float)(Math.sin(theta) * 0.5f)); @@ -74,8 +80,6 @@ public class TessellationShader01bGL4 implements GLEventListener { backgroundColor.put(2, 0.25f); backgroundColor.put(3, 1.0f); - final GL4 gl = auto.getGL().getGL4(); - program = createProgram(auto); gl.glGenVertexArrays(vertexArray.length, vertexArray, 0); gl.glBindVertexArray(vertexArray[0]); gl.glPatchParameteri(GL4.GL_PATCH_VERTICES, 3); @@ -84,6 +88,9 @@ public class TessellationShader01bGL4 implements GLEventListener { @Override public void display(final GLAutoDrawable auto) { + if( null == program ) { + return; + } final GL4 gl = auto.getGL().getGL4(); final double value = System.currentTimeMillis() / ANIMATION_RATE; gl.glClearBufferfv(GL2ES3.GL_COLOR, 0, backgroundColor); @@ -96,6 +103,9 @@ public class TessellationShader01bGL4 implements GLEventListener { @Override public void dispose(final GLAutoDrawable auto) { + if( null == program ) { + return; + } final GL4 gl = auto.getGL().getGL4(); gl.glDeleteVertexArrays(vertexArray.length, vertexArray, 0); program.destroy(gl); @@ -132,11 +142,13 @@ public class TessellationShader01bGL4 implements GLEventListener { sp.add(gl, tcs, System.err); sp.add(gl, tes, System.err); sp.add(gl, fs, System.err); - if(!sp.link(gl, System.err)) { - throw new GLException("Couldn't link program: "+sp); - } } - - return sp; + if( !sp.link(gl, System.err) ) { + System.err.println("[error] Couldn't link program: "+sp); + sp.destroy(gl); + return null; + } else { + return sp; + } } } diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl4/newt/TestTessellationShader01GL4NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl4/newt/TestTessellationShader01GL4NEWT.java index a05dcec06..ca2638581 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl4/newt/TestTessellationShader01GL4NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl4/newt/TestTessellationShader01GL4NEWT.java @@ -39,7 +39,7 @@ import org.junit.FixMethodOrder; import org.junit.runners.MethodSorters; import com.jogamp.newt.opengl.GLWindow; -import com.jogamp.opengl.test.junit.jogl.demos.gl4.TessellationShader01aGL4; +import com.jogamp.opengl.test.junit.jogl.demos.gl4.TessellationShader01aGLSL440CoreHardcoded; import com.jogamp.opengl.test.junit.jogl.demos.gl4.TessellationShader01bGL4; import com.jogamp.opengl.test.junit.util.MiscUtils; import com.jogamp.opengl.test.junit.util.QuitAdapter; @@ -65,7 +65,7 @@ public class TestTessellationShader01GL4NEWT extends UITestCase { public void test01_01a() throws InterruptedException { final GLCapabilities caps = getCaps(GLProfile.GL4); if( null == caps ) { return; } - testImpl(caps, new TessellationShader01aGL4()); + testImpl(caps, new TessellationShader01aGLSL440CoreHardcoded()); } @Test |