ovr_sdk

view LibOVR/Src/Displays/OVR_Linux_SDKWindow.h @ 0:1b39a1b46319

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