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:
authorPeter Kim <pk15950@gmail.com>2021-10-12 10:18:05 +0300
committerPeter Kim <pk15950@gmail.com>2021-10-12 10:18:05 +0300
commit9dda65455b54336fe3efef91eba9e41866dac1c1 (patch)
tree2f8fd6edf8d190e018b63c6b6bdacb38ab7905bd /source/blender/draw
parentcfa59b3fabe729e49a57154ce21c5a4b88aa5812 (diff)
XR Controller Support Step 4: Controller Drawing
Addresses T77127 (Controller Drawing). Adds VR controller visualization and custom drawing via draw handlers. Add-ons can draw to the XR surface (headset display) and mirror window by adding a View3D draw handler of region type 'XR' and draw type 'POST_VIEW'. Controller drawing and custom overlays can be toggled individually as XR session options, which will be added in a future update to the VR Scene Inspection add-on. For the actual drawing, the OpenXR XR_MSFT_controller_model extension is used to load a glTF model provided by the XR runtime. The model's vertex data is then used to create a GPUBatch in the XR session state. Finally, this batch is drawn via the XR surface draw handler mentioned above. For runtimes that do not support the controller model extension, a a simple fallback shape (sphere) is drawn instead. Reviewed By: Severin, fclem Differential Revision: https://developer.blender.org/D10948
Diffstat (limited to 'source/blender/draw')
-rw-r--r--source/blender/draw/intern/draw_manager.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c
index b8de92dea7f..c8900d64935 100644
--- a/source/blender/draw/intern/draw_manager.c
+++ b/source/blender/draw/intern/draw_manager.c
@@ -51,6 +51,7 @@
#include "BKE_pbvh.h"
#include "BKE_pointcache.h"
#include "BKE_pointcloud.h"
+#include "BKE_screen.h"
#include "BKE_volume.h"
#include "DNA_camera_types.h"
@@ -1418,6 +1419,27 @@ void DRW_draw_callbacks_post_scene(void)
ED_region_draw_cb_draw(DST.draw_ctx.evil_C, DST.draw_ctx.region, REGION_DRAW_POST_VIEW);
+#ifdef WITH_XR_OPENXR
+ /* XR callbacks (controllers, custom draw functions) for session mirror. */
+ if ((v3d->flag & V3D_XR_SESSION_MIRROR) != 0) {
+ if ((v3d->flag2 & V3D_XR_SHOW_CONTROLLERS) != 0) {
+ ARegionType *art = WM_xr_surface_controller_region_type_get();
+ if (art) {
+ ED_region_surface_draw_cb_draw(art, REGION_DRAW_POST_VIEW);
+ }
+ }
+ if ((v3d->flag2 & V3D_XR_SHOW_CUSTOM_OVERLAYS) != 0) {
+ SpaceType *st = BKE_spacetype_from_id(SPACE_VIEW3D);
+ if (st) {
+ ARegionType *art = BKE_regiontype_from_id(st, RGN_TYPE_XR);
+ if (art) {
+ ED_region_surface_draw_cb_draw(art, REGION_DRAW_POST_VIEW);
+ }
+ }
+ }
+ }
+#endif
+
/* Callback can be nasty and do whatever they want with the state.
* Don't trust them! */
DRW_state_reset();
@@ -1464,6 +1486,46 @@ void DRW_draw_callbacks_post_scene(void)
ED_annotation_draw_view3d(DEG_get_input_scene(depsgraph), depsgraph, v3d, region, true);
GPU_depth_test(GPU_DEPTH_LESS_EQUAL);
}
+
+#ifdef WITH_XR_OPENXR
+ if ((v3d->flag & V3D_XR_SESSION_SURFACE) != 0) {
+ DefaultFramebufferList *dfbl = DRW_viewport_framebuffer_list_get();
+
+ DRW_state_reset();
+
+ GPU_framebuffer_bind(dfbl->overlay_fb);
+
+ GPU_matrix_projection_set(rv3d->winmat);
+ GPU_matrix_set(rv3d->viewmat);
+
+ /* XR callbacks (controllers, custom draw functions) for session surface. */
+ if (((v3d->flag2 & V3D_XR_SHOW_CONTROLLERS) != 0) ||
+ ((v3d->flag2 & V3D_XR_SHOW_CUSTOM_OVERLAYS) != 0)) {
+ GPU_depth_test(GPU_DEPTH_NONE);
+ GPU_apply_state();
+
+ if ((v3d->flag2 & V3D_XR_SHOW_CONTROLLERS) != 0) {
+ ARegionType *art = WM_xr_surface_controller_region_type_get();
+ if (art) {
+ ED_region_surface_draw_cb_draw(art, REGION_DRAW_POST_VIEW);
+ }
+ }
+ if ((v3d->flag2 & V3D_XR_SHOW_CUSTOM_OVERLAYS) != 0) {
+ SpaceType *st = BKE_spacetype_from_id(SPACE_VIEW3D);
+ if (st) {
+ ARegionType *art = BKE_regiontype_from_id(st, RGN_TYPE_XR);
+ if (art) {
+ ED_region_surface_draw_cb_draw(art, REGION_DRAW_POST_VIEW);
+ }
+ }
+ }
+
+ DRW_state_reset();
+ }
+
+ GPU_depth_test(GPU_DEPTH_LESS_EQUAL);
+ }
+#endif
}
}