JOGL v2.6.0-rc-20250706
JOGL, High-Performance Graphics Binding for Java™ (public API).
StereoDeviceUtil.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.newt.opengl.util.stereo;
29
30import java.util.List;
31
32import com.jogamp.nativewindow.util.Dimension;
33import com.jogamp.nativewindow.util.DimensionImmutable;
34import com.jogamp.nativewindow.util.PointImmutable;
35import com.jogamp.nativewindow.util.Rectangle;
36import com.jogamp.nativewindow.util.RectangleImmutable;
37
38import com.jogamp.newt.Display;
39import com.jogamp.newt.MonitorDevice;
40import com.jogamp.newt.MonitorMode;
41import com.jogamp.newt.NewtFactory;
42import com.jogamp.newt.Screen;
43import com.jogamp.newt.util.MonitorModeUtil;
44import com.jogamp.opengl.util.stereo.StereoDevice;
45
46/**
47 * {@link StereoDevice} NEWT related utilities.
48 */
49public class StereoDeviceUtil {
50 /**
51 * Returns the {@link StereoDevice}'s associated {@link MonitorDevice} or {@code null}, if none is attached.
52 * <p>
53 * The returned {@link MonitorDevice}'s {@link Screen}, retrieved via {@link MonitorDevice#getScreen()},
54 * has been natively created via {@link Screen#addReference()} and caller shall ensure
55 * {@link Screen#removeReference()} will be called when no more in use.
56 * </p>
57 * <p>
58 * If {@code adjustRotation} is {@code true} and the {@link StereoDevice}
59 * {@link StereoDevice#getRequiredRotation() requires rotation}, the {@link MonitorDevice}
60 * will be rotated.
61 * </p>
62 * @param stereoDevice the {@link StereoDevice}
63 * @param adjustRotation if {@code true} rotate the {@link MonitorDevice} if {@link StereoDevice#getRequiredRotation() required}.
64 */
65 public static MonitorDevice getMonitorDevice(final StereoDevice stereoDevice, final boolean adjustRotation) {
66 final PointImmutable devicePos = stereoDevice.getPosition();
67 final DimensionImmutable deviceRes = stereoDevice.getSurfaceSize();
68 final int deviceReqRotation = stereoDevice.getRequiredRotation();
69 final RectangleImmutable rect = new Rectangle(devicePos.getX(), devicePos.getY(), 128, 128);
70
71 final Display display = NewtFactory.createDisplay(null);
72 final Screen screen = NewtFactory.createScreen(display, 0);
73 screen.addReference();
74 final MonitorDevice monitor = screen.getMainMonitor(rect);
75 System.err.println("StereoDevice Monitor: "+monitor);
76 final MonitorMode currentMode = monitor.getCurrentMode();
77 if( adjustRotation && deviceReqRotation != currentMode.getRotation() ) {
78 System.err.println("StereoDevice Current Mode: "+currentMode+", requires rotation: "+deviceReqRotation);
79 final DimensionImmutable deviceRotRes;
80 if( 90 == deviceReqRotation || 270 == deviceReqRotation ) {
81 deviceRotRes = new Dimension(deviceRes.getHeight(), deviceRes.getWidth());
82 } else {
83 deviceRotRes = deviceRes;
84 }
85 final List<MonitorMode> mmodes0 = monitor.getSupportedModes();
86 final List<MonitorMode> mmodes1 = MonitorModeUtil.filterByResolution(mmodes0, deviceRotRes);
87 final List<MonitorMode> mmodes2 = MonitorModeUtil.filterByRotation(mmodes1, deviceReqRotation);
88 if( mmodes2.size() > 0 ) {
89 final MonitorMode newMode = mmodes2.get(0);
90 System.err.println("StereoDevice Set Mode: "+newMode);
91 monitor.setCurrentMode(newMode);
92 }
93 final MonitorMode queriedMode = monitor.queryCurrentMode();
94 System.err.println("StereoDevice Post-Set Mode: "+queriedMode);
95 } else {
96 System.err.println("StereoDevice Keeps Mode: "+currentMode);
97 }
98 return monitor;
99 }
100}
Visual output device, i.e.
final MonitorMode getCurrentMode()
Returns the cached current MonitorMode w/o native query.
abstract MonitorMode queryCurrentMode()
Returns the current MonitorMode resulting from a native query.
abstract boolean setCurrentMode(MonitorMode mode)
Set the current com.jogamp.newt.MonitorMode.
final List< MonitorMode > getSupportedModes()
Returns a list of immutable MonitorModes supported by this monitor.
Immutable MonitorMode Class, consisting of it's read only components:
final int getRotation()
Returns the CCW rotation of this mode.
static Display createDisplay(final String name)
Create a Display entity.
static Screen createScreen(final Display display, final int index)
Create a Screen entity.
A screen may span multiple MonitorDevices representing their combined virtual size.
Definition: Screen.java:58
abstract int addReference()
See Display#addReference().
final MonitorDevice getMainMonitor(final RectangleImmutable r)
Returns the MonitorDevice with the highest viewport coverage of the given rectangle in window units,...
Definition: Screen.java:227
static MonitorDevice getMonitorDevice(final StereoDevice stereoDevice, final boolean adjustRotation)
Returns the StereoDevice's associated MonitorDevice or null, if none is attached.
Convenient com.jogamp.newt.MonitorMode utility methods, filters etc.
static List< MonitorMode > filterByResolution(final List< MonitorMode > monitorModes, final DimensionImmutable resolution)
static List< MonitorMode > filterByRotation(final List< MonitorMode > monitorModes, final int rotation)
Immutable Dimension Interface, consisting of it's read only components:
Immutable Rectangle interface, with its position on the top-left.
Interface describing a native stereoscopic device.
DimensionImmutable getSurfaceSize()
Returns the required surface size in pixel in target space.
PointImmutable getPosition()
If operation within a device spanning virtual desktop, returns the device position.
int getRequiredRotation()
Returns the CCW rotation as required by this display device.