diff options
Diffstat (limited to 'src/test/com')
7 files changed, 300 insertions, 304 deletions
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestBug692GL3VAO.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestBug692GL3VAO.java index 55328f1e6..29b48fecd 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestBug692GL3VAO.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestBug692GL3VAO.java @@ -41,8 +41,7 @@ import javax.media.opengl.GLEventListener; import javax.media.opengl.GLException;
import javax.media.opengl.GLProfile;
-import junit.framework.Assert;
-
+import org.junit.Assert;
import org.junit.Test; import org.junit.FixMethodOrder; import org.junit.runners.MethodSorters;
@@ -67,7 +66,7 @@ import com.jogamp.opengl.util.GLBuffers; @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class TestBug692GL3VAO extends UITestCase {
static long duration = 500; // ms
-
+
static class GL3VAODemo implements GLEventListener {
/** Different modes of displaying the geometry */
public enum Mode {
@@ -78,7 +77,7 @@ public class TestBug692GL3VAO extends UITestCase { t.displayNonVAO(gl);
}
},
-
+
/** Using VAOs throws [incorrectly as of JOGL 2.0rc11] a GLException */
VAO_NORMAL {
@Override
@@ -86,34 +85,34 @@ public class TestBug692GL3VAO extends UITestCase { t.displayVAONormal(gl);
}
};
-
+
abstract void display(GL3VAODemo t, GL3 gl);
}
-
+
private final Mode[] allModes;
private Mode currentMode;
- private int currentModeIdx;
-
+ private int currentModeIdx;
+
public GL3VAODemo(Mode[] modes) {
allModes = modes;
currentMode = allModes[0];
currentModeIdx = 0;
}
-
+
private final static float[] vertexData = new float[]{
0.0f, 0.75f, 0.0f, 1,0,0,
-0.5f, -0.75f, 0.0f, 0,1,0,
0.9f, -0.75f, 0.0f, 0,0,1
};
-
+
private int ibo = -1;
private int vbo = -1;
private int vertID = -1;
private int fragID = -1;
private int progID = -1;
-
+
private int vaoNormal = -1;
-
+
private static int createShader(final GL3 gl, int type,
final String[] srcLines){
int shaderID = gl.glCreateShader(type);
@@ -126,14 +125,14 @@ public class TestBug692GL3VAO extends UITestCase { gl.glCompileShader(shaderID);
return shaderID;
}
-
+
private void initBuffers(GL3 gl) {
// IDs for 2 buffers
int[] buffArray = new int[2];
gl.glGenBuffers(buffArray.length, buffArray, 0);
vbo = buffArray[0];
assert vbo > 0;
-
+
// Bind buffer and upload data
gl.glBindBuffer(GL3.GL_ARRAY_BUFFER, vbo);
FloatBuffer buffer = GLBuffers.newDirectFloatBuffer(vertexData);
@@ -141,7 +140,7 @@ public class TestBug692GL3VAO extends UITestCase { gl.glBufferData(GL3.GL_ARRAY_BUFFER, vertexData.length * Buffers.SIZEOF_FLOAT,
buffer, GL3.GL_STATIC_DRAW);
gl.glBindBuffer(GL3.GL_ARRAY_BUFFER, 0);
-
+
// Buffer with the 3 indices required for one triangle
ibo = buffArray[1];
assert ibo > 0;
@@ -165,7 +164,7 @@ public class TestBug692GL3VAO extends UITestCase { "}\n"
};
vertID = createShader(gl, GL3.GL_VERTEX_SHADER, vertSrc);
-
+
final String[] fragSrc = new String[]{
"#version 150\n",
"in vec4 pColor;\n",
@@ -174,10 +173,10 @@ public class TestBug692GL3VAO extends UITestCase { "}\n"
};
fragID = createShader(gl, GL3.GL_FRAGMENT_SHADER, fragSrc);
-
+
// We're done with the compiler
gl.glReleaseShaderCompiler();
-
+
progID = gl.glCreateProgram();
assert progID > 0;
gl.glAttachShader(progID, vertID);
@@ -185,50 +184,50 @@ public class TestBug692GL3VAO extends UITestCase { gl.glLinkProgram(progID);
gl.glValidateProgram(progID);
}
-
+
private int initVAO(GL3 gl) {
int[] buff = new int[1];
gl.glGenVertexArrays(1, buff, 0);
int vao = buff[0];
Assert.assertTrue("Invalid VAO: "+vao, vao > 0);
-
-
+
+
gl.glUseProgram(progID);
final int posLoc = gl.glGetAttribLocation(progID, "vPosition");
final int colorLoc = gl.glGetAttribLocation(progID, "vColor");
gl.glUseProgram(0);
-
+
gl.glBindVertexArray(vao);
gl.glBindBuffer(GL3.GL_ARRAY_BUFFER, vbo);
gl.glBindBuffer(GL3.GL_ELEMENT_ARRAY_BUFFER, ibo);
-
+
gl.glEnableVertexAttribArray(posLoc);
gl.glEnableVertexAttribArray(colorLoc);
-
+
final int stride = 6 * Buffers.SIZEOF_FLOAT;
final int cOff = 3 * Buffers.SIZEOF_FLOAT;
gl.glVertexAttribPointer(posLoc, 3, GL3.GL_FLOAT, false, stride, 0L);
gl.glVertexAttribPointer(colorLoc,3, GL3.GL_FLOAT, false, stride, cOff);
-
+
gl.glBindVertexArray(0);
return vao;
}
-
+
@Override
public void init(GLAutoDrawable drawable) {
drawable.setGL(new DebugGL3(drawable.getGL().getGL3()));
-
+
final GL3 gl = drawable.getGL().getGL3();
gl.glEnable(GL3.GL_DEPTH_TEST);
gl.glDisable(GL3.GL_CULL_FACE);
initBuffers(gl);
initShaders(gl);
-
+
vaoNormal = initVAO(gl);
-
+
gl.setSwapInterval(1);
}
-
+
@Override
public void dispose(GLAutoDrawable drawable) {
final GL3 gl = drawable.getGL().getGL3();
@@ -239,13 +238,13 @@ public class TestBug692GL3VAO extends UITestCase { gl.glDeleteShader(fragID);
gl.glDeleteShader(vertID);
}
-
+
private void displayNonVAO(final GL3 gl) {
final int posLoc = gl.glGetAttribLocation(progID, "vPosition");
final int colorLoc = gl.glGetAttribLocation(progID, "vColor");
gl.glEnableVertexAttribArray(posLoc);
gl.glEnableVertexAttribArray(colorLoc);
-
+
gl.glBindBuffer(GL3.GL_ARRAY_BUFFER, vbo);
final int stride = 6 * Buffers.SIZEOF_FLOAT;
final int cOff = 3 * Buffers.SIZEOF_FLOAT;
@@ -253,13 +252,13 @@ public class TestBug692GL3VAO extends UITestCase { gl.glVertexAttribPointer(colorLoc,3, GL3.GL_FLOAT, false, stride, cOff);
gl.glBindBuffer(GL3.GL_ELEMENT_ARRAY_BUFFER, ibo);
gl.glDrawElements(GL3.GL_TRIANGLES, 3, GL3.GL_UNSIGNED_SHORT, 0L);
-
+
gl.glDisableVertexAttribArray(posLoc);
gl.glDisableVertexAttribArray(colorLoc);
gl.glBindBuffer(GL3.GL_ARRAY_BUFFER, 0);
gl.glBindBuffer(GL3.GL_ELEMENT_ARRAY_BUFFER, 0);
}
-
+
private void displayVAONormal(final GL3 gl) {
try {
gl.glBindVertexArray(vaoNormal);
@@ -269,7 +268,7 @@ public class TestBug692GL3VAO extends UITestCase { Logger.getLogger(TestBug692GL3VAO.class.getName()).log(Level.SEVERE,null,ex);
}
}
-
+
@Override
public void display(GLAutoDrawable drawable) {
final GL3 gl = drawable.getGL().getGL3();
@@ -279,7 +278,7 @@ public class TestBug692GL3VAO extends UITestCase { gl.glUseProgram(progID);
final Mode newMode;
{
- currentModeIdx = ( currentModeIdx + 1 ) % allModes.length;
+ currentModeIdx = ( currentModeIdx + 1 ) % allModes.length;
newMode = allModes[ currentModeIdx ];
}
if (newMode != currentMode) {
@@ -289,59 +288,59 @@ public class TestBug692GL3VAO extends UITestCase { currentMode.display(this, gl);
gl.glUseProgram(0);
}
-
+
@Override
public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h) {
- }
+ }
}
-
+
private void testImpl(GLProfile profile, GL3VAODemo.Mode[] modes) throws InterruptedException {
final GLCapabilities capabilities = new GLCapabilities(profile);
final GLWindow glWindow = GLWindow.create(capabilities);
glWindow.setSize(512, 512);
-
+
Animator anim = new Animator(glWindow);
-
+
QuitAdapter quitAdapter = new QuitAdapter();
glWindow.addKeyListener(quitAdapter);
glWindow.addWindowListener(quitAdapter);
-
+
final GL3VAODemo vaoTest = new GL3VAODemo(modes);
glWindow.addGLEventListener(vaoTest);
glWindow.setVisible(true);
anim.start();
-
+
final long t0 = System.currentTimeMillis();
long t1 = t0;
while(!quitAdapter.shouldQuit() && t1-t0<duration) {
Thread.sleep(100);
t1 = System.currentTimeMillis();
}
-
+
anim.stop();
glWindow.destroy();
}
-
+
//@Test
public void testGL3() throws GLException, InterruptedException {
if( ! GLProfile.isAvailable(GLProfile.GL3) ) {
System.err.println("GL3 n/a");
return;
}
- GL3VAODemo.Mode[] modes = new GL3VAODemo.Mode[] { GL3VAODemo.Mode.VAO_NORMAL };
- testImpl(GLProfile.get(GLProfile.GL3), modes);
+ GL3VAODemo.Mode[] modes = new GL3VAODemo.Mode[] { GL3VAODemo.Mode.VAO_NORMAL };
+ testImpl(GLProfile.get(GLProfile.GL3), modes);
}
-
+
@Test
public void testGL3bc() throws GLException, InterruptedException {
if( ! GLProfile.isAvailable(GLProfile.GL3bc) ) {
System.err.println("GL3bc n/a");
return;
}
- GL3VAODemo.Mode[] modes = new GL3VAODemo.Mode[] { GL3VAODemo.Mode.VAO_NORMAL, GL3VAODemo.Mode.NON_VAO };
- testImpl(GLProfile.get(GLProfile.GL3bc), modes);
+ GL3VAODemo.Mode[] modes = new GL3VAODemo.Mode[] { GL3VAODemo.Mode.VAO_NORMAL, GL3VAODemo.Mode.NON_VAO };
+ testImpl(GLProfile.get(GLProfile.GL3bc), modes);
}
-
+
public static void main(String args[]) throws IOException {
for(int i=0; i<args.length; i++) {
if(args[i].equals("-time")) {
@@ -350,6 +349,6 @@ public class TestBug692GL3VAO extends UITestCase { }
String tstname = TestBug692GL3VAO.class.getName();
org.junit.runner.JUnitCore.main(tstname);
- }
-
+ }
+
}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug572AWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug572AWT.java index 763c0c8ff..234336016 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug572AWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug572AWT.java @@ -3,14 +3,14 @@ * * 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 @@ -20,12 +20,12 @@ * 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; import java.awt.Dimension; @@ -38,8 +38,7 @@ import javax.media.opengl.awt.GLCanvas; import javax.swing.JFrame; import javax.swing.SwingUtilities; -import junit.framework.Assert; - +import org.junit.Assert; import org.junit.Assume; import org.junit.Test; import org.junit.FixMethodOrder; @@ -55,14 +54,14 @@ import com.jogamp.opengl.test.junit.util.UITestCase; @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class TestBug572AWT extends UITestCase { static long durationPerTest = 150; // ms - + static class Cleanup implements Runnable { Window window; - + public Cleanup(Window w) { window = w; } - + public void run() { System.err.println("cleaning up..."); window.setVisible(false); @@ -75,10 +74,10 @@ public class TestBug572AWT extends UITestCase { window.dispose(); } } - + private void testRealizeGLCanvas(final boolean onAWTEDT, final boolean setFrameSize) throws InterruptedException, InvocationTargetException { final Window window = new JFrame(this.getSimpleTestName(" - ")); - final GLCapabilities caps = new GLCapabilities(GLProfile.getGL2ES2()); + final GLCapabilities caps = new GLCapabilities(GLProfile.getGL2ES2()); final GLCanvas glCanvas = new GLCanvas(caps); final SnapshotGLEventListener snapshooter = new SnapshotGLEventListener(); snapshooter.setMakeSnapshotAlways(true); @@ -95,7 +94,7 @@ public class TestBug572AWT extends UITestCase { if( setFrameSize ) { window.setSize(512, 512); window.validate(); - } else { + } else { Dimension size = new Dimension(512, 512); glCanvas.setPreferredSize(size); glCanvas.setMinimumSize(size); @@ -109,42 +108,42 @@ public class TestBug572AWT extends UITestCase { } else { // trigger realization on non AWT-EDT, realization will happen at a later time .. realizeAction.run(); - + // Wait until it's displayable after issuing initial setVisible(true) on current thread (non AWT-EDT)! Assert.assertTrue("GLCanvas didn't become visible", AWTRobotUtil.waitForVisible(glCanvas, true)); - Assert.assertTrue("GLCanvas didn't become realized", AWTRobotUtil.waitForRealized(glCanvas, true)); // implies displayable + Assert.assertTrue("GLCanvas didn't become realized", AWTRobotUtil.waitForRealized(glCanvas, true)); // implies displayable } - + System.err.println("XXXX-0 "+glCanvas.getDelegatedDrawable().isRealized()+", "+glCanvas); - + Assert.assertTrue("GLCanvas didn't become displayable", glCanvas.isDisplayable()); Assert.assertTrue("GLCanvas didn't become realized", glCanvas.isRealized()); - + // The AWT-EDT reshape/repaint events happen offthread later .. System.err.println("XXXX-1 reshapeCount "+snapshooter.getReshapeCount()); System.err.println("XXXX-1 displayCount "+snapshooter.getDisplayCount()); - + // Wait unitl AWT-EDT has issued reshape/repaint for (int wait=0; wait<AWTRobotUtil.POLL_DIVIDER && - ( 0 == snapshooter.getReshapeCount() || 0 == snapshooter.getDisplayCount() ); + ( 0 == snapshooter.getReshapeCount() || 0 == snapshooter.getDisplayCount() ); wait++) { Thread.sleep(AWTRobotUtil.TIME_SLICE); } System.err.println("XXXX-2 reshapeCount "+snapshooter.getReshapeCount()); System.err.println("XXXX-2 displayCount "+snapshooter.getDisplayCount()); - + Assert.assertTrue("GLCanvas didn't reshape", snapshooter.getReshapeCount()>0); Assert.assertTrue("GLCanvas didn't display", snapshooter.getDisplayCount()>0); - + Thread.sleep(durationPerTest); - + // After initial 'setVisible(true)' all AWT manipulation needs to be done // via the AWT EDT, according to the AWT spec. // AWT / Swing on EDT.. SwingUtilities.invokeAndWait(new Cleanup(window)); } - + @Test(timeout = 10000) // 10s timeout public void test01RealizeGLCanvasOnAWTEDTUseFrameSize() throws InterruptedException, InvocationTargetException { testRealizeGLCanvas(true, true); @@ -154,7 +153,7 @@ public class TestBug572AWT extends UITestCase { public void test02RealizeGLCanvasOnAWTEDTUseGLCanvasSize() throws InterruptedException, InvocationTargetException { testRealizeGLCanvas(true, false); } - + @Test(timeout = 10000) // 10s timeout public void test11RealizeGLCanvasOnMainTUseFrameSize() throws InterruptedException, InvocationTargetException { testRealizeGLCanvas(false, true); @@ -164,7 +163,7 @@ public class TestBug572AWT extends UITestCase { public void test12RealizeGLCanvasOnMainTUseGLCanvasSize() throws InterruptedException, InvocationTargetException { testRealizeGLCanvas(false, false); } - + public static void main(String args[]) { org.junit.runner.JUnitCore.main(TestBug572AWT.class.getName()); } diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug675BeansInDesignTimeAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug675BeansInDesignTimeAWT.java index 05f0c1ce3..3363fdd52 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug675BeansInDesignTimeAWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/awt/TestBug675BeansInDesignTimeAWT.java @@ -3,14 +3,14 @@ * * 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 @@ -20,12 +20,12 @@ * 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; import java.awt.BorderLayout; @@ -40,8 +40,7 @@ import javax.media.opengl.awt.GLCanvas; import javax.swing.JFrame; import javax.swing.SwingUtilities; -import junit.framework.Assert; - +import org.junit.Assert; import org.junit.Test; import org.junit.FixMethodOrder; import org.junit.runners.MethodSorters; @@ -54,24 +53,24 @@ import com.jogamp.opengl.test.junit.util.UITestCase; public class TestBug675BeansInDesignTimeAWT extends UITestCase { static boolean waitForKey = false; static long durationPerTest = 200; - + @Test public void test01() throws InterruptedException, InvocationTargetException { Beans.setDesignTime(true); - - final GLCapabilities caps = new GLCapabilities(GLProfile.getGL2ES2()); + + final GLCapabilities caps = new GLCapabilities(GLProfile.getGL2ES2()); final GLCanvas glCanvas = new GLCanvas(caps); final Dimension preferredGLSize = new Dimension(400,200); glCanvas.setPreferredSize(preferredGLSize); glCanvas.setMinimumSize(preferredGLSize); glCanvas.setSize(preferredGLSize); - + glCanvas.addGLEventListener(new GearsES2()); final Window window = new JFrame(this.getSimpleTestName(" - ")); window.setLayout(new BorderLayout()); window.add(glCanvas, BorderLayout.CENTER); - + // trigger realization on AWT-EDT, otherwise it won't immediatly .. SwingUtilities.invokeAndWait(new Runnable() { @Override @@ -79,22 +78,22 @@ public class TestBug675BeansInDesignTimeAWT extends UITestCase { window.pack(); window.validate(); window.setVisible(true); - } + } } ); - + // Immediately displayable after issuing initial setVisible(true) on AWT-EDT! Assert.assertTrue("GLCanvas didn't become displayable", glCanvas.isDisplayable()); if( !Beans.isDesignTime() ) { Assert.assertTrue("GLCanvas didn't become realized", glCanvas.isRealized()); } - + Thread.sleep(durationPerTest); - + SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { window.dispose(); - } + } } ); } diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/caps/TestBug605FlippedImageAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/caps/TestBug605FlippedImageAWT.java index 0b317eb84..89470a922 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/caps/TestBug605FlippedImageAWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/caps/TestBug605FlippedImageAWT.java @@ -3,14 +3,14 @@ * * 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 @@ -20,7 +20,7 @@ * 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. @@ -45,8 +45,7 @@ import com.jogamp.opengl.util.texture.TextureIO; import java.awt.image.BufferedImage; -import junit.framework.Assert; - +import org.junit.Assert; import org.junit.Test; import org.junit.FixMethodOrder; import org.junit.runners.MethodSorters; @@ -58,19 +57,19 @@ public class TestBug605FlippedImageAWT extends UITestCase { class FlippedImageTest implements GLEventListener { public void display(GLAutoDrawable drawable) { GL2 gl = drawable.getGL().getGL2(); - + gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT | GL.GL_STENCIL_BUFFER_BIT | GL2.GL_ACCUM_BUFFER_BIT ); - + gl.glMatrixMode(GL2.GL_PROJECTION); gl.glLoadIdentity(); gl.glMatrixMode(GL2.GL_MODELVIEW); gl.glLoadIdentity(); - + // red below gl.glColor3f(1, 0, 0); gl.glRectf(-1, -1, 1, 0); - + // green above gl.glColor3f(0, 1, 0); gl.glRectf(-1, 0, 1, 1); @@ -80,12 +79,12 @@ public class TestBug605FlippedImageAWT extends UITestCase { if(caps.getAccumGreenBits() > 0) { gl.glAccum(GL2.GL_ACCUM, 1.0f); gl.glAccum(GL2.GL_RETURN, 1.0f); - } + } gl.glFinish(); - + final int width = drawable.getWidth(); final int height = drawable.getHeight(); - + final String fname = getSnapshotFilename(0, null, caps, width, height, false, TextureIO.PNG, null); try { Screenshot.writeToFile(new File(fname), width, height, false); @@ -93,83 +92,83 @@ public class TestBug605FlippedImageAWT extends UITestCase { throw e; } catch (IOException e) { throw new GLException(e); - } + } testFlipped(width, height); } - + public void init(GLAutoDrawable drawable) { final GL gl = drawable.getGL(); System.err.println("GL_RENDERER: "+gl.glGetString(GL.GL_RENDERER)); System.err.println("GL_VERSION: "+gl.glGetString(GL.GL_VERSION)); - } - public void reshape(GLAutoDrawable glDrawable, int x, int y, int w, int h) {} - public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {} + } + public void reshape(GLAutoDrawable glDrawable, int x, int y, int w, int h) {} + public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {} public void dispose(GLAutoDrawable drawable) {} } - + static final int green = 0x0000ff00; // above static final int red = 0x00ff0000; // below private void testFlipped(int width, int height) { // Default origin 0/0 is lower left corner, so is the memory layout - // However AWT origin 0/0 is upper left corner + // However AWT origin 0/0 is upper left corner final BufferedImage image = Screenshot.readToBufferedImage(width, height); - + final int below = image.getRGB(0, height-1) & 0x00ffffff; System.err.println("below: 0x"+Integer.toHexString(below)); - + final int above = image.getRGB(0, 0) & 0x00ffffff; System.err.println("above: 0x"+Integer.toHexString(above)); - + if (above == green && below == red) { System.out.println("Image right side up"); } else if (above == red && below == green) { Assert.assertTrue("Image is flipped", false); } else { Assert.assertTrue("Error in test", false); - } + } } - + private void test(GLCapabilitiesImmutable caps) { - + final GLDrawableFactory glFactory = GLDrawableFactory.getFactory(caps.getGLProfile()); final GLAutoDrawable glad = glFactory.createOffscreenAutoDrawable(null, caps, null, 256, 256, null); final FlippedImageTest tglel = new FlippedImageTest(); glad.addGLEventListener(tglel); - + // 1 frame incl. snapshot to memory & file glad.display(); System.err.println("XXX "+glad.getChosenGLCapabilities()); System.err.println("XXX "+glad.getContext().getGLVersion()); - - glad.destroy(); + + glad.destroy(); } - + @Test public void test01DefaultFBO() { final GLProfile glp = GLProfile.get(GLProfile.GL2); final GLCapabilities caps = new GLCapabilities(glp); - caps.setFBO(true); - test(caps); + caps.setFBO(true); + test(caps); } - + @Test public void test01StencilFBO() { final GLProfile glp = GLProfile.get(GLProfile.GL2); final GLCapabilities caps = new GLCapabilities(glp); caps.setStencilBits(8); - caps.setFBO(true); - test(caps); + caps.setFBO(true); + test(caps); } - + @Test public void test01DefaultPBuffer() { final GLProfile glp = GLProfile.get(GLProfile.GL2); final GLCapabilities caps = new GLCapabilities(glp); - caps.setPBuffer(true); - test(caps); + caps.setPBuffer(true); + test(caps); } - + @Test public void test01AccumStencilPBuffer() { final GLProfile glp = GLProfile.get(GLProfile.GL2); @@ -178,10 +177,10 @@ public class TestBug605FlippedImageAWT extends UITestCase { caps.setAccumGreenBits(16); caps.setAccumBlueBits(16); caps.setStencilBits(8); - caps.setPBuffer(true); - test(caps); + caps.setPBuffer(true); + test(caps); } - + public static void main(String[] args) { org.junit.runner.JUnitCore.main(TestBug605FlippedImageAWT.class.getName()); } diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/caps/TestBug605FlippedImageNEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/caps/TestBug605FlippedImageNEWT.java index 4fc681a74..8d4710ad3 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/caps/TestBug605FlippedImageNEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/caps/TestBug605FlippedImageNEWT.java @@ -3,14 +3,14 @@ * * 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 @@ -20,7 +20,7 @@ * 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. @@ -38,8 +38,7 @@ import javax.media.opengl.GLDrawableFactory; import javax.media.opengl.GLEventListener; import javax.media.opengl.GLProfile; -import junit.framework.Assert; - +import org.junit.Assert; import org.junit.Test; import org.junit.FixMethodOrder; import org.junit.runners.MethodSorters; @@ -52,71 +51,71 @@ public class TestBug605FlippedImageNEWT extends UITestCase { static class FlippedImageTest implements GLEventListener { public void display(GLAutoDrawable drawable) { GL2 gl = drawable.getGL().getGL2(); - + gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT | GL.GL_STENCIL_BUFFER_BIT | GL2.GL_ACCUM_BUFFER_BIT ); - + gl.glMatrixMode(GL2.GL_PROJECTION); gl.glLoadIdentity(); gl.glMatrixMode(GL2.GL_MODELVIEW); gl.glLoadIdentity(); - + // red below gl.glColor3f(1, 0, 0); gl.glRectf(-1, -1, 1, 0); - + // green above gl.glColor3f(0, 1, 0); gl.glRectf(-1, 0, 1, 1); gl.glFinish(); - + final GLCapabilitiesImmutable caps = drawable.getChosenGLCapabilities(); if(caps.getAccumGreenBits() > 0) { gl.glAccum(GL2.GL_ACCUM, 1.0f); gl.glAccum(GL2.GL_RETURN, 1.0f); - } + } gl.glFinish(); } - + public void init(GLAutoDrawable drawable) { final GL gl = drawable.getGL(); System.err.println("GL_RENDERER: "+gl.glGetString(GL.GL_RENDERER)); System.err.println("GL_VERSION: "+gl.glGetString(GL.GL_VERSION)); - } - public void reshape(GLAutoDrawable glDrawable, int x, int y, int w, int h) {} - public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {} + } + public void reshape(GLAutoDrawable glDrawable, int x, int y, int w, int h) {} + public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {} public void dispose(GLAutoDrawable drawable) {} } - + static final int green = 0x0000ff00; // above static final int red = 0x00ff0000; // below private int getRGB(ByteBuffer bb, int o) { - return ( (int)bb.get(o+0) & 0x000000ff ) << 16 | - ( (int)bb.get(o+1) & 0x000000ff ) << 8 | - ( (int)bb.get(o+2) & 0x000000ff ); + return ( bb.get(o+0) & 0x000000ff ) << 16 | + ( bb.get(o+1) & 0x000000ff ) << 8 | + ( bb.get(o+2) & 0x000000ff ); } - + private void testFlipped(ByteBuffer bb, int width, int height, int comp) { // Default origin 0/0 is lower left corner, so is the memory layout - + // x=0, y=0: RGB -> _RGB [high-byte .. low-byte] final int below = getRGB(bb, 0); System.err.println("below: 0x"+Integer.toHexString(below)); - + // x=0, y=height-1: RGB -> _RGB [high-byte .. low-byte] final int above= getRGB(bb, ( height - 1 ) * ( width * comp )); System.err.println("above: 0x"+Integer.toHexString(above)); - + if (above == green && below == red) { System.out.println("Image right side up"); } else if (above == red && below == green) { Assert.assertTrue("Image is flipped", false); } else { Assert.assertTrue("Error in test", false); - } + } } - + private void test(GLCapabilitiesImmutable caps) { final GLReadBufferUtil rbu = new GLReadBufferUtil(false, false); final GLDrawableFactory glFactory = GLDrawableFactory.getFactory(caps.getGLProfile()); @@ -125,42 +124,42 @@ public class TestBug605FlippedImageNEWT extends UITestCase { glad.addGLEventListener(tglel); final SnapshotGLEventListener snap = new SnapshotGLEventListener(rbu); glad.addGLEventListener(snap); - snap.setMakeSnapshotAlways(true); - + snap.setMakeSnapshotAlways(true); + // 1 frame incl. snapshot to memory & file glad.display(); System.err.println("XXX "+glad.getChosenGLCapabilities()); System.err.println("XXX "+glad.getContext().getGLVersion()); - testFlipped((ByteBuffer)rbu.getPixelBuffer().buffer, glad.getWidth(), glad.getHeight(), 3); - - glad.destroy(); + testFlipped((ByteBuffer)rbu.getPixelBuffer().buffer, glad.getWidth(), glad.getHeight(), 3); + + glad.destroy(); } - + @Test public void test01DefaultFBO() { final GLProfile glp = GLProfile.get(GLProfile.GL2); final GLCapabilities caps = new GLCapabilities(glp); - caps.setFBO(true); - test(caps); + caps.setFBO(true); + test(caps); } - + @Test public void test01StencilFBO() { final GLProfile glp = GLProfile.get(GLProfile.GL2); final GLCapabilities caps = new GLCapabilities(glp); caps.setStencilBits(8); - caps.setFBO(true); - test(caps); + caps.setFBO(true); + test(caps); } - + @Test public void test01DefaultPBuffer() { final GLProfile glp = GLProfile.get(GLProfile.GL2); final GLCapabilities caps = new GLCapabilities(glp); - caps.setPBuffer(true); - test(caps); + caps.setPBuffer(true); + test(caps); } - + @Test public void test01AccumStencilPBuffer() { final GLProfile glp = GLProfile.get(GLProfile.GL2); @@ -169,10 +168,10 @@ public class TestBug605FlippedImageNEWT extends UITestCase { caps.setAccumGreenBits(16); caps.setAccumBlueBits(16); caps.setStencilBits(8); - caps.setPBuffer(true); - test(caps); + caps.setPBuffer(true); + test(caps); } - + public static void main(String[] args) { org.junit.runner.JUnitCore.main(TestBug605FlippedImageNEWT.class.getName()); } diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestNewtCanvasSWTBug628ResizeDeadlockAWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestNewtCanvasSWTBug628ResizeDeadlockAWT.java index dcb041147..87d4dafd6 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestNewtCanvasSWTBug628ResizeDeadlockAWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestNewtCanvasSWTBug628ResizeDeadlockAWT.java @@ -3,14 +3,14 @@ * * 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 @@ -20,7 +20,7 @@ * 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. @@ -39,6 +39,8 @@ 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.Test; import org.junit.FixMethodOrder; @@ -51,8 +53,6 @@ import javax.media.opengl.GLCapabilities ; import javax.media.opengl.GLEventListener ; import javax.media.opengl.GLProfile; -import junit.framework.Assert; - import com.jogamp.nativewindow.swt.SWTAccessor; import com.jogamp.newt.NewtFactory; import com.jogamp.newt.event.KeyAdapter; @@ -68,63 +68,63 @@ import com.jogamp.opengl.test.junit.util.UITestCase; @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class TestNewtCanvasSWTBug628ResizeDeadlockAWT extends UITestCase { - + static int duration = 500; - + static class BigFlashingX implements GLEventListener - { + { float r = 0f, g = 0f, b = 0f; - + public void init( GLAutoDrawable drawable ) { GL2 gl = drawable.getGL().getGL2() ; - + gl.glClearColor( 0.0f, 0.0f, 0.0f, 1.0f ) ; - + gl.glEnable( GL.GL_LINE_SMOOTH ) ; gl.glEnable( GL.GL_BLEND ) ; gl.glBlendFunc( GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA ) ; } - + public void reshape( GLAutoDrawable drawable, int x, int y, int width, int height ) { - // System.err.println( ">>>>>>>> reshape " + x + ", " + y + ", " + width + ", " +height ) ; + // System.err.println( ">>>>>>>> reshape " + x + ", " + y + ", " + width + ", " +height ) ; GL2 gl = drawable.getGL().getGL2() ; - + gl.glViewport( 0, 0, width, height ) ; - + gl.glMatrixMode( GL2.GL_PROJECTION ) ; gl.glLoadIdentity() ; gl.glOrtho( -1.0, 1.0, -1.0, 1.0, -1.0, 1.0 ) ; - + gl.glMatrixMode( GL2.GL_MODELVIEW ) ; gl.glLoadIdentity() ; } - + public void display( GLAutoDrawable drawable ) { - // System.err.println( ">>>> display" ) ; + // System.err.println( ">>>> display" ) ; GL2 gl = drawable.getGL().getGL2() ; - + // Sven: I could have been seeing things, but it seemed that if this // glClear is in here twice it seems aggravates the problem. Not // sure why other than it just takes longer, but this is pretty // fast operation. gl.glClear( GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT ) ; gl.glClear( GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT ) ; - + gl.glColor4f( r, g, b, 1.0f ) ; - + gl.glBegin( GL.GL_LINES ) ; { gl.glVertex2f( -1.0f, 1.0f ) ; gl.glVertex2f( 1.0f, -1.0f ) ; - + gl.glVertex2f( -1.0f, -1.0f ) ; gl.glVertex2f( 1.0f, 1.0f ) ; } gl.glEnd() ; - + if(r<1f) { r+=0.1f; } else if(g<1f) { @@ -137,25 +137,25 @@ public class TestNewtCanvasSWTBug628ResizeDeadlockAWT extends UITestCase { b = 0f; } } - + public void dispose( GLAutoDrawable drawable ) { } } - + //////////////////////////////////////////////////////////////////////////////// - + static class ResizeThread extends Thread { volatile boolean shallStop = false; - private Shell _shell ; + private final Shell _shell ; private int _n ; - + public ResizeThread( Shell shell ) { super(); _shell = shell ; } - + final Runnable resizeAction = new Runnable() { public void run() { @@ -172,10 +172,10 @@ public class TestNewtCanvasSWTBug628ResizeDeadlockAWT extends UITestCase { } catch (Exception e0) { e0.printStackTrace(); Assert.assertTrue("Deadlock @ setSize: "+e0, false); - } + } ++_n ; } }; - + public void run() { // The problem was originally observed by grabbing the lower right @@ -185,11 +185,11 @@ public class TestNewtCanvasSWTBug628ResizeDeadlockAWT extends UITestCase { // // This loop simulates rapid resizing by the user by toggling // the shell back-and-forth between two sizes. - + System.err.println("[R-0 shallStop "+shallStop+", disposed "+_shell.isDisposed()+"]"); - + final Display display = _shell.getDisplay(); - + while( !shallStop && !_shell.isDisposed() ) { try @@ -197,8 +197,8 @@ public class TestNewtCanvasSWTBug628ResizeDeadlockAWT extends UITestCase { System.err.println("[R-n shallStop "+shallStop+", disposed "+_shell.isDisposed()+"]"); display.asyncExec( resizeAction ); display.wake(); - - Thread.sleep( 50L ) ; + + Thread.sleep( 50L ) ; } catch( InterruptedException e ) { break ; } @@ -206,26 +206,26 @@ public class TestNewtCanvasSWTBug628ResizeDeadlockAWT extends UITestCase { System.err.println("*R-Exit* shallStop "+shallStop+", disposed "+_shell.isDisposed()); } } - + //////////////////////////////////////////////////////////////////////////////// - + static class KeyfireThread extends Thread { volatile boolean shallStop = false; Display _display; Robot _robot; int _n = 0; - + public KeyfireThread(Robot robot, Display display) { _robot = robot; _display = display; } - + public void run() { System.err.println("[K-0]"); - + while( !shallStop ) { try { @@ -245,26 +245,26 @@ public class TestNewtCanvasSWTBug628ResizeDeadlockAWT extends UITestCase { System.err.println("*K-Exit*"); } } - + //////////////////////////////////////////////////////////////////////////////// - + private volatile boolean shallStop = false; - + static class SWT_DSC { volatile Display display; volatile Shell shell; volatile Composite composite; volatile com.jogamp.newt.Display swtNewtDisplay = null; - + public void init() { SWTAccessor.invoke(true, new Runnable() { - public void run() { + public void run() { display = new Display(); Assert.assertNotNull( display ); }}); - + display.syncExec(new Runnable() { - public void run() { + public void run() { shell = new Shell( display ); Assert.assertNotNull( shell ); shell.setLayout( new FillLayout() ); @@ -274,7 +274,7 @@ public class TestNewtCanvasSWTBug628ResizeDeadlockAWT extends UITestCase { }}); swtNewtDisplay = NewtFactory.createDisplay(null, false); // no-reuse } - + public void dispose() { Assert.assertNotNull( display ); Assert.assertNotNull( shell ); @@ -297,17 +297,17 @@ public class TestNewtCanvasSWTBug628ResizeDeadlockAWT extends UITestCase { swtNewtDisplay = null; display = null; shell = null; - composite = null; + composite = null; } } - + @Test public void test() throws InterruptedException, AWTException, InvocationTargetException { final Robot robot = new Robot(); - + final SWT_DSC dsc = new SWT_DSC(); dsc.init(); - + final GLWindow glWindow; { final GLProfile gl2Profile = GLProfile.get( GLProfile.GL2 ) ; @@ -320,38 +320,38 @@ public class TestNewtCanvasSWTBug628ResizeDeadlockAWT extends UITestCase { public void keyReleased(com.jogamp.newt.event.KeyEvent e) { if( !e.isPrintableKey() || e.isAutoRepeat() ) { return; - } + } System.err.print("."); - glWindow.display(); - } + glWindow.display(); + } }); NewtCanvasSWT.create( dsc.composite, 0, glWindow ) ; } - + dsc.display.syncExec( new Runnable() { public void run() { dsc.shell.setText( "NewtCanvasSWT Resize Bug Demo" ) ; dsc.shell.setSize( 400, 450 ) ; dsc.shell.open() ; } } ); - + AWTRobotUtil.requestFocus(robot, glWindow, false); AWTRobotUtil.setMouseToClientLocation(robot, glWindow, 50, 50); shallStop = false; - + final ResizeThread resizer; { resizer = new ResizeThread( dsc.shell ) ; resizer.start() ; } - + final KeyfireThread keyfire; { keyfire = new KeyfireThread( robot, dsc.display ) ; keyfire.start() ; } - + { final Thread t = new Thread(new Runnable() { @Override @@ -377,7 +377,7 @@ public class TestNewtCanvasSWTBug628ResizeDeadlockAWT extends UITestCase { t.setDaemon(true); t.start(); } - + try { while( !shallStop && !dsc.display.isDisposed() ) { dsc.display.syncExec( new Runnable() { @@ -394,12 +394,12 @@ public class TestNewtCanvasSWTBug628ResizeDeadlockAWT extends UITestCase { e0.printStackTrace(); Assert.assertTrue("Deadlock @ dispatch: "+e0, false); } - + // canvas is disposed implicit, due to it's disposed listener ! - + dsc.dispose(); } - + public static void main( String[] args ) { for(int i=0; i<args.length; i++) { if(args[i].equals("-time")) { @@ -407,7 +407,7 @@ public class TestNewtCanvasSWTBug628ResizeDeadlockAWT extends UITestCase { } } System.out.println("durationPerTest: "+duration); - org.junit.runner.JUnitCore.main(TestNewtCanvasSWTBug628ResizeDeadlockAWT.class.getName()); + org.junit.runner.JUnitCore.main(TestNewtCanvasSWTBug628ResizeDeadlockAWT.class.getName()); } - + } diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWTBug643AsyncExec.java b/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWTBug643AsyncExec.java index c9b832b8a..8b4e095f3 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWTBug643AsyncExec.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/swt/TestSWTBug643AsyncExec.java @@ -3,14 +3,14 @@ * * 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 @@ -20,7 +20,7 @@ * 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. @@ -37,6 +37,8 @@ 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.Test; import org.junit.FixMethodOrder; @@ -48,7 +50,6 @@ import javax.media.opengl.GLProfile; import jogamp.newt.swt.SWTEDTUtil; import jogamp.newt.swt.event.SWTNewtEventFactory; -import junit.framework.Assert; import com.jogamp.nativewindow.swt.SWTAccessor; import com.jogamp.newt.NewtFactory; @@ -66,12 +67,12 @@ import com.jogamp.opengl.util.Animator; @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class TestSWTBug643AsyncExec extends UITestCase { - + static int duration = 500; static boolean useAnimator = false; - + //////////////////////////////////////////////////////////////////////////////// - + static void resetSWTAndNEWTEDTCounter() { synchronized(swtCountSync) { swtCount=0; @@ -103,43 +104,43 @@ public class TestSWTBug643AsyncExec extends UITestCase { } } static Object swtCountSync = new Object(); - static int swtCount = 0; + static int swtCount = 0; static Object edtCountSync = new Object(); - static int edtCount = 0; - + static int edtCount = 0; + //////////////////////////////////////////////////////////////////////////////// - + static class AsyncExecEDTFeederThread extends Thread { volatile boolean shallStop = false; - private Display swtDisplay ; - private jogamp.newt.DisplayImpl newtDisplay; + private final Display swtDisplay ; + private final jogamp.newt.DisplayImpl newtDisplay; private int swtN, newtN ; - + public AsyncExecEDTFeederThread( Display swtDisplay, com.jogamp.newt.Display newtDisplay ) { super(); this.swtDisplay = swtDisplay ; this.newtDisplay = (jogamp.newt.DisplayImpl)newtDisplay; } - + final Runnable swtAsyncAction = new Runnable() { public void run() { ++swtN ; incrSWTCount(); System.err.println("[SWT A-i shallStop "+shallStop+"]: Counter[loc "+swtN+", glob: "+getSWTCount()+"]"); } }; - + final Runnable newtAsyncAction = new Runnable() { public void run() { ++newtN ; incrNEWTCount(); System.err.println("[NEWT A-i shallStop "+shallStop+"]: Counter[loc "+newtN+", glob: "+getNEWTCount()+"]"); } }; - + public void run() { System.err.println("[A-0 shallStop "+shallStop+"]"); - + while( !shallStop && !swtDisplay.isDisposed() ) { try @@ -151,7 +152,7 @@ public class TestSWTBug643AsyncExec extends UITestCase { // only perform async exec on valid and already running NEWT EDT! newtDisplay.runOnEDTIfAvail(false, newtAsyncAction); } - Thread.sleep( 50L ) ; + Thread.sleep( 50L ) ; } catch( InterruptedException e ) { break ; } @@ -159,34 +160,34 @@ public class TestSWTBug643AsyncExec extends UITestCase { System.err.println("*R-Exit* shallStop "+shallStop); } } - + //////////////////////////////////////////////////////////////////////////////// - + private volatile boolean shallStop = false; - + static class SWT_DSC { Display display; Shell shell; Composite composite; - + public void init() { SWTAccessor.invoke(true, new Runnable() { - public void run() { + public void run() { display = new Display(); Assert.assertNotNull( display ); }}); - + display.syncExec(new Runnable() { - public void run() { + public void run() { shell = new Shell( display ); Assert.assertNotNull( shell ); shell.setLayout( new FillLayout() ); composite = new Composite( shell, SWT.NO_BACKGROUND ); composite.setLayout( new FillLayout() ); Assert.assertNotNull( composite ); - }}); + }}); } - + public void dispose() { Assert.assertNotNull( display ); Assert.assertNotNull( shell ); @@ -208,21 +209,21 @@ public class TestSWTBug643AsyncExec extends UITestCase { } display = null; shell = null; - composite = null; + composite = null; } } - + private void testImpl(boolean useJOGLGLCanvas, boolean useNewtCanvasSWT, boolean glWindowPreVisible) throws InterruptedException, InvocationTargetException { resetSWTAndNEWTEDTCounter(); - + final SWT_DSC dsc = new SWT_DSC(); dsc.init(); - + final com.jogamp.newt.Display newtDisplay; { final GLProfile gl2Profile = GLProfile.get( GLProfile.GL2 ) ; final GLCapabilities caps = new GLCapabilities( gl2Profile ) ; - + final GLAutoDrawable glad; if( useJOGLGLCanvas ) { final GearsES2 demo = new GearsES2(); @@ -230,10 +231,10 @@ public class TestSWTBug643AsyncExec extends UITestCase { final SWTNewtEventFactory swtNewtEventFactory = new SWTNewtEventFactory(); swtNewtEventFactory.attachDispatchListener(glc, glc, demo.gearsMouse, demo.gearsKeys); glc.addGLEventListener( demo ) ; - glad = glc; - newtDisplay = null; + glad = glc; + newtDisplay = null; } else if( useNewtCanvasSWT ) { - newtDisplay = NewtFactory.createDisplay(null, false); // no-reuse + newtDisplay = NewtFactory.createDisplay(null, false); // no-reuse com.jogamp.newt.Screen screen = NewtFactory.createScreen(newtDisplay, 0); final GLWindow glWindow = GLWindow.create( screen, caps ) ; glWindow.addGLEventListener( new GearsES2() ) ; @@ -241,10 +242,10 @@ public class TestSWTBug643AsyncExec extends UITestCase { newtDisplay.setEDTUtil(new SWTEDTUtil(newtDisplay, dsc.display)); // Especially Windows requires creation access via same thread! glWindow.setVisible(true); AWTRobotUtil.waitForRealized(glWindow, true); - Thread.sleep(120); // let it render a bit, before consumed by SWT + Thread.sleep(120); // let it render a bit, before consumed by SWT } glad = glWindow; - NewtCanvasSWT.create( dsc.composite, 0, glWindow ) ; + NewtCanvasSWT.create( dsc.composite, 0, glWindow ) ; } else { throw new InternalError("XXX"); } @@ -253,7 +254,7 @@ public class TestSWTBug643AsyncExec extends UITestCase { animator.start(); } } - + System.err.println("**** Pre Shell Open"); dsc.display.syncExec( new Runnable() { public void run() { @@ -264,15 +265,15 @@ public class TestSWTBug643AsyncExec extends UITestCase { System.err.println("**** Post Shell Open"); shallStop = false; - + final int[] counterBeforeExit = new int[] { 0 /* SWT */, 0 /* NEWT */ }; - + final AsyncExecEDTFeederThread asyncExecFeeder; { asyncExecFeeder = new AsyncExecEDTFeederThread(dsc.display, newtDisplay) ; asyncExecFeeder.start() ; } - + { final Thread t = new Thread(new Runnable() { @Override @@ -280,7 +281,7 @@ public class TestSWTBug643AsyncExec extends UITestCase { try { Thread.sleep(duration); } catch (InterruptedException e) {} - + counterBeforeExit[0] = getSWTCount(); counterBeforeExit[1] = getNEWTCount(); asyncExecFeeder.shallStop = true; @@ -294,9 +295,9 @@ public class TestSWTBug643AsyncExec extends UITestCase { t.setDaemon(true); t.start(); } - + try { - final Display d = dsc.display; + final Display d = dsc.display; while( !shallStop && !d.isDisposed() ) { if( !d.readAndDispatch() && !shallStop ) { // blocks on linux .. dsc.display.sleep(); @@ -307,11 +308,11 @@ public class TestSWTBug643AsyncExec extends UITestCase { e0.printStackTrace(); Assert.assertTrue("Deadlock @ dispatch: "+e0, false); } - + // canvas is disposed implicit, due to it's disposed listener ! - + dsc.dispose(); - + System.err.println("EDT Counter before exit: SWT " + counterBeforeExit[0] + ", NEWT "+counterBeforeExit[1]); Assert.assertTrue("SWT EDT Counter not greater zero before dispose!", 0 < counterBeforeExit[0]); if( null != newtDisplay ) { @@ -323,17 +324,17 @@ public class TestSWTBug643AsyncExec extends UITestCase { public void test01JOGLGLCanvas() throws InterruptedException, InvocationTargetException { testImpl(true /* useJOGLGLCanvas */, false /* useNewtCanvasSWT */, false /* glWindowPreVisible */); } - + @Test public void test02NewtCanvasSWTSimple() throws InterruptedException, InvocationTargetException { testImpl(false /* useJOGLGLCanvas */, true /* useNewtCanvasSWT */, false /* glWindowPreVisible */); } - + @Test public void test02NewtCanvasSWTPreVisible() throws InterruptedException, InvocationTargetException { testImpl(false /* useJOGLGLCanvas */, true /* useNewtCanvasSWT */, true /* glWindowPreVisible */); } - + public static void main( String[] args ) { for(int i=0; i<args.length; i++) { if(args[i].equals("-time")) { @@ -343,7 +344,7 @@ public class TestSWTBug643AsyncExec extends UITestCase { } } System.out.println("durationPerTest: "+duration); - org.junit.runner.JUnitCore.main(TestSWTBug643AsyncExec.class.getName()); + org.junit.runner.JUnitCore.main(TestSWTBug643AsyncExec.class.getName()); } - + } |