JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
GenericStereoDeviceConfig.java
Go to the documentation of this file.
1/**
2 * Copyright 2015 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 java.util.Arrays;
31
32import jogamp.opengl.util.stereo.DistortionMesh;
33import jogamp.opengl.util.stereo.GenericStereoDevice;
34
35import com.jogamp.nativewindow.util.DimensionImmutable;
36import com.jogamp.opengl.util.stereo.EyeParameter;
37import com.jogamp.opengl.util.stereo.StereoDeviceConfig;
38import com.jogamp.opengl.util.stereo.StereoDeviceRenderer;
39import com.jogamp.opengl.util.stereo.StereoUtil;
40import com.jogamp.opengl.util.stereo.StereoDevice;
41
42/**
43 * Configuration for {@link GenericStereoDevice}s.
44 */
46 public static enum ShutterType {
47 Global, RollingLeftToRight, RollingRightToLeft, RollingTopToBottom
48 }
49 public GenericStereoDeviceConfig(final String name,
52 final float[] screenSizeInMeters,
53 final DimensionImmutable[/*pre-eye*/] eyeTextureSize,
56 final int[] eyeRenderOrder,
58 final int supportedSensorBits,
59 final DistortionMesh.Producer distortionMeshProducer,
62 final int minimumDistortionBits
63 ) {
64 if( eyeRenderOrder.length != defaultEyeParam.length ) {
65 throw new IllegalArgumentException("eye arrays of different length");
66 }
67 this.name = name;
68 this.shutterType = shutterType;
69 this.surfaceSizeInPixels = surfaceSizeInPixels;
70 this.screenSizeInMeters = screenSizeInMeters;
71 this.eyeTextureSizes = eyeTextureSize;
72 this.pupilCenterFromScreenTopInMeters = pupilCenterFromScreenTopInMeters;
73 this.interpupillaryDistanceInMeters = interpupillaryDistanceInMeters;
74 this.eyeRenderOrder = eyeRenderOrder;
75 this.defaultEyeParam = defaultEyeParam;
76 this.supportedSensorBits = supportedSensorBits;
77 this.distortionMeshProducer = distortionMeshProducer;
78 this.supportedDistortionBits = supportedDistortionBits;
79 this.recommendedDistortionBits = recommendedDistortionBits;
80 this.minimumDistortionBits = minimumDistortionBits;
81 this.pupilCenterFromTopLeft = new float[2][2];
82 calcPupilCenterFromTopLeft();
83 }
84 /** A variation w/ different surface/screen specs */
87 final float[] screenSizeInMeters,
88 final DimensionImmutable[/*pre-eye*/] eyeTextureSize) {
89 this.name = source.name;
90 this.shutterType = source.shutterType;
91 this.surfaceSizeInPixels = surfaceSizeInPixels;
92 this.screenSizeInMeters = screenSizeInMeters;
93 this.eyeTextureSizes = eyeTextureSize;
94 this.pupilCenterFromScreenTopInMeters = source.pupilCenterFromScreenTopInMeters;
95 this.interpupillaryDistanceInMeters = source.interpupillaryDistanceInMeters;
96 this.eyeRenderOrder = source.eyeRenderOrder;
97 this.defaultEyeParam = source.defaultEyeParam;
98 this.supportedSensorBits = source.supportedSensorBits;
99 this.distortionMeshProducer = source.distortionMeshProducer;
100 this.supportedDistortionBits = source.supportedDistortionBits;
101 this.recommendedDistortionBits = source.recommendedDistortionBits;
102 this.minimumDistortionBits = source.minimumDistortionBits;
103 this.pupilCenterFromTopLeft = new float[2][2];
104 calcPupilCenterFromTopLeft();
105 }
106 private void calcPupilCenterFromTopLeft() {
107 final float visibleWidthOfOneEye = 0.5f * screenSizeInMeters[0];
108 final float leftPupilCenterFromLeftInMeters = ( screenSizeInMeters[0] - interpupillaryDistanceInMeters ) * 0.5f;
109 final float rightPupilCenterFromMiddleInMeters = leftPupilCenterFromLeftInMeters + interpupillaryDistanceInMeters - visibleWidthOfOneEye;
110 pupilCenterFromTopLeft[0][0] = leftPupilCenterFromLeftInMeters / visibleWidthOfOneEye;
112 pupilCenterFromTopLeft[1][0] = rightPupilCenterFromMiddleInMeters / visibleWidthOfOneEye;
114 }
115
116 /**
117 * One time lazy initialization before use.
118 * @see #isInitialized()
119 */
120 public synchronized void init() {
121 if( !isInitialized ) {
122 if( null != distortionMeshProducer ) {
123 final float[] eyeReliefInMeters = new float[defaultEyeParam.length];
124 if( 0 < defaultEyeParam.length ) {
125 eyeReliefInMeters[0] = defaultEyeParam[0].eyeReliefZ;
126 }
127 if( 1 < defaultEyeParam.length ) {
128 eyeReliefInMeters[1] = defaultEyeParam[1].eyeReliefZ;
129 }
130 distortionMeshProducer.init(this, eyeReliefInMeters);
131 }
132 isInitialized = true;
133 }
134 }
135 /**
136 * Returns {@code true} if {@link #init() initialized}, otherwise {@code false}.
137 * @see #init()
138 */
139 public final boolean isInitialized() { return isInitialized; }
140
141 @Override
142 public String toString() { return "StereoConfig["+name+", shutter "+shutterType+", surfaceSize "+surfaceSizeInPixels+
143 ", screenSize "+screenSizeInMeters[0]+" x "+screenSizeInMeters[0]+
144 " [m], eyeTexSize "+Arrays.toString(eyeTextureSizes)+", IPD "+interpupillaryDistanceInMeters+
145 " [m], eyeParam "+Arrays.toString(defaultEyeParam)+
146 ", distortionBits[supported ["+StereoUtil.distortionBitsToString(supportedDistortionBits)+
149 ", sensorBits[supported ["+StereoUtil.sensorBitsToString(supportedSensorBits)+"]]]";
150 }
151
152 /** Configuration Name */
153 public final String name;
154 public final GenericStereoDeviceConfig.ShutterType shutterType;
155
157 public final float[] screenSizeInMeters;
158 /** Texture size per eye */
159 public final DimensionImmutable[/*pre-eye*/] eyeTextureSizes;
160
161 /** Vertical distance from pupil to screen-top in meters */
163 /** Horizontal interpupillary distance (IPD) in meters */
165 /**
166 * Pupil center from top left per eye, ranging from [0..1], maybe used to produce FovHVHalves,
167 * see {@link #getHorizPupilCenterFromLeft(float, float)} and {@link #getVertPupilCenterFromTop(float, float)}.
168 */
169 public final float[/*per-eye*/][/*xy*/] pupilCenterFromTopLeft;
170 public final int[] eyeRenderOrder;
172
173 /** Supported sensor bits, see {@link StereoDevice#SENSOR_ORIENTATION}. */
174 public final int supportedSensorBits;
175
176 public final DistortionMesh.Producer distortionMeshProducer;
177
178 /** Supported distortion bits, see {@link StereoDeviceRenderer#DISTORTION_BARREL}. */
179 public final int supportedDistortionBits;
180 /** Recommended distortion bits, see {@link StereoDeviceRenderer.DISTORTION_BARREL}. */
182 /** Required distortion bits, see {@link StereoDeviceRenderer.DISTORTION_BARREL}. */
183 public final int minimumDistortionBits;
184
185 private boolean isInitialized = false;
186}
Constant single eye parameter of the viewer, relative to its ViewerPose.
final float eyeReliefZ
Z-axis eye relief in meter.
Merely a class providing a type-tag for extended configuration.
static String distortionBitsToString(final int distortionBits)
See StereoDeviceRenderer#getDistortionBits().
Definition: StereoUtil.java:78
static String sensorBitsToString(final int sensorBits)
See StereoDevice#getSupportedSensorBits() and StereoDevice#getEnabledSensorBits().
GenericStereoDeviceConfig(final String name, final GenericStereoDeviceConfig.ShutterType shutterType, final DimensionImmutable surfaceSizeInPixels, final float[] screenSizeInMeters, final DimensionImmutable[] eyeTextureSize, final float pupilCenterFromScreenTopInMeters, final float interpupillaryDistanceInMeters, final int[] eyeRenderOrder, final EyeParameter[] defaultEyeParam, final int supportedSensorBits, final DistortionMesh.Producer distortionMeshProducer, final int supportedDistortionBits, final int recommendedDistortionBits, final int minimumDistortionBits)
final float pupilCenterFromScreenTopInMeters
Vertical distance from pupil to screen-top in meters.
GenericStereoDeviceConfig(final GenericStereoDeviceConfig source, final DimensionImmutable surfaceSizeInPixels, final float[] screenSizeInMeters, final DimensionImmutable[] eyeTextureSize)
A variation w/ different surface/screen specs.
final int supportedDistortionBits
Supported distortion bits, see StereoDeviceRenderer#DISTORTION_BARREL.
final boolean isInitialized()
Returns true if initialized, otherwise false.
final float[][] pupilCenterFromTopLeft
Pupil center from top left per eye, ranging from [0..1], maybe used to produce FovHVHalves,...
final float interpupillaryDistanceInMeters
Horizontal interpupillary distance (IPD) in meters.
synchronized void init()
One time lazy initialization before use.
final int minimumDistortionBits
Required distortion bits, see StereoDeviceRenderer.DISTORTION_BARREL.
final int recommendedDistortionBits
Recommended distortion bits, see StereoDeviceRenderer.DISTORTION_BARREL.
final int supportedSensorBits
Supported sensor bits, see StereoDevice#SENSOR_ORIENTATION.
Immutable Dimension Interface, consisting of it's read only components: