[Bf-blender-cvs] [2f68a76409e] soc-2019-openxr: Split wm_xr.c into multiple files
Julian Eisel
noreply at git.blender.org
Tue Jun 11 17:53:11 CEST 2019
Commit: 2f68a76409eaed743790727ee3a8296f070ee40d
Author: Julian Eisel
Date: Tue Jun 11 17:50:16 2019 +0200
Branches: soc-2019-openxr
https://developer.blender.org/rB2f68a76409eaed743790727ee3a8296f070ee40d
Split wm_xr.c into multiple files
Similar to gizmo/ and message_bus/, there's now a xr/ directory
containing header files and a intern/ directory for source and internal
header files.
Guess this is reasonable to do. And better to do early on to avoid
loosing much git history.
===================================================================
M release/scripts/addons
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
M source/blender/windowmanager/wm.h
R060 source/blender/windowmanager/intern/wm_xr.c source/blender/windowmanager/xr/intern/wm_xr.c
A source/blender/windowmanager/xr/intern/wm_xr_event.c
A source/blender/windowmanager/xr/intern/wm_xr_intern.h
A source/blender/windowmanager/xr/intern/wm_xr_openxr_includes.h
A source/blender/windowmanager/xr/intern/wm_xr_session.c
A source/blender/windowmanager/xr/wm_xr.h
===================================================================
diff --git a/release/scripts/addons b/release/scripts/addons
index 7317987baa8..fcf7d4c16b1 160000
--- a/release/scripts/addons
+++ b/release/scripts/addons
@@ -1 +1 @@
-Subproject commit 7317987baa8aac52a11d6af0a825d87acc658f60
+Subproject commit fcf7d4c16b17c34579fc080386425e0774a502d2
diff --git a/source/blender/windowmanager/CMakeLists.txt b/source/blender/windowmanager/CMakeLists.txt
index a6a1f068e33..41b992862fa 100644
--- a/source/blender/windowmanager/CMakeLists.txt
+++ b/source/blender/windowmanager/CMakeLists.txt
@@ -176,7 +176,16 @@ endif()
if(WITH_OPENXR)
list(APPEND SRC
- intern/wm_xr.c
+ xr/intern/wm_xr.c
+ xr/intern/wm_xr_event.c
+ xr/intern/wm_xr_session.c
+
+ xr/wm_xr.h
+ xr/intern/wm_xr_intern.h
+ xr/intern/wm_xr_openxr_includes.h
+ )
+ list(APPEND INC
+ xr
)
list(APPEND INC_SYS
${OPENXR_SDK_INCLUDES}
diff --git a/source/blender/windowmanager/intern/wm.c b/source/blender/windowmanager/intern/wm.c
index a3b2b85e53b..87a2e1a4647 100644
--- a/source/blender/windowmanager/intern/wm.c
+++ b/source/blender/windowmanager/intern/wm.c
@@ -52,6 +52,9 @@
#include "wm_event_system.h"
#include "wm_draw.h"
#include "wm.h"
+#ifdef WITH_OPENXR
+# include "wm_xr.h"
+#endif
#include "ED_screen.h"
#include "BKE_undo_system.h"
diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c
index 30965abc4e1..bbea21b7c7b 100644
--- a/source/blender/windowmanager/intern/wm_operators.c
+++ b/source/blender/windowmanager/intern/wm_operators.c
@@ -115,6 +115,9 @@
#include "wm_event_types.h"
#include "wm_files.h"
#include "wm_window.h"
+#ifdef WITH_OPENXR
+# include "wm_xr.h"
+#endif
#define UNDOCUMENTED_OPERATOR_TIP N_("(undocumented operator)")
diff --git a/source/blender/windowmanager/intern/wm_window.c b/source/blender/windowmanager/intern/wm_window.c
index 6ab7466ac48..a63726ae82d 100644
--- a/source/blender/windowmanager/intern/wm_window.c
+++ b/source/blender/windowmanager/intern/wm_window.c
@@ -64,6 +64,9 @@
#include "wm_files.h"
#include "wm_window.h"
#include "wm_event_system.h"
+#ifdef WITH_OPENXR
+# include "wm_xr.h"
+#endif
#include "ED_anim_api.h"
#include "ED_render.h"
diff --git a/source/blender/windowmanager/wm.h b/source/blender/windowmanager/wm.h
index 6eb3a16fd25..fa375efb469 100644
--- a/source/blender/windowmanager/wm.h
+++ b/source/blender/windowmanager/wm.h
@@ -95,49 +95,4 @@ void wm_stereo3d_set_cancel(bContext *C, wmOperator *op);
void wm_open_init_load_ui(wmOperator *op, bool use_prefs);
void wm_open_init_use_scripts(wmOperator *op, bool use_prefs);
-/* wm_xr.c */
-#ifdef WITH_OPENXR
-
-/**
- * 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)
- ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
-void wm_xr_context_destroy(struct wmXRContext *xr_context);
-
-/* sessions */
-bool wm_xr_session_is_running(const struct wmXRContext *xr_context) ATTR_WARN_UNUSED_RESULT;
-eWM_xrGraphicsBinding wm_xr_session_active_graphics_binding_type_get(
- const struct wmXRContext *xr_context) ATTR_NONNULL();
-void wm_xr_session_start(struct wmXRContext *xr_context, void *ghost_context) ATTR_NONNULL();
-void wm_xr_session_end(struct wmXRContext *xr_context) ATTR_NONNULL();
-
-/* events */
-bool wm_xr_events_handle(struct wmXRContext *xr_context) ATTR_NONNULL();
-#endif
-
#endif /* __WM_H__ */
diff --git a/source/blender/windowmanager/intern/wm_xr.c b/source/blender/windowmanager/xr/intern/wm_xr.c
similarity index 60%
rename from source/blender/windowmanager/intern/wm_xr.c
rename to source/blender/windowmanager/xr/intern/wm_xr.c
index 36d745c85a9..d3b9969d056 100644
--- a/source/blender/windowmanager/intern/wm_xr.c
+++ b/source/blender/windowmanager/xr/intern/wm_xr.c
@@ -24,76 +24,22 @@
#include "CLG_log.h"
-#include "BKE_context.h"
-
#include "MEM_guardedalloc.h"
#include "BLI_assert.h"
#include "BLI_compiler_attrs.h"
#include "BLI_string.h"
-#include "DNA_windowmanager_types.h"
+#include "BLI_utildefines.h"
-#include "GHOST_C-api.h"
+#include "wm_xr_openxr_includes.h"
-/* Platform headers */
-#ifdef XR_USE_PLATFORM_WIN32
-# define WIN32_LEAN_AND_MEAN
-# define NOMINMAX
-# include <windows.h>
-#endif
-/* Graphics headers */
-#ifdef XR_USE_GRAPHICS_API_D3D10
-# include <d3d10_1.h>
-#endif
-#ifdef XR_USE_GRAPHICS_API_D3D11
-# include <d3d11_4.h>
-#endif
-#ifdef XR_USE_GRAPHICS_API_D3D12
-# include <d3d12.h>
-#endif
-#ifdef WITH_X11
-# include <GL/glxew.h>
-#endif
-
-#include "openxr/openxr.h"
-#include "openxr/openxr_platform.h"
-
-#include "WM_api.h"
-#include "WM_types.h"
-#include "wm.h"
+#include "wm_xr.h"
+#include "wm_xr_intern.h"
/* Toggle printing of available OpenXR extensions and API-layers. Should probably be changed to use
* CLOG at some point */
#define USE_EXT_LAYER_PRINTS
-#if !defined(WITH_OPENXR)
-static_assert(false, "WITH_OPENXR not defined, but wm_xr.c is being compiled.");
-#endif
-
-typedef struct OpenXRData {
- XrInstance instance;
-
- XrExtensionProperties *extensions;
- uint32_t extension_count;
-
- XrApiLayerProperties *layers;
- uint32_t layer_count;
-
- XrSystemId system_id;
- XrSession session;
- XrSessionState session_state;
-} OpenXRData;
-
-typedef struct wmXRContext {
- OpenXRData oxr;
-
- /** Active graphics binding type. */
- eWM_xrGraphicsBinding gpu_binding;
-
- /** Names of enabled extensions */
- const char **enabled_extensions;
-} wmXRContext;
-
/**
* \param layer_name May be NULL for extensions not belonging to a specific layer.
*/
@@ -337,153 +283,3 @@ void wm_xr_context_destroy(wmXRContext *xr_context)
MEM_SAFE_FREE(xr_context);
}
-
-bool wm_xr_session_is_running(const wmXRContext *xr_context)
-{
- const OpenXRData *oxr = &xr_context->oxr;
-
- if (oxr->session == XR_NULL_HANDLE) {
- return false;
- }
-
- return ELEM(oxr->session_state,
- XR_SESSION_STATE_RUNNING,
- XR_SESSION_STATE_VISIBLE,
- XR_SESSION_STATE_FOCUSED);
-}
-
-/**
- * A system in OpenXR the combination of some sort of HMD plus controllers and whatever other
- * devices are managed through OpenXR. So this attempts to init the HMD and the other devices.
- */
-static void wm_xr_system_init(OpenXRData *oxr)
-{
- BLI_assert(oxr->instance != XR_NULL_HANDLE);
- BLI_assert(oxr->system_id == XR_NULL_SYSTEM_ID);
-
- XrSystemGetInfo system_info = {.type = XR_TYPE_SYSTEM_GET_INFO};
- system_info.formFactor = XR_FORM_FACTOR_HEAD_MOUNTED_DISPLAY;
-
- xrGetSystem(oxr->instance, &system_info, &oxr->system_id);
-}
-
-eWM_xrGraphicsBinding wm_xr_session_active_graphics_binding_type_get(const wmXRContext *xr_context)
-{
- return xr_context->gpu_binding;
-}
-
-static void *openxr_graphics_binding_create(const wmXRContext *xr_context,
- GHOST_ContextHandle UNUSED(ghost_context))
-{
- void *binding_ptr = NULL;
-
- switch (xr_context->gpu_binding) {
- case WM_XR_GRAPHICS_OPENGL: {
-#if defined(WITH_X11)
- XrGraphicsBindingOpenGLXlibKHR binding = {.type = XR_TYPE_GRAPHICS_BINDING_OPENGL_XLIB_KHR};
-
-#elif defined(WIN32)
- XrGraphicsBindingOpenGLWin32KHR binding = {
- .type = XR_TYPE_GRAPHICS_BINDING_OPENGL_WIN32_KHR};
-
-#endif
-
- binding_ptr = MEM_mallocN(sizeof(binding), __func__);
- memcpy(binding_ptr, &binding, sizeof(binding));
-
- break;
- }
-#ifdef WIN32
- case WM_XR_GRAPHICS_D3D11: {
- XrGraphicsBindingD3D11KHR binding = {.type = XR_TYPE_GRAPHICS_BINDING_D3D11_KHR};
-
- binding_ptr = MEM_mallocN(sizeof(binding), __func__);
- memcpy(binding_ptr, &binding, sizeof(binding));
-
- break;
- }
-#endif
- default:
- BLI_assert(false);
- }
-
- return binding_ptr;
-}
-
-void wm_xr_session_start(wmXRContext *xr_context, void *ghost_context)
-{
- OpenXRData *oxr = &xr_context->oxr;
-
- BLI_assert(oxr->instance != XR_NULL_HANDLE);
- BLI_assert(oxr->session == XR_NULL_HANDLE);
-
- wm_xr_system_init(oxr);
-
- XrSessionCreateInfo create_info = {.type = XR_TYPE_SESSION_CREATE_INFO};
- create_info.systemId = oxr->system_id;
- create_info.next = openxr_graphics_binding_create(xr_context, ghost_context);
-
- xrCreateSession(oxr->instance, &create_info, &oxr->session);
-}
-
-void wm_xr_session_end(wmXRContext *xr_context)
-{
- xrEndSession(xr_context->oxr.session);
-}
-
-static void wm_xr_session_state_change(OpenXRData *oxr,
- const XrEventDataSessionStateChanged *lifecycle)
-{
- oxr->session_state = lifecycle->state;
-
- switch (lifecycle->state) {
- case XR_SESSION_STATE_READY: {
- XrSessionBeginInfo begin_info = {
- .type = XR_TYPE_SESSION_BEGIN_INFO,
- .primaryViewConfigurationType = XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO};
- xrBeginSession(oxr->session, &begin_info);
- break;
- }
- case XR_SESSION_STATE_STOPPING: {
- BLI_assert(oxr->session != XR_NULL_HANDLE);
- xrEndSession(oxr->session);
- }
- default:
- break;
- }
-}
-
-static bool wm_xr_event_poll_next(OpenXRData *oxr, XrEventDataBuffer *r_event_data)
-{
- /* (Re-)initialize as required by specification */
- r_event_data->type = XR_TYPE_EVENT_DATA_BUFFER;
- r_event_data->next = NULL;
-
- return
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list