Changeset View
Changeset View
Standalone View
Standalone View
source/blender/windowmanager/xr/intern/wm_xr_draw.c
| Show All 18 Lines | |||||
| * | * | ||||
| * \name Window-Manager XR Drawing | * \name Window-Manager XR Drawing | ||||
| * | * | ||||
| * Implements Blender specific drawing functionality for use with the Ghost-XR API. | * Implements Blender specific drawing functionality for use with the Ghost-XR API. | ||||
| */ | */ | ||||
| #include <string.h> | #include <string.h> | ||||
| #include "BLI_listbase.h" | |||||
| #include "BLI_math.h" | #include "BLI_math.h" | ||||
| #include "ED_view3d_offscreen.h" | #include "ED_view3d_offscreen.h" | ||||
| #include "GHOST_C-api.h" | #include "GHOST_C-api.h" | ||||
| #include "GPU_viewport.h" | #include "GPU_viewport.h" | ||||
| ▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | static void wm_xr_draw_matrices_create(const wmXrDrawData *draw_data, | ||||
| mul_m4_m4m4(r_view_mat, eye_mat, base_mat); | mul_m4_m4m4(r_view_mat, eye_mat, base_mat); | ||||
| } | } | ||||
| static void wm_xr_draw_viewport_buffers_to_active_framebuffer( | static void wm_xr_draw_viewport_buffers_to_active_framebuffer( | ||||
| const wmXrRuntimeData *runtime_data, | const wmXrRuntimeData *runtime_data, | ||||
| const wmXrSurfaceData *surface_data, | const wmXrSurfaceData *surface_data, | ||||
| const GHOST_XrDrawViewInfo *draw_view) | const GHOST_XrDrawViewInfo *draw_view) | ||||
| { | { | ||||
| const wmXrViewportPair *vp = BLI_findlink(&surface_data->viewports, draw_view->view_idx); | |||||
| BLI_assert(vp && vp->viewport); | |||||
| const bool is_upside_down = GHOST_XrSessionNeedsUpsideDownDrawing(runtime_data->context); | const bool is_upside_down = GHOST_XrSessionNeedsUpsideDownDrawing(runtime_data->context); | ||||
| rcti rect = {.xmin = 0, .ymin = 0, .xmax = draw_view->width - 1, .ymax = draw_view->height - 1}; | rcti rect = {.xmin = 0, .ymin = 0, .xmax = draw_view->width - 1, .ymax = draw_view->height - 1}; | ||||
| wmViewport(&rect); | wmViewport(&rect); | ||||
| /* For upside down contexts, draw with inverted y-values. */ | /* For upside down contexts, draw with inverted y-values. */ | ||||
| if (is_upside_down) { | if (is_upside_down) { | ||||
| SWAP(int, rect.ymin, rect.ymax); | SWAP(int, rect.ymin, rect.ymax); | ||||
| } | } | ||||
| GPU_viewport_draw_to_screen_ex( | GPU_viewport_draw_to_screen_ex(vp->viewport, 0, &rect, draw_view->expects_srgb_buffer, true); | ||||
| surface_data->viewport, 0, &rect, draw_view->expects_srgb_buffer, true); | |||||
| } | } | ||||
| /** | /** | ||||
| * \brief Draw a viewport for a single eye. | * \brief Draw a viewport for a single eye. | ||||
| * | * | ||||
| * This is the main viewport drawing function for VR sessions. It's assigned to Ghost-XR as a | * This is the main viewport drawing function for VR sessions. It's assigned to Ghost-XR as a | ||||
| * callback (see GHOST_XrDrawViewFunc()) and executed for each view (read: eye). | * callback (see GHOST_XrDrawViewFunc()) and executed for each view (read: eye). | ||||
| */ | */ | ||||
| Show All 14 Lines | void wm_xr_draw_view(const GHOST_XrDrawViewInfo *draw_view, void *customdata) | ||||
| wm_xr_session_draw_data_update(session_state, settings, draw_view, draw_data); | wm_xr_session_draw_data_update(session_state, settings, draw_view, draw_data); | ||||
| wm_xr_draw_matrices_create(draw_data, draw_view, settings, viewmat, winmat); | wm_xr_draw_matrices_create(draw_data, draw_view, settings, viewmat, winmat); | ||||
| wm_xr_session_state_update(settings, draw_data, draw_view, session_state); | wm_xr_session_state_update(settings, draw_data, draw_view, session_state); | ||||
| if (!wm_xr_session_surface_offscreen_ensure(surface_data, draw_view)) { | if (!wm_xr_session_surface_offscreen_ensure(surface_data, draw_view)) { | ||||
| return; | return; | ||||
| } | } | ||||
| const wmXrViewportPair *vp = BLI_findlink(&surface_data->viewports, draw_view->view_idx); | |||||
| BLI_assert(vp && vp->viewport && vp->offscreen); | |||||
| /* In case a framebuffer is still bound from drawing the last eye. */ | /* In case a framebuffer is still bound from drawing the last eye. */ | ||||
| GPU_framebuffer_restore(); | GPU_framebuffer_restore(); | ||||
| /* Some systems have drawing glitches without this. */ | /* Some systems have drawing glitches without this. */ | ||||
| GPU_clear_depth(1.0f); | GPU_clear_depth(1.0f); | ||||
| /* Draws the view into the surface_data->viewport's frame-buffers. */ | /* Draws the view into the surface_data->viewport's frame-buffers. */ | ||||
| ED_view3d_draw_offscreen_simple(draw_data->depsgraph, | ED_view3d_draw_offscreen_simple(draw_data->depsgraph, | ||||
| draw_data->scene, | draw_data->scene, | ||||
| &settings->shading, | &settings->shading, | ||||
| settings->shading.type, | settings->shading.type, | ||||
| draw_view->width, | draw_view->width, | ||||
| draw_view->height, | draw_view->height, | ||||
| display_flags, | display_flags, | ||||
| viewmat, | viewmat, | ||||
| winmat, | winmat, | ||||
| settings->clip_start, | settings->clip_start, | ||||
| settings->clip_end, | settings->clip_end, | ||||
| false, | false, | ||||
| true, | true, | ||||
| NULL, | NULL, | ||||
| false, | false, | ||||
| surface_data->offscreen, | vp->offscreen, | ||||
| surface_data->viewport); | vp->viewport); | ||||
| /* The draw-manager uses both GPUOffscreen and GPUViewport to manage frame and texture buffers. A | /* The draw-manager uses both GPUOffscreen and GPUViewport to manage frame and texture buffers. A | ||||
| * call to GPU_viewport_draw_to_screen() is still needed to get the final result from the | * call to GPU_viewport_draw_to_screen() is still needed to get the final result from the | ||||
| * viewport buffers composited together and potentially color managed for display on screen. | * viewport buffers composited together and potentially color managed for display on screen. | ||||
| * It needs a bound frame-buffer to draw into, for which we simply reuse the GPUOffscreen one. | * It needs a bound frame-buffer to draw into, for which we simply reuse the GPUOffscreen one. | ||||
| * | * | ||||
| * In a next step, Ghost-XR will use the currently bound frame-buffer to retrieve the image | * In a next step, Ghost-XR will use the currently bound frame-buffer to retrieve the image | ||||
| * to be submitted to the OpenXR swap-chain. So do not un-bind the off-screen yet! */ | * to be submitted to the OpenXR swap-chain. So do not un-bind the off-screen yet! */ | ||||
| GPU_offscreen_bind(surface_data->offscreen, false); | GPU_offscreen_bind(vp->offscreen, false); | ||||
| wm_xr_draw_viewport_buffers_to_active_framebuffer(xr_data->runtime, surface_data, draw_view); | wm_xr_draw_viewport_buffers_to_active_framebuffer(xr_data->runtime, surface_data, draw_view); | ||||
| } | } | ||||