summaryrefslogtreecommitdiffstats
path: root/src/test/com/jogamp
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2012-11-04 07:09:39 +0100
committerSven Gothel <[email protected]>2012-11-04 07:09:39 +0100
commitc002e04f848116922a1ed7bd96ead54961649bbd (patch)
tree37d51d971aceabb3f1afe8ce3cd7164a0096842b /src/test/com/jogamp
parent808c8da0729b845d010d3f5e0babf1fc6129c3e9 (diff)
GLAutoDrawable: Fix GLEventListener lifecycle and expose more user control (API Change) ; Added GLDrawableUtil
A GLEventListener resides in two states, initialized and uninitialized. When added to a GLAutoDrawable, it is uninitialized. A first 'display()' will issue GLEventListener's 'init(..)' which renders it initialized. This is usually accompanied by 'reshape(..)' propagating the drawable's dimension. Destruction of the GLAutoDrawable will issue GLEventListener's 'dispose(..)' which renders it uninitialized. It turns our these means of GLEventListener controls are not sufficient in case the user requires to remove and add them during the lifecycle and rendering of their GLAutoDrawable host. GLAutoDrawable 'removeGLEventListener(..)' merely removes the GLEventListener from the list, but does not complete it's lifecycle, i.e. issues 'dispose(..)' if initialized to realease GL related resources. Hence the following essential API changes are made to complete the lifecycle: + public GLEventListener disposeGLEventListener(GLEventListener listener, boolean remove); disposing a single GLEventListener, allowing it's removal from the list being optional This is demonstrated via GLDrawableUtil.swapGLContextAndAllGLEventListener(GLAutoDrawable a, GLAutoDrawable b), see below. ++++++++ Further more the following API changes were made to expose complete control of GLEventListener to the user: - public void removeGLEventListener(GLEventListener listener); + public GLEventListener removeGLEventListener(GLEventListener listener); The return value allows simple pipelining, and also delivers information whether the passed listener was actually removed. - public GLEventListener removeGLEventListener(int index) throws IndexOutOfBoundsException; + public int getGLEventListenerCount(); + public GLEventListener getGLEventListener(int index) throws IndexOutOfBoundsException; Dropping the redundant removal by index, while adding count and get methods. + public boolean getGLEventListenerInitState(GLEventListener listener); + public void setGLEventListenerInitState(GLEventListener listener, boolean initialized); Allows retrieving and setting of listener states. All in all these API changes allows a user to experience all freedoms in dealing w/ GLEventListeners hosted by GLAutoDrawable impl. and shall be future proof. Note that we have avoided the Iterator pattern due to it's overhead of temporal objects creation. The simple indexed access allows us to implement each method as an atomic operation. +++++++++++ Further more a simple enqueue(..) method has been added, allowing to just enqueue a GLRunnable w/o provoking it's execution - as invoke(..) does. This method pleases a use case where GLRunnables are batched and shall be executed later on.. public boolean invoke(boolean wait, GLRunnable glRunnable); + public void enqueue(GLRunnable glRunnable); +++++++++++ Added GLDrawableUtil, exposes utility function to rearrange GLEventListener, modifiy GLAutoDrawable, etc. GLDrawableUtil.swapGLContextAndAllGLEventListener(GLAutoDrawable a, GLAutoDrawable b) is tested and demonstrated w/ TestGLContextDrawableSwitchNEWT. Manually tested on X11, OSX and Windows.
Diffstat (limited to 'src/test/com/jogamp')
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLContextDrawableSwitchNEWT.java64
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java11
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/RedSquareES2.java11
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/TextureSequenceCubeES2.java1
4 files changed, 17 insertions, 70 deletions
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLContextDrawableSwitchNEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLContextDrawableSwitchNEWT.java
index 496be3d93..8d4b8f700 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLContextDrawableSwitchNEWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLContextDrawableSwitchNEWT.java
@@ -43,11 +43,11 @@ import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLContext;
import javax.media.opengl.GLDrawable;
import javax.media.opengl.GLDrawableFactory;
-import javax.media.opengl.GLEventListener;
import javax.media.opengl.GLProfile;
import com.jogamp.opengl.GLAutoDrawableDelegate;
import com.jogamp.opengl.util.Animator;
+import com.jogamp.opengl.util.GLDrawableUtil;
import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
import com.jogamp.opengl.test.junit.jogl.demos.es2.RedSquareES2;
@@ -157,28 +157,11 @@ public class TestGLContextDrawableSwitchNEWT extends UITestCase {
if( ( t1 - t0 ) / period > s) {
s++;
System.err.println(s+" - switch - START "+ ( t1 - t0 ));
- animator.pause();
// switch context _and_ the demo synchronously
- if(0 == s%2) {
- final GLEventListener demo = glad2.removeGLEventListener(0);
- GLContext ctx1 = glad1.setContext(glad2.getContext());
- glad2.setContext(ctx1);
- glad1.addGLEventListener(0, demo);
- } else {
- final GLEventListener demo = glad1.removeGLEventListener(0);
- GLContext ctx2 = glad2.setContext(glad1.getContext());
- glad1.setContext(ctx2);
- glad2.addGLEventListener(0, demo);
- }
- System.err.println(s+" - switch - display-1");
- glad1.display();
- System.err.println(s+" - switch - display-2");
- glad2.display();
+ GLDrawableUtil.swapGLContextAndAllGLEventListener(glad1, glad2);
- System.err.println(s+" - switch - END "+ ( t1 - t0 ));
-
- animator.resume();
+ System.err.println(s+" - switch - END "+ ( t1 - t0 ));
}
Thread.sleep(100);
t1 = System.currentTimeMillis();
@@ -223,24 +206,15 @@ public class TestGLContextDrawableSwitchNEWT extends UITestCase {
if( ( t1 - t0 ) / period > s) {
s++;
System.err.println(s+" - switch - START "+ ( t1 - t0 ));
- animator.pause();
+ System.err.println(s+" - A w1-h 0x"+Long.toHexString(glWindow1.getHandle())+",-ctx 0x"+Long.toHexString(glWindow1.getContext().getHandle()));
+ System.err.println(s+" - A w2-h 0x"+Long.toHexString(glWindow2.getHandle())+",-ctx 0x"+Long.toHexString(glWindow2.getContext().getHandle()));
// switch context _and_ the demo synchronously
- if(0 == s%2) {
- final GLEventListener demo = glWindow2.removeGLEventListener(0);
- GLContext ctx1 = glWindow1.setContext(glWindow2.getContext());
- glWindow1.addGLEventListener(0, demo);
- glWindow2.setContext(ctx1);
- } else {
- final GLEventListener demo = glWindow1.removeGLEventListener(0);
- GLContext ctx2 = glWindow2.setContext(glWindow1.getContext());
- glWindow2.addGLEventListener(0, demo);
- glWindow1.setContext(ctx2);
- }
+ GLDrawableUtil.swapGLContextAndAllGLEventListener(glWindow1, glWindow2);
+ System.err.println(s+" - B w1-h 0x"+Long.toHexString(glWindow1.getHandle())+",-ctx 0x"+Long.toHexString(glWindow1.getContext().getHandle()));
+ System.err.println(s+" - B w2-h 0x"+Long.toHexString(glWindow2.getHandle())+",-ctx 0x"+Long.toHexString(glWindow2.getContext().getHandle()));
System.err.println(s+" - switch - END "+ ( t1 - t0 ));
-
- animator.resume();
}
Thread.sleep(100);
t1 = System.currentTimeMillis();
@@ -288,27 +262,23 @@ public class TestGLContextDrawableSwitchNEWT extends UITestCase {
if( ( t1 - t0 ) / period > s) {
s++;
System.err.println(s+" - switch - START "+ ( t1 - t0 ));
- animator.pause();
-
- GLEventListener demo1 = glWindow1.removeGLEventListener(0);
- GLEventListener demo2 = glWindow2.removeGLEventListener(0);
-
- GLContext ctx1 = glWindow1.setContext(glWindow2.getContext());
- glWindow1.addGLEventListener(0, demo2);
-
- glWindow2.setContext(ctx1);
- glWindow2.addGLEventListener(0, demo1);
-
+ System.err.println(s+" - A w1-h 0x"+Long.toHexString(glWindow1.getHandle())+",-ctx 0x"+Long.toHexString(glWindow1.getContext().getHandle()));
+ System.err.println(s+" - A w2-h 0x"+Long.toHexString(glWindow2.getHandle())+",-ctx 0x"+Long.toHexString(glWindow2.getContext().getHandle()));
+ GLDrawableUtil.swapGLContextAndAllGLEventListener(glWindow1, glWindow2);
+ System.err.println(s+" - B w1-h 0x"+Long.toHexString(glWindow1.getHandle())+",-ctx 0x"+Long.toHexString(glWindow1.getContext().getHandle()));
+ System.err.println(s+" - B w2-h 0x"+Long.toHexString(glWindow2.getHandle())+",-ctx 0x"+Long.toHexString(glWindow2.getContext().getHandle()));
System.err.println(s+" - switch - END "+ ( t1 - t0 ));
-
- animator.resume();
}
Thread.sleep(100);
t1 = System.currentTimeMillis();
}
animator.stop();
+ System.err.println("pre -del-w1: w1: "+glWindow1);
+ System.err.println("pre -del-w1: w2: "+glWindow2);
glWindow1.destroy();
+ System.err.println("post-del-w1: w1: "+glWindow1);
+ System.err.println("post-del-w1: w2: "+glWindow2);
glWindow2.destroy();
}
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 e703b6fd9..e9fe9b401 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
@@ -65,7 +65,6 @@ public class GearsES2 implements GLEventListener {
private int prevMouseX, prevMouseY;
private boolean doRotate = true;
- private boolean isInitialized = false;
boolean ignoreFocus = false;
public GearsES2(int swapInterval) {
@@ -106,11 +105,6 @@ public class GearsES2 implements GLEventListener {
public void init(GLAutoDrawable drawable) {
- if(isInitialized) {
- System.err.println(Thread.currentThread()+" GearsES2.init skipped!");
- return;
- }
- isInitialized = true;
System.err.println(Thread.currentThread()+" GearsES2.init ...");
GL2ES2 gl = drawable.getGL().getGL2ES2();
@@ -228,11 +222,6 @@ public class GearsES2 implements GLEventListener {
// private boolean useAndroidDebug = false;
public void dispose(GLAutoDrawable drawable) {
- if(!isInitialized) {
- System.err.println(Thread.currentThread()+" GearsES2.dispose skipped!");
- return;
- }
- isInitialized = false;
System.err.println(Thread.currentThread()+" GearsES2.dispose ... ");
final Object upstreamWidget = drawable.getUpstreamWidget();
if (upstreamWidget instanceof Window) {
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/RedSquareES2.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/RedSquareES2.java
index bf1ca5c2d..e4a457954 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/RedSquareES2.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/RedSquareES2.java
@@ -50,7 +50,6 @@ public class RedSquareES2 implements GLEventListener {
Window window = null;
float aspect = 1.0f;
boolean doRotate = true;
- boolean isInitialized = false;
public RedSquareES2(int swapInterval) {
this.swapInterval = swapInterval;
@@ -64,11 +63,6 @@ public class RedSquareES2 implements GLEventListener {
public void setDoRotation(boolean rotate) { this.doRotate = rotate; }
public void init(GLAutoDrawable glad) {
- if(isInitialized) {
- System.err.println(Thread.currentThread()+" RedSquareES2.init skipped!");
- return;
- }
- isInitialized = true;
System.err.println(Thread.currentThread()+" RedSquareES2.init ...");
GL2ES2 gl = glad.getGL().getGL2ES2();
@@ -184,11 +178,6 @@ public class RedSquareES2 implements GLEventListener {
}
public void dispose(GLAutoDrawable glad) {
- if(!isInitialized) {
- System.err.println(Thread.currentThread()+" RedSquareES2.dispose skipped!");
- return;
- }
- isInitialized = false;
System.err.println(Thread.currentThread()+" RedSquareES2.dispose ... ");
GL2ES2 gl = glad.getGL().getGL2ES2();
st.destroy(gl);
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/TextureSequenceCubeES2.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/TextureSequenceCubeES2.java
index 9217e2b53..25f8740d4 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/TextureSequenceCubeES2.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/TextureSequenceCubeES2.java
@@ -75,7 +75,6 @@ public class TextureSequenceCubeES2 implements GLEventListener {
private float view_rotx = 0.0f, view_roty = 0.0f, view_rotz = 0.0f;
int[] vboNames = new int[4];
boolean innerCube;
- boolean initialized = false;
private ByteBuffer cubeIndices;
private final MouseListener mouseAction = new MouseAdapter() {