diff options
author | Sven Gothel <[email protected]> | 2012-12-16 02:55:07 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2012-12-16 02:55:07 +0100 |
commit | b8a8fc24a3afb0cb06a31504bdea1a98b8f00ef4 (patch) | |
tree | 37bd8b49f7e4fd547ff58656dff09b5a88e65c47 /src/test/com | |
parent | e7064ece049705e013d80985eae698ce0ee3c4e3 (diff) |
GLArrayData/ImmModeSink: Remove implicit dependency on ShaderState - allow operating w/o it; ShaderState: Remove notion of GL context attachment, use pass-through or object association; GLArrayData/GLUniformData: Add basic GLSL location methods
- GLArrayData/GLUniformData: Add basic GLSL location methods
- GLArrayData
- add: setLocation(..) for attribute location/index retrieval (post link) and binding (pre link)
- GLUniformData
- add: setLocation(..) for attribute location/index retrieval (post link)
- GLArrayData/ImmModeSink: Remove implicit dependency on ShaderState - allow operating w/o it
- GLArrayData
- add: 'public void associate(Object obj, boolean enable)', allows setting ShaderState usage
- ShaderState: Remove notion of GL context attachment, use pass-through or object association
- ownsAttribute(..) associates the attribute w/ ShaderState
- removed GL context ShaderState attachment
Tested:
- ImmModeSink w/ GLSL/ES2 w/ and w/o ShaderState
- GLArrayData* w/ and w/o ShaderState
Diffstat (limited to 'src/test/com')
10 files changed, 662 insertions, 174 deletions
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java index a3023538f..21c9f3535 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java @@ -152,26 +152,26 @@ public class GearsES2 implements GLEventListener { st.uniform(gl, colorU); if(null == gear1) { - gear1 = new GearsObjectES2(1.0f, 4.0f, 1.0f, 20, 0.7f, pmvMatrix, pmvMatrixUniform, colorU); + gear1 = new GearsObjectES2(st, 1.0f, 4.0f, 1.0f, 20, 0.7f, pmvMatrix, pmvMatrixUniform, colorU); System.err.println("gear1 created: "+gear1); } else { - gear1 = new GearsObjectES2(gear1, pmvMatrix, pmvMatrixUniform, colorU); + gear1 = new GearsObjectES2(gear1, st, pmvMatrix, pmvMatrixUniform, colorU); System.err.println("gear1 reused: "+gear1); } if(null == gear2) { - gear2 = new GearsObjectES2(0.5f, 2.0f, 2.0f, 10, 0.7f, pmvMatrix, pmvMatrixUniform, colorU); + gear2 = new GearsObjectES2(st, 0.5f, 2.0f, 2.0f, 10, 0.7f, pmvMatrix, pmvMatrixUniform, colorU); System.err.println("gear2 created: "+gear2); } else { - gear2 = new GearsObjectES2(gear2, pmvMatrix, pmvMatrixUniform, colorU); + gear2 = new GearsObjectES2(gear2, st, pmvMatrix, pmvMatrixUniform, colorU); System.err.println("gear2 reused: "+gear2); } if(null == gear3) { - gear3 = new GearsObjectES2(1.3f, 2.0f, 0.5f, 10, 0.7f, pmvMatrix, pmvMatrixUniform, colorU); + gear3 = new GearsObjectES2(st, 1.3f, 2.0f, 0.5f, 10, 0.7f, pmvMatrix, pmvMatrixUniform, colorU); System.err.println("gear3 created: "+gear3); } else { - gear3 = new GearsObjectES2(gear3, pmvMatrix, pmvMatrixUniform, colorU); + gear3 = new GearsObjectES2(gear3, st, pmvMatrix, pmvMatrixUniform, colorU); System.err.println("gear3 reused: "+gear3); } diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsObjectES2.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsObjectES2.java index 32cc4c4d9..826f68cc3 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsObjectES2.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsObjectES2.java @@ -39,28 +39,41 @@ public class GearsObjectES2 extends GearsObject { PMVMatrix pmvMatrix; GLUniformData pmvMatrixUniform; GLUniformData colorUniform; + ShaderState st; - public GearsObjectES2(float inner_radius, float outer_radius, float width, - int teeth, float tooth_depth, - PMVMatrix pmvMatrix, - GLUniformData pmvMatrixUniform, - GLUniformData colorUniform) + public GearsObjectES2(ShaderState st, float inner_radius, float outer_radius, + float width, int teeth, + float tooth_depth, + PMVMatrix pmvMatrix, + GLUniformData pmvMatrixUniform, GLUniformData colorUniform) { super(inner_radius, outer_radius, width, teeth, tooth_depth); this.pmvMatrix = pmvMatrix; this.pmvMatrixUniform = pmvMatrixUniform; this.colorUniform = colorUniform; + this.st = st; + associate(st); } public GearsObjectES2(GearsObjectES2 shared, - PMVMatrix pmvMatrix, - GLUniformData pmvMatrixUniform, - GLUniformData colorUniform) + ShaderState st, + PMVMatrix pmvMatrix, + GLUniformData pmvMatrixUniform, GLUniformData colorUniform) { super(shared); this.pmvMatrix = pmvMatrix; this.pmvMatrixUniform = pmvMatrixUniform; this.colorUniform = colorUniform; + associate(st); + } + + private void associate(ShaderState st) { + frontFace.associate(st, true); + frontSide.associate(st, true); + backFace.associate(st, true); + backSide.associate(st, true); + outwardFace.associate(st, true); + insideRadiusCyl.associate(st, true); } @Override @@ -83,7 +96,6 @@ public class GearsObjectES2 extends GearsObject { @Override public void draw(GL _gl, float x, float y, float angle, FloatBuffer color) { final GL2ES2 gl = _gl.getGL2ES2(); - final ShaderState st = ShaderState.getShaderState(gl); pmvMatrix.glPushMatrix(); pmvMatrix.glTranslatef(x, y, 0f); pmvMatrix.glRotatef(angle, 0f, 0f, 1f); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/MultisampleDemoES2.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/MultisampleDemoES2.java index 691e08ed2..98641398d 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/MultisampleDemoES2.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/MultisampleDemoES2.java @@ -117,7 +117,7 @@ public class MultisampleDemoES2 implements GLEventListener { 4, GL.GL_FLOAT, // color 0, GL.GL_FLOAT, // normal 0, GL.GL_FLOAT, // texCoords - GL.GL_STATIC_DRAW); + GL.GL_STATIC_DRAW, st); final int numSteps = 20; final double increment = Math.PI / numSteps; final double radius = 1; diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/glsl/GLSLMiscHelper.java b/src/test/com/jogamp/opengl/test/junit/jogl/glsl/GLSLMiscHelper.java index c2285ba25..361c2916a 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/glsl/GLSLMiscHelper.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/glsl/GLSLMiscHelper.java @@ -40,8 +40,7 @@ public class GLSLMiscHelper { public static final int frames_perftest = 600; // frames public static final int frames_warmup = 100; // frames - public static void validateGLArrayDataServerState(GL2ES2 gl, GLArrayDataServer data) { - final ShaderState st = ShaderState.getShaderState(gl); + public static void validateGLArrayDataServerState(GL2ES2 gl, ShaderState st, GLArrayDataServer data) { int[] qi = new int[1]; if(null != st) { Assert.assertEquals(data, st.getAttribute(data.getName())); @@ -66,7 +65,7 @@ public class GLSLMiscHelper { } } - public static void displayVCArrays(GLDrawable drawable, GL2ES2 gl, boolean preEnable, GLArrayDataServer vertices, GLArrayDataServer colors, boolean postDisable, int num, long postDelay) throws InterruptedException { + public static void displayVCArrays(GLDrawable drawable, GL2ES2 gl, ShaderState st, boolean preEnable, GLArrayDataServer vertices, GLArrayDataServer colors, boolean postDisable, int num, long postDelay) throws InterruptedException { System.err.println("screen #"+num); if(preEnable) { vertices.enableBuffer(gl, true); @@ -81,8 +80,8 @@ public class GLSLMiscHelper { Assert.assertTrue(vertices.enabled()); Assert.assertTrue(colors.enabled()); - validateGLArrayDataServerState(gl, vertices); - validateGLArrayDataServerState(gl, colors); + validateGLArrayDataServerState(gl, st, vertices); + validateGLArrayDataServerState(gl, st, colors); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); gl.glDrawArrays(GL.GL_TRIANGLE_STRIP, 0, 4); Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); @@ -111,88 +110,98 @@ public class GLSLMiscHelper { drawable.swapBuffers(); } - public static GLArrayDataServer createRSVertices0(GL2ES2 gl, int location) { - final ShaderState st = ShaderState.getShaderState(gl); - + public static GLArrayDataServer createVertices(GL2ES2 gl, ShaderState st, int shaderProgram, int location, float[] vertices) { + if(null != st && 0 != shaderProgram) { + throw new InternalError("Use either ShaderState _or_ shader-program, not both"); + } + if(null == st && 0 == shaderProgram) { + throw new InternalError("Pass a valid ShaderState _xor_ shader-program, not none"); + } // Allocate Vertex Array0 - GLArrayDataServer vertices0 = GLArrayDataServer.createGLSL("mgl_Vertex", 3, GL.GL_FLOAT, false, 4, GL.GL_STATIC_DRAW); - if(0<=location) { - st.bindAttribLocation(gl, location, vertices0); + GLArrayDataServer vDataArray = GLArrayDataServer.createGLSL("mgl_Vertex", 3, GL.GL_FLOAT, false, 4, GL.GL_STATIC_DRAW); + if(null != st) { + st.ownAttribute(vDataArray, true); + if(0<=location) { + st.bindAttribLocation(gl, location, vDataArray); + } + } else { + if(0<=location) { + vDataArray.setLocation(gl, shaderProgram, location); + } else { + vDataArray.setLocation(gl, shaderProgram); + } } - Assert.assertTrue(vertices0.isVBO()); - Assert.assertTrue(vertices0.isVertexAttribute()); - Assert.assertTrue(!vertices0.isVBOWritten()); - Assert.assertTrue(!vertices0.sealed()); - vertices0.putf(-2); vertices0.putf(2); vertices0.putf(0); - vertices0.putf(2); vertices0.putf(2); vertices0.putf(0); - vertices0.putf(-2); vertices0.putf(-2); vertices0.putf(0); - vertices0.putf(2); vertices0.putf(-2); vertices0.putf(0); - vertices0.seal(gl, true); - Assert.assertTrue(vertices0.isVBOWritten()); - Assert.assertTrue(vertices0.sealed()); - Assert.assertEquals(4, vertices0.getElementCount()); + Assert.assertTrue(vDataArray.isVBO()); + Assert.assertTrue(vDataArray.isVertexAttribute()); + Assert.assertTrue(!vDataArray.isVBOWritten()); + Assert.assertTrue(!vDataArray.sealed()); + int i=0; + vDataArray.putf(vertices[i++]); vDataArray.putf(vertices[i++]); vDataArray.putf(vertices[i++]); + vDataArray.putf(vertices[i++]); vDataArray.putf(vertices[i++]); vDataArray.putf(vertices[i++]); + vDataArray.putf(vertices[i++]); vDataArray.putf(vertices[i++]); vDataArray.putf(vertices[i++]); + vDataArray.putf(vertices[i++]); vDataArray.putf(vertices[i++]); vDataArray.putf(vertices[i++]); + vDataArray.seal(gl, true); + Assert.assertTrue(vDataArray.isVBOWritten()); + Assert.assertTrue(vDataArray.sealed()); + Assert.assertEquals(4, vDataArray.getElementCount()); Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); Assert.assertEquals(0, gl.glGetBoundBuffer(GL.GL_ARRAY_BUFFER)); // should be cleared ASAP - validateGLArrayDataServerState(gl, vertices0); - return vertices0; + validateGLArrayDataServerState(gl, st, vDataArray); + return vDataArray; } + public static float[] vertices0 = new float[] { -2f, 2f, 0f, + 2f, 2f, 0f, + -2f, -2f, 0f, + 2f, -2f, 0f }; - public static GLArrayDataServer createRSVertices1(GL2ES2 gl) { - GLArrayDataServer vertices1 = GLArrayDataServer.createGLSL("mgl_Vertex", 3, GL.GL_FLOAT, false, 4, GL.GL_STATIC_DRAW); - Assert.assertTrue(vertices1.isVBO()); - Assert.assertTrue(vertices1.isVertexAttribute()); - Assert.assertTrue(!vertices1.isVBOWritten()); - Assert.assertTrue(!vertices1.sealed()); - vertices1.putf(-2); vertices1.putf(1); vertices1.putf(0); - vertices1.putf(2); vertices1.putf(1); vertices1.putf(0); - vertices1.putf(-2); vertices1.putf(-1); vertices1.putf(0); - vertices1.putf(2); vertices1.putf(-1); vertices1.putf(0); - vertices1.seal(gl, true); - Assert.assertTrue(vertices1.isVBOWritten()); - Assert.assertTrue(vertices1.sealed()); - Assert.assertEquals(4, vertices1.getElementCount()); - Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); - Assert.assertEquals(0, gl.glGetBoundBuffer(GL.GL_ARRAY_BUFFER)); // should be cleared ASAP - validateGLArrayDataServerState(gl, vertices1); - return vertices1; - } - - public static GLArrayDataServer createRSColors0(GL2ES2 gl, int location) { - final ShaderState st = ShaderState.getShaderState(gl); - GLArrayDataServer colors0 = GLArrayDataServer.createGLSL("mgl_Color", 4, GL.GL_FLOAT, false, 4, GL.GL_STATIC_DRAW); - if(0<=location) { - st.bindAttribLocation(gl, location, colors0); - } - colors0.putf(1); colors0.putf(0); colors0.putf(0); colors0.putf(1); - colors0.putf(0); colors0.putf(0); colors0.putf(1); colors0.putf(1); - colors0.putf(1); colors0.putf(0); colors0.putf(0); colors0.putf(1); - colors0.putf(1); colors0.putf(0); colors0.putf(0); colors0.putf(1); - colors0.seal(gl, true); - Assert.assertTrue(colors0.isVBO()); - Assert.assertTrue(colors0.isVertexAttribute()); - Assert.assertTrue(colors0.isVBOWritten()); - Assert.assertTrue(colors0.sealed()); + public static float[] vertices1 = new float[] { -2f, 1f, 0f, + 2f, 1f, 0f, + -2f, -1f, 0f, + 2f, -1f, 0f }; + + public static GLArrayDataServer createColors(GL2ES2 gl, ShaderState st, int shaderProgram, int location, float[] colors) { + if(null != st && 0 != shaderProgram) { + throw new InternalError("Use either ShaderState _or_ shader-program, not both"); + } + if(null == st && 0 == shaderProgram) { + throw new InternalError("Pass a valid ShaderState _xor_ shader-program, not none"); + } + GLArrayDataServer cDataArray = GLArrayDataServer.createGLSL("mgl_Color", 4, GL.GL_FLOAT, false, 4, GL.GL_STATIC_DRAW); + if(null != st) { + st.ownAttribute(cDataArray, true); + if(0<=location) { + st.bindAttribLocation(gl, location, cDataArray); + } + } else { + if(0<=location) { + cDataArray.setLocation(gl, shaderProgram, location); + } else { + cDataArray.setLocation(gl, shaderProgram); + } + } + int i=0; + cDataArray.putf(colors[i++]); cDataArray.putf(colors[i++]); cDataArray.putf(colors[i++]); cDataArray.putf(colors[i++]); + cDataArray.putf(colors[i++]); cDataArray.putf(colors[i++]); cDataArray.putf(colors[i++]); cDataArray.putf(colors[i++]); + cDataArray.putf(colors[i++]); cDataArray.putf(colors[i++]); cDataArray.putf(colors[i++]); cDataArray.putf(colors[i++]); + cDataArray.putf(colors[i++]); cDataArray.putf(colors[i++]); cDataArray.putf(colors[i++]); cDataArray.putf(colors[i++]); + cDataArray.seal(gl, true); + Assert.assertTrue(cDataArray.isVBO()); + Assert.assertTrue(cDataArray.isVertexAttribute()); + Assert.assertTrue(cDataArray.isVBOWritten()); + Assert.assertTrue(cDataArray.sealed()); Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); Assert.assertEquals(0, gl.glGetBoundBuffer(GL.GL_ARRAY_BUFFER)); // should be cleared ASAP - validateGLArrayDataServerState(gl, colors0); - return colors0; + validateGLArrayDataServerState(gl, st, cDataArray); + return cDataArray; } + public static float[] colors0 = new float[] { 1f, 0f, 0f, 1f, + 0f, 0f, 1f, 1f, + 1f, 0f, 0f, 1f, + 1f, 0f, 1f, 1f }; + + public static float[] colors1 = new float[] { 1f, 0f, 1f, 1f, + 0f, 1f, 0f, 1f, + 1f, 0f, 1f, 1f, + 1f, 0f, 1f, 1f }; - public static GLArrayDataServer createRSColors1(GL2ES2 gl) { - // Allocate Color Array1 - GLArrayDataServer colors1 = GLArrayDataServer.createGLSL("mgl_Color", 4, GL.GL_FLOAT, false, 4, GL.GL_STATIC_DRAW); - colors1.putf(1); colors1.putf(0); colors1.putf(1); colors1.putf(1); - colors1.putf(0); colors1.putf(1); colors1.putf(0); colors1.putf(1); - colors1.putf(1); colors1.putf(0); colors1.putf(1); colors1.putf(1); - colors1.putf(1); colors1.putf(0); colors1.putf(1); colors1.putf(1); - colors1.seal(gl, true); - Assert.assertTrue(colors1.isVBO()); - Assert.assertTrue(colors1.isVertexAttribute()); - Assert.assertTrue(colors1.isVBOWritten()); - Assert.assertTrue(colors1.sealed()); - Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); - Assert.assertEquals(0, gl.glGetBoundBuffer(GL.GL_ARRAY_BUFFER)); // should be cleared ASAP - validateGLArrayDataServerState(gl, colors1); - return colors1; - } } diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestGLSLShaderState01NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestGLSLShaderState01NEWT.java index ab4b2d8b6..04108eda5 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestGLSLShaderState01NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestGLSLShaderState01NEWT.java @@ -60,7 +60,123 @@ public class TestGLSLShaderState01NEWT extends UITestCase { static final int colors0_loc = 1; @Test - public void testShaderState01Validation() throws InterruptedException { + public void test00NoShaderState_Validation() throws InterruptedException { + // preset .. + final NEWTGLContext.WindowContext winctx = NEWTGLContext.createOnscreenWindow( + new GLCapabilities(GLProfile.getGL2ES2()), 480, 480, true); + final GLDrawable drawable = winctx.context.getGLDrawable(); + final GL2ES2 gl = winctx.context.getGL().getGL2ES2(); + System.err.println(winctx.context); + + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + + // test code .. + final ShaderCode rsVp = ShaderCode.create(gl, GL2ES2.GL_VERTEX_SHADER, RedSquareES2.class, + "shader", "shader/bin", "RedSquareShader", true); + final ShaderCode rsFp = ShaderCode.create(gl, GL2ES2.GL_FRAGMENT_SHADER, RedSquareES2.class, + "shader", "shader/bin", "RedSquareShader", true); + rsVp.defaultShaderCustomization(gl, true, ShaderCode.es2_default_precision_vp); + rsFp.defaultShaderCustomization(gl, true, ShaderCode.es2_default_precision_fp); + + final ShaderProgram sp = new ShaderProgram(); + Assert.assertTrue(0 == sp.program()); + + sp.add(gl, rsVp, System.err); + sp.add(gl, rsFp, System.err); + + Assert.assertTrue(0 != sp.program()); + Assert.assertTrue(!sp.inUse()); + Assert.assertTrue(!sp.linked()); + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + + Assert.assertTrue( sp.link(gl, System.err) ); + sp.useProgram(gl, true); + + // Allocate Vertex Array0 + final GLArrayDataServer vertices0 = GLSLMiscHelper.createVertices(gl, null, sp.program(), vertices0_loc, GLSLMiscHelper.vertices0); + System.err.println("vertices0: " + vertices0); + vertices0.enableBuffer(gl, false); + Assert.assertEquals(vertices0_loc, vertices0.getLocation()); + + // Allocate Color Array0 + final GLArrayDataServer colors0 = GLSLMiscHelper.createColors(gl, null, sp.program(), colors0_loc, GLSLMiscHelper.colors0); + System.err.println("colors0: " + colors0); + colors0.enableBuffer(gl, false); + Assert.assertEquals(colors0_loc, colors0.getLocation()); + + Assert.assertTrue(sp.link(gl, System.err)); + Assert.assertTrue(sp.linked()); + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + + Assert.assertEquals(vertices0_loc, vertices0.getLocation()); + GLSLMiscHelper.validateGLArrayDataServerState(gl, null, vertices0); + + Assert.assertEquals(colors0_loc, colors0.getLocation()); + GLSLMiscHelper.validateGLArrayDataServerState(gl, null, colors0); + + sp.useProgram(gl, true); + Assert.assertTrue(sp.inUse()); + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + + // setup mgl_PMVMatrix + final PMVMatrix pmvMatrix = new PMVMatrix(); + final GLUniformData pmvMatrixUniform = new GLUniformData("mgl_PMVMatrix", 4, 4, pmvMatrix.glGetPMvMatrixf()); + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + pmvMatrixUniform.setLocation(gl, sp.program()); + gl.glUniform(pmvMatrixUniform); + + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + + // Allocate Vertex Array1 + final GLArrayDataServer vertices1 = GLSLMiscHelper.createVertices(gl, null, sp.program(), -1, GLSLMiscHelper.vertices1); + System.err.println("vertices1: " + vertices1); + vertices1.enableBuffer(gl, false); + GLSLMiscHelper.validateGLArrayDataServerState(gl, null, vertices1); + + // Allocate Color Array1 + final GLArrayDataServer colors1 = GLSLMiscHelper.createColors(gl, null, sp.program(), -1, GLSLMiscHelper.colors1); + System.err.println("colors1: " + colors1); + colors1.enableBuffer(gl, false); + GLSLMiscHelper.validateGLArrayDataServerState(gl, null, colors1); + + // misc GL setup + gl.glClearColor(0, 0, 0, 1); + gl.glEnable(GL2ES2.GL_DEPTH_TEST); + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + + // reshape + pmvMatrix.glMatrixMode(PMVMatrix.GL_PROJECTION); + pmvMatrix.glLoadIdentity(); + pmvMatrix.gluPerspective(45.0F, (float) drawable.getWidth() / (float) drawable.getHeight(), 1.0F, 100.0F); + pmvMatrix.glMatrixMode(PMVMatrix.GL_MODELVIEW); + pmvMatrix.glLoadIdentity(); + pmvMatrix.glTranslatef(0, 0, -10); + gl.glUniform(pmvMatrixUniform); + + gl.glViewport(0, 0, drawable.getWidth(), drawable.getHeight()); + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + + // display #1 vertices0 / colors0 (post-disable) + GLSLMiscHelper.displayVCArrays(drawable, gl, null, true, vertices0, colors0, true, 1, durationPerTest); + + // display #2 #1 vertices1 / colors1 (post-disable) + GLSLMiscHelper.displayVCArrays(drawable, gl, null, true, vertices1, colors1, true, 2, durationPerTest); + + // display #3 vertices0 / colors0 (post-disable) + GLSLMiscHelper.displayVCArrays(drawable, gl, null, true, vertices0, colors0, true, 3, durationPerTest); + + // cleanup + sp.useProgram(gl, false); + sp.destroy(gl); + vertices1.destroy(gl); + colors0.destroy(gl); + colors1.destroy(gl); + + NEWTGLContext.destroyWindow(winctx); + } + + @Test + public void test01ShaderState_Validation() throws InterruptedException { // preset .. final NEWTGLContext.WindowContext winctx = NEWTGLContext.createOnscreenWindow( new GLCapabilities(GLProfile.getGL2ES2()), 480, 480, true); @@ -95,33 +211,27 @@ public class TestGLSLShaderState01NEWT extends UITestCase { Assert.assertTrue(!sp.inUse()); Assert.assertTrue(!sp.linked()); - Assert.assertEquals(null, ShaderState.getShaderState(gl)); - st.setShaderState(gl); // pre-use attach - Assert.assertEquals(st, ShaderState.getShaderState(gl)); - // Allocate Vertex Array0 - final GLArrayDataServer vertices0 = GLSLMiscHelper.createRSVertices0(gl, vertices0_loc); + final GLArrayDataServer vertices0 = GLSLMiscHelper.createVertices(gl, st, 0, vertices0_loc, GLSLMiscHelper.vertices0); System.err.println("vertices0: " + vertices0); vertices0.enableBuffer(gl, false); Assert.assertEquals(vertices0_loc, vertices0.getLocation()); - st.ownAttribute(vertices0, true); // Allocate Color Array0 - final GLArrayDataServer colors0 = GLSLMiscHelper.createRSColors0(gl, colors0_loc); + final GLArrayDataServer colors0 = GLSLMiscHelper.createColors(gl, st, 0, colors0_loc, GLSLMiscHelper.colors0); System.err.println("colors0: " + colors0); colors0.enableBuffer(gl, false); Assert.assertEquals(colors0_loc, colors0.getLocation()); - st.ownAttribute(colors0, true); Assert.assertTrue(sp.link(gl, System.err)); Assert.assertTrue(sp.linked()); Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); Assert.assertEquals(vertices0_loc, vertices0.getLocation()); - GLSLMiscHelper.validateGLArrayDataServerState(gl, vertices0); + GLSLMiscHelper.validateGLArrayDataServerState(gl, st, vertices0); Assert.assertEquals(colors0_loc, colors0.getLocation()); - GLSLMiscHelper.validateGLArrayDataServerState(gl, colors0); + GLSLMiscHelper.validateGLArrayDataServerState(gl, st, colors0); st.useProgram(gl, true); Assert.assertTrue(sp.inUse()); @@ -138,18 +248,16 @@ public class TestGLSLShaderState01NEWT extends UITestCase { Assert.assertEquals(pmvMatrixUniform, st.getUniform("mgl_PMVMatrix")); // Allocate Vertex Array1 - final GLArrayDataServer vertices1 = GLSLMiscHelper.createRSVertices1(gl); + final GLArrayDataServer vertices1 = GLSLMiscHelper.createVertices(gl, st, 0, -1, GLSLMiscHelper.vertices1); System.err.println("vertices1: " + vertices1); vertices1.enableBuffer(gl, false); - GLSLMiscHelper.validateGLArrayDataServerState(gl, vertices1); - st.ownAttribute(vertices1, true); + GLSLMiscHelper.validateGLArrayDataServerState(gl, st, vertices1); // Allocate Color Array1 - final GLArrayDataServer colors1 = GLSLMiscHelper.createRSColors1(gl); + final GLArrayDataServer colors1 = GLSLMiscHelper.createColors(gl, st, 0, -1, GLSLMiscHelper.colors1); System.err.println("colors1: " + colors1); colors1.enableBuffer(gl, false); - GLSLMiscHelper.validateGLArrayDataServerState(gl, colors1); - st.ownAttribute(colors0, true); + GLSLMiscHelper.validateGLArrayDataServerState(gl, st, colors1); // misc GL setup gl.glClearColor(0, 0, 0, 1); @@ -168,13 +276,13 @@ public class TestGLSLShaderState01NEWT extends UITestCase { Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); // display #1 vertices0 / colors0 (post-disable) - GLSLMiscHelper.displayVCArrays(drawable, gl, true, vertices0, colors0, true, 1, durationPerTest); + GLSLMiscHelper.displayVCArrays(drawable, gl, st, true, vertices0, colors0, true, 1, durationPerTest); // display #2 #1 vertices1 / colors1 (post-disable) - GLSLMiscHelper.displayVCArrays(drawable, gl, true, vertices1, colors1, true, 2, durationPerTest); + GLSLMiscHelper.displayVCArrays(drawable, gl, st, true, vertices1, colors1, true, 2, durationPerTest); // display #3 vertices0 / colors0 (post-disable) - GLSLMiscHelper.displayVCArrays(drawable, gl, true, vertices0, colors0, true, 3, durationPerTest); + GLSLMiscHelper.displayVCArrays(drawable, gl, st, true, vertices0, colors0, true, 3, durationPerTest); // cleanup st.destroy(gl); @@ -183,15 +291,15 @@ public class TestGLSLShaderState01NEWT extends UITestCase { } @Test(timeout=240000) - public void testShaderState00PerformanceSingleKeepEnabled() throws InterruptedException { - testShaderState00PerformanceSingle(false); + public void test02ShaderState_PerformanceSingleKeepEnabled() throws InterruptedException { + testShaderState_PerformanceSingleImpl(false); } @Test(timeout=240000) - public void testShaderState00PerformanceSingleToggleEnable() throws InterruptedException { - testShaderState00PerformanceSingle(true); + public void test03ShaderState_PerformanceSingleToggleEnable() throws InterruptedException { + testShaderState_PerformanceSingleImpl(true); } - void testShaderState00PerformanceSingle(boolean toggleEnable) throws InterruptedException { + private void testShaderState_PerformanceSingleImpl(boolean toggleEnable) throws InterruptedException { // preset .. final NEWTGLContext.WindowContext winctx = NEWTGLContext.createOnscreenWindow( new GLCapabilities(GLProfile.getGL2ES2()), 480, 480, false); @@ -226,13 +334,11 @@ public class TestGLSLShaderState01NEWT extends UITestCase { st.uniform(gl, pmvMatrixUniform); // Allocate Vertex Array0 - final GLArrayDataServer vertices0 = GLSLMiscHelper.createRSVertices0(gl, -1); - st.ownAttribute(vertices0, true); + final GLArrayDataServer vertices0 = GLSLMiscHelper.createVertices(gl, st, 0, -1, GLSLMiscHelper.vertices0); vertices0.enableBuffer(gl, toggleEnable ? false : true); // Allocate Color Array0 - final GLArrayDataServer colors0 = GLSLMiscHelper.createRSColors0(gl, -1); - st.ownAttribute(colors0, true); + final GLArrayDataServer colors0 = GLSLMiscHelper.createColors(gl, st, 0, -1, GLSLMiscHelper.colors0); colors0.enableBuffer(gl, toggleEnable ? false : true); // misc GL setup @@ -252,7 +358,7 @@ public class TestGLSLShaderState01NEWT extends UITestCase { gl.setSwapInterval(0); // validation .. - GLSLMiscHelper.displayVCArrays(drawable, gl, toggleEnable, vertices0, colors0, toggleEnable, 1, 0); + GLSLMiscHelper.displayVCArrays(drawable, gl, st, toggleEnable, vertices0, colors0, toggleEnable, 1, 0); // warmup .. for(int frames=0; frames<GLSLMiscHelper.frames_warmup; frames++) { @@ -280,7 +386,7 @@ public class TestGLSLShaderState01NEWT extends UITestCase { } @Test(timeout=240000) - public void testShaderState01PerformanceDouble() throws InterruptedException { + public void test04ShaderState_PerformanceDouble() throws InterruptedException { // preset .. final NEWTGLContext.WindowContext winctx = NEWTGLContext.createOnscreenWindow( new GLCapabilities(GLProfile.getGL2ES2()), 480, 480, false); @@ -315,23 +421,19 @@ public class TestGLSLShaderState01NEWT extends UITestCase { st.uniform(gl, pmvMatrixUniform); // Allocate Vertex Array0 - final GLArrayDataServer vertices0 = GLSLMiscHelper.createRSVertices0(gl, -1); - st.ownAttribute(vertices0, true); + final GLArrayDataServer vertices0 = GLSLMiscHelper.createVertices(gl, st, 0, -1, GLSLMiscHelper.vertices0); vertices0.enableBuffer(gl, false); // Allocate Vertex Array1 - final GLArrayDataServer vertices1 = GLSLMiscHelper.createRSVertices1(gl); - st.ownAttribute(vertices1, true); + final GLArrayDataServer vertices1 = GLSLMiscHelper.createVertices(gl, st, 0, -1, GLSLMiscHelper.vertices1); vertices1.enableBuffer(gl, false); // Allocate Color Array0 - final GLArrayDataServer colors0 = GLSLMiscHelper.createRSColors0(gl, -1); - st.ownAttribute(colors0, true); + final GLArrayDataServer colors0 = GLSLMiscHelper.createColors(gl, st, 0, -1, GLSLMiscHelper.colors0); colors0.enableBuffer(gl, false); // Allocate Color Array1 - final GLArrayDataServer colors1 = GLSLMiscHelper.createRSColors1(gl); - st.ownAttribute(colors1, true); + final GLArrayDataServer colors1 = GLSLMiscHelper.createColors(gl, st, 0, -1, GLSLMiscHelper.colors1); colors1.enableBuffer(gl, false); // misc GL setup @@ -351,8 +453,8 @@ public class TestGLSLShaderState01NEWT extends UITestCase { gl.setSwapInterval(0); // validation .. - GLSLMiscHelper.displayVCArrays(drawable, gl, true, vertices0, colors0, true, 1, 0); - GLSLMiscHelper.displayVCArrays(drawable, gl, true, vertices1, colors1, true, 2, 0); + GLSLMiscHelper.displayVCArrays(drawable, gl, st, true, vertices0, colors0, true, 1, 0); + GLSLMiscHelper.displayVCArrays(drawable, gl, st, true, vertices1, colors1, true, 2, 0); // warmup .. for(int frames=0; frames<GLSLMiscHelper.frames_warmup; frames+=2) { @@ -397,7 +499,7 @@ public class TestGLSLShaderState01NEWT extends UITestCase { while(-1 == System.in.read()) ; TestGLSLShaderState01NEWT tst = new TestGLSLShaderState01NEWT(); try { - tst.testShaderState01PerformanceDouble(); + tst.test04ShaderState_PerformanceDouble(); } catch (Exception e) { e.printStackTrace(); } diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestGLSLShaderState02NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestGLSLShaderState02NEWT.java index 7022b7400..1ba7d9edb 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestGLSLShaderState02NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestGLSLShaderState02NEWT.java @@ -121,20 +121,15 @@ public class TestGLSLShaderState02NEWT extends UITestCase { st.attachShaderProgram(gl, sp0, false); Assert.assertTrue(!sp0.inUse()); Assert.assertTrue(!sp0.linked()); - Assert.assertEquals(null, ShaderState.getShaderState(gl)); - st.setShaderState(gl); // pre-use attach - Assert.assertEquals(st, ShaderState.getShaderState(gl)); // Allocate Vertex Array0 - final GLArrayDataServer vertices0 = GLSLMiscHelper.createRSVertices0(gl, vertices0_loc); - st.ownAttribute(vertices0, true); + final GLArrayDataServer vertices0 = GLSLMiscHelper.createVertices(gl, st, 0, vertices0_loc, GLSLMiscHelper.vertices0); System.err.println("vertices0: " + vertices0); vertices0.enableBuffer(gl, false); Assert.assertEquals(vertices0_loc, vertices0.getLocation()); // Allocate Color Array0 - final GLArrayDataServer colors0 = GLSLMiscHelper.createRSColors0(gl, colors0_loc); - st.ownAttribute(colors0, true); + final GLArrayDataServer colors0 = GLSLMiscHelper.createColors(gl, st, 0, colors0_loc, GLSLMiscHelper.colors0); System.err.println("colors0: " + colors0); colors0.enableBuffer(gl, false); Assert.assertEquals(colors0_loc, colors0.getLocation()); @@ -166,14 +161,12 @@ public class TestGLSLShaderState02NEWT extends UITestCase { Assert.assertEquals(pmvMatrixUniform, st.getUniform("mgl_PMVMatrix")); // Allocate Vertex Array1 - final GLArrayDataServer vertices1 = GLSLMiscHelper.createRSVertices1(gl); - st.ownAttribute(vertices1, true); + final GLArrayDataServer vertices1 = GLSLMiscHelper.createVertices(gl, st, 0, -1, GLSLMiscHelper.vertices1); System.err.println("vertices1: " + vertices1); vertices1.enableBuffer(gl, false); // Allocate Color Array1 - final GLArrayDataServer colors1 = GLSLMiscHelper.createRSColors1(gl); - st.ownAttribute(colors1, true); + final GLArrayDataServer colors1 = GLSLMiscHelper.createColors(gl, st, 0, -1, GLSLMiscHelper.colors1); System.err.println("colors1: " + colors1); colors1.enableBuffer(gl, false); @@ -194,16 +187,16 @@ public class TestGLSLShaderState02NEWT extends UITestCase { Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); // display #1 vertices0 / colors0 (post-disable) - GLSLMiscHelper.displayVCArrays(drawable, gl, true, vertices0, colors0, true, 1, durationPerTest); + GLSLMiscHelper.displayVCArrays(drawable, gl, st, true, vertices0, colors0, true, 1, durationPerTest); // display #2 vertices1 / colors1 (post-disable) - GLSLMiscHelper.displayVCArrays(drawable, gl, true, vertices1, colors1, true, 2, durationPerTest); + GLSLMiscHelper.displayVCArrays(drawable, gl, st, true, vertices1, colors1, true, 2, durationPerTest); // display #3 vertices0 / colors0 (post-disable) - GLSLMiscHelper.displayVCArrays(drawable, gl, true, vertices0, colors0, true, 3, durationPerTest); + GLSLMiscHelper.displayVCArrays(drawable, gl, st, true, vertices0, colors0, true, 3, durationPerTest); // display #4 vertices1 / colors1 (post-disable) - GLSLMiscHelper.displayVCArrays(drawable, gl, true, vertices1, colors1, true, 4, durationPerTest); + GLSLMiscHelper.displayVCArrays(drawable, gl, st, true, vertices1, colors1, true, 4, durationPerTest); // SP1 st.attachShaderProgram(gl, sp1, true); @@ -222,16 +215,16 @@ public class TestGLSLShaderState02NEWT extends UITestCase { } // display #1 vertices0 / colors0 (post-disable) - GLSLMiscHelper.displayVCArrays(drawable, gl, true, vertices0, colors0, true, 10, durationPerTest); + GLSLMiscHelper.displayVCArrays(drawable, gl, st, true, vertices0, colors0, true, 10, durationPerTest); // display #2 vertices1 / colors1 (post-disable) - GLSLMiscHelper.displayVCArrays(drawable, gl, true, vertices1, colors1, true, 20, durationPerTest); + GLSLMiscHelper.displayVCArrays(drawable, gl, st, true, vertices1, colors1, true, 20, durationPerTest); // display #3 vertices0 / colors0 (post-disable) - GLSLMiscHelper.displayVCArrays(drawable, gl, true, vertices0, colors0, true, 30, durationPerTest); + GLSLMiscHelper.displayVCArrays(drawable, gl, st, true, vertices0, colors0, true, 30, durationPerTest); // display #4 vertices1 / colors1 (post-disable) - GLSLMiscHelper.displayVCArrays(drawable, gl, true, vertices1, colors1, true, 40, durationPerTest); + GLSLMiscHelper.displayVCArrays(drawable, gl, st, true, vertices1, colors1, true, 40, durationPerTest); // cleanup st.destroy(gl); @@ -286,23 +279,19 @@ public class TestGLSLShaderState02NEWT extends UITestCase { st.uniform(gl, pmvMatrixUniform); // Allocate Vertex Array0 - final GLArrayDataServer vertices0 = GLSLMiscHelper.createRSVertices0(gl, -1); - st.ownAttribute(vertices0, true); + final GLArrayDataServer vertices0 = GLSLMiscHelper.createVertices(gl, st, 0, -1, GLSLMiscHelper.vertices0); vertices0.enableBuffer(gl, false); // Allocate Vertex Array1 - final GLArrayDataServer vertices1 = GLSLMiscHelper.createRSVertices1(gl); - st.ownAttribute(vertices1, true); + final GLArrayDataServer vertices1 = GLSLMiscHelper.createVertices(gl, st, 0, -1, GLSLMiscHelper.vertices1); vertices1.enableBuffer(gl, false); // Allocate Color Array0 - final GLArrayDataServer colors0 = GLSLMiscHelper.createRSColors0(gl, -1); - st.ownAttribute(colors0, true); + final GLArrayDataServer colors0 = GLSLMiscHelper.createColors(gl, st, 0, -1, GLSLMiscHelper.colors0); colors0.enableBuffer(gl, false); // Allocate Color Array1 - final GLArrayDataServer colors1 = GLSLMiscHelper.createRSColors1(gl); - st.ownAttribute(colors1, true); + final GLArrayDataServer colors1 = GLSLMiscHelper.createColors(gl, st, 0, -1, GLSLMiscHelper.colors1); colors1.enableBuffer(gl, false); // misc GL setup @@ -323,11 +312,11 @@ public class TestGLSLShaderState02NEWT extends UITestCase { // validation .. st.attachShaderProgram(gl, sp0, true); - GLSLMiscHelper.displayVCArrays(drawable, gl, true, vertices0, colors0, true, 1, 0); - GLSLMiscHelper.displayVCArrays(drawable, gl, true, vertices1, colors1, true, 2, 0); + GLSLMiscHelper.displayVCArrays(drawable, gl, st, true, vertices0, colors0, true, 1, 0); + GLSLMiscHelper.displayVCArrays(drawable, gl, st, true, vertices1, colors1, true, 2, 0); st.attachShaderProgram(gl, sp1, true); - GLSLMiscHelper.displayVCArrays(drawable, gl, true, vertices0, colors0, true, 1, 0); - GLSLMiscHelper.displayVCArrays(drawable, gl, true, vertices1, colors1, true, 2, 0); + GLSLMiscHelper.displayVCArrays(drawable, gl, st, true, vertices0, colors0, true, 1, 0); + GLSLMiscHelper.displayVCArrays(drawable, gl, st, true, vertices1, colors1, true, 2, 0); // warmup .. for(int frames=0; frames<GLSLMiscHelper.frames_warmup; frames+=2) { diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/util/DemoGL2ES1ImmModeSink.java b/src/test/com/jogamp/opengl/test/junit/jogl/util/DemoGL2ES1ImmModeSink.java index 276fb17f9..c82e7def4 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/util/DemoGL2ES1ImmModeSink.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/util/DemoGL2ES1ImmModeSink.java @@ -1,3 +1,30 @@ +/** + * Copyright 2012 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ package com.jogamp.opengl.test.junit.jogl.util; import javax.media.opengl.GL; @@ -68,8 +95,6 @@ class DemoGL2ES1ImmModeSink implements GLEventListener { gl.glMatrixMode( GL2ES1.GL_MODELVIEW ); gl.glLoadIdentity(); - - gl.glViewport( 0, 0, width, height ); } @Override @@ -79,15 +104,13 @@ class DemoGL2ES1ImmModeSink implements GLEventListener { gl.glClear( GL.GL_COLOR_BUFFER_BIT ); // draw a triangle filling the window - gl.glLoadIdentity(); - ims.glBegin(GL.GL_TRIANGLES); ims.glColor3f( 1, 0, 0 ); ims.glVertex2f( 0, 0 ); ims.glColor3f( 0, 1, 0 ); - ims.glVertex2f( TestImmModeSinkES1NEWT.iWidth, 0 ); + ims.glVertex2f( drawable.getWidth(), 0 ); ims.glColor3f( 0, 0, 1 ); - ims.glVertex2f( TestImmModeSinkES1NEWT.iWidth / 2, TestImmModeSinkES1NEWT.iHeight ); + ims.glVertex2f( drawable.getWidth() / 2, drawable.getHeight() ); ims.glEnd(gl, true); } diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/util/DemoGL2ES1Plain.java b/src/test/com/jogamp/opengl/test/junit/jogl/util/DemoGL2ES1Plain.java index b66a0955c..0df368615 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/util/DemoGL2ES1Plain.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/util/DemoGL2ES1Plain.java @@ -1,3 +1,30 @@ +/** + * Copyright 2012 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ package com.jogamp.opengl.test.junit.jogl.util; import java.nio.ByteBuffer; diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/util/DemoGL2ES2ImmModeSink.java b/src/test/com/jogamp/opengl/test/junit/jogl/util/DemoGL2ES2ImmModeSink.java new file mode 100644 index 000000000..b38ae85e8 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/util/DemoGL2ES2ImmModeSink.java @@ -0,0 +1,207 @@ +/** + * Copyright 2012 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package com.jogamp.opengl.test.junit.jogl.util; + +import javax.media.opengl.GL; +import javax.media.opengl.GL2ES2; +import javax.media.opengl.GLAutoDrawable; +import javax.media.opengl.GLEventListener; +import javax.media.opengl.GLException; +import javax.media.opengl.GLUniformData; +import javax.media.opengl.fixedfunc.GLMatrixFunc; + +import com.jogamp.opengl.util.ImmModeSink; +import com.jogamp.opengl.util.PMVMatrix; +import com.jogamp.opengl.util.glsl.ShaderCode; +import com.jogamp.opengl.util.glsl.ShaderProgram; +import com.jogamp.opengl.util.glsl.ShaderState; + +public class DemoGL2ES2ImmModeSink implements GLEventListener { + + private final ShaderState st; + private final PMVMatrix pmvMatrix; + private int glBufferUsage; + private ShaderProgram sp; + private GLUniformData pmvMatrixUniform; + private ImmModeSink ims; + + public DemoGL2ES2ImmModeSink(boolean useVBO, boolean useShaderState) { + if(useShaderState) { + st = new ShaderState(); + st.setVerbose(true); + } else { + st = null; + } + glBufferUsage = useVBO ? GL.GL_STATIC_DRAW : 0; + pmvMatrix = new PMVMatrix(); + } + + static final String[] es2_prelude = { "#version 100\n", "precision mediump float;\n" }; + static final String gl2_prelude = "#version 110\n"; + + public void init(GLAutoDrawable glad) { + final GL2ES2 gl = glad.getGL().getGL2ES2(); + + System.err.println("GL_VENDOR "+gl.glGetString(GL.GL_VENDOR)); + System.err.println("GL_RENDERER "+gl.glGetString(GL.GL_RENDERER)); + System.err.println("GL_VERSION "+gl.glGetString(GL.GL_VERSION)); + + final ShaderCode vp0 = ShaderCode.create(gl, GL2ES2.GL_VERTEX_SHADER, DemoGL2ES2ImmModeSink.class, + "../demos/es2/shader", "../demos/es2/shader/bin", "mgl_default_xxx", true); + final ShaderCode fp0 = ShaderCode.create(gl, GL2ES2.GL_FRAGMENT_SHADER, DemoGL2ES2ImmModeSink.class, + "../demos/es2/shader", "../demos/es2/shader/bin", "mgl_default_xxx", true); + + // Prelude shader code w/ GLSL profile specifics [ 1. pre-proc, 2. other ] + int fp0Pos; + if(gl.isGLES2()) { + vp0.insertShaderSource(0, 0, es2_prelude[0]); + fp0Pos = fp0.insertShaderSource(0, 0, es2_prelude[0]); + } else { + vp0.insertShaderSource(0, 0, gl2_prelude); + fp0Pos = fp0.insertShaderSource(0, 0, gl2_prelude); + } + if(gl.isGLES2()) { + fp0Pos = fp0.insertShaderSource(0, fp0Pos, es2_prelude[1]); + } + + sp = new ShaderProgram(); + sp.add(gl, vp0, System.err); + sp.add(gl, fp0, System.err); + if( null != st ) { + st.attachShaderProgram(gl, sp, true); + } else { + if(!sp.link(gl, System.err)) { + throw new GLException("Could not link program: "+sp); + } + sp.useProgram(gl, true); + } + + pmvMatrixUniform = new GLUniformData("mgl_PMVMatrix", 4, 4, pmvMatrix.glGetPMvMatrixf()); + if(null != st) { + st.ownUniform(pmvMatrixUniform); + st.uniform(gl, pmvMatrixUniform); + } else { + if( pmvMatrixUniform.setLocation(gl, sp.program()) < 0 ) { + throw new GLException("Could not find location for uniform: "+pmvMatrixUniform+", "+sp); + } + gl.glUniform(pmvMatrixUniform); + } + + // Using predef array names, see + // GLPointerFuncUtil.getPredefinedArrayIndexName(glArrayIndex); + if( null != st ) { + ims = ImmModeSink.createGLSL(40, + 3, GL.GL_FLOAT, // vertex + 4, GL.GL_FLOAT, // color + 0, GL.GL_FLOAT, // normal + 0, GL.GL_FLOAT, // texCoords + glBufferUsage, st); + } else { + ims = ImmModeSink.createGLSL(40, + 3, GL.GL_FLOAT, // vertex + 4, GL.GL_FLOAT, // color + 0, GL.GL_FLOAT, // normal + 0, GL.GL_FLOAT, // texCoords + glBufferUsage, sp.program()); + } + final int numSteps = 20; + final double increment = Math.PI / numSteps; + final double radius = 1; + ims.glBegin(GL.GL_LINES); + for (int i = numSteps - 1; i >= 0; i--) { + ims.glVertex3f((float) (radius * Math.cos(i * increment)), + (float) (radius * Math.sin(i * increment)), + 0f); + ims.glColor4f( 1f, 1f, 1f, 1f ); + ims.glVertex3f((float) (-1.0 * radius * Math.cos(i * increment)), + (float) (-1.0 * radius * Math.sin(i * increment)), + 0f); + ims.glColor4f( 1f, 1f, 1f, 1f ); + } + ims.glEnd(gl, false); + + if(null != st) { + st.useProgram(gl, false); + } else { + gl.glUseProgram(0); + } + } + + public void dispose(GLAutoDrawable glad) { + final GL2ES2 gl = glad.getGL().getGL2ES2(); + ims.destroy(gl); + ims = null; + if(null != st) { + st.destroy(gl); + } + } + + public void display(GLAutoDrawable drawable) { + final GL2ES2 gl = drawable.getGL().getGL2ES2(); + + gl.glClear( GL.GL_COLOR_BUFFER_BIT ); + + // draw a triangle filling the window + ims.glBegin(GL.GL_TRIANGLES); + ims.glColor3f( 1, 0, 0 ); + ims.glVertex2f( 0, 0 ); + ims.glColor3f( 0, 1, 0 ); + ims.glVertex2f( drawable.getWidth(), 0 ); + ims.glColor3f( 0, 0, 1 ); + ims.glVertex2f( drawable.getWidth() / 2, drawable.getHeight() ); + ims.glEnd(gl, true); + } + + // Unused routines + public void reshape(GLAutoDrawable glad, int x, int y, int width, int height) { + System.err.println("reshape .."); + final GL2ES2 gl = glad.getGL().getGL2ES2(); + pmvMatrix.glMatrixMode(GLMatrixFunc.GL_PROJECTION); + pmvMatrix.glLoadIdentity(); + + // coordinate system origin at lower left with width and height same as the window + pmvMatrix.glOrthof( 0.0f, width, 0.0f, height, -1, 1 ); + + pmvMatrix.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); + pmvMatrix.glLoadIdentity(); + + if(null != st) { + st.useProgram(gl, true); + st.uniform(gl, pmvMatrixUniform); + st.useProgram(gl, false); + } else { + gl.glUseProgram(sp.program()); + gl.glUniform(pmvMatrixUniform); + gl.glUseProgram(0); + } + } + + public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) { + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/util/TestImmModeSinkES2NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/util/TestImmModeSinkES2NEWT.java new file mode 100644 index 000000000..48f1df757 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/util/TestImmModeSinkES2NEWT.java @@ -0,0 +1,119 @@ +/** + * Copyright 2010 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package com.jogamp.opengl.test.junit.jogl.util; + +import java.io.IOException; + +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLCapabilitiesImmutable; +import javax.media.opengl.GLEventListener; +import javax.media.opengl.GLProfile; + +import org.junit.Test; + +import com.jogamp.newt.opengl.GLWindow; +import com.jogamp.opengl.test.junit.util.MiscUtils; +import com.jogamp.opengl.test.junit.util.UITestCase; + +/** + * Testing the ImmModeSink w/ GL2ES1 context + */ +public class TestImmModeSinkES2NEWT extends UITestCase { + static int duration = 100; + static final int iWidth = 400; + static final int iHeight = 400; + + static GLCapabilities getCaps(String profile) { + if( !GLProfile.isAvailable(profile) ) { + System.err.println("Profile "+profile+" n/a"); + return null; + } + return new GLCapabilities(GLProfile.get(profile)); + } + + void doTest(GLCapabilitiesImmutable reqGLCaps, GLEventListener demo) throws InterruptedException { + System.out.println("Requested GL Caps: "+reqGLCaps); + + // + // Create native windowing resources .. X11/Win/OSX + // + final GLWindow glad = GLWindow.create(reqGLCaps); + glad.addGLEventListener(demo); + + final SnapshotGLEventListener snapshotGLEventListener = new SnapshotGLEventListener(); + glad.addGLEventListener(snapshotGLEventListener); + glad.setSize(iWidth, iHeight); + glad.setVisible(true); + + snapshotGLEventListener.setMakeSnapshot(); + glad.display(); // initial resize/display + + Thread.sleep(duration); + + glad.destroy(); + } + + @Test + public void test05ImmSinkGL2ES2_VBOOff_Direct() throws InterruptedException { + final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2ES2); + if(null == reqGLCaps) return; + doTest(reqGLCaps, new DemoGL2ES2ImmModeSink(false, false)); + } + + @Test + public void test05ImmSinkGL2ES2_VBOOff_ShaderState() throws InterruptedException { + final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2ES2); + if(null == reqGLCaps) return; + doTest(reqGLCaps, new DemoGL2ES2ImmModeSink(false, true)); + } + + @Test + public void test06ImmSinkGL2ES2_VBOOn_Direct() throws InterruptedException { + final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2ES2); + if(null == reqGLCaps) return; + doTest(reqGLCaps, new DemoGL2ES2ImmModeSink(true, false)); + } + + @Test + public void test06ImmSinkGL2ES2_VBOOn_ShaderState() throws InterruptedException { + final GLCapabilities reqGLCaps = getCaps(GLProfile.GL2ES2); + if(null == reqGLCaps) return; + doTest(reqGLCaps, new DemoGL2ES2ImmModeSink(true, true)); + } + + public static void main(String args[]) throws IOException { + for(int i=0; i<args.length; i++) { + if(args[i].equals("-time")) { + duration = MiscUtils.atoi(args[++i], duration); + } + } + org.junit.runner.JUnitCore.main(TestImmModeSinkES2NEWT.class.getName()); + } + +} |