diff options
author | Peter Kim <pk15950@gmail.com> | 2021-09-23 05:16:52 +0300 |
---|---|---|
committer | Peter Kim <pk15950@gmail.com> | 2021-09-23 05:16:52 +0300 |
commit | 1ef02d8f4b2a40884170c98cc78bebc28de77259 (patch) | |
tree | 12534339bdf7370ea7044f023496ac0e68a2f177 /source/blender/windowmanager | |
parent | 6d7113c363b99409b30dd6b48b90ad03e50b369d (diff) |
Update with changes from D10948, D12472
Diffstat (limited to 'source/blender/windowmanager')
4 files changed, 76 insertions, 70 deletions
diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c index 4c5df150818..05eaeae5a7c 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -3280,23 +3280,12 @@ static void wm_event_free_and_remove_from_queue_if_valid(wmEvent *event) * \{ */ #ifdef WITH_XR_OPENXR -static int wm_event_handle_xrevent( +static void wm_event_handle_xrevent( bContext *C, wmWindowManager *wm, wmWindow *win, bScreen *screen, wmEvent *event) { - BLI_assert(event->val == KM_PRESS || event->val == KM_RELEASE); - int action = 0; - if (event->val == KM_RELEASE) { - wmXrActionData *actiondata = event->customdata; - if (actiondata->ot->modal || actiondata->ot->modal_3d) { - /* Don't execute modal operators on release. */ - action |= WM_HANDLER_BREAK; - return action; - } - } - - /* Find a valid region for executing XR operators. */ + /* Find a valid region for XR operator execution and modal handling. */ ED_screen_areas_iter (win, screen, area) { CTX_wm_area_set(C, area); if (!CTX_wm_view3d(C)) { @@ -3309,31 +3298,39 @@ static int wm_event_handle_xrevent( } CTX_wm_region_set(C, region); - wmXrActionData *actiondata = event->customdata; - PointerRNA properties = {.type = actiondata->ot->srna, .data = actiondata->op_properties}; + action |= wm_handlers_do(C, event, &win->modalhandlers); - if (actiondata->ot->invoke || actiondata->ot->invoke_3d) { - /* Invoke operator, either executing operator or transferring responsibility to window - * modal handlers. */ - wm_operator_invoke(C, - actiondata->ot, - event, - actiondata->op_properties ? &properties : NULL, - NULL, - false, - false); - } - else { - /* Execute operator. */ - wmOperator *op = wm_operator_create( - wm, actiondata->ot, actiondata->op_properties ? &properties : NULL, NULL); - if ((WM_operator_call(C, op) & OPERATOR_HANDLED) == 0) { - WM_operator_free(op); + if ((action & WM_HANDLER_BREAK) == 0) { + wmXrActionData *actiondata = event->customdata; + if ((actiondata->ot->modal || actiondata->ot->modal_3d) && event->val == KM_RELEASE) { + /* Don't execute modal operators on release. */ + } + else { + PointerRNA properties = {.type = actiondata->ot->srna, + .data = actiondata->op_properties}; + if (actiondata->ot->invoke || actiondata->ot->invoke_3d) { + /* Invoke operator, either executing operator or transferring responsibility to window + * modal handlers. */ + wm_operator_invoke(C, + actiondata->ot, + event, + actiondata->op_properties ? &properties : NULL, + NULL, + false, + false); + } + else { + /* Execute operator. */ + wmOperator *op = wm_operator_create( + wm, actiondata->ot, actiondata->op_properties ? &properties : NULL, NULL); + if ((WM_operator_call(C, op) & OPERATOR_HANDLED) == 0) { + WM_operator_free(op); + } + } } + action |= WM_HANDLER_BREAK; } - action |= WM_HANDLER_BREAK; - CTX_wm_region_set(C, NULL); break; } @@ -3344,8 +3341,6 @@ static int wm_event_handle_xrevent( } CTX_wm_area_set(C, NULL); - - return action; } #endif /* WITH_XR_OPENXR */ @@ -3446,6 +3441,16 @@ void wm_event_do_handlers(bContext *C) CTX_wm_window_set(C, win); +#ifdef WITH_XR_OPENXR + if (event->type == EVT_XR_ACTION) { + wm_event_handle_xrevent(C, wm, win, screen, event); + BLI_remlink(&win->event_queue, event); + wm_event_free(event); + /* Skip mouse event handling below, which is unnecessary for XR events. */ + continue; + } +#endif + /* Clear tool-tip on mouse move. */ if (screen->tool_tip && screen->tool_tip->exit_on_event) { if (ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE)) { @@ -3503,17 +3508,6 @@ void wm_event_do_handlers(bContext *C) win->addmousemove = true; } #endif -#ifdef WITH_XR_OPENXR - else if (event->type == EVT_XR_ACTION) { - action |= wm_event_handle_xrevent(C, wm, win, screen, event); - if (action & WM_HANDLER_BREAK) { - BLI_remlink(&win->event_queue, event); - wm_event_free(event); - } - /* Skip mouse event handling below, which is unnecessary for XR events. */ - continue; - } -#endif ED_screen_areas_iter (win, screen, area) { /* After restoring a screen from SCREENMAXIMIZED we have to wait diff --git a/source/blender/windowmanager/xr/intern/wm_xr_draw.c b/source/blender/windowmanager/xr/intern/wm_xr_draw.c index 0f0806754e8..bbbf7a16c9f 100644 --- a/source/blender/windowmanager/xr/intern/wm_xr_draw.c +++ b/source/blender/windowmanager/xr/intern/wm_xr_draw.c @@ -331,7 +331,8 @@ void wm_xr_draw_controllers(const bContext *UNUSED(C), ARegion *UNUSED(region), GPUVertFormat *format = immVertexFormat(); uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT); - uint col = GPU_vertformat_attr_add(format, "color", GPU_COMP_F32, 4, GPU_FETCH_FLOAT); + uint col = GPU_vertformat_attr_add( + format, "color", GPU_COMP_U8, 4, GPU_FETCH_INT_TO_FLOAT_UNIT); immBindBuiltinProgram(GPU_SHADER_3D_POLYLINE_FLAT_COLOR); float viewport[4]; @@ -341,7 +342,7 @@ void wm_xr_draw_controllers(const bContext *UNUSED(C), ARegion *UNUSED(region), immUniform1f("lineWidth", 3.0f * U.pixelsize); if (draw_ray) { - const float color[4] = {0.35f, 0.35f, 1.0f, 0.5f}; + const uchar color[4] = {89, 89, 255, 127}; const float scale = settings->clip_end; float ray[3]; @@ -349,22 +350,23 @@ void wm_xr_draw_controllers(const bContext *UNUSED(C), ARegion *UNUSED(region), GPU_blend(GPU_BLEND_ALPHA); immBegin(GPU_PRIM_LINES, (uint)BLI_listbase_count(&state->controllers) * 2); - immAttr4fv(col, color); LISTBASE_FOREACH (wmXrController *, controller, &state->controllers) { const float(*mat)[4] = controller->aim_mat; madd_v3_v3v3fl(ray, mat[3], mat[2], -scale); + immAttrSkip(col); immVertex3fv(pos, mat[3]); + immAttr4ubv(col, color); immVertex3fv(pos, ray); } immEnd(); } else { - const float r[4] = {1.0f, 0.2f, 0.322f, 1.0f}; - const float g[4] = {0.545f, 0.863f, 0.0f, 1.0f}; - const float b[4] = {0.157f, 0.565f, 1.0f, 1.0f}; + const uchar r[4] = {255, 51, 82, 255}; + const uchar g[4] = {139, 220, 0, 255}; + const uchar b[4] = {40, 144, 255, 255}; const float scale = 0.01f; float x_axis[3], y_axis[3], z_axis[3]; @@ -379,16 +381,19 @@ void wm_xr_draw_controllers(const bContext *UNUSED(C), ARegion *UNUSED(region), madd_v3_v3v3fl(y_axis, mat[3], mat[1], scale); madd_v3_v3v3fl(z_axis, mat[3], mat[2], scale); - immAttr4fv(col, r); + immAttrSkip(col); immVertex3fv(pos, mat[3]); + immAttr4ubv(col, r); immVertex3fv(pos, x_axis); - immAttr4fv(col, g); + immAttrSkip(col); immVertex3fv(pos, mat[3]); + immAttr4ubv(col, g); immVertex3fv(pos, y_axis); - immAttr4fv(col, b); + immAttrSkip(col); immVertex3fv(pos, mat[3]); + immAttr4ubv(col, b); immVertex3fv(pos, z_axis); } diff --git a/source/blender/windowmanager/xr/intern/wm_xr_operators.c b/source/blender/windowmanager/xr/intern/wm_xr_operators.c index 7efd70115c2..4f7499f3aa0 100644 --- a/source/blender/windowmanager/xr/intern/wm_xr_operators.c +++ b/source/blender/windowmanager/xr/intern/wm_xr_operators.c @@ -605,10 +605,11 @@ static void wm_xr_raycast_draw(const bContext *UNUSED(C), GPUVertFormat *format = immVertexFormat(); uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT); - immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR); - immUniformColor4fv(data->color); if (data->from_viewer) { + immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR); + immUniformColor4fv(data->color); + GPU_depth_test(GPU_DEPTH_NONE); GPU_point_size(7.0f); @@ -617,11 +618,21 @@ static void wm_xr_raycast_draw(const bContext *UNUSED(C), immEnd(); } else { + uint col = GPU_vertformat_attr_add(format, "color", GPU_COMP_F32, 4, GPU_FETCH_FLOAT); + immBindBuiltinProgram(GPU_SHADER_3D_POLYLINE_FLAT_COLOR); + + float viewport[4]; + GPU_viewport_size_get_f(viewport); + immUniform2fv("viewportSize", &viewport[2]); + + immUniform1f("lineWidth", 3.0f * U.pixelsize); + GPU_depth_test(GPU_DEPTH_LESS_EQUAL); - GPU_line_width(3.0f); immBegin(GPU_PRIM_LINES, 2); + immAttrSkip(col); immVertex3fv(pos, data->origin); + immAttr4fv(col, data->color); immVertex3fv(pos, data->end); immEnd(); } diff --git a/source/blender/windowmanager/xr/intern/wm_xr_session.c b/source/blender/windowmanager/xr/intern/wm_xr_session.c index c30decf5c97..845c0fa20b4 100644 --- a/source/blender/windowmanager/xr/intern/wm_xr_session.c +++ b/source/blender/windowmanager/xr/intern/wm_xr_session.c @@ -151,6 +151,7 @@ void wm_xr_session_toggle(wmWindowManager *wm, if (WM_xr_session_exists(xr_data)) { GHOST_XrSessionEnd(xr_data->runtime->context); + xr_data->runtime->session_state.is_started = false; } else { GHOST_XrSessionBeginInfo begin_info; @@ -1353,11 +1354,9 @@ void wm_xr_session_controller_data_populate(const wmXrAction *grip_action, /* Activate draw callback. */ if (g_xr_surface) { wmXrSurfaceData *surface_data = g_xr_surface->customdata; - if (surface_data && !surface_data->controller_draw_handle) { - if (surface_data->controller_art) { - surface_data->controller_draw_handle = ED_region_draw_cb_activate( - surface_data->controller_art, wm_xr_draw_controllers, xr, REGION_DRAW_POST_VIEW); - } + if (surface_data->controller_art && !surface_data->controller_draw_handle) { + surface_data->controller_draw_handle = ED_region_draw_cb_activate( + surface_data->controller_art, wm_xr_draw_controllers, xr, REGION_DRAW_POST_VIEW); } } } @@ -1369,10 +1368,8 @@ void wm_xr_session_controller_data_clear(wmXrSessionState *state) /* Deactivate draw callback. */ if (g_xr_surface) { wmXrSurfaceData *surface_data = g_xr_surface->customdata; - if (surface_data && surface_data->controller_draw_handle) { - if (surface_data->controller_art) { - ED_region_draw_cb_exit(surface_data->controller_art, surface_data->controller_draw_handle); - } + if (surface_data->controller_art && surface_data->controller_draw_handle) { + ED_region_draw_cb_exit(surface_data->controller_art, surface_data->controller_draw_handle); surface_data->controller_draw_handle = NULL; } } @@ -1401,7 +1398,7 @@ static void wm_xr_session_surface_draw(bContext *C) Main *bmain = CTX_data_main(C); wmXrDrawData draw_data; - if (!GHOST_XrSessionIsRunning(wm->xr.runtime->context)) { + if (!WM_xr_session_is_ready(&wm->xr)) { return; } @@ -1570,7 +1567,6 @@ ARegionType *WM_xr_surface_controller_region_type_get(void) wmXrSurfaceData *data = g_xr_surface->customdata; return data->controller_art; } - return NULL; } |