ovr_sdk
diff 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 diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/LibOVR/Src/Displays/OVR_Linux_SDKWindow.h Wed Jan 14 06:51:16 2015 +0200 1.3 @@ -0,0 +1,147 @@ 1.4 +/******************************************************************************* 1.5 + 1.6 +Filename : OVR_Linux_SDKWindow.h 1.7 +Content : SDK generated Linux window. 1.8 +Created : October 1, 2014 1.9 +Authors : James Hughes 1.10 + 1.11 +Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved. 1.12 + 1.13 +Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License"); 1.14 +you may not use the Oculus VR Rift SDK except in compliance with the License, 1.15 +which is provided at the time of installation or download, or which 1.16 +otherwise accompanies this software in either electronic or hard copy form. 1.17 + 1.18 +You may obtain a copy of the License at 1.19 + 1.20 +http://www.oculusvr.com/licenses/LICENSE-3.2 1.21 + 1.22 +Unless required by applicable law or agreed to in writing, the Oculus VR SDK 1.23 +distributed under the License is distributed on an "AS IS" BASIS, 1.24 +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1.25 +See the License for the specific language governing permissions and 1.26 +limitations under the License. 1.27 + 1.28 +*******************************************************************************/ 1.29 + 1.30 +#ifndef OVR_Linux_SDKWindow_h 1.31 +#define OVR_Linux_SDKWindow_h 1.32 + 1.33 +#include "../OVR_CAPI.h" 1.34 +#include "../CAPI/GL/CAPI_GL_Util.h" 1.35 + 1.36 +#include <X11/Xlib.h> 1.37 +#include <X11/Xatom.h> 1.38 +#include <X11/extensions/Xrandr.h> 1.39 +#include <X11/Xresource.h> 1.40 +#include <GL/glx.h> 1.41 + 1.42 +namespace OVR { 1.43 + 1.44 +enum DistortionRotation 1.45 +{ 1.46 + DistRotateNone, 1.47 + DistRotateCCW90 1.48 +}; 1.49 + 1.50 +struct LinuxDeviceScreen 1.51 +{ 1.52 + LinuxDeviceScreen() : 1.53 + screen(-1), 1.54 + crtcid(0), 1.55 + rotation(DistRotateNone), 1.56 + productCode(-1), 1.57 + width(-1), 1.58 + height(-1), 1.59 + offsetX(-1), 1.60 + offsetY(-1) 1.61 + {} 1.62 + 1.63 + void set(int xScreen, XID xid, DistortionRotation rot, int prodCode, 1.64 + int w, int h, int x, int y) 1.65 + { 1.66 + screen = xScreen; 1.67 + crtcid = xid; 1.68 + rotation = rot; 1.69 + productCode = prodCode; 1.70 + 1.71 + width = w; 1.72 + height = h; 1.73 + offsetX = x; 1.74 + offsetY = y; 1.75 + } 1.76 + 1.77 + bool isValid() {return (screen != -1);} 1.78 + 1.79 + int screen; ///< X Screen this device occupies. 1.80 + XID crtcid; ///< XID uniquely identifying this device on XDisplay. 1.81 + DistortionRotation rotation; 1.82 + int productCode; 1.83 + 1.84 + // Actual width and height of screen. 1.85 + int width; 1.86 + int height; 1.87 + 1.88 + // Offset if using twinview 1.89 + int offsetX; 1.90 + int offsetY; 1.91 +}; 1.92 + 1.93 +class SDKWindow 1.94 +{ 1.95 +public: 1.96 + 1.97 + SDKWindow(const ovrHmd& hmd); 1.98 + ~SDKWindow(); 1.99 + 1.100 + /// Rotation necessary to correctly orient this SDK window. 1.101 + DistortionRotation GetDistortionRotation() {return mDeviceScreen.rotation;} 1.102 + 1.103 + struct _XDisplay* GetDisplay() {return mXDisplay;} 1.104 + XVisualInfo* GetVisual() {return mXVisual;} 1.105 + Window GetDrawable() {return mXWindow;} 1.106 + bool HasValidWindow() {return (mXWindow != 0);} 1.107 + 1.108 + // Choose frame buffer configuration and return fbConfigID. Returns -1 if 1.109 + // a failure occurs. 1.110 + static int chooseFBConfigID(struct _XDisplay* display, int xscreen); 1.111 + 1.112 + // Obtain visual from frame buffer configuration ID. You must call XFree 1.113 + // on the XVisualInfo* pointer. 1.114 + static XVisualInfo* getVisual(struct _XDisplay* display, 1.115 + int fbConfigID, int xscreen); 1.116 + 1.117 + // GLXFBConfig pointer from frame buffer configuration ID. You must call 1.118 + // XFree on the GLXFBConfig pointer. 1.119 + static GLXFBConfig* getGLXFBConfig(struct _XDisplay* display, 1.120 + int fbConfigID, int xscreen); 1.121 + 1.122 + static LinuxDeviceScreen findDevScreenForHMD(const ovrHmd& hmd); 1.123 + static LinuxDeviceScreen findDevScreenForDevID(const char* deviceID); 1.124 + 1.125 + static DistortionRotation getRotation(const ovrHmd& hmd); 1.126 + 1.127 + // Obtains XVisualInfo for currently bound context. Returns true if a 1.128 + // visual was successfully obtained. False otherwise. 1.129 + static bool getVisualFromDrawable(GLXDrawable drawable, XVisualInfo* vinfoOut); 1.130 + 1.131 +private: 1.132 + 1.133 + /// Constructs SDK window on the given device screen. 1.134 + void buildVisualAndWindow(const LinuxDeviceScreen& devScreen); 1.135 + 1.136 + // Added m in front of variables so as to not conflict with X names. 1.137 + struct _XDisplay* mXDisplay; 1.138 + int mXScreen; 1.139 + XVisualInfo* mXVisual; 1.140 + XContext mXUniqueContext; 1.141 + Window mXWindow; 1.142 + int mFBConfigID; 1.143 + 1.144 + LinuxDeviceScreen mDeviceScreen; 1.145 +}; 1.146 + 1.147 + 1.148 +} // namespace OVR 1.149 + 1.150 +#endif // OVR_Linux_SDKWindow_h