summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2013-09-05 12:47:15 +0200
committerSven Gothel <[email protected]>2013-09-05 12:47:15 +0200
commit3f2e0d3a9a6cab80936851c44f61107a2993ddfe (patch)
treec2b0f7203044ea245981777ab40f397174a9ec4d /src
parent7ee9b87bdb025f98651c2685d416029a17fc3937 (diff)
TileRendererBase: Add interface TileRendererNotify, to notify implementing GLEventListener about attached/detached TileRenderer
.. since GLEventListener's reshape(..) method must query certain tile renderer attributes (tile pos and image size), they have to be aware of the TileRendererBase. To simplify such awareness and hence automate this attachement and passing over the tile renderer reference, they should implement this new interface. Gears example implements the new interface, which caches the TR reference and pauses rotation.
Diffstat (limited to 'src')
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/TileRendererBase.java48
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/Gears.java16
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/tile/TestRandomTiledRendering2GL2NEWT.java3
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/tile/TestRandomTiledRendering3GL2AWT.java4
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledRendering1GL2NEWT.java5
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledRendering2GL2NEWT.java3
6 files changed, 53 insertions, 26 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/util/TileRendererBase.java b/src/jogl/classes/com/jogamp/opengl/util/TileRendererBase.java
index b6774b6b7..8a339456a 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/TileRendererBase.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/TileRendererBase.java
@@ -95,6 +95,18 @@ public abstract class TileRendererBase {
*/
public static final int TR_CURRENT_TILE_HEIGHT = 6;
+ /**
+ * Notifies {@link GLEventListener} implementing this interface
+ * that the owning {@link GLAutoDrawable} is {@link TileRendererBase#attachToAutoDrawable(GLAutoDrawable) attached}
+ * to a tile renderer or {@link TileRendererBase#detachFromAutoDrawable() detached} from it.
+ */
+ public static interface TileRendererNotify {
+ /** The owning {@link GLAutoDrawable} is {@link TileRendererBase#attachToAutoDrawable(GLAutoDrawable) attached} to a {@link TileRendererBase}. */
+ public void addTileRendererNotify(TileRendererBase tr);
+ /** The owning {@link GLAutoDrawable} is {@link TileRendererBase#detachFromAutoDrawable() detached} from a {@link TileRendererBase}. */
+ public void removeTileRendererNotify(TileRendererBase tr);
+ }
+
protected final Dimension imageSize = new Dimension(0, 0);
protected final GLPixelStorageModes psm = new GLPixelStorageModes();
protected GLPixelBuffer imageBuffer;
@@ -216,8 +228,13 @@ public abstract class TileRendererBase {
/**
* Attaches this renderer to the {@link GLAutoDrawable}.
* <p>
- * The {@link GLAutoDrawable}'s original {@link GLEventListener} are moved to local storage.
- * This renderer {@link GLEventListener} is then added to handle the tile rendering
+ * The {@link GLAutoDrawable}'s original {@link GLEventListener} are moved to this tile renderer.<br>
+ * It is <i>highly recommended</i> that the original {@link GLEventListener} implement
+ * {@link TileRendererNotify}, so they get {@link TileRendererNotify#addTileRendererNotify(TileRendererBase) notified}
+ * about this event.
+ * </p>
+ * <p>
+ * This tile renderer's {@link GLEventListener} is then added to handle the tile rendering
* for the original {@link GLEventListener}, i.e. it's {@link GLEventListener#display(GLAutoDrawable) display} issues:
* <ul>
* <li>Optional {@link #setGLEventListener(GLEventListener, GLEventListener) pre-glel}.{@link GLEventListener#display(GLAutoDrawable) display(..)}</li>
@@ -232,6 +249,16 @@ public abstract class TileRendererBase {
* </ul>
* </p>
* <p>
+ * The <a href="#pmvmatrix">PMV Matrix</a> shall be reshaped in the
+ * original {@link GLEventListener}'s {@link GLEventListener#reshape(GLAutoDrawable, int, int, int, int) reshape} method
+ * according to the tile-position, -size and image-size<br>
+ * The {@link GLEventListener#reshape(GLAutoDrawable, int, int, int, int) reshape} method is called for each tile
+ * w/ the current viewport of tile-size, where the tile-position and image-size can be retrieved by this tile renderer,
+ * see details in {@link #beginTile(GL2ES3)}.<br>
+ * The original {@link GLEventListener} implementing {@link TileRendererNotify} is aware of this
+ * tile renderer instance.
+ * </p>
+ * <p>
* Consider using {@link #setGLEventListener(GLEventListener, GLEventListener)} to add pre- and post
* hooks to be performed on this renderer {@link GLEventListener}.<br>
* The pre-hook is able to allocate memory and setup parameters, since it's called before {@link #beginTile(GL2ES3)}.<br>
@@ -242,12 +269,6 @@ public abstract class TileRendererBase {
* Call {@link #detachFromAutoDrawable()} to remove this renderer from the {@link GLAutoDrawable}
* and to restore it's original {@link GLEventListener}.
* </p>
- * <p>
- * The <a href="#pmvmatrix">PMV Matrix</a> shall be reshaped in the
- * original {@link GLEventListener}'s {@link GLEventListener#reshape(GLAutoDrawable, int, int, int, int) reshape}
- * method. The latter is called for each tile w/ the current viewport.
- * The tile's position and image size can be utilized. See details in {@link #beginTile(GL2ES3)}.
- * </p>
* @param glad
* @throws IllegalStateException if an {@link GLAutoDrawable} is already attached
*/
@@ -264,6 +285,9 @@ public abstract class TileRendererBase {
final GLEventListener l = glad.getGLEventListener(0);
listenersInit[i] = glad.getGLEventListenerInitState(l);
listeners[i] = glad.removeGLEventListener( l );
+ if( listeners[i] instanceof TileRendererNotify ) {
+ ((TileRendererNotify)listeners[i]).addTileRendererNotify(this);
+ }
}
glad.addGLEventListener(tiledGLEL);
}
@@ -271,6 +295,11 @@ public abstract class TileRendererBase {
/**
* Detaches this renderer from the {@link GLAutoDrawable}.
* <p>
+ * It is <i>highly recommended</i> that the original {@link GLEventListener} implement
+ * {@link TileRendererNotify}, so they get {@link TileRendererNotify#removeTileRendererNotify(TileRendererBase) notified}
+ * about this event.
+ * </p>
+ * <p>
* See {@link #attachToAutoDrawable(GLAutoDrawable)}.
* </p>
*/
@@ -280,6 +309,9 @@ public abstract class TileRendererBase {
final int aSz = listenersInit.length;
for(int i=0; i<aSz; i++) {
final GLEventListener l = listeners[i];
+ if( l instanceof TileRendererNotify ) {
+ ((TileRendererNotify)l).removeTileRendererNotify(this);
+ }
glad.addGLEventListener(l);
glad.setGLEventListenerInitState(l, listenersInit[i]);
}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/Gears.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/Gears.java
index 0c84fac39..22fb72aec 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/Gears.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/Gears.java
@@ -25,8 +25,7 @@ import com.jogamp.opengl.util.TileRendererBase;
*
* This version is equal to Brian Paul's version 1.2 1999/10/21
*/
-
-public class Gears implements GLEventListener {
+public class Gears implements GLEventListener, TileRendererBase.TileRendererNotify {
private float view_rotx = 20.0f, view_roty = 30.0f, view_rotz = 0.0f;
private int gear1=0, gear2=0, gear3=0;
private float angle = 0.0f;
@@ -47,11 +46,18 @@ public class Gears implements GLEventListener {
this.swapInterval = 1;
}
- public void setTileRenderer(TileRendererBase tileRenderer) {
- tileRendererInUse = tileRenderer;
+ private boolean doRotateBeforePrinting;
+ public void addTileRendererNotify(TileRendererBase tr) {
+ tileRendererInUse = tr;
+ doRotateBeforePrinting = doRotate;
+ setDoRotation(false);
+ }
+ public void removeTileRendererNotify(TileRendererBase tr) {
+ tileRendererInUse = null;
+ setDoRotation(doRotateBeforePrinting);
}
- public void setDoRotation(boolean rotate) { this.doRotate = rotate; }
+ public void setDoRotation(boolean rotate) { doRotate = rotate; }
public void setGears(int g1, int g2, int g3) {
gear1 = g1;
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestRandomTiledRendering2GL2NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestRandomTiledRendering2GL2NEWT.java
index 866a8a753..ca9bf9a9c 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestRandomTiledRendering2GL2NEWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestRandomTiledRendering2GL2NEWT.java
@@ -85,7 +85,6 @@ public class TestRandomTiledRendering2GL2NEWT extends UITestCase {
final GLOffscreenAutoDrawable glad = factory.createOffscreenAutoDrawable(null, caps, null, 256, 256, null);
final Gears gears = new Gears();
- gears.setDoRotation(false);
glad.addGLEventListener( gears );
// Fix the image size for now
@@ -97,7 +96,6 @@ public class TestRandomTiledRendering2GL2NEWT extends UITestCase {
// Initialize the tile rendering library
final RandomTileRenderer renderer = new RandomTileRenderer();
- gears.setTileRenderer(renderer);
renderer.attachToAutoDrawable(glad);
renderer.setImageSize(imageWidth, imageHeight);
@@ -138,7 +136,6 @@ public class TestRandomTiledRendering2GL2NEWT extends UITestCase {
}
renderer.detachFromAutoDrawable();
- gears.setTileRenderer(null);
// Restore viewport and Gear's PMV matrix
// .. even though we close the demo, this is for documentation!
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestRandomTiledRendering3GL2AWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestRandomTiledRendering3GL2AWT.java
index 28ff19bad..2b7e727b8 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestRandomTiledRendering3GL2AWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestRandomTiledRendering3GL2AWT.java
@@ -129,7 +129,6 @@ public class TestRandomTiledRendering3GL2AWT extends UITestCase {
@Override
public void init(GLAutoDrawable drawable) {
- gears.setDoRotation(false);
final GL gl = drawable.getGL();
GLPixelAttributes pixelAttribs = pixelBufferProvider.getAttributes(gl, 3);
GLPixelBuffer pixelBuffer = pixelBufferProvider.allocate(gl, pixelAttribs, imageWidth, imageHeight, 1, true, 0);
@@ -189,12 +188,10 @@ public class TestRandomTiledRendering3GL2AWT extends UITestCase {
} catch (IOException e) {
e.printStackTrace();
}
- gears.setTileRenderer(null);
renderer.detachFromAutoDrawable();
System.err.println("XXX post-display detached: "+renderer);
drawable.getGL().glViewport(0, 0, drawable.getWidth(), drawable.getHeight());
glad.getGLEventListener(0).reshape(drawable, 0, 0, drawable.getWidth(), drawable.getHeight());
- gears.setDoRotation(true);
}
}
@Override
@@ -219,7 +216,6 @@ public class TestRandomTiledRendering3GL2AWT extends UITestCase {
signalTileRenderer = false;
// tile rendering !
System.err.println("XXX START TILE RENDERING");
- gears.setTileRenderer(renderer);
renderer.attachToAutoDrawable(glad);
}
Thread.sleep(100);
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledRendering1GL2NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledRendering1GL2NEWT.java
index c80a0cadd..62bdf6d64 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledRendering1GL2NEWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledRendering1GL2NEWT.java
@@ -131,17 +131,16 @@ public class TestTiledRendering1GL2NEWT extends UITestCase {
flipVertically[0] = false;
final Gears gears = new Gears();
- gears.setDoRotation(false);
gears.init(gl);
- gears.setTileRenderer(renderer);
+ gears.addTileRendererNotify(renderer);
do {
renderer.beginTile(dc.glc.getGL().getGL2ES3());
gears.reshape(gl, 0, 0, renderer.getParam(TileRendererBase.TR_CURRENT_TILE_WIDTH), renderer.getParam(TileRendererBase.TR_CURRENT_TILE_HEIGHT));
gears.display(gl);
renderer.endTile(dc.glc.getGL().getGL2ES3());
} while ( !renderer.eot() );
- gears.setTileRenderer(null);
+ gears.removeTileRendererNotify(renderer);
destroyDrawableContext(dc);
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledRendering2GL2NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledRendering2GL2NEWT.java
index 72917bc7f..fb26eeb24 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledRendering2GL2NEWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledRendering2GL2NEWT.java
@@ -85,7 +85,6 @@ public class TestTiledRendering2GL2NEWT extends UITestCase {
final GLOffscreenAutoDrawable glad = factory.createOffscreenAutoDrawable(null, caps, null, 256, 256, null);
final Gears gears = new Gears();
- gears.setDoRotation(false);
glad.addGLEventListener( gears );
// Fix the image size for now
@@ -97,7 +96,6 @@ public class TestTiledRendering2GL2NEWT extends UITestCase {
// Initialize the tile rendering library
final TileRenderer renderer = new TileRenderer();
- gears.setTileRenderer(renderer);
renderer.attachToAutoDrawable(glad);
renderer.setImageSize(imageWidth, imageHeight);
@@ -131,7 +129,6 @@ public class TestTiledRendering2GL2NEWT extends UITestCase {
} while ( !renderer.eot() );
renderer.detachFromAutoDrawable();
- gears.setTileRenderer(null);
// Restore viewport and Gear's PMV matrix
// .. even though we close the demo, this is for documentation!