aboutsummaryrefslogtreecommitdiffstats
path: root/src/junit/com/jogamp/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/junit/com/jogamp/test')
-rw-r--r--src/junit/com/jogamp/test/junit/jogl/acore/TestSharedContextListNEWT.java133
-rw-r--r--src/junit/com/jogamp/test/junit/jogl/demos/gl2/gears/Gears.java68
2 files changed, 185 insertions, 16 deletions
diff --git a/src/junit/com/jogamp/test/junit/jogl/acore/TestSharedContextListNEWT.java b/src/junit/com/jogamp/test/junit/jogl/acore/TestSharedContextListNEWT.java
new file mode 100644
index 000000000..cccd91b4c
--- /dev/null
+++ b/src/junit/com/jogamp/test/junit/jogl/acore/TestSharedContextListNEWT.java
@@ -0,0 +1,133 @@
+/**
+ * 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.test.junit.jogl.acore;
+
+import com.jogamp.newt.opengl.GLWindow;
+import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.GLDrawableFactory;
+import javax.media.opengl.GLPbuffer;
+import javax.media.opengl.GLProfile;
+import com.jogamp.opengl.util.Animator;
+
+import com.jogamp.test.junit.util.UITestCase;
+import com.jogamp.test.junit.jogl.demos.gl2.gears.Gears;
+
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class TestSharedContextListNEWT extends UITestCase {
+ static GLProfile glp;
+ static GLCapabilities caps;
+ static int width, height;
+ GLPbuffer sharedDrawable;
+ Gears sharedGears;
+
+ @BeforeClass
+ public static void initClass() {
+ GLProfile.initSingleton(true);
+ glp = GLProfile.getDefault();
+ Assert.assertNotNull(glp);
+ caps = new GLCapabilities(glp);
+ Assert.assertNotNull(caps);
+ width = 512;
+ height = 512;
+ }
+
+ private void initShared() {
+ sharedDrawable = GLDrawableFactory.getFactory(glp).createGLPbuffer(null, caps, null, width, height, null);
+ Assert.assertNotNull(sharedDrawable);
+ sharedGears = new Gears();
+ Assert.assertNotNull(sharedGears);
+ sharedDrawable.addGLEventListener(sharedGears);
+ // init and render one frame, which will setup the Gears display lists
+ sharedDrawable.display();
+ }
+
+ private void releaseShared() {
+ Assert.assertNotNull(sharedDrawable);
+ sharedDrawable.destroy();
+ }
+
+ protected GLWindow runTestGL(Animator animator, int x, int y, boolean useShared) {
+ GLWindow glWindow = GLWindow.create(caps);
+ Assert.assertNotNull(glWindow);
+ glWindow.setTitle("Shared Gears NEWT Test: "+x+"/"+y+" shared "+useShared);
+ if(useShared) {
+ glWindow.setSharedContext(sharedDrawable.getContext());
+ }
+
+ glWindow.setSize(width, height);
+ glWindow.setPosition(x, y);
+
+ Gears gears = new Gears();
+ if(useShared) {
+ gears.setGears(sharedGears.getGear1(), sharedGears.getGear2(), sharedGears.getGear3());
+ }
+ glWindow.addGLEventListener(gears);
+
+ animator.add(glWindow);
+
+ glWindow.setVisible(true);
+
+ return glWindow;
+ }
+
+ @Test
+ public void test01() throws InterruptedException {
+ initShared();
+ Animator animator = new Animator();
+ GLWindow f1 = runTestGL(animator, 0, 0, true);
+ GLWindow f2 = runTestGL(animator, width, 0, true);
+ GLWindow f3 = runTestGL(animator, 0, height, false);
+ animator.start();
+ while(animator.isAnimating() && animator.getDuration()<duration) {
+ Thread.sleep(100);
+ }
+ animator.stop();
+ f1.destroy();
+ f2.destroy();
+ f3.destroy();
+ releaseShared();
+ }
+
+ 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(TestSharedContextListNEWT.class.getName());
+ }
+}
diff --git a/src/junit/com/jogamp/test/junit/jogl/demos/gl2/gears/Gears.java b/src/junit/com/jogamp/test/junit/jogl/demos/gl2/gears/Gears.java
index d9194c216..78846250f 100644
--- a/src/junit/com/jogamp/test/junit/jogl/demos/gl2/gears/Gears.java
+++ b/src/junit/com/jogamp/test/junit/jogl/demos/gl2/gears/Gears.java
@@ -16,7 +16,7 @@ import com.jogamp.newt.Window;
public class Gears implements GLEventListener {
private float view_rotx = 20.0f, view_roty = 30.0f, view_rotz = 0.0f;
- private int gear1, gear2, gear3;
+ private int gear1=0, gear2=0, gear3=0;
private float angle = 0.0f;
private int swapInterval;
@@ -31,6 +31,27 @@ public class Gears implements GLEventListener {
this.swapInterval = 1;
}
+ public void setGears(int g1, int g2, int g3) {
+ gear1 = g1;
+ gear2 = g2;
+ gear3 = g3;
+ }
+
+ /**
+ * @return display list gear1
+ */
+ public int getGear1() { return gear1; }
+
+ /**
+ * @return display list gear2
+ */
+ public int getGear2() { return gear2; }
+
+ /**
+ * @return display list gear3
+ */
+ public int getGear3() { return gear3; }
+
public void init(GLAutoDrawable drawable) {
System.err.println("Gears: Init");
// Use debug pipeline
@@ -50,23 +71,38 @@ public class Gears implements GLEventListener {
gl.glEnable(GL2.GL_DEPTH_TEST);
/* make the gears */
- gear1 = gl.glGenLists(1);
- gl.glNewList(gear1, GL2.GL_COMPILE);
- gl.glMaterialfv(GL2.GL_FRONT, GL2.GL_AMBIENT_AND_DIFFUSE, red, 0);
- gear(gl, 1.0f, 4.0f, 1.0f, 20, 0.7f);
- gl.glEndList();
+ if(0>=gear1) {
+ gear1 = gl.glGenLists(1);
+ gl.glNewList(gear1, GL2.GL_COMPILE);
+ gl.glMaterialfv(GL2.GL_FRONT, GL2.GL_AMBIENT_AND_DIFFUSE, red, 0);
+ gear(gl, 1.0f, 4.0f, 1.0f, 20, 0.7f);
+ gl.glEndList();
+ System.err.println("gear1 list created: "+gear1);
+ } else {
+ System.err.println("gear1 list reused: "+gear1);
+ }
- gear2 = gl.glGenLists(1);
- gl.glNewList(gear2, GL2.GL_COMPILE);
- gl.glMaterialfv(GL2.GL_FRONT, GL2.GL_AMBIENT_AND_DIFFUSE, green, 0);
- gear(gl, 0.5f, 2.0f, 2.0f, 10, 0.7f);
- gl.glEndList();
+ if(0>=gear2) {
+ gear2 = gl.glGenLists(1);
+ gl.glNewList(gear2, GL2.GL_COMPILE);
+ gl.glMaterialfv(GL2.GL_FRONT, GL2.GL_AMBIENT_AND_DIFFUSE, green, 0);
+ gear(gl, 0.5f, 2.0f, 2.0f, 10, 0.7f);
+ gl.glEndList();
+ System.err.println("gear2 list created: "+gear2);
+ } else {
+ System.err.println("gear2 list reused: "+gear2);
+ }
- gear3 = gl.glGenLists(1);
- gl.glNewList(gear3, GL2.GL_COMPILE);
- gl.glMaterialfv(GL2.GL_FRONT, GL2.GL_AMBIENT_AND_DIFFUSE, blue, 0);
- gear(gl, 1.3f, 2.0f, 0.5f, 10, 0.7f);
- gl.glEndList();
+ if(0>=gear3) {
+ gear3 = gl.glGenLists(1);
+ gl.glNewList(gear3, GL2.GL_COMPILE);
+ gl.glMaterialfv(GL2.GL_FRONT, GL2.GL_AMBIENT_AND_DIFFUSE, blue, 0);
+ gear(gl, 1.3f, 2.0f, 0.5f, 10, 0.7f);
+ gl.glEndList();
+ System.err.println("gear3 list created: "+gear3);
+ } else {
+ System.err.println("gear3 list reused: "+gear3);
+ }
gl.glEnable(GL2.GL_NORMALIZE);