aboutsummaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2013-05-08 05:49:41 +0200
committerSven Gothel <[email protected]>2013-05-08 05:49:41 +0200
commit66e3917da774b723007811e66d95f37b1ffffc97 (patch)
treea09a341280b3dc4309c3f926ad2dd9077c470053 /src/test
parentff08ebae2f6ed8788d481f4a21fc7a07a75733ee (diff)
Add TestGearsGLJPanelAWT, i.e. multiple JPanels w/ GLJPanel running GearsES2 in their own color.
Note: JComponent will introduce flickering if using opaque rendering mode!
Diffstat (limited to 'src/test')
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/GearsObject.java10
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/GearsES1.java21
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/GearsObjectES1.java8
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java33
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsObjectES2.java8
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2AWT.java4
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2GLJPanelAWT.java4
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2GLJPanelsAWT.java317
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NEWT.java1
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/awt/TestGearsGLJPanelAWT.java4
-rw-r--r--src/test/com/jogamp/opengl/test/junit/util/MiscUtils.java9
11 files changed, 388 insertions, 31 deletions
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/GearsObject.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/GearsObject.java
index 44a74a367..82dd7071f 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/GearsObject.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/GearsObject.java
@@ -36,7 +36,8 @@ public abstract class GearsObject {
public static final FloatBuffer green = Buffers.newDirectFloatBuffer( new float[] { 0.0f, 0.8f, 0.2f, 0.7f } );
public static final FloatBuffer blue = Buffers.newDirectFloatBuffer( new float[] { 0.2f, 0.2f, 1.0f, 0.7f } );
public static final float M_PI = (float)Math.PI;
-
+
+ public final FloatBuffer gearColor;
public GLArrayDataServer frontFace;
public GLArrayDataServer frontSide;
public GLArrayDataServer backFace;
@@ -47,7 +48,7 @@ public abstract class GearsObject {
public abstract GLArrayDataServer createInterleaved(int comps, int dataType, boolean normalized, int initialSize, int vboUsage);
public abstract void addInterleavedVertexAndNormalArrays(GLArrayDataServer array, int components);
- public abstract void draw(GL gl, float x, float y, float angle, FloatBuffer color);
+ public abstract void draw(GL gl, float x, float y, float angle);
public void destroy(GL gl) {
if(!isShared) {
@@ -88,9 +89,11 @@ public abstract class GearsObject {
backSide = shared.backSide;
outwardFace = shared.outwardFace;
insideRadiusCyl = shared.insideRadiusCyl;
+ gearColor = shared.gearColor;
}
public GearsObject (
+ FloatBuffer gearColor,
float inner_radius,
float outer_radius,
float width,
@@ -107,7 +110,8 @@ public abstract class GearsObject {
float normal[] = new float[3];
// final int tris_per_tooth = 32;
- isShared = false;
+ this.isShared = false;
+ this.gearColor = gearColor;
r0 = inner_radius;
r1 = outer_radius - tooth_depth / 2.0f;
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/GearsES1.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/GearsES1.java
index bf668879a..0cd45e53f 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/GearsES1.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/GearsES1.java
@@ -21,6 +21,8 @@
package com.jogamp.opengl.test.junit.jogl.demos.es1;
+import java.nio.FloatBuffer;
+
import javax.media.nativewindow.NativeWindow;
import javax.media.opengl.GL;
import javax.media.opengl.GL2ES1;
@@ -57,6 +59,7 @@ public class GearsES1 implements GLEventListener {
private float view_rotx = 20.0f, view_roty = 30.0f, view_rotz = 0.0f;
private GearsObject gear1=null, gear2=null, gear3=null;
+ private FloatBuffer gear1Color=GearsObject.red, gear2Color=GearsObject.green, gear3Color=GearsObject.blue;
private float angle = 0.0f;
private int swapInterval;
private MouseListener gearsMouse = new GearsMouseAdapter();
@@ -80,6 +83,12 @@ public class GearsES1 implements GLEventListener {
this.traceFFPEmu = traceFFPEmu;
}
+ public void setGearsColors(FloatBuffer gear1Color, FloatBuffer gear2Color, FloatBuffer gear3Color) {
+ this.gear1Color = gear1Color;
+ this.gear2Color = gear2Color;
+ this.gear3Color = gear3Color;
+ }
+
public void setGears(GearsObject g1, GearsObject g2, GearsObject g3) {
gear1 = g1;
gear2 = g2;
@@ -153,21 +162,21 @@ public class GearsES1 implements GLEventListener {
/* make the gears */
if(null == gear1) {
- gear1 = new GearsObjectES1(1.0f, 4.0f, 1.0f, 20, 0.7f);
+ gear1 = new GearsObjectES1(gear1Color, 1.0f, 4.0f, 1.0f, 20, 0.7f);
System.err.println("gear1 created: "+gear1);
} else {
System.err.println("gear1 reused: "+gear1);
}
if(null == gear2) {
- gear2 = new GearsObjectES1(0.5f, 2.0f, 2.0f, 10, 0.7f);
+ gear2 = new GearsObjectES1(gear2Color, 0.5f, 2.0f, 2.0f, 10, 0.7f);
System.err.println("gear2 created: "+gear2);
} else {
System.err.println("gear2 reused: "+gear2);
}
if(null == gear3) {
- gear3 = new GearsObjectES1(1.3f, 2.0f, 0.5f, 10, 0.7f);
+ gear3 = new GearsObjectES1(gear3Color, 1.3f, 2.0f, 0.5f, 10, 0.7f);
System.err.println("gear3 created: "+gear3);
} else {
System.err.println("gear3 reused: "+gear3);
@@ -268,9 +277,9 @@ public class GearsES1 implements GLEventListener {
gl.glRotatef(view_roty, 0.0f, 1.0f, 0.0f);
gl.glRotatef(view_rotz, 0.0f, 0.0f, 1.0f);
- gear1.draw(gl, -3.0f, -2.0f, angle, GearsObject.red);
- gear2.draw(gl, 3.1f, -2.0f, -2.0f * angle - 9.0f, GearsObject.green);
- gear3.draw(gl, -3.1f, 4.2f, -2.0f * angle - 25.0f, GearsObject.blue);
+ gear1.draw(gl, -3.0f, -2.0f, angle);
+ gear2.draw(gl, 3.1f, -2.0f, -2.0f * angle - 9.0f);
+ gear3.draw(gl, -3.1f, 4.2f, -2.0f * angle - 25.0f);
// Remember that every push needs a pop; this one is paired with
// rotating the entire gear assembly
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/GearsObjectES1.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/GearsObjectES1.java
index 8276c6bb9..89e469799 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/GearsObjectES1.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es1/GearsObjectES1.java
@@ -36,9 +36,9 @@ import com.jogamp.opengl.util.GLArrayDataServer;
*/
public class GearsObjectES1 extends GearsObject {
- public GearsObjectES1(float inner_radius, float outer_radius, float width,
+ public GearsObjectES1(FloatBuffer gearColor, float inner_radius, float outer_radius, float width,
int teeth, float tooth_depth) {
- super(inner_radius, outer_radius, width, teeth, tooth_depth);
+ super(gearColor, inner_radius, outer_radius, width, teeth, tooth_depth);
}
@Override
@@ -59,12 +59,12 @@ public class GearsObjectES1 extends GearsObject {
}
@Override
- public void draw(GL _gl, float x, float y, float angle, FloatBuffer color) {
+ public void draw(GL _gl, float x, float y, float angle) {
GL2ES1 gl = _gl.getGL2ES1();
gl.glPushMatrix();
gl.glTranslatef(x, y, 0f);
gl.glRotatef(angle, 0f, 0f, 1f);
- gl.glMaterialfv(GL2ES1.GL_FRONT_AND_BACK, GL2ES1.GL_AMBIENT_AND_DIFFUSE, color);
+ gl.glMaterialfv(GL2ES1.GL_FRONT_AND_BACK, GL2ES1.GL_AMBIENT_AND_DIFFUSE, gearColor);
gl.glShadeModel(GL2ES1.GL_FLAT);
draw(gl, frontFace, GL.GL_TRIANGLE_STRIP);
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 4cf6f3764..f21e767fa 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
@@ -58,6 +58,7 @@ public class GearsES2 implements GLEventListener {
private float panX = 0.0f, panY = 0.0f, panZ=0.0f;
private int drawableHeight = 1;
private GearsObjectES2 gear1=null, gear2=null, gear3=null;
+ private FloatBuffer gear1Color=GearsObject.red, gear2Color=GearsObject.green, gear3Color=GearsObject.blue;
private float angle = 0.0f;
private int swapInterval = 0;
private boolean pmvUseBackingArray = true; // the default for PMVMatrix now, since it's faster
@@ -67,6 +68,7 @@ public class GearsES2 implements GLEventListener {
private boolean doRotate = true;
private boolean ignoreFocus = false;
+ private float[] clearColor = null;
private boolean clearBuffers = true;
private boolean verbose = true;
@@ -87,6 +89,17 @@ public class GearsES2 implements GLEventListener {
this.pmvUseBackingArray = pmvUseBackingArray;
}
+ /** float[4] */
+ public void setClearColor(float[] clearColor) {
+ this.clearColor = clearColor;
+ }
+
+ public void setGearsColors(FloatBuffer gear1Color, FloatBuffer gear2Color, FloatBuffer gear3Color) {
+ this.gear1Color = gear1Color;
+ this.gear2Color = gear2Color;
+ this.gear3Color = gear3Color;
+ }
+
public void setGears(GearsObjectES2 g1, GearsObjectES2 g2, GearsObjectES2 g3) {
gear1 = g1;
gear2 = g2;
@@ -159,7 +172,7 @@ public class GearsES2 implements GLEventListener {
st.uniform(gl, colorU);
if(null == gear1) {
- gear1 = new GearsObjectES2(st, 1.0f, 4.0f, 1.0f, 20, 0.7f, pmvMatrix, pmvMatrixUniform, colorU);
+ gear1 = new GearsObjectES2(st, gear1Color, 1.0f, 4.0f, 1.0f, 20, 0.7f, pmvMatrix, pmvMatrixUniform, colorU);
if(verbose) {
System.err.println("gear1 created: "+gear1);
}
@@ -171,7 +184,7 @@ public class GearsES2 implements GLEventListener {
}
if(null == gear2) {
- gear2 = new GearsObjectES2(st, 0.5f, 2.0f, 2.0f, 10, 0.7f, pmvMatrix, pmvMatrixUniform, colorU);
+ gear2 = new GearsObjectES2(st, gear2Color, 0.5f, 2.0f, 2.0f, 10, 0.7f, pmvMatrix, pmvMatrixUniform, colorU);
if(verbose) {
System.err.println("gear2 created: "+gear2);
}
@@ -183,7 +196,7 @@ public class GearsES2 implements GLEventListener {
}
if(null == gear3) {
- gear3 = new GearsObjectES2(st, 1.3f, 2.0f, 0.5f, 10, 0.7f, pmvMatrix, pmvMatrixUniform, colorU);
+ gear3 = new GearsObjectES2(st, gear3Color, 1.3f, 2.0f, 0.5f, 10, 0.7f, pmvMatrix, pmvMatrixUniform, colorU);
if(verbose) {
System.err.println("gear3 created: "+gear3);
}
@@ -288,10 +301,10 @@ public class GearsES2 implements GLEventListener {
hasFocus = true;
}
- gl.glEnable(GL.GL_CULL_FACE);
-
if( clearBuffers ) {
- if( ignoreFocus || hasFocus ) {
+ if( null != clearColor ) {
+ gl.glClearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]);
+ } else if( ignoreFocus || hasFocus ) {
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
} else {
gl.glClearColor(0.2f, 0.2f, 0.2f, 0.0f);
@@ -308,6 +321,8 @@ public class GearsES2 implements GLEventListener {
}
}
+ gl.glEnable(GL.GL_CULL_FACE);
+
st.useProgram(gl, true);
pmvMatrix.glPushMatrix();
pmvMatrix.glTranslatef(panX, panY, panZ);
@@ -315,9 +330,9 @@ public class GearsES2 implements GLEventListener {
pmvMatrix.glRotatef(view_roty, 0.0f, 1.0f, 0.0f);
pmvMatrix.glRotatef(view_rotz, 0.0f, 0.0f, 1.0f);
- gear1.draw(gl, -3.0f, -2.0f, 1f * angle - 0f, GearsObject.red);
- gear2.draw(gl, 3.1f, -2.0f, -2f * angle - 9.0f, GearsObject.green);
- gear3.draw(gl, -3.1f, 4.2f, -2f * angle - 25.0f, GearsObject.blue);
+ gear1.draw(gl, -3.0f, -2.0f, 1f * angle - 0f);
+ gear2.draw(gl, 3.1f, -2.0f, -2f * angle - 9.0f);
+ gear3.draw(gl, -3.1f, 4.2f, -2f * angle - 25.0f);
pmvMatrix.glPopMatrix();
st.useProgram(gl, false);
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 eb9647949..c5f5f7a44 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
@@ -41,13 +41,13 @@ public class GearsObjectES2 extends GearsObject {
final GLUniformData colorUniform;
final ShaderState st;
- public GearsObjectES2(ShaderState st, float inner_radius, float outer_radius,
+ public GearsObjectES2(ShaderState st, FloatBuffer gearColor, 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);
+ super(gearColor, inner_radius, outer_radius, width, teeth, tooth_depth);
this.pmvMatrix = pmvMatrix;
this.pmvMatrixUniform = pmvMatrixUniform;
this.colorUniform = colorUniform;
@@ -95,7 +95,7 @@ public class GearsObjectES2 extends GearsObject {
}
@Override
- public void draw(GL _gl, float x, float y, float angle, FloatBuffer color) {
+ public void draw(GL _gl, float x, float y, float angle) {
final GL2ES2 gl = _gl.getGL2ES2();
pmvMatrix.glPushMatrix();
pmvMatrix.glTranslatef(x, y, 0f);
@@ -106,7 +106,7 @@ public class GearsObjectES2 extends GearsObject {
throw new InternalError("PMVMatrix.update() returns false after mutable operations");
}
- colorUniform.setData(color);
+ colorUniform.setData(gearColor);
st.uniform(gl, colorUniform);
draw(gl, frontFace, GL.GL_TRIANGLE_STRIP);
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2AWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2AWT.java
index 3d8fa69ea..a51df5088 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2AWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2AWT.java
@@ -198,7 +198,9 @@ public class TestGearsES2AWT extends UITestCase {
}
frame.setTitle("Gears AWT Test (translucent "+!caps.isBackgroundOpaque()+"), swapInterval "+swapInterval);
- glCanvas.addGLEventListener(new GearsES2(swapInterval));
+ final GearsES2 demo = new GearsES2(swapInterval);
+ glCanvas.addGLEventListener(demo);
+
final SnapshotGLEventListener snap = new SnapshotGLEventListener();
glCanvas.addGLEventListener(snap);
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2GLJPanelAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2GLJPanelAWT.java
index eddf5126b..bbb9fde1b 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2GLJPanelAWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2GLJPanelAWT.java
@@ -60,7 +60,7 @@ public class TestGearsES2GLJPanelAWT extends UITestCase {
static boolean shallUsePBuffer = false;
static boolean shallUseBitmap = false;
static boolean useMSAA = false;
- static int swapInterval = 1;
+ static int swapInterval = 0;
static boolean useAnimator = true;
static boolean manualTest = false;
@@ -92,7 +92,7 @@ public class TestGearsES2GLJPanelAWT extends UITestCase {
glJPanel.setMinimumSize(glc_sz);
glJPanel.setPreferredSize(glc_sz);
glJPanel.setSize(glc_sz);
- glJPanel.addGLEventListener(new GearsES2());
+ glJPanel.addGLEventListener(new GearsES2(swapInterval));
final SnapshotGLEventListener snap = new SnapshotGLEventListener();
glJPanel.addGLEventListener(snap);
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2GLJPanelsAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2GLJPanelsAWT.java
new file mode 100644
index 000000000..e4c0f47a4
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/awt/TestGearsES2GLJPanelsAWT.java
@@ -0,0 +1,317 @@
+/**
+ * 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.es2.awt;
+
+import java.awt.AWTException;
+import java.awt.BorderLayout;
+import java.awt.Dimension;
+import java.lang.reflect.InvocationTargetException;
+import java.nio.FloatBuffer;
+
+import javax.media.opengl.GLAnimatorControl;
+import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.GLCapabilitiesImmutable;
+import javax.media.opengl.GLProfile;
+import javax.media.opengl.awt.GLJPanel;
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+import javax.swing.SwingUtilities;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.jogamp.common.nio.Buffers;
+import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
+import com.jogamp.opengl.test.junit.util.MiscUtils;
+import com.jogamp.opengl.test.junit.util.QuitAdapter;
+import com.jogamp.opengl.test.junit.util.UITestCase;
+import com.jogamp.opengl.util.FPSAnimator;
+
+public class TestGearsES2GLJPanelsAWT extends UITestCase {
+ static int demoCount = 4;
+ static boolean opaque = false; // always faster and flicker-less w/o opaque, i.e. w/ alpha channel due to JComponent _paintImmediately(..)
+ static float alpha = 0.3f;
+ static GLProfile glp;
+ static boolean shallUsePBuffer = false;
+ static boolean shallUseBitmap = false;
+ static boolean useMSAA = false;
+ static int swapInterval = 0;
+ static boolean useAnimator = true;
+ static boolean manualTest = false;
+
+ @BeforeClass
+ public static void initClass() {
+ if(GLProfile.isAvailable(GLProfile.GL2)) {
+ glp = GLProfile.get(GLProfile.GL2);
+ Assert.assertNotNull(glp);
+ } else {
+ setTestSupported(false);
+ }
+ }
+
+ @AfterClass
+ public static void releaseClass() {
+ }
+
+ private void addPanel(GLCapabilitiesImmutable caps, GLAnimatorControl anim, final JFrame frame, boolean opaque, int x, int y, int w, int h, FloatBuffer color, float[] clearColor)
+ throws InterruptedException, InvocationTargetException
+ {
+ final GLJPanel canvas = new GLJPanel(caps);
+ canvas.setOpaque(opaque);
+ final Dimension glc_sz = new Dimension(w, h);
+ canvas.setMinimumSize(glc_sz);
+ canvas.setPreferredSize(glc_sz);
+ canvas.setSize(glc_sz);
+ GearsES2 demo = new GearsES2(swapInterval);
+ demo.setIgnoreFocus(true);
+ demo.setGearsColors(color, color, color);
+ demo.setClearColor(clearColor);
+ canvas.addGLEventListener(demo);
+ if( null != anim ) {
+ anim.add(canvas);
+ }
+
+ final JPanel panel = new JPanel(new BorderLayout());
+ panel.setBounds(x, y, w, h);
+ panel.setOpaque(opaque);
+
+ SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ panel.add(canvas, BorderLayout.CENTER);
+ frame.getContentPane().add(panel);
+ } } ) ;
+ }
+
+ public static final FloatBuffer red = Buffers.newDirectFloatBuffer( new float[] { 1.0f, 0.0f, 0.0f, 1.0f } );
+ public static final FloatBuffer green = Buffers.newDirectFloatBuffer( new float[] { 0.0f, 1.0f, 0.0f, 1.0f } );
+ public static final FloatBuffer blue = Buffers.newDirectFloatBuffer( new float[] { 0.0f, 0.0f, 1.0f, 1.0f } );
+ public static final FloatBuffer yellow = Buffers.newDirectFloatBuffer( new float[] { 1.0f, 1.0f, 0.0f, 1.0f } );
+ public static final float grayf = 0.3f;
+ public static final float[] redish = new float[] { grayf, 0.0f, 0.0f, alpha };
+ public static final float[] greenish = new float[] { 0.0f, grayf, 0.0f, alpha };
+ public static final float[] blueish = new float[] { 0.0f, 0.0f, grayf, alpha };
+ public static final float[] yellowish = new float[] { grayf, grayf, 0.0f, alpha };
+
+ protected void runTestGL(GLCapabilities caps)
+ throws AWTException, InterruptedException, InvocationTargetException
+ {
+ if( !opaque ) {
+ caps.setAlphaBits(caps.getRedBits());
+ }
+
+ final JFrame frame = new JFrame("Swing GLJPanel");
+ Assert.assertNotNull(frame);
+
+ final FPSAnimator animator = useAnimator ? new FPSAnimator(60) : null;
+
+ SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ frame.getContentPane().setLayout(null);
+ } } );
+
+ if( demoCount > 0 ) {
+ addPanel(caps, animator, frame, opaque, 50, 50, 300, 300, red, redish); // A
+ }
+ if( demoCount > 1 ) {
+ addPanel(caps, animator, frame, opaque, 200, 0, 150, 150, green, greenish); // B
+ }
+ if( demoCount > 2 ) {
+ addPanel(caps, animator, frame, opaque, 0, 250, 300, 300, blue, blueish); // C
+ }
+ if( demoCount > 3 ) {
+ addPanel(caps, animator, frame, opaque, 300, 300, 100, 100, yellow, yellowish); // D
+ }
+
+ SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ frame.setSize(600, 600);
+ frame.getContentPane().validate();
+ // frame.pack();
+ frame.setVisible(true);
+ } } ) ;
+
+ if( useAnimator ) {
+ animator.setUpdateFPSFrames(60, System.err);
+ animator.start();
+ Assert.assertEquals(true, animator.isAnimating());
+ }
+
+ QuitAdapter quitAdapter = new QuitAdapter();
+
+ final long t0 = System.currentTimeMillis();
+ long t1 = t0;
+ while(!quitAdapter.shouldQuit() && t1 - t0 < duration) {
+ Thread.sleep(100);
+ t1 = System.currentTimeMillis();
+ }
+
+ Assert.assertNotNull(frame);
+ Assert.assertNotNull(animator);
+
+ if( useAnimator ) {
+ animator.stop();
+ Assert.assertEquals(false, animator.isAnimating());
+ }
+ SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ frame.setVisible(false);
+ // frame.getContentPane().removeAll();
+ // frame.removeAll();
+ frame.dispose();
+ } } );
+ }
+
+ @Test
+ public void test01_DefaultNorm()
+ throws AWTException, InterruptedException, InvocationTargetException
+ {
+ GLCapabilities caps = new GLCapabilities(GLProfile.getDefault());
+ if(useMSAA) {
+ caps.setNumSamples(4);
+ caps.setSampleBuffers(true);
+ }
+ if(shallUsePBuffer) {
+ caps.setPBuffer(true);
+ }
+ if(shallUseBitmap) {
+ caps.setBitmap(true);
+ }
+ runTestGL(caps);
+ }
+
+ @Test
+ public void test02_DefaultMsaa()
+ throws AWTException, InterruptedException, InvocationTargetException
+ {
+ if( manualTest ) {
+ return;
+ }
+ GLCapabilities caps = new GLCapabilities(GLProfile.getDefault());
+ caps.setNumSamples(4);
+ caps.setSampleBuffers(true);
+ runTestGL(caps);
+ }
+
+ @Test
+ public void test03_PbufferNorm()
+ throws AWTException, InterruptedException, InvocationTargetException
+ {
+ if( manualTest ) {
+ return;
+ }
+ GLCapabilities caps = new GLCapabilities(GLProfile.getDefault());
+ caps.setPBuffer(true);
+ runTestGL(caps);
+ }
+
+ @Test
+ public void test04_PbufferMsaa()
+ throws AWTException, InterruptedException, InvocationTargetException
+ {
+ if( manualTest ) {
+ return;
+ }
+ GLCapabilities caps = new GLCapabilities(GLProfile.getDefault());
+ caps.setNumSamples(4);
+ caps.setSampleBuffers(true);
+ caps.setPBuffer(true);
+ runTestGL(caps);
+ }
+
+ @Test
+ public void test05_BitmapNorm()
+ throws AWTException, InterruptedException, InvocationTargetException
+ {
+ if( manualTest ) {
+ return;
+ }
+ GLCapabilities caps = new GLCapabilities(GLProfile.getDefault());
+ caps.setBitmap(true);
+ runTestGL(caps);
+ }
+
+ @Test
+ public void test06_BitmapMsaa()
+ throws AWTException, InterruptedException, InvocationTargetException
+ {
+ if( manualTest ) {
+ return;
+ }
+ GLCapabilities caps = new GLCapabilities(GLProfile.getDefault());
+ caps.setNumSamples(4);
+ caps.setSampleBuffers(true);
+ caps.setBitmap(true);
+ 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++;
+ duration = MiscUtils.atol(args[i], duration);
+ } else if(args[i].equals("-vsync")) {
+ i++;
+ swapInterval = MiscUtils.atoi(args[i], swapInterval);
+ } else if(args[i].equals("-msaa")) {
+ useMSAA = true;
+ } else if(args[i].equals("-opaque")) {
+ opaque = true;
+ } else if(args[i].equals("-alpha")) {
+ i++;
+ alpha = MiscUtils.atof(args[i], alpha);
+ } else if(args[i].equals("-noanim")) {
+ useAnimator = false;
+ } else if(args[i].equals("-pbuffer")) {
+ shallUsePBuffer = true;
+ } else if(args[i].equals("-bitmap")) {
+ shallUseBitmap = true;
+ } else if(args[i].equals("-manual")) {
+ manualTest = true;
+ } else if(args[i].equals("-demos")) {
+ i++;
+ demoCount = MiscUtils.atoi(args[i], demoCount);
+ }
+ }
+ System.err.println("swapInterval "+swapInterval);
+ System.err.println("opaque "+opaque);
+ System.err.println("alpha "+alpha);
+ System.err.println("demos "+demoCount);
+ System.err.println("useMSAA "+useMSAA);
+ System.err.println("useAnimator "+useAnimator);
+ System.err.println("shallUsePBuffer "+shallUsePBuffer);
+ System.err.println("shallUseBitmap "+shallUseBitmap);
+ System.err.println("manualTest "+manualTest);
+
+ org.junit.runner.JUnitCore.main(TestGearsES2GLJPanelsAWT.class.getName());
+ }
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NEWT.java
index 4c6cae501..d195d6b18 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NEWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NEWT.java
@@ -122,6 +122,7 @@ public class TestGearsES2NEWT extends UITestCase {
final GearsES2 demo = new GearsES2(swapInterval);
demo.setPMVUseBackingArray(pmvUseBackingArray);
glWindow.addGLEventListener(demo);
+
final SnapshotGLEventListener snap = new SnapshotGLEventListener();
glWindow.addGLEventListener(snap);
if(waitForKey) {
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/awt/TestGearsGLJPanelAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/awt/TestGearsGLJPanelAWT.java
index 728b040af..02e44e747 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/awt/TestGearsGLJPanelAWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/awt/TestGearsGLJPanelAWT.java
@@ -60,7 +60,7 @@ public class TestGearsGLJPanelAWT extends UITestCase {
static boolean shallUsePBuffer = false;
static boolean shallUseBitmap = false;
static boolean useMSAA = false;
- static int swapInterval = 1;
+ static int swapInterval = 0;
static boolean useAnimator = true;
static boolean manualTest = false;
@@ -92,7 +92,7 @@ public class TestGearsGLJPanelAWT extends UITestCase {
glJPanel.setMinimumSize(glc_sz);
glJPanel.setPreferredSize(glc_sz);
glJPanel.setSize(glc_sz);
- glJPanel.addGLEventListener(new Gears());
+ glJPanel.addGLEventListener(new Gears(swapInterval));
final SnapshotGLEventListener snap = new SnapshotGLEventListener();
glJPanel.addGLEventListener(snap);
diff --git a/src/test/com/jogamp/opengl/test/junit/util/MiscUtils.java b/src/test/com/jogamp/opengl/test/junit/util/MiscUtils.java
index 0aee0f087..d17914939 100644
--- a/src/test/com/jogamp/opengl/test/junit/util/MiscUtils.java
+++ b/src/test/com/jogamp/opengl/test/junit/util/MiscUtils.java
@@ -51,6 +51,15 @@ public class MiscUtils {
return def;
}
+ public static float atof(String str, float def) {
+ try {
+ return Float.parseFloat(str);
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ return def;
+ }
+
public static String toHexString(byte hex) {
return "0x" + Integer.toHexString( (int)hex & 0x000000FF );
}