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/test/com/jogamp/opengl | |
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/test/com/jogamp/opengl')
-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 |
6 files changed, 187 insertions, 41 deletions
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()); } } |