[Bf-blender-cvs] [62cde7a9ef8] soc-2019-openxr: Finish VR view drawing callback set up
Julian Eisel
noreply at git.blender.org
Thu Jun 27 19:22:26 CEST 2019
Commit: 62cde7a9ef8ebfd0d33bbc14210db338608411c1
Author: Julian Eisel
Date: Thu Jun 27 19:12:54 2019 +0200
Branches: soc-2019-openxr
https://developer.blender.org/rB62cde7a9ef8ebfd0d33bbc14210db338608411c1
Finish VR view drawing callback set up
* Allow passing custom data to session draw function, passed to the
callback
* Actually call the callback
* Create and bind a WM level callback. Will later be used to draw the
viewport.
Also, check if session is actually visible before drawing.
===================================================================
M intern/ghost/GHOST_C-api.h
M intern/ghost/intern/GHOST_XRSession.cpp
M source/blender/windowmanager/intern/wm_draw.c
M source/blender/windowmanager/intern/wm_operators.c
M source/blender/windowmanager/intern/wm_xr.c
M source/blender/windowmanager/wm.h
===================================================================
diff --git a/intern/ghost/GHOST_C-api.h b/intern/ghost/GHOST_C-api.h
index 40a711b207d..a7fcb46211c 100644
--- a/intern/ghost/GHOST_C-api.h
+++ b/intern/ghost/GHOST_C-api.h
@@ -1002,7 +1002,7 @@ 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);
-typedef void (*GHOST_XrDrawViewFn)(const GHOST_XrDrawViewInfo draw_view, void *customdata);
+typedef void (*GHOST_XrDrawViewFn)(const GHOST_XrDrawViewInfo *draw_view, void *customdata);
void GHOST_XrGraphicsContextBindFuncs(struct GHOST_XrContext *xr_context,
GHOST_XrGraphicsContextBindFn bind_fn,
@@ -1015,7 +1015,7 @@ 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 GHOST_XrSessionDrawViews(struct GHOST_XrContext *xr_context, void *customdata);
/* events */
GHOST_TSuccess GHOST_XrEventsHandle(struct GHOST_XrContext *xr_context);
diff --git a/intern/ghost/intern/GHOST_XRSession.cpp b/intern/ghost/intern/GHOST_XRSession.cpp
index 84193b2f13f..be7a7849929 100644
--- a/intern/ghost/intern/GHOST_XRSession.cpp
+++ b/intern/ghost/intern/GHOST_XRSession.cpp
@@ -42,6 +42,19 @@ GHOST_TSuccess GHOST_XrSessionIsRunning(const GHOST_XrContext *xr_context)
return GHOST_kFailure;
}
}
+static GHOST_TSuccess GHOST_XrSessionIsVisible(const GHOST_XrContext *xr_context)
+{
+ if ((xr_context == nullptr) || (xr_context->oxr.session == XR_NULL_HANDLE)) {
+ return GHOST_kFailure;
+ }
+ switch (xr_context->oxr.session_state) {
+ case XR_SESSION_STATE_VISIBLE:
+ case XR_SESSION_STATE_FOCUSED:
+ return GHOST_kSuccess;
+ default:
+ return GHOST_kFailure;
+ }
+}
/**
* A system in OpenXR the combination of some sort of HMD plus controllers and whatever other
@@ -231,12 +244,14 @@ static void draw_view(GHOST_XrContext *xr_context,
OpenXRData *oxr,
XrSwapchain swapchain,
XrCompositionLayerProjectionView &proj_layer_view,
- XrView &view)
+ XrView &view,
+ void *draw_customdata)
{
XrSwapchainImageAcquireInfo acquire_info{XR_TYPE_SWAPCHAIN_IMAGE_ACQUIRE_INFO};
XrSwapchainImageWaitInfo wait_info{XR_TYPE_SWAPCHAIN_IMAGE_WAIT_INFO};
XrSwapchainImageReleaseInfo release_info{XR_TYPE_SWAPCHAIN_IMAGE_RELEASE_INFO};
XrSwapchainImageBaseHeader *swapchain_image;
+ GHOST_XrDrawViewInfo draw_view_info{};
uint32_t swapchain_idx;
xrAcquireSwapchainImage(swapchain, &acquire_info, &swapchain_idx);
@@ -254,7 +269,7 @@ static void draw_view(GHOST_XrContext *xr_context,
swapchain_image = oxr->swapchain_images[swapchain][swapchain_idx];
xr_context->gpu_binding->drawViewBegin(swapchain_image);
- // xr_context->draw_view_fn();
+ xr_context->draw_view_fn(&draw_view_info, draw_customdata);
xr_context->gpu_binding->drawViewEnd(swapchain_image);
xrReleaseSwapchainImage(swapchain, &release_info);
@@ -264,7 +279,8 @@ static XrCompositionLayerProjection draw_layer(
GHOST_XrContext *xr_context,
OpenXRData *oxr,
XrSpace space,
- std::vector<XrCompositionLayerProjectionView> &proj_layer_views)
+ std::vector<XrCompositionLayerProjectionView> &proj_layer_views,
+ void *draw_customdata)
{
XrViewLocateInfo viewloc_info{XR_TYPE_VIEW_LOCATE_INFO};
XrViewState view_state{XR_TYPE_VIEW_STATE};
@@ -285,7 +301,8 @@ static XrCompositionLayerProjection draw_layer(
oxr,
oxr->swapchains[view_idx],
proj_layer_views[view_idx],
- oxr->views[view_idx]);
+ oxr->views[view_idx],
+ draw_customdata);
}
layer.space = space;
@@ -295,7 +312,7 @@ static XrCompositionLayerProjection draw_layer(
return layer;
}
-void GHOST_XrSessionDrawViews(GHOST_XrContext *xr_context)
+void GHOST_XrSessionDrawViews(GHOST_XrContext *xr_context, void *draw_customdata)
{
OpenXRData *oxr = &xr_context->oxr;
XrReferenceSpaceCreateInfo refspace_info{XR_TYPE_REFERENCE_SPACE_CREATE_INFO};
@@ -313,8 +330,10 @@ void GHOST_XrSessionDrawViews(GHOST_XrContext *xr_context)
refspace_info.poseInReferenceSpace.orientation = {0.0f, 0.0f, 0.0f, 1.0f};
xrCreateReferenceSpace(oxr->session, &refspace_info, &space);
- proj_layer = draw_layer(xr_context, oxr, space, projection_layer_views);
- layers.push_back(reinterpret_cast<XrCompositionLayerBaseHeader *>(&proj_layer));
+ if (GHOST_XrSessionIsVisible(xr_context)) {
+ proj_layer = draw_layer(xr_context, oxr, space, projection_layer_views, draw_customdata);
+ layers.push_back(reinterpret_cast<XrCompositionLayerBaseHeader *>(&proj_layer));
+ }
drawing_end(xr_context, &layers);
}
diff --git a/source/blender/windowmanager/intern/wm_draw.c b/source/blender/windowmanager/intern/wm_draw.c
index 03bd08495f0..401ef25af53 100644
--- a/source/blender/windowmanager/intern/wm_draw.c
+++ b/source/blender/windowmanager/intern/wm_draw.c
@@ -870,11 +870,11 @@ static void wm_draw_window(bContext *C, wmWindow *win)
* For now keeping it simple by handling all possible cases here directly (only VR view drawing
* currently). Could generalize this by something like a wmSurface type.
*/
-static void wm_draw_non_window_surfaces(wmWindowManager *wm)
+static void wm_draw_non_window_surfaces(bContext *C, wmWindowManager *wm)
{
#ifdef WITH_OPENXR
if (wm->xr_context) {
- wm_xr_session_draw(wm->xr_context);
+ wm_xr_session_draw(C, wm->xr_context);
}
#else
UNUSED_VARS(wm);
@@ -993,7 +993,7 @@ void wm_draw_update(bContext *C)
}
}
- wm_draw_non_window_surfaces(wm);
+ wm_draw_non_window_surfaces(C, wm);
}
void wm_draw_region_clear(wmWindow *win, ARegion *UNUSED(ar))
diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c
index 33b78b04486..329b716a0ff 100644
--- a/source/blender/windowmanager/intern/wm_operators.c
+++ b/source/blender/windowmanager/intern/wm_operators.c
@@ -3638,6 +3638,13 @@ static void xr_session_window_create(bContext *C)
}
# endif /* WIN32 */
+static void wm_xr_draw_view_fn(const GHOST_XrDrawViewInfo *UNUSED(draw_view), void *customdata)
+{
+ bContext *C = customdata;
+
+ (void)C;
+}
+
static bool wm_xr_ensure_context(wmWindowManager *wm)
{
if (wm->xr_context) {
@@ -3676,8 +3683,10 @@ static int wm_xr_session_toggle_exec(bContext *C, wmOperator *UNUSED(op))
# endif
GHOST_XrGraphicsContextBindFuncs(wm->xr_context,
- xr_session_gpu_binding_context_create,
- xr_session_gpu_binding_context_destroy);
+ xr_session_gpu_binding_context_create,
+ xr_session_gpu_binding_context_destroy);
+ GHOST_XrDrawViewFunc(wm->xr_context, wm_xr_draw_view_fn);
+
GHOST_XrSessionStart(wm->xr_context);
GHOST_XrSessionRenderingPrepare(wm->xr_context);
}
diff --git a/source/blender/windowmanager/intern/wm_xr.c b/source/blender/windowmanager/intern/wm_xr.c
index 73f925aa7db..5a07a3b46e6 100644
--- a/source/blender/windowmanager/intern/wm_xr.c
+++ b/source/blender/windowmanager/intern/wm_xr.c
@@ -18,13 +18,15 @@
* \ingroup wm
*/
+#include "BKE_context.h"
+
#include "GHOST_C-api.h"
-void wm_xr_session_draw(struct GHOST_XrContext *xr_context)
+
+void wm_xr_session_draw(bContext *C, struct GHOST_XrContext *xr_context)
{
if (!GHOST_XrSessionIsRunning(xr_context)) {
return;
}
- // TODO session visible?
- GHOST_XrSessionDrawViews(xr_context);
+ GHOST_XrSessionDrawViews(xr_context, C);
}
diff --git a/source/blender/windowmanager/wm.h b/source/blender/windowmanager/wm.h
index 326dc035942..e0ac389ae8a 100644
--- a/source/blender/windowmanager/wm.h
+++ b/source/blender/windowmanager/wm.h
@@ -96,6 +96,6 @@ 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 */
-void wm_xr_session_draw(struct GHOST_XrContext *xr_context);
+void wm_xr_session_draw(bContext *C, struct GHOST_XrContext *xr_context);
#endif /* __WM_H__ */
More information about the Bf-blender-cvs
mailing list