diff options
Diffstat (limited to 'src/test/com/jogamp')
17 files changed, 1482 insertions, 57 deletions
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLProfile01NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLProfile01NEWT.java index 88caed357..d4f24bb19 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLProfile01NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLProfile01NEWT.java @@ -28,21 +28,22 @@ package com.jogamp.opengl.test.junit.jogl.acore; -import com.jogamp.common.GlueGenVersion; -import com.jogamp.common.util.VersionUtil; -import com.jogamp.nativewindow.NativeWindowVersion; -import com.jogamp.opengl.test.junit.util.UITestCase; -import com.jogamp.opengl.test.junit.util.DumpGLInfo; +import java.io.IOException; +import java.util.List; import org.junit.Assert; import org.junit.Test; import javax.media.opengl.*; -import com.jogamp.newt.opengl.*; -import com.jogamp.newt.*; +import com.jogamp.common.GlueGenVersion; +import com.jogamp.common.util.VersionUtil; +import com.jogamp.nativewindow.NativeWindowVersion; +import com.jogamp.opengl.test.junit.util.UITestCase; +import com.jogamp.opengl.test.junit.util.DumpGLInfo; import com.jogamp.opengl.JoglVersion; -import java.io.IOException; +import com.jogamp.newt.opengl.*; +import com.jogamp.newt.*; public class TestGLProfile01NEWT extends UITestCase { @@ -53,20 +54,19 @@ public class TestGLProfile01NEWT extends UITestCase { System.err.println(NativeWindowVersion.getInstance()); System.err.println(JoglVersion.getInstance()); System.err.println(NewtVersion.getInstance()); + + GLDrawableFactory factory = GLDrawableFactory.getFactory(GLProfile.getDefault()); + List/*<GLCapabilitiesImmutable>*/ availCaps = factory.getAvailableCapabilities(null); + for(int i=0; i<availCaps.size(); i++) { + System.err.println(availCaps.get(i)); + } } @Test public void test01GLProfileDefault() throws InterruptedException { System.out.println("GLProfile "+GLProfile.glAvailabilityToString()); GLProfile glp = GLProfile.getDefault(); - dumpVersion(glp); - } - - @Test - public void test02GLProfileMaxFixedFunc() throws InterruptedException { - // Assuming at least one fixed profile is available - GLProfile glp = GLProfile.getMaxFixedFunc(); - System.out.println("GLProfile getMaxFixedFunc(): "+glp); + System.out.println("GLProfile.getDefault(): "+glp); if(glp.getName().equals(GLProfile.GL4bc)) { Assert.assertTrue(GLProfile.isGL4bcAvailable()); Assert.assertTrue(GLProfile.isGL3bcAvailable()); @@ -89,10 +89,16 @@ public class TestGLProfile01NEWT extends UITestCase { } @Test + public void test02GL2() throws InterruptedException { + GLProfile glp = GLProfile.get(GLProfile.GL2); + dumpVersion(glp); + } + + @Test public void test03GLProfileMaxProgrammable() throws InterruptedException { // Assuming at least one programmable profile is available GLProfile glp = GLProfile.getMaxProgrammable(); - System.out.println("GLProfile getMaxProgrammable(): "+glp); + System.out.println("GLProfile.getMaxProgrammable(): "+glp); if(glp.getName().equals(GLProfile.GL4)) { Assert.assertTrue(GLProfile.isGL4Available()); Assert.assertTrue(GLProfile.isGL3Available()); diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestAWT01GLn.java b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestAWT01GLn.java index 83561eb97..21e1a4aca 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestAWT01GLn.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestAWT01GLn.java @@ -122,23 +122,11 @@ public class TestAWT01GLn extends UITestCase { } @Test - public void test03GLMaxFixed() throws InterruptedException { - GLProfile maxFixed = GLProfile.getMaxFixedFunc(); - System.out.println("GLProfile MaxFixed: "+maxFixed); - GLCapabilities caps = new GLCapabilities(maxFixed); - try { - runTestGL(caps); - } catch (Throwable t) { - // FIXME: - // Stop test and ignore if GL3bc and GL4bc - // currently this won't work on ATI! - if(maxFixed.equals(GLProfile.GL3bc) || - maxFixed.equals(GLProfile.GL4bc)) { - t.printStackTrace(); - Assume.assumeNoException(t); - } - // else .. serious unexpected exception - } + public void test02GL2() throws InterruptedException { + GLProfile glprofile = GLProfile.get(GLProfile.GL2); + System.out.println( "GLProfile GL2: " + glprofile ); + GLCapabilities caps = new GLCapabilities(glprofile); + runTestGL(caps); } public static void main(String args[]) { diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestSwingAWT01GLn.java b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestSwingAWT01GLn.java index 8f642dfc9..779ad7666 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestSwingAWT01GLn.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestSwingAWT01GLn.java @@ -134,23 +134,11 @@ public class TestSwingAWT01GLn extends UITestCase { } @Test - public void test03GLMaxFixed() throws InterruptedException, InvocationTargetException { - GLProfile maxFixed = GLProfile.getMaxFixedFunc(); - System.out.println("GLProfile MaxFixed: "+maxFixed); - GLCapabilities caps = new GLCapabilities(maxFixed); - try { - runTestGL(caps); - } catch (Throwable t) { - // FIXME: - // Stop test and ignore if GL3bc and GL4bc - // currently this won't work on ATI! - if(maxFixed.getName().equals(GLProfile.GL3bc) || - maxFixed.getName().equals(GLProfile.GL4bc)) { - t.printStackTrace(); - assumeNoException(t); - } - // else .. serious unexpected exception - } + public void test02GL2() throws InterruptedException, InvocationTargetException { + GLProfile glprofile = GLProfile.get(GLProfile.GL2); + System.out.println( "GLProfile GL2: " + glprofile ); + GLCapabilities caps = new GLCapabilities(glprofile); + runTestGL(caps); } public static void main(String args[]) { diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/awt/text/TestAWTTextRendererUseVertexArrayBug464.java b/src/test/com/jogamp/opengl/test/junit/jogl/awt/text/TestAWTTextRendererUseVertexArrayBug464.java new file mode 100644 index 000000000..fc19a6842 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/awt/text/TestAWTTextRendererUseVertexArrayBug464.java @@ -0,0 +1,155 @@ +/** + * Copyright 2011 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.awt.text; + +import javax.media.opengl.GLProfile; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.awt.GLCanvas; +import com.jogamp.opengl.util.Animator; + +import com.jogamp.opengl.test.junit.util.UITestCase; + +import java.awt.Frame; +import java.io.IOException; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.After; +import org.junit.Test; + +/* + * Unit tests for Bug464 + * Some ATI-Drivers crash the JVM if VBO-related glFunctions are called. This test checks + * if TextRenderer calls any of these functions while it's useVertexArray variable is set + * to false. + * 2D- and 3D-TextRendering is tested by creating a GLCanvas showing a simple line of text + * while filtering all glFunction calls by using a modified version of TraceGL2. + * VBO-related function are logged to the disallowedMethodCalls String of the GLEventListener + * instead of being executed (to prevent JVM crashes). Therefore, if the + * disallowedMethodCalls isn't an empty String after the test, the test fails. + * + * Other classes related to this test: + * TestTextRendererGLEventListener01 + * TestTextRendererTraceGL2Mock01 + */ + +public class TestAWTTextRendererUseVertexArrayBug464 extends UITestCase { + static GLProfile glp; + static GLCapabilities caps; + + private GLCanvas glCanvas; + private Frame frame; + + @BeforeClass + public static void initClass() { + GLProfile.initSingleton(true); + glp = GLProfile.get(GLProfile.GL2); + Assert.assertNotNull(glp); + caps = new GLCapabilities(glp); + Assert.assertNotNull(caps); + } + + @Before + public void initTest() { + glCanvas = new GLCanvas(caps); + + frame = new Frame("TextRenderer Test"); + Assert.assertNotNull(frame); + frame.add(glCanvas); + frame.setSize(512, 512); + frame.setVisible(true); + + } + + @After + public void cleanupTest() { + frame.setVisible(false); + frame.remove(glCanvas); + glCanvas=null; + Assert.assertNotNull(frame); + frame.dispose(); + frame=null; + } + + @Test + public void testTextRendererDraw2D() throws InterruptedException { + + TextRendererGLEventListener01 listener = new TextRendererGLEventListener01(1); + Assert.assertNotNull(listener); + glCanvas.addGLEventListener(listener); + Animator animator = new Animator(glCanvas); + + animator.start(); + + Thread.sleep(500); // 500 ms + + animator.stop(); + + String disallowedMethods = listener.getDisallowedMethodCalls(); + if (!disallowedMethods.equals("")) { + Assert.fail("Following VBO-related glMethods have been called: "+ disallowedMethods); + } + } + + @Test + public void testTextRendererDraw3D() throws InterruptedException { + + TextRendererGLEventListener01 listener = new TextRendererGLEventListener01(2); + Assert.assertNotNull(listener); + glCanvas.addGLEventListener(listener); + Animator animator = new Animator(glCanvas); + + animator.start(); + + Thread.sleep(500); // 500 ms + + animator.stop(); + + String disallowedMethods = listener.getDisallowedMethodCalls(); + if (!disallowedMethods.equals("")) { + Assert.fail("Following VBO-related glMethods have been called: "+ disallowedMethods); + } + } + + public static void main(String args[]) throws IOException { + String tstname = TestAWTTextRendererUseVertexArrayBug464.class.getName(); + org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] { + tstname, + "filtertrace=true", + "haltOnError=false", + "haltOnFailure=false", + "showoutput=true", + "outputtoformatters=true", + "logfailedtests=true", + "logtestlistenerevents=true", + "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter", + "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } ); + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/awt/text/TextRendererGLEventListener01.java b/src/test/com/jogamp/opengl/test/junit/jogl/awt/text/TextRendererGLEventListener01.java new file mode 100644 index 000000000..b14704142 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/awt/text/TextRendererGLEventListener01.java @@ -0,0 +1,124 @@ +/** + * Copyright 2011 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.awt.text; + +import java.awt.Font; +import java.io.OutputStream; +import java.io.PrintStream; + +import com.jogamp.opengl.util.awt.TextRenderer; +import javax.media.opengl.GL2ES1; +import javax.media.opengl.GL2; +import javax.media.opengl.GLAutoDrawable; +import javax.media.opengl.GLEventListener; +import javax.media.opengl.glu.GLU; + +import org.junit.Assert; + +/* + * Unit tests for Bug464 + * GLEventListener for unit test TestAWTTextRendererUseVertexArrayBug464. The display + * method renders the String "ABC123#+?" to the lower left corner of the canvas. + * + * The testNumber variable is used to switch between 2D- and 3D-textrendering in the display + * method. + * The disallowedMethodCalls variable is used to log VBO-related glFunction calls during + * the execution of the test. + * + * Other classes related to this test: + * TestAWTTextRendererUseVertexArrayBug464 + * TextRendererTraceGL2Mock01 + */ + +public class TextRendererGLEventListener01 implements GLEventListener { + private GLU glu = new GLU(); + private TextRenderer renderer; + private String text; + private String disallowedMethodCalls; + private int testNumber; + + public TextRendererGLEventListener01(int testNumber) { + this.disallowedMethodCalls = ""; + this.testNumber = testNumber; + } + + public void init(GLAutoDrawable drawable) { + renderer = new TextRenderer(new Font("SansSerif", Font.BOLD, 36)); + renderer.setUseVertexArrays(false); + Assert.assertNotNull(renderer); + Assert.assertFalse(renderer.getUseVertexArrays()); + + text = "ABC123#+?"; + + PrintStream nullStream = new PrintStream(new OutputStream(){ public void write(int b){}}); + drawable.setGL(new TextRendererTraceGL2Mock01(drawable.getGL().getGL2(), nullStream, this)); + } + + public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { + GL2 gl = drawable.getGL().getGL2(); + gl.glMatrixMode(GL2ES1.GL_PROJECTION); + gl.glLoadIdentity(); + glu.gluOrtho2D(0, 1, 0, 1); + gl.glMatrixMode(GL2ES1.GL_MODELVIEW); + gl.glLoadIdentity(); + } + + public void dispose(GLAutoDrawable drawable) { + renderer.dispose(); + } + + public void display(GLAutoDrawable drawable) { + if (disallowedMethodCalls.equals("")) { + if (testNumber == 1) { + renderer.beginRendering(drawable.getWidth(), drawable.getHeight()); + renderer.setColor(1.0f, 1.0f, 1.0f, 1.0f); + renderer.draw(text, 0, 0); + renderer.endRendering(); + } + if (testNumber == 2) { + renderer.begin3DRendering(); + renderer.setColor(1.0f, 1.0f, 1.0f, 1.0f); + renderer.draw3D(text, 0, 0, 0, 0.002f); + renderer.end3DRendering(); + } + } + } + + public void disallowedMethodCalled (String method) { + if (!disallowedMethodCalls.equals("")) { + disallowedMethodCalls += ", "; + } + disallowedMethodCalls += method; + } + + public String getDisallowedMethodCalls() { + return this.disallowedMethodCalls; + } +} + diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/awt/text/TextRendererTraceGL2Mock01.java b/src/test/com/jogamp/opengl/test/junit/jogl/awt/text/TextRendererTraceGL2Mock01.java new file mode 100644 index 000000000..63258a574 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/awt/text/TextRendererTraceGL2Mock01.java @@ -0,0 +1,137 @@ +/** + * Copyright 2011 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.awt.text; + +import java.io.PrintStream; +import java.nio.Buffer; +import java.nio.ByteBuffer; +import java.nio.IntBuffer; + +import javax.media.opengl.GL2; +import javax.media.opengl.TraceGL2; + +import com.jogamp.common.nio.Buffers; + +/* + * Unit tests for Bug464 + * Modified Version of TraceGL2 for unit test TestAWTTextRendererUseVertexArrayBug464. + * This class overrides all glFunctions related to VBO's according to + * http://code.google.com/p/glextensions/wiki/GL_ARB_vertex_buffer_object: + * glBindBuffer (glBindBufferARB) + * glDeleteBuffers (glDeleteBuffersARB) + * glGenBuffers (glGenBuffersARB) + * glIsBuffer (glIsBufferARB) + * glBufferData (glBufferDataARB) + * glBufferSubData (glBufferSubDataARB) + * glGetBufferSubData (glGetBufferSubDataARB) + * glMapBuffer (glMapBufferARB) + * glUnmapBuffer (glUnmapBufferARB) + * glGetBufferParameteriv (glGetBufferParameterivARB) + * glGetBufferPointerv (glGetBufferPointervARB) + * Calls to the overridden methods are logged to the disallowedMethodCalls variable of + * the GLEventListener instead of being passed to the downstreamGL object. + * + * Other classes related to this test: + * TestAWTTextRendererUseVertexArrayBug464 + * TextRendererGLEventListener01 + */ + +public class TextRendererTraceGL2Mock01 extends TraceGL2 { + + TextRendererGLEventListener01 listener; + + public TextRendererTraceGL2Mock01(GL2 downstreamGL2, PrintStream stream, TextRendererGLEventListener01 listener) { + super(downstreamGL2, stream); + this.listener = listener; + } + + @Override + public void glGetBufferSubData(int arg0, long arg1, long arg2, Buffer arg3) { + listener.disallowedMethodCalled("glGetBufferSubData"); + } + + @Override + public ByteBuffer glMapBuffer(int arg0, int arg1) { + listener.disallowedMethodCalled("glMapBuffer"); + return Buffers.newDirectByteBuffer(0); + } + + @Override + public void glGetBufferParameteriv(int arg0, int arg1, IntBuffer arg2) { + listener.disallowedMethodCalled("glGetBufferParameteriv"); + } + + @Override + public boolean glUnmapBuffer(int arg0) { + listener.disallowedMethodCalled("glUnmapBuffer"); + return false; + } + + @Override + public void glGenBuffers(int arg0, IntBuffer arg1) { + listener.disallowedMethodCalled("glGenBuffers"); + } + + @Override + public void glGenBuffers(int arg0, int[] arg1, int arg2) { + listener.disallowedMethodCalled("glGenBuffers"); + } + + @Override + public boolean glIsBuffer(int arg0) { + listener.disallowedMethodCalled("glIsBuffer"); + return false; + } + + @Override + public void glBindBuffer(int arg0, int arg1) { + listener.disallowedMethodCalled("glBindBuffer"); + } + + @Override + public void glDeleteBuffers(int arg0, int[] arg1, int arg2) { + listener.disallowedMethodCalled("glDeleteBuffers"); + } + + @Override + public void glBufferSubData(int arg0, long arg1, long arg2, Buffer arg3) { + listener.disallowedMethodCalled("glBufferSubData"); + } + + @Override + public void glGetBufferParameteriv(int arg0, int arg1, int[] arg2, int arg3) { + listener.disallowedMethodCalled("glGetBufferParameteriv"); + } + + @Override + public void glBufferData(int arg0, long arg1, Buffer arg2, int arg3) { + listener.disallowedMethodCalled("glBufferData"); + } + +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/caps/MultisampleChooser01.java b/src/test/com/jogamp/opengl/test/junit/jogl/caps/MultisampleChooser01.java index 9653038d1..c2182b8b7 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/caps/MultisampleChooser01.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/caps/MultisampleChooser01.java @@ -39,16 +39,17 @@ */ package com.jogamp.opengl.test.junit.jogl.caps; +import java.util.List; import javax.media.opengl.DefaultGLCapabilitiesChooser; import javax.media.opengl.GLCapabilitiesImmutable; class MultisampleChooser01 extends DefaultGLCapabilitiesChooser { - public int chooseCapabilities(GLCapabilitiesImmutable desired, GLCapabilitiesImmutable[] available, int windowSystemRecommendedChoice) { + public int chooseCapabilities(GLCapabilitiesImmutable desired, List/*<GLCapabilitiesImmutable>*/ available, int windowSystemRecommendedChoice) { boolean anyHaveSampleBuffers = false; - for (int i = 0; i < available.length; i++) { - GLCapabilitiesImmutable caps = available[i]; - if (caps != null && caps.getSampleBuffers()) { + for (int i = 0; i < available.size(); i++) { + GLCapabilitiesImmutable caps = (GLCapabilitiesImmutable) available.get(i); + if ( caps.getSampleBuffers() ) { anyHaveSampleBuffers = true; break; } @@ -57,7 +58,8 @@ class MultisampleChooser01 extends DefaultGLCapabilitiesChooser { if (!anyHaveSampleBuffers) { System.err.println("WARNING: antialiasing will be disabled because none of the available pixel formats had it to offer"); } else { - if (!available[selection].getSampleBuffers()) { + GLCapabilitiesImmutable selected = (GLCapabilitiesImmutable) available.get(selection); + if (!selected.getSampleBuffers()) { System.err.println("WARNING: antialiasing will be disabled because the DefaultGLCapabilitiesChooser didn't supply it"); } } diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/gears/TestGearsGLJPanelAWTBug450.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/gears/TestGearsGLJPanelAWTBug450.java new file mode 100644 index 000000000..cd2682541 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/gears/TestGearsGLJPanelAWTBug450.java @@ -0,0 +1,163 @@ +/** + * 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.demos.gl2.gears; + +import javax.media.opengl.*; + +import com.jogamp.opengl.util.FPSAnimator; + +import javax.media.opengl.awt.GLJPanel; +import javax.media.opengl.glu.gl2.GLUgl2; + +import com.jogamp.opengl.test.junit.util.UITestCase; +import java.awt.AWTException; +import java.awt.BorderLayout; +import java.lang.reflect.InvocationTargetException; +import java.nio.ByteBuffer; + +import javax.swing.JFrame; +import javax.swing.SwingUtilities; + +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.AfterClass; +import org.junit.Test; + +/** + * Test for bug 450, which causes the right part of the frame to be black + * for all x >= height. + * + * Draws the Gears demo in a window that's twice as wide than it is tall, + * and checks to see if a particular pixel in the right half of the frame + * is colored. + * + * @author Wade Walker (adapted from TestGearsGLJPanelAWT) + */ +public class TestGearsGLJPanelAWTBug450 extends UITestCase { + static GLProfile glp; + static int width, height; + /** Set this if test fails. Needed because we can't throw an exception + * all the way up the stack from where we test the pixel. */ + static boolean failed; + + @BeforeClass + public static void initClass() { + GLProfile.initSingleton(false); + glp = GLProfile.getDefault(); + Assert.assertNotNull(glp); + width = 512; + height = 256; + } + + @AfterClass + public static void releaseClass() { + } + + protected void runTestGL(GLCapabilities caps) + throws AWTException, InterruptedException, InvocationTargetException + { + JFrame frame = new JFrame("Swing GLJPanel"); + Assert.assertNotNull(frame); + + GLJPanel glJPanel = new GLJPanel(caps); + Assert.assertNotNull(glJPanel); + glJPanel.addGLEventListener(new Gears() { + @Override + public void display(GLAutoDrawable drawable) { + super.display(drawable); + // look at one pixel at the bottom of the frame, just right of + // the center line, and make sure it's not black + GL2 gl = GLUgl2.getCurrentGL2(); + ByteBuffer bytebuffer = ByteBuffer.allocateDirect( 3 ); + gl.glReadPixels( 260, 10, 1, 1, GL2.GL_BGR, GL2.GL_UNSIGNED_BYTE, bytebuffer ); + byte byte0 = bytebuffer.get( 0 ); + byte byte1 = bytebuffer.get( 1 ); + byte byte2 = bytebuffer.get( 2 ); + if( (byte0 == 0) && (byte1 == 0) && (byte2 == 0) ) + failed = true; + } + }); + + FPSAnimator animator = new FPSAnimator(glJPanel, 60); + + final JFrame _frame = frame; + final GLJPanel _glJPanel = glJPanel; + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + _frame.getContentPane().add(_glJPanel, BorderLayout.CENTER); + _frame.setSize(width, height); + _frame.setVisible(true); + } } ) ; + + animator.start(); + Assert.assertEquals(true, animator.isAnimating()); + + while(animator.isAnimating() && animator.getDuration()<duration) { + Thread.sleep(100); + } + + Assert.assertNotNull(frame); + Assert.assertNotNull(glJPanel); + Assert.assertNotNull(animator); + + animator.stop(); + Assert.assertEquals(false, animator.isAnimating()); + SwingUtilities.invokeAndWait(new Runnable() { + public void run() { + _frame.setVisible(false); + _frame.getContentPane().remove(_glJPanel); + _frame.remove(_glJPanel); + _glJPanel.destroy(); + _frame.dispose(); + } } ); + + Assert.assertFalse( failed ); + } + + @Test + public void test01() + throws AWTException, InterruptedException, InvocationTargetException + { + GLCapabilities caps = new GLCapabilities(GLProfile.getDefault()); + runTestGL(caps); + } + + static long duration = 500; // ms + + public static void main(String args[]) { + for(int i=0; i<args.length; i++) { + if(args[i].equals("-time")) { + i++; + try { + duration = Integer.parseInt(args[i]); + } catch (Exception ex) { ex.printStackTrace(); } + } + } + org.junit.runner.JUnitCore.main(TestGearsGLJPanelAWTBug450.class.getName()); + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestShaderCompilationBug459AWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestShaderCompilationBug459AWT.java new file mode 100644 index 000000000..e740577d3 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/glsl/TestShaderCompilationBug459AWT.java @@ -0,0 +1,162 @@ +/** + * 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.glsl; + +import com.jogamp.opengl.test.junit.util.UITestCase; +import com.jogamp.opengl.util.Animator; + +import javax.media.opengl.GL2GL3; +import javax.media.opengl.GLAutoDrawable; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.GLEventListener; +import javax.media.opengl.GLException; +import javax.media.opengl.GLProfile; +import javax.media.opengl.awt.GLCanvas; +import java.awt.Frame; + +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.AfterClass; +import org.junit.Test; + +/** + * Duplicates bug 459, where a vertex shader won't compile when 8 bits of stencil are requested. + * This bug is Windows-only; it works on Mac OS X and CentOS. + */ +public class TestShaderCompilationBug459AWT extends UITestCase { + static GLProfile glp; + static int width, height; + static long duration = 500; // ms + /** Exception in shader code sets this, since it won't bubble up through AWT. */ + GLException glexception; + + @BeforeClass + public static void initClass() { + GLProfile.initSingleton(true); + glp = GLProfile.getDefault(); + Assert.assertNotNull(glp); + width = 512; + height = 512; + } + + @AfterClass + public static void releaseClass() { + } + + @Test + public void compileShader() throws InterruptedException { + GLProfile glp = GLProfile.get("GL2GL3"); + GLCapabilities caps = new GLCapabilities(glp); + // commenting out this line makes it work + caps.setStencilBits(8); + + // commenting in this line also makes it work + //caps.setSampleBuffers(true); + + Frame frame = new Frame("Bug 459 shader compilation test"); + Assert.assertNotNull(frame); + + GLCanvas glCanvas = new GLCanvas(caps); + Assert.assertNotNull(glCanvas); + frame.add(glCanvas); + frame.setSize(512, 512); + + glCanvas.addGLEventListener(new GLEventListener() { + @Override + public void init(GLAutoDrawable drawable) { + String code = "void main(void){gl_Position = vec4(0,0,0,1);}"; + + GL2GL3 gl = drawable.getGL().getGL2GL3(); + int id = gl.glCreateShader(GL2GL3.GL_VERTEX_SHADER); + + try { + gl.glShaderSource(id, 1, new String[] { code }, (int[])null, 0); + gl.glCompileShader(id); + + int[] compiled = new int[1]; + gl.glGetShaderiv(id, GL2GL3.GL_COMPILE_STATUS, compiled, 0); + if (compiled[0] == GL2GL3.GL_FALSE) { + int[] logLength = new int[1]; + gl.glGetShaderiv(id, GL2GL3.GL_INFO_LOG_LENGTH, logLength, 0); + + byte[] log = new byte[logLength[0]]; + gl.glGetShaderInfoLog(id, logLength[0], (int[])null, 0, log, 0); + + System.err.println("Error compiling the shader: " + new String(log)); + + gl.glDeleteShader(id); + } + else { + System.out.println("Shader compiled: id=" + id); + } + } + catch( GLException e ) { + glexception = e; + } + } + + @Override + public void dispose(GLAutoDrawable drawable) { + } + + @Override + public void display(GLAutoDrawable drawable) { + } + + @Override + public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { + } + }); + + Animator animator = new Animator(glCanvas); + frame.setVisible(true); + animator.start(); + + while(animator.isAnimating() && animator.getDuration()<duration) { + Thread.sleep(100); + } + + Assert.assertTrue( glexception != null ? glexception.getMessage() : "", glexception == null ); + Assert.assertNotNull(frame); + Assert.assertNotNull(glCanvas); + Assert.assertNotNull(animator); + + animator.stop(); + Assert.assertEquals(false, animator.isAnimating()); + frame.setVisible(false); + Assert.assertEquals(false, frame.isVisible()); + frame.remove(glCanvas); + frame.dispose(); + frame=null; + glCanvas=null; + } + + public static void main(String args[]) { + org.junit.runner.JUnitCore.main(TestShaderCompilationBug459AWT.class.getName()); + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/glu/TestGluUnprojectDoubleNOUI.java b/src/test/com/jogamp/opengl/test/junit/jogl/glu/TestGluUnprojectDoubleNOUI.java new file mode 100755 index 000000000..34b30f04e --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/glu/TestGluUnprojectDoubleNOUI.java @@ -0,0 +1,57 @@ +/** + * 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.glu; + +import javax.media.opengl.glu.GLU; + +import org.junit.Assert; +import org.junit.Test; + +/** + * @author Julien Gouesse + */ +public class TestGluUnprojectDoubleNOUI { + + @Test + public void test(){ + final GLU glu = new GLU(); + final int[] pickedPoint = new int[]{400,300}; + final double pickedPointDepth = 0; + final double[] sceneModelViewValues = new double[]{1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}; + final double[] projectionValues = new double[]{1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}; + final int[] viewport = new int[]{0,0,800,600}; + final double[] objCoords = new double[]{Double.NaN,Double.NaN,Double.NaN}; + glu.gluUnProject(pickedPoint[0], pickedPoint[1], pickedPointDepth, sceneModelViewValues, 0, projectionValues, 0, viewport, 0, objCoords, 0); + Assert.assertTrue(!Double.isNaN(objCoords[0])&&!Double.isNaN(objCoords[1])&&!Double.isNaN(objCoords[2])); + } + + public static void main(String args[]) { + org.junit.runner.JUnitCore.main(TestGluUnprojectDoubleNOUI.class.getName()); + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/glu/TestGluUnprojectFloatNOUI.java b/src/test/com/jogamp/opengl/test/junit/jogl/glu/TestGluUnprojectFloatNOUI.java new file mode 100755 index 000000000..9e48a2000 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/glu/TestGluUnprojectFloatNOUI.java @@ -0,0 +1,58 @@ +/** + * 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.glu; + +import javax.media.opengl.glu.GLU; + +import org.junit.Assert; +import org.junit.Test; + +/** + * @author Julien Gouesse + */ +public class TestGluUnprojectFloatNOUI { + + + @Test + public void test(){ + final GLU glu = new GLU(); + final int[] pickedPoint = new int[]{400,300}; + final float pickedPointDepth = 0; + final float[] sceneModelViewValues = new float[]{1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}; + final float[] projectionValues = new float[]{1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}; + final int[] viewport = new int[]{0,0,800,600}; + final float[] objCoords = new float[]{Float.NaN,Float.NaN,Float.NaN}; + glu.gluUnProject(pickedPoint[0], pickedPoint[1], pickedPointDepth, sceneModelViewValues, 0, projectionValues, 0, viewport, 0, objCoords, 0); + Assert.assertTrue(!Double.isNaN(objCoords[0])&&!Double.isNaN(objCoords[1])&&!Double.isNaN(objCoords[2])); + } + + public static void main(String args[]) { + org.junit.runner.JUnitCore.main(TestGluUnprojectFloatNOUI.class.getName()); + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/swt/OneTriangle.java b/src/test/com/jogamp/opengl/test/junit/jogl/swt/OneTriangle.java new file mode 100644 index 000000000..655e590a3 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/swt/OneTriangle.java @@ -0,0 +1,71 @@ +/**
+ * 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.swt;
+
+import javax.media.opengl.GL;
+import javax.media.opengl.GL2;
+import javax.media.opengl.glu.GLU;
+
+import org.eclipse.swt.graphics.Rectangle;
+
+/**
+ * A utility class to encapsulate drawing a single triangle for unit tests.
+ * @author Wade Walker
+ */
+public class OneTriangle {
+
+ public static void setup( GL2 gl, Rectangle rectangle ) {
+ gl.glMatrixMode( GL2.GL_PROJECTION );
+ gl.glLoadIdentity();
+
+ // coordinate system origin at lower left with width and height same as the window
+ GLU glu = new GLU();
+ glu.gluOrtho2D( 0.0f, rectangle.width, 0.0f, rectangle.height );
+
+ gl.glMatrixMode( GL2.GL_MODELVIEW );
+ gl.glLoadIdentity();
+
+ gl.glViewport( 0, 0, rectangle.width, rectangle.height );
+ }
+
+ public static void render( GL2 gl, Rectangle rectangle ) {
+ gl.glClear( GL.GL_COLOR_BUFFER_BIT );
+
+ // draw a triangle filling the window
+ gl.glLoadIdentity();
+ gl.glBegin( GL.GL_TRIANGLES );
+ gl.glColor3f( 1, 0, 0 );
+ gl.glVertex2f( 0, 0 );
+ gl.glColor3f( 0, 1, 0 );
+ gl.glVertex2f( rectangle.width, 0 );
+ gl.glColor3f( 0, 0, 1 );
+ gl.glVertex2f( rectangle.width / 2, rectangle.height );
+ gl.glEnd();
+ }
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWT01GLn.java b/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWT01GLn.java new file mode 100644 index 000000000..94231a88d --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWT01GLn.java @@ -0,0 +1,184 @@ +/**
+ * 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.swt;
+
+import javax.media.opengl.GL2;
+import javax.media.opengl.GLContext;
+import javax.media.opengl.GLDrawableFactory;
+import javax.media.opengl.GLProfile;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.PaintEvent;
+import org.eclipse.swt.events.PaintListener;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.opengl.GLCanvas;
+import org.eclipse.swt.opengl.GLData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Shell;
+
+import org.junit.Assert;
+import org.junit.Assume;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.After;
+import org.junit.Test;
+
+import com.jogamp.opengl.test.junit.util.UITestCase;
+
+/**
+ * Tests that a basic SWT app can open without crashing under different GL profiles. Uses the SWT GL canvas.
+ * @author Wade Walker
+ */
+public class TestSWT01GLn extends UITestCase {
+
+ static final int duration = 250;
+
+ Display display = null;
+ Shell shell = null;
+ Composite composite = null;
+ GLCanvas glcanvas = null;
+
+ @BeforeClass
+ public static void startup() {
+ GLProfile.initSingleton( true );
+ System.out.println( "GLProfile " + GLProfile.glAvailabilityToString() );
+ }
+
+ @Before
+ public void init() {
+ display = new Display();
+ Assert.assertNotNull( display );
+ shell = new Shell( display );
+ Assert.assertNotNull( shell );
+ shell.setLayout( new FillLayout() );
+ composite = new Composite( shell, SWT.NONE );
+ composite.setLayout( new FillLayout() );
+ Assert.assertNotNull( composite );
+ }
+
+ @After
+ public void release() {
+ Assert.assertNotNull( display );
+ Assert.assertNotNull( shell );
+ Assert.assertNotNull( composite );
+ Assert.assertNotNull( glcanvas );
+ try {
+ glcanvas.dispose();
+ composite.dispose();
+ shell.dispose();
+ display.dispose();
+ }
+ catch( Throwable throwable ) {
+ throwable.printStackTrace();
+ Assume.assumeNoException( throwable );
+ }
+ display = null;
+ shell = null;
+ composite = null;
+ glcanvas = null;
+ }
+
+ protected void runTestGL( GLProfile glprofile ) throws InterruptedException {
+ GLData gldata = new GLData();
+ gldata.doubleBuffer = true;
+ // need SWT.NO_BACKGROUND to prevent SWT from clearing the window
+ // at the wrong times (we use glClear for this instead)
+ glcanvas = new GLCanvas( composite, SWT.NO_BACKGROUND, gldata );
+ Assert.assertNotNull( glcanvas );
+ glcanvas.setCurrent();
+ final GLContext glcontext = GLDrawableFactory.getFactory( glprofile ).createExternalGLContext();
+ Assert.assertNotNull( glcontext );
+
+ // fix the viewport when the user resizes the window
+ glcanvas.addListener( SWT.Resize, new Listener() {
+ public void handleEvent( Event event ) {
+ Rectangle rectangle = glcanvas.getClientArea();
+ glcanvas.setCurrent();
+ glcontext.makeCurrent();
+ GL2 gl = glcontext.getGL().getGL2();
+ OneTriangle.setup( gl, rectangle );
+ glcontext.release();
+ }
+ });
+
+ // draw the triangle when the OS tells us that any part of the window needs drawing
+ glcanvas.addPaintListener( new PaintListener() {
+ public void paintControl( PaintEvent paintevent ) {
+ Rectangle rectangle = glcanvas.getClientArea();
+ glcanvas.setCurrent();
+ glcontext.makeCurrent();
+ GL2 gl = glcontext.getGL().getGL2();
+ OneTriangle.render( gl, rectangle );
+ glcanvas.swapBuffers();
+ glcontext.release();
+ }
+ });
+
+ shell.setText( getClass().getName() );
+ shell.setSize( 640, 480 );
+ shell.open();
+
+ long lStartTime = System.currentTimeMillis();
+ long lEndTime = lStartTime + duration;
+ try {
+ while( (System.currentTimeMillis() < lEndTime) && !glcanvas.isDisposed() ) {
+ if( !display.readAndDispatch() ) {
+ // blocks on linux .. display.sleep();
+ Thread.sleep(10);
+ }
+ }
+ }
+ catch( Throwable throwable ) {
+ throwable.printStackTrace();
+ Assume.assumeNoException( throwable );
+ }
+ }
+
+ @Test
+ public void test01GLDefault() throws InterruptedException {
+ GLProfile glprofile = GLProfile.getDefault();
+ System.out.println( "GLProfile Default: " + glprofile );
+ runTestGL( glprofile );
+ }
+
+ @Test
+ public void test02GL2() throws InterruptedException {
+ GLProfile glprofile = GLProfile.get(GLProfile.GL2);
+ System.out.println( "GLProfile GL2: " + glprofile );
+ runTestGL( glprofile );
+ }
+
+ public static void main(String args[]) {
+ org.junit.runner.JUnitCore.main(TestSWT01GLn.class.getName());
+ }
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWTAWT01GLn.java b/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWTAWT01GLn.java new file mode 100644 index 000000000..2ab3c96ad --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWTAWT01GLn.java @@ -0,0 +1,184 @@ +/**
+ * 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.swt;
+
+import java.awt.Frame;
+
+import javax.media.opengl.GL2;
+import javax.media.opengl.GLAutoDrawable;
+import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.GLEventListener;
+import javax.media.opengl.GLProfile;
+import javax.media.opengl.awt.GLCanvas;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.awt.SWT_AWT;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+
+import org.junit.Assert;
+import org.junit.Assume;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.After;
+import org.junit.Test;
+
+import com.jogamp.opengl.test.junit.util.UITestCase;
+
+/**
+ * Tests that a basic SWT app can open without crashing under different GL profiles. Uses the AWT GL canvas with
+ * the SWT_AWT bridge.
+ * @author Wade Walker
+ */
+public class TestSWTAWT01GLn extends UITestCase {
+
+ static final int duration = 250;
+
+ Display display = null;
+ Shell shell = null;
+ Composite composite = null;
+ Frame frame = null;
+ GLCanvas glcanvas = null;
+
+ @BeforeClass
+ public static void startup() {
+ GLProfile.initSingleton( true );
+ System.out.println( "GLProfile " + GLProfile.glAvailabilityToString() );
+ }
+
+ @Before
+ public void init() {
+ display = new Display();
+ Assert.assertNotNull( display );
+ shell = new Shell( display );
+ Assert.assertNotNull( shell );
+ shell.setLayout( new FillLayout() );
+ composite = new Composite( shell, SWT.EMBEDDED | SWT.NO_BACKGROUND );
+ composite.setLayout( new FillLayout() );
+ Assert.assertNotNull( composite );
+ frame = SWT_AWT.new_Frame( composite );
+ Assert.assertNotNull( frame );
+ }
+
+ @After
+ public void release() {
+ Assert.assertNotNull( display );
+ Assert.assertNotNull( shell );
+ Assert.assertNotNull( composite );
+ Assert.assertNotNull( glcanvas );
+ try {
+ frame.setVisible( false );
+ frame.remove( glcanvas );
+ frame.dispose();
+ composite.dispose();
+ shell.dispose();
+ display.dispose();
+ }
+ catch( Throwable throwable ) {
+ throwable.printStackTrace();
+ Assume.assumeNoException( throwable );
+ }
+ display = null;
+ shell = null;
+ composite = null;
+ frame = null;
+ glcanvas = null;
+ }
+
+ protected void runTestGL( GLProfile glprofile ) throws InterruptedException {
+ GLCapabilities glcapabilities = new GLCapabilities( glprofile );
+ glcanvas = new GLCanvas( glcapabilities );
+ Assert.assertNotNull( glcanvas );
+ frame.add( glcanvas );
+
+ glcanvas.addGLEventListener( new GLEventListener() {
+ @Override
+ public void init( GLAutoDrawable glautodrawable ) {
+ }
+
+ @Override
+ public void dispose( GLAutoDrawable glautodrawable ) {
+ }
+
+ @Override
+ public void display( GLAutoDrawable glautodrawable ) {
+ Rectangle rectangle = new Rectangle( 0, 0, glautodrawable.getWidth(), glautodrawable.getHeight() );
+ GL2 gl = glautodrawable.getGL().getGL2();
+ OneTriangle.render( gl, rectangle );
+ }
+
+ @Override
+ public void reshape( GLAutoDrawable glautodrawable, int x, int y, int width, int height ) {
+ Rectangle rectangle = new Rectangle( 0, 0, glautodrawable.getWidth(), glautodrawable.getHeight() );
+ GL2 gl = glautodrawable.getGL().getGL2();
+ OneTriangle.setup( gl, rectangle );
+ }
+ });
+
+ shell.setText( getClass().getName() );
+ shell.setSize( 640, 480 );
+ shell.open();
+
+ long lStartTime = System.currentTimeMillis();
+ long lEndTime = lStartTime + duration;
+ try {
+ while( (System.currentTimeMillis() < lEndTime) && !composite.isDisposed() ) {
+ if( !display.readAndDispatch() ) {
+ // blocks on linux .. display.sleep();
+ Thread.sleep(10);
+ }
+ }
+ }
+ catch( Throwable throwable ) {
+ throwable.printStackTrace();
+ Assume.assumeNoException( throwable );
+ }
+ }
+
+ @Test
+ public void test01GLDefault() throws InterruptedException {
+ GLProfile glprofile = GLProfile.getDefault();
+ System.out.println( "GLProfile Default: " + glprofile );
+ runTestGL( glprofile );
+ }
+
+ @Test
+ public void test02GL2() throws InterruptedException {
+ GLProfile glprofile = GLProfile.get(GLProfile.GL2);
+ System.out.println( "GLProfile GL2: " + glprofile );
+ runTestGL( glprofile );
+ }
+
+ public static void main(String args[]) {
+ org.junit.runner.JUnitCore.main( TestSWTAWT01GLn.class.getName() );
+ }
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/texture/TestGrayTextureFromFileAWTBug417.java b/src/test/com/jogamp/opengl/test/junit/jogl/texture/TestGrayTextureFromFileAWTBug417.java new file mode 100644 index 000000000..82cd91718 --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/texture/TestGrayTextureFromFileAWTBug417.java @@ -0,0 +1,143 @@ +/** + * 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.texture; + +import com.jogamp.opengl.test.junit.jogl.util.texture.gl2.TextureGL2ListenerDraw1; + +import com.jogamp.opengl.test.junit.util.UITestCase; + +import javax.media.opengl.GLAutoDrawable; +import javax.media.opengl.GLException; +import javax.media.opengl.GLProfile; +import javax.media.opengl.GLCapabilities; +import javax.media.opengl.awt.GLCanvas; +import com.jogamp.opengl.util.texture.TextureIO; +import com.jogamp.opengl.util.Animator; + +import java.awt.Frame; + +import java.io.IOException; +import java.io.InputStream; + +import org.junit.Assert; +import org.junit.After; +import org.junit.Assume; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * Unit test for bug 417, which shows a GLException when reading a grayscale texture. + * Couldn't duplicate the failure, so it must have been fixed unknowingly sometime + * after the bug was submitted. + * @author Wade Walker + */ +public class TestGrayTextureFromFileAWTBug417 extends UITestCase { + static GLProfile glp; + static GLCapabilities caps; + InputStream textureStream; + + @BeforeClass + public static void initClass() { + GLProfile.initSingleton(true); + glp = GLProfile.get(GLProfile.GL2GL3); + Assert.assertNotNull(glp); + caps = new GLCapabilities(glp); + Assert.assertNotNull(caps); + } + + @Before + public void initTest() { + textureStream = TestGrayTextureFromFileAWTBug417.class.getResourceAsStream( "grayscale_texture.png" ); + Assert.assertNotNull(textureStream); + } + + @After + public void cleanupTest() { + textureStream=null; + } + + @Test + public void test1() throws InterruptedException { + GLCanvas glCanvas = new GLCanvas(caps); + + Frame frame = new Frame("Texture Test"); + Assert.assertNotNull(frame); + frame.add(glCanvas); + frame.setSize( 256, 128 ); + + // load texture from file inside current GL context to match the way + // the bug submitter was doing it + glCanvas.addGLEventListener(new TextureGL2ListenerDraw1( null ) { + @Override + public void init(GLAutoDrawable drawable) { + try { + setTexture( TextureIO.newTexture( textureStream, true, TextureIO.PNG ) ); + } + catch(GLException glexception) { + glexception.printStackTrace(); + Assume.assumeNoException(glexception); + } + catch(IOException ioexception) { + ioexception.printStackTrace(); + Assume.assumeNoException(ioexception); + } + } + }); + + Animator animator = new Animator(glCanvas); + frame.setVisible(true); + animator.start(); + + Thread.sleep(500); // 500 ms + + animator.stop(); + frame.setVisible(false); + frame.remove(glCanvas); + glCanvas=null; + Assert.assertNotNull(frame); + frame.dispose(); + frame=null; + } + + public static void main(String args[]) throws IOException { + String tstname = TestGrayTextureFromFileAWTBug417.class.getName(); + org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] { + tstname, + "filtertrace=true", + "haltOnError=false", + "haltOnFailure=false", + "showoutput=true", + "outputtoformatters=true", + "logfailedtests=true", + "logtestlistenerevents=true", + "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter", + "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } ); + } +} diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/texture/grayscale_texture.png b/src/test/com/jogamp/opengl/test/junit/jogl/texture/grayscale_texture.png Binary files differnew file mode 100755 index 000000000..dac0f13de --- /dev/null +++ b/src/test/com/jogamp/opengl/test/junit/jogl/texture/grayscale_texture.png diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/gl2/TextureGL2ListenerDraw1.java b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/gl2/TextureGL2ListenerDraw1.java index b41dde645..649a3b19a 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/gl2/TextureGL2ListenerDraw1.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/util/texture/gl2/TextureGL2ListenerDraw1.java @@ -32,7 +32,6 @@ import com.jogamp.opengl.util.texture.Texture; import com.jogamp.opengl.util.texture.TextureCoords; import com.jogamp.opengl.util.texture.TextureData; import com.jogamp.opengl.util.texture.TextureIO; -import javax.media.opengl.GL; import javax.media.opengl.GL2ES1; import javax.media.opengl.GL2; import javax.media.opengl.GLAutoDrawable; @@ -54,6 +53,10 @@ public class TextureGL2ListenerDraw1 implements GLEventListener { } } + public void setTexture( Texture texture ) { + this.texture = texture; + } + public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { GL2 gl = drawable.getGL().getGL2(); gl.glMatrixMode(GL2ES1.GL_PROJECTION); |