JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
GenericStereoDeviceFactory.java
Go to the documentation of this file.
1/**
2 * Copyright 2014 JogAmp Community. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are
5 * permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * The views and conclusions contained in the software and documentation are those of the
25 * authors and should not be interpreted as representing official policies, either expressed
26 * or implied, of JogAmp Community.
27 */
28package com.jogamp.opengl.util.stereo.generic;
29
30import jogamp.opengl.util.stereo.DistortionMesh;
31import jogamp.opengl.util.stereo.GenericStereoDevice;
32
33import com.jogamp.common.util.ReflectionUtil;
34import com.jogamp.math.FloatUtil;
35import com.jogamp.math.FovHVHalves;
36import com.jogamp.math.Vec3f;
37import com.jogamp.nativewindow.util.Dimension;
38import com.jogamp.nativewindow.util.DimensionImmutable;
39import com.jogamp.opengl.util.stereo.EyeParameter;
40import com.jogamp.opengl.util.stereo.StereoDevice;
41import com.jogamp.opengl.util.stereo.StereoDeviceConfig;
42import com.jogamp.opengl.util.stereo.StereoDeviceFactory;
43import com.jogamp.opengl.util.stereo.StereoDeviceRenderer;
44import com.jogamp.opengl.util.stereo.StereoUtil;
45
47
48 /**
49 * Create a generic monoscopic {@link GenericStereoDeviceConfig generic device config}.
50 * @param name
51 * @param surfaceSizeInPixel
52 * @param screenSizeInMeters
53 * @param defaultEyePositionOffset
54 */
55 public static GenericStereoDeviceConfig createMono(final String name,
56 final DimensionImmutable surfaceSizeInPixel, final float[] screenSizeInMeters,
57 final Vec3f defaultEyePositionOffset) {
58 final float pupilCenterFromScreenTopInMeters = screenSizeInMeters[1] / 2f;
59 final float d2r = FloatUtil.PI / 180.0f;
61 name,
63 surfaceSizeInPixel, // resolution
64 screenSizeInMeters, // screenSize [m]
65 new DimensionImmutable[] { surfaceSizeInPixel }, // eye textureSize
66 pupilCenterFromScreenTopInMeters, // pupilCenterFromScreenTop [m]
67 0f, // IPD [m]
68 new int[] { 0 }, // eye order
69 new EyeParameter[] {
70 new EyeParameter(0, defaultEyePositionOffset,
71 // degrees: 45/2 l, 45/2 r, 45/2 * aspect t, 45/2 * aspect b
72 FovHVHalves.byFovyRadianAndAspect(45f*d2r, 1280f / 800f),
73 0f /* distNoseToPupil */, 0f /* verticalDelta */, 0f /* eyeReliefInMeters */) },
74 0, // supported sensor bits
75 null, // mash producer distortion bits
76 0, // supported distortion bits
77 0, // recommended distortion bits
78 0 // minimum distortion bits
79 );
80 }
81
82 /**
83 * Create a generic homogenous side-by-side stereoscopic {@link GenericStereoDeviceConfig generic device config}.
84 * @param name
85 * @param surfaceSizeInPixel
86 * @param screenSizeInMeters
87 * @param interpupillaryDistanceInMeters
88 * @param fovy
89 * @param defaultEyePositionOffset
90 */
91 public static GenericStereoDeviceConfig createStereoSBS(final String name,
92 final DimensionImmutable surfaceSizeInPixel, final float[] screenSizeInMeters,
93 final float interpupillaryDistanceInMeters, final float fovy,
94 final Vec3f defaultEyePositionOffset) {
95 final float pupilCenterFromScreenTopInMeters = screenSizeInMeters[1] / 2f;
96 final float d2r = FloatUtil.PI / 180.0f;
97
98 final DimensionImmutable eyeTextureSize = new Dimension(surfaceSizeInPixel.getWidth()/2, surfaceSizeInPixel.getHeight());
99 final float[] horizPupilCenterFromLeft = StereoUtil.getHorizPupilCenterFromLeft(screenSizeInMeters[0], interpupillaryDistanceInMeters);
100 final float vertPupilCenterFromTop = StereoUtil.getVertPupilCenterFromTop(screenSizeInMeters[1], pupilCenterFromScreenTopInMeters);
101 final float aspect = (float)eyeTextureSize.getWidth() / (float)eyeTextureSize.getHeight();
102 final FovHVHalves defaultSBSEyeFovLeft = FovHVHalves.byFovyRadianAndAspect(fovy * d2r, vertPupilCenterFromTop, aspect, horizPupilCenterFromLeft[0]);
103 final FovHVHalves defaultSBSEyeFovRight = FovHVHalves.byFovyRadianAndAspect(fovy * d2r, vertPupilCenterFromTop, aspect, horizPupilCenterFromLeft[1]);
104
105 return new GenericStereoDeviceConfig(
106 name,
108 surfaceSizeInPixel, // resolution
109 screenSizeInMeters, // screenSize [m]
110 new DimensionImmutable[] { eyeTextureSize, eyeTextureSize }, // eye textureSize
111 pupilCenterFromScreenTopInMeters, // pupilCenterFromScreenTop [m]
112 interpupillaryDistanceInMeters, // IPD [m]
113 new int[] { 0, 1 }, // eye order
114 new EyeParameter[] {
115 new EyeParameter(0, defaultEyePositionOffset, defaultSBSEyeFovLeft,
116 interpupillaryDistanceInMeters/2f /* distNoseToPupil */, 0f /* verticalDelta */, 0.010f /* eyeReliefInMeters */),
117 new EyeParameter(1, defaultEyePositionOffset, defaultSBSEyeFovRight,
118 -interpupillaryDistanceInMeters/2f /* distNoseToPupil */, 0f /* verticalDelta */, 0.010f /* eyeReliefInMeters */) },
119 0, // supported sensor bits
120 null, // mash producer distortion bits
121 0, // supported distortion bits
122 0, // recommended distortion bits
123 0 // minimum distortion bits
124 );
125
126 }
127
128 /**
129 * Create a generic lense distorted side-by-side stereoscopic {@link GenericStereoDeviceConfig generic device config}.
130 * @param name
131 * @param surfaceSizeInPixel
132 * @param screenSizeInMeters
133 * @param interpupillaryDistanceInMeters
134 * @param fovy
135 * @param eyeTextureSize
136 * @param defaultEyePositionOffset
137 */
138 public static GenericStereoDeviceConfig createStereoSBSLense(final String name,
139 final DimensionImmutable surfaceSizeInPixel, final float[] screenSizeInMeters,
140 final float interpupillaryDistanceInMeters, final float fovy,
141 final DimensionImmutable eyeTextureSize,
142 final Vec3f defaultEyePositionOffset) {
143 DistortionMesh.Producer lenseDistMeshProduce = null;
144 try {
145 lenseDistMeshProduce =
146 (DistortionMesh.Producer)
147 ReflectionUtil.createInstance("jogamp.opengl.oculusvr.stereo.lense.DistortionMeshProducer", GenericStereoDevice.class.getClassLoader());
148 } catch (final Throwable t) {
149 if(StereoDevice.DEBUG) { System.err.println("Caught: "+t.getMessage()); t.printStackTrace(); }
150 }
151 if( null == lenseDistMeshProduce ) {
152 return null;
153 }
154 final float pupilCenterFromScreenTopInMeters = screenSizeInMeters[1] / 2f;
155 final float d2r = FloatUtil.PI / 180.0f;
156
157 final float[] horizPupilCenterFromLeft = StereoUtil.getHorizPupilCenterFromLeft(screenSizeInMeters[0], interpupillaryDistanceInMeters);
158 final float vertPupilCenterFromTop = StereoUtil.getVertPupilCenterFromTop(screenSizeInMeters[1], pupilCenterFromScreenTopInMeters);
159 final float aspect = (float)eyeTextureSize.getWidth() / (float)eyeTextureSize.getHeight();
160 final FovHVHalves defaultSBSEyeFovLeft = FovHVHalves.byFovyRadianAndAspect(fovy * d2r, vertPupilCenterFromTop, aspect, horizPupilCenterFromLeft[0]);
161 final FovHVHalves defaultSBSEyeFovRight = FovHVHalves.byFovyRadianAndAspect(fovy * d2r, vertPupilCenterFromTop, aspect, horizPupilCenterFromLeft[1]);
162
163 return new GenericStereoDeviceConfig(
164 name,
166 surfaceSizeInPixel, // resolution
167 screenSizeInMeters, // screenSize [m]
168 new DimensionImmutable[] { eyeTextureSize, eyeTextureSize }, // eye textureSize
169 pupilCenterFromScreenTopInMeters, // pupilCenterFromScreenTop [m]
170 interpupillaryDistanceInMeters, // IPD [m]
171 new int[] { 0, 1 }, // eye order
172 new EyeParameter[] {
173 new EyeParameter(0, defaultEyePositionOffset, defaultSBSEyeFovLeft,
174 interpupillaryDistanceInMeters/2f /* distNoseToPupil */, 0f /* verticalDelta */, 0.010f /* eyeReliefInMeters */),
175 new EyeParameter(1, defaultEyePositionOffset, defaultSBSEyeFovRight,
176 -interpupillaryDistanceInMeters/2f /* distNoseToPupil */, 0f /* verticalDelta */, 0.010f /* eyeReliefInMeters */) },
177 0, // supported sensor bits
178 lenseDistMeshProduce,
179 // supported distortion bits
181 // recommended distortion bits
183 // minimum distortion bits
185 );
186 }
187
188
189 public static boolean isAvailable() {
190 return true;
191 }
192
193 @Override
194 protected final StereoDevice createDeviceImpl(final int deviceIndex, final StereoDeviceConfig config, final boolean verbose) {
195 return new GenericStereoDevice(this, deviceIndex, config);
196 }
197
198 private boolean isValid = true;
199
200 @Override
201 public boolean isValid() {
202 return isValid;
203 }
204
205 @Override
206 public final void shutdown() {
207 if( isValid ) {
208 // NOP
209 isValid = false;
210 }
211 }
212}
Horizontal and vertical field of view (FOV) halves, allowing a non-centered projection.
static FovHVHalves byFovyRadianAndAspect(final float verticalFov, final float aspect)
Returns a symmetrical centered FovHVHalves instance in inTangents, using:
3D Vector based upon three float components.
Definition: Vec3f.java:37
Constant single eye parameter of the viewer, relative to its ViewerPose.
Merely a class providing a type-tag for extended configuration.
Platform agnostic StereoDevice factory.
static float[] getHorizPupilCenterFromLeft(final float screenWidthInMeters, final float interpupillaryDistanceInMeters)
Return the horizontal pupil center from the left side for both eyes in the range [0....
Definition: StereoUtil.java:60
static float getVertPupilCenterFromTop(final float screenHeightInMeters, final float pupilCenterFromScreenTopInMeters)
Return the vertical pupil center from the screen top in the range [0..1].
Definition: StereoUtil.java:42
static GenericStereoDeviceConfig createStereoSBSLense(final String name, final DimensionImmutable surfaceSizeInPixel, final float[] screenSizeInMeters, final float interpupillaryDistanceInMeters, final float fovy, final DimensionImmutable eyeTextureSize, final Vec3f defaultEyePositionOffset)
Create a generic lense distorted side-by-side stereoscopic generic device config.
final StereoDevice createDeviceImpl(final int deviceIndex, final StereoDeviceConfig config, final boolean verbose)
static GenericStereoDeviceConfig createMono(final String name, final DimensionImmutable surfaceSizeInPixel, final float[] screenSizeInMeters, final Vec3f defaultEyePositionOffset)
Create a generic monoscopic generic device config.
boolean isValid()
Returns true, if instance is created and not shutdown() otherwise returns false.
static GenericStereoDeviceConfig createStereoSBS(final String name, final DimensionImmutable surfaceSizeInPixel, final float[] screenSizeInMeters, final float interpupillaryDistanceInMeters, final float fovy, final Vec3f defaultEyePositionOffset)
Create a generic homogenous side-by-side stereoscopic generic device config.
Immutable Dimension Interface, consisting of it's read only components:
Stereoscopic device rendering interface.
static final int DISTORTION_BARREL
Distortion Bit: Barrel distortion compensating lens pincushion distortion.
static final int DISTORTION_CHROMATIC
Distortion Bit: Chromatic distortion compensating lens chromatic aberration.
static final int DISTORTION_VIGNETTE
Distortion Bit: Vignette distortion compensating lens chromatic aberration.
Interface describing a native stereoscopic device.