nuclear@0: /******************************************************************************* nuclear@0: nuclear@0: Filename : OVR_Linux_SDKWindow.h nuclear@0: Content : SDK generated Linux window. nuclear@0: Created : October 1, 2014 nuclear@0: Authors : James Hughes nuclear@0: nuclear@0: Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved. nuclear@0: nuclear@0: Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License"); nuclear@0: you may not use the Oculus VR Rift SDK except in compliance with the License, nuclear@0: which is provided at the time of installation or download, or which nuclear@0: otherwise accompanies this software in either electronic or hard copy form. nuclear@0: nuclear@0: You may obtain a copy of the License at nuclear@0: nuclear@0: http://www.oculusvr.com/licenses/LICENSE-3.2 nuclear@0: nuclear@0: Unless required by applicable law or agreed to in writing, the Oculus VR SDK nuclear@0: distributed under the License is distributed on an "AS IS" BASIS, nuclear@0: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. nuclear@0: See the License for the specific language governing permissions and nuclear@0: limitations under the License. nuclear@0: nuclear@0: *******************************************************************************/ nuclear@0: nuclear@0: #ifndef OVR_Linux_SDKWindow_h nuclear@0: #define OVR_Linux_SDKWindow_h nuclear@0: nuclear@0: #include "../OVR_CAPI.h" nuclear@0: #include "../CAPI/GL/CAPI_GL_Util.h" nuclear@0: nuclear@0: #include nuclear@0: #include nuclear@0: #include nuclear@0: #include nuclear@0: #include nuclear@0: nuclear@0: namespace OVR { nuclear@0: nuclear@0: enum DistortionRotation nuclear@0: { nuclear@0: DistRotateNone, nuclear@0: DistRotateCCW90 nuclear@0: }; nuclear@0: nuclear@0: struct LinuxDeviceScreen nuclear@0: { nuclear@0: LinuxDeviceScreen() : nuclear@0: screen(-1), nuclear@0: crtcid(0), nuclear@0: rotation(DistRotateNone), nuclear@0: productCode(-1), nuclear@0: width(-1), nuclear@0: height(-1), nuclear@0: offsetX(-1), nuclear@0: offsetY(-1) nuclear@0: {} nuclear@0: nuclear@0: void set(int xScreen, XID xid, DistortionRotation rot, int prodCode, nuclear@0: int w, int h, int x, int y) nuclear@0: { nuclear@0: screen = xScreen; nuclear@0: crtcid = xid; nuclear@0: rotation = rot; nuclear@0: productCode = prodCode; nuclear@0: nuclear@0: width = w; nuclear@0: height = h; nuclear@0: offsetX = x; nuclear@0: offsetY = y; nuclear@0: } nuclear@0: nuclear@0: bool isValid() {return (screen != -1);} nuclear@0: nuclear@0: int screen; ///< X Screen this device occupies. nuclear@0: XID crtcid; ///< XID uniquely identifying this device on XDisplay. nuclear@0: DistortionRotation rotation; nuclear@0: int productCode; nuclear@0: nuclear@0: // Actual width and height of screen. nuclear@0: int width; nuclear@0: int height; nuclear@0: nuclear@0: // Offset if using twinview nuclear@0: int offsetX; nuclear@0: int offsetY; nuclear@0: }; nuclear@0: nuclear@0: class SDKWindow nuclear@0: { nuclear@0: public: nuclear@0: nuclear@0: SDKWindow(const ovrHmd& hmd); nuclear@0: ~SDKWindow(); nuclear@0: nuclear@0: /// Rotation necessary to correctly orient this SDK window. nuclear@0: DistortionRotation GetDistortionRotation() {return mDeviceScreen.rotation;} nuclear@0: nuclear@0: struct _XDisplay* GetDisplay() {return mXDisplay;} nuclear@0: XVisualInfo* GetVisual() {return mXVisual;} nuclear@0: Window GetDrawable() {return mXWindow;} nuclear@0: bool HasValidWindow() {return (mXWindow != 0);} nuclear@0: nuclear@0: // Choose frame buffer configuration and return fbConfigID. Returns -1 if nuclear@0: // a failure occurs. nuclear@0: static int chooseFBConfigID(struct _XDisplay* display, int xscreen); nuclear@0: nuclear@0: // Obtain visual from frame buffer configuration ID. You must call XFree nuclear@0: // on the XVisualInfo* pointer. nuclear@0: static XVisualInfo* getVisual(struct _XDisplay* display, nuclear@0: int fbConfigID, int xscreen); nuclear@0: nuclear@0: // GLXFBConfig pointer from frame buffer configuration ID. You must call nuclear@0: // XFree on the GLXFBConfig pointer. nuclear@0: static GLXFBConfig* getGLXFBConfig(struct _XDisplay* display, nuclear@0: int fbConfigID, int xscreen); nuclear@0: nuclear@0: static LinuxDeviceScreen findDevScreenForHMD(const ovrHmd& hmd); nuclear@0: static LinuxDeviceScreen findDevScreenForDevID(const char* deviceID); nuclear@0: nuclear@0: static DistortionRotation getRotation(const ovrHmd& hmd); nuclear@0: nuclear@0: // Obtains XVisualInfo for currently bound context. Returns true if a nuclear@0: // visual was successfully obtained. False otherwise. nuclear@0: static bool getVisualFromDrawable(GLXDrawable drawable, XVisualInfo* vinfoOut); nuclear@0: nuclear@0: private: nuclear@0: nuclear@0: /// Constructs SDK window on the given device screen. nuclear@0: void buildVisualAndWindow(const LinuxDeviceScreen& devScreen); nuclear@0: nuclear@0: // Added m in front of variables so as to not conflict with X names. nuclear@0: struct _XDisplay* mXDisplay; nuclear@0: int mXScreen; nuclear@0: XVisualInfo* mXVisual; nuclear@0: XContext mXUniqueContext; nuclear@0: Window mXWindow; nuclear@0: int mFBConfigID; nuclear@0: nuclear@0: LinuxDeviceScreen mDeviceScreen; nuclear@0: }; nuclear@0: nuclear@0: nuclear@0: } // namespace OVR nuclear@0: nuclear@0: #endif // OVR_Linux_SDKWindow_h