diff options
author | Sven Gothel <[email protected]> | 2013-09-07 19:47:28 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2013-09-07 19:47:28 +0200 |
commit | 4965923722fe44dfcf7eaff16cd5449707773123 (patch) | |
tree | 21645b2ecb0a3b9ba14ed1b0e24cb49c4813e167 /src | |
parent | 6fe3e99dab9721294a3bf72eaea77af33afc9481 (diff) |
TileRenderer*: Fix FBO MSAA use-case, i.e. call swapBuffers() before endTile(); Enhance unit tests for MSAA, also add TileRendererBase.TileRendererNotify to GearsES2
GL[Auto]Drawable.swapBuffers() must be called before endTile().
This is especially important if using multisampling offscreen FBO drawables,
where swapBuffers() triggers the <i>downsampling</i> to the readable sampling sink.
Otherwise, we will be 'one tile behind' !
Diffstat (limited to 'src')
-rw-r--r-- | src/jogl/classes/com/jogamp/opengl/util/RandomTileRenderer.java | 9 | ||||
-rw-r--r-- | src/jogl/classes/com/jogamp/opengl/util/TileRenderer.java | 20 | ||||
-rw-r--r-- | src/jogl/classes/com/jogamp/opengl/util/TileRendererBase.java | 32 | ||||
-rw-r--r-- | src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java | 69 | ||||
-rw-r--r-- | src/test/com/jogamp/opengl/test/junit/jogl/demos/gl2/Gears.java | 29 | ||||
-rw-r--r-- | src/test/com/jogamp/opengl/test/junit/jogl/tile/TestRandomTiledRendering2GL2NEWT.java | 29 | ||||
-rw-r--r-- | src/test/com/jogamp/opengl/test/junit/jogl/tile/TestRandomTiledRendering3GL2AWT.java | 26 | ||||
-rw-r--r-- | src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledRendering1GL2NEWT.java | 3 | ||||
-rw-r--r-- | src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledRendering2NEWT.java (renamed from src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledRendering2GL2NEWT.java) | 72 |
9 files changed, 234 insertions, 55 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/util/RandomTileRenderer.java b/src/jogl/classes/com/jogamp/opengl/util/RandomTileRenderer.java index 2b698d2f5..55b31b692 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/RandomTileRenderer.java +++ b/src/jogl/classes/com/jogamp/opengl/util/RandomTileRenderer.java @@ -104,6 +104,11 @@ public class RandomTileRenderer extends TileRendererBase { validateGL(gl); gl.glViewport( 0, 0, currentTileWidth, currentTileHeight ); + + if( DEBUG ) { + System.err.println("TileRenderer.begin.X: "+this.toString()); + } + // Do not forget to issue: // reshape( 0, 0, tW, tH ); // which shall reflect tile renderer fileds: currentTileXPos, currentTileYPos and imageSize @@ -121,6 +126,10 @@ public class RandomTileRenderer extends TileRendererBase { // be sure OpenGL rendering is finished gl.glFlush(); + if( DEBUG ) { + System.err.println("TileRenderer.end.0: "+this.toString()); + } + // save current glPixelStore values psm.save(gl); psm.setPackAlignment(gl, 1); diff --git a/src/jogl/classes/com/jogamp/opengl/util/TileRenderer.java b/src/jogl/classes/com/jogamp/opengl/util/TileRenderer.java index 46a1e2452..e24fa9706 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/TileRenderer.java +++ b/src/jogl/classes/com/jogamp/opengl/util/TileRenderer.java @@ -104,7 +104,6 @@ public class TileRenderer extends TileRendererBase { */ public static final int TR_BOTTOM_TO_TOP = 16; - private static final boolean DEBUG = true; private static final int DEFAULT_TILE_WIDTH = 256; private static final int DEFAULT_TILE_HEIGHT = 256; private static final int DEFAULT_TILE_BORDER = 0; @@ -259,9 +258,6 @@ public class TileRenderer extends TileRendererBase { setup(); } - final int preRow = currentRow; - final int preColumn = currentColumn; - /* which tile (by row and column) we're about to render */ if (rowOrder == TR_BOTTOM_TO_TOP) { currentRow = currentTile / columns; @@ -293,20 +289,16 @@ public class TileRenderer extends TileRendererBase { currentTileXPos = currentColumn * tileSizeNB.getWidth() + offsetX; currentTileYPos = currentRow * tileSizeNB.getHeight() + offsetY; - final int preTileWidth = currentTileWidth; - final int preTileHeight = currentTileHeight; - /* Save tile size, with border */ currentTileWidth = tW; currentTileHeight = tH; + gl.glViewport( 0, 0, tW, tH ); + if( DEBUG ) { - System.err.println("Tile["+currentTile+"]: off "+offsetX+"/"+offsetX+", ["+preColumn+"]["+preRow+"] "+preTileWidth+"x"+preTileHeight+ - " -> ["+currentColumn+"]["+currentRow+"] "+currentTileXPos+"/"+currentTileYPos+", "+tW+"x"+tH+ - ", image "+imageSize.getWidth()+"x"+imageSize.getHeight()); + System.err.println("TileRenderer.begin.X: "+this.toString()); } - - gl.glViewport( 0, 0, tW, tH ); + // Do not forget to issue: // reshape( 0, 0, tW, tH ); // which shall reflect tile renderer fileds: currentTileXPos, currentTileYPos and imageSize @@ -323,6 +315,10 @@ public class TileRenderer extends TileRendererBase { // be sure OpenGL rendering is finished gl.glFlush(); + if( DEBUG ) { + System.err.println("TileRenderer.end.0: "+this.toString()); + } + // save current glPixelStore values psm.save(gl); psm.setPackAlignment(gl, 1); diff --git a/src/jogl/classes/com/jogamp/opengl/util/TileRendererBase.java b/src/jogl/classes/com/jogamp/opengl/util/TileRendererBase.java index e7296ab0a..70e68b97f 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/TileRendererBase.java +++ b/src/jogl/classes/com/jogamp/opengl/util/TileRendererBase.java @@ -41,9 +41,12 @@ import javax.media.nativewindow.util.DimensionImmutable; import javax.media.opengl.GL; import javax.media.opengl.GL2ES3; import javax.media.opengl.GLAutoDrawable; +import javax.media.opengl.GLDrawable; import javax.media.opengl.GLEventListener; import javax.media.opengl.GLException; +import jogamp.opengl.Debug; + /** * A fairly direct port of Brian Paul's tile rendering library, found * at <a href = "http://www.mesa3d.org/brianp/TR.html"> @@ -111,6 +114,8 @@ public abstract class TileRendererBase { */ public static final int TR_CURRENT_TILE_HEIGHT = 6; + /* 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} @@ -133,6 +138,7 @@ public abstract class TileRendererBase { protected int currentTileWidth; protected int currentTileHeight; protected GLAutoDrawable glad; + protected boolean gladAutoSwapBufferMode = true; protected GLEventListener[] listeners; protected boolean[] listenersInit; protected GLEventListener glEventListenerPre = null; @@ -180,6 +186,9 @@ public abstract class TileRendererBase { */ public final void setTileBuffer(GLPixelBuffer buffer) { tileBuffer = buffer; + if( DEBUG ) { + System.err.println("TileRenderer: tile-buffer "+tileBuffer); + } } /** @see #setTileBuffer(GLPixelBuffer) */ @@ -206,6 +215,9 @@ public abstract class TileRendererBase { */ public final void setImageBuffer(GLPixelBuffer buffer) { imageBuffer = buffer; + if( DEBUG ) { + System.err.println("TileRenderer: image-buffer "+imageBuffer); + } } /** @see #setImageBuffer(GLPixelBuffer) */ @@ -259,6 +271,11 @@ public abstract class TileRendererBase { * Must be called after rendering the scene, * see {@link #beginTile(GL)}. * <p> + * Is is highly recommended to perform {@link GLDrawable#swapBuffers() swapBuffers()} before calling this method.<br> + * This is especially true in regards to multisampling offscreen FBO drawables, + * where {@link GLDrawable#swapBuffers() swapBuffers()} triggers the <i>downsampling</i> to the readable sampling sink. + * </p> + * <p> * User has to comply with the <a href="#glprequirement">GL profile requirement</a>. * </p> * @@ -277,8 +294,13 @@ public abstract class TileRendererBase { * 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: + * The {@link GLAutoDrawable}'s {@link GLAutoDrawable#getAutoSwapBufferMode() auto-swap mode} is cached + * and set to <code>false</code>, since {@link GLAutoDrawable#swapBuffers() swapBuffers()} must be issued before {@link #endTile(GL)}. + * </p> + * <p> + * This tile renderer's {@link GLEventListener} is then added to handle the tile rendering, + * replacing the original {@link GLEventListener}.<br> + * This {@link GLEventListener#display(GLAutoDrawable) display} implementations issues: * <ul> * <li>Optional {@link #setGLEventListener(GLEventListener, GLEventListener) pre-glel}.{@link GLEventListener#display(GLAutoDrawable) display(..)}</li> * <li>{@link #beginTile(GL)}</li> @@ -287,6 +309,7 @@ public abstract class TileRendererBase { * <li>{@link GLEventListener#reshape(GLAutoDrawable, int, int, int, int) reshape(0, 0, tile-width, tile-height)}</li> * <li>{@link GLEventListener#display(GLAutoDrawable) display(autoDrawable)}</li> * </ul></li> + * <li>{@link GLAutoDrawable#swapBuffers() swapBuffers()}</li> * <li>{@link #endTile(GL)}</li> * <li>Optional {@link #setGLEventListener(GLEventListener, GLEventListener) post-glel}.{@link GLEventListener#display(GLAutoDrawable) display(..)}</li> * </ul> @@ -333,6 +356,8 @@ public abstract class TileRendererBase { } } glad.addGLEventListener(tiledGLEL); + gladAutoSwapBufferMode = glad.getAutoSwapBufferMode(); + glad.setAutoSwapBufferMode(false); } /** @@ -358,6 +383,8 @@ public abstract class TileRendererBase { glad.addGLEventListener(l); glad.setGLEventListenerInitState(l, listenersInit[i]); } + glad.setAutoSwapBufferMode(gladAutoSwapBufferMode); + listeners = null; listenersInit = null; glad = null; @@ -432,6 +459,7 @@ public abstract class TileRendererBase { listeners[i].reshape(drawable, 0, 0, currentTileWidth, currentTileHeight); listeners[i].display(drawable); } + glad.swapBuffers(); endTile(gl); if( null != glEventListenerPost ) { 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 75a25e2ad..2e98514a6 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 @@ -30,6 +30,7 @@ import com.jogamp.newt.event.MouseListener; import com.jogamp.opengl.JoglVersion; import com.jogamp.opengl.test.junit.jogl.demos.GearsObject; import com.jogamp.opengl.util.PMVMatrix; +import com.jogamp.opengl.util.TileRendererBase; import com.jogamp.opengl.util.glsl.ShaderCode; import com.jogamp.opengl.util.glsl.ShaderProgram; import com.jogamp.opengl.util.glsl.ShaderState; @@ -48,7 +49,7 @@ import javax.media.opengl.GLUniformData; * GearsES2.java <BR> * @author Brian Paul (converted to Java by Ron Cemer and Sven Gothel) <P> */ -public class GearsES2 implements GLEventListener { +public class GearsES2 implements GLEventListener, TileRendererBase.TileRendererNotify { private final FloatBuffer lightPos = Buffers.newDirectFloatBuffer( new float[] { 5.0f, 5.0f, 10.0f } ); private ShaderState st = null; @@ -66,6 +67,8 @@ public class GearsES2 implements GLEventListener { // private MouseListener gearsMouse = new TraceMouseAdapter(new GearsMouseAdapter()); public MouseListener gearsMouse = new GearsMouseAdapter(); public KeyListener gearsKeys = new GearsKeyAdapter(); + private TileRendererBase tileRendererInUse = null; + private boolean doRotateBeforePrinting; private boolean doRotate = true; private boolean ignoreFocus = false; @@ -81,6 +84,16 @@ public class GearsES2 implements GLEventListener { this.swapInterval = 1; } + public void addTileRendererNotify(TileRendererBase tr) { + tileRendererInUse = tr; + doRotateBeforePrinting = doRotate; + setDoRotation(false); + } + public void removeTileRendererNotify(TileRendererBase tr) { + tileRendererInUse = null; + setDoRotation(doRotateBeforePrinting); + } + public void setIgnoreFocus(boolean v) { ignoreFocus = v; } public void setDoRotation(boolean rotate) { this.doRotate = rotate; } public void setClearBuffers(boolean v) { clearBuffers = v; } @@ -221,12 +234,13 @@ public class GearsES2 implements GLEventListener { } public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { - System.err.println(Thread.currentThread()+" GearsES2.reshape "+x+"/"+y+" "+width+"x"+height+", swapInterval "+swapInterval+", drawable 0x"+Long.toHexString(drawable.getHandle())); + final GL2ES2 gl = drawable.getGL().getGL2ES2(); + final boolean msaa = gl.getContext().getGLDrawable().getChosenGLCapabilities().getSampleBuffers(); + System.err.println(Thread.currentThread()+" GearsES2.reshape "+x+"/"+y+" "+width+"x"+height+", swapInterval "+swapInterval+", drawable 0x"+Long.toHexString(drawable.getHandle())+", msaa "+msaa+", tileRendererInUse "+tileRendererInUse); drawableHeight = height; // Thread.dumpStack(); - final GL2ES2 gl = drawable.getGL().getGL2ES2(); if(-1 != swapInterval) { gl.setSwapInterval(swapInterval); // in case switching the drawable (impl. may bound attribute there) @@ -239,14 +253,49 @@ public class GearsES2 implements GLEventListener { pmvMatrix.glMatrixMode(PMVMatrix.GL_PROJECTION); pmvMatrix.glLoadIdentity(); - if(height>width) { - float h = (float)height / (float)width; - pmvMatrix.glFrustumf(-1.0f, 1.0f, -h, h, 5.0f, 200.0f); + final int tileWidth = width; + final int tileHeight = height; + final int tileX, tileY, imageWidth, imageHeight; + if( null == tileRendererInUse ) { + gl.setSwapInterval(swapInterval); + tileX = 0; + tileY = 0; + imageWidth = width; + imageHeight = height; } else { - float h = (float)width / (float)height; - pmvMatrix.glFrustumf(-h, h, -1.0f, 1.0f, 5.0f, 200.0f); + gl.setSwapInterval(0); + tileX = tileRendererInUse.getParam(TileRendererBase.TR_CURRENT_TILE_X_POS); + tileY = tileRendererInUse.getParam(TileRendererBase.TR_CURRENT_TILE_Y_POS); + imageWidth = tileRendererInUse.getParam(TileRendererBase.TR_IMAGE_WIDTH); + imageHeight = tileRendererInUse.getParam(TileRendererBase.TR_IMAGE_HEIGHT); } - + /* compute projection parameters */ + float left, right, bottom, top; + if( imageHeight > imageWidth ) { + float a = (float)imageHeight / (float)imageWidth; + left = -1.0f; + right = 1.0f; + bottom = -a; + top = a; + } else { + float a = (float)imageWidth / (float)imageHeight; + left = -a; + right = a; + bottom = -1.0f; + top = 1.0f; + } + final float w = right - left; + final float h = top - bottom; + final float l = left + tileX * w / imageWidth; + final float r = l + w * tileWidth / imageWidth; + final float b = bottom + tileY * h / imageHeight; + final float t = b + h * tileHeight / imageHeight; + + final float _w = r - l; + final float _h = t - b; + System.err.println(">> angle "+angle+", [l "+left+", r "+right+", b "+bottom+", t "+top+"] "+w+"x"+h+" -> [l "+l+", r "+r+", b "+b+", t "+t+"] "+_w+"x"+_h); + pmvMatrix.glFrustumf(l, r, b, t, 5.0f, 200.0f); + pmvMatrix.glMatrixMode(PMVMatrix.GL_MODELVIEW); pmvMatrix.glLoadIdentity(); pmvMatrix.glTranslatef(0.0f, 0.0f, -40.0f); @@ -308,6 +357,8 @@ public class GearsES2 implements GLEventListener { if( clearBuffers ) { if( null != clearColor ) { gl.glClearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]); + } else if( null != tileRendererInUse ) { + gl.glClearColor(1.0f, 1.0f, 1.0f, 0.0f); } else if( ignoreFocus || hasFocus ) { gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); } else { 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 c781bc8de..04f552e34 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 @@ -1,6 +1,7 @@ package com.jogamp.opengl.test.junit.jogl.demos.gl2; +import javax.media.opengl.GL; import javax.media.opengl.GL2; import javax.media.opengl.GLAutoDrawable; import javax.media.opengl.GLEventListener; @@ -34,6 +35,7 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererNoti private MouseListener gearsMouse = new GearsMouseAdapter(); private KeyListener gearsKeys = new GearsKeyAdapter(); private TileRendererBase tileRendererInUse = null; + private boolean doRotateBeforePrinting; // private boolean mouseRButtonDown = false; private int prevMouseX, prevMouseY; @@ -46,7 +48,6 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererNoti this.swapInterval = 1; } - private boolean doRotateBeforePrinting; public void addTileRendererNotify(TileRendererBase tr) { tileRendererInUse = tr; doRotateBeforePrinting = doRotate; @@ -157,8 +158,13 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererNoti } public void reshape(GL2 gl, int x, int y, int width, int height) { - System.err.println("Gears: Reshape "+x+"/"+y+" "+width+"x"+height+", tileRendererInUse "+tileRendererInUse); + final boolean msaa = gl.getContext().getGLDrawable().getChosenGLCapabilities().getSampleBuffers(); + System.err.println("Gears: Reshape "+x+"/"+y+" "+width+"x"+height+", msaa "+msaa+", tileRendererInUse "+tileRendererInUse); + if( msaa ) { + gl.glEnable(GL.GL_MULTISAMPLE); + } + gl.glMatrixMode(GL2.GL_PROJECTION); gl.glLoadIdentity(); @@ -209,6 +215,10 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererNoti gl.glMatrixMode(GL2.GL_MODELVIEW); gl.glLoadIdentity(); gl.glTranslatef(0.0f, 0.0f, -40.0f); + + if( msaa ) { + gl.glDisable(GL.GL_MULTISAMPLE); + } } public void dispose(GLAutoDrawable drawable) { @@ -227,7 +237,12 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererNoti public void display(GLAutoDrawable drawable) { // Get the GL corresponding to the drawable we are animating GL2 gl = drawable.getGL().getGL2(); + final boolean msaa = gl.getContext().getGLDrawable().getChosenGLCapabilities().getSampleBuffers(); + if( msaa ) { + gl.glEnable(GL.GL_MULTISAMPLE); + } + if( null == tileRendererInUse ) { gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); } else { @@ -245,8 +260,15 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererNoti gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT); } displayImpl(gl); + if( msaa ) { + gl.glDisable(GL.GL_MULTISAMPLE); + } } public void display(GL2 gl) { + final boolean msaa = gl.getContext().getGLDrawable().getChosenGLCapabilities().getSampleBuffers(); + if( msaa ) { + gl.glEnable(GL.GL_MULTISAMPLE); + } if( null == tileRendererInUse ) { gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); } else { @@ -254,6 +276,9 @@ public class Gears implements GLEventListener, TileRendererBase.TileRendererNoti } gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT); displayImpl(gl); + if( msaa ) { + gl.glDisable(GL.GL_MULTISAMPLE); + } } private void displayImpl(GL2 gl) { if( doRotate ) { 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 ca9bf9a9c..09817a27f 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 @@ -38,6 +38,8 @@ import com.jogamp.opengl.util.texture.TextureIO; import java.io.File; import java.io.IOException; +import java.lang.reflect.InvocationTargetException; + import javax.media.opengl.GL; import javax.media.opengl.GLAutoDrawable; import javax.media.opengl.GLCapabilities; @@ -73,23 +75,32 @@ public class TestRandomTiledRendering2GL2NEWT extends UITestCase { static long duration = 500; // ms @Test - public void test01() throws IOException { - doTest(); + public void test01_aa0() throws IOException, InterruptedException, InvocationTargetException { + doTest(0); + } + @Test + public void test02_aa8() throws IOException, InterruptedException, InvocationTargetException { + doTest(8); } - void doTest() throws IOException { - GLCapabilities caps = new GLCapabilities(null); - caps.setDoubleBuffered(false); + void doTest(int msaaCount) throws IOException, InterruptedException, InvocationTargetException { + final GLCapabilities caps = new GLCapabilities(null); + caps.setDoubleBuffered(true); + if( msaaCount > 0 ) { + caps.setSampleBuffers(true); + caps.setNumSamples(msaaCount); + } + final int maxTileSize = 64; final GLDrawableFactory factory = GLDrawableFactory.getFactory(caps.getGLProfile()); - final GLOffscreenAutoDrawable glad = factory.createOffscreenAutoDrawable(null, caps, null, 256, 256, null); + final GLOffscreenAutoDrawable glad = factory.createOffscreenAutoDrawable(null, caps, null, maxTileSize, maxTileSize, null); final Gears gears = new Gears(); glad.addGLEventListener( gears ); // Fix the image size for now - final int imageWidth = glad.getWidth() * 6; - final int imageHeight = glad.getHeight() * 4; + final int imageWidth = 256 * 6; + final int imageHeight = 256 * 4; final String filename = this.getSnapshotFilename(0, "-tile", glad.getChosenGLCapabilities(), imageWidth, imageHeight, false, TextureIO.PNG, null); final File file = new File(filename); @@ -124,7 +135,7 @@ public class TestRandomTiledRendering2GL2NEWT extends UITestCase { }; renderer.setGLEventListener(preTileGLEL, null); - final int w = 50, h = 50; + final int w = maxTileSize, h = maxTileSize; int dx = 0, dy = 0; while( dx+w <= imageWidth && dy+h <= imageHeight ) { renderer.display(dx, dy, w, h); 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 2b7e727b8..16f11d85b 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 @@ -80,17 +80,24 @@ import org.junit.runners.MethodSorters; @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class TestRandomTiledRendering3GL2AWT extends UITestCase { static long duration = 3500; // ms - static int width = 640; - static int height = 480; + static int width = 512; + static int height = 512; @Test - public void test01() throws IOException, InterruptedException, InvocationTargetException { - doTest(); + public void test01_aa0() throws IOException, InterruptedException, InvocationTargetException { + doTest(0); + } + @Test + public void test02_aa8() throws IOException, InterruptedException, InvocationTargetException { + doTest(8); } - void doTest() throws IOException, InterruptedException, InvocationTargetException { + void doTest(int msaaCount) throws IOException, InterruptedException, InvocationTargetException { final GLCapabilities caps = new GLCapabilities(null); - caps.setDoubleBuffered(false); + if( msaaCount > 0 ) { + caps.setSampleBuffers(true); + caps.setNumSamples(msaaCount); + } final Frame frame = new Frame("Gears AWT Test"); Assert.assertNotNull(frame); @@ -113,8 +120,9 @@ public class TestRandomTiledRendering3GL2AWT extends UITestCase { new AWTWindowAdapter(new TraceWindowAdapter(quitAdapter)).addTo(frame); // Fix the image size for now - final int imageWidth = glad.getWidth() * 3; - final int imageHeight = glad.getHeight() * 2; + final int maxTileSize = 64; + final int imageWidth = 256 * 6; + final int imageHeight = 256 * 4; // Initialize the tile rendering library final RandomTileRenderer renderer = new RandomTileRenderer(); @@ -124,7 +132,7 @@ public class TestRandomTiledRendering3GL2AWT extends UITestCase { final boolean[] rendererActive = { true }; final GLEventListener preTileGLEL = new GLEventListener() { - final int w = 50, h = 50; + final int w = maxTileSize, h = maxTileSize; int dx = 0, dy = 0; @Override 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 62bdf6d64..c38140ce0 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 @@ -107,7 +107,8 @@ public class TestTiledRendering1GL2NEWT extends UITestCase { GLCapabilities caps = new GLCapabilities(glp); caps.setOnscreen(false); - DrawableContext dc = createDrawableAndCurrentCtx(caps, 256, 256); + final int maxTileSize = 256; + DrawableContext dc = createDrawableAndCurrentCtx(caps, maxTileSize, maxTileSize); final GL2 gl = dc.glc.getGL().getGL2(); // Fix the image size for now diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledRendering2GL2NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledRendering2NEWT.java index 28e1b21c4..be209412e 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledRendering2GL2NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/tile/TestTiledRendering2NEWT.java @@ -27,6 +27,7 @@ */ package com.jogamp.opengl.test.junit.jogl.tile; +import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2; import com.jogamp.opengl.test.junit.jogl.demos.gl2.Gears; import com.jogamp.opengl.test.junit.util.UITestCase; import com.jogamp.opengl.util.GLPixelBuffer; @@ -44,6 +45,7 @@ import javax.media.opengl.GLCapabilities; import javax.media.opengl.GLDrawableFactory; import javax.media.opengl.GLEventListener; import javax.media.opengl.GLOffscreenAutoDrawable; +import javax.media.opengl.GLProfile; import javax.media.opengl.GLRunnable; import org.junit.FixMethodOrder; @@ -69,23 +71,71 @@ import org.junit.runners.MethodSorters; * </p> */ @FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class TestTiledRendering2GL2NEWT extends UITestCase { +public class TestTiledRendering2NEWT extends UITestCase { static long duration = 500; // ms + static GLProfile getGLProfile(String profile) { + if( !GLProfile.isAvailable(profile) ) { + System.err.println("Profile "+profile+" n/a"); + return null; + } + return GLProfile.get(profile); + } + static GLProfile getGL2ES3() { + final GLProfile glp = GLProfile.getMaxProgrammableCore(true); + if( null == glp || !glp.isGL2ES3() ) { + System.err.println("GL2ES3 n/a, has max-core "+glp); + return null; + } + return glp; + } + @Test - public void test01() throws IOException { - doTest(); + public void test01_gl2___aa0() throws IOException { + GLProfile glp = getGLProfile(GLProfile.GL2); + if( null == glp ) { + return; + } + doTest(new Gears(), glp, 0); + } + @Test + public void test02_gl2___aa8() throws IOException { + GLProfile glp = getGLProfile(GLProfile.GL2); + if( null == glp ) { + return; + } + doTest(new Gears(), glp, 8); + } + @Test + public void test11_gl2es3_aa0() throws IOException { + GLProfile glp = getGL2ES3(); + if( null == glp ) { + return; + } + doTest(new GearsES2(), glp, 0); + } + @Test + public void test12_gl2es3_aa8() throws IOException { + GLProfile glp = getGL2ES3(); + if( null == glp ) { + return; + } + doTest(new GearsES2(), glp, 8); } - void doTest() throws IOException { - GLCapabilities caps = new GLCapabilities(null); + void doTest(final GLEventListener demo, GLProfile glp, final int msaaCount) throws IOException { + GLCapabilities caps = new GLCapabilities(glp); caps.setDoubleBuffered(false); + if( msaaCount > 0 ) { + caps.setSampleBuffers(true); + caps.setNumSamples(msaaCount); + } - final GLDrawableFactory factory = GLDrawableFactory.getFactory(caps.getGLProfile()); - final GLOffscreenAutoDrawable glad = factory.createOffscreenAutoDrawable(null, caps, null, 256, 256, null); + final int maxTileSize = 256; + final GLDrawableFactory factory = GLDrawableFactory.getFactory(glp); + final GLOffscreenAutoDrawable glad = factory.createOffscreenAutoDrawable(null, caps, null, maxTileSize, maxTileSize, null); - final Gears gears = new Gears(); - glad.addGLEventListener( gears ); + glad.addGLEventListener( demo ); // Fix the image size for now final int imageWidth = glad.getWidth() * 6; @@ -137,7 +187,7 @@ public class TestTiledRendering2GL2NEWT extends UITestCase { @Override public boolean run(GLAutoDrawable drawable) { drawable.getGL().glViewport(0, 0, drawable.getWidth(), drawable.getHeight()); - gears.reshape(drawable, 0, 0, drawable.getWidth(), drawable.getHeight()); + demo.reshape(drawable, 0, 0, drawable.getWidth(), drawable.getHeight()); return false; } }); @@ -168,6 +218,6 @@ public class TestTiledRendering2GL2NEWT extends UITestCase { } catch (Exception ex) { ex.printStackTrace(); } } } - org.junit.runner.JUnitCore.main(TestTiledRendering2GL2NEWT.class.getName()); + org.junit.runner.JUnitCore.main(TestTiledRendering2NEWT.class.getName()); } } |