rev |
line source |
nuclear@0
|
1 /*******************************************************************************
|
nuclear@0
|
2
|
nuclear@0
|
3 Filename : OVR_Linux_SDKWindow.h
|
nuclear@0
|
4 Content : SDK generated Linux window.
|
nuclear@0
|
5 Created : October 1, 2014
|
nuclear@0
|
6 Authors : James Hughes
|
nuclear@0
|
7
|
nuclear@0
|
8 Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved.
|
nuclear@0
|
9
|
nuclear@0
|
10 Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License");
|
nuclear@0
|
11 you may not use the Oculus VR Rift SDK except in compliance with the License,
|
nuclear@0
|
12 which is provided at the time of installation or download, or which
|
nuclear@0
|
13 otherwise accompanies this software in either electronic or hard copy form.
|
nuclear@0
|
14
|
nuclear@0
|
15 You may obtain a copy of the License at
|
nuclear@0
|
16
|
nuclear@0
|
17 http://www.oculusvr.com/licenses/LICENSE-3.2
|
nuclear@0
|
18
|
nuclear@0
|
19 Unless required by applicable law or agreed to in writing, the Oculus VR SDK
|
nuclear@0
|
20 distributed under the License is distributed on an "AS IS" BASIS,
|
nuclear@0
|
21 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
nuclear@0
|
22 See the License for the specific language governing permissions and
|
nuclear@0
|
23 limitations under the License.
|
nuclear@0
|
24
|
nuclear@0
|
25 *******************************************************************************/
|
nuclear@0
|
26
|
nuclear@0
|
27 #ifndef OVR_Linux_SDKWindow_h
|
nuclear@0
|
28 #define OVR_Linux_SDKWindow_h
|
nuclear@0
|
29
|
nuclear@0
|
30 #include "../OVR_CAPI.h"
|
nuclear@0
|
31 #include "../CAPI/GL/CAPI_GL_Util.h"
|
nuclear@0
|
32
|
nuclear@0
|
33 #include <X11/Xlib.h>
|
nuclear@0
|
34 #include <X11/Xatom.h>
|
nuclear@0
|
35 #include <X11/extensions/Xrandr.h>
|
nuclear@0
|
36 #include <X11/Xresource.h>
|
nuclear@0
|
37 #include <GL/glx.h>
|
nuclear@0
|
38
|
nuclear@0
|
39 namespace OVR {
|
nuclear@0
|
40
|
nuclear@0
|
41 enum DistortionRotation
|
nuclear@0
|
42 {
|
nuclear@0
|
43 DistRotateNone,
|
nuclear@0
|
44 DistRotateCCW90
|
nuclear@0
|
45 };
|
nuclear@0
|
46
|
nuclear@0
|
47 struct LinuxDeviceScreen
|
nuclear@0
|
48 {
|
nuclear@0
|
49 LinuxDeviceScreen() :
|
nuclear@0
|
50 screen(-1),
|
nuclear@0
|
51 crtcid(0),
|
nuclear@0
|
52 rotation(DistRotateNone),
|
nuclear@0
|
53 productCode(-1),
|
nuclear@0
|
54 width(-1),
|
nuclear@0
|
55 height(-1),
|
nuclear@0
|
56 offsetX(-1),
|
nuclear@0
|
57 offsetY(-1)
|
nuclear@0
|
58 {}
|
nuclear@0
|
59
|
nuclear@0
|
60 void set(int xScreen, XID xid, DistortionRotation rot, int prodCode,
|
nuclear@0
|
61 int w, int h, int x, int y)
|
nuclear@0
|
62 {
|
nuclear@0
|
63 screen = xScreen;
|
nuclear@0
|
64 crtcid = xid;
|
nuclear@0
|
65 rotation = rot;
|
nuclear@0
|
66 productCode = prodCode;
|
nuclear@0
|
67
|
nuclear@0
|
68 width = w;
|
nuclear@0
|
69 height = h;
|
nuclear@0
|
70 offsetX = x;
|
nuclear@0
|
71 offsetY = y;
|
nuclear@0
|
72 }
|
nuclear@0
|
73
|
nuclear@0
|
74 bool isValid() {return (screen != -1);}
|
nuclear@0
|
75
|
nuclear@0
|
76 int screen; ///< X Screen this device occupies.
|
nuclear@0
|
77 XID crtcid; ///< XID uniquely identifying this device on XDisplay.
|
nuclear@0
|
78 DistortionRotation rotation;
|
nuclear@0
|
79 int productCode;
|
nuclear@0
|
80
|
nuclear@0
|
81 // Actual width and height of screen.
|
nuclear@0
|
82 int width;
|
nuclear@0
|
83 int height;
|
nuclear@0
|
84
|
nuclear@0
|
85 // Offset if using twinview
|
nuclear@0
|
86 int offsetX;
|
nuclear@0
|
87 int offsetY;
|
nuclear@0
|
88 };
|
nuclear@0
|
89
|
nuclear@0
|
90 class SDKWindow
|
nuclear@0
|
91 {
|
nuclear@0
|
92 public:
|
nuclear@0
|
93
|
nuclear@0
|
94 SDKWindow(const ovrHmd& hmd);
|
nuclear@0
|
95 ~SDKWindow();
|
nuclear@0
|
96
|
nuclear@0
|
97 /// Rotation necessary to correctly orient this SDK window.
|
nuclear@0
|
98 DistortionRotation GetDistortionRotation() {return mDeviceScreen.rotation;}
|
nuclear@0
|
99
|
nuclear@0
|
100 struct _XDisplay* GetDisplay() {return mXDisplay;}
|
nuclear@0
|
101 XVisualInfo* GetVisual() {return mXVisual;}
|
nuclear@0
|
102 Window GetDrawable() {return mXWindow;}
|
nuclear@0
|
103 bool HasValidWindow() {return (mXWindow != 0);}
|
nuclear@0
|
104
|
nuclear@0
|
105 // Choose frame buffer configuration and return fbConfigID. Returns -1 if
|
nuclear@0
|
106 // a failure occurs.
|
nuclear@0
|
107 static int chooseFBConfigID(struct _XDisplay* display, int xscreen);
|
nuclear@0
|
108
|
nuclear@0
|
109 // Obtain visual from frame buffer configuration ID. You must call XFree
|
nuclear@0
|
110 // on the XVisualInfo* pointer.
|
nuclear@0
|
111 static XVisualInfo* getVisual(struct _XDisplay* display,
|
nuclear@0
|
112 int fbConfigID, int xscreen);
|
nuclear@0
|
113
|
nuclear@0
|
114 // GLXFBConfig pointer from frame buffer configuration ID. You must call
|
nuclear@0
|
115 // XFree on the GLXFBConfig pointer.
|
nuclear@0
|
116 static GLXFBConfig* getGLXFBConfig(struct _XDisplay* display,
|
nuclear@0
|
117 int fbConfigID, int xscreen);
|
nuclear@0
|
118
|
nuclear@0
|
119 static LinuxDeviceScreen findDevScreenForHMD(const ovrHmd& hmd);
|
nuclear@0
|
120 static LinuxDeviceScreen findDevScreenForDevID(const char* deviceID);
|
nuclear@0
|
121
|
nuclear@0
|
122 static DistortionRotation getRotation(const ovrHmd& hmd);
|
nuclear@0
|
123
|
nuclear@0
|
124 // Obtains XVisualInfo for currently bound context. Returns true if a
|
nuclear@0
|
125 // visual was successfully obtained. False otherwise.
|
nuclear@0
|
126 static bool getVisualFromDrawable(GLXDrawable drawable, XVisualInfo* vinfoOut);
|
nuclear@0
|
127
|
nuclear@0
|
128 private:
|
nuclear@0
|
129
|
nuclear@0
|
130 /// Constructs SDK window on the given device screen.
|
nuclear@0
|
131 void buildVisualAndWindow(const LinuxDeviceScreen& devScreen);
|
nuclear@0
|
132
|
nuclear@0
|
133 // Added m in front of variables so as to not conflict with X names.
|
nuclear@0
|
134 struct _XDisplay* mXDisplay;
|
nuclear@0
|
135 int mXScreen;
|
nuclear@0
|
136 XVisualInfo* mXVisual;
|
nuclear@0
|
137 XContext mXUniqueContext;
|
nuclear@0
|
138 Window mXWindow;
|
nuclear@0
|
139 int mFBConfigID;
|
nuclear@0
|
140
|
nuclear@0
|
141 LinuxDeviceScreen mDeviceScreen;
|
nuclear@0
|
142 };
|
nuclear@0
|
143
|
nuclear@0
|
144
|
nuclear@0
|
145 } // namespace OVR
|
nuclear@0
|
146
|
nuclear@0
|
147 #endif // OVR_Linux_SDKWindow_h
|