From 4ef53cf2ae509a625795bfa3a8982ce75e24e83a Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Fri, 27 Sep 2013 07:13:24 +0200 Subject: TileRenderer*: TileRendererNotify -> TileRendererListener w/ clarifying functionality (reshapeTile(..), ..); Only process GLEventListener impl. TileRendererListener; attachToAutoDrawable -> attachAutoDrawable, etc. -TileRendererNotify -> TileRendererListener - Added methods: - void reshapeTile(TileRendererBase tr,int tileX, int tileY, int tileWidth, int tileHeight, int imageWidth, int imageHeight); - void startTileRendering(TileRendererBase tr); - void endTileRendering(TileRendererBase tr); allowing to clarify user code and API specification, i.e. TR only processes GLEventListener which impl. TileRendererListener. This also allows simplifying the API doc, while having a more descriptive reshape method focusing solely on tile rendering. Further more, the start/end TR methods allow certain GL related actions while the context is current before and after iterating through the tiles. This is even used for RandomTileRenderer (one tile only), to allow to reuse same TileRendererListener for diff TRs. - Fix language, attach and detach usage was vice versa. We do attach an GLAutoDrawable to a TR - attachToAutoDrawable -> attachAutoDrawable - detachFromAutoDrawable -> detachAutoDrawable - Adapted unit tests. --- .../com/jogamp/opengl/util/RandomTileRenderer.java | 2 +- .../com/jogamp/opengl/util/TileRenderer.java | 4 +- .../com/jogamp/opengl/util/TileRendererBase.java | 221 +++++++++++++++------ 3 files changed, 165 insertions(+), 62 deletions(-) (limited to 'src/jogl/classes/com') diff --git a/src/jogl/classes/com/jogamp/opengl/util/RandomTileRenderer.java b/src/jogl/classes/com/jogamp/opengl/util/RandomTileRenderer.java index 03b782ff8..dcf229716 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/RandomTileRenderer.java +++ b/src/jogl/classes/com/jogamp/opengl/util/RandomTileRenderer.java @@ -201,7 +201,7 @@ public class RandomTileRenderer extends TileRendererBase { /** * Rendering one tile, by simply calling {@link GLAutoDrawable#display()}. * - * @throws IllegalStateException if no {@link GLAutoDrawable} is {@link #attachToAutoDrawable(GLAutoDrawable) attached} + * @throws IllegalStateException if no {@link GLAutoDrawable} is {@link #attachAutoDrawable(GLAutoDrawable) attached} * or imageSize is not set */ public void display(int tX, int tY, int tWidth, int tHeight) throws IllegalStateException { diff --git a/src/jogl/classes/com/jogamp/opengl/util/TileRenderer.java b/src/jogl/classes/com/jogamp/opengl/util/TileRenderer.java index 266909470..7c57627e9 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/TileRenderer.java +++ b/src/jogl/classes/com/jogamp/opengl/util/TileRenderer.java @@ -137,7 +137,7 @@ public class TileRenderer extends TileRendererBase { private int rowOrder = TR_BOTTOM_TO_TOP; private int rows; private int columns; - private int currentTile = -1; + private int currentTile = -1; private int currentRow; private int currentColumn; private int offsetX; @@ -269,6 +269,8 @@ public class TileRenderer extends TileRendererBase { assert rows >= 0; } + /* pp */ final int getCurrentTile() { return currentTile; } + /** * Returns true if all tiles have been rendered or {@link #setup()} * has not been called, otherwise false. diff --git a/src/jogl/classes/com/jogamp/opengl/util/TileRendererBase.java b/src/jogl/classes/com/jogamp/opengl/util/TileRendererBase.java index 74e1df316..5b3644f59 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/TileRendererBase.java +++ b/src/jogl/classes/com/jogamp/opengl/util/TileRendererBase.java @@ -67,9 +67,9 @@ import jogamp.opengl.Debug; * after calling {@link #beginTile(GL)}, See {@link #beginTile(GL)}. *

*

- * If {@link #attachToAutoDrawable(GLAutoDrawable) attaching to} an {@link GLAutoDrawable}, - * the {@link GLEventListener#reshape(GLAutoDrawable, int, int, int, int)} method - * is being called after {@link #beginTile(GL)}. + * If {@link #attachAutoDrawable(GLAutoDrawable) attaching to} an {@link GLAutoDrawable}, + * the {@link TileRendererListener#reshapeTile(TileRendererBase, int, int, int, int, int, int)} method + * is being called after {@link #beginTile(GL)} for each rendered tile. * It's implementation shall reshape the PMV matrix according to {@link #beginTile(GL)}. *

*
GL Profile Requirement
@@ -118,15 +118,97 @@ public abstract class TileRendererBase { /* pp */ static final boolean DEBUG = Debug.debug("TileRenderer"); /** - * 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. + * Listener for tile renderer events, intended to extend {@link GLEventListener} implementations, + * enabling tile rendering via {@link TileRendererBase#attachAutoDrawable(GLAutoDrawable)}. */ - public static interface TileRendererNotify { - /** The owning {@link GLAutoDrawable} is {@link TileRendererBase#attachToAutoDrawable(GLAutoDrawable) attached} to a {@link TileRendererBase}. */ + public static interface TileRendererListener { + /** + * The owning {@link GLAutoDrawable} is {@link TileRendererBase#attachAutoDrawable(GLAutoDrawable) attached} + * to the given {@link TileRendererBase} instance. + *

+ * The {@link GLContext} of the {@link TileRendererBase}'s {@link TileRendererBase#getAttachedDrawable() attached} {@link GLAutoDrawable} + * is not current. + *

+ * @param tr the associated {@link TileRendererBase} + * @see TileRendererBase#getAttachedDrawable() + */ public void addTileRendererNotify(TileRendererBase tr); - /** The owning {@link GLAutoDrawable} is {@link TileRendererBase#detachFromAutoDrawable() detached} from a {@link TileRendererBase}. */ + + /** + * The owning {@link GLAutoDrawable} is {@link TileRendererBase#detachAutoDrawable() detached} + * from the given {@link TileRendererBase} instance. + *

+ * The {@link GLContext} of the {@link TileRendererBase}'s {@link TileRendererBase#getAttachedDrawable() attached} {@link GLAutoDrawable} + * is not current. + *

+ * @param tr the disassociated {@link TileRendererBase} + * @see TileRendererBase#getAttachedDrawable() + */ public void removeTileRendererNotify(TileRendererBase tr); + + /** + * Called by the {@link TileRendererBase} during tile-rendering via an + * {@link TileRendererBase#getAttachedDrawable() attached} {@link GLAutoDrawable}'s + * {@link GLAutoDrawable#display()} call for each tile before {@link #display(GLAutoDrawable)}. + *

+ * The PMV Matrix shall be reshaped + * according to the given + *

+ * The GL viewport is already set to origin 0/0 and the current tile-size.
+ * See details in {@link TileRendererBase#beginTile(GL)}.
+ *

+ *

+ * The {@link GLContext} of the {@link TileRendererBase}'s {@link TileRendererBase#getAttachedDrawable() attached} {@link GLAutoDrawable} + * is current. + *

+ * @param tr the issuing {@link TileRendererBase} + * @param tileX the {@link TileRendererBase#TR_CURRENT_TILE_X_POS current tile's x-pos} + * @param tileY the {@link TileRendererBase#TR_CURRENT_TILE_Y_POS current tile's y-pos} + * @param tileWidth the {@link TileRendererBase#TR_CURRENT_TILE_WIDTH current tile's width} + * @param tileHeight the {@link TileRendererBase#TR_CURRENT_TILE_HEIGHT current tile's height} + * @param imageWidth the {@link TileRendererBase#TR_IMAGE_WIDTH final image width} + * @param imageHeight the {@link TileRendererBase#TR_IMAGE_HEIGHT final image height} + * @see TileRendererBase#getAttachedDrawable() + */ + public void reshapeTile(TileRendererBase tr, + int tileX, int tileY, int tileWidth, int tileHeight, + int imageWidth, int imageHeight); + + /** + * Called by the {@link TileRendererBase} during tile-rendering + * after {@link TileRendererBase#beginTile(GL)} and before {@link #reshapeTile(TileRendererBase, int, int, int, int, int, int) reshapeTile(..)}. + *

+ * If {@link TileRendererBase} is of type {@link TileRenderer}, + * method is called for the first tile of all tiles.
+ * Otherwise, i.e. {@link RandomTileRenderer}, method is called for each particular tile. + *

+ *

+ * The {@link GLContext} of the {@link TileRenderer}'s {@link TileRenderer#getAttachedDrawable() attached} {@link GLAutoDrawable} + * is current. + *

+ * @param tr the issuing {@link TileRendererBase} + */ + public void startTileRendering(TileRendererBase tr); + + /** + * Called by the {@link TileRenderer} during tile-rendering + * after {@link TileRendererBase#endTile(GL)} and {@link GLAutoDrawable#swapBuffers()}. + *

+ * If {@link TileRendererBase} is of type {@link TileRenderer}, + * method is called for the last tile of all tiles.
+ * Otherwise, i.e. {@link RandomTileRenderer}, method is called for each particular tile. + *

+ *

+ * The {@link GLContext} of the {@link TileRenderer}'s {@link TileRenderer#getAttachedDrawable() attached} {@link GLAutoDrawable} + * is current. + *

+ * @param tr the issuing {@link TileRendererBase} + */ + public void endTileRendering(TileRendererBase tr); } protected final Dimension imageSize = new Dimension(0, 0); @@ -246,13 +328,13 @@ public abstract class TileRendererBase { * - *
  • {@link #TR_CURRENT_TILE_X_POS tile x-pos}
  • - *
  • {@link #TR_CURRENT_TILE_Y_POS tile y-pos}
  • - *
  • {@link #TR_IMAGE_WIDTH image width}
  • - *
  • {@link #TR_IMAGE_HEIGHT image height}
  • + *
  • {@link #TR_CURRENT_TILE_X_POS current tile's x-pos}
  • + *
  • {@link #TR_CURRENT_TILE_Y_POS current tile's y-pos}
  • + *
  • {@link #TR_IMAGE_WIDTH final image width}
  • + *
  • {@link #TR_IMAGE_HEIGHT final image height}
  • * *

    *

    @@ -311,12 +393,12 @@ public abstract class TileRendererBase { } /** - * Attaches this renderer to the {@link GLAutoDrawable}. + * Attaches the given {@link GLAutoDrawable} to this tile renderer. + *

    + * The {@link GLAutoDrawable}'s original {@link GLEventListener} are moved to this tile renderer. + *

    *

    - * The {@link GLAutoDrawable}'s original {@link GLEventListener} are moved to this tile renderer.
    - * It is highly recommended that the original {@link GLEventListener} implement - * {@link TileRendererNotify}, so they get {@link TileRendererNotify#addTileRendererNotify(TileRendererBase) notified} - * about this event. + * {@link GLEventListeners} not implementing {@link TileRendererListener} are ignored while tile rendering. *

    *

    * The {@link GLAutoDrawable}'s {@link GLAutoDrawable#getAutoSwapBufferMode() auto-swap mode} is cached @@ -324,15 +406,15 @@ public abstract class TileRendererBase { * see {@link #reqPreSwapBuffers(GLCapabilitiesImmutable)}. *

    *

    - * This tile renderer's {@link GLEventListener} is then added to handle the tile rendering, - * replacing the original {@link GLEventListener}.
    - * This {@link GLEventListener#display(GLAutoDrawable) display} implementations issues: + * This tile renderer's internal {@link GLEventListener} is then added to the attached {@link GLAutoDrawable} + * to handle the tile rendering, replacing the original {@link GLEventListener}.
    + * It's {@link GLEventListener#display(GLAutoDrawable) display} implementations issues: *

    *

    *

    - * The PMV Matrix 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
    - * 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(GL)}.
    - * The original {@link GLEventListener} implementing {@link TileRendererNotify} is aware of this - * tile renderer instance. - *

    - *

    * Consider using {@link #setGLEventListener(GLEventListener, GLEventListener)} to add pre- and post * hooks to be performed on this renderer {@link GLEventListener}.
    * The pre-hook is able to allocate memory and setup parameters, since it's called before {@link #beginTile(GL)}.
    @@ -359,13 +431,15 @@ public abstract class TileRendererBase { * since it's called after {@link #endTile(GL)}. *

    *

    - * Call {@link #detachFromAutoDrawable()} to remove this renderer from the {@link GLAutoDrawable} + * Call {@link #detachAutoDrawable()} to remove the attached {@link GLAutoDrawable} from this tile renderer * and to restore it's original {@link GLEventListener}. *

    - * @param glad + * @param glad the {@link GLAutoDrawable} to attach. * @throws IllegalStateException if an {@link GLAutoDrawable} is already attached + * @see #getAttachedDrawable() + * @see #detachAutoDrawable() */ - public void attachToAutoDrawable(GLAutoDrawable glad) throws IllegalStateException { + public final void attachAutoDrawable(GLAutoDrawable glad) throws IllegalStateException { if( null != this.glad ) { throw new IllegalStateException("GLAutoDrawable already attached"); } @@ -379,9 +453,9 @@ public abstract class TileRendererBase { listenersInit[i] = glad.getGLEventListenerInitState(l); listeners[i] = glad.removeGLEventListener( l ); final boolean trn; - if( listeners[i] instanceof TileRendererNotify ) { + if( listeners[i] instanceof TileRendererListener ) { trn = true; - ((TileRendererNotify)listeners[i]).addTileRendererNotify(this); + ((TileRendererListener)listeners[i]).addTileRendererNotify(this); } else { trn = false; } @@ -399,25 +473,34 @@ public abstract class TileRendererBase { } } - /** - * Detaches this renderer from the {@link GLAutoDrawable}. - *

    - * It is highly recommended that the original {@link GLEventListener} implement - * {@link TileRendererNotify}, so they get {@link TileRendererNotify#removeTileRendererNotify(TileRendererBase) notified} - * about this event. - *

    + /** + * Returns a previously {@link #attachAutoDrawable(GLAutoDrawable) attached} {@link GLAutoDrawable}, + * null if none is attached. *

    - * See {@link #attachToAutoDrawable(GLAutoDrawable)}. + * If called from {@link TileRendererListener#addTileRendererNotify(TileRendererBase)} + * or {@link TileRendererListener#removeTileRendererNotify(TileRendererBase)}, method returns the + * just attached or soon to be detached {@link GLAutoDrawable}. *

    + * @see #attachAutoDrawable(GLAutoDrawable) + * @see #detachAutoDrawable() + */ + public final GLAutoDrawable getAttachedDrawable() { + return glad; + } + + /** + * Detaches the given {@link GLAutoDrawable} from this tile renderer. + * @see #attachAutoDrawable(GLAutoDrawable) + * @see #getAttachedDrawable() */ - public void detachFromAutoDrawable() { + public final void detachAutoDrawable() { if( null != glad ) { glad.removeGLEventListener(tiledGLEL); final int aSz = listenersInit.length; for(int i=0; i