diff options
author | Sven Gothel <[email protected]> | 2011-05-16 03:48:29 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2011-05-16 03:48:29 +0200 |
commit | a0777144c46d12d148556ed64ad0a9b9d6d24c0c (patch) | |
tree | 001516bbee1bb758c4c7c5e3d890ad071b8b6c2c /src/test/com/jogamp | |
parent | b82a409135f3b79889499d77c8ecffc80e310a20 (diff) |
JUnit Test: Add 'ruler' testcase using monitor mode's mm/pixel size.
Diffstat (limited to 'src/test/com/jogamp')
3 files changed, 212 insertions, 0 deletions
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/TestRulerNEWT01.java b/src/test/com/jogamp/opengl/test/junit/graph/TestRulerNEWT01.java new file mode 100644 index 000000000..a8b6fab20 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/graph/TestRulerNEWT01.java @@ -0,0 +1,166 @@ +/** + * 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.graph; + +import com.jogamp.common.nio.Buffers; +import com.jogamp.newt.util.MonitorMode; +import com.jogamp.opengl.util.GLArrayDataServer; +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; +import com.jogamp.opengl.test.junit.jogl.demos.es2.RedSquare0; +import com.jogamp.opengl.test.junit.util.MiscUtils; +import com.jogamp.opengl.test.junit.util.NEWTGLContext; +import com.jogamp.opengl.test.junit.util.UITestCase; + +import java.io.IOException; +import java.nio.FloatBuffer; + +import javax.media.nativewindow.util.DimensionReadOnly; +import javax.media.opengl.GL; +import javax.media.opengl.GL2ES2; +import javax.media.opengl.GLDrawable; +import javax.media.opengl.GLProfile; +import javax.media.opengl.GLUniformData; + +import org.junit.Assert; +import org.junit.Test; + +public class TestRulerNEWT01 extends UITestCase { + static long durationPerTest = 10; // ms + + @Test + public void test01() throws InterruptedException { + // preset .. + NEWTGLContext.WindowContext winctx = NEWTGLContext.createWindow(GLProfile.getGL2ES2(), 640, 480, true); + GLDrawable drawable = winctx.context.getGLDrawable(); + GL2ES2 gl = winctx.context.getGL().getGL2ES2(); + System.err.println(winctx.context); + + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + // test code .. + ShaderState st = new ShaderState(); + + ShaderCode rsVp = ShaderCode.create(gl, GL2ES2.GL_VERTEX_SHADER, 1, RedSquare0.class, + "shader", "shader/bin", "default"); + ShaderCode rsFp = ShaderCode.create(gl, GL2ES2.GL_FRAGMENT_SHADER, 1, RedSquare0.class, + "shader", "shader/bin", "ruler"); + + ShaderProgram sp = new ShaderProgram(); + 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()); + + st.attachShaderProgram(gl, sp); + st.useProgram(gl, true); + + PMVMatrix pmvMatrix = new PMVMatrix(); + GLUniformData pmvMatrixUniform = new GLUniformData("gcu_PMVMatrix", 4, 4, pmvMatrix.glGetPMvMatrixf()); + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + st.ownUniform(pmvMatrixUniform); + st.uniform(gl, pmvMatrixUniform); + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + + GLUniformData rulerColor= new GLUniformData("gcu_RulerColor", 3, Buffers.newDirectFloatBuffer(3)); + FloatBuffer rulerColorV = (FloatBuffer) rulerColor.getBuffer(); + rulerColorV.put(0, 0.5f); + rulerColorV.put(1, 0.5f); + rulerColorV.put(2, 0.5f); + st.ownUniform(rulerColor); + st.uniform(gl, rulerColor); + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + + MonitorMode mmode = winctx.window.getScreen().getCurrentScreenMode().getMonitorMode(); + DimensionReadOnly sdim = mmode.getScreenSizeMM(); + DimensionReadOnly spix = mmode.getSurfaceSize().getResolution(); + GLUniformData rulerPixFreq = new GLUniformData("gcu_RulerPixFreq", 2, Buffers.newDirectFloatBuffer(2)); + FloatBuffer rulerPixFreqV = (FloatBuffer) rulerPixFreq.getBuffer(); + rulerPixFreqV.put(0, (float)spix.getWidth() / (float)sdim.getWidth() * 10.0f); + rulerPixFreqV.put(1, (float)spix.getHeight() / (float)sdim.getHeight() * 10.0f); + st.ownUniform(rulerPixFreq); + st.uniform(gl, rulerPixFreq); + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + System.err.println("Screen dim "+sdim); + System.err.println("Screen siz "+spix); + System.err.println("Screen pixel/cm "+rulerPixFreqV.get(0)+", "+rulerPixFreqV.get(1)); + + GLArrayDataServer vertices0 = GLArrayDataServer.createGLSL(st, "gca_Vertices", 3, GL.GL_FLOAT, false, 4, GL.GL_STATIC_DRAW); + vertices0.putf(0); vertices0.putf(1); vertices0.putf(0); + vertices0.putf(1); vertices0.putf(1); vertices0.putf(0); + vertices0.putf(0); vertices0.putf(0); vertices0.putf(0); + vertices0.putf(1); vertices0.putf(0); vertices0.putf(0); + vertices0.seal(gl, true); + st.ownAttribute(vertices0, true); + + // misc GL setup + gl.glClearColor(1, 1, 1, 1); + gl.glEnable(GL2ES2.GL_DEPTH_TEST); + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + + // reshape + pmvMatrix.glMatrixMode(PMVMatrix.GL_PROJECTION); + pmvMatrix.glLoadIdentity(); + pmvMatrix.glOrthof(0f, 1f, 0f, 1f, -10f, 10f); + // 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, -6); + // pmvMatrix.glRotatef(45f, 1f, 0f, 0f); + st.uniform(gl, pmvMatrixUniform); + gl.glViewport(0, 0, drawable.getWidth(), drawable.getHeight()); + Assert.assertEquals(GL.GL_NO_ERROR, gl.glGetError()); + + for(int i=0; i<10; i++) { + vertices0.enableBuffer(gl, true); + gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); + gl.glDrawArrays(GL.GL_TRIANGLE_STRIP, 0, 4); + vertices0.enableBuffer(gl, false); + drawable.swapBuffers(); + Thread.sleep(durationPerTest/10); + } + + NEWTGLContext.destroyWindow(winctx); + } + + public static void main(String args[]) throws IOException { + System.err.println("main - start"); + for(int i=0; i<args.length; i++) { + if(args[i].equals("-time")) { + durationPerTest = MiscUtils.atoi(args[++i], (int)durationPerTest); + } + } + String tstname = TestRulerNEWT01.class.getName(); + org.junit.runner.JUnitCore.main(tstname); + System.err.println("main - end"); + } +} + diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/default.vp b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/default.vp new file mode 100644 index 000000000..4adbc5c96 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/default.vp @@ -0,0 +1,20 @@ +//Copyright 2010 JogAmp Community. All rights reserved. + +#ifdef GL_ES + #define MEDIUMP mediump + #define HIGHP highp + #define LOWP lowp +#else + #define MEDIUMP + #define HIGHP + #define LOWP +#endif + +uniform HIGHP mat4 gcu_PMVMatrix[3]; // P, Mv, and Mvi +attribute HIGHP vec4 gca_Vertices; + +void main(void) +{ + // gl_Position = gcu_PMVMatrix[0] * gcu_PMVMatrix[1] * vec4(gca_Vertices, 1); + gl_Position = gcu_PMVMatrix[0] * gcu_PMVMatrix[1] * gca_Vertices; +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/ruler.fp b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/ruler.fp new file mode 100644 index 000000000..f643ea104 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/shader/ruler.fp @@ -0,0 +1,26 @@ +//Copyright 2010 JogAmp Community. All rights reserved. + +#ifdef GL_ES + #define MEDIUMP mediump + #define HIGHP highp + #define LOWP lowp +#else + #define MEDIUMP + #define HIGHP + #define LOWP +#endif + +uniform HIGHP vec3 gcu_RulerColor; +uniform HIGHP vec2 gcu_RulerPixFreq; + +const vec2 onev2 = vec2(1.0, 1.0); + +void main (void) +{ + vec2 c = step( onev2, mod(gl_FragCoord.xy, gcu_RulerPixFreq) ); + if( c.s == 0.0 || c.t == 0.0 ) { + gl_FragColor = vec4(gcu_RulerColor, 1.0); + } else { + discard; + } +}
\ No newline at end of file |