From 609b3f6d28bb13b589cde815acdb0e72e58ebe44 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Thu, 7 Aug 2014 00:10:41 +0200 Subject: Bug 1021: Refine Stereo API; Fix GenericStereoDevice; Fix StereoDemo01 for movie playback and OSX usage (HiDPI surfaceSize) - StereoDevice.DeviceType: Add API doc - StereoDevice: Add getFactory() - GenericStereoDevice - Use common static vars for configurations for simplicity - Fix createRenderer(..)'s eyeViewport in case no post-processing is performed, i.e. needs viewport X offset. - StereoDemo01 - Use 'movie' eyePosition instead of default if: - using a movie player _and_ using lenses! - Fix NEWT window pixel-unit size after window creation! --- .../junit/jogl/demos/es2/av/MovieSBSStereo.java | 29 ++++++++++++----- .../test/junit/jogl/stereo/StereoDemo01.java | 38 +++++++++++++--------- 2 files changed, 44 insertions(+), 23 deletions(-) (limited to 'src/test/com') diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieSBSStereo.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieSBSStereo.java index 0c7bdc81d..9098ad00f 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieSBSStereo.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/av/MovieSBSStereo.java @@ -203,6 +203,7 @@ public class MovieSBSStereo implements StereoGLEventListener { renderString(drawable, font, pixelSize, text4, 1 /* col */, -2 /* row */, 0, height, 1, true); } } }; + private final boolean enableTextRendererGLEL = false; private InfoTextRendererGLELBase textRendererGLEL = null; private boolean displayOSD = false; @@ -534,8 +535,12 @@ public class MovieSBSStereo implements StereoGLEventListener { } final int rmode = drawable.getChosenGLCapabilities().getSampleBuffers() ? 0 : Region.VBAA_RENDERING_BIT; final boolean lowPerfDevice = gl.isGLES(); - textRendererGLEL = new InfoTextRendererGLELBase(rmode, lowPerfDevice); - textRendererGLEL.init(drawable); + if( enableTextRendererGLEL ) { + textRendererGLEL = new InfoTextRendererGLELBase(rmode, lowPerfDevice); + textRendererGLEL.init(drawable); + } else { + textRendererGLEL = null; + } } protected void updateInterleavedVBO(final GL gl, final GLArrayDataServer iVBO, final Texture tex, final int eyeNum) { @@ -608,7 +613,9 @@ public class MovieSBSStereo implements StereoGLEventListener { } System.out.println("pR "+mPlayer); - textRendererGLEL.reshape(drawable, x, y, width, height); + if( null != textRendererGLEL ) { + textRendererGLEL.reshape(drawable, 0, 0, width, height); + } } private final float zNear = 0.1f; @@ -666,13 +673,17 @@ public class MovieSBSStereo implements StereoGLEventListener { st.useProgram(gl, true); st.uniform(gl, pmvMatrixUniform); st.useProgram(gl, false); - textRendererGLEL.reshape(drawable, x, y, width, height); + if( null != textRendererGLEL ) { + textRendererGLEL.reshape(drawable, 0, 0, width, height); + } } @Override public void dispose(final GLAutoDrawable drawable) { - textRendererGLEL.dispose(drawable); - textRendererGLEL = null; + if( null != textRendererGLEL ) { + textRendererGLEL.dispose(drawable); + textRendererGLEL = null; + } disposeImpl(drawable, true); } @@ -747,7 +758,7 @@ public class MovieSBSStereo implements StereoGLEventListener { pmvMatrix.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); pmvMatrix.glPushMatrix(); pmvMatrix.glTranslatef(0, 0, zoom); - if(rotate > 0) { + if( rotate > 0) { final float ang = ((System.currentTimeMillis() - startTime) * 360.0f) / 8000.0f; pmvMatrix.glRotatef(ang, 0, 0, 1); } else { @@ -778,7 +789,9 @@ public class MovieSBSStereo implements StereoGLEventListener { st.useProgram(gl, false); pmvMatrix.glPopMatrix(); - textRendererGLEL.display(drawable); + if( null != textRendererGLEL ) { + textRendererGLEL.display(drawable); + } } static class StereoGLMediaEventListener implements GLMediaEventListener { diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/stereo/StereoDemo01.java b/src/test/com/jogamp/opengl/test/junit/jogl/stereo/StereoDemo01.java index 05685c05a..142c941a5 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/stereo/StereoDemo01.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/stereo/StereoDemo01.java @@ -41,7 +41,6 @@ import javax.media.opengl.GLProfile; import jogamp.opengl.util.stereo.GenericStereoDevice; import com.jogamp.common.util.IOUtil; -import com.jogamp.common.util.ReflectionUtil; import com.jogamp.newt.event.KeyAdapter; import com.jogamp.newt.event.KeyEvent; import com.jogamp.newt.opengl.GLWindow; @@ -88,6 +87,16 @@ import com.jogamp.opengl.util.stereo.StereoUtil; * java StereoDemo01 -time 10000000 -filmURI http://whoknows.not/Some_SBS_3D_Movie.mkv * *

