summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2011-09-03 03:13:45 +0200
committerSven Gothel <[email protected]>2011-09-03 03:13:45 +0200
commitbbdd6f95687da343bf7a6550c3bc9bb4444116e5 (patch)
tree027da6de1a88bc143b1d2f4edb4cadcf68d8546f
parent9955e053ac28d1dc1f6722893d7989d5e2b710c3 (diff)
Complete translucency support (core w/ X11 (only) - tested w/ NEWT)
DefaultGLCapabilitiesChooser: - Add penalty for opaque mismatch: dbl-buf > opaq > stencil GLGraphicsConfigurationFactory: - Case no-chooser && has-recommended-idx: - Only use recommended index if caps is opaque, otherwise use default chooser to validate translucency NativeWindow Capabilities: - transparent default values -> 0 Added NEWT Test: TestTranslucencyNEWT Added command line translucency/undecorated options for TestGearsES2NEWT
-rwxr-xr-xmake/scripts/tests.sh5
-rw-r--r--src/jogl/classes/javax/media/opengl/DefaultGLCapabilitiesChooser.java19
-rw-r--r--src/jogl/classes/jogamp/opengl/GLGraphicsConfigurationFactory.java4
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/Capabilities.java8
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/caps/TestTranslucencyNEWT.java151
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/newt/TestGearsES2NEWT.java15
6 files changed, 183 insertions, 19 deletions
diff --git a/make/scripts/tests.sh b/make/scripts/tests.sh
index b155a12f8..da16be48b 100755
--- a/make/scripts/tests.sh
+++ b/make/scripts/tests.sh
@@ -67,6 +67,7 @@ function jrun() {
#D_ARGS="-Djogl.debug.Animator -Dnewt.debug=all"
#D_ARGS="-Dnewt.debug.EDT -Dnewt.debug.Display -Dnativewindow.debug.X11Util -Djogl.debug.GLDrawable -Djogl.debug.GLCanvas"
#D_ARGS="-Djogl.debug.GLContext -Dnewt.debug=all"
+ D_ARGS="-Djogl.debug.GraphicsConfiguration -Djogl.debug.CapabilitiesChooser -Dnewt.debug=all"
#D_ARGS="-Dnewt.debug.Screen -Dnewt.debug.EDT -Djogamp.debug.Lock"
#D_ARGS="-Dnewt.debug.EDT"
#D_ARGS="-Djogl.debug=all -Dnativewindow.debug=all -Dnewt.debug=all"
@@ -147,7 +148,7 @@ function testawtmt() {
#testawt com.jogamp.opengl.test.junit.jogl.demos.gl2.newt.TestGearsNEWT $*
#testnoawt com.jogamp.opengl.test.junit.jogl.demos.gl2.newt.TestGearsNEWT $*
#testnoawt com.jogamp.opengl.test.junit.jogl.demos.es1.newt.TestGearsES1NEWT $*
-#testnoawt com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestGearsES2NEWT $*
+testnoawt com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestGearsES2NEWT $*
#testnoawt com.jogamp.opengl.test.junit.newt.TestGLWindows02NEWTAnimated $*
#testawt com.jogamp.opengl.test.junit.newt.TestDisplayLifecycle01NEWT
#testawt com.jogamp.opengl.test.junit.newt.TestDisplayLifecycle02NEWT
@@ -232,7 +233,7 @@ function testawtmt() {
#testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestGPUMemSec01NEWT $*
#testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestMapBuffer01NEWT $*
-testnoawt com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestElektronenMultipliziererNEWT $*
+#testnoawt com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestElektronenMultipliziererNEWT $*
$spath/count-edt-start.sh java-run.log
diff --git a/src/jogl/classes/javax/media/opengl/DefaultGLCapabilitiesChooser.java b/src/jogl/classes/javax/media/opengl/DefaultGLCapabilitiesChooser.java
index 52628f6fa..be509c332 100644
--- a/src/jogl/classes/javax/media/opengl/DefaultGLCapabilitiesChooser.java
+++ b/src/jogl/classes/javax/media/opengl/DefaultGLCapabilitiesChooser.java
@@ -120,16 +120,18 @@ public class DefaultGLCapabilitiesChooser implements GLCapabilitiesChooser {
// Create score array
int[] scores = new int[availnum];
- int NO_SCORE = -9999999;
- int DOUBLE_BUFFER_MISMATCH_PENALTY = 1000;
- int STENCIL_MISMATCH_PENALTY = 500;
+ final int NO_SCORE = -9999999;
+ final int DOUBLE_BUFFER_MISMATCH_PENALTY = 1000;
+ final int OPAQUE_MISMATCH_PENALTY = 750;
+ final int STENCIL_MISMATCH_PENALTY = 500;
// Pseudo attempt to keep equal rank penalties scale-equivalent
// (e.g., stencil mismatch is 3 * accum because there are 3 accum
// components)
- int COLOR_MISMATCH_PENALTY_SCALE = 36;
- int DEPTH_MISMATCH_PENALTY_SCALE = 6;
- int ACCUM_MISMATCH_PENALTY_SCALE = 1;
- int STENCIL_MISMATCH_PENALTY_SCALE = 3;
+ final int COLOR_MISMATCH_PENALTY_SCALE = 36;
+ final int DEPTH_MISMATCH_PENALTY_SCALE = 6;
+ final int ACCUM_MISMATCH_PENALTY_SCALE = 1;
+ final int STENCIL_MISMATCH_PENALTY_SCALE = 3;
+
for (int i = 0; i < scores.length; i++) {
scores[i] = NO_SCORE;
}
@@ -166,6 +168,9 @@ public class DefaultGLCapabilitiesChooser implements GLCapabilitiesChooser {
if (cur.getDoubleBuffered() != gldes.getDoubleBuffered()) {
score += sign(score) * DOUBLE_BUFFER_MISMATCH_PENALTY;
}
+ if (cur.isBackgroundOpaque() != gldes.isBackgroundOpaque()) {
+ score += sign(score) * OPAQUE_MISMATCH_PENALTY;
+ }
if ((gldes.getStencilBits() > 0) && (cur.getStencilBits() == 0)) {
score += sign(score) * STENCIL_MISMATCH_PENALTY;
}
diff --git a/src/jogl/classes/jogamp/opengl/GLGraphicsConfigurationFactory.java b/src/jogl/classes/jogamp/opengl/GLGraphicsConfigurationFactory.java
index e51e997a3..6fe9f080c 100644
--- a/src/jogl/classes/jogamp/opengl/GLGraphicsConfigurationFactory.java
+++ b/src/jogl/classes/jogamp/opengl/GLGraphicsConfigurationFactory.java
@@ -49,9 +49,9 @@ public abstract class GLGraphicsConfigurationFactory extends GraphicsConfigurati
return -1; // none available
}
- if(null == chooser && 0 <= recommendedIndex) {
+ if(null == chooser && 0 <= recommendedIndex && capsRequested.isBackgroundOpaque()) {
if (DEBUG) {
- System.err.println("chooseCapabilities: Using recommendedIndex: idx " + recommendedIndex);
+ System.err.println("chooseCapabilities: Using recommendedIndex (opaque): idx " + recommendedIndex);
}
return recommendedIndex;
}
diff --git a/src/nativewindow/classes/javax/media/nativewindow/Capabilities.java b/src/nativewindow/classes/javax/media/nativewindow/Capabilities.java
index 79d69c703..b162392da 100644
--- a/src/nativewindow/classes/javax/media/nativewindow/Capabilities.java
+++ b/src/nativewindow/classes/javax/media/nativewindow/Capabilities.java
@@ -52,10 +52,10 @@ public class Capabilities implements CapabilitiesImmutable, Cloneable, Comparabl
// Support for transparent windows containing OpenGL content
private boolean backgroundOpaque = true;
- private int transparentValueRed = -1;
- private int transparentValueGreen = -1;
- private int transparentValueBlue = -1;
- private int transparentValueAlpha = -1;
+ private int transparentValueRed = 0;
+ private int transparentValueGreen = 0;
+ private int transparentValueBlue = 0;
+ private int transparentValueAlpha = 0;
// Switch for on- or offscreen
private boolean onscreen = true;
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/caps/TestTranslucencyNEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/caps/TestTranslucencyNEWT.java
new file mode 100644
index 000000000..ebadb7a84
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/caps/TestTranslucencyNEWT.java
@@ -0,0 +1,151 @@
+/**
+ * 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.caps;
+
+import com.jogamp.newt.event.KeyAdapter;
+import com.jogamp.newt.event.KeyEvent;
+import com.jogamp.newt.opengl.GLWindow;
+import com.jogamp.opengl.test.junit.util.UITestCase;
+import com.jogamp.opengl.test.junit.util.QuitAdapter;
+
+import com.jogamp.opengl.util.Animator;
+
+import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
+
+import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.GLProfile;
+
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.AfterClass;
+import org.junit.Test;
+
+public class TestTranslucencyNEWT extends UITestCase {
+ static GLProfile glp;
+ static int width, height;
+
+ @BeforeClass
+ public static void initClass() {
+ GLProfile.initSingleton(true);
+ /*if(GLProfile.isAvailable(GLProfile.getDefaultEGLDevice(), GLProfile.GLES2)) {
+ // exact match
+ glp = GLProfile.get(GLProfile.getDefaultEGLDevice(), GLProfile.GLES2);
+ } else */ {
+ // default device, somehow ES2 compatible
+ glp = GLProfile.getGL2ES2();
+ }
+ Assert.assertNotNull(glp);
+ width = 512;
+ height = 512;
+ }
+
+ @AfterClass
+ public static void releaseClass() {
+ }
+
+ protected void runTestGL(GLCapabilities caps, boolean undecorated) throws InterruptedException {
+ GLWindow glWindow = GLWindow.create(caps);
+ Assert.assertNotNull(glWindow);
+ glWindow.setTitle("Gears NEWT Test (translucent "+!caps.isBackgroundOpaque()+")");
+ glWindow.setUndecorated(undecorated);
+ glWindow.addGLEventListener(new GearsES2());
+
+ Animator animator = new Animator(glWindow);
+ QuitAdapter quitAdapter = new QuitAdapter();
+
+ //glWindow.addKeyListener(new TraceKeyAdapter(quitAdapter));
+ //glWindow.addWindowListener(new TraceWindowAdapter(quitAdapter));
+ glWindow.addKeyListener(quitAdapter);
+ glWindow.addWindowListener(quitAdapter);
+
+ final GLWindow f_glWindow = glWindow;
+ glWindow.addKeyListener(new KeyAdapter() {
+ public void keyTyped(KeyEvent e) {
+ if(e.getKeyChar()=='f') {
+ new Thread() {
+ public void run() {
+ f_glWindow.setFullscreen(!f_glWindow.isFullscreen());
+ } }.start();
+ } else if(e.getKeyChar()=='d') {
+ new Thread() {
+ public void run() {
+ f_glWindow.setUndecorated(!f_glWindow.isUndecorated());
+ } }.start();
+ }
+ }
+ });
+
+ glWindow.setSize(width, height);
+ glWindow.setVisible(true);
+ animator.setUpdateFPSFrames(1, null);
+ animator.start();
+
+ while(!quitAdapter.shouldQuit() && animator.isAnimating() && animator.getTotalFPSDuration()<duration) {
+ Thread.sleep(100);
+ }
+
+ animator.stop();
+ glWindow.destroy();
+ }
+
+ @Test
+ public void test01OpaqueDecorated() throws InterruptedException {
+ GLCapabilities caps = new GLCapabilities(glp);
+ caps.setBackgroundOpaque(true); // default
+ runTestGL(caps, false);
+ }
+
+ @Test
+ public void test01TransparentDecorated() throws InterruptedException {
+ GLCapabilities caps = new GLCapabilities(glp);
+ caps.setBackgroundOpaque(false);
+ runTestGL(caps, false);
+ }
+
+ @Test
+ public void test01TransparentUndecorated() throws InterruptedException {
+ GLCapabilities caps = new GLCapabilities(glp);
+ caps.setBackgroundOpaque(false);
+ runTestGL(caps, true);
+ }
+
+ 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(TestTranslucencyNEWT.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 3bf7490d2..c8c92ea48 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
@@ -69,11 +69,11 @@ public class TestGearsES2NEWT extends UITestCase {
public static void releaseClass() {
}
- protected void runTestGL(GLCapabilities caps) throws InterruptedException {
+ protected void runTestGL(GLCapabilities caps, boolean undecorated) throws InterruptedException {
GLWindow glWindow = GLWindow.create(caps);
Assert.assertNotNull(glWindow);
- glWindow.setTitle("Gears NEWT Test");
-
+ glWindow.setTitle("Gears NEWT Test (translucent "+!caps.isBackgroundOpaque()+")");
+ glWindow.setUndecorated(undecorated);
glWindow.addGLEventListener(new GearsES2());
Animator animator = new Animator(glWindow);
@@ -117,10 +117,13 @@ public class TestGearsES2NEWT extends UITestCase {
@Test
public void test01() throws InterruptedException {
GLCapabilities caps = new GLCapabilities(glp);
- runTestGL(caps);
+ caps.setBackgroundOpaque(opaque);
+ runTestGL(caps, undecorated);
}
static long duration = 500; // ms
+ static boolean opaque = true;
+ static boolean undecorated = false;
public static void main(String args[]) {
for(int i=0; i<args.length; i++) {
@@ -129,6 +132,10 @@ public class TestGearsES2NEWT extends UITestCase {
try {
duration = Integer.parseInt(args[i]);
} catch (Exception ex) { ex.printStackTrace(); }
+ } else if(args[i].equals("-translucent")) {
+ opaque = false;
+ } else if(args[i].equals("-undecorated")) {
+ undecorated = true;
}
}
org.junit.runner.JUnitCore.main(TestGearsES2NEWT.class.getName());