| 
5 | 5 | 	#include <Windows.h>  | 
6 | 6 | 	#pragma comment(lib, "opengl32") // wglGetCurrentDC  | 
7 | 7 | 	#define XR_USE_PLATFORM_WIN32  | 
 | 8 | +	#define GLFW_EXPOSE_NATIVE_WIN32  | 
8 | 9 | #endif // CAGE_SYSTEM_WINDOWS  | 
9 | 10 | 
 
  | 
 | 11 | +#ifdef CAGE_SYSTEM_LINUX  | 
 | 12 | +	#if defined(_GLFW_X11)  | 
 | 13 | +		#define XR_USE_PLATFORM_XLIB  | 
 | 14 | +		#define GLFW_EXPOSE_NATIVE_X11  | 
 | 15 | +	#endif  | 
 | 16 | +	#if defined(_GLFW_WAYLAND)  | 
 | 17 | +		#define XR_USE_PLATFORM_WAYLAND  | 
 | 18 | +		#define GLFW_EXPOSE_NATIVE_WAYLAND  | 
 | 19 | +	#endif  | 
 | 20 | +#endif // CAGE_SYSTEM_LINUX  | 
 | 21 | + | 
 | 22 | +#include <GLFW/glfw3.h>  | 
 | 23 | +#include <GLFW/glfw3native.h>  | 
 | 24 | + | 
10 | 25 | #define XR_USE_GRAPHICS_API_OPENGL  | 
11 | 26 | #include <openxr/openxr_platform.h>  | 
12 | 27 | 
 
  | 
@@ -45,22 +60,38 @@ namespace cage  | 
45 | 60 | 
 
  | 
46 | 61 | #ifdef CAGE_SYSTEM_WINDOWS  | 
47 | 62 | 
 
  | 
 | 63 | +			CAGE_ASSERT(glfwGetPlatform() == GLFW_PLATFORM_WIN32);  | 
48 | 64 | 			XrGraphicsBindingOpenGLWin32KHR binding;  | 
49 | 65 | 			init(binding, XR_TYPE_GRAPHICS_BINDING_OPENGL_WIN32_KHR);  | 
50 | 66 | 			binding.hDC = wglGetCurrentDC();  | 
51 | 67 | 			binding.hGLRC = wglGetCurrentContext();  | 
52 | 68 | 
 
  | 
53 |  | -#else  | 
 | 69 | +#elif defined(XR_USE_PLATFORM_XLIB)  | 
54 | 70 | 
 
  | 
55 |  | -			CAGE_THROW_CRITICAL(Exception, "cage openxr currently works on windows only");  | 
 | 71 | +			if (glfwGetPlatform() != GLFW_PLATFORM_X11)  | 
 | 72 | +				CAGE_THROW_ERROR(Exception, "cannot initialize OpenXR for x11, glfw platform differs");  | 
 | 73 | +			XrGraphicsBindingOpenGLXlibKHR binding;  | 
 | 74 | +			init(binding, XR_TYPE_GRAPHICS_BINDING_OPENGL_XLIB_KHR);  | 
 | 75 | +			binding.xDisplay = glfwGetX11Display();  | 
 | 76 | +			// binding.visualid  | 
 | 77 | +			// binding.glxFBConfig  | 
 | 78 | +			binding.glxDrawable = glXGetCurrentDrawable();  | 
 | 79 | +			binding.glxContext = glXGetCurrentContext();  | 
56 | 80 | 
 
  | 
57 |  | -			char binding[100] = {}; // dummy structure to allow compiling  | 
58 |  | -			//XrGraphicsBindingOpenGLXlibKHR binding;  | 
59 |  | -			//init(binding, XR_TYPE_GRAPHICS_BINDING_OPENGL_XLIB_KHR);  | 
 | 81 | +#elif defined(XR_USE_PLATFORM_WAYLAND)  | 
60 | 82 | 
 
  | 
61 |  | -			// todo some platform specific magic  | 
 | 83 | +			if (glfwGetPlatform() != GLFW_PLATFORM_WAYLAND)  | 
 | 84 | +				CAGE_THROW_ERROR(Exception, "cannot initialize OpenXR for wayland, glfw platform differs");  | 
 | 85 | +			XrGraphicsBindingOpenGLWaylandKHR binding;  | 
 | 86 | +			init(binding, XR_TYPE_GRAPHICS_BINDING_OPENGL_WAYLAND_KHR);  | 
 | 87 | +			binding.Display = glfwGetWaylandDisplay();  | 
62 | 88 | 
 
  | 
63 |  | -#endif // CAGE_SYSTEM_WINDOWS  | 
 | 89 | +#else  | 
 | 90 | + | 
 | 91 | +			CAGE_THROW_ERROR(Exception, "unsupported platform for OpenXR in cage");  | 
 | 92 | +			char binding[100] = {}; // dummy structure to allow compiling  | 
 | 93 | + | 
 | 94 | +#endif  | 
64 | 95 | 
 
  | 
65 | 96 | 			XrSessionCreateInfo info;  | 
66 | 97 | 			init(info, XR_TYPE_SESSION_CREATE_INFO);  | 
 | 
0 commit comments