diff options
author | Sven Gothel <[email protected]> | 2014-07-03 13:55:56 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2014-07-03 13:55:56 +0200 |
commit | 62bc3219736ea003e69d8a63dc4ce29841d4129e (patch) | |
tree | 17d30efc3c8669eeb4714ee8d606c72f87c34c5d | |
parent | f37cab0d57697655279e32d5282bff8e9aa40715 (diff) |
Bug 1021: OVRSBSRenderer*: Add texture filtering parameter (bilinear/none), adjust FBO texture params (alpha, filtering); Demo: Pass all parameters w/ arguments, use sane good defaults.
Turns out that using bilinear texture filtering w/o multisampling is 'good enough' ..
- OVRSBSRenderer*:
- Add texture filtering parameter (bilinear/none)
- Adjust FBO texture params (alpha, filtering)
No alpha needed in FBO sink/target!
- Demo: Pass all parameters w/ arguments, use sane good defaults.
3 files changed, 124 insertions, 57 deletions
diff --git a/src/oculusvr/classes/com/jogamp/opengl/oculusvr/OVRSBSRendererDualFBO.java b/src/oculusvr/classes/com/jogamp/opengl/oculusvr/OVRSBSRendererDualFBO.java index ab53862cd..026345067 100644 --- a/src/oculusvr/classes/com/jogamp/opengl/oculusvr/OVRSBSRendererDualFBO.java +++ b/src/oculusvr/classes/com/jogamp/opengl/oculusvr/OVRSBSRendererDualFBO.java @@ -37,6 +37,7 @@ import jogamp.opengl.oculusvr.OVRDistortion; import com.jogamp.oculusvr.OVR; import com.jogamp.oculusvr.ovrFrameTiming; import com.jogamp.opengl.FBObject; +import com.jogamp.opengl.FBObject.Attachment; import com.jogamp.opengl.FBObject.TextureAttachment; import com.jogamp.opengl.FBObject.Attachment.Type; import com.jogamp.opengl.util.CustomRendererListener; @@ -55,19 +56,25 @@ public class OVRSBSRendererDualFBO implements GLEventListener { private final boolean ownsDist; private final StereoRendererListener upstream; private final FBObject[] fbos; + private final int magFilter; + private final int minFilter; private int numSamples; private final TextureAttachment[] fboTexs; - public OVRSBSRendererDualFBO(final OVRDistortion dist, final boolean ownsDist, final StereoRendererListener upstream, final int numSamples) { + public OVRSBSRendererDualFBO(final OVRDistortion dist, final boolean ownsDist, final StereoRendererListener upstream, + final int magFilter, final int minFilter, final int numSamples) { this.dist = dist; this.ownsDist = ownsDist; this.upstream = upstream; + this.fbos = new FBObject[2]; + this.fbos[0] = new FBObject(); + this.fbos[1] = new FBObject(); + this.magFilter = magFilter; + this.minFilter = minFilter; + this.numSamples = numSamples; - fbos = new FBObject[2]; - fbos[0] = new FBObject(); - fbos[1] = new FBObject(); - fboTexs = new TextureAttachment[2]; + this.fboTexs = new TextureAttachment[2]; } private void initFBOs(final GL gl, final int width, final int height) { @@ -84,20 +91,36 @@ public class OVRSBSRendererDualFBO implements GLEventListener { numSamples = fbos[0].getNumSamples(); if(numSamples>0) { - fbos[0].attachColorbuffer(gl, 0, true); - fbos[0].resetSamplingSink(gl); - fbos[1].attachColorbuffer(gl, 0, true); - fbos[1].resetSamplingSink(gl); + fbos[0].attachColorbuffer(gl, 0, true); // MSAA requires alpha + fbos[0].attachRenderbuffer(gl, Type.DEPTH, 24); + final FBObject ssink0 = new FBObject(); + { + ssink0.reset(gl, width, height); + ssink0.attachTexture2D(gl, 0, false, magFilter, minFilter, GL2ES2.GL_CLAMP_TO_EDGE, GL2ES2.GL_CLAMP_TO_EDGE); + ssink0.attachRenderbuffer(gl, Attachment.Type.DEPTH, 24); + } + fbos[0].setSamplingSink(ssink0); + fbos[0].resetSamplingSink(gl); // validate fboTexs[0] = fbos[0].getSamplingSink(); + + fbos[1].attachColorbuffer(gl, 0, true); // MSAA requires alpha + fbos[1].attachRenderbuffer(gl, Type.DEPTH, 24); + final FBObject ssink1 = new FBObject(); + { + ssink1.reset(gl, width, height); + ssink1.attachTexture2D(gl, 0, false, magFilter, minFilter, GL2ES2.GL_CLAMP_TO_EDGE, GL2ES2.GL_CLAMP_TO_EDGE); + ssink1.attachRenderbuffer(gl, Attachment.Type.DEPTH, 24); + } + fbos[1].setSamplingSink(ssink1); + fbos[1].resetSamplingSink(gl); // validate fboTexs[1] = fbos[1].getSamplingSink(); } else { - fboTexs[0] = fbos[0].attachTexture2D(gl, 0, true); - fboTexs[1] = fbos[1].attachTexture2D(gl, 0, true); + fboTexs[0] = fbos[0].attachTexture2D(gl, 0, false, magFilter, minFilter, GL2ES2.GL_CLAMP_TO_EDGE, GL2ES2.GL_CLAMP_TO_EDGE); + fbos[0].attachRenderbuffer(gl, Type.DEPTH, 24); + fboTexs[1] = fbos[1].attachTexture2D(gl, 0, false, magFilter, minFilter, GL2ES2.GL_CLAMP_TO_EDGE, GL2ES2.GL_CLAMP_TO_EDGE); + fbos[1].attachRenderbuffer(gl, Type.DEPTH, 24); } - numSamples=fbos[0].getNumSamples(); - fbos[0].attachRenderbuffer(gl, Type.DEPTH, 24); fbos[0].unbind(gl); - fbos[1].attachRenderbuffer(gl, Type.DEPTH, 24); fbos[1].unbind(gl); } diff --git a/src/oculusvr/classes/com/jogamp/opengl/oculusvr/OVRSBSRendererSingleFBO.java b/src/oculusvr/classes/com/jogamp/opengl/oculusvr/OVRSBSRendererSingleFBO.java index c9d307665..bfc0dd57a 100644 --- a/src/oculusvr/classes/com/jogamp/opengl/oculusvr/OVRSBSRendererSingleFBO.java +++ b/src/oculusvr/classes/com/jogamp/opengl/oculusvr/OVRSBSRendererSingleFBO.java @@ -37,6 +37,7 @@ import jogamp.opengl.oculusvr.OVRDistortion; import com.jogamp.oculusvr.OVR; import com.jogamp.oculusvr.ovrFrameTiming; import com.jogamp.opengl.FBObject; +import com.jogamp.opengl.FBObject.Attachment; import com.jogamp.opengl.FBObject.TextureAttachment; import com.jogamp.opengl.FBObject.Attachment.Type; import com.jogamp.opengl.util.CustomRendererListener; @@ -55,47 +56,68 @@ public class OVRSBSRendererSingleFBO implements GLEventListener { private final OVRDistortion dist; private final boolean ownsDist; private final StereoRendererListener upstream; - private final FBObject fbo0; + private final FBObject fbo; + private final int magFilter; + private final int minFilter; private int numSamples; - private TextureAttachment fbo0Tex; - - public OVRSBSRendererSingleFBO(final OVRDistortion dist, final boolean ownsDist, final StereoRendererListener upstream, final int numSamples) { + private TextureAttachment fboTex; + + /** + * @param dist {@link OVRDistortion} instance used for rendering. + * @param ownsDist if true, {@link OVRDistortion#dispose(GL2ES2)} is issued on this instance's {@link #dispose(GLAutoDrawable)} method, otherwise not. + * @param upstream the upstream {@link StereoRendererListener}, a.k.a the <i>content</i> to render for both eyes + * @param magFilter if > 0 value for {@link GL#GL_TEXTURE_MAG_FILTER} + * @param minFilter if > 0 value for {@link GL#GL_TEXTURE_MIN_FILTER} + * @param numSamples sample-count, if > 0 using multisampling w/ given samples, otherwise no multisampling applies + */ + public OVRSBSRendererSingleFBO(final OVRDistortion dist, final boolean ownsDist, final StereoRendererListener upstream, + final int magFilter, final int minFilter, final int numSamples) { this.dist = dist; this.ownsDist = ownsDist; this.upstream = upstream; + this.fbo = new FBObject(); + this.magFilter = magFilter; + this.minFilter = minFilter; + this.numSamples = numSamples; - fbo0 = new FBObject(); } private void initFBOs(final GL gl, final int width, final int height) { // remove all texture attachments, since MSAA uses just color-render-buffer // and non-MSAA uses texture2d-buffer - fbo0.detachAllColorbuffer(gl); + fbo.detachAllColorbuffer(gl); - fbo0.reset(gl, width, height, numSamples, false); - numSamples = fbo0.getNumSamples(); + fbo.reset(gl, width, height, numSamples, false); + numSamples = fbo.getNumSamples(); if(numSamples>0) { - fbo0.attachColorbuffer(gl, 0, true); - fbo0.resetSamplingSink(gl); - fbo0Tex = fbo0.getSamplingSink(); + fbo.attachColorbuffer(gl, 0, true); // MSAA requires alpha + fbo.attachRenderbuffer(gl, Type.DEPTH, 24); + final FBObject ssink = new FBObject(); + { + ssink.reset(gl, width, height); + ssink.attachTexture2D(gl, 0, false, magFilter, minFilter, GL2ES2.GL_CLAMP_TO_EDGE, GL2ES2.GL_CLAMP_TO_EDGE); + ssink.attachRenderbuffer(gl, Attachment.Type.DEPTH, 24); + } + fbo.setSamplingSink(ssink); + fbo.resetSamplingSink(gl); // validate + fboTex = fbo.getSamplingSink(); } else { - fbo0Tex = fbo0.attachTexture2D(gl, 0, true); + fboTex = fbo.attachTexture2D(gl, 0, false, magFilter, minFilter, GL2ES2.GL_CLAMP_TO_EDGE, GL2ES2.GL_CLAMP_TO_EDGE); + fbo.attachRenderbuffer(gl, Type.DEPTH, 24); } - numSamples=fbo0.getNumSamples(); - fbo0.attachRenderbuffer(gl, Type.DEPTH, 24); - fbo0.unbind(gl); + fbo.unbind(gl); } @SuppressWarnings("unused") private void resetFBOs(final GL gl, final int width, final int height) { - fbo0.reset(gl, width, height, numSamples, true); - numSamples = fbo0.getNumSamples(); + fbo.reset(gl, width, height, numSamples, true); + numSamples = fbo.getNumSamples(); if(numSamples>0) { - fbo0Tex = fbo0.getSamplingSink(); + fboTex = fbo.getSamplingSink(); } else { - fbo0Tex = (TextureAttachment) fbo0.getColorbuffer(0); + fboTex = (TextureAttachment) fbo.getColorbuffer(0); } } @@ -120,7 +142,7 @@ public class OVRSBSRendererSingleFBO implements GLEventListener { // FIXME complete release if( null != upstream ) { upstream.dispose(drawable); - fbo0.destroy(gl); + fbo.destroy(gl); } if( ownsDist ) { dist.dispose(gl); @@ -139,7 +161,7 @@ public class OVRSBSRendererSingleFBO implements GLEventListener { // FIXME: Instead of setting the viewport, // it's better to change the projection matrix! if( null != upstream ) { - fbo0.bind(gl); + fbo.bind(gl); for(int eyeNum=0; eyeNum<2; eyeNum++) { // final ovrPosef eyeRenderPose = OVR.ovrHmd_GetEyePose(hmdCtx, eyeNum); @@ -152,7 +174,7 @@ public class OVRSBSRendererSingleFBO implements GLEventListener { dist.getEyeParam(eyeNum), dist.updateEyePose(eyeNum)); upstream.display(drawable, eyeNum > 0 ? CustomRendererListener.DISPLAY_REPEAT | CustomRendererListener.DISPLAY_DONTCLEAR : 0); } - fbo0.unbind(gl); + fbo.unbind(gl); gl.glViewport(0, 0, drawable.getSurfaceWidth(), drawable.getSurfaceHeight()); } @@ -161,9 +183,9 @@ public class OVRSBSRendererSingleFBO implements GLEventListener { gl.glActiveTexture(GL.GL_TEXTURE0 + dist.texUnit0.intValue()); if( null != upstream ) { - fbo0.use(gl, fbo0Tex); + fbo.use(gl, fboTex); dist.display(gl, frameTiming.getTimewarpPointSeconds()); - fbo0.unuse(gl); + fbo.unuse(gl); } else { dist.display(gl, frameTiming.getTimewarpPointSeconds()); } diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/stereo/ovr/OVRDemo01.java b/src/test/com/jogamp/opengl/test/junit/jogl/stereo/ovr/OVRDemo01.java index cb5fa932c..bfd660556 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/stereo/ovr/OVRDemo01.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/stereo/ovr/OVRDemo01.java @@ -27,6 +27,7 @@ */ package com.jogamp.opengl.test.junit.jogl.stereo.ovr; +import javax.media.opengl.GL; import javax.media.opengl.GLCapabilities; import javax.media.opengl.GLEventListener; import javax.media.opengl.GLProfile; @@ -50,17 +51,25 @@ import com.jogamp.opengl.test.junit.util.QuitAdapter; import com.jogamp.opengl.util.Animator; /** - * All distortions, multisampling and using two FBOs + * All distortions, no multisampling, bilinear filtering, manual-swap and using two FBOs (default, good) * <pre> - * java OVRDemo01 -time 10000000 -vignette -chromatic -timewarp -samples 8 + * java OVRDemo01 -time 10000000 * </pre> - * All distortions, multisampling and using a big single FBO + * All distortions, 8x multisampling, bilinear filtering, manual-swap and using two FBOs (best - slowest) * <pre> - * java OVRDemo01 -time 10000000 -vignette -chromatic -timewarp -samples 8 -singleFBO + * java OVRDemo01 -time 10000000 -samples 8 + * </pre> + * All distortions, 8x multisampling, bilinear filtering, manual-swap and using one a big single FBO (w/ all commandline params) + * <pre> + * java OVRDemo01 -time 10000000 -vignette true -chromatic true -timewarp false -samples 8 -biLinear true -autoSwap false -singleFBO true -mainScreen false + * </pre> + * No distortions, no multisampling, no filtering, auto-swap and using a big single FBO (worst and fastest) + * <pre> + * java OVRDemo01 -time 10000000 -vignette false -chromatic false -timewarp false -samples 0 -biLinear false -autoSwap true -singleFBO true * </pre> * Test on main screen: * <pre> - * java OVRDemo01 -time 10000000 -mainScreen + * java OVRDemo01 -time 10000000 -mainScreen true * </pre> * */ @@ -70,10 +79,11 @@ public class OVRDemo01 { static boolean useOVRScreen = true; static int numSamples = 0; + static boolean biLinear = true; static boolean useSingleFBO = false; - static boolean useVignette = false; - static boolean useChromatic = false; - static boolean useTimewarp = false; + static boolean useVignette = true; + static boolean useChromatic = true; + static boolean useTimewarp = true; static boolean useAutoSwap = false; public static void main(final String args[]) throws InterruptedException { @@ -84,28 +94,38 @@ public class OVRDemo01 { } else if(args[i].equals("-samples")) { i++; numSamples = MiscUtils.atoi(args[i], numSamples); + } else if(args[i].equals("-biLinear")) { + i++; + biLinear = MiscUtils.atob(args[i], biLinear); } else if(args[i].equals("-singleFBO")) { - useSingleFBO = true; + i++; + useSingleFBO = MiscUtils.atob(args[i], useSingleFBO); } else if(args[i].equals("-vignette")) { - useVignette = true; + i++; + useVignette = MiscUtils.atob(args[i], useVignette); } else if(args[i].equals("-chromatic")) { - useChromatic = true; + i++; + useChromatic = MiscUtils.atob(args[i], useChromatic); } else if(args[i].equals("-timewarp")) { - useTimewarp = true; + i++; + useTimewarp = MiscUtils.atob(args[i], useTimewarp); } else if(args[i].equals("-vignette")) { - useVignette = true; + i++; + useVignette = MiscUtils.atob(args[i], useVignette); } else if(args[i].equals("-mainScreen")) { - useOVRScreen = false; + i++; + useOVRScreen = !MiscUtils.atob(args[i], useOVRScreen); } else if(args[i].equals("-autoSwap")) { - useAutoSwap = true; + i++; + useAutoSwap = MiscUtils.atob(args[i], useAutoSwap); } } final OVRDemo01 demo01 = new OVRDemo01(); - demo01.doIt(0, numSamples, useSingleFBO, useVignette, useChromatic, useTimewarp, + demo01.doIt(0, biLinear, numSamples, useSingleFBO, useVignette, useChromatic, useTimewarp, useAutoSwap, true /* useAnimator */, false /* exclusiveContext*/); } - public void doIt(final int ovrHmdIndex, final int numSamples, + public void doIt(final int ovrHmdIndex, final boolean biLinear, final int numSamples, final boolean useSingleFBO, final boolean useVignette, final boolean useChromatic, final boolean useTimewarp, final boolean useAutoSwap, @@ -113,6 +133,7 @@ public class OVRDemo01 { System.err.println("glob duration "+duration); System.err.println("glob useOVRScreen "+useOVRScreen); + System.err.println("biLinear "+biLinear); System.err.println("numSamples "+numSamples); System.err.println("useSingleFBO "+useSingleFBO); System.err.println("useVignette "+useVignette); @@ -174,13 +195,14 @@ public class OVRDemo01 { final OVRDistortion dist = OVRDistortion.create(hmdCtx, useSingleFBO, eyePositionOffset, defaultEyeFov, pixelsPerDisplayPixel, distortionCaps); System.err.println("OVRDistortion: "+dist); + final int texFilter = biLinear ? GL.GL_LINEAR : GL.GL_NEAREST; final GearsES2 upstream = new GearsES2(0); upstream.setVerbose(false); final GLEventListener renderer; if( useSingleFBO ) { - renderer = new OVRSBSRendererSingleFBO(dist, true /* ownsDist */, upstream, numSamples); + renderer = new OVRSBSRendererSingleFBO(dist, true /* ownsDist */, upstream, texFilter, texFilter, numSamples); } else { - renderer = new OVRSBSRendererDualFBO(dist, true /* ownsDist */, upstream, numSamples); + renderer = new OVRSBSRendererDualFBO(dist, true /* ownsDist */, upstream, texFilter, texFilter, numSamples); } window.addGLEventListener(renderer); |