From 38e51e4a5f6f35c658df10f6d48a33e3ffaea2f3 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Mon, 7 Jul 2014 23:46:19 +0200 Subject: Bug 1021: Add GenericStereoDevice* Supporting custom configurations; Hook-in oculusvr-sdk java distortion-mesh calculation if available StereoDeviceFactory support new GenericStereoDeviceFactory, with it's GenericStereoDevice and GenericStereoDeviceRenderer. GenericStereoDevice maintains different configurations, triggered either by passing a GenericStereoDevice.Config instance directly or by the device-index parameter: - 0: monoscopi device: No post-processing - 1: stereoscopic device SBS: No post-processing - 2: stereoscopic device SBS + Lenses: Distortion post-processing (only available w/ oculusvr-sdk sub-module) Producing a 'GenericStereoDevice.Config' instance is self containing and may extend if supporting more device types like top-bottom, interlaced etc. StereoDemo01 handles all use-cases and may be used as a test-bed to add and experiment with stereoscopy, devices and settings. --- .../jogamp/opengl/oculusvr/OVRStereoDevice.java | 64 +++++++++- .../opengl/oculusvr/OVRStereoDeviceFactory.java | 3 +- .../opengl/oculusvr/OVRStereoDeviceRenderer.java | 134 ++++++++++++--------- .../classes/jogamp/opengl/oculusvr/OVRUtil.java | 19 ++- 4 files changed, 152 insertions(+), 68 deletions(-) (limited to 'src/oculusvr/classes/jogamp/opengl') diff --git a/src/oculusvr/classes/jogamp/opengl/oculusvr/OVRStereoDevice.java b/src/oculusvr/classes/jogamp/opengl/oculusvr/OVRStereoDevice.java index 09a348c46..2832012e4 100644 --- a/src/oculusvr/classes/jogamp/opengl/oculusvr/OVRStereoDevice.java +++ b/src/oculusvr/classes/jogamp/opengl/oculusvr/OVRStereoDevice.java @@ -42,19 +42,50 @@ import com.jogamp.oculusvr.ovrSizei; import com.jogamp.opengl.math.FovHVHalves; import com.jogamp.opengl.util.stereo.StereoDevice; import com.jogamp.opengl.util.stereo.StereoDeviceRenderer; +import com.jogamp.opengl.util.stereo.StereoUtil; public class OVRStereoDevice implements StereoDevice { + /** 1.6 up, 5 forward */ + private static final float[] DEFAULT_EYE_POSITION_OFFSET = { 0.0f, 1.6f, -5.0f }; + public final OvrHmdContext handle; public final int deviceIndex; public final ovrHmdDesc hmdDesc; + private final FovHVHalves[] defaultEyeFov; private boolean sensorsStarted = false; + private final int[] eyeRenderOrder; + private final int supportedDistortionBits, recommendedDistortionBits, minimumDistortionBits; public OVRStereoDevice(final OvrHmdContext nativeContext, final int deviceIndex) { this.handle = nativeContext; this.deviceIndex = deviceIndex; this.hmdDesc = ovrHmdDesc.create(); OVR.ovrHmd_GetDesc(handle, hmdDesc); + final ovrFovPort[] defaultOVREyeFov = hmdDesc.getDefaultEyeFov(0, new ovrFovPort[hmdDesc.getEyeRenderOrderArrayLength()]); + defaultEyeFov = new FovHVHalves[defaultOVREyeFov.length]; + for(int i=0; i vboPos.setLocation(gl, sp.program()) ) { - throw new OVRException("Couldn't locate "+vboPos); + throw new GLException("Couldn't locate "+vboPos); } if( 0 > vboParams.setLocation(gl, sp.program()) ) { - throw new OVRException("Couldn't locate "+vboParams); + throw new GLException("Couldn't locate "+vboParams); } if( 0 > vboTexCoordsR.setLocation(gl, sp.program()) ) { - throw new OVRException("Couldn't locate "+vboTexCoordsR); + throw new GLException("Couldn't locate "+vboTexCoordsR); } if( StereoUtil.usesChromaticDistortion(distortionBits) ) { if( 0 > vboTexCoordsG.setLocation(gl, sp.program()) ) { - throw new OVRException("Couldn't locate "+vboTexCoordsG); + throw new GLException("Couldn't locate "+vboTexCoordsG); } if( 0 > vboTexCoordsB.setLocation(gl, sp.program()) ) { - throw new OVRException("Couldn't locate "+vboTexCoordsB); + throw new GLException("Couldn't locate "+vboTexCoordsB); } } if( 0 > eyeToSourceUVScale.setLocation(gl, sp.program()) ) { - throw new OVRException("Couldn't locate "+eyeToSourceUVScale); + throw new GLException("Couldn't locate "+eyeToSourceUVScale); } if( 0 > eyeToSourceUVOffset.setLocation(gl, sp.program()) ) { - throw new OVRException("Couldn't locate "+eyeToSourceUVOffset); + throw new GLException("Couldn't locate "+eyeToSourceUVOffset); } if( StereoUtil.usesTimewarpDistortion(distortionBits) ) { if( 0 > eyeRotationStart.setLocation(gl, sp.program()) ) { - throw new OVRException("Couldn't locate "+eyeRotationStart); + throw new GLException("Couldn't locate "+eyeRotationStart); } if( 0 > eyeRotationEnd.setLocation(gl, sp.program()) ) { - throw new OVRException("Couldn't locate "+eyeRotationEnd); + throw new GLException("Couldn't locate "+eyeRotationEnd); } } iVBO.seal(gl, true); @@ -368,17 +397,17 @@ public class OVRStereoDeviceRenderer implements StereoDeviceRenderer { private static int distBits2OVRDistCaps(final int distortionBits) { - int bits = 0; + int caps = 0; if( StereoUtil.usesTimewarpDistortion(distortionBits) ) { - bits |= OVR.ovrDistortionCap_TimeWarp; + caps |= OVR.ovrDistortionCap_TimeWarp; } if( StereoUtil.usesChromaticDistortion(distortionBits) ) { - bits |= OVR.ovrDistortionCap_Chromatic; + caps |= OVR.ovrDistortionCap_Chromatic; } if( StereoUtil.usesVignetteDistortion(distortionBits) ) { - bits |= OVR.ovrDistortionCap_Vignette; + caps |= OVR.ovrDistortionCap_Vignette; } - return bits; + return caps; } /* pp */ OVRStereoDeviceRenderer(final OVRStereoDevice context, final int distortionBits, @@ -390,7 +419,7 @@ public class OVRStereoDeviceRenderer implements StereoDeviceRenderer { } this.context = context; this.eyes = new OVREye[2]; - this.distortionBits = distortionBits | StereoDeviceRenderer.DISTORTION_BARREL /* always */; + this.distortionBits = ( distortionBits | context.getMinimumDistortionBits() ) & context.getSupportedDistortionBits(); this.textureCount = textureCount; this.singleTextureSize = singleTextureSize; this.totalTextureSize = totalTextureSize; @@ -428,7 +457,7 @@ public class OVRStereoDeviceRenderer implements StereoDeviceRenderer { public final int getTextureUnit() { return texUnit0.intValue(); } @Override - public final boolean ppRequired() { return true; } + public final boolean ppAvailable() { return 0 != distortionBits; } @Override public final void init(final GL gl) { @@ -554,21 +583,6 @@ public class OVRStereoDeviceRenderer implements StereoDeviceRenderer { gl2es2.glUniform(texUnit0); } - @Override - public final void ppBothEyes(final GL gl) { - final GL2ES2 gl2es2 = gl.getGL2ES2(); - for(int eyeNum=0; eyeNum<2; eyeNum++) { - final OVREye eye = eyes[eyeNum]; - if( StereoUtil.usesTimewarpDistortion(distortionBits) ) { - eye.updateTimewarp(context.handle, eye.ovrEyePose, mat4Tmp1, mat4Tmp2); - } - eye.updateUniform(gl2es2, sp); - eye.enableVBO(gl2es2, true); - gl2es2.glDrawElements(GL.GL_TRIANGLES, eye.indexCount, GL.GL_UNSIGNED_SHORT, 0); - eyes[eyeNum].enableVBO(gl2es2, false); - } - } - @Override public final void ppOneEye(final GL gl, final int eyeNum) { final OVREye eye = eyes[eyeNum]; diff --git a/src/oculusvr/classes/jogamp/opengl/oculusvr/OVRUtil.java b/src/oculusvr/classes/jogamp/opengl/oculusvr/OVRUtil.java index 48222ea97..44ec728fc 100644 --- a/src/oculusvr/classes/jogamp/opengl/oculusvr/OVRUtil.java +++ b/src/oculusvr/classes/jogamp/opengl/oculusvr/OVRUtil.java @@ -33,6 +33,7 @@ import javax.media.nativewindow.util.Point; import javax.media.nativewindow.util.PointImmutable; import javax.media.nativewindow.util.RectangleImmutable; +import com.jogamp.oculusvr.OVR; import com.jogamp.oculusvr.ovrEyeRenderDesc; import com.jogamp.oculusvr.ovrFovPort; import com.jogamp.oculusvr.ovrQuatf; @@ -43,6 +44,7 @@ import com.jogamp.oculusvr.ovrVector2i; import com.jogamp.oculusvr.ovrVector3f; import com.jogamp.opengl.math.FovHVHalves; import com.jogamp.opengl.math.Quaternion; +import com.jogamp.opengl.util.stereo.StereoDeviceRenderer; /** * OculusVR Data Conversion Helper Functions @@ -122,7 +124,7 @@ public class OVRUtil { } public static ovrFovPort getOVRFovPort(final FovHVHalves fovHVHalves) { final ovrFovPort tanHalfFov = ovrFovPort.create(); - final FovHVHalves fovHVHalvesTan = fovHVHalves.getInTangents(); + final FovHVHalves fovHVHalvesTan = fovHVHalves.toTangents(); tanHalfFov.setLeftTan(fovHVHalvesTan.left); tanHalfFov.setRightTan(fovHVHalvesTan.right); tanHalfFov.setUpTan(fovHVHalvesTan.top); @@ -130,6 +132,21 @@ public class OVRUtil { return tanHalfFov; } + public static int ovrDistCaps2DistBits(final int ovrDistortionCaps) { + int bits = StereoDeviceRenderer.DISTORTION_BARREL; + if( 0 != ( OVR.ovrDistortionCap_TimeWarp & ovrDistortionCaps ) ) { + bits |= StereoDeviceRenderer.DISTORTION_TIMEWARP; + } + if( 0 != ( OVR.ovrDistortionCap_Chromatic & ovrDistortionCaps ) ) { + bits |= StereoDeviceRenderer.DISTORTION_CHROMATIC; + } + if( 0 != ( OVR.ovrDistortionCap_Vignette & ovrDistortionCaps ) ) { + bits |= StereoDeviceRenderer.DISTORTION_VIGNETTE; + } + return bits; + } + + public static String toString(final ovrFovPort fov) { return "["+fov.getLeftTan()+" l, "+fov.getRightTan()+" r, "+ fov.getUpTan()+" u, "+fov.getDownTan()+" d]"; -- cgit v1.2.3