+ * In case user likes to utilize the {@link StereoDeviceFactory.DeviceType#Generic Generic} software implementation, + * which is selected {@link StereoDeviceFactory.DeviceType#Default Default} if no other device is available + * or explicit via -device Generic, the user can chose between different generic stereo modes: + *

+ *   mono            : -device Generic -deviceIndex 0
+ *   stereo-sbs      : -device Generic -deviceIndex 1
+ *   stereo-sbs-lense: -device Generic -deviceIndex 2
+ * 
+ *

+ *

* Key 'R' enables/disables the VR's sensors, i.e. head rotation .. *

* @@ -106,7 +115,6 @@ public class StereoDemo01 { static boolean useAutoSwap = false; static String useFilmFile = null; static String useFilmURI = null; - static String stereoRendererListenerName = null; static StereoDeviceFactory.DeviceType deviceType = StereoDeviceFactory.DeviceType.Default; static int deviceIndex = 0; @@ -162,9 +170,6 @@ public class StereoDemo01 { } else if(args[i].equals("-autoSwap")) { i++; useAutoSwap = MiscUtils.atob(args[i], useAutoSwap); - } else if(args[i].equals("-test")) { - i++; - stereoRendererListenerName = args[i]; } else if(args[i].equals("-filmFile")) { i++; useFilmFile = args[i]; @@ -173,13 +178,6 @@ public class StereoDemo01 { useFilmURI = args[i]; } } - if( null != stereoRendererListenerName ) { - try { - final Object stereoRendererListener = ReflectionUtil.createInstance(stereoRendererListenerName, null); - } catch (final Exception e) { - e.printStackTrace(); - } - } final StereoGLEventListener upstream; final MovieSBSStereo movieSimple; final URI movieURI; @@ -256,10 +254,10 @@ public class StereoDemo01 { final PointImmutable devicePos = stereoDevice.getPosition(); final DimensionImmutable deviceRes = stereoDevice.getSurfaceSize(); - window.setSize(deviceRes.getWidth(), deviceRes.getHeight()); if( useStereoScreen ) { window.setPosition(devicePos.getX(), devicePos.getY()); } + window.setSurfaceSize(deviceRes.getWidth(), deviceRes.getHeight()); // might be not correct .. window.setAutoSwapBufferMode(useAutoSwap); window.setUndecorated(true); @@ -281,8 +279,9 @@ public class StereoDemo01 { System.err.println("Default Fov[1]: "+defaultEyeFov[1].toStringInDegrees()); } - final float[] eyePositionOffset = null == movieSimple || isGenericDevice ? stereoDevice.getDefaultEyePositionOffset() // default - : new float[] { 0f, 0.3f, 0f }; // better fixed movie position + final boolean usesLenses = 0 != ( StereoDeviceRenderer.DISTORTION_BARREL & stereoDevice.getMinimumDistortionBits() ); + final float[] eyePositionOffset = null != movieSimple && usesLenses ? new float[] { 0f, 0.3f, 0f } // better fixed movie position w/ lenses + : stereoDevice.getDefaultEyePositionOffset(); // default System.err.println("Eye Position Offset: "+Arrays.toString(eyePositionOffset)); final int textureUnit = 0; @@ -338,6 +337,15 @@ public class StereoDemo01 { animator.start(); } window.setVisible(true); + + // Correct window size to actual pixel size, + // which ration is unknown before window creation when using multiple displays! + System.err.println("Window.0.windowSize : "+window.getWidth()+" x "+window.getHeight()); + System.err.println("Window.0.surfaceSize: "+window.getSurfaceWidth()+" x "+window.getSurfaceHeight()); + window.setSurfaceSize(deviceRes.getWidth(), deviceRes.getHeight()); + System.err.println("Window.1.windowSize : "+window.getWidth()+" x "+window.getHeight()); + System.err.println("Window.1.surfaceSize: "+window.getSurfaceWidth()+" x "+window.getSurfaceHeight()); + if( useAnimator ) { animator.setUpdateFPSFrames(60, System.err); } -- cgit v1.2.3