[Bf-blender-cvs] [5891e86420d] soc-2019-openxr: Cleanup GHOST_Xr types and functions
Julian Eisel
noreply at git.blender.org
Mon Jul 1 19:06:12 CEST 2019
Commit: 5891e86420d9718670841f0282bac499c225ccd8
Author: Julian Eisel
Date: Mon Jul 1 18:56:26 2019 +0200
Branches: soc-2019-openxr
https://developer.blender.org/rB5891e86420d9718670841f0282bac499c225ccd8
Cleanup GHOST_Xr types and functions
* Move GHOST_Xr types to GHOST_Types.h
* Add GHOST_XrPose. We'll have to pass around pose data at multiple
places.
* Don't require extra call to prepare session rendering, handle
everything through GHOST_XrSessionStart
* Naming
===================================================================
M intern/ghost/GHOST_C-api.h
M intern/ghost/GHOST_Types.h
M intern/ghost/intern/GHOST_XrSession.cpp
M source/blender/windowmanager/intern/wm_xr.c
===================================================================
diff --git a/intern/ghost/GHOST_C-api.h b/intern/ghost/GHOST_C-api.h
index d9f9cf93bd3..e0d951885b5 100644
--- a/intern/ghost/GHOST_C-api.h
+++ b/intern/ghost/GHOST_C-api.h
@@ -30,21 +30,6 @@
extern "C" {
#endif
-/**
- * Creates a "handle" for a C++ GHOST object.
- * A handle is just an opaque pointer to an empty struct.
- * In the API the pointer is cast to the actual C++ class.
- * The 'name' argument to the macro is the name of the handle to create.
- */
-
-GHOST_DECLARE_HANDLE(GHOST_SystemHandle);
-GHOST_DECLARE_HANDLE(GHOST_TimerTaskHandle);
-GHOST_DECLARE_HANDLE(GHOST_WindowHandle);
-GHOST_DECLARE_HANDLE(GHOST_EventHandle);
-GHOST_DECLARE_HANDLE(GHOST_RectangleHandle);
-GHOST_DECLARE_HANDLE(GHOST_EventConsumerHandle);
-GHOST_DECLARE_HANDLE(GHOST_ContextHandle);
-
/**
* Definition of a callback routine that receives events.
* \param event The event received.
@@ -990,58 +975,10 @@ extern void GHOST_EndIME(GHOST_WindowHandle windowhandle);
#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 {
- GHOST_kXrGraphicsUnknown = 0,
- GHOST_kXrGraphicsOpenGL,
-# ifdef WIN32
- GHOST_kXrGraphicsD3D11,
-# endif
- /* For later */
- // GHOST_kXrGraphicsVulkan,
-} GHOST_TXrGraphicsBinding;
-/* An array of GHOST_TXrGraphicsBinding items defining the candidate bindings to use. The first
- * available candidate will be chosen, so order defines priority. */
-typedef const GHOST_TXrGraphicsBinding *GHOST_XrGraphicsBindingCandidates;
-
-typedef struct {
- const GHOST_XrGraphicsBindingCandidates gpu_binding_candidates;
- unsigned int gpu_binding_candidates_count;
-} GHOST_XrContextCreateInfo;
-
-typedef struct {
- int ofsx, ofsy;
- int width, height;
-
- struct {
- float position[3];
- float quat[4];
- } pose;
-
- struct {
- float angle_left, angle_right;
- float angle_up, angle_down;
- } fov;
-} GHOST_XrDrawViewInfo;
-
/* xr-context */
struct GHOST_XrContext *GHOST_XrContextCreate(const GHOST_XrContextCreateInfo *create_info);
void GHOST_XrContextDestroy(struct GHOST_XrContext *xr_context);
-typedef void *(*GHOST_XrGraphicsContextBindFn)(GHOST_TXrGraphicsBinding graphics_lib);
-typedef void (*GHOST_XrGraphicsContextUnbindFn)(GHOST_TXrGraphicsBinding graphics_lib,
- void *graphics_context);
-/* XXX hacky: returns GHOST_ContextHandle so DirectX binding can get a handle to the OpenGL
- * offscreen context. */
-typedef GHOST_ContextHandle (*GHOST_XrDrawViewFn)(const GHOST_XrDrawViewInfo *draw_view,
- void *customdata);
-
void GHOST_XrGraphicsContextBindFuncs(struct GHOST_XrContext *xr_context,
GHOST_XrGraphicsContextBindFn bind_fn,
GHOST_XrGraphicsContextUnbindFn unbind_fn);
@@ -1052,7 +989,6 @@ void GHOST_XrDrawViewFunc(struct GHOST_XrContext *xr_context, GHOST_XrDrawViewFn
GHOST_TSuccess GHOST_XrSessionIsRunning(const struct GHOST_XrContext *xr_context);
void GHOST_XrSessionStart(struct GHOST_XrContext *xr_context);
void GHOST_XrSessionEnd(struct GHOST_XrContext *xr_context);
-void GHOST_XrSessionRenderingPrepare(struct GHOST_XrContext *xr_context);
void GHOST_XrSessionDrawViews(struct GHOST_XrContext *xr_context, void *customdata);
/* events */
diff --git a/intern/ghost/GHOST_Types.h b/intern/ghost/GHOST_Types.h
index dfefd7cc474..89bab0987a7 100644
--- a/intern/ghost/GHOST_Types.h
+++ b/intern/ghost/GHOST_Types.h
@@ -41,6 +41,21 @@
} * name
#endif
+/**
+ * Creates a "handle" for a C++ GHOST object.
+ * A handle is just an opaque pointer to an empty struct.
+ * In the API the pointer is cast to the actual C++ class.
+ * The 'name' argument to the macro is the name of the handle to create.
+ */
+
+GHOST_DECLARE_HANDLE(GHOST_SystemHandle);
+GHOST_DECLARE_HANDLE(GHOST_TimerTaskHandle);
+GHOST_DECLARE_HANDLE(GHOST_WindowHandle);
+GHOST_DECLARE_HANDLE(GHOST_EventHandle);
+GHOST_DECLARE_HANDLE(GHOST_RectangleHandle);
+GHOST_DECLARE_HANDLE(GHOST_EventConsumerHandle);
+GHOST_DECLARE_HANDLE(GHOST_ContextHandle);
+
typedef char GHOST_TInt8;
typedef unsigned char GHOST_TUns8;
typedef short GHOST_TInt16;
@@ -545,4 +560,59 @@ struct GHOST_TimerTaskHandle__;
typedef void (*GHOST_TimerProcPtr)(struct GHOST_TimerTaskHandle__ *task, GHOST_TUns64 time);
#endif
+#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 {
+ GHOST_kXrGraphicsUnknown = 0,
+ GHOST_kXrGraphicsOpenGL,
+# ifdef WIN32
+ GHOST_kXrGraphicsD3D11,
+# endif
+ /* For later */
+ // GHOST_kXrGraphicsVulkan,
+} GHOST_TXrGraphicsBinding;
+/* An array of GHOST_TXrGraphicsBinding items defining the candidate bindings to use. The first
+ * available candidate will be chosen, so order defines priority. */
+typedef const GHOST_TXrGraphicsBinding *GHOST_XrGraphicsBindingCandidates;
+
+typedef struct {
+ const GHOST_XrGraphicsBindingCandidates gpu_binding_candidates;
+ unsigned int gpu_binding_candidates_count;
+} GHOST_XrContextCreateInfo;
+
+typedef struct {
+ float position[3];
+ /* Blender convention (w, x, y, z) */
+ float orientation_quat[4];
+} GHOST_XrPose;
+
+typedef struct {
+ int ofsx, ofsy;
+ int width, height;
+
+ GHOST_XrPose pose;
+
+ struct {
+ float angle_left, angle_right;
+ float angle_up, angle_down;
+ } fov;
+} GHOST_XrDrawViewInfo;
+
+typedef void *(*GHOST_XrGraphicsContextBindFn)(GHOST_TXrGraphicsBinding graphics_lib);
+typedef void (*GHOST_XrGraphicsContextUnbindFn)(GHOST_TXrGraphicsBinding graphics_lib,
+ void *graphics_context);
+/* XXX hacky: returns GHOST_ContextHandle so DirectX binding can get a handle to the OpenGL
+ * offscreen context. */
+typedef GHOST_ContextHandle (*GHOST_XrDrawViewFn)(const GHOST_XrDrawViewInfo *draw_view,
+ void *customdata);
+
+#endif
+
#endif // __GHOST_TYPES_H__
diff --git a/intern/ghost/intern/GHOST_XrSession.cpp b/intern/ghost/intern/GHOST_XrSession.cpp
index ea26f83c915..fbf6d5d857a 100644
--- a/intern/ghost/intern/GHOST_XrSession.cpp
+++ b/intern/ghost/intern/GHOST_XrSession.cpp
@@ -72,69 +72,6 @@ static void GHOST_XrSystemInit(OpenXRData *oxr)
xrGetSystem(oxr->instance, &system_info, &oxr->system_id);
}
-void GHOST_XrSessionStart(GHOST_XrContext *xr_context)
-{
- OpenXRData *oxr = &xr_context->oxr;
-
- assert(oxr->instance != XR_NULL_HANDLE);
- assert(oxr->session == XR_NULL_HANDLE);
- if (xr_context->gpu_ctx_bind_fn == nullptr) {
- fprintf(stderr,
- "Invalid API usage: No way to bind graphics context to the XR session. Call "
- "GHOST_XrGraphicsContextBindFuncs() with valid parameters before starting the "
- "session (through GHOST_XrSessionStart()).");
- return;
- }
-
- GHOST_XrSystemInit(oxr);
-
- GHOST_XrGraphicsContextBind(*xr_context);
- if (xr_context->gpu_ctx == nullptr) {
- fprintf(stderr,
- "Invalid API usage: No graphics context returned through the callback set with "
- "GHOST_XrGraphicsContextBindFuncs(). This is required for session starting (through "
- "GHOST_XrSessionStart()).\n");
- return;
- }
- xr_context->gpu_binding = GHOST_XrGraphicsBindingCreateFromType(xr_context->gpu_binding_type);
- xr_context->gpu_binding->initFromGhostContext(xr_context->gpu_ctx);
-
- XrSessionCreateInfo create_info{};
- create_info.type = XR_TYPE_SESSION_CREATE_INFO;
- create_info.systemId = oxr->system_id;
- create_info.next = &xr_context->gpu_binding->oxr_binding;
-
- xrCreateSession(oxr->instance, &create_info, &oxr->session);
-}
-
-void GHOST_XrSessionEnd(GHOST_XrContext *xr_context)
-{
- xrEndSession(xr_context->oxr.session);
- GHOST_XrGraphicsContextUnbind(*xr_context);
-}
-
-void GHOST_XrSessionStateChange(OpenXRData *oxr, const XrEventDataSessionStateChanged &lifecycle)
-{
- oxr->session_state = lifecycle.state;
-
- switch (lifecycle.state) {
- case XR_SESSION_STATE_READY: {
- XrSessionBeginInfo begin_info{};
-
- begin_info.type = XR_TYPE_SESSION_BEGIN_INFO;
- begin_info.primaryViewConfigurationType = oxr->view_type;
- xrBeginSession(oxr->session, &begin_info);
- break;
- }
- case XR_SESSION_STATE_STOPPING: {
- assert(oxr->session != XR_NULL_HANDLE);
- xrEndSession(oxr->session);
- }
- default:
- break;
- }
-}
-
static std::vector<XrSwapchainImageBaseHeader *> swapchain_images_create(
XrSwapchain swapchain, GHOST_IXrGraphicsBinding *gpu_binding)
{
@@ -182,7 +119,7 @@ static XrSwapchain swapchain_create(const XrSession session,
return swapchain;
}
-void GHOST_XrSessionRenderingPrepare(GHOST_XrContext *xr_context)
+void prepare_drawing(GHOST_XrContext *xr_context)
{
OpenXRData *oxr = &xr_context->oxr;
std::vector<XrViewConfigurationView> view_configs;
@@ -211,7 +148,72 @@ void GHOST_XrSessionRenderingPrepare(GHOST_XrContext *xr_context)
oxr->views.resize(view_count, {XR_TYPE_VIEW});
}
-static void drawing_begin(GHOST_XrContext *xr_context)
+void GHOST_XrSessionStart(GHOST_XrContext *xr_context)
+{
+ OpenXRData *oxr = &xr_context->oxr;
+
+ assert(oxr->instance != XR_NULL_HANDLE);
+ assert(oxr->session == XR_NULL_HANDLE);
+ if (xr_context->gpu_ctx_bind_fn == nullptr) {
+ fprintf(stderr,
+ "Invalid API usage: No way to bind graphics context to the XR session. Call "
+ "GHOST_XrGraphicsContextBindFuncs() with valid parameters before starting the "
+ "session (through GHOST_XrSessionStart()).");
+ return;
+ }
+
+ GHOST_XrSystemInit(oxr);
+
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list