From c8b0516472dec8b76cc7c3a3f71683ffe1410a3a Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Tue, 3 Sep 2013 16:28:32 +0200 Subject: Cleaned up TiledRenderer capable to be used w/ GL2ES3 and TiledRenderer2 to be used w/ GLAutoDrawable. - Remove GL2 dependencies - Only requires PixelStorage ROW_LENGTH -> GL2ES3 - Position target buffer position according to skip [pixels, rows] - Use an interface PMVMatrixCallback, allowing user to reshape the custom 'PMV Matrix' according to the current rendered tile - Properly adjust tile/image buffer to written position and flip for read operation --- .../com/jogamp/opengl/util/TileRenderer2.java | 129 +++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 src/jogl/classes/com/jogamp/opengl/util/TileRenderer2.java (limited to 'src/jogl/classes/com/jogamp/opengl/util/TileRenderer2.java') diff --git a/src/jogl/classes/com/jogamp/opengl/util/TileRenderer2.java b/src/jogl/classes/com/jogamp/opengl/util/TileRenderer2.java new file mode 100644 index 000000000..a77456889 --- /dev/null +++ b/src/jogl/classes/com/jogamp/opengl/util/TileRenderer2.java @@ -0,0 +1,129 @@ +package com.jogamp.opengl.util; + +import javax.media.opengl.GL2ES3; +import javax.media.opengl.GLAutoDrawable; +import javax.media.opengl.GLEventListener; + +/** + * See {@link TileRenderer}. + *

+ * Enhanced for {@link GLAutoDrawable} usage. + *

+ */ +public class TileRenderer2 extends TileRenderer { + private GLAutoDrawable glad; + private GLEventListener[] listeners; + private boolean[] listenersInit; + + /** + * Creates a new TileRenderer object + */ + public TileRenderer2() { + glad = null; + listeners = null; + listenersInit = null; + } + + /** + * + *

+ * Sets the size of the tiles to use in rendering. The actual + * effective size of the tile depends on the border size, ie ( + * width - 2*border ) * ( height - 2 * border ) + *

+ * @param glad + * @param border + * The width of the borders on each tile. This is needed + * to avoid artifacts when rendering lines or points with + * thickness > 1. + * @throws IllegalStateException if an {@link GLAutoDrawable} is already attached + */ + public void attachAutoDrawable(GLAutoDrawable glad, int border, PMVMatrixCallback pmvMatrixCB) throws IllegalStateException { + if( null != this.glad ) { + throw new IllegalStateException("GLAutoDrawable already attached"); + } + this.glad = glad; + setTileSize(glad.getWidth(), glad.getHeight(), border); + setPMVMatrixCallback(pmvMatrixCB); + + final int aSz = glad.getGLEventListenerCount(); + listeners = new GLEventListener[aSz]; + listenersInit = new boolean[aSz]; + for(int i=0; i