st/oxr: Wire up Win32 OpenGL

This commit is contained in:
Ryan Pavlik 2021-10-15 14:16:29 -05:00
parent a681252ac1
commit 570f27d486
6 changed files with 118 additions and 0 deletions

View file

@ -91,6 +91,14 @@ if(ANDROID)
target_sources(st_oxr PRIVATE oxr_session_gfx_gles_android.c) target_sources(st_oxr PRIVATE oxr_session_gfx_gles_android.c)
target_link_libraries(st_oxr PRIVATE aux_android) target_link_libraries(st_oxr PRIVATE aux_android)
endif() endif()
if(WIN32)
target_link_libraries(st_oxr PRIVATE kernel32)
target_compile_definitions(st_oxr PRIVATE XR_USE_PLATFORM_WIN32)
endif()
if(WIN32 AND XRT_HAVE_OPENGL)
target_sources(st_oxr PRIVATE oxr_session_gfx_gl_win32.c)
endif()
if(WIN32) if(WIN32)
target_compile_definitions(st_oxr PRIVATE XR_USE_PLATFORM_WIN32) target_compile_definitions(st_oxr PRIVATE XR_USE_PLATFORM_WIN32)

View file

@ -270,6 +270,12 @@ XrResult
oxr_verify_XrGraphicsBindingOpenGLXlibKHR(struct oxr_logger * /*log*/, const XrGraphicsBindingOpenGLXlibKHR * /*next*/); oxr_verify_XrGraphicsBindingOpenGLXlibKHR(struct oxr_logger * /*log*/, const XrGraphicsBindingOpenGLXlibKHR * /*next*/);
#endif // defined(XR_USE_PLATFORM_XLIB) && defined(XR_USE_GRAPHICS_API_OPENGL) #endif // defined(XR_USE_PLATFORM_XLIB) && defined(XR_USE_GRAPHICS_API_OPENGL)
#if defined(XR_USE_PLATFORM_WIN32) && defined(XR_USE_GRAPHICS_API_OPENGL)
XrResult
oxr_verify_XrGraphicsBindingOpenGLWin32KHR(struct oxr_logger * /*log*/,
const XrGraphicsBindingOpenGLWin32KHR * /*next*/);
#endif // defined(XR_USE_PLATFORM_WIN32) && defined(XR_USE_GRAPHICS_API_OPENGL)
#if defined(XR_USE_GRAPHICS_API_VULKAN) #if defined(XR_USE_GRAPHICS_API_VULKAN)
XrResult XrResult
oxr_verify_XrGraphicsBindingVulkanKHR(struct oxr_logger * /*log*/, const XrGraphicsBindingVulkanKHR * /*next*/); oxr_verify_XrGraphicsBindingVulkanKHR(struct oxr_logger * /*log*/, const XrGraphicsBindingVulkanKHR * /*next*/);

View file

@ -1097,6 +1097,13 @@ oxr_session_populate_gl_xlib(struct oxr_logger *log,
struct oxr_session *sess); struct oxr_session *sess);
#endif // XR_USE_PLATFORM_XLIB #endif // XR_USE_PLATFORM_XLIB
#ifdef XR_USE_PLATFORM_WIN32
XrResult
oxr_session_populate_gl_win32(struct oxr_logger *log,
struct oxr_system *sys,
XrGraphicsBindingOpenGLWin32KHR const *next,
struct oxr_session *sess);
#endif // XR_USE_PLATFORM_WIN32
#endif // XR_USE_GRAPHICS_API_OPENGL #endif // XR_USE_GRAPHICS_API_OPENGL
#if defined(XR_USE_GRAPHICS_API_OPENGL) || defined(XR_USE_GRAPHICS_API_OPENGL_ES) #if defined(XR_USE_GRAPHICS_API_OPENGL) || defined(XR_USE_GRAPHICS_API_OPENGL_ES)

View file

@ -722,6 +722,21 @@ oxr_session_create_impl(struct oxr_logger *log,
} }
#endif #endif
#if defined(XR_USE_PLATFORM_WIN32) && defined(XR_USE_GRAPHICS_API_OPENGL)
XrGraphicsBindingOpenGLWin32KHR const *opengl_win32 = OXR_GET_INPUT_FROM_CHAIN(
createInfo, XR_TYPE_GRAPHICS_BINDING_OPENGL_WIN32_KHR, XrGraphicsBindingOpenGLWin32KHR);
if (opengl_win32 != NULL) {
if (!sys->gotten_requirements) {
return oxr_error(log, XR_ERROR_GRAPHICS_REQUIREMENTS_CALL_MISSING,
"Has not called xrGetOpenGLGraphicsRequirementsKHR");
}
OXR_SESSION_ALLOCATE_AND_INIT(log, sys, *out_session);
OXR_ALLOCATE_NATIVE_COMPOSITOR(log, xsi, *out_session);
return oxr_session_populate_gl_win32(log, sys, opengl_win32, *out_session);
}
#endif
#ifdef XR_USE_GRAPHICS_API_VULKAN #ifdef XR_USE_GRAPHICS_API_VULKAN
XrGraphicsBindingVulkanKHR const *vulkan = XrGraphicsBindingVulkanKHR const *vulkan =
OXR_GET_INPUT_FROM_CHAIN(createInfo, XR_TYPE_GRAPHICS_BINDING_VULKAN_KHR, XrGraphicsBindingVulkanKHR); OXR_GET_INPUT_FROM_CHAIN(createInfo, XR_TYPE_GRAPHICS_BINDING_VULKAN_KHR, XrGraphicsBindingVulkanKHR);

