Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'intern/ghost/intern')
-rw-r--r--intern/ghost/intern/GHOST_C-api.cpp5
-rw-r--r--intern/ghost/intern/GHOST_IXrGraphicsBinding.h19
-rw-r--r--intern/ghost/intern/GHOST_System.h2
-rw-r--r--intern/ghost/intern/GHOST_SystemCocoa.h2
-rw-r--r--intern/ghost/intern/GHOST_SystemCocoa.mm2
-rw-r--r--intern/ghost/intern/GHOST_SystemNULL.h2
-rw-r--r--intern/ghost/intern/GHOST_SystemSDL.cpp2
-rw-r--r--intern/ghost/intern/GHOST_SystemSDL.h2
-rw-r--r--intern/ghost/intern/GHOST_SystemWayland.cpp2
-rw-r--r--intern/ghost/intern/GHOST_SystemWayland.h2
-rw-r--r--intern/ghost/intern/GHOST_SystemWin32.cpp4
-rw-r--r--intern/ghost/intern/GHOST_SystemWin32.h2
-rw-r--r--intern/ghost/intern/GHOST_SystemX11.cpp12
-rw-r--r--intern/ghost/intern/GHOST_SystemX11.h2
-rw-r--r--intern/ghost/intern/GHOST_WindowCocoa.mm2
-rw-r--r--intern/ghost/intern/GHOST_Xr.cpp7
-rw-r--r--intern/ghost/intern/GHOST_XrContext.cpp91
-rw-r--r--intern/ghost/intern/GHOST_XrContext.h11
-rw-r--r--intern/ghost/intern/GHOST_XrEvent.cpp14
-rw-r--r--intern/ghost/intern/GHOST_XrGraphicsBinding.cpp128
-rw-r--r--intern/ghost/intern/GHOST_XrSession.cpp56
-rw-r--r--intern/ghost/intern/GHOST_XrSession.h6
-rw-r--r--intern/ghost/intern/GHOST_XrSwapchain.cpp12
23 files changed, 209 insertions, 178 deletions
diff --git a/intern/ghost/intern/GHOST_C-api.cpp b/intern/ghost/intern/GHOST_C-api.cpp
index 843684b6d2e..e4bb908fec8 100644
--- a/intern/ghost/intern/GHOST_C-api.cpp
+++ b/intern/ghost/intern/GHOST_C-api.cpp
@@ -135,11 +135,12 @@ void GHOST_GetAllDisplayDimensions(GHOST_SystemHandle systemhandle,
system->getAllDisplayDimensions(*width, *height);
}
-GHOST_ContextHandle GHOST_CreateOpenGLContext(GHOST_SystemHandle systemhandle)
+GHOST_ContextHandle GHOST_CreateOpenGLContext(GHOST_SystemHandle systemhandle,
+ GHOST_GLSettings glSettings)
{
GHOST_ISystem *system = (GHOST_ISystem *)systemhandle;
- return (GHOST_ContextHandle)system->createOffscreenContext();
+ return (GHOST_ContextHandle)system->createOffscreenContext(glSettings);
}
GHOST_TSuccess GHOST_DisposeOpenGLContext(GHOST_SystemHandle systemhandle,
diff --git a/intern/ghost/intern/GHOST_IXrGraphicsBinding.h b/intern/ghost/intern/GHOST_IXrGraphicsBinding.h
index de8bf9f1a5a..24b42c08e8a 100644
--- a/intern/ghost/intern/GHOST_IXrGraphicsBinding.h
+++ b/intern/ghost/intern/GHOST_IXrGraphicsBinding.h
@@ -21,15 +21,13 @@
#pragma once
#include <memory>
+#include <optional>
#include <string>
#include <vector>
#include "GHOST_Xr_openxr_includes.h"
class GHOST_IXrGraphicsBinding {
- friend std::unique_ptr<GHOST_IXrGraphicsBinding> GHOST_XrGraphicsBindingCreateFromType(
- GHOST_TXrGraphicsBinding type);
-
public:
union {
#if defined(WITH_GHOST_X11)
@@ -49,18 +47,17 @@ class GHOST_IXrGraphicsBinding {
* \param r_requirement_info Return argument to retrieve an informal string on the requirements
* to be met. Useful for error/debug messages.
*/
- virtual bool checkVersionRequirements(class GHOST_Context *ghost_ctx,
+ virtual bool checkVersionRequirements(class GHOST_Context &ghost_ctx,
XrInstance instance,
XrSystemId system_id,
std::string *r_requirement_info) const = 0;
- virtual void initFromGhostContext(class GHOST_Context *ghost_ctx) = 0;
- virtual bool chooseSwapchainFormat(const std::vector<int64_t> &runtime_formats,
- int64_t &r_result,
- bool &r_is_rgb_format) const = 0;
+ virtual void initFromGhostContext(class GHOST_Context &ghost_ctx) = 0;
+ virtual std::optional<int64_t> chooseSwapchainFormat(const std::vector<int64_t> &runtime_formats,
+ bool &r_is_rgb_format) const = 0;
virtual std::vector<XrSwapchainImageBaseHeader *> createSwapchainImages(
uint32_t image_count) = 0;
- virtual void submitToSwapchainImage(XrSwapchainImageBaseHeader *swapchain_image,
- const GHOST_XrDrawViewInfo *draw_info) = 0;
+ virtual void submitToSwapchainImage(XrSwapchainImageBaseHeader &swapchain_image,
+ const GHOST_XrDrawViewInfo &draw_info) = 0;
virtual bool needsUpsideDownDrawing(GHOST_Context &ghost_ctx) const = 0;
protected:
@@ -69,4 +66,4 @@ class GHOST_IXrGraphicsBinding {
};
std::unique_ptr<GHOST_IXrGraphicsBinding> GHOST_XrGraphicsBindingCreateFromType(
- GHOST_TXrGraphicsBinding type, GHOST_Context *ghost_ctx);
+ GHOST_TXrGraphicsBinding type, GHOST_Context &ghost_ctx);
diff --git a/intern/ghost/intern/GHOST_System.h b/intern/ghost/intern/GHOST_System.h
index e29a9ba0c29..d5b23d76016 100644
--- a/intern/ghost/intern/GHOST_System.h
+++ b/intern/ghost/intern/GHOST_System.h
@@ -115,7 +115,7 @@ class GHOST_System : public GHOST_ISystem {
* Never explicitly delete the context, use disposeContext() instead.
* \return The new context (or 0 if creation failed).
*/
- virtual GHOST_IContext *createOffscreenContext() = 0;
+ virtual GHOST_IContext *createOffscreenContext(GHOST_GLSettings glSettings) = 0;
/**
* Returns whether a window is valid.
diff --git a/intern/ghost/intern/GHOST_SystemCocoa.h b/intern/ghost/intern/GHOST_SystemCocoa.h
index 8e36cebb88a..b89edf8835d 100644
--- a/intern/ghost/intern/GHOST_SystemCocoa.h
+++ b/intern/ghost/intern/GHOST_SystemCocoa.h
@@ -116,7 +116,7 @@ class GHOST_SystemCocoa : public GHOST_System {
* Never explicitly delete the context, use disposeContext() instead.
* \return The new context (or 0 if creation failed).
*/
- GHOST_IContext *createOffscreenContext();
+ GHOST_IContext *createOffscreenContext(GHOST_GLSettings glSettings);
/**
* Dispose of a context.
diff --git a/intern/ghost/intern/GHOST_SystemCocoa.mm b/intern/ghost/intern/GHOST_SystemCocoa.mm
index 5592078e20e..467f59defea 100644
--- a/intern/ghost/intern/GHOST_SystemCocoa.mm
+++ b/intern/ghost/intern/GHOST_SystemCocoa.mm
@@ -765,7 +765,7 @@ GHOST_IWindow *GHOST_SystemCocoa::createWindow(const char *title,
* Never explicitly delete the context, use #disposeContext() instead.
* \return The new context (or 0 if creation failed).
*/
-GHOST_IContext *GHOST_SystemCocoa::createOffscreenContext()
+GHOST_IContext *GHOST_SystemCocoa::createOffscreenContext(GHOST_GLSettings glSettings)
{
GHOST_Context *context = new GHOST_ContextCGL(false, NULL, NULL, NULL);
if (context->initializeDrawingContext())
diff --git a/intern/ghost/intern/GHOST_SystemNULL.h b/intern/ghost/intern/GHOST_SystemNULL.h
index 5becf110b15..faeffffed9e 100644
--- a/intern/ghost/intern/GHOST_SystemNULL.h
+++ b/intern/ghost/intern/GHOST_SystemNULL.h
@@ -81,7 +81,7 @@ class GHOST_SystemNULL : public GHOST_System {
void getAllDisplayDimensions(GHOST_TUns32 &width, GHOST_TUns32 &height) const
{ /* nop */
}
- GHOST_IContext *createOffscreenContext()
+ GHOST_IContext *createOffscreenContext(GHOST_GLSettings glSettings)
{
return NULL;
}
diff --git a/intern/ghost/intern/GHOST_SystemSDL.cpp b/intern/ghost/intern/GHOST_SystemSDL.cpp
index b32ec4306e8..1769c432d96 100644
--- a/intern/ghost/intern/GHOST_SystemSDL.cpp
+++ b/intern/ghost/intern/GHOST_SystemSDL.cpp
@@ -139,7 +139,7 @@ GHOST_TUns8 GHOST_SystemSDL::getNumDisplays() const
return SDL_GetNumVideoDisplays();
}
-GHOST_IContext *GHOST_SystemSDL::createOffscreenContext()
+GHOST_IContext *GHOST_SystemSDL::createOffscreenContext(GHOST_GLSettings glSettings)
{
GHOST_Context *context = new GHOST_ContextSDL(0,
NULL,
diff --git a/intern/ghost/intern/GHOST_SystemSDL.h b/intern/ghost/intern/GHOST_SystemSDL.h
index 4b2c52f8282..57e8d17861d 100644
--- a/intern/ghost/intern/GHOST_SystemSDL.h
+++ b/intern/ghost/intern/GHOST_SystemSDL.h
@@ -72,7 +72,7 @@ class GHOST_SystemSDL : public GHOST_System {
void getMainDisplayDimensions(GHOST_TUns32 &width, GHOST_TUns32 &height) const;
- GHOST_IContext *createOffscreenContext();
+ GHOST_IContext *createOffscreenContext(GHOST_GLSettings glSettings);
GHOST_TSuccess disposeContext(GHOST_IContext *context);
diff --git a/intern/ghost/intern/GHOST_SystemWayland.cpp b/intern/ghost/intern/GHOST_SystemWayland.cpp
index 31110694ea6..81d9824ed26 100644
--- a/intern/ghost/intern/GHOST_SystemWayland.cpp
+++ b/intern/ghost/intern/GHOST_SystemWayland.cpp
@@ -1481,7 +1481,7 @@ void GHOST_SystemWayland::getAllDisplayDimensions(GHOST_TUns32 &width, GHOST_TUn
getMainDisplayDimensions(width, height);
}
-GHOST_IContext *GHOST_SystemWayland::createOffscreenContext()
+GHOST_IContext *GHOST_SystemWayland::createOffscreenContext(GHOST_GLSettings glSettings)
{
/* Create new off-screen window. */
wl_surface *os_surface = wl_compositor_create_surface(compositor());
diff --git a/intern/ghost/intern/GHOST_SystemWayland.h b/intern/ghost/intern/GHOST_SystemWayland.h
index 30ee7679287..10b9ef6bd62 100644
--- a/intern/ghost/intern/GHOST_SystemWayland.h
+++ b/intern/ghost/intern/GHOST_SystemWayland.h
@@ -62,7 +62,7 @@ class GHOST_SystemWayland : public GHOST_System {
void getAllDisplayDimensions(GHOST_TUns32 &width, GHOST_TUns32 &height) const override;
- GHOST_IContext *createOffscreenContext() override;
+ GHOST_IContext *createOffscreenContext(GHOST_GLSettings glSettings) override;
GHOST_TSuccess disposeContext(GHOST_IContext *context) override;
diff --git a/intern/ghost/intern/GHOST_SystemWin32.cpp b/intern/ghost/intern/GHOST_SystemWin32.cpp
index f59b106afd6..533e51db355 100644
--- a/intern/ghost/intern/GHOST_SystemWin32.cpp
+++ b/intern/ghost/intern/GHOST_SystemWin32.cpp
@@ -328,9 +328,9 @@ GHOST_IWindow *GHOST_SystemWin32::createWindow(const char *title,
* Never explicitly delete the window, use #disposeContext() instead.
* \return The new context (or 0 if creation failed).
*/
-GHOST_IContext *GHOST_SystemWin32::createOffscreenContext()
+GHOST_IContext *GHOST_SystemWin32::createOffscreenContext(GHOST_GLSettings glSettings)
{
- bool debug_context = false; /* TODO: inform as a parameter */
+ const bool debug_context = (glSettings.flags & GHOST_glDebugContext) != 0;
GHOST_Context *context;
diff --git a/intern/ghost/intern/GHOST_SystemWin32.h b/intern/ghost/intern/GHOST_SystemWin32.h
index 24925b9c403..86916b3aeeb 100644
--- a/intern/ghost/intern/GHOST_SystemWin32.h
+++ b/intern/ghost/intern/GHOST_SystemWin32.h
@@ -142,7 +142,7 @@ class GHOST_SystemWin32 : public GHOST_System {
* Never explicitly delete the window, use disposeContext() instead.
* \return The new context (or 0 if creation failed).
*/
- GHOST_IContext *createOffscreenContext();
+ GHOST_IContext *createOffscreenContext(GHOST_GLSettings glSettings);
/**
* Dispose of a context.
diff --git a/intern/ghost/intern/GHOST_SystemX11.cpp b/intern/ghost/intern/GHOST_SystemX11.cpp
index c0676618101..2a07e02706b 100644
--- a/intern/ghost/intern/GHOST_SystemX11.cpp
+++ b/intern/ghost/intern/GHOST_SystemX11.cpp
@@ -394,7 +394,7 @@ GHOST_IWindow *GHOST_SystemX11::createWindow(const char *title,
* Never explicitly delete the context, use disposeContext() instead.
* \return The new context (or 0 if creation failed).
*/
-GHOST_IContext *GHOST_SystemX11::createOffscreenContext()
+GHOST_IContext *GHOST_SystemX11::createOffscreenContext(GHOST_GLSettings glSettings)
{
// During development:
// try 4.x compatibility profile
@@ -406,6 +406,8 @@ GHOST_IContext *GHOST_SystemX11::createOffscreenContext()
// try 3.3 core profile
// no fallbacks
+ const bool debug_context = (glSettings.flags & GHOST_glDebugContext) != 0;
+
#if defined(WITH_GL_PROFILE_CORE)
{
const char *version_major = (char *)glewGetString(GLEW_VERSION_MAJOR);
@@ -446,7 +448,7 @@ GHOST_IContext *GHOST_SystemX11::createOffscreenContext()
4,
minor,
GHOST_OPENGL_EGL_CONTEXT_FLAGS |
- (false ? EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR : 0),
+ (debug_context ? EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR : 0),
GHOST_OPENGL_EGL_RESET_NOTIFICATION_STRATEGY,
EGL_OPENGL_API);
#else
@@ -458,7 +460,7 @@ GHOST_IContext *GHOST_SystemX11::createOffscreenContext()
4,
minor,
GHOST_OPENGL_GLX_CONTEXT_FLAGS |
- (false ? GLX_CONTEXT_DEBUG_BIT_ARB : 0),
+ (debug_context ? GLX_CONTEXT_DEBUG_BIT_ARB : 0),
GHOST_OPENGL_GLX_RESET_NOTIFICATION_STRATEGY);
#endif
@@ -476,7 +478,7 @@ GHOST_IContext *GHOST_SystemX11::createOffscreenContext()
3,
3,
GHOST_OPENGL_EGL_CONTEXT_FLAGS |
- (false ? EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR : 0),
+ (debug_context ? EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR : 0),
GHOST_OPENGL_EGL_RESET_NOTIFICATION_STRATEGY,
EGL_OPENGL_API);
#else
@@ -488,7 +490,7 @@ GHOST_IContext *GHOST_SystemX11::createOffscreenContext()
3,
3,
GHOST_OPENGL_GLX_CONTEXT_FLAGS |
- (false ? GLX_CONTEXT_DEBUG_BIT_ARB : 0),
+ (debug_context ? GLX_CONTEXT_DEBUG_BIT_ARB : 0),
GHOST_OPENGL_GLX_RESET_NOTIFICATION_STRATEGY);
#endif
diff --git a/intern/ghost/intern/GHOST_SystemX11.h b/intern/ghost/intern/GHOST_SystemX11.h
index ad58138d416..a852675acfb 100644
--- a/intern/ghost/intern/GHOST_SystemX11.h
+++ b/intern/ghost/intern/GHOST_SystemX11.h
@@ -153,7 +153,7 @@ class GHOST_SystemX11 : public GHOST_System {
* Never explicitly delete the context, use disposeContext() instead.
* \return The new context (or 0 if creation failed).
*/
- GHOST_IContext *createOffscreenContext();
+ GHOST_IContext *createOffscreenContext(GHOST_GLSettings glSettings);
/**
* Dispose of a context.
diff --git a/intern/ghost/intern/GHOST_WindowCocoa.mm b/intern/ghost/intern/GHOST_WindowCocoa.mm
index 62b0e48a7c1..f8e2f96d111 100644
--- a/intern/ghost/intern/GHOST_WindowCocoa.mm
+++ b/intern/ghost/intern/GHOST_WindowCocoa.mm
@@ -415,7 +415,7 @@ GHOST_WindowCocoa::GHOST_WindowCocoa(GHOST_SystemCocoa *systemCocoa,
[parentWindow->getCocoaWindow() addChildWindow:m_window ordered:NSWindowAbove];
[m_window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenAuxiliary];
}
- else if (state != GHOST_kWindowStateFullScreen) {
+ else {
[m_window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
}
diff --git a/intern/ghost/intern/GHOST_Xr.cpp b/intern/ghost/intern/GHOST_Xr.cpp
index dc63aac217c..2c94aaab430 100644
--- a/intern/ghost/intern/GHOST_Xr.cpp
+++ b/intern/ghost/intern/GHOST_Xr.cpp
@@ -31,7 +31,7 @@
GHOST_XrContextHandle GHOST_XrContextCreate(const GHOST_XrContextCreateInfo *create_info)
{
- GHOST_XrContext *xr_context = new GHOST_XrContext(create_info);
+ auto xr_context = std::make_unique<GHOST_XrContext>(create_info);
/* TODO GHOST_XrContext's should probably be owned by the GHOST_System, which will handle context
* creation and destruction. Try-catch logic can be moved to C-API then. */
@@ -40,12 +40,11 @@ GHOST_XrContextHandle GHOST_XrContextCreate(const GHOST_XrContextCreateInfo *cre
}
catch (GHOST_XrException &e) {
xr_context->dispatchErrorMessage(&e);
- delete xr_context;
-
return nullptr;
}
- return (GHOST_XrContextHandle)xr_context;
+ /* Give ownership to the caller. */
+ return (GHOST_XrContextHandle)xr_context.release();
}
void GHOST_XrContextDestroy(GHOST_XrContextHandle xr_contexthandle)
diff --git a/intern/ghost/intern/GHOST_XrContext.cpp b/intern/ghost/intern/GHOST_XrContext.cpp
index 16687c34679..583bda9731a 100644
--- a/intern/ghost/intern/GHOST_XrContext.cpp
+++ b/intern/ghost/intern/GHOST_XrContext.cpp
@@ -23,6 +23,7 @@
#include <cassert>
#include <sstream>
#include <string>
+#include <string_view>
#include "GHOST_Types.h"
#include "GHOST_XrException.h"
@@ -58,7 +59,7 @@ void *GHOST_XrContext::s_error_handler_customdata = nullptr;
* \{ */
GHOST_XrContext::GHOST_XrContext(const GHOST_XrContextCreateInfo *create_info)
- : m_oxr(new OpenXRInstanceData()),
+ : m_oxr(std::make_unique<OpenXRInstanceData>()),
m_debug(create_info->context_flag & GHOST_kXrContextDebug),
m_debug_time(create_info->context_flag & GHOST_kXrContextDebugTime)
{
@@ -88,18 +89,26 @@ void GHOST_XrContext::initialize(const GHOST_XrContextCreateInfo *create_info)
printAvailableAPILayersAndExtensionsInfo();
}
- m_gpu_binding_type = determineGraphicsBindingTypeToEnable(create_info);
+ /* Multiple graphics binding extensions can be enabled, but only one will actually be used
+ * (determined later on). */
+ const std::vector<GHOST_TXrGraphicsBinding> graphics_binding_types =
+ determineGraphicsBindingTypesToEnable(create_info);
assert(m_oxr->instance == XR_NULL_HANDLE);
- createOpenXRInstance();
+ createOpenXRInstance(graphics_binding_types);
storeInstanceProperties();
+
+ /* Multiple bindings may be enabled. Now that we know the runtime in use, settle for one. */
+ m_gpu_binding_type = determineGraphicsBindingTypeToUse(graphics_binding_types);
+
printInstanceInfo();
if (isDebugMode()) {
initDebugMessenger();
}
}
-void GHOST_XrContext::createOpenXRInstance()
+void GHOST_XrContext::createOpenXRInstance(
+ const std::vector<GHOST_TXrGraphicsBinding> &graphics_binding_types)
{
XrInstanceCreateInfo create_info = {XR_TYPE_INSTANCE_CREATE_INFO};
@@ -108,7 +117,7 @@ void GHOST_XrContext::createOpenXRInstance()
create_info.applicationInfo.apiVersion = XR_CURRENT_API_VERSION;
getAPILayersToEnable(m_enabled_layers);
- getExtensionsToEnable(m_enabled_extensions);
+ getExtensionsToEnable(graphics_binding_types, m_enabled_extensions);
create_info.enabledApiLayerCount = m_enabled_layers.size();
create_info.enabledApiLayerNames = m_enabled_layers.data();
create_info.enabledExtensionCount = m_enabled_extensions.size();
@@ -327,7 +336,7 @@ void GHOST_XrContext::initApiLayers()
}
}
-static bool openxr_layer_is_available(const std::vector<XrApiLayerProperties> layers_info,
+static bool openxr_layer_is_available(const std::vector<XrApiLayerProperties> &layers_info,
const std::string &layer_name)
{
for (const XrApiLayerProperties &layer_info : layers_info) {
@@ -339,8 +348,9 @@ static bool openxr_layer_is_available(const std::vector<XrApiLayerProperties> la
return false;
}
-static bool openxr_extension_is_available(const std::vector<XrExtensionProperties> extensions_info,
- const std::string &extension_name)
+static bool openxr_extension_is_available(
+ const std::vector<XrExtensionProperties> &extensions_info,
+ const std::string_view &extension_name)
{
for (const XrExtensionProperties &ext_info : extensions_info) {
if (ext_info.extensionName == extension_name) {
@@ -393,32 +403,30 @@ static const char *openxr_ext_name_from_wm_gpu_binding(GHOST_TXrGraphicsBinding
/**
* Gather an array of names for the extensions to enable.
*/
-void GHOST_XrContext::getExtensionsToEnable(std::vector<const char *> &r_ext_names)
+void GHOST_XrContext::getExtensionsToEnable(
+ const std::vector<GHOST_TXrGraphicsBinding> &graphics_binding_types,
+ std::vector<const char *> &r_ext_names)
{
- assert(m_gpu_binding_type != GHOST_kXrGraphicsUnknown);
-
- const char *gpu_binding = openxr_ext_name_from_wm_gpu_binding(m_gpu_binding_type);
- static std::vector<std::string> try_ext;
-
- try_ext.clear();
+ std::vector<std::string_view> try_ext;
/* Try enabling debug extension. */
-#ifndef WIN32
if (isDebugMode()) {
try_ext.push_back(XR_EXT_DEBUG_UTILS_EXTENSION_NAME);
}
-#endif
- r_ext_names.reserve(try_ext.size() + 1); /* + 1 for graphics binding extension. */
+ r_ext_names.reserve(try_ext.size() + graphics_binding_types.size());
- /* Add graphics binding extension. */
- assert(gpu_binding);
- assert(openxr_extension_is_available(m_oxr->extensions, gpu_binding));
- r_ext_names.push_back(gpu_binding);
+ /* Add graphics binding extensions (may be multiple ones, we'll settle for one to use later, once
+ * we have more info about the runtime). */
+ for (GHOST_TXrGraphicsBinding type : graphics_binding_types) {
+ const char *gpu_binding = openxr_ext_name_from_wm_gpu_binding(type);
+ assert(openxr_extension_is_available(m_oxr->extensions, gpu_binding));
+ r_ext_names.push_back(gpu_binding);
+ }
- for (const std::string &ext : try_ext) {
+ for (const std::string_view &ext : try_ext) {
if (openxr_extension_is_available(m_oxr->extensions, ext)) {
- r_ext_names.push_back(ext.c_str());
+ r_ext_names.push_back(ext.data());
}
}
}
@@ -427,9 +435,10 @@ void GHOST_XrContext::getExtensionsToEnable(std::vector<const char *> &r_ext_nam
* Decide which graphics binding extension to use based on
* #GHOST_XrContextCreateInfo.gpu_binding_candidates and available extensions.
*/
-GHOST_TXrGraphicsBinding GHOST_XrContext::determineGraphicsBindingTypeToEnable(
+std::vector<GHOST_TXrGraphicsBinding> GHOST_XrContext::determineGraphicsBindingTypesToEnable(
const GHOST_XrContextCreateInfo *create_info)
{
+ std::vector<GHOST_TXrGraphicsBinding> result;
assert(create_info->gpu_binding_candidates != NULL);
assert(create_info->gpu_binding_candidates_count > 0);
@@ -438,11 +447,35 @@ GHOST_TXrGraphicsBinding GHOST_XrContext::determineGraphicsBindingTypeToEnable(
const char *ext_name = openxr_ext_name_from_wm_gpu_binding(
create_info->gpu_binding_candidates[i]);
if (openxr_extension_is_available(m_oxr->extensions, ext_name)) {
- return create_info->gpu_binding_candidates[i];
+ result.push_back(create_info->gpu_binding_candidates[i]);
}
}
- return GHOST_kXrGraphicsUnknown;
+ if (result.empty()) {
+ throw GHOST_XrException("No supported graphics binding found.");
+ }
+
+ return result;
+}
+
+GHOST_TXrGraphicsBinding GHOST_XrContext::determineGraphicsBindingTypeToUse(
+ const std::vector<GHOST_TXrGraphicsBinding> &enabled_types)
+{
+ /* Return the first working type. */
+ for (GHOST_TXrGraphicsBinding type : enabled_types) {
+#ifdef WIN32
+ /* The SteamVR OpenGL backend fails currently. Disable it and allow falling back to the DirectX
+ * one. */
+ if ((m_runtime_id == OPENXR_RUNTIME_STEAMVR) && (type == GHOST_kXrGraphicsOpenGL)) {
+ continue;
+ }
+#endif
+
+ assert(type != GHOST_kXrGraphicsUnknown);
+ return type;
+ }
+
+ throw GHOST_XrException("Failed to determine a graphics binding to use.");
}
/** \} */ /* OpenXR API-Layers and Extensions */
@@ -459,7 +492,7 @@ void GHOST_XrContext::startSession(const GHOST_XrSessionBeginInfo *begin_info)
m_custom_funcs.session_exit_customdata = begin_info->exit_customdata;
if (m_session == nullptr) {
- m_session = std::unique_ptr<GHOST_XrSession>(new GHOST_XrSession(this));
+ m_session = std::make_unique<GHOST_XrSession>(*this);
}
m_session->start(begin_info);
}
@@ -489,7 +522,7 @@ void GHOST_XrContext::drawSessionViews(void *draw_customdata)
/**
* Delegates event to session, allowing context to destruct the session if needed.
*/
-void GHOST_XrContext::handleSessionStateChange(const XrEventDataSessionStateChanged *lifecycle)
+void GHOST_XrContext::handleSessionStateChange(const XrEventDataSessionStateChanged &lifecycle)
{
if (m_session &&
m_session->handleStateChangeEvent(lifecycle) == GHOST_XrSession::SESSION_DESTROY) {
diff --git a/intern/ghost/intern/GHOST_XrContext.h b/intern/ghost/intern/GHOST_XrContext.h
index d2edb40c080..59c7786ed7a 100644
--- a/intern/ghost/intern/GHOST_XrContext.h
+++ b/intern/ghost/intern/GHOST_XrContext.h
@@ -80,7 +80,7 @@ class GHOST_XrContext : public GHOST_IXrContext {
void setDrawViewFunc(GHOST_XrDrawViewFn draw_view_fn) override;
bool needsUpsideDownDrawing() const override;
- void handleSessionStateChange(const XrEventDataSessionStateChanged *lifecycle);
+ void handleSessionStateChange(const XrEventDataSessionStateChanged &lifecycle);
GHOST_TXrOpenXRRuntimeID getOpenXRRuntimeID() const;
const GHOST_XrCustomFuncs &getCustomFuncs() const;
@@ -114,7 +114,7 @@ class GHOST_XrContext : public GHOST_IXrContext {
bool m_debug = false;
bool m_debug_time = false;
- void createOpenXRInstance();
+ void createOpenXRInstance(const std::vector<GHOST_TXrGraphicsBinding> &graphics_binding_types);
void storeInstanceProperties();
void initDebugMessenger();
@@ -126,7 +126,10 @@ class GHOST_XrContext : public GHOST_IXrContext {
void initExtensions();
void initExtensionsEx(std::vector<XrExtensionProperties> &extensions, const char *layer_name);
void getAPILayersToEnable(std::vector<const char *> &r_ext_names);
- void getExtensionsToEnable(std::vector<const char *> &r_ext_names);
- GHOST_TXrGraphicsBinding determineGraphicsBindingTypeToEnable(
+ void getExtensionsToEnable(const std::vector<GHOST_TXrGraphicsBinding> &graphics_binding_types,
+ std::vector<const char *> &r_ext_names);
+ std::vector<GHOST_TXrGraphicsBinding> determineGraphicsBindingTypesToEnable(
const GHOST_XrContextCreateInfo *create_info);
+ GHOST_TXrGraphicsBinding determineGraphicsBindingTypeToUse(
+ const std::vector<GHOST_TXrGraphicsBinding> &enabled_types);
};
diff --git a/intern/ghost/intern/GHOST_XrEvent.cpp b/intern/ghost/intern/GHOST_XrEvent.cpp
index 30005055f9b..992f89fadeb 100644
--- a/intern/ghost/intern/GHOST_XrEvent.cpp
+++ b/intern/ghost/intern/GHOST_XrEvent.cpp
@@ -35,25 +35,25 @@ static bool GHOST_XrEventPollNext(XrInstance instance, XrEventDataBuffer &r_even
GHOST_TSuccess GHOST_XrEventsHandle(GHOST_XrContextHandle xr_contexthandle)
{
- GHOST_XrContext *xr_context = (GHOST_XrContext *)xr_contexthandle;
- XrEventDataBuffer event_buffer; /* Structure big enough to hold all possible events. */
-
- if (xr_context == NULL) {
+ if (xr_contexthandle == nullptr) {
return GHOST_kFailure;
}
- while (GHOST_XrEventPollNext(xr_context->getInstance(), event_buffer)) {
+ GHOST_XrContext &xr_context = *(GHOST_XrContext *)xr_contexthandle;
+ XrEventDataBuffer event_buffer; /* Structure big enough to hold all possible events. */
+
+ while (GHOST_XrEventPollNext(xr_context.getInstance(), event_buffer)) {
XrEventDataBaseHeader *event = (XrEventDataBaseHeader *)&event_buffer;
switch (event->type) {
case XR_TYPE_EVENT_DATA_SESSION_STATE_CHANGED:
- xr_context->handleSessionStateChange((XrEventDataSessionStateChanged *)event);
+ xr_context.handleSessionStateChange((XrEventDataSessionStateChanged &)*event);
return GHOST_kSuccess;
case XR_TYPE_EVENT_DATA_INSTANCE_LOSS_PENDING:
GHOST_XrContextDestroy(xr_contexthandle);
return GHOST_kSuccess;
default:
- if (xr_context->isDebugMode()) {
+ if (xr_context.isDebugMode()) {
printf("Unhandled event: %i\n", event->type);
}
return GHOST_kFailure;
diff --git a/intern/ghost/intern/GHOST_XrGraphicsBinding.cpp b/intern/ghost/intern/GHOST_XrGraphicsBinding.cpp
index 7d7405a974d..39b7f0776e1 100644
--- a/intern/ghost/intern/GHOST_XrGraphicsBinding.cpp
+++ b/intern/ghost/intern/GHOST_XrGraphicsBinding.cpp
@@ -34,12 +34,11 @@
#include "GHOST_IXrGraphicsBinding.h"
-static bool choose_swapchain_format_from_candidates(std::vector<int64_t> gpu_binding_formats,
- std::vector<int64_t> runtime_formats,
- int64_t &r_result)
+static std::optional<int64_t> choose_swapchain_format_from_candidates(
+ const std::vector<int64_t> &gpu_binding_formats, const std::vector<int64_t> &runtime_formats)
{
if (gpu_binding_formats.empty()) {
- return false;
+ return std::nullopt;
}
auto res = std::find_first_of(gpu_binding_formats.begin(),
@@ -47,11 +46,10 @@ static bool choose_swapchain_format_from_candidates(std::vector<int64_t> gpu_bin
runtime_formats.begin(),
runtime_formats.end());
if (res == gpu_binding_formats.end()) {
- return false;
+ return std::nullopt;
}
- r_result = *res;
- return true;
+ return *res;
}
class GHOST_XrGraphicsBindingOpenGL : public GHOST_IXrGraphicsBinding {
@@ -63,21 +61,21 @@ class GHOST_XrGraphicsBindingOpenGL : public GHOST_IXrGraphicsBinding {
}
}
- bool checkVersionRequirements(GHOST_Context *ghost_ctx,
+ bool checkVersionRequirements(GHOST_Context &ghost_ctx,
XrInstance instance,
XrSystemId system_id,
std::string *r_requirement_info) const override
{
#if defined(WITH_GHOST_X11)
- GHOST_ContextGLX *ctx_gl = static_cast<GHOST_ContextGLX *>(ghost_ctx);
+ GHOST_ContextGLX &ctx_gl = static_cast<GHOST_ContextGLX &>(ghost_ctx);
#else
- GHOST_ContextWGL *ctx_gl = static_cast<GHOST_ContextWGL *>(ghost_ctx);
+ GHOST_ContextWGL &ctx_gl = static_cast<GHOST_ContextWGL &>(ghost_ctx);
#endif
static PFN_xrGetOpenGLGraphicsRequirementsKHR s_xrGetOpenGLGraphicsRequirementsKHR_fn =
nullptr;
XrGraphicsRequirementsOpenGLKHR gpu_requirements = {XR_TYPE_GRAPHICS_REQUIREMENTS_OPENGL_KHR};
const XrVersion gl_version = XR_MAKE_VERSION(
- ctx_gl->m_contextMajorVersion, ctx_gl->m_contextMinorVersion, 0);
+ ctx_gl.m_contextMajorVersion, ctx_gl.m_contextMinorVersion, 0);
if (!s_xrGetOpenGLGraphicsRequirementsKHR_fn &&
XR_FAILED(xrGetInstanceProcAddr(
@@ -105,47 +103,45 @@ class GHOST_XrGraphicsBindingOpenGL : public GHOST_IXrGraphicsBinding {
(gl_version <= gpu_requirements.maxApiVersionSupported);
}
- void initFromGhostContext(GHOST_Context *ghost_ctx) override
+ void initFromGhostContext(GHOST_Context &ghost_ctx) override
{
#if defined(WITH_GHOST_X11)
- GHOST_ContextGLX *ctx_glx = static_cast<GHOST_ContextGLX *>(ghost_ctx);
- XVisualInfo *visual_info = glXGetVisualFromFBConfig(ctx_glx->m_display, ctx_glx->m_fbconfig);
+ GHOST_ContextGLX &ctx_glx = static_cast<GHOST_ContextGLX &>(ghost_ctx);
+ XVisualInfo *visual_info = glXGetVisualFromFBConfig(ctx_glx.m_display, ctx_glx.m_fbconfig);
oxr_binding.glx.type = XR_TYPE_GRAPHICS_BINDING_OPENGL_XLIB_KHR;
- oxr_binding.glx.xDisplay = ctx_glx->m_display;
- oxr_binding.glx.glxFBConfig = ctx_glx->m_fbconfig;
- oxr_binding.glx.glxDrawable = ctx_glx->m_window;
- oxr_binding.glx.glxContext = ctx_glx->m_context;
+ oxr_binding.glx.xDisplay = ctx_glx.m_display;
+ oxr_binding.glx.glxFBConfig = ctx_glx.m_fbconfig;
+ oxr_binding.glx.glxDrawable = ctx_glx.m_window;
+ oxr_binding.glx.glxContext = ctx_glx.m_context;
oxr_binding.glx.visualid = visual_info->visualid;
XFree(visual_info);
#elif defined(WIN32)
- GHOST_ContextWGL *ctx_wgl = static_cast<GHOST_ContextWGL *>(ghost_ctx);
+ GHOST_ContextWGL &ctx_wgl = static_cast<GHOST_ContextWGL &>(ghost_ctx);
oxr_binding.wgl.type = XR_TYPE_GRAPHICS_BINDING_OPENGL_WIN32_KHR;
- oxr_binding.wgl.hDC = ctx_wgl->m_hDC;
- oxr_binding.wgl.hGLRC = ctx_wgl->m_hGLRC;
+ oxr_binding.wgl.hDC = ctx_wgl.m_hDC;
+ oxr_binding.wgl.hGLRC = ctx_wgl.m_hGLRC;
#endif
/* Generate a framebuffer to use for blitting into the texture. */
glGenFramebuffers(1, &m_fbo);
}
- bool chooseSwapchainFormat(const std::vector<int64_t> &runtime_formats,
- int64_t &r_result,
- bool &r_is_srgb_format) const override
+ std::optional<int64_t> chooseSwapchainFormat(const std::vector<int64_t> &runtime_formats,
+ bool &r_is_srgb_format) const override
{
std::vector<int64_t> gpu_binding_formats = {
GL_RGBA8,
GL_SRGB8_ALPHA8,
};
- if (choose_swapchain_format_from_candidates(gpu_binding_formats, runtime_formats, r_result)) {
- r_is_srgb_format = (r_result == GL_SRGB8_ALPHA8);
- return true;
- }
+ std::optional result = choose_swapchain_format_from_candidates(gpu_binding_formats,
+ runtime_formats);
+ r_is_srgb_format = result ? (*result == GL_SRGB8_ALPHA8) : false;
- return false;
+ return result;
}
std::vector<XrSwapchainImageBaseHeader *> createSwapchainImages(uint32_t image_count) override
@@ -166,25 +162,25 @@ class GHOST_XrGraphicsBindingOpenGL : public GHOST_IXrGraphicsBinding {
return base_images;
}
- void submitToSwapchainImage(XrSwapchainImageBaseHeader *swapchain_image,
- const GHOST_XrDrawViewInfo *draw_info) override
+ void submitToSwapchainImage(XrSwapchainImageBaseHeader &swapchain_image,
+ const GHOST_XrDrawViewInfo &draw_info) override
{
- XrSwapchainImageOpenGLKHR *ogl_swapchain_image = reinterpret_cast<XrSwapchainImageOpenGLKHR *>(
+ XrSwapchainImageOpenGLKHR &ogl_swapchain_image = reinterpret_cast<XrSwapchainImageOpenGLKHR &>(
swapchain_image);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbo);
glFramebufferTexture2D(
- GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, ogl_swapchain_image->image, 0);
-
- glBlitFramebuffer(draw_info->ofsx,
- draw_info->ofsy,
- draw_info->ofsx + draw_info->width,
- draw_info->ofsy + draw_info->height,
- draw_info->ofsx,
- draw_info->ofsy,
- draw_info->ofsx + draw_info->width,
- draw_info->ofsy + draw_info->height,
+ GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, ogl_swapchain_image.image, 0);
+
+ glBlitFramebuffer(draw_info.ofsx,
+ draw_info.ofsy,
+ draw_info.ofsx + draw_info.width,
+ draw_info.ofsy + draw_info.height,
+ draw_info.ofsx,
+ draw_info.ofsy,
+ draw_info.ofsx + draw_info.width,
+ draw_info.ofsy + draw_info.height,
GL_COLOR_BUFFER_BIT,
GL_LINEAR);
@@ -204,8 +200,8 @@ class GHOST_XrGraphicsBindingOpenGL : public GHOST_IXrGraphicsBinding {
#ifdef WIN32
class GHOST_XrGraphicsBindingD3D : public GHOST_IXrGraphicsBinding {
public:
- GHOST_XrGraphicsBindingD3D(GHOST_Context *ghost_ctx)
- : GHOST_IXrGraphicsBinding(), m_ghost_wgl_ctx(*static_cast<GHOST_ContextWGL *>(ghost_ctx))
+ GHOST_XrGraphicsBindingD3D(GHOST_Context &ghost_ctx)
+ : GHOST_IXrGraphicsBinding(), m_ghost_wgl_ctx(static_cast<GHOST_ContextWGL &>(ghost_ctx))
{
m_ghost_d3d_ctx = GHOST_SystemWin32::createOffscreenContextD3D();
}
@@ -220,7 +216,7 @@ class GHOST_XrGraphicsBindingD3D : public GHOST_IXrGraphicsBinding {
}
bool checkVersionRequirements(
- GHOST_Context * /*ghost_ctx*/, /* Remember: This is the OpenGL context! */
+ GHOST_Context & /*ghost_ctx*/, /* Remember: This is the OpenGL context! */
XrInstance instance,
XrSystemId system_id,
std::string *r_requirement_info) const override
@@ -250,27 +246,25 @@ class GHOST_XrGraphicsBindingD3D : public GHOST_IXrGraphicsBinding {
}
void initFromGhostContext(
- GHOST_Context * /*ghost_ctx*/ /* Remember: This is the OpenGL context! */
+ GHOST_Context & /*ghost_ctx*/ /* Remember: This is the OpenGL context! */
) override
{
oxr_binding.d3d11.type = XR_TYPE_GRAPHICS_BINDING_D3D11_KHR;
oxr_binding.d3d11.device = m_ghost_d3d_ctx->m_device;
}
- bool chooseSwapchainFormat(const std::vector<int64_t> &runtime_formats,
- int64_t &r_result,
- bool &r_is_srgb_format) const override
+ std::optional<int64_t> chooseSwapchainFormat(const std::vector<int64_t> &runtime_formats,
+ bool &r_is_srgb_format) const override
{
std::vector<int64_t> gpu_binding_formats = {
DXGI_FORMAT_R8G8B8A8_UNORM,
DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
};
- if (choose_swapchain_format_from_candidates(gpu_binding_formats, runtime_formats, r_result)) {
- r_is_srgb_format = (r_result == DXGI_FORMAT_R8G8B8A8_UNORM_SRGB);
- return true;
- }
- return false;
+ std::optional result = choose_swapchain_format_from_candidates(gpu_binding_formats,
+ runtime_formats);
+ r_is_srgb_format = result ? (*result == DXGI_FORMAT_R8G8B8A8_UNORM_SRGB) : false;
+ return result;
}
std::vector<XrSwapchainImageBaseHeader *> createSwapchainImages(uint32_t image_count) override
@@ -291,10 +285,10 @@ class GHOST_XrGraphicsBindingD3D : public GHOST_IXrGraphicsBinding {
return base_images;
}
- void submitToSwapchainImage(XrSwapchainImageBaseHeader *swapchain_image,
- const GHOST_XrDrawViewInfo *draw_info) override
+ void submitToSwapchainImage(XrSwapchainImageBaseHeader &swapchain_image,
+ const GHOST_XrDrawViewInfo &draw_info) override
{
- XrSwapchainImageD3D11KHR *d3d_swapchain_image = reinterpret_cast<XrSwapchainImageD3D11KHR *>(
+ XrSwapchainImageD3D11KHR &d3d_swapchain_image = reinterpret_cast<XrSwapchainImageD3D11KHR &>(
swapchain_image);
# if 0
@@ -308,22 +302,22 @@ class GHOST_XrGraphicsBindingD3D : public GHOST_IXrGraphicsBinding {
CD3D11_RENDER_TARGET_VIEW_DESC rtv_desc(D3D11_RTV_DIMENSION_TEXTURE2D,
DXGI_FORMAT_R8G8B8A8_UNORM);
- m_ghost_ctx->m_device->CreateRenderTargetView(d3d_swapchain_image->texture, &rtv_desc, &rtv);
+ m_ghost_ctx->m_device->CreateRenderTargetView(d3d_swapchain_image.texture, &rtv_desc, &rtv);
if (!m_shared_resource) {
m_shared_resource = m_ghost_ctx->createSharedOpenGLResource(
- draw_info->width, draw_info->height, rtv);
+ draw_info.width, draw_info.height, rtv);
}
- m_ghost_ctx->blitFromOpenGLContext(m_shared_resource, draw_info->width, draw_info->height);
+ m_ghost_ctx->blitFromOpenGLContext(m_shared_resource, draw_info.width, draw_info.height);
# else
if (!m_shared_resource) {
- m_shared_resource = m_ghost_d3d_ctx->createSharedOpenGLResource(draw_info->width,
- draw_info->height);
+ m_shared_resource = m_ghost_d3d_ctx->createSharedOpenGLResource(draw_info.width,
+ draw_info.height);
}
- m_ghost_d3d_ctx->blitFromOpenGLContext(m_shared_resource, draw_info->width, draw_info->height);
+ m_ghost_d3d_ctx->blitFromOpenGLContext(m_shared_resource, draw_info.width, draw_info.height);
m_ghost_d3d_ctx->m_device_ctx->OMSetRenderTargets(0, nullptr, nullptr);
m_ghost_d3d_ctx->m_device_ctx->CopyResource(
- d3d_swapchain_image->texture, m_ghost_d3d_ctx->getSharedTexture2D(m_shared_resource));
+ d3d_swapchain_image.texture, m_ghost_d3d_ctx->getSharedTexture2D(m_shared_resource));
# endif
}
@@ -345,14 +339,14 @@ class GHOST_XrGraphicsBindingD3D : public GHOST_IXrGraphicsBinding {
#endif // WIN32
std::unique_ptr<GHOST_IXrGraphicsBinding> GHOST_XrGraphicsBindingCreateFromType(
- GHOST_TXrGraphicsBinding type, GHOST_Context *context)
+ GHOST_TXrGraphicsBinding type, GHOST_Context &context)
{
switch (type) {
case GHOST_kXrGraphicsOpenGL:
- return std::unique_ptr<GHOST_XrGraphicsBindingOpenGL>(new GHOST_XrGraphicsBindingOpenGL());
+ return std::make_unique<GHOST_XrGraphicsBindingOpenGL>();
#ifdef WIN32
case GHOST_kXrGraphicsD3D11:
- return std::unique_ptr<GHOST_XrGraphicsBindingD3D>(new GHOST_XrGraphicsBindingD3D(context));
+ return std::make_unique<GHOST_XrGraphicsBindingD3D>(context);
#endif
default:
return nullptr;
diff --git a/intern/ghost/intern/GHOST_XrSession.cpp b/intern/ghost/intern/GHOST_XrSession.cpp
index 5a747b1e787..e43991853cb 100644
--- a/intern/ghost/intern/GHOST_XrSession.cpp
+++ b/intern/ghost/intern/GHOST_XrSession.cpp
@@ -62,8 +62,8 @@ struct GHOST_XrDrawInfo {
*
* \{ */
-GHOST_XrSession::GHOST_XrSession(GHOST_XrContext *xr_context)
- : m_context(xr_context), m_oxr(new OpenXRSessionData())
+GHOST_XrSession::GHOST_XrSession(GHOST_XrContext &xr_context)
+ : m_context(&xr_context), m_oxr(std::make_unique<OpenXRSessionData>())
{
}
@@ -113,7 +113,7 @@ void GHOST_XrSession::initSystem()
*
* \{ */
-static void create_reference_spaces(OpenXRSessionData *oxr, const GHOST_XrPose *base_pose)
+static void create_reference_spaces(OpenXRSessionData &oxr, const GHOST_XrPose &base_pose)
{
XrReferenceSpaceCreateInfo create_info = {XR_TYPE_REFERENCE_SPACE_CREATE_INFO};
create_info.poseInReferenceSpace.orientation.w = 1.0f;
@@ -142,11 +142,11 @@ static void create_reference_spaces(OpenXRSessionData *oxr, const GHOST_XrPose *
(void)base_pose;
#endif
- CHECK_XR(xrCreateReferenceSpace(oxr->session, &create_info, &oxr->reference_space),
+ CHECK_XR(xrCreateReferenceSpace(oxr.session, &create_info, &oxr.reference_space),
"Failed to create reference space.");
create_info.referenceSpaceType = XR_REFERENCE_SPACE_TYPE_VIEW;
- CHECK_XR(xrCreateReferenceSpace(oxr->session, &create_info, &oxr->view_space),
+ CHECK_XR(xrCreateReferenceSpace(oxr.session, &create_info, &oxr.view_space),
"Failed to create view reference space.");
}
@@ -173,15 +173,15 @@ void GHOST_XrSession::start(const GHOST_XrSessionBeginInfo *begin_info)
std::string requirement_str;
m_gpu_binding = GHOST_XrGraphicsBindingCreateFromType(m_context->getGraphicsBindingType(),
- m_gpu_ctx);
+ *m_gpu_ctx);
if (!m_gpu_binding->checkVersionRequirements(
- m_gpu_ctx, m_context->getInstance(), m_oxr->system_id, &requirement_str)) {
+ *m_gpu_ctx, m_context->getInstance(), m_oxr->system_id, &requirement_str)) {
std::ostringstream strstream;
strstream << "Available graphics context version does not meet the following requirements: "
<< requirement_str;
throw GHOST_XrException(strstream.str().c_str());
}
- m_gpu_binding->initFromGhostContext(m_gpu_ctx);
+ m_gpu_binding->initFromGhostContext(*m_gpu_ctx);
XrSessionCreateInfo create_info = {};
create_info.type = XR_TYPE_SESSION_CREATE_INFO;
@@ -195,7 +195,7 @@ void GHOST_XrSession::start(const GHOST_XrSessionBeginInfo *begin_info)
"detailed error information to the command line.");
prepareDrawing();
- create_reference_spaces(m_oxr.get(), &begin_info->base_pose);
+ create_reference_spaces(*m_oxr, begin_info->base_pose);
}
void GHOST_XrSession::requestEnd()
@@ -217,14 +217,14 @@ void GHOST_XrSession::endSession()
}
GHOST_XrSession::LifeExpectancy GHOST_XrSession::handleStateChangeEvent(
- const XrEventDataSessionStateChanged *lifecycle)
+ const XrEventDataSessionStateChanged &lifecycle)
{
- m_oxr->session_state = lifecycle->state;
+ m_oxr->session_state = lifecycle.state;
/* Runtime may send events for apparently destroyed session. Our handle should be NULL then. */
- assert((m_oxr->session == XR_NULL_HANDLE) || (m_oxr->session == lifecycle->session));
+ assert((m_oxr->session == XR_NULL_HANDLE) || (m_oxr->session == lifecycle.session));
- switch (lifecycle->state) {
+ switch (lifecycle.state) {
case XR_SESSION_STATE_READY: {
beginSession();
break;
@@ -272,7 +272,7 @@ void GHOST_XrSession::prepareDrawing()
m_oxr->views.resize(view_count, {XR_TYPE_VIEW});
- m_draw_info = std::unique_ptr<GHOST_XrDrawInfo>(new GHOST_XrDrawInfo());
+ m_draw_info = std::make_unique<GHOST_XrDrawInfo>();
}
void GHOST_XrSession::beginFrameDrawing()
@@ -295,43 +295,43 @@ void GHOST_XrSession::beginFrameDrawing()
}
}
-static void print_debug_timings(GHOST_XrDrawInfo *draw_info)
+static void print_debug_timings(GHOST_XrDrawInfo &draw_info)
{
/** Render time of last 8 frames (in ms) to calculate an average. */
std::chrono::duration<double, std::milli> duration = std::chrono::high_resolution_clock::now() -
- draw_info->frame_begin_time;
+ draw_info.frame_begin_time;
const double duration_ms = duration.count();
const int avg_frame_count = 8;
double avg_ms_tot = 0.0;
- if (draw_info->last_frame_times.size() >= avg_frame_count) {
- draw_info->last_frame_times.pop_front();
- assert(draw_info->last_frame_times.size() == avg_frame_count - 1);
+ if (draw_info.last_frame_times.size() >= avg_frame_count) {
+ draw_info.last_frame_times.pop_front();
+ assert(draw_info.last_frame_times.size() == avg_frame_count - 1);
}
- draw_info->last_frame_times.push_back(duration_ms);
- for (double ms_iter : draw_info->last_frame_times) {
+ draw_info.last_frame_times.push_back(duration_ms);
+ for (double ms_iter : draw_info.last_frame_times) {
avg_ms_tot += ms_iter;
}
printf("VR frame render time: %.0fms - %.2f FPS (%.2f FPS 8 frames average)\n",
duration_ms,
1000.0 / duration_ms,
- 1000.0 / (avg_ms_tot / draw_info->last_frame_times.size()));
+ 1000.0 / (avg_ms_tot / draw_info.last_frame_times.size()));
}
-void GHOST_XrSession::endFrameDrawing(std::vector<XrCompositionLayerBaseHeader *> *layers)
+void GHOST_XrSession::endFrameDrawing(std::vector<XrCompositionLayerBaseHeader *> &layers)
{
XrFrameEndInfo end_info = {XR_TYPE_FRAME_END_INFO};
end_info.displayTime = m_draw_info->frame_state.predictedDisplayTime;
end_info.environmentBlendMode = XR_ENVIRONMENT_BLEND_MODE_OPAQUE;
- end_info.layerCount = layers->size();
- end_info.layers = layers->data();
+ end_info.layerCount = layers.size();
+ end_info.layers = layers.data();
CHECK_XR(xrEndFrame(m_oxr->session, &end_info), "Failed to submit rendered frame.");
if (m_context->isDebugTimeMode()) {
- print_debug_timings(m_draw_info.get());
+ print_debug_timings(*m_draw_info);
}
}
@@ -349,7 +349,7 @@ void GHOST_XrSession::draw(void *draw_customdata)
layers.push_back(reinterpret_cast<XrCompositionLayerBaseHeader *>(&proj_layer));
}
- endFrameDrawing(&layers);
+ endFrameDrawing(layers);
}
static void copy_openxr_pose_to_ghost_pose(const XrPosef &oxr_pose, GHOST_XrPose &r_ghost_pose)
@@ -399,7 +399,7 @@ void GHOST_XrSession::drawView(GHOST_XrSwapchain &swapchain,
/* Draw! */
m_context->getCustomFuncs().draw_view_fn(&draw_view_info, draw_customdata);
- m_gpu_binding->submitToSwapchainImage(swapchain_image, &draw_view_info);
+ m_gpu_binding->submitToSwapchainImage(*swapchain_image, draw_view_info);
swapchain.releaseImage();
}
diff --git a/intern/ghost/intern/GHOST_XrSession.h b/intern/ghost/intern/GHOST_XrSession.h
index 74555c0c170..79a586411e9 100644
--- a/intern/ghost/intern/GHOST_XrSession.h
+++ b/intern/ghost/intern/GHOST_XrSession.h
@@ -37,13 +37,13 @@ class GHOST_XrSession {
SESSION_DESTROY,
};
- GHOST_XrSession(GHOST_XrContext *xr_context);
+ GHOST_XrSession(GHOST_XrContext &xr_context);
~GHOST_XrSession();
void start(const GHOST_XrSessionBeginInfo *begin_info);
void requestEnd();
- LifeExpectancy handleStateChangeEvent(const XrEventDataSessionStateChanged *lifecycle);
+ LifeExpectancy handleStateChangeEvent(const XrEventDataSessionStateChanged &lifecycle);
bool isRunning() const;
bool needsUpsideDownDrawing() const;
@@ -81,5 +81,5 @@ class GHOST_XrSession {
XrView &view,
void *draw_customdata);
void beginFrameDrawing();
- void endFrameDrawing(std::vector<XrCompositionLayerBaseHeader *> *layers);
+ void endFrameDrawing(std::vector<XrCompositionLayerBaseHeader *> &layers);
};
diff --git a/intern/ghost/intern/GHOST_XrSwapchain.cpp b/intern/ghost/intern/GHOST_XrSwapchain.cpp
index f7808c20112..9973d99cc37 100644
--- a/intern/ghost/intern/GHOST_XrSwapchain.cpp
+++ b/intern/ghost/intern/GHOST_XrSwapchain.cpp
@@ -54,11 +54,10 @@ static OpenXRSwapchainData::ImageVec swapchain_images_create(XrSwapchain swapcha
GHOST_XrSwapchain::GHOST_XrSwapchain(GHOST_IXrGraphicsBinding &gpu_binding,
const XrSession &session,
const XrViewConfigurationView &view_config)
- : m_oxr(new OpenXRSwapchainData())
+ : m_oxr(std::make_unique<OpenXRSwapchainData>())
{
XrSwapchainCreateInfo create_info = {XR_TYPE_SWAPCHAIN_CREATE_INFO};
uint32_t format_count = 0;
- int64_t chosen_format;
CHECK_XR(xrEnumerateSwapchainFormats(session, 0, &format_count, nullptr),
"Failed to get count of swapchain image formats.");
@@ -68,14 +67,16 @@ GHOST_XrSwapchain::GHOST_XrSwapchain(GHOST_IXrGraphicsBinding &gpu_binding,
"Failed to get swapchain image formats.");
assert(swapchain_formats.size() == format_count);
- if (!gpu_binding.chooseSwapchainFormat(swapchain_formats, chosen_format, m_is_srgb_buffer)) {
+ std::optional chosen_format = gpu_binding.chooseSwapchainFormat(swapchain_formats,
+ m_is_srgb_buffer);
+ if (!chosen_format) {
throw GHOST_XrException(
"Error: No format matching OpenXR runtime supported swapchain formats found.");
}
create_info.usageFlags = XR_SWAPCHAIN_USAGE_SAMPLED_BIT |
XR_SWAPCHAIN_USAGE_COLOR_ATTACHMENT_BIT;
- create_info.format = chosen_format;
+ create_info.format = *chosen_format;
create_info.sampleCount = view_config.recommendedSwapchainSampleCount;
create_info.width = view_config.recommendedImageRectWidth;
create_info.height = view_config.recommendedImageRectHeight;
@@ -95,7 +96,8 @@ GHOST_XrSwapchain::GHOST_XrSwapchain(GHOST_IXrGraphicsBinding &gpu_binding,
GHOST_XrSwapchain::GHOST_XrSwapchain(GHOST_XrSwapchain &&other)
: m_oxr(std::move(other.m_oxr)),
m_image_width(other.m_image_width),
- m_image_height(other.m_image_height)
+ m_image_height(other.m_image_height),
+ m_is_srgb_buffer(other.m_is_srgb_buffer)
{
/* Prevent xrDestroySwapchain call for the moved out item. */
other.m_oxr = nullptr;