Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_view3d/view3d_draw.cc
- This file was moved from source/blender/editors/space_view3d/view3d_draw.c.
| /* SPDX-License-Identifier: GPL-2.0-or-later | /* SPDX-License-Identifier: GPL-2.0-or-later | ||||
| * Copyright 2008 Blender Foundation. All rights reserved. */ | * Copyright 2008 Blender Foundation. All rights reserved. */ | ||||
| /** \file | /** \file | ||||
| * \ingroup spview3d | * \ingroup spview3d | ||||
| */ | */ | ||||
| #include <math.h> | #include <math.h> | ||||
| #include "BLI_jitter_2d.h" | #include "BLI_jitter_2d.h" | ||||
| #include "BLI_listbase.h" | #include "BLI_listbase.h" | ||||
| #include "BLI_math.h" | #include "BLI_math.h" | ||||
| #include "BLI_math_vector.hh" | |||||
| #include "BLI_rect.h" | #include "BLI_rect.h" | ||||
| #include "BLI_string.h" | #include "BLI_string.h" | ||||
| #include "BLI_string_utils.h" | #include "BLI_string_utils.h" | ||||
| #include "BLI_threads.h" | #include "BLI_threads.h" | ||||
| #include "BKE_armature.h" | #include "BKE_armature.h" | ||||
| #include "BKE_camera.h" | #include "BKE_camera.h" | ||||
| #include "BKE_collection.h" | #include "BKE_collection.h" | ||||
| Show All 28 Lines | |||||
| #include "ED_gpencil.h" | #include "ED_gpencil.h" | ||||
| #include "ED_info.h" | #include "ED_info.h" | ||||
| #include "ED_keyframing.h" | #include "ED_keyframing.h" | ||||
| #include "ED_screen.h" | #include "ED_screen.h" | ||||
| #include "ED_screen_types.h" | #include "ED_screen_types.h" | ||||
| #include "ED_transform.h" | #include "ED_transform.h" | ||||
| #include "ED_view3d_offscreen.h" | #include "ED_view3d_offscreen.h" | ||||
| #include "ED_viewer_path.hh" | |||||
| #include "DEG_depsgraph_query.h" | #include "DEG_depsgraph_query.h" | ||||
| #include "GPU_batch.h" | #include "GPU_batch.h" | ||||
| #include "GPU_batch_presets.h" | #include "GPU_batch_presets.h" | ||||
| #include "GPU_framebuffer.h" | #include "GPU_framebuffer.h" | ||||
| #include "GPU_immediate.h" | #include "GPU_immediate.h" | ||||
| #include "GPU_immediate_util.h" | #include "GPU_immediate_util.h" | ||||
| Show All 14 Lines | |||||
| #include "RNA_access.h" | #include "RNA_access.h" | ||||
| #include "IMB_imbuf.h" | #include "IMB_imbuf.h" | ||||
| #include "IMB_imbuf_types.h" | #include "IMB_imbuf_types.h" | ||||
| #include "view3d_intern.h" /* own include */ | #include "view3d_intern.h" /* own include */ | ||||
| using blender::float4; | |||||
| #define M_GOLDEN_RATIO_CONJUGATE 0.618033988749895f | #define M_GOLDEN_RATIO_CONJUGATE 0.618033988749895f | ||||
| #define VIEW3D_OVERLAY_LINEHEIGHT (0.9f * U.widget_unit) | #define VIEW3D_OVERLAY_LINEHEIGHT (0.9f * U.widget_unit) | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name General Functions | /** \name General Functions | ||||
| * \{ */ | * \{ */ | ||||
| void ED_view3d_update_viewmat(Depsgraph *depsgraph, | void ED_view3d_update_viewmat(Depsgraph *depsgraph, | ||||
| const Scene *scene, | const Scene *scene, | ||||
| View3D *v3d, | View3D *v3d, | ||||
| ARegion *region, | ARegion *region, | ||||
| const float viewmat[4][4], | const float viewmat[4][4], | ||||
| const float winmat[4][4], | const float winmat[4][4], | ||||
| const rcti *rect, | const rcti *rect, | ||||
| bool offscreen) | bool offscreen) | ||||
| { | { | ||||
| RegionView3D *rv3d = region->regiondata; | RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata); | ||||
| /* setup window matrices */ | /* setup window matrices */ | ||||
| if (winmat) { | if (winmat) { | ||||
| copy_m4_m4(rv3d->winmat, winmat); | copy_m4_m4(rv3d->winmat, winmat); | ||||
| } | } | ||||
| else { | else { | ||||
| view3d_winmatrix_set(depsgraph, region, v3d, rect); | view3d_winmatrix_set(depsgraph, region, v3d, rect); | ||||
| } | } | ||||
| /* setup view matrix */ | /* setup view matrix */ | ||||
| if (viewmat) { | if (viewmat) { | ||||
| copy_m4_m4(rv3d->viewmat, viewmat); | copy_m4_m4(rv3d->viewmat, viewmat); | ||||
| } | } | ||||
| else { | else { | ||||
| float rect_scale[2]; | float rect_scale[2]; | ||||
| if (rect) { | if (rect) { | ||||
| rect_scale[0] = (float)BLI_rcti_size_x(rect) / (float)region->winx; | rect_scale[0] = float(BLI_rcti_size_x(rect)) / float(region->winx); | ||||
| rect_scale[1] = (float)BLI_rcti_size_y(rect) / (float)region->winy; | rect_scale[1] = float(BLI_rcti_size_y(rect)) / float(region->winy); | ||||
| } | } | ||||
| /* NOTE: calls BKE_object_where_is_calc for camera... */ | /* NOTE: calls BKE_object_where_is_calc for camera... */ | ||||
| view3d_viewmatrix_set(depsgraph, scene, v3d, rv3d, rect ? rect_scale : NULL); | view3d_viewmatrix_set(depsgraph, scene, v3d, rv3d, rect ? rect_scale : nullptr); | ||||
| } | } | ||||
| /* update utility matrices */ | /* update utility matrices */ | ||||
| mul_m4_m4m4(rv3d->persmat, rv3d->winmat, rv3d->viewmat); | mul_m4_m4m4(rv3d->persmat, rv3d->winmat, rv3d->viewmat); | ||||
| invert_m4_m4(rv3d->persinv, rv3d->persmat); | invert_m4_m4(rv3d->persinv, rv3d->persmat); | ||||
| invert_m4_m4(rv3d->viewinv, rv3d->viewmat); | invert_m4_m4(rv3d->viewinv, rv3d->viewmat); | ||||
| /* calculate GLSL view dependent values */ | /* calculate GLSL view dependent values */ | ||||
| /* store window coordinates scaling/offset */ | /* store window coordinates scaling/offset */ | ||||
| if (!offscreen && rv3d->persp == RV3D_CAMOB && v3d->camera) { | if (!offscreen && rv3d->persp == RV3D_CAMOB && v3d->camera) { | ||||
| rctf cameraborder; | rctf cameraborder; | ||||
| ED_view3d_calc_camera_border(scene, depsgraph, region, v3d, rv3d, &cameraborder, false); | ED_view3d_calc_camera_border(scene, depsgraph, region, v3d, rv3d, &cameraborder, false); | ||||
| rv3d->viewcamtexcofac[0] = (float)region->winx / BLI_rctf_size_x(&cameraborder); | rv3d->viewcamtexcofac[0] = float(region->winx) / BLI_rctf_size_x(&cameraborder); | ||||
| rv3d->viewcamtexcofac[1] = (float)region->winy / BLI_rctf_size_y(&cameraborder); | rv3d->viewcamtexcofac[1] = float(region->winy) / BLI_rctf_size_y(&cameraborder); | ||||
| rv3d->viewcamtexcofac[2] = -rv3d->viewcamtexcofac[0] * cameraborder.xmin / (float)region->winx; | rv3d->viewcamtexcofac[2] = -rv3d->viewcamtexcofac[0] * cameraborder.xmin / float(region->winx); | ||||
| rv3d->viewcamtexcofac[3] = -rv3d->viewcamtexcofac[1] * cameraborder.ymin / (float)region->winy; | rv3d->viewcamtexcofac[3] = -rv3d->viewcamtexcofac[1] * cameraborder.ymin / float(region->winy); | ||||
| } | } | ||||
| else { | else { | ||||
| rv3d->viewcamtexcofac[0] = rv3d->viewcamtexcofac[1] = 1.0f; | rv3d->viewcamtexcofac[0] = rv3d->viewcamtexcofac[1] = 1.0f; | ||||
| rv3d->viewcamtexcofac[2] = rv3d->viewcamtexcofac[3] = 0.0f; | rv3d->viewcamtexcofac[2] = rv3d->viewcamtexcofac[3] = 0.0f; | ||||
| } | } | ||||
| /* Calculate pixel-size factor once, this is used for lights and object-centers. */ | /* Calculate pixel-size factor once, this is used for lights and object-centers. */ | ||||
| { | { | ||||
| /* NOTE: '1.0f / len_v3(v1)' replaced 'len_v3(rv3d->viewmat[0])' | /* NOTE: '1.0f / len_v3(v1)' replaced 'len_v3(rv3d->viewmat[0])' | ||||
| * because of float point precision problems at large values T23908. */ | * because of float point precision problems at large values T23908. */ | ||||
| float v1[3], v2[3]; | float v1[3], v2[3]; | ||||
| float len_px, len_sc; | float len_px, len_sc; | ||||
| v1[0] = rv3d->persmat[0][0]; | v1[0] = rv3d->persmat[0][0]; | ||||
| v1[1] = rv3d->persmat[1][0]; | v1[1] = rv3d->persmat[1][0]; | ||||
| v1[2] = rv3d->persmat[2][0]; | v1[2] = rv3d->persmat[2][0]; | ||||
| v2[0] = rv3d->persmat[0][1]; | v2[0] = rv3d->persmat[0][1]; | ||||
| v2[1] = rv3d->persmat[1][1]; | v2[1] = rv3d->persmat[1][1]; | ||||
| v2[2] = rv3d->persmat[2][1]; | v2[2] = rv3d->persmat[2][1]; | ||||
| len_px = 2.0f / sqrtf(min_ff(len_squared_v3(v1), len_squared_v3(v2))); | len_px = 2.0f / sqrtf(min_ff(len_squared_v3(v1), len_squared_v3(v2))); | ||||
| if (rect) { | if (rect) { | ||||
| len_sc = (float)max_ii(BLI_rcti_size_x(rect), BLI_rcti_size_y(rect)); | len_sc = float(max_ii(BLI_rcti_size_x(rect), BLI_rcti_size_y(rect))); | ||||
| } | } | ||||
| else { | else { | ||||
| len_sc = (float)MAX2(region->winx, region->winy); | len_sc = float(MAX2(region->winx, region->winy)); | ||||
| } | } | ||||
| rv3d->pixsize = len_px / len_sc; | rv3d->pixsize = len_px / len_sc; | ||||
| } | } | ||||
| } | } | ||||
| static void view3d_main_region_setup_view(Depsgraph *depsgraph, | static void view3d_main_region_setup_view(Depsgraph *depsgraph, | ||||
| Scene *scene, | Scene *scene, | ||||
| View3D *v3d, | View3D *v3d, | ||||
| ARegion *region, | ARegion *region, | ||||
| const float viewmat[4][4], | const float viewmat[4][4], | ||||
| const float winmat[4][4], | const float winmat[4][4], | ||||
| const rcti *rect) | const rcti *rect) | ||||
| { | { | ||||
| RegionView3D *rv3d = region->regiondata; | RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata); | ||||
| ED_view3d_update_viewmat(depsgraph, scene, v3d, region, viewmat, winmat, rect, false); | ED_view3d_update_viewmat(depsgraph, scene, v3d, region, viewmat, winmat, rect, false); | ||||
| /* set for opengl */ | /* set for opengl */ | ||||
| GPU_matrix_projection_set(rv3d->winmat); | GPU_matrix_projection_set(rv3d->winmat); | ||||
| GPU_matrix_set(rv3d->viewmat); | GPU_matrix_set(rv3d->viewmat); | ||||
| } | } | ||||
| static void view3d_main_region_setup_offscreen(Depsgraph *depsgraph, | static void view3d_main_region_setup_offscreen(Depsgraph *depsgraph, | ||||
| const Scene *scene, | const Scene *scene, | ||||
| View3D *v3d, | View3D *v3d, | ||||
| ARegion *region, | ARegion *region, | ||||
| const float viewmat[4][4], | const float viewmat[4][4], | ||||
| const float winmat[4][4]) | const float winmat[4][4]) | ||||
| { | { | ||||
| RegionView3D *rv3d = region->regiondata; | RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata); | ||||
| ED_view3d_update_viewmat(depsgraph, scene, v3d, region, viewmat, winmat, NULL, true); | ED_view3d_update_viewmat(depsgraph, scene, v3d, region, viewmat, winmat, nullptr, true); | ||||
| /* set for opengl */ | /* set for opengl */ | ||||
| GPU_matrix_projection_set(rv3d->winmat); | GPU_matrix_projection_set(rv3d->winmat); | ||||
| GPU_matrix_set(rv3d->viewmat); | GPU_matrix_set(rv3d->viewmat); | ||||
| } | } | ||||
| static bool view3d_stereo3d_active(wmWindow *win, | static bool view3d_stereo3d_active(wmWindow *win, | ||||
| const Scene *scene, | const Scene *scene, | ||||
| View3D *v3d, | View3D *v3d, | ||||
| RegionView3D *rv3d) | RegionView3D *rv3d) | ||||
| { | { | ||||
| if ((scene->r.scemode & R_MULTIVIEW) == 0) { | if ((scene->r.scemode & R_MULTIVIEW) == 0) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| if ((v3d->camera == NULL) || (v3d->camera->type != OB_CAMERA) || rv3d->persp != RV3D_CAMOB) { | if ((v3d->camera == nullptr) || (v3d->camera->type != OB_CAMERA) || rv3d->persp != RV3D_CAMOB) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| switch (v3d->stereo3d_camera) { | switch (v3d->stereo3d_camera) { | ||||
| case STEREO_MONO_ID: | case STEREO_MONO_ID: | ||||
| return false; | return false; | ||||
| break; | break; | ||||
| case STEREO_3D_ID: | case STEREO_3D_ID: | ||||
| /* win will be NULL when calling this from the selection or draw loop. */ | /* win will be nullptr when calling this from the selection or draw loop. */ | ||||
| if ((win == NULL) || (WM_stereo3d_enabled(win, true) == false)) { | if ((win == nullptr) || (WM_stereo3d_enabled(win, true) == false)) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| if (((scene->r.views_format & SCE_VIEWS_FORMAT_MULTIVIEW) != 0) && | if (((scene->r.views_format & SCE_VIEWS_FORMAT_MULTIVIEW) != 0) && | ||||
| !BKE_scene_multiview_is_stereo3d(&scene->r)) { | !BKE_scene_multiview_is_stereo3d(&scene->r)) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| break; | break; | ||||
| /* We always need the stereo calculation for left and right cameras. */ | /* We always need the stereo calculation for left and right cameras. */ | ||||
| Show All 38 Lines | if (scene->r.views_format == SCE_VIEWS_FORMAT_STEREO_3D) { | ||||
| data_eval = (Camera *)DEG_get_evaluated_id(depsgraph, &data->id); | data_eval = (Camera *)DEG_get_evaluated_id(depsgraph, &data->id); | ||||
| shiftx = data_eval->shiftx; | shiftx = data_eval->shiftx; | ||||
| BLI_thread_lock(LOCK_VIEW3D); | BLI_thread_lock(LOCK_VIEW3D); | ||||
| data_eval->shiftx = BKE_camera_multiview_shift_x(&scene->r, v3d->camera, viewname); | data_eval->shiftx = BKE_camera_multiview_shift_x(&scene->r, v3d->camera, viewname); | ||||
| BKE_camera_multiview_view_matrix(&scene->r, v3d->camera, is_left, viewmat); | BKE_camera_multiview_view_matrix(&scene->r, v3d->camera, is_left, viewmat); | ||||
| view3d_main_region_setup_view(depsgraph, scene, v3d, region, viewmat, NULL, rect); | view3d_main_region_setup_view(depsgraph, scene, v3d, region, viewmat, nullptr, rect); | ||||
| data_eval->shiftx = shiftx; | data_eval->shiftx = shiftx; | ||||
| BLI_thread_unlock(LOCK_VIEW3D); | BLI_thread_unlock(LOCK_VIEW3D); | ||||
| } | } | ||||
| else { /* SCE_VIEWS_FORMAT_MULTIVIEW */ | else { /* SCE_VIEWS_FORMAT_MULTIVIEW */ | ||||
| float viewmat[4][4]; | float viewmat[4][4]; | ||||
| Object *view_ob = v3d->camera; | Object *view_ob = v3d->camera; | ||||
| Object *camera = BKE_camera_multiview_render(scene, v3d->camera, viewname); | Object *camera = BKE_camera_multiview_render(scene, v3d->camera, viewname); | ||||
| BLI_thread_lock(LOCK_VIEW3D); | BLI_thread_lock(LOCK_VIEW3D); | ||||
| v3d->camera = camera; | v3d->camera = camera; | ||||
| BKE_camera_multiview_view_matrix(&scene->r, camera, false, viewmat); | BKE_camera_multiview_view_matrix(&scene->r, camera, false, viewmat); | ||||
| view3d_main_region_setup_view(depsgraph, scene, v3d, region, viewmat, NULL, rect); | view3d_main_region_setup_view(depsgraph, scene, v3d, region, viewmat, nullptr, rect); | ||||
| v3d->camera = view_ob; | v3d->camera = view_ob; | ||||
| BLI_thread_unlock(LOCK_VIEW3D); | BLI_thread_unlock(LOCK_VIEW3D); | ||||
| } | } | ||||
| } | } | ||||
| #ifdef WITH_XR_OPENXR | #ifdef WITH_XR_OPENXR | ||||
| static void view3d_xr_mirror_setup(const wmWindowManager *wm, | static void view3d_xr_mirror_setup(const wmWindowManager *wm, | ||||
| Depsgraph *depsgraph, | Depsgraph *depsgraph, | ||||
| Scene *scene, | Scene *scene, | ||||
| View3D *v3d, | View3D *v3d, | ||||
| ARegion *region, | ARegion *region, | ||||
| const rcti *rect) | const rcti *rect) | ||||
| { | { | ||||
| RegionView3D *rv3d = region->regiondata; | RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata); | ||||
| float viewmat[4][4]; | float viewmat[4][4]; | ||||
| const float lens_old = v3d->lens; | const float lens_old = v3d->lens; | ||||
| if (!WM_xr_session_state_viewer_pose_matrix_info_get(&wm->xr, viewmat, &v3d->lens)) { | if (!WM_xr_session_state_viewer_pose_matrix_info_get(&wm->xr, viewmat, &v3d->lens)) { | ||||
| /* Can't get info from XR session, use fallback values. */ | /* Can't get info from XR session, use fallback values. */ | ||||
| copy_m4_m4(viewmat, rv3d->viewmat); | copy_m4_m4(viewmat, rv3d->viewmat); | ||||
| v3d->lens = lens_old; | v3d->lens = lens_old; | ||||
| } | } | ||||
| view3d_main_region_setup_view(depsgraph, scene, v3d, region, viewmat, NULL, rect); | view3d_main_region_setup_view(depsgraph, scene, v3d, region, viewmat, nullptr, rect); | ||||
| /* Set draw flags. */ | /* Set draw flags. */ | ||||
| SET_FLAG_FROM_TEST(v3d->flag2, | SET_FLAG_FROM_TEST(v3d->flag2, | ||||
| (wm->xr.session_settings.draw_flags & V3D_OFSDRAW_XR_SHOW_CONTROLLERS) != 0, | (wm->xr.session_settings.draw_flags & V3D_OFSDRAW_XR_SHOW_CONTROLLERS) != 0, | ||||
| V3D_XR_SHOW_CONTROLLERS); | V3D_XR_SHOW_CONTROLLERS); | ||||
| SET_FLAG_FROM_TEST(v3d->flag2, | SET_FLAG_FROM_TEST(v3d->flag2, | ||||
| (wm->xr.session_settings.draw_flags & V3D_OFSDRAW_XR_SHOW_CUSTOM_OVERLAYS) != | (wm->xr.session_settings.draw_flags & V3D_OFSDRAW_XR_SHOW_CUSTOM_OVERLAYS) != | ||||
| 0, | 0, | ||||
| Show All 11 Lines | void ED_view3d_draw_setup_view(const wmWindowManager *wm, | ||||
| Depsgraph *depsgraph, | Depsgraph *depsgraph, | ||||
| Scene *scene, | Scene *scene, | ||||
| ARegion *region, | ARegion *region, | ||||
| View3D *v3d, | View3D *v3d, | ||||
| const float viewmat[4][4], | const float viewmat[4][4], | ||||
| const float winmat[4][4], | const float winmat[4][4], | ||||
| const rcti *rect) | const rcti *rect) | ||||
| { | { | ||||
| RegionView3D *rv3d = region->regiondata; | RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata); | ||||
| #ifdef WITH_XR_OPENXR | #ifdef WITH_XR_OPENXR | ||||
| /* Setup the view matrix. */ | /* Setup the view matrix. */ | ||||
| if (ED_view3d_is_region_xr_mirror_active(wm, v3d, region)) { | if (ED_view3d_is_region_xr_mirror_active(wm, v3d, region)) { | ||||
| view3d_xr_mirror_setup(wm, depsgraph, scene, v3d, region, rect); | view3d_xr_mirror_setup(wm, depsgraph, scene, v3d, region, rect); | ||||
| } | } | ||||
| else | else | ||||
| #endif | #endif | ||||
| ▲ Show 20 Lines • Show All 168 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| static void drawviewborder(Scene *scene, Depsgraph *depsgraph, ARegion *region, View3D *v3d) | static void drawviewborder(Scene *scene, Depsgraph *depsgraph, ARegion *region, View3D *v3d) | ||||
| { | { | ||||
| float x1, x2, y1, y2; | float x1, x2, y1, y2; | ||||
| float x1i, x2i, y1i, y2i; | float x1i, x2i, y1i, y2i; | ||||
| rctf viewborder; | rctf viewborder; | ||||
| Camera *ca = NULL; | Camera *ca = nullptr; | ||||
| RegionView3D *rv3d = region->regiondata; | RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata); | ||||
| if (v3d->camera == NULL) { | if (v3d->camera == nullptr) { | ||||
| return; | return; | ||||
| } | } | ||||
| if (v3d->camera->type == OB_CAMERA) { | if (v3d->camera->type == OB_CAMERA) { | ||||
| ca = v3d->camera->data; | ca = static_cast<Camera *>(v3d->camera->data); | ||||
| } | } | ||||
| ED_view3d_calc_camera_border(scene, depsgraph, region, v3d, rv3d, &viewborder, false); | ED_view3d_calc_camera_border(scene, depsgraph, region, v3d, rv3d, &viewborder, false); | ||||
| /* the offsets */ | /* the offsets */ | ||||
| x1 = viewborder.xmin; | x1 = viewborder.xmin; | ||||
| y1 = viewborder.ymin; | y1 = viewborder.ymin; | ||||
| x2 = viewborder.xmax; | x2 = viewborder.xmax; | ||||
| y2 = viewborder.ymax; | y2 = viewborder.ymax; | ||||
| GPU_line_width(1.0f); | GPU_line_width(1.0f); | ||||
| /* apply offsets so the real 3D camera shows through */ | /* apply offsets so the real 3D camera shows through */ | ||||
| /* NOTE: quite un-scientific but without this bit extra | /* NOTE: quite un-scientific but without this bit extra | ||||
| * 0.0001 on the lower left the 2D border sometimes | * 0.0001 on the lower left the 2D border sometimes | ||||
| * obscures the 3D camera border */ | * obscures the 3D camera border */ | ||||
| /* NOTE: with VIEW3D_CAMERA_BORDER_HACK defined this error isn't noticeable | /* NOTE: with VIEW3D_CAMERA_BORDER_HACK defined this error isn't noticeable | ||||
| * but keep it here in case we need to remove the workaround */ | * but keep it here in case we need to remove the workaround */ | ||||
| x1i = (int)(x1 - 1.0001f); | x1i = int(x1 - 1.0001f); | ||||
| y1i = (int)(y1 - 1.0001f); | y1i = int(y1 - 1.0001f); | ||||
| x2i = (int)(x2 + (1.0f - 0.0001f)); | x2i = int(x2 + (1.0f - 0.0001f)); | ||||
| y2i = (int)(y2 + (1.0f - 0.0001f)); | y2i = int(y2 + (1.0f - 0.0001f)); | ||||
| uint shdr_pos = GPU_vertformat_attr_add( | uint shdr_pos = GPU_vertformat_attr_add( | ||||
| immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); | immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); | ||||
| /* First, solid lines. */ | /* First, solid lines. */ | ||||
| { | { | ||||
| immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR); | immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR); | ||||
| ▲ Show 20 Lines • Show All 134 Lines • ▼ Show 20 Lines | if (ca->dtx & CAM_DTX_HARMONY_TRI_A) { | ||||
| drawviewborder_triangle(shdr_pos, x1, x2, y1, y2, 1, 'A'); | drawviewborder_triangle(shdr_pos, x1, x2, y1, y2, 1, 'A'); | ||||
| } | } | ||||
| if (ca->dtx & CAM_DTX_HARMONY_TRI_B) { | if (ca->dtx & CAM_DTX_HARMONY_TRI_B) { | ||||
| drawviewborder_triangle(shdr_pos, x1, x2, y1, y2, 1, 'B'); | drawviewborder_triangle(shdr_pos, x1, x2, y1, y2, 1, 'B'); | ||||
| } | } | ||||
| if (ca->flag & CAM_SHOW_SAFE_MARGINS) { | if (ca->flag & CAM_SHOW_SAFE_MARGINS) { | ||||
| UI_draw_safe_areas(shdr_pos, | rctf margins_rect{}; | ||||
| &(const rctf){ | margins_rect.xmin = x1; | ||||
| .xmin = x1, | margins_rect.xmax = x2; | ||||
| .xmax = x2, | margins_rect.ymin = y1; | ||||
| .ymin = y1, | margins_rect.ymax = y2; | ||||
| .ymax = y2, | |||||
| }, | UI_draw_safe_areas( | ||||
| scene->safe_areas.title, | shdr_pos, &margins_rect, scene->safe_areas.title, scene->safe_areas.action); | ||||
| scene->safe_areas.action); | |||||
| if (ca->flag & CAM_SHOW_SAFE_CENTER) { | if (ca->flag & CAM_SHOW_SAFE_CENTER) { | ||||
| rctf center_rect{}; | |||||
| center_rect.xmin = x1; | |||||
| center_rect.xmax = x2; | |||||
| center_rect.ymin = y1; | |||||
| center_rect.ymax = y2; | |||||
| UI_draw_safe_areas(shdr_pos, | UI_draw_safe_areas(shdr_pos, | ||||
| &(const rctf){ | ¢er_rect, | ||||
| .xmin = x1, | |||||
| .xmax = x2, | |||||
| .ymin = y1, | |||||
| .ymax = y2, | |||||
| }, | |||||
| scene->safe_areas.title_center, | scene->safe_areas.title_center, | ||||
| scene->safe_areas.action_center); | scene->safe_areas.action_center); | ||||
| } | } | ||||
| } | } | ||||
| if (ca->flag & CAM_SHOWSENSOR) { | if (ca->flag & CAM_SHOWSENSOR) { | ||||
| /* determine sensor fit, and get sensor x/y, for auto fit we | /* determine sensor fit, and get sensor x/y, for auto fit we | ||||
| * assume and square sensor and only use sensor_x */ | * assume and square sensor and only use sensor_x */ | ||||
| ▲ Show 20 Lines • Show All 95 Lines • ▼ Show 20 Lines | if (scene->unit.system) { | ||||
| BKE_unit_system_get(scene->unit.system, B_UNIT_LENGTH, &usys, &len); | BKE_unit_system_get(scene->unit.system, B_UNIT_LENGTH, &usys, &len); | ||||
| if (usys) { | if (usys) { | ||||
| int i = BKE_unit_base_get(usys); | int i = BKE_unit_base_get(usys); | ||||
| if (r_grid_unit) { | if (r_grid_unit) { | ||||
| *r_grid_unit = BKE_unit_display_name_get(usys, i); | *r_grid_unit = BKE_unit_display_name_get(usys, i); | ||||
| } | } | ||||
| return (float)BKE_unit_scalar_get(usys, i) / scene->unit.scale_length; | return float(BKE_unit_scalar_get(usys, i)) / scene->unit.scale_length; | ||||
| } | } | ||||
| } | } | ||||
| return 1.0f; | return 1.0f; | ||||
| } | } | ||||
| float ED_view3d_grid_scale(const Scene *scene, View3D *v3d, const char **r_grid_unit) | float ED_view3d_grid_scale(const Scene *scene, View3D *v3d, const char **r_grid_unit) | ||||
| { | { | ||||
| Show All 17 Lines | if (rv3d->view == RV3D_VIEW_USER) { | ||||
| /* Skip steps */ | /* Skip steps */ | ||||
| len = BKE_unit_base_get(usys) + 1; | len = BKE_unit_base_get(usys) + 1; | ||||
| } | } | ||||
| grid_scale /= scene->unit.scale_length; | grid_scale /= scene->unit.scale_length; | ||||
| int i; | int i; | ||||
| for (i = 0; i < len; i++) { | for (i = 0; i < len; i++) { | ||||
| r_grid_steps[i] = (float)BKE_unit_scalar_get(usys, len - 1 - i) * grid_scale; | r_grid_steps[i] = float(BKE_unit_scalar_get(usys, len - 1 - i)) * grid_scale; | ||||
| } | } | ||||
| for (; i < STEPS_LEN; i++) { | for (; i < STEPS_LEN; i++) { | ||||
| /* Fill last slots */ | /* Fill last slots */ | ||||
| r_grid_steps[i] = 10.0f * r_grid_steps[i - 1]; | r_grid_steps[i] = 10.0f * r_grid_steps[i - 1]; | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| if (rv3d->view != RV3D_VIEW_USER) { | if (rv3d->view != RV3D_VIEW_USER) { | ||||
| Show All 13 Lines | |||||
| } | } | ||||
| float ED_view3d_grid_view_scale(Scene *scene, | float ED_view3d_grid_view_scale(Scene *scene, | ||||
| View3D *v3d, | View3D *v3d, | ||||
| ARegion *region, | ARegion *region, | ||||
| const char **r_grid_unit) | const char **r_grid_unit) | ||||
| { | { | ||||
| float grid_scale; | float grid_scale; | ||||
| RegionView3D *rv3d = region->regiondata; | RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata); | ||||
| if (!rv3d->is_persp && RV3D_VIEW_IS_AXIS(rv3d->view)) { | if (!rv3d->is_persp && RV3D_VIEW_IS_AXIS(rv3d->view)) { | ||||
| /* Decrease the distance between grid snap points depending on zoom. */ | /* Decrease the distance between grid snap points depending on zoom. */ | ||||
| float dist = 12.0f / (region->sizex * rv3d->winmat[0][0]); | float dist = 12.0f / (region->sizex * rv3d->winmat[0][0]); | ||||
| float grid_steps[STEPS_LEN]; | float grid_steps[STEPS_LEN]; | ||||
| ED_view3d_grid_steps(scene, v3d, rv3d, grid_steps); | ED_view3d_grid_steps(scene, v3d, rv3d, grid_steps); | ||||
| /* Skip last item, in case the 'mid_dist' is greater than the largest unit. */ | /* Skip last item, in case the 'mid_dist' is greater than the largest unit. */ | ||||
| int i; | int i; | ||||
| for (i = 0; i < ARRAY_SIZE(grid_steps) - 1; i++) { | for (i = 0; i < ARRAY_SIZE(grid_steps) - 1; i++) { | ||||
| ▲ Show 20 Lines • Show All 81 Lines • ▼ Show 20 Lines | static void draw_view_axis(RegionView3D *rv3d, const rcti *rect) | ||||
| immEnd(); | immEnd(); | ||||
| immUnbindProgram(); | immUnbindProgram(); | ||||
| GPU_line_smooth(false); | GPU_line_smooth(false); | ||||
| /* draw axis names */ | /* draw axis names */ | ||||
| for (int axis_i = 0; axis_i < 3; axis_i++) { | for (int axis_i = 0; axis_i < 3; axis_i++) { | ||||
| int i = axis_order[axis_i]; | int i = axis_order[axis_i]; | ||||
| const char axis_text[2] = {'x' + i, '\0'}; | const char axis_text[2] = {char('x' + i), '\0'}; | ||||
| BLF_color4ubv(BLF_default(), axis_col[i]); | BLF_color4ubv(BLF_default(), axis_col[i]); | ||||
| BLF_draw_default(axis_pos[i][0] + 2, axis_pos[i][1] + 2, 0.0f, axis_text, 1); | BLF_draw_default(axis_pos[i][0] + 2, axis_pos[i][1] + 2, 0.0f, axis_text, 1); | ||||
| } | } | ||||
| } | } | ||||
| #ifdef WITH_INPUT_NDOF | #ifdef WITH_INPUT_NDOF | ||||
| /* draw center and axis of rotation for ongoing 3D mouse navigation */ | /* draw center and axis of rotation for ongoing 3D mouse navigation */ | ||||
| static void draw_rotation_guide(const RegionView3D *rv3d) | static void draw_rotation_guide(const RegionView3D *rv3d) | ||||
| ▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | # endif | ||||
| immVertex3fv(pos, end); | immVertex3fv(pos, end); | ||||
| immEnd(); | immEnd(); | ||||
| /* -- draw ring around rotation center -- */ | /* -- draw ring around rotation center -- */ | ||||
| { | { | ||||
| # define ROT_AXIS_DETAIL 13 | # define ROT_AXIS_DETAIL 13 | ||||
| const float s = 0.05f * scale; | const float s = 0.05f * scale; | ||||
| const float step = 2.0f * (float)(M_PI / ROT_AXIS_DETAIL); | const float step = 2.0f * float(M_PI / ROT_AXIS_DETAIL); | ||||
| float q[4]; /* rotate ring so it's perpendicular to axis */ | float q[4]; /* rotate ring so it's perpendicular to axis */ | ||||
| const int upright = fabsf(rv3d->rot_axis[2]) >= 0.95f; | const int upright = fabsf(rv3d->rot_axis[2]) >= 0.95f; | ||||
| if (!upright) { | if (!upright) { | ||||
| const float up[3] = {0.0f, 0.0f, 1.0f}; | const float up[3] = {0.0f, 0.0f, 1.0f}; | ||||
| float vis_angle, vis_axis[3]; | float vis_angle, vis_axis[3]; | ||||
| cross_v3_v3v3(vis_axis, up, rv3d->rot_axis); | cross_v3_v3v3(vis_axis, up, rv3d->rot_axis); | ||||
| ▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | |||||
| /** | /** | ||||
| * Render and camera border | * Render and camera border | ||||
| */ | */ | ||||
| static void view3d_draw_border(const bContext *C, ARegion *region) | static void view3d_draw_border(const bContext *C, ARegion *region) | ||||
| { | { | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| Depsgraph *depsgraph = CTX_data_expect_evaluated_depsgraph(C); | Depsgraph *depsgraph = CTX_data_expect_evaluated_depsgraph(C); | ||||
| RegionView3D *rv3d = region->regiondata; | RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata); | ||||
| View3D *v3d = CTX_wm_view3d(C); | View3D *v3d = CTX_wm_view3d(C); | ||||
| if (rv3d->persp == RV3D_CAMOB) { | if (rv3d->persp == RV3D_CAMOB) { | ||||
| drawviewborder(scene, depsgraph, region, v3d); | drawviewborder(scene, depsgraph, region, v3d); | ||||
| } | } | ||||
| else if (v3d->flag2 & V3D_RENDER_BORDER) { | else if (v3d->flag2 & V3D_RENDER_BORDER) { | ||||
| drawrenderborder(region, v3d); | drawrenderborder(region, v3d); | ||||
| } | } | ||||
| Show All 13 Lines | static void view3d_draw_grease_pencil(const bContext *UNUSED(C)) | ||||
| /* TODO: viewport. */ | /* TODO: viewport. */ | ||||
| } | } | ||||
| /** | /** | ||||
| * Viewport Name | * Viewport Name | ||||
| */ | */ | ||||
| static const char *view3d_get_name(View3D *v3d, RegionView3D *rv3d) | static const char *view3d_get_name(View3D *v3d, RegionView3D *rv3d) | ||||
| { | { | ||||
| const char *name = NULL; | const char *name = nullptr; | ||||
| switch (rv3d->view) { | switch (rv3d->view) { | ||||
| case RV3D_VIEW_FRONT: | case RV3D_VIEW_FRONT: | ||||
| if (rv3d->persp == RV3D_ORTHO) { | if (rv3d->persp == RV3D_ORTHO) { | ||||
| name = IFACE_("Front Orthographic"); | name = IFACE_("Front Orthographic"); | ||||
| } | } | ||||
| else { | else { | ||||
| name = IFACE_("Front Perspective"); | name = IFACE_("Front Perspective"); | ||||
| Show All 39 Lines | case RV3D_VIEW_LEFT: | ||||
| name = IFACE_("Left Perspective"); | name = IFACE_("Left Perspective"); | ||||
| } | } | ||||
| break; | break; | ||||
| default: | default: | ||||
| if (rv3d->persp == RV3D_CAMOB) { | if (rv3d->persp == RV3D_CAMOB) { | ||||
| if ((v3d->camera) && (v3d->camera->type == OB_CAMERA)) { | if ((v3d->camera) && (v3d->camera->type == OB_CAMERA)) { | ||||
| Camera *cam; | Camera *cam; | ||||
| cam = v3d->camera->data; | cam = static_cast<Camera *>(v3d->camera->data); | ||||
| if (cam->type == CAM_PERSP) { | if (cam->type == CAM_PERSP) { | ||||
| name = IFACE_("Camera Perspective"); | name = IFACE_("Camera Perspective"); | ||||
| } | } | ||||
| else if (cam->type == CAM_ORTHO) { | else if (cam->type == CAM_ORTHO) { | ||||
| name = IFACE_("Camera Orthographic"); | name = IFACE_("Camera Orthographic"); | ||||
| } | } | ||||
| else { | else { | ||||
| BLI_assert(cam->type == CAM_PANO); | BLI_assert(cam->type == CAM_PANO); | ||||
| Show All 10 Lines | default: | ||||
| } | } | ||||
| } | } | ||||
| return name; | return name; | ||||
| } | } | ||||
| static void draw_viewport_name(ARegion *region, View3D *v3d, int xoffset, int *yoffset) | static void draw_viewport_name(ARegion *region, View3D *v3d, int xoffset, int *yoffset) | ||||
| { | { | ||||
| RegionView3D *rv3d = region->regiondata; | RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata); | ||||
| const char *name = view3d_get_name(v3d, rv3d); | const char *name = view3d_get_name(v3d, rv3d); | ||||
| const char *name_array[3] = {name, NULL, NULL}; | const char *name_array[3] = {name, nullptr, nullptr}; | ||||
| int name_array_len = 1; | int name_array_len = 1; | ||||
| const int font_id = BLF_default(); | const int font_id = BLF_default(); | ||||
| /* 6 is the maximum size of the axis roll text. */ | /* 6 is the maximum size of the axis roll text. */ | ||||
| /* increase size for unicode languages (Chinese in utf-8...) */ | /* increase size for unicode languages (Chinese in utf-8...) */ | ||||
| char tmpstr[96 + 6]; | char tmpstr[96 + 6]; | ||||
| BLF_enable(font_id, BLF_SHADOW); | BLF_enable(font_id, BLF_SHADOW); | ||||
| BLF_shadow(font_id, 5, (const float[4]){0.0f, 0.0f, 0.0f, 1.0f}); | BLF_shadow(font_id, 5, float4{0.0f, 0.0f, 0.0f, 1.0f}); | ||||
| BLF_shadow_offset(font_id, 1, -1); | BLF_shadow_offset(font_id, 1, -1); | ||||
| if (RV3D_VIEW_IS_AXIS(rv3d->view) && (rv3d->view_axis_roll != RV3D_VIEW_AXIS_ROLL_0)) { | if (RV3D_VIEW_IS_AXIS(rv3d->view) && (rv3d->view_axis_roll != RV3D_VIEW_AXIS_ROLL_0)) { | ||||
| const char *axis_roll; | const char *axis_roll; | ||||
| switch (rv3d->view_axis_roll) { | switch (rv3d->view_axis_roll) { | ||||
| case RV3D_VIEW_AXIS_ROLL_90: | case RV3D_VIEW_AXIS_ROLL_90: | ||||
| axis_roll = " 90\xC2\xB0"; | axis_roll = " 90\xC2\xB0"; | ||||
| break; | break; | ||||
| Show All 30 Lines | static void draw_viewport_name(ARegion *region, View3D *v3d, int xoffset, int *yoffset) | ||||
| BLF_disable(font_id, BLF_SHADOW); | BLF_disable(font_id, BLF_SHADOW); | ||||
| } | } | ||||
| /** | /** | ||||
| * Draw info beside axes in top-left corner: | * Draw info beside axes in top-left corner: | ||||
| * frame-number, collection, object name, bone name (if available), marker name (if available). | * frame-number, collection, object name, bone name (if available), marker name (if available). | ||||
| */ | */ | ||||
| static void draw_selected_name( | static void draw_selected_name( | ||||
| Scene *scene, ViewLayer *view_layer, Object *ob, int xoffset, int *yoffset) | const View3D *v3d, Scene *scene, ViewLayer *view_layer, Object *ob, int xoffset, int *yoffset) | ||||
| { | { | ||||
| const int cfra = scene->r.cfra; | const int cfra = scene->r.cfra; | ||||
| const char *msg_pin = " (Pinned)"; | const char *msg_pin = " (Pinned)"; | ||||
| const char *msg_sep = " : "; | const char *msg_sep = " : "; | ||||
| const int font_id = BLF_default(); | const int font_id = BLF_default(); | ||||
| char info[300]; | char info[300]; | ||||
| char *s = info; | char *s = info; | ||||
| s += sprintf(s, "(%d)", cfra); | s += sprintf(s, "(%d)", cfra); | ||||
| if ((ob == NULL) || (ob->mode == OB_MODE_OBJECT)) { | if ((ob == nullptr) || (ob->mode == OB_MODE_OBJECT)) { | ||||
| BKE_view_layer_synced_ensure(scene, view_layer); | BKE_view_layer_synced_ensure(scene, view_layer); | ||||
| LayerCollection *layer_collection = BKE_view_layer_active_collection_get(view_layer); | LayerCollection *layer_collection = BKE_view_layer_active_collection_get(view_layer); | ||||
| s += sprintf(s, | s += sprintf(s, | ||||
| " %s%s", | " %s%s", | ||||
| BKE_collection_ui_name_get(layer_collection->collection), | BKE_collection_ui_name_get(layer_collection->collection), | ||||
| (ob == NULL) ? "" : " |"); | (ob == nullptr) ? "" : " |"); | ||||
| } | } | ||||
| /* Info can contain: | /* Info can contain: | ||||
| * - A frame `(7 + 2)`. | * - A frame `(7 + 2)`. | ||||
| * - A collection name `(MAX_NAME + 3)`. | * - A collection name `(MAX_NAME + 3)`. | ||||
| * - 3 object names `(MAX_NAME)`. | * - 3 object names `(MAX_NAME)`. | ||||
| * - 2 BREAD_CRUMB_SEPARATOR(s) `(6)`. | * - 2 BREAD_CRUMB_SEPARATOR(s) `(6)`. | ||||
| * - A SHAPE_KEY_PINNED marker and a trailing '\0' `(9+1)` - translated, so give some room! | * - A SHAPE_KEY_PINNED marker and a trailing '\0' `(9+1)` - translated, so give some room! | ||||
| * - A marker name `(MAX_NAME + 3)`. | * - A marker name `(MAX_NAME + 3)`. | ||||
| */ | */ | ||||
| /* get name of marker on current frame (if available) */ | /* get name of marker on current frame (if available) */ | ||||
| const char *markern = BKE_scene_find_marker_name(scene, cfra); | const char *markern = BKE_scene_find_marker_name(scene, cfra); | ||||
| /* check if there is an object */ | /* check if there is an object */ | ||||
| if (ob) { | if (ob) { | ||||
| *s++ = ' '; | *s++ = ' '; | ||||
| s += BLI_strcpy_rlen(s, ob->id.name + 2); | s += BLI_strcpy_rlen(s, ob->id.name + 2); | ||||
| /* name(s) to display depends on type of object */ | /* name(s) to display depends on type of object */ | ||||
| if (ob->type == OB_ARMATURE) { | if (ob->type == OB_ARMATURE) { | ||||
| bArmature *arm = ob->data; | bArmature *arm = static_cast<bArmature *>(ob->data); | ||||
| /* show name of active bone too (if possible) */ | /* show name of active bone too (if possible) */ | ||||
| if (arm->edbo) { | if (arm->edbo) { | ||||
| if (arm->act_edbone) { | if (arm->act_edbone) { | ||||
| s += BLI_strcpy_rlen(s, msg_sep); | s += BLI_strcpy_rlen(s, msg_sep); | ||||
| s += BLI_strcpy_rlen(s, arm->act_edbone->name); | s += BLI_strcpy_rlen(s, arm->act_edbone->name); | ||||
| } | } | ||||
| } | } | ||||
| else if (ob->mode & OB_MODE_POSE) { | else if (ob->mode & OB_MODE_POSE) { | ||||
| if (arm->act_bone) { | if (arm->act_bone) { | ||||
| if (arm->act_bone->layer & arm->layer) { | if (arm->act_bone->layer & arm->layer) { | ||||
| s += BLI_strcpy_rlen(s, msg_sep); | s += BLI_strcpy_rlen(s, msg_sep); | ||||
| s += BLI_strcpy_rlen(s, arm->act_bone->name); | s += BLI_strcpy_rlen(s, arm->act_bone->name); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| else if (ELEM(ob->type, OB_MESH, OB_LATTICE, OB_CURVES_LEGACY)) { | else if (ELEM(ob->type, OB_MESH, OB_LATTICE, OB_CURVES_LEGACY)) { | ||||
| /* Try to display active bone and active shape-key too (if they exist). */ | /* Try to display active bone and active shape-key too (if they exist). */ | ||||
| if (ob->type == OB_MESH && ob->mode & OB_MODE_WEIGHT_PAINT) { | if (ob->type == OB_MESH && ob->mode & OB_MODE_WEIGHT_PAINT) { | ||||
| Object *armobj = BKE_object_pose_armature_get(ob); | Object *armobj = BKE_object_pose_armature_get(ob); | ||||
| if (armobj && armobj->mode & OB_MODE_POSE) { | if (armobj && armobj->mode & OB_MODE_POSE) { | ||||
| bArmature *arm = armobj->data; | bArmature *arm = static_cast<bArmature *>(armobj->data); | ||||
| if (arm->act_bone) { | if (arm->act_bone) { | ||||
| if (arm->act_bone->layer & arm->layer) { | if (arm->act_bone->layer & arm->layer) { | ||||
| s += BLI_strcpy_rlen(s, msg_sep); | s += BLI_strcpy_rlen(s, msg_sep); | ||||
| s += BLI_strcpy_rlen(s, arm->act_bone->name); | s += BLI_strcpy_rlen(s, arm->act_bone->name); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| Key *key = BKE_key_from_object(ob); | Key *key = BKE_key_from_object(ob); | ||||
| if (key) { | if (key) { | ||||
| KeyBlock *kb = BLI_findlink(&key->block, ob->shapenr - 1); | KeyBlock *kb = static_cast<KeyBlock *>(BLI_findlink(&key->block, ob->shapenr - 1)); | ||||
| if (kb) { | if (kb) { | ||||
| s += BLI_strcpy_rlen(s, msg_sep); | s += BLI_strcpy_rlen(s, msg_sep); | ||||
| s += BLI_strcpy_rlen(s, kb->name); | s += BLI_strcpy_rlen(s, kb->name); | ||||
| if (ob->shapeflag & OB_SHAPE_LOCK) { | if (ob->shapeflag & OB_SHAPE_LOCK) { | ||||
| s += BLI_strcpy_rlen(s, IFACE_(msg_pin)); | s += BLI_strcpy_rlen(s, IFACE_(msg_pin)); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* color depends on whether there is a keyframe */ | /* color depends on whether there is a keyframe */ | ||||
| if (id_frame_has_keyframe( | if (id_frame_has_keyframe( | ||||
| (ID *)ob, /* BKE_scene_ctime_get(scene) */ (float)cfra, ANIMFILTER_KEYS_LOCAL)) { | (ID *)ob, /* BKE_scene_ctime_get(scene) */ float(cfra), ANIMFILTER_KEYS_LOCAL)) { | ||||
| UI_FontThemeColor(font_id, TH_TIME_KEYFRAME); | UI_FontThemeColor(font_id, TH_TIME_KEYFRAME); | ||||
| } | } | ||||
| else if (ED_gpencil_has_keyframe_v3d(scene, ob, cfra)) { | else if (ED_gpencil_has_keyframe_v3d(scene, ob, cfra)) { | ||||
| UI_FontThemeColor(font_id, TH_TIME_GP_KEYFRAME); | UI_FontThemeColor(font_id, TH_TIME_GP_KEYFRAME); | ||||
| } | } | ||||
| else { | else { | ||||
| UI_FontThemeColor(font_id, TH_TEXT_HI); | UI_FontThemeColor(font_id, TH_TEXT_HI); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| /* no object */ | /* no object */ | ||||
| if (ED_gpencil_has_keyframe_v3d(scene, NULL, cfra)) { | if (ED_gpencil_has_keyframe_v3d(scene, nullptr, cfra)) { | ||||
| UI_FontThemeColor(font_id, TH_TIME_GP_KEYFRAME); | UI_FontThemeColor(font_id, TH_TIME_GP_KEYFRAME); | ||||
| } | } | ||||
| else { | else { | ||||
| UI_FontThemeColor(font_id, TH_TEXT_HI); | UI_FontThemeColor(font_id, TH_TEXT_HI); | ||||
| } | } | ||||
| } | } | ||||
| if (markern) { | if (markern) { | ||||
| s += sprintf(s, " <%s>", markern); | s += sprintf(s, " <%s>", markern); | ||||
| } | } | ||||
| if (v3d->flag2 & V3D_SHOW_VIEWER) { | |||||
| if (!BLI_listbase_is_empty(&v3d->viewer_path.path)) { | |||||
| s += sprintf(s, "%s", IFACE_(" (Viewer)")); | |||||
| } | |||||
| } | |||||
| BLF_enable(font_id, BLF_SHADOW); | BLF_enable(font_id, BLF_SHADOW); | ||||
| BLF_shadow(font_id, 5, (const float[4]){0.0f, 0.0f, 0.0f, 1.0f}); | BLF_shadow(font_id, 5, float4{0.0f, 0.0f, 0.0f, 1.0f}); | ||||
| BLF_shadow_offset(font_id, 1, -1); | BLF_shadow_offset(font_id, 1, -1); | ||||
| *yoffset -= VIEW3D_OVERLAY_LINEHEIGHT; | *yoffset -= VIEW3D_OVERLAY_LINEHEIGHT; | ||||
| BLF_draw_default(xoffset, *yoffset, 0.0f, info, sizeof(info)); | BLF_draw_default(xoffset, *yoffset, 0.0f, info, sizeof(info)); | ||||
| BLF_disable(font_id, BLF_SHADOW); | BLF_disable(font_id, BLF_SHADOW); | ||||
| } | } | ||||
| static void draw_grid_unit_name( | static void draw_grid_unit_name( | ||||
| Scene *scene, ARegion *region, View3D *v3d, int xoffset, int *yoffset) | Scene *scene, ARegion *region, View3D *v3d, int xoffset, int *yoffset) | ||||
| { | { | ||||
| RegionView3D *rv3d = region->regiondata; | RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata); | ||||
| if (!rv3d->is_persp && RV3D_VIEW_IS_AXIS(rv3d->view)) { | if (!rv3d->is_persp && RV3D_VIEW_IS_AXIS(rv3d->view)) { | ||||
| const char *grid_unit = NULL; | const char *grid_unit = nullptr; | ||||
| int font_id = BLF_default(); | int font_id = BLF_default(); | ||||
| ED_view3d_grid_view_scale(scene, v3d, region, &grid_unit); | ED_view3d_grid_view_scale(scene, v3d, region, &grid_unit); | ||||
| if (grid_unit) { | if (grid_unit) { | ||||
| char numstr[32] = ""; | char numstr[32] = ""; | ||||
| UI_FontThemeColor(font_id, TH_TEXT_HI); | UI_FontThemeColor(font_id, TH_TEXT_HI); | ||||
| if (v3d->grid != 1.0f) { | if (v3d->grid != 1.0f) { | ||||
| BLI_snprintf(numstr, sizeof(numstr), "%s x %.4g", grid_unit, v3d->grid); | BLI_snprintf(numstr, sizeof(numstr), "%s x %.4g", grid_unit, v3d->grid); | ||||
| } | } | ||||
| *yoffset -= VIEW3D_OVERLAY_LINEHEIGHT; | *yoffset -= VIEW3D_OVERLAY_LINEHEIGHT; | ||||
| BLF_enable(font_id, BLF_SHADOW); | BLF_enable(font_id, BLF_SHADOW); | ||||
| BLF_shadow(font_id, 5, (const float[4]){0.0f, 0.0f, 0.0f, 1.0f}); | BLF_shadow(font_id, 5, float4{0.0f, 0.0f, 0.0f, 1.0f}); | ||||
| BLF_shadow_offset(font_id, 1, -1); | BLF_shadow_offset(font_id, 1, -1); | ||||
| BLF_draw_default(xoffset, *yoffset, 0.0f, numstr[0] ? numstr : grid_unit, sizeof(numstr)); | BLF_draw_default(xoffset, *yoffset, 0.0f, numstr[0] ? numstr : grid_unit, sizeof(numstr)); | ||||
| BLF_disable(font_id, BLF_SHADOW); | BLF_disable(font_id, BLF_SHADOW); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| void view3d_draw_region_info(const bContext *C, ARegion *region) | void view3d_draw_region_info(const bContext *C, ARegion *region) | ||||
| { | { | ||||
| RegionView3D *rv3d = region->regiondata; | RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata); | ||||
| View3D *v3d = CTX_wm_view3d(C); | View3D *v3d = CTX_wm_view3d(C); | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| wmWindowManager *wm = CTX_wm_manager(C); | wmWindowManager *wm = CTX_wm_manager(C); | ||||
| Main *bmain = CTX_data_main(C); | Main *bmain = CTX_data_main(C); | ||||
| ViewLayer *view_layer = CTX_data_view_layer(C); | ViewLayer *view_layer = CTX_data_view_layer(C); | ||||
| #ifdef WITH_INPUT_NDOF | #ifdef WITH_INPUT_NDOF | ||||
| if ((U.ndof_flag & NDOF_SHOW_GUIDE) && ((RV3D_LOCK_FLAGS(rv3d) & RV3D_LOCK_ROTATION) == 0) && | if ((U.ndof_flag & NDOF_SHOW_GUIDE) && ((RV3D_LOCK_FLAGS(rv3d) & RV3D_LOCK_ROTATION) == 0) && | ||||
| Show All 38 Lines | if ((v3d->flag2 & V3D_HIDE_OVERLAYS) == 0 && (v3d->overlay.flag & V3D_OVERLAY_HIDE_TEXT) == 0) { | ||||
| } | } | ||||
| else if (U.uiflag & USER_SHOW_VIEWPORTNAME) { | else if (U.uiflag & USER_SHOW_VIEWPORTNAME) { | ||||
| draw_viewport_name(region, v3d, xoffset, &yoffset); | draw_viewport_name(region, v3d, xoffset, &yoffset); | ||||
| } | } | ||||
| if (U.uiflag & USER_DRAWVIEWINFO) { | if (U.uiflag & USER_DRAWVIEWINFO) { | ||||
| BKE_view_layer_synced_ensure(scene, view_layer); | BKE_view_layer_synced_ensure(scene, view_layer); | ||||
| Object *ob = BKE_view_layer_active_object_get(view_layer); | Object *ob = BKE_view_layer_active_object_get(view_layer); | ||||
| draw_selected_name(scene, view_layer, ob, xoffset, &yoffset); | draw_selected_name(v3d, scene, view_layer, ob, xoffset, &yoffset); | ||||
| } | } | ||||
| if (v3d->gridflag & (V3D_SHOW_FLOOR | V3D_SHOW_X | V3D_SHOW_Y | V3D_SHOW_Z)) { | if (v3d->gridflag & (V3D_SHOW_FLOOR | V3D_SHOW_X | V3D_SHOW_Y | V3D_SHOW_Z)) { | ||||
| /* draw below the viewport name */ | /* draw below the viewport name */ | ||||
| draw_grid_unit_name(scene, region, v3d, xoffset, &yoffset); | draw_grid_unit_name(scene, region, v3d, xoffset, &yoffset); | ||||
| } | } | ||||
| DRW_draw_region_engine_info(xoffset, &yoffset, VIEW3D_OVERLAY_LINEHEIGHT); | DRW_draw_region_engine_info(xoffset, &yoffset, VIEW3D_OVERLAY_LINEHEIGHT); | ||||
| } | } | ||||
| if ((v3d->flag2 & V3D_HIDE_OVERLAYS) == 0 && (v3d->overlay.flag & V3D_OVERLAY_STATS)) { | if ((v3d->flag2 & V3D_HIDE_OVERLAYS) == 0 && (v3d->overlay.flag & V3D_OVERLAY_STATS)) { | ||||
| View3D *v3d_local = v3d->localvd ? v3d : NULL; | View3D *v3d_local = v3d->localvd ? v3d : nullptr; | ||||
| ED_info_draw_stats( | ED_info_draw_stats( | ||||
| bmain, scene, view_layer, v3d_local, xoffset, &yoffset, VIEW3D_OVERLAY_LINEHEIGHT); | bmain, scene, view_layer, v3d_local, xoffset, &yoffset, VIEW3D_OVERLAY_LINEHEIGHT); | ||||
| } | } | ||||
| BLF_batch_draw_end(); | BLF_batch_draw_end(); | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Draw Viewport Contents | /** \name Draw Viewport Contents | ||||
| * \{ */ | * \{ */ | ||||
| static void view3d_draw_view(const bContext *C, ARegion *region) | static void view3d_draw_view(const bContext *C, ARegion *region) | ||||
| { | { | ||||
| ED_view3d_draw_setup_view(CTX_wm_manager(C), | ED_view3d_draw_setup_view(CTX_wm_manager(C), | ||||
| CTX_wm_window(C), | CTX_wm_window(C), | ||||
| CTX_data_expect_evaluated_depsgraph(C), | CTX_data_expect_evaluated_depsgraph(C), | ||||
| CTX_data_scene(C), | CTX_data_scene(C), | ||||
| region, | region, | ||||
| CTX_wm_view3d(C), | CTX_wm_view3d(C), | ||||
| NULL, | nullptr, | ||||
| NULL, | nullptr, | ||||
| NULL); | nullptr); | ||||
| /* Only 100% compliant on new spec goes below */ | /* Only 100% compliant on new spec goes below */ | ||||
| DRW_draw_view(C); | DRW_draw_view(C); | ||||
| } | } | ||||
| RenderEngineType *ED_view3d_engine_type(const Scene *scene, int drawtype) | RenderEngineType *ED_view3d_engine_type(const Scene *scene, int drawtype) | ||||
| { | { | ||||
| /* | /* | ||||
| * Temporary viewport draw modes until we have a proper system. | * Temporary viewport draw modes until we have a proper system. | ||||
| * all modes are done in the draw manager, except external render | * all modes are done in the draw manager, except external render | ||||
| * engines like Cycles. | * engines like Cycles. | ||||
| */ | */ | ||||
| RenderEngineType *type = RE_engines_find(scene->r.engine); | RenderEngineType *type = RE_engines_find(scene->r.engine); | ||||
| if (drawtype == OB_MATERIAL && (type->flag & RE_USE_EEVEE_VIEWPORT)) { | if (drawtype == OB_MATERIAL && (type->flag & RE_USE_EEVEE_VIEWPORT)) { | ||||
| return RE_engines_find(RE_engine_id_BLENDER_EEVEE); | return RE_engines_find(RE_engine_id_BLENDER_EEVEE); | ||||
| } | } | ||||
| return type; | return type; | ||||
| } | } | ||||
| static void view3d_update_viewer_path(const bContext *C) | |||||
| { | |||||
| View3D *v3d = CTX_wm_view3d(C); | |||||
| WorkSpace *workspace = CTX_wm_workspace(C); | |||||
| /* Always use viewer path from workspace, pinning is not supported currently. */ | |||||
| if (!BKE_viewer_path_equal(&v3d->viewer_path, &workspace->viewer_path)) { | |||||
| BKE_viewer_path_clear(&v3d->viewer_path); | |||||
| BKE_viewer_path_copy(&v3d->viewer_path, &workspace->viewer_path); | |||||
| } | |||||
| } | |||||
| void view3d_main_region_draw(const bContext *C, ARegion *region) | void view3d_main_region_draw(const bContext *C, ARegion *region) | ||||
| { | { | ||||
| Main *bmain = CTX_data_main(C); | Main *bmain = CTX_data_main(C); | ||||
| View3D *v3d = CTX_wm_view3d(C); | View3D *v3d = CTX_wm_view3d(C); | ||||
| view3d_update_viewer_path(C); | |||||
| view3d_draw_view(C, region); | view3d_draw_view(C, region); | ||||
| DRW_cache_free_old_subdiv(); | DRW_cache_free_old_subdiv(); | ||||
| DRW_cache_free_old_batches(bmain); | DRW_cache_free_old_batches(bmain); | ||||
| BKE_image_free_old_gputextures(bmain); | BKE_image_free_old_gputextures(bmain); | ||||
| GPU_pass_cache_garbage_collect(); | GPU_pass_cache_garbage_collect(); | ||||
| /* No depth test for drawing action zones afterwards. */ | /* No depth test for drawing action zones afterwards. */ | ||||
| ▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | void ED_view3d_draw_offscreen(Depsgraph *depsgraph, | ||||
| bool is_image_render, | bool is_image_render, | ||||
| bool draw_background, | bool draw_background, | ||||
| const char *viewname, | const char *viewname, | ||||
| const bool do_color_management, | const bool do_color_management, | ||||
| const bool restore_rv3d_mats, | const bool restore_rv3d_mats, | ||||
| GPUOffScreen *ofs, | GPUOffScreen *ofs, | ||||
| GPUViewport *viewport) | GPUViewport *viewport) | ||||
| { | { | ||||
| RegionView3D *rv3d = region->regiondata; | RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata); | ||||
| RenderEngineType *engine_type = ED_view3d_engine_type(scene, drawtype); | RenderEngineType *engine_type = ED_view3d_engine_type(scene, drawtype); | ||||
| /* Store `orig` variables. */ | /* Store `orig` variables. */ | ||||
| struct { | struct { | ||||
| struct bThemeState theme_state; | struct bThemeState theme_state; | ||||
| /* #View3D */ | /* #View3D */ | ||||
| eDrawType v3d_shading_type; | eDrawType v3d_shading_type; | ||||
| /* #Region */ | /* #Region */ | ||||
| int region_winx, region_winy; | int region_winx, region_winy; | ||||
| rcti region_winrct; | rcti region_winrct; | ||||
| /* #RegionView3D */ | /* #RegionView3D */ | ||||
| /** | /** | ||||
| * Needed so the value won't be left overwritten, | * Needed so the value won't be left overwritten, | ||||
| * Without this the #wmPaintCursor can't use the pixel size & view matrices for drawing. | * Without this the #wmPaintCursor can't use the pixel size & view matrices for drawing. | ||||
| */ | */ | ||||
| struct RV3DMatrixStore *rv3d_mats; | struct RV3DMatrixStore *rv3d_mats; | ||||
| } orig = { | } orig{}; | ||||
| .v3d_shading_type = v3d->shading.type, | orig.v3d_shading_type = eDrawType(v3d->shading.type); | ||||
| orig.region_winx = region->winx; | |||||
| .region_winx = region->winx, | orig.region_winy = region->winy; | ||||
| .region_winy = region->winy, | orig.region_winrct = region->winrct; | ||||
| .region_winrct = region->winrct, | orig.rv3d_mats = ED_view3d_mats_rv3d_backup(static_cast<RegionView3D *>(region->regiondata)); | ||||
| .rv3d_mats = ED_view3d_mats_rv3d_backup(region->regiondata), | |||||
| }; | |||||
| UI_Theme_Store(&orig.theme_state); | UI_Theme_Store(&orig.theme_state); | ||||
| UI_SetTheme(SPACE_VIEW3D, RGN_TYPE_WINDOW); | UI_SetTheme(SPACE_VIEW3D, RGN_TYPE_WINDOW); | ||||
| /* Set temporary new size. */ | /* Set temporary new size. */ | ||||
| region->winx = winx; | region->winx = winx; | ||||
| region->winy = winy; | region->winy = winy; | ||||
| region->winrct.xmin = 0; | region->winrct.xmin = 0; | ||||
| Show All 14 Lines | G.f |= G_FLAG_RENDER_VIEWPORT; | ||||
| BKE_image_free_anim_gputextures(G.main); | BKE_image_free_anim_gputextures(G.main); | ||||
| } | } | ||||
| GPU_matrix_push_projection(); | GPU_matrix_push_projection(); | ||||
| GPU_matrix_identity_set(); | GPU_matrix_identity_set(); | ||||
| GPU_matrix_push(); | GPU_matrix_push(); | ||||
| GPU_matrix_identity_set(); | GPU_matrix_identity_set(); | ||||
| if ((viewname != NULL && viewname[0] != '\0') && (viewmat == NULL) && | if ((viewname != nullptr && viewname[0] != '\0') && (viewmat == nullptr) && | ||||
| rv3d->persp == RV3D_CAMOB && v3d->camera) { | rv3d->persp == RV3D_CAMOB && v3d->camera) { | ||||
| view3d_stereo3d_setup_offscreen(depsgraph, scene, v3d, region, winmat, viewname); | view3d_stereo3d_setup_offscreen(depsgraph, scene, v3d, region, winmat, viewname); | ||||
| } | } | ||||
| else { | else { | ||||
| view3d_main_region_setup_offscreen(depsgraph, scene, v3d, region, viewmat, winmat); | view3d_main_region_setup_offscreen(depsgraph, scene, v3d, region, viewmat, winmat); | ||||
| } | } | ||||
| /* main drawing call */ | /* main drawing call */ | ||||
| Show All 12 Lines | void ED_view3d_draw_offscreen(Depsgraph *depsgraph, | ||||
| /* Restore all `orig` members. */ | /* Restore all `orig` members. */ | ||||
| region->winx = orig.region_winx; | region->winx = orig.region_winx; | ||||
| region->winy = orig.region_winy; | region->winy = orig.region_winy; | ||||
| region->winrct = orig.region_winrct; | region->winrct = orig.region_winrct; | ||||
| /* Optionally do _not_ restore rv3d matrices (e.g. they are used/stored in the ImBuff for | /* Optionally do _not_ restore rv3d matrices (e.g. they are used/stored in the ImBuff for | ||||
| * reprojection, see texture_paint_image_from_view_exec(). */ | * reprojection, see texture_paint_image_from_view_exec(). */ | ||||
| if (restore_rv3d_mats) { | if (restore_rv3d_mats) { | ||||
| ED_view3d_mats_rv3d_restore(region->regiondata, orig.rv3d_mats); | ED_view3d_mats_rv3d_restore(static_cast<RegionView3D *>(region->regiondata), orig.rv3d_mats); | ||||
| } | } | ||||
| MEM_freeN(orig.rv3d_mats); | MEM_freeN(orig.rv3d_mats); | ||||
| UI_Theme_Restore(&orig.theme_state); | UI_Theme_Restore(&orig.theme_state); | ||||
| v3d->shading.type = orig.v3d_shading_type; | v3d->shading.type = orig.v3d_shading_type; | ||||
| G.f &= ~G_FLAG_RENDER_VIEWPORT; | G.f &= ~G_FLAG_RENDER_VIEWPORT; | ||||
| Show All 15 Lines | void ED_view3d_draw_offscreen_simple(Depsgraph *depsgraph, | ||||
| bool is_xr_surface, | bool is_xr_surface, | ||||
| bool is_image_render, | bool is_image_render, | ||||
| bool draw_background, | bool draw_background, | ||||
| const char *viewname, | const char *viewname, | ||||
| const bool do_color_management, | const bool do_color_management, | ||||
| GPUOffScreen *ofs, | GPUOffScreen *ofs, | ||||
| GPUViewport *viewport) | GPUViewport *viewport) | ||||
| { | { | ||||
| View3D v3d = {NULL}; | View3D v3d = {nullptr}; | ||||
| ARegion ar = {NULL}; | ARegion ar = {nullptr}; | ||||
| RegionView3D rv3d = {{{0}}}; | RegionView3D rv3d = {{{0}}}; | ||||
| v3d.regionbase.first = v3d.regionbase.last = &ar; | v3d.regionbase.first = v3d.regionbase.last = &ar; | ||||
| ar.regiondata = &rv3d; | ar.regiondata = &rv3d; | ||||
| ar.regiontype = RGN_TYPE_WINDOW; | ar.regiontype = RGN_TYPE_WINDOW; | ||||
| View3DShading *source_shading_settings = &scene->display.shading; | View3DShading *source_shading_settings = &scene->display.shading; | ||||
| if (draw_flags & V3D_OFSDRAW_OVERRIDE_SCENE_SETTINGS && shading_override != NULL) { | if (draw_flags & V3D_OFSDRAW_OVERRIDE_SCENE_SETTINGS && shading_override != nullptr) { | ||||
| source_shading_settings = shading_override; | source_shading_settings = shading_override; | ||||
| } | } | ||||
| memcpy(&v3d.shading, source_shading_settings, sizeof(View3DShading)); | memcpy(&v3d.shading, source_shading_settings, sizeof(View3DShading)); | ||||
| v3d.shading.type = drawtype; | v3d.shading.type = drawtype; | ||||
| if (shading_override) { | if (shading_override) { | ||||
| /* Pass. */ | /* Pass. */ | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 76 Lines • ▼ Show 20 Lines | ImBuf *ED_view3d_draw_offscreen_imbuf(Depsgraph *depsgraph, | ||||
| eImBufFlags imbuf_flag, | eImBufFlags imbuf_flag, | ||||
| int alpha_mode, | int alpha_mode, | ||||
| const char *viewname, | const char *viewname, | ||||
| const bool restore_rv3d_mats, | const bool restore_rv3d_mats, | ||||
| /* output vars */ | /* output vars */ | ||||
| GPUOffScreen *ofs, | GPUOffScreen *ofs, | ||||
| char err_out[256]) | char err_out[256]) | ||||
| { | { | ||||
| RegionView3D *rv3d = region->regiondata; | RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata); | ||||
| const bool draw_sky = (alpha_mode == R_ADDSKY); | const bool draw_sky = (alpha_mode == R_ADDSKY); | ||||
| /* view state */ | /* view state */ | ||||
| bool is_ortho = false; | bool is_ortho = false; | ||||
| float winmat[4][4]; | float winmat[4][4]; | ||||
| if (ofs && ((GPU_offscreen_width(ofs) != sizex) || (GPU_offscreen_height(ofs) != sizey))) { | if (ofs && ((GPU_offscreen_width(ofs) != sizex) || (GPU_offscreen_height(ofs) != sizey))) { | ||||
| /* sizes differ, can't reuse */ | /* sizes differ, can't reuse */ | ||||
| ofs = NULL; | ofs = nullptr; | ||||
| } | } | ||||
| GPUFrameBuffer *old_fb = GPU_framebuffer_active_get(); | GPUFrameBuffer *old_fb = GPU_framebuffer_active_get(); | ||||
| if (old_fb) { | if (old_fb) { | ||||
| GPU_framebuffer_restore(); | GPU_framebuffer_restore(); | ||||
| } | } | ||||
| const bool own_ofs = (ofs == NULL); | const bool own_ofs = (ofs == nullptr); | ||||
| DRW_opengl_context_enable(); | DRW_opengl_context_enable(); | ||||
| if (own_ofs) { | if (own_ofs) { | ||||
| /* bind */ | /* bind */ | ||||
| ofs = GPU_offscreen_create(sizex, sizey, true, GPU_RGBA8, err_out); | ofs = GPU_offscreen_create(sizex, sizey, true, GPU_RGBA8, err_out); | ||||
| if (ofs == NULL) { | if (ofs == nullptr) { | ||||
| DRW_opengl_context_disable(); | DRW_opengl_context_disable(); | ||||
| return NULL; | return nullptr; | ||||
| } | } | ||||
| } | } | ||||
| GPU_offscreen_bind(ofs, true); | GPU_offscreen_bind(ofs, true); | ||||
| /* read in pixels & stamp */ | /* read in pixels & stamp */ | ||||
| ImBuf *ibuf = IMB_allocImBuf(sizex, sizey, 32, imbuf_flag); | ImBuf *ibuf = IMB_allocImBuf(sizex, sizey, 32, imbuf_flag); | ||||
| Show All 15 Lines | if (rv3d->persp == RV3D_CAMOB && v3d->camera) { | ||||
| is_ortho = params.is_ortho; | is_ortho = params.is_ortho; | ||||
| copy_m4_m4(winmat, params.winmat); | copy_m4_m4(winmat, params.winmat); | ||||
| } | } | ||||
| else { | else { | ||||
| rctf viewplane; | rctf viewplane; | ||||
| float clip_start, clipend; | float clip_start, clipend; | ||||
| is_ortho = ED_view3d_viewplane_get( | is_ortho = ED_view3d_viewplane_get( | ||||
| depsgraph, v3d, rv3d, sizex, sizey, &viewplane, &clip_start, &clipend, NULL); | depsgraph, v3d, rv3d, sizex, sizey, &viewplane, &clip_start, &clipend, nullptr); | ||||
| if (is_ortho) { | if (is_ortho) { | ||||
| orthographic_m4(winmat, | orthographic_m4(winmat, | ||||
| viewplane.xmin, | viewplane.xmin, | ||||
| viewplane.xmax, | viewplane.xmax, | ||||
| viewplane.ymin, | viewplane.ymin, | ||||
| viewplane.ymax, | viewplane.ymax, | ||||
| -clipend, | -clipend, | ||||
| clipend); | clipend); | ||||
| Show All 14 Lines | ImBuf *ED_view3d_draw_offscreen_imbuf(Depsgraph *depsgraph, | ||||
| * twice. Once here, and once when saving the saving to disk. In this case the Save As Render | * twice. Once here, and once when saving the saving to disk. In this case the Save As Render | ||||
| * option cannot be controlled either. But when doing an off-screen render you want to do the | * option cannot be controlled either. But when doing an off-screen render you want to do the | ||||
| * color management here. | * color management here. | ||||
| * | * | ||||
| * This option was added here to increase the performance for quick view-port preview renders. | * This option was added here to increase the performance for quick view-port preview renders. | ||||
| * When using workbench the color differences haven't been reported as a bug. But users also use | * When using workbench the color differences haven't been reported as a bug. But users also use | ||||
| * the viewport rendering to render Eevee scenes. In the later situation the saved colors are | * the viewport rendering to render Eevee scenes. In the later situation the saved colors are | ||||
| * totally wrong. */ | * totally wrong. */ | ||||
| const bool do_color_management = (ibuf->rect_float == NULL); | const bool do_color_management = (ibuf->rect_float == nullptr); | ||||
| ED_view3d_draw_offscreen(depsgraph, | ED_view3d_draw_offscreen(depsgraph, | ||||
| scene, | scene, | ||||
| drawtype, | drawtype, | ||||
| v3d, | v3d, | ||||
| region, | region, | ||||
| sizex, | sizex, | ||||
| sizey, | sizey, | ||||
| NULL, | nullptr, | ||||
| winmat, | winmat, | ||||
| true, | true, | ||||
| draw_sky, | draw_sky, | ||||
| viewname, | viewname, | ||||
| do_color_management, | do_color_management, | ||||
| restore_rv3d_mats, | restore_rv3d_mats, | ||||
| ofs, | ofs, | ||||
| NULL); | nullptr); | ||||
| if (ibuf->rect_float) { | if (ibuf->rect_float) { | ||||
| GPU_offscreen_read_pixels(ofs, GPU_DATA_FLOAT, ibuf->rect_float); | GPU_offscreen_read_pixels(ofs, GPU_DATA_FLOAT, ibuf->rect_float); | ||||
| } | } | ||||
| else if (ibuf->rect) { | else if (ibuf->rect) { | ||||
| GPU_offscreen_read_pixels(ofs, GPU_DATA_UBYTE, ibuf->rect); | GPU_offscreen_read_pixels(ofs, GPU_DATA_UBYTE, ibuf->rect); | ||||
| } | } | ||||
| Show All 26 Lines | ImBuf *ED_view3d_draw_offscreen_imbuf_simple(Depsgraph *depsgraph, | ||||
| int height, | int height, | ||||
| eImBufFlags imbuf_flag, | eImBufFlags imbuf_flag, | ||||
| eV3DOffscreenDrawFlag draw_flags, | eV3DOffscreenDrawFlag draw_flags, | ||||
| int alpha_mode, | int alpha_mode, | ||||
| const char *viewname, | const char *viewname, | ||||
| GPUOffScreen *ofs, | GPUOffScreen *ofs, | ||||
| char err_out[256]) | char err_out[256]) | ||||
| { | { | ||||
| View3D v3d = {NULL}; | View3D v3d = {nullptr}; | ||||
| ARegion region = {NULL}; | ARegion region = {nullptr}; | ||||
| RegionView3D rv3d = {{{0}}}; | RegionView3D rv3d = {{{0}}}; | ||||
| /* connect data */ | /* connect data */ | ||||
| v3d.regionbase.first = v3d.regionbase.last = ®ion; | v3d.regionbase.first = v3d.regionbase.last = ®ion; | ||||
| region.regiondata = &rv3d; | region.regiondata = &rv3d; | ||||
| region.regiontype = RGN_TYPE_WINDOW; | region.regiontype = RGN_TYPE_WINDOW; | ||||
| v3d.camera = camera; | v3d.camera = camera; | ||||
| View3DShading *source_shading_settings = &scene->display.shading; | View3DShading *source_shading_settings = &scene->display.shading; | ||||
| if (draw_flags & V3D_OFSDRAW_OVERRIDE_SCENE_SETTINGS && shading_override != NULL) { | if (draw_flags & V3D_OFSDRAW_OVERRIDE_SCENE_SETTINGS && shading_override != nullptr) { | ||||
| source_shading_settings = shading_override; | source_shading_settings = shading_override; | ||||
| } | } | ||||
| memcpy(&v3d.shading, source_shading_settings, sizeof(View3DShading)); | memcpy(&v3d.shading, source_shading_settings, sizeof(View3DShading)); | ||||
| if (drawtype == OB_RENDER) { | if (drawtype == OB_RENDER) { | ||||
| /* Don't use external engines for preview. Fall back to solid instead of Eevee as rendering | /* Don't use external engines for preview. Fall back to solid instead of Eevee as rendering | ||||
| * with Eevee is potentially slow due to compiling shaders and loading textures, and the | * with Eevee is potentially slow due to compiling shaders and loading textures, and the | ||||
| * depsgraph may not have been updated to have all the right geometry attributes. */ | * depsgraph may not have been updated to have all the right geometry attributes. */ | ||||
| ▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | invert_m4_m4(rv3d.viewmat, rv3d.viewinv); | ||||
| v3d.lens = params.lens; | v3d.lens = params.lens; | ||||
| } | } | ||||
| mul_m4_m4m4(rv3d.persmat, rv3d.winmat, rv3d.viewmat); | mul_m4_m4m4(rv3d.persmat, rv3d.winmat, rv3d.viewmat); | ||||
| invert_m4_m4(rv3d.persinv, rv3d.viewinv); | invert_m4_m4(rv3d.persinv, rv3d.viewinv); | ||||
| return ED_view3d_draw_offscreen_imbuf(depsgraph, | return ED_view3d_draw_offscreen_imbuf(depsgraph, | ||||
| scene, | scene, | ||||
| v3d.shading.type, | eDrawType(v3d.shading.type), | ||||
| &v3d, | &v3d, | ||||
| ®ion, | ®ion, | ||||
| width, | width, | ||||
| height, | height, | ||||
| imbuf_flag, | imbuf_flag, | ||||
| alpha_mode, | alpha_mode, | ||||
| viewname, | viewname, | ||||
| true, | true, | ||||
| ▲ Show 20 Lines • Show All 79 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| /* TODO: Creating, attaching texture, and destroying a framebuffer is quite slow. | /* TODO: Creating, attaching texture, and destroying a framebuffer is quite slow. | ||||
| * Calling this function should be avoided during interactive drawing. */ | * Calling this function should be avoided during interactive drawing. */ | ||||
| static void view3d_opengl_read_Z_pixels(GPUViewport *viewport, rcti *rect, void *data) | static void view3d_opengl_read_Z_pixels(GPUViewport *viewport, rcti *rect, void *data) | ||||
| { | { | ||||
| GPUTexture *depth_tx = GPU_viewport_depth_texture(viewport); | GPUTexture *depth_tx = GPU_viewport_depth_texture(viewport); | ||||
| GPUFrameBuffer *depth_read_fb = NULL; | GPUFrameBuffer *depth_read_fb = nullptr; | ||||
| GPU_framebuffer_ensure_config(&depth_read_fb, | GPU_framebuffer_ensure_config(&depth_read_fb, | ||||
| { | { | ||||
| GPU_ATTACHMENT_TEXTURE(depth_tx), | GPU_ATTACHMENT_TEXTURE(depth_tx), | ||||
| GPU_ATTACHMENT_NONE, | GPU_ATTACHMENT_NONE, | ||||
| }); | }); | ||||
| GPU_framebuffer_bind(depth_read_fb); | GPU_framebuffer_bind(depth_read_fb); | ||||
| GPU_framebuffer_read_depth(depth_read_fb, | GPU_framebuffer_read_depth(depth_read_fb, | ||||
| Show All 11 Lines | |||||
| void ED_view3d_select_id_validate(ViewContext *vc) | void ED_view3d_select_id_validate(ViewContext *vc) | ||||
| { | { | ||||
| validate_object_select_id( | validate_object_select_id( | ||||
| vc->depsgraph, vc->scene, vc->view_layer, vc->region, vc->v3d, vc->obact); | vc->depsgraph, vc->scene, vc->view_layer, vc->region, vc->v3d, vc->obact); | ||||
| } | } | ||||
| int ED_view3d_backbuf_sample_size_clamp(ARegion *region, const float dist) | int ED_view3d_backbuf_sample_size_clamp(ARegion *region, const float dist) | ||||
| { | { | ||||
| return (int)min_ff(ceilf(dist), (float)max_ii(region->winx, region->winx)); | return int(min_ff(ceilf(dist), float(max_ii(region->winx, region->winx)))); | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Z-Depth Utilities | /** \name Z-Depth Utilities | ||||
| * \{ */ | * \{ */ | ||||
| void view3d_depths_rect_create(ARegion *region, rcti *rect, ViewDepths *r_d) | void view3d_depths_rect_create(ARegion *region, rcti *rect, ViewDepths *r_d) | ||||
| { | { | ||||
| /* clamp rect by region */ | /* clamp rect by region */ | ||||
| rcti r = { | rcti r{}; | ||||
| .xmin = 0, | r.xmin = 0; | ||||
| .xmax = region->winx - 1, | r.xmax = region->winx - 1; | ||||
| .ymin = 0, | r.ymin = 0; | ||||
| .ymax = region->winy - 1, | r.ymax = region->winy - 1; | ||||
| }; | |||||
| /* Constrain rect to depth bounds */ | /* Constrain rect to depth bounds */ | ||||
| BLI_rcti_isect(&r, rect, rect); | BLI_rcti_isect(&r, rect, rect); | ||||
| /* assign values to compare with the ViewDepths */ | /* assign values to compare with the ViewDepths */ | ||||
| int x = rect->xmin; | int x = rect->xmin; | ||||
| int y = rect->ymin; | int y = rect->ymin; | ||||
| int w = BLI_rcti_size_x(rect); | int w = BLI_rcti_size_x(rect); | ||||
| int h = BLI_rcti_size_y(rect); | int h = BLI_rcti_size_y(rect); | ||||
| if (w <= 0 || h <= 0) { | if (w <= 0 || h <= 0) { | ||||
| r_d->depths = NULL; | r_d->depths = nullptr; | ||||
| return; | return; | ||||
| } | } | ||||
| r_d->x = x; | r_d->x = x; | ||||
| r_d->y = y; | r_d->y = y; | ||||
| r_d->w = w; | r_d->w = w; | ||||
| r_d->h = h; | r_d->h = h; | ||||
| r_d->depths = MEM_mallocN(sizeof(float) * w * h, "View depths Subset"); | r_d->depths = static_cast<float *>(MEM_mallocN(sizeof(float) * w * h, "View depths Subset")); | ||||
| { | { | ||||
| GPUViewport *viewport = WM_draw_region_get_viewport(region); | GPUViewport *viewport = WM_draw_region_get_viewport(region); | ||||
| view3d_opengl_read_Z_pixels(viewport, rect, r_d->depths); | view3d_opengl_read_Z_pixels(viewport, rect, r_d->depths); | ||||
| /* Range is assumed to be this as they are never changed. */ | /* Range is assumed to be this as they are never changed. */ | ||||
| r_d->depth_range[0] = 0.0; | r_d->depth_range[0] = 0.0; | ||||
| r_d->depth_range[1] = 1.0; | r_d->depth_range[1] = 1.0; | ||||
| } | } | ||||
| } | } | ||||
| /* NOTE: with nouveau drivers the glReadPixels() is very slow. T24339. */ | /* NOTE: with NOUVEAU drivers the #glReadPixels() is very slow. T24339. */ | ||||
| static ViewDepths *view3d_depths_create(ARegion *region) | static ViewDepths *view3d_depths_create(ARegion *region) | ||||
| { | { | ||||
| ViewDepths *d = MEM_callocN(sizeof(ViewDepths), "ViewDepths"); | ViewDepths *d = MEM_cnew<ViewDepths>("ViewDepths"); | ||||
| { | { | ||||
| GPUViewport *viewport = WM_draw_region_get_viewport(region); | GPUViewport *viewport = WM_draw_region_get_viewport(region); | ||||
| GPUTexture *depth_tx = GPU_viewport_depth_texture(viewport); | GPUTexture *depth_tx = GPU_viewport_depth_texture(viewport); | ||||
| uint32_t *int_depths = GPU_texture_read(depth_tx, GPU_DATA_UINT_24_8, 0); | uint32_t *int_depths = static_cast<uint32_t *>( | ||||
| GPU_texture_read(depth_tx, GPU_DATA_UINT_24_8, 0)); | |||||
| d->w = GPU_texture_width(depth_tx); | d->w = GPU_texture_width(depth_tx); | ||||
| d->h = GPU_texture_height(depth_tx); | d->h = GPU_texture_height(depth_tx); | ||||
| d->depths = (float *)int_depths; | d->depths = (float *)int_depths; | ||||
| /* Convert in-place. */ | /* Convert in-place. */ | ||||
| int pixel_count = d->w * d->h; | int pixel_count = d->w * d->h; | ||||
| for (int i = 0; i < pixel_count; i++) { | for (int i = 0; i < pixel_count; i++) { | ||||
| d->depths[i] = (int_depths[i] >> 8u) / (float)0xFFFFFF; | d->depths[i] = (int_depths[i] >> 8u) / float(0xFFFFFF); | ||||
| } | } | ||||
| /* Assumed to be this as they are never changed. */ | /* Assumed to be this as they are never changed. */ | ||||
| d->depth_range[0] = 0.0; | d->depth_range[0] = 0.0; | ||||
| d->depth_range[1] = 1.0; | d->depth_range[1] = 1.0; | ||||
| } | } | ||||
| return d; | return d; | ||||
| } | } | ||||
| float view3d_depth_near(ViewDepths *d) | float view3d_depth_near(ViewDepths *d) | ||||
| { | { | ||||
| /* Convert to float for comparisons. */ | /* Convert to float for comparisons. */ | ||||
| const float near = (float)d->depth_range[0]; | const float near = float(d->depth_range[0]); | ||||
| const float far_real = (float)d->depth_range[1]; | const float far_real = float(d->depth_range[1]); | ||||
| float far = far_real; | float far = far_real; | ||||
| const float *depths = d->depths; | const float *depths = d->depths; | ||||
| float depth = FLT_MAX; | float depth = FLT_MAX; | ||||
| int i = (int)d->w * (int)d->h; /* Cast to avoid short overflow. */ | int i = int(d->w) * int(d->h); /* Cast to avoid short overflow. */ | ||||
| /* Far is both the starting 'far' value | /* Far is both the starting 'far' value | ||||
| * and the closest value found. */ | * and the closest value found. */ | ||||
| while (i--) { | while (i--) { | ||||
| depth = *depths++; | depth = *depths++; | ||||
| if ((depth < far) && (depth > near)) { | if ((depth < far) && (depth > near)) { | ||||
| far = depth; | far = depth; | ||||
| } | } | ||||
| } | } | ||||
| return far == far_real ? FLT_MAX : far; | return far == far_real ? FLT_MAX : far; | ||||
| } | } | ||||
| void ED_view3d_depth_override(Depsgraph *depsgraph, | void ED_view3d_depth_override(Depsgraph *depsgraph, | ||||
| ARegion *region, | ARegion *region, | ||||
| View3D *v3d, | View3D *v3d, | ||||
| Object *obact, | Object *obact, | ||||
| eV3DDepthOverrideMode mode, | eV3DDepthOverrideMode mode, | ||||
| ViewDepths **r_depths) | ViewDepths **r_depths) | ||||
| { | { | ||||
| if (v3d->runtime.flag & V3D_RUNTIME_DEPTHBUF_OVERRIDDEN) { | if (v3d->runtime.flag & V3D_RUNTIME_DEPTHBUF_OVERRIDDEN) { | ||||
| /* Force redraw if `r_depths` is required. */ | /* Force redraw if `r_depths` is required. */ | ||||
| if (!r_depths || *r_depths != NULL) { | if (!r_depths || *r_depths != nullptr) { | ||||
| return; | return; | ||||
| } | } | ||||
| } | } | ||||
| struct bThemeState theme_state; | struct bThemeState theme_state; | ||||
| Scene *scene = DEG_get_evaluated_scene(depsgraph); | Scene *scene = DEG_get_evaluated_scene(depsgraph); | ||||
| RegionView3D *rv3d = region->regiondata; | RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata); | ||||
| short flag = v3d->flag; | short flag = v3d->flag; | ||||
| /* temp set drawtype to solid */ | /* temp set drawtype to solid */ | ||||
| /* Setting these temporarily is not nice */ | /* Setting these temporarily is not nice */ | ||||
| v3d->flag &= ~V3D_SELECT_OUTLINE; | v3d->flag &= ~V3D_SELECT_OUTLINE; | ||||
| /* Tools may request depth outside of regular drawing code. */ | /* Tools may request depth outside of regular drawing code. */ | ||||
| UI_Theme_Store(&theme_state); | UI_Theme_Store(&theme_state); | ||||
| UI_SetTheme(SPACE_VIEW3D, RGN_TYPE_WINDOW); | UI_SetTheme(SPACE_VIEW3D, RGN_TYPE_WINDOW); | ||||
| ED_view3d_draw_setup_view( | ED_view3d_draw_setup_view(static_cast<wmWindowManager *>(G_MAIN->wm.first), | ||||
| G_MAIN->wm.first, NULL, depsgraph, scene, region, v3d, NULL, NULL, NULL); | nullptr, | ||||
| depsgraph, | |||||
| scene, | |||||
| region, | |||||
| v3d, | |||||
| nullptr, | |||||
| nullptr, | |||||
| nullptr); | |||||
| /* get surface depth without bias */ | /* get surface depth without bias */ | ||||
| rv3d->rflag |= RV3D_ZOFFSET_DISABLED; | rv3d->rflag |= RV3D_ZOFFSET_DISABLED; | ||||
| /* Needed in cases the 3D Viewport isn't already setup. */ | /* Needed in cases the 3D Viewport isn't already setup. */ | ||||
| WM_draw_region_viewport_ensure(region, SPACE_VIEW3D); | WM_draw_region_viewport_ensure(region, SPACE_VIEW3D); | ||||
| WM_draw_region_viewport_bind(region); | WM_draw_region_viewport_bind(region); | ||||
| GPUViewport *viewport = WM_draw_region_get_viewport(region); | GPUViewport *viewport = WM_draw_region_get_viewport(region); | ||||
| /* When Blender is starting, a click event can trigger a depth test while the viewport is not | /* When Blender is starting, a click event can trigger a depth test while the viewport is not | ||||
| * yet available. */ | * yet available. */ | ||||
| if (viewport != NULL) { | if (viewport != nullptr) { | ||||
| switch (mode) { | switch (mode) { | ||||
| case V3D_DEPTH_NO_GPENCIL: | case V3D_DEPTH_NO_GPENCIL: | ||||
| DRW_draw_depth_loop(depsgraph, region, v3d, viewport); | DRW_draw_depth_loop(depsgraph, region, v3d, viewport); | ||||
| break; | break; | ||||
| case V3D_DEPTH_GPENCIL_ONLY: | case V3D_DEPTH_GPENCIL_ONLY: | ||||
| DRW_draw_depth_loop_gpencil(depsgraph, region, v3d, viewport); | DRW_draw_depth_loop_gpencil(depsgraph, region, v3d, viewport); | ||||
| break; | break; | ||||
| case V3D_DEPTH_OBJECT_ONLY: | case V3D_DEPTH_OBJECT_ONLY: | ||||
| ▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | void ED_view3d_screen_datamask(const bContext *C, | ||||
| const bScreen *screen, | const bScreen *screen, | ||||
| CustomData_MeshMasks *r_cddata_masks) | CustomData_MeshMasks *r_cddata_masks) | ||||
| { | { | ||||
| CustomData_MeshMasks_update(r_cddata_masks, &CD_MASK_BAREMESH); | CustomData_MeshMasks_update(r_cddata_masks, &CD_MASK_BAREMESH); | ||||
| /* Check if we need tfaces & mcols due to view mode. */ | /* Check if we need tfaces & mcols due to view mode. */ | ||||
| LISTBASE_FOREACH (const ScrArea *, area, &screen->areabase) { | LISTBASE_FOREACH (const ScrArea *, area, &screen->areabase) { | ||||
| if (area->spacetype == SPACE_VIEW3D) { | if (area->spacetype == SPACE_VIEW3D) { | ||||
| ED_view3d_datamask(C, scene, area->spacedata.first, r_cddata_masks); | ED_view3d_datamask(C, scene, static_cast<View3D *>(area->spacedata.first), r_cddata_masks); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Region View Matrix Backup/Restore | /** \name Region View Matrix Backup/Restore | ||||
| Show All 13 Lines | struct RV3DMatrixStore { | ||||
| float persmat[4][4]; | float persmat[4][4]; | ||||
| float persinv[4][4]; | float persinv[4][4]; | ||||
| float viewcamtexcofac[4]; | float viewcamtexcofac[4]; | ||||
| float pixsize; | float pixsize; | ||||
| }; | }; | ||||
| struct RV3DMatrixStore *ED_view3d_mats_rv3d_backup(struct RegionView3D *rv3d) | struct RV3DMatrixStore *ED_view3d_mats_rv3d_backup(struct RegionView3D *rv3d) | ||||
| { | { | ||||
| struct RV3DMatrixStore *rv3dmat = MEM_mallocN(sizeof(*rv3dmat), __func__); | struct RV3DMatrixStore *rv3dmat = static_cast<RV3DMatrixStore *>( | ||||
| MEM_mallocN(sizeof(*rv3dmat), __func__)); | |||||
| copy_m4_m4(rv3dmat->winmat, rv3d->winmat); | copy_m4_m4(rv3dmat->winmat, rv3d->winmat); | ||||
| copy_m4_m4(rv3dmat->viewmat, rv3d->viewmat); | copy_m4_m4(rv3dmat->viewmat, rv3d->viewmat); | ||||
| copy_m4_m4(rv3dmat->persmat, rv3d->persmat); | copy_m4_m4(rv3dmat->persmat, rv3d->persmat); | ||||
| copy_m4_m4(rv3dmat->persinv, rv3d->persinv); | copy_m4_m4(rv3dmat->persinv, rv3d->persinv); | ||||
| copy_m4_m4(rv3dmat->viewinv, rv3d->viewinv); | copy_m4_m4(rv3dmat->viewinv, rv3d->viewinv); | ||||
| copy_v4_v4(rv3dmat->viewcamtexcofac, rv3d->viewcamtexcofac); | copy_v4_v4(rv3dmat->viewcamtexcofac, rv3d->viewcamtexcofac); | ||||
| rv3dmat->pixsize = rv3d->pixsize; | rv3dmat->pixsize = rv3d->pixsize; | ||||
| return rv3dmat; | return rv3dmat; | ||||
| Show All 14 Lines | |||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name FPS Drawing | /** \name FPS Drawing | ||||
| * \{ */ | * \{ */ | ||||
| void ED_scene_draw_fps(const Scene *scene, int xoffset, int *yoffset) | void ED_scene_draw_fps(const Scene *scene, int xoffset, int *yoffset) | ||||
| { | { | ||||
| ScreenFrameRateInfo *fpsi = scene->fps_info; | ScreenFrameRateInfo *fpsi = static_cast<ScreenFrameRateInfo *>(scene->fps_info); | ||||
| char printable[16]; | char printable[16]; | ||||
| if (!fpsi || !fpsi->lredrawtime || !fpsi->redrawtime) { | if (!fpsi || !fpsi->lredrawtime || !fpsi->redrawtime) { | ||||
| return; | return; | ||||
| } | } | ||||
| printable[0] = '\0'; | printable[0] = '\0'; | ||||
| /* Doing an average for a more robust calculation. */ | /* Doing an average for a more robust calculation. */ | ||||
| fpsi->redrawtimes_fps[fpsi->redrawtime_index] = (float)(1.0 / | fpsi->redrawtimes_fps[fpsi->redrawtime_index] = float(1.0 / | ||||
| (fpsi->lredrawtime - fpsi->redrawtime)); | (fpsi->lredrawtime - fpsi->redrawtime)); | ||||
| float fps = 0.0f; | float fps = 0.0f; | ||||
| int tot = 0; | int tot = 0; | ||||
| for (int i = 0; i < REDRAW_FRAME_AVERAGE; i++) { | for (int i = 0; i < REDRAW_FRAME_AVERAGE; i++) { | ||||
| if (fpsi->redrawtimes_fps[i]) { | if (fpsi->redrawtimes_fps[i]) { | ||||
| fps += fpsi->redrawtimes_fps[i]; | fps += fpsi->redrawtimes_fps[i]; | ||||
| tot++; | tot++; | ||||
| } | } | ||||
| } | } | ||||
| if (tot) { | if (tot) { | ||||
| fpsi->redrawtime_index = (fpsi->redrawtime_index + 1) % REDRAW_FRAME_AVERAGE; | fpsi->redrawtime_index = (fpsi->redrawtime_index + 1) % REDRAW_FRAME_AVERAGE; | ||||
| fps = fps / tot; | fps = fps / tot; | ||||
| } | } | ||||
| const int font_id = BLF_default(); | const int font_id = BLF_default(); | ||||
| /* Is this more than half a frame behind? */ | /* Is this more than half a frame behind? */ | ||||
| if (fps + 0.5f < (float)(FPS)) { | if (fps + 0.5f < float(FPS)) { | ||||
| UI_FontThemeColor(font_id, TH_REDALERT); | UI_FontThemeColor(font_id, TH_REDALERT); | ||||
| BLI_snprintf(printable, sizeof(printable), IFACE_("fps: %.2f"), fps); | BLI_snprintf(printable, sizeof(printable), IFACE_("fps: %.2f"), fps); | ||||
| } | } | ||||
| else { | else { | ||||
| UI_FontThemeColor(font_id, TH_TEXT_HI); | UI_FontThemeColor(font_id, TH_TEXT_HI); | ||||
| BLI_snprintf(printable, sizeof(printable), IFACE_("fps: %i"), (int)(fps + 0.5f)); | BLI_snprintf(printable, sizeof(printable), IFACE_("fps: %i"), int(fps + 0.5f)); | ||||
| } | } | ||||
| BLF_enable(font_id, BLF_SHADOW); | BLF_enable(font_id, BLF_SHADOW); | ||||
| BLF_shadow(font_id, 5, (const float[4]){0.0f, 0.0f, 0.0f, 1.0f}); | BLF_shadow(font_id, 5, float4{0.0f, 0.0f, 0.0f, 1.0f}); | ||||
| BLF_shadow_offset(font_id, 1, -1); | BLF_shadow_offset(font_id, 1, -1); | ||||
| *yoffset -= VIEW3D_OVERLAY_LINEHEIGHT; | *yoffset -= VIEW3D_OVERLAY_LINEHEIGHT; | ||||
| BLF_draw_default(xoffset, *yoffset, 0.0f, printable, sizeof(printable)); | BLF_draw_default(xoffset, *yoffset, 0.0f, printable, sizeof(printable)); | ||||
| BLF_disable(font_id, BLF_SHADOW); | BLF_disable(font_id, BLF_SHADOW); | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Calculate Render Border | /** \name Calculate Render Border | ||||
| * \{ */ | * \{ */ | ||||
| static bool view3d_main_region_do_render_draw(const Scene *scene) | static bool view3d_main_region_do_render_draw(const Scene *scene) | ||||
| { | { | ||||
| RenderEngineType *type = RE_engines_find(scene->r.engine); | RenderEngineType *type = RE_engines_find(scene->r.engine); | ||||
| return (type && type->view_update && type->view_draw); | return (type && type->view_update && type->view_draw); | ||||
| } | } | ||||
| bool ED_view3d_calc_render_border( | bool ED_view3d_calc_render_border( | ||||
| const Scene *scene, Depsgraph *depsgraph, View3D *v3d, ARegion *region, rcti *rect) | const Scene *scene, Depsgraph *depsgraph, View3D *v3d, ARegion *region, rcti *rect) | ||||
| { | { | ||||
| RegionView3D *rv3d = region->regiondata; | RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata); | ||||
| bool use_border; | bool use_border; | ||||
| /* Test if there is a 3d view rendering. */ | /* Test if there is a 3d view rendering. */ | ||||
| if (v3d->shading.type != OB_RENDER || !view3d_main_region_do_render_draw(scene)) { | if (v3d->shading.type != OB_RENDER || !view3d_main_region_do_render_draw(scene)) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| /* Test if there is a border render. */ | /* Test if there is a border render. */ | ||||
| Show All 35 Lines | |||||