[Bf-blender-cvs] [f30fcd6c85d] temp-ghost_openxr: Initially move XR files to GHOST and compile in C++
Julian Eisel
noreply at git.blender.org
Tue Jun 18 01:04:41 CEST 2019
Commit: f30fcd6c85d60d9ed3513033f39ae674bc742d1f
Author: Julian Eisel
Date: Mon Jun 17 23:45:28 2019 +0200
Branches: temp-ghost_openxr
https://developer.blender.org/rBf30fcd6c85d60d9ed3513033f39ae674bc742d1f
Initially move XR files to GHOST and compile in C++
===================================================================
M intern/ghost/CMakeLists.txt
M intern/ghost/GHOST_C-api.h
R084 source/blender/windowmanager/xr/intern/wm_xr.c intern/ghost/intern/GHOST_XR.cpp
R081 source/blender/windowmanager/xr/intern/wm_xr_event.c intern/ghost/intern/GHOST_XREvent.cpp
R079 source/blender/windowmanager/xr/intern/wm_xr_session.c intern/ghost/intern/GHOST_XRSession.cpp
R089 source/blender/windowmanager/xr/intern/wm_xr_intern.h intern/ghost/intern/GHOST_XR_intern.h
R100 source/blender/windowmanager/xr/intern/wm_xr_openxr_includes.h intern/ghost/intern/GHOST_XR_openxr_includes.h
M source/blender/windowmanager/CMakeLists.txt
M source/blender/windowmanager/intern/wm.c
M source/blender/windowmanager/intern/wm_operators.c
M source/blender/windowmanager/intern/wm_window.c
D source/blender/windowmanager/xr/wm_xr.h
===================================================================
diff --git a/intern/ghost/CMakeLists.txt b/intern/ghost/CMakeLists.txt
index d7b1a396303..61b8649db15 100644
--- a/intern/ghost/CMakeLists.txt
+++ b/intern/ghost/CMakeLists.txt
@@ -347,6 +347,37 @@ elseif(WIN32)
endif()
+if(WITH_OPENXR)
+ list(APPEND SRC
+ intern/GHOST_XR.cpp
+ intern/GHOST_XREvent.cpp
+ intern/GHOST_XRSession.cpp
+
+ intern/GHOST_XR_intern.h
+ intern/GHOST_XR_openxr_includes.h
+# intern/GHOST_XRSession.h
+ )
+ list(APPEND INC
+ )
+ list(APPEND INC_SYS
+ ${OPENXR_SDK_INCLUDES}
+ )
+
+ include(xr_platform_defines)
+
+ if(OPENXR_USE_BUNDLED_SRC)
+ if(WIN32)
+ set(OPENXR_LOADER_NAME openxr_loader-0_90)
+ else()
+ set(OPENXR_LOADER_NAME openxr_loader)
+ endif()
+
+ list(APPEND LIB ${OPENXR_LOADER_NAME})
+ endif()
+
+ add_definitions(-DWITH_OPENXR)
+endif()
+
add_definitions(${GL_DEFINITIONS})
blender_add_lib(bf_intern_ghost "${SRC}" "${INC}" "${INC_SYS}" "${LIB}")
diff --git a/intern/ghost/GHOST_C-api.h b/intern/ghost/GHOST_C-api.h
index 85bb9b54e2a..e9c90c37c7d 100644
--- a/intern/ghost/GHOST_C-api.h
+++ b/intern/ghost/GHOST_C-api.h
@@ -963,6 +963,58 @@ extern void GHOST_BeginIME(GHOST_WindowHandle windowhandle,
*/
extern void GHOST_EndIME(GHOST_WindowHandle windowhandle);
+#ifdef WITH_OPENXR
+# if !defined(WITH_OPENXR)
+// TODO
+static_assert(false, "WITH_OPENXR not defined, but wm_xr.c is being compiled.");
+# endif
+
+/**
+ * The XR view (i.e. the OpenXR runtime) may require a different graphics library than OpenGL. An
+ * offscreen texture of the viewport will then be drawn into using OpenGL, but the final texture
+ * draw call will happen through another lib (say DirectX).
+ *
+ * This enum defines the possible graphics bindings to attempt to enable.
+ */
+typedef enum {
+ WM_XR_GRAPHICS_UNKNOWN = 0,
+ WM_XR_GRAPHICS_OPENGL,
+# ifdef WIN32
+ WM_XR_GRAPHICS_D3D11,
+# endif
+ /* For later */
+ // WM_XR_GRAPHICS_VULKAN,
+} eWM_xrGraphicsBinding;
+/* An array of eWM_xrGraphicsBinding items defining the candidate bindings to use. The first
+ * available candidate will be chosen, so order defines priority. */
+typedef const eWM_xrGraphicsBinding *wmXRGraphicsBindingCandidates;
+
+typedef struct {
+ const wmXRGraphicsBindingCandidates gpu_binding_candidates;
+ unsigned int gpu_binding_candidates_count;
+} wmXRContextCreateInfo;
+
+/* xr-context */
+struct wmXRContext *wm_xr_context_create(const wmXRContextCreateInfo *create_info);
+void wm_xr_context_destroy(struct wmXRContext *xr_context);
+
+typedef void *(*wmXRGraphicsContextBindFn)(eWM_xrGraphicsBinding graphics_lib);
+typedef void (*wmXRGraphicsContextUnbindFn)(eWM_xrGraphicsBinding graphics_lib,
+ void *graphics_context);
+
+void wm_xr_graphics_context_bind_funcs(struct wmXRContext *xr_context,
+ wmXRGraphicsContextBindFn bind_fn,
+ wmXRGraphicsContextUnbindFn unbind_fn);
+
+/* sessions */
+GHOST_TSuccess wm_xr_session_is_running(const struct wmXRContext *xr_context);
+void wm_xr_session_start(struct wmXRContext *xr_context);
+void wm_xr_session_end(struct wmXRContext *xr_context);
+
+/* events */
+GHOST_TSuccess wm_xr_events_handle(struct wmXRContext *xr_context);
+#endif
+
#ifdef __cplusplus
}
#endif
diff --git a/source/blender/windowmanager/xr/intern/wm_xr.c b/intern/ghost/intern/GHOST_XR.cpp
similarity index 84%
rename from source/blender/windowmanager/xr/intern/wm_xr.c
rename to intern/ghost/intern/GHOST_XR.cpp
index c692ae60d5b..cc26ba60e14 100644
--- a/source/blender/windowmanager/xr/intern/wm_xr.c
+++ b/intern/ghost/intern/GHOST_XR.cpp
@@ -20,21 +20,18 @@
* Abstraction for XR (VR, AR, MR, ..) access via OpenXR.
*/
+#include <cassert>
+#include <cstring>
+#include <cstdio>
+#include <stdlib.h>
#include <string.h>
-#include "CLG_log.h"
+#include "GHOST_C-api.h"
-#include "MEM_guardedalloc.h"
+#include "GHOST_XR_openxr_includes.h"
-#include "BLI_assert.h"
-#include "BLI_compiler_attrs.h"
-#include "BLI_string.h"
-#include "BLI_utildefines.h"
-
-#include "wm_xr_openxr_includes.h"
-
-#include "wm_xr.h"
-#include "wm_xr_intern.h"
+//#include "wm_xr.h"
+#include "GHOST_XR_intern.h"
/* Toggle printing of available OpenXR extensions and API-layers. Should probably be changed to use
* CLOG at some point */
@@ -59,8 +56,8 @@ static bool openxr_gather_extensions_ex(OpenXRData *oxr, const char *layer_name)
return true;
}
- oxr->extensions = MEM_calloc_arrayN(
- extension_count, sizeof(*oxr->extensions), "xrExtensionProperties");
+ oxr->extensions = (XrExtensionProperties *)calloc(oxr->extension_count,
+ sizeof(*oxr->extensions));
oxr->extension_count = extension_count;
for (uint i = 0; i < extension_count; i++) {
oxr->extensions[i].type = XR_TYPE_EXTENSION_PROPERTIES;
@@ -101,7 +98,7 @@ static bool openxr_gather_api_layers(OpenXRData *oxr)
return true;
}
- oxr->layers = MEM_calloc_arrayN(layer_count, sizeof(*oxr->layers), "XrApiLayerProperties");
+ oxr->layers = (XrApiLayerProperties *)calloc(layer_count, sizeof(*oxr->layers));
oxr->layer_count = layer_count;
for (uint i = 0; i < layer_count; i++) {
oxr->layers[i].type = XR_TYPE_API_LAYER_PROPERTIES;
@@ -120,12 +117,10 @@ static bool openxr_gather_api_layers(OpenXRData *oxr)
return true;
}
-ATTR_NONNULL()
-ATTR_WARN_UNUSED_RESULT
static bool openxr_extension_is_available(const OpenXRData *oxr, const char *extension_name)
{
for (uint i = 0; i < oxr->extension_count; i++) {
- if (STREQ(oxr->extensions[i].extensionName, extension_name)) {
+ if (strncmp(oxr->extensions[i].extensionName, extension_name, strlen(extension_name)) == 0) {
return true;
}
}
@@ -143,7 +138,7 @@ static const char *openxr_ext_name_from_wm_gpu_binding(eWM_xrGraphicsBinding bin
return XR_KHR_D3D11_ENABLE_EXTENSION_NAME;
#endif
case WM_XR_GRAPHICS_UNKNOWN:
- BLI_assert(false);
+ assert(false);
}
return NULL;
@@ -156,11 +151,11 @@ static const char *openxr_ext_name_from_wm_gpu_binding(eWM_xrGraphicsBinding bin
static eWM_xrGraphicsBinding openxr_graphics_extension_to_enable_get(
const OpenXRData *oxr, const wmXRContextCreateInfo *create_info)
{
- BLI_assert(create_info->gpu_binding_candidates != NULL);
- BLI_assert(create_info->gpu_binding_candidates_count > 0);
+ assert(create_info->gpu_binding_candidates != NULL);
+ assert(create_info->gpu_binding_candidates_count > 0);
for (uint i = 0; i < create_info->gpu_binding_candidates_count; i++) {
- BLI_assert(create_info->gpu_binding_candidates[i] != WM_XR_GRAPHICS_UNKNOWN);
+ assert(create_info->gpu_binding_candidates[i] != WM_XR_GRAPHICS_UNKNOWN);
const char *ext_name = openxr_ext_name_from_wm_gpu_binding(
create_info->gpu_binding_candidates[i]);
if (openxr_extension_is_available(oxr, ext_name)) {
@@ -179,10 +174,10 @@ static void openxr_extensions_to_enable_get(const wmXRContext *context,
const char ***r_ext_names,
uint *r_ext_count)
{
- BLI_assert(context->gpu_binding != WM_XR_GRAPHICS_UNKNOWN);
+ assert(context->gpu_binding != WM_XR_GRAPHICS_UNKNOWN);
const char *gpu_binding = openxr_ext_name_from_wm_gpu_binding(context->gpu_binding);
- BLI_assert(gpu_binding);
+ assert(gpu_binding);
{
/* Zero sized array is GCC extension, so disable until it grows. */
@@ -194,11 +189,11 @@ static void openxr_extensions_to_enable_get(const wmXRContext *context,
const uint try_ext_count = 0;
#endif
- BLI_assert(r_ext_names != NULL);
- BLI_assert(r_ext_count != NULL);
+ assert(r_ext_names != NULL);
+ assert(r_ext_count != NULL);
/* try_ext_count + 1 for graphics binding extension. */
- *r_ext_names = MEM_malloc_arrayN(try_ext_count + 1, sizeof(char *), __func__);
+ *r_ext_names = (const char **)malloc(sizeof(char *) * (try_ext_count + 1));
/* Add graphics binding extension. */
*r_ext_names[0] = gpu_binding;
@@ -213,14 +208,12 @@ static void openxr_extensions_to_enable_get(const wmXRContext *context,
}
}
-ATTR_NONNULL()
static bool openxr_instance_create(wmXRContext *context)
{
XrInstanceCreateInfo create_info = {.type = XR_TYPE_INSTANCE_CREATE_INFO};
OpenXRData *oxr = &context->oxr;
- BLI_strncpy(
- create_info.applicationInfo.applicationName, "Blender", XR_MAX_APPLICATION_NAME_SIZE);
+ strncpy(create_info.applicationInfo.applicationName, "Blender", XR_MAX_APPLICATION_NAME_SIZE);
create_info.applicationInfo.apiVersion = XR_CURRENT_API_VERSION;
openxr_extensions_to_enable_get(
@@ -232,10 +225,9 @@ static bool openxr_instance_create(wmXRContext *context)
return true;
}
-ATTR_NONNULL()
static void openxr_instance_log_print(OpenXRData *oxr)
{
- BLI_assert(oxr->instance != XR_NULL_HANDLE);
+ assert(oxr->instance != XR_NULL_HANDLE);
XrInstanceProperties instanceProperties = {.type = XR_TYPE_INSTANCE_PROPERTIES};
xrGetInstanceProperties(oxr->instance, &instanceProperties);
@@ -250,14 +242,14 @@ static void openxr_instance_log_print(OpenXRData *oxr)
*/
wmXRContext *wm_xr_context_create(const wmXRContextCreateInfo *create_info)
{
- wmXRContext *xr_context = MEM_callocN(sizeof(*xr_context), "wmXRContext");
+ wmXRContext *xr_context = (wmXRContext *)calloc(1, sizeof(*xr_context));
OpenXRData *oxr = &xr_context->oxr;
#ifdef USE_EXT_LAYER_PRINTS
puts("Available OpenXR layers/extensions:");
#endif
if (!openxr_gather_api_layers(oxr) || !openxr_gather_extensions(oxr)) {
- MEM_freeN(xr_context);
+ free(xr_context);
return NULL;
}
#ifdef USE_EXT_LAYER_PRINTS
@@ -266,7 +258,7 @@ wmXRContext *wm_xr_context_create(const wmXRContextCreateInfo *create_info)
xr_context->gpu_binding = openxr_graphics_extension_to_enable_get(oxr, create_info);
- BLI_assert(xr_context->oxr.instance == XR_NULL_HANDLE);
+ assert(xr_context->oxr.instance == XR_NULL_HANDLE);
openxr_instance_create(xr_context);
openxr_instance_log_print(oxr);
@@ -289,12 +281,12 @@ void wm_xr_context_destroy(wmXRContext *xr_context)
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list