View file

@ -0,0 +1,51 @@
// Copyright 2018-2022, Collabora, Ltd.
// SPDX-License-Identifier: BSL-1.0
/*!
* @file
* @brief Holds OpenGL-specific session functions for Windows
* @author Jakob Bornecrantz <jakob@collabora.com>
* @author Ryan Pavlik <ryan.pavlik@collabora.com>
* @ingroup oxr_main
* @ingroup comp_client
*/
#ifndef XR_USE_PLATFORM_WIN32
#error "Must build this file with Win32 enabled!"
#endif
#ifndef XR_USE_GRAPHICS_API_OPENGL
#error "Must build this file with OpenGL enabled!"
#endif
#include <stdlib.h>
#include "util/u_misc.h"
#include "oxr_objects.h"
#include "oxr_logger.h"
#include "oxr_two_call.h"
#include "oxr_handle.h"
#include "xrt/xrt_instance.h"
#include "xrt/xrt_gfx_win32.h"
XrResult
oxr_session_populate_gl_win32(struct oxr_logger *log,
struct oxr_system *sys,
XrGraphicsBindingOpenGLWin32KHR const *next,
struct oxr_session *sess)
{
struct xrt_compositor_native *xcn = sess->xcn;
struct xrt_compositor_gl *xcgl = xrt_gfx_provider_create_gl_win32(xcn, next->hDC, next->hGLRC);
if (xcgl == NULL) {
return oxr_error(log, XR_ERROR_INITIALIZATION_FAILED, "Failed to create a Win32 client compositor");
}
sess->compositor = &xcgl->base;
sess->create_swapchain = oxr_swapchain_gl_create;
return XR_SUCCESS;
}

View file

@ -470,6 +470,15 @@ oxr_verify_XrSessionCreateInfo(struct oxr_logger *log,
} }
#endif // defined(OXR_HAVE_KHR_opengl_enable) && defined(XR_USE_PLATFORM_XLIB) #endif // defined(OXR_HAVE_KHR_opengl_enable) && defined(XR_USE_PLATFORM_XLIB)
#if defined(OXR_HAVE_KHR_opengl_enable) && defined(XR_USE_PLATFORM_WIN32)
XrGraphicsBindingOpenGLWin32KHR const *opengl_win32 = OXR_GET_INPUT_FROM_CHAIN(
createInfo, XR_TYPE_GRAPHICS_BINDING_OPENGL_WIN32_KHR, XrGraphicsBindingOpenGLWin32KHR);
if (opengl_win32 != NULL) {
OXR_VERIFY_EXTENSION(log, inst, KHR_opengl_enable);
return oxr_verify_XrGraphicsBindingOpenGLWin32KHR(log, opengl_win32);
}
#endif // defined(OXR_HAVE_KHR_opengl_enable) && defined(XR_USE_PLATFORM_WIN32)
#if defined(OXR_HAVE_KHR_vulkan_enable) || defined(OXR_HAVE_KHR_vulkan_enable2) #if defined(OXR_HAVE_KHR_vulkan_enable) || defined(OXR_HAVE_KHR_vulkan_enable2)
/* XR_TYPE_GRAPHICS_BINDING_VULKAN2_KHR aliased to /* XR_TYPE_GRAPHICS_BINDING_VULKAN2_KHR aliased to
* XR_TYPE_GRAPHICS_BINDING_VULKAN_KHR */ * XR_TYPE_GRAPHICS_BINDING_VULKAN_KHR */
@ -567,6 +576,28 @@ oxr_verify_XrGraphicsBindingOpenGLXlibKHR(struct oxr_logger *log, const XrGraphi
#endif // defined(XR_USE_PLATFORM_XLIB) && defined(XR_USE_GRAPHICS_API_OPENGL) #endif // defined(XR_USE_PLATFORM_XLIB) && defined(XR_USE_GRAPHICS_API_OPENGL)
#if defined(XR_USE_PLATFORM_WIN32) && defined(XR_USE_GRAPHICS_API_OPENGL)
XrResult
oxr_verify_XrGraphicsBindingOpenGLWin32KHR(struct oxr_logger *log, const XrGraphicsBindingOpenGLWin32KHR *next)
{
if (next->type != XR_TYPE_GRAPHICS_BINDING_OPENGL_WIN32_KHR) {
return oxr_error(log, XR_ERROR_VALIDATION_FAILURE, "Graphics binding has invalid type");
}
if (next->hDC == NULL) {
return oxr_error(log, XR_ERROR_VALIDATION_FAILURE, "hDC is NULL");
}
if (next->hGLRC == NULL) {
return oxr_error(log, XR_ERROR_VALIDATION_FAILURE, "hGLRC is NULL");
}
return XR_SUCCESS;
}
#endif // defined(XR_USE_PLATFORM_WIN32) && defined(XR_USE_GRAPHICS_API_OPENGL)
#ifdef XR_USE_GRAPHICS_API_VULKAN #ifdef XR_USE_GRAPHICS_API_VULKAN