Blender V5.3
view3d_draw.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2008 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <cmath>
10#include <fmt/format.h>
11
12#include "BLI_listbase.hh"
13#include "BLI_math_color_c.hh"
14#include "BLI_math_geom_c.hh"
15#include "BLI_math_half.hh"
16#include "BLI_math_matrix_c.hh"
18#include "BLI_rect.hh"
19#include "BLI_string_utf8.hh"
20#include "BLI_string_utils.hh"
21#include "BLI_threads.hh"
22#include "BLI_time.hh"
23
24#include "BKE_armature.hh"
25#include "BKE_camera.h"
26#include "BKE_collection.hh"
27#include "BKE_context.hh"
28#include "BKE_customdata.hh"
29#include "BKE_global.hh"
30#include "BKE_grease_pencil.hh"
31#include "BKE_image.hh"
32#include "BKE_image_gpu.hh"
33#include "BKE_key.hh"
34#include "BKE_layer.hh"
35#include "BKE_main.hh"
36#include "BKE_object.hh"
37#include "BKE_paint.hh"
38#include "BKE_scene.hh"
39#include "BKE_screen.hh"
40#include "BKE_unit.hh"
41#include "BKE_viewer_path.hh"
42
43#include "BLF_api.hh"
44
45#include "BLT_translation.hh"
46
47#include "DNA_armature_types.h"
48#include "DNA_camera_types.h"
49#include "DNA_key_types.h"
50#include "DNA_object_types.h"
51#include "DNA_view3d_types.h"
53
54#include "DRW_engine.hh"
55#include "DRW_select_buffer.hh"
56
57#include "ED_gpencil_legacy.hh"
58#include "ED_info.hh"
59#include "ED_scene.hh"
60#include "ED_screen.hh"
61#include "ED_util.hh"
63#include "ED_viewer_path.hh"
64
66
69
70#include "GPU_framebuffer.hh"
71#include "GPU_immediate.hh"
72#include "GPU_immediate_util.hh"
73#include "GPU_matrix.hh"
74#include "GPU_state.hh"
75#include "GPU_viewport.hh"
76
77#include "MEM_guardedalloc.h"
78
79#include "UI_interface.hh"
80#include "UI_resources.hh"
81
82#include "RE_engine.h"
83
84#include "WM_api.hh"
85#include "WM_types.hh"
86
87#include "IMB_imbuf.hh"
88#include "IMB_imbuf_types.hh"
89
90#include "ANIM_keyframing.hh"
91
92#include "view3d_intern.hh" /* own include */
93
94namespace blender {
95
96#define VIEW3D_OVERLAY_LINEHEIGHT (ui::style_get()->widget.points * UI_SCALE_FAC * 1.6f)
97
98/* -------------------------------------------------------------------- */
101
102void ED_view3d_update_viewmat(const Depsgraph *depsgraph,
103 const Scene *scene,
104 View3D *v3d,
105 ARegion *region,
106 const float viewmat[4][4],
107 const float winmat[4][4],
108 const rcti *rect,
109 bool offscreen)
110{
111 RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata);
112
113 /* setup window matrices */
114 if (winmat) {
115 copy_m4_m4(rv3d->winmat, winmat);
116 }
117 else {
118 view3d_winmatrix_set(depsgraph, region, v3d, rect);
119 }
120
121 /* setup view matrix */
122 if (viewmat) {
123 copy_m4_m4(rv3d->viewmat, viewmat);
124 }
125 else {
126 float rect_scale[2];
127 if (rect) {
128 rect_scale[0] = float(BLI_rcti_size_x(rect)) / float(region->winx);
129 rect_scale[1] = float(BLI_rcti_size_y(rect)) / float(region->winy);
130 }
131 /* NOTE: calls BKE_object_where_is_calc for camera... */
132 view3d_viewmatrix_set(depsgraph, scene, v3d, rv3d, rect ? rect_scale : nullptr);
133 }
134 /* update utility matrices */
135 mul_m4_m4m4(rv3d->persmat, rv3d->winmat, rv3d->viewmat);
136 invert_m4_m4(rv3d->persinv, rv3d->persmat);
137 invert_m4_m4(rv3d->viewinv, rv3d->viewmat);
138
139 /* calculate GLSL view dependent values */
140
141 /* store window coordinates scaling/offset */
142 if (!offscreen && rv3d->persp == RV3D_CAMOB && v3d->camera) {
143 rctf cameraborder;
144 cameraborder = BKE_camera_view_border(
145 scene, depsgraph, v3d, rv3d, region->winx, region->winy, false, false, false);
146 rv3d->viewcamtexcofac[0] = float(region->winx) / BLI_rctf_size_x(&cameraborder);
147 rv3d->viewcamtexcofac[1] = float(region->winy) / BLI_rctf_size_y(&cameraborder);
148
149 rv3d->viewcamtexcofac[2] = -rv3d->viewcamtexcofac[0] * cameraborder.xmin / float(region->winx);
150 rv3d->viewcamtexcofac[3] = -rv3d->viewcamtexcofac[1] * cameraborder.ymin / float(region->winy);
151 }
152 else {
153 rv3d->viewcamtexcofac[0] = rv3d->viewcamtexcofac[1] = 1.0f;
154 rv3d->viewcamtexcofac[2] = rv3d->viewcamtexcofac[3] = 0.0f;
155 }
156
157 /* Calculate pixel-size factor once, this is used for lights and object-centers. */
158 {
159 /* NOTE: '1.0f / len_v3(v1)' replaced 'len_v3(rv3d->viewmat[0])'
160 * because of float point precision problems at large values #23908. */
161 float v1[3], v2[3];
162 float len_px, len_sc;
163
164 v1[0] = rv3d->persmat[0][0];
165 v1[1] = rv3d->persmat[1][0];
166 v1[2] = rv3d->persmat[2][0];
167
168 v2[0] = rv3d->persmat[0][1];
169 v2[1] = rv3d->persmat[1][1];
170 v2[2] = rv3d->persmat[2][1];
171
172 len_px = 2.0f / sqrtf(min_ff(len_squared_v3(v1), len_squared_v3(v2)));
173
174 if (rect) {
175 len_sc = float(max_ii(BLI_rcti_size_x(rect), BLI_rcti_size_y(rect)));
176 }
177 else {
178 len_sc = float(std::max(region->winx, region->winy));
179 }
180
181 rv3d->pixsize = len_px / len_sc;
182 }
183}
184
185static void view3d_main_region_setup_view(Depsgraph *depsgraph,
186 Scene *scene,
187 View3D *v3d,
188 ARegion *region,
189 const float viewmat[4][4],
190 const float winmat[4][4],
191 const rcti *rect)
192{
193 RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata);
194
195 ED_view3d_update_viewmat(depsgraph, scene, v3d, region, viewmat, winmat, rect, false);
196
197 /* Set for GPU drawing. */
199 GPU_matrix_set(rv3d->viewmat);
200}
201
202static void view3d_main_region_setup_offscreen(Depsgraph *depsgraph,
203 const Scene *scene,
204 View3D *v3d,
205 ARegion *region,
206 const float viewmat[4][4],
207 const float winmat[4][4])
208{
209 RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata);
210 ED_view3d_update_viewmat(depsgraph, scene, v3d, region, viewmat, winmat, nullptr, true);
211
212 /* Set for GPU drawing. */
214 GPU_matrix_set(rv3d->viewmat);
215}
216
218 const Scene *scene,
219 View3D *v3d,
220 RegionView3D *rv3d)
221{
222 if ((scene->r.scemode & R_MULTIVIEW) == 0) {
223 return false;
224 }
225
226 if ((v3d->camera == nullptr) || (v3d->camera->type != OB_CAMERA) || rv3d->persp != RV3D_CAMOB) {
227 return false;
228 }
229
230 switch (v3d->stereo3d_camera) {
231 case STEREO_MONO_ID:
232 return false;
233 break;
234 case STEREO_3D_ID:
235 /* win will be nullptr when calling this from the selection or draw loop. */
236 if ((win == nullptr) || (WM_stereo3d_enabled(win, true) == false)) {
237 return false;
238 }
239 if (((scene->r.views_format & SCE_VIEWS_FORMAT_MULTIVIEW) != 0) &&
241 {
242 return false;
243 }
244 break;
245 /* We always need the stereo calculation for left and right cameras. */
246 case STEREO_LEFT_ID:
247 case STEREO_RIGHT_ID:
248 default:
249 break;
250 }
251 return true;
252}
253
264 Depsgraph *depsgraph, Scene *scene, View3D *v3d, ARegion *region, const rcti *rect)
265{
266 bool is_left;
267 const char *names[2] = {STEREO_LEFT_NAME, STEREO_RIGHT_NAME};
268 const char *viewname;
269
270 /* show only left or right camera */
271 if (v3d->stereo3d_camera != STEREO_3D_ID) {
272 v3d->multiview_eye = v3d->stereo3d_camera;
273 }
274
275 is_left = v3d->multiview_eye == STEREO_LEFT_ID;
276 viewname = names[is_left ? STEREO_LEFT_ID : STEREO_RIGHT_ID];
277
278 /* update the viewport matrices with the new camera */
280 Camera *data, *data_eval;
281 float viewmat[4][4];
282 float shiftx;
283
284 data = id_cast<Camera *>(v3d->camera->data);
285 data_eval = DEG_get_evaluated(depsgraph, data);
286
287 shiftx = data_eval->shiftx;
288
290 data_eval->shiftx = BKE_camera_multiview_shift_x(&scene->r, v3d->camera, viewname);
291
292 BKE_camera_multiview_view_matrix(&scene->r, v3d->camera, is_left, viewmat);
293 view3d_main_region_setup_view(depsgraph, scene, v3d, region, viewmat, nullptr, rect);
294
295 data_eval->shiftx = shiftx;
297 }
298 else { /* SCE_VIEWS_FORMAT_MULTIVIEW */
299 float viewmat[4][4];
300 Object *view_ob = v3d->camera;
302 *DEG_get_bmain(depsgraph), scene, v3d->camera, viewname);
303
305 v3d->camera = camera;
306
307 BKE_camera_multiview_view_matrix(&scene->r, camera, false, viewmat);
308 view3d_main_region_setup_view(depsgraph, scene, v3d, region, viewmat, nullptr, rect);
309
310 v3d->camera = view_ob;
312 }
313}
314
315#ifdef WITH_XR_OPENXR
316static void view3d_xr_mirror_setup(const wmWindowManager *wm,
317 Depsgraph *depsgraph,
318 Scene *scene,
319 View3D *v3d,
320 ARegion *region,
321 const rcti *rect)
322{
323 RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata);
324 float viewmat[4][4];
325 const float lens_old = v3d->lens;
326
327 if (!WM_xr_session_state_viewer_pose_matrix_info_get(&wm->xr, viewmat, &v3d->lens)) {
328 /* Can't get info from XR session, use fallback values. */
329 copy_m4_m4(viewmat, rv3d->viewmat);
330 v3d->lens = lens_old;
331 }
332 view3d_main_region_setup_view(depsgraph, scene, v3d, region, viewmat, nullptr, rect);
333
334 /* Set draw flags. */
335 SET_FLAG_FROM_TEST(v3d->flag2,
336 (wm->xr.session_settings.draw_flags & V3D_OFSDRAW_XR_SHOW_CONTROLLERS) != 0,
338 SET_FLAG_FROM_TEST(v3d->flag2,
339 (wm->xr.session_settings.draw_flags & V3D_OFSDRAW_XR_SHOW_CUSTOM_OVERLAYS) !=
340 0,
342 /* Hide navigation gizmo since it gets distorted if the view matrix has a scale factor. */
343 v3d->gizmo_flag |= V3D_GIZMO_HIDE_NAVIGATE;
344
345 /* Reset overridden View3D data. */
346 v3d->lens = lens_old;
347}
348#endif /* WITH_XR_OPENXR */
349
351 wmWindow *win,
352 Depsgraph *depsgraph,
353 Scene *scene,
354 ARegion *region,
355 View3D *v3d,
356 const float viewmat[4][4],
357 const float winmat[4][4],
358 const rcti *rect)
359{
360 RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata);
361
362#ifdef WITH_XR_OPENXR
363 /* Setup the view matrix. */
364 if (ED_view3d_is_region_xr_mirror_active(wm, v3d, region)) {
365 view3d_xr_mirror_setup(wm, depsgraph, scene, v3d, region, rect);
366 }
367 else
368#endif
369 if (view3d_stereo3d_active(win, scene, v3d, rv3d))
370 {
371 view3d_stereo3d_setup(depsgraph, scene, v3d, region, rect);
372 }
373 else {
374 view3d_main_region_setup_view(depsgraph, scene, v3d, region, viewmat, winmat, rect);
375 }
376
377#ifndef WITH_XR_OPENXR
379#endif
380}
381
383
384/* -------------------------------------------------------------------- */
387
388static void drawviewborder(Scene *scene, Depsgraph *depsgraph, ARegion *region, View3D *v3d)
389{
390 float x1, x2, y1, y2;
391 float x1i, x2i, y1i, y2i;
392
393 Camera *ca = nullptr;
394 RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata);
395
396 if (v3d->camera == nullptr) {
397 return;
398 }
399 if (v3d->camera->type == OB_CAMERA) {
400 ca = id_cast<Camera *>(v3d->camera->data);
401 }
402
403 const rctf viewborder = BKE_camera_view_border(
404 scene, depsgraph, v3d, rv3d, region->winx, region->winy, false, false, true);
405 /* the offsets */
406 x1 = viewborder.xmin;
407 y1 = viewborder.ymin;
408 x2 = viewborder.xmax;
409 y2 = viewborder.ymax;
410
411 const float roll = rv3d->camroll;
412 const bool is_flipped_x = (rv3d->rflag & RV3D_FLIP_X) != 0;
413 GPU_line_width(1.0f);
414
415 /* apply offsets so the real 3D camera shows through */
416
417 /* NOTE: quite un-scientific but without this bit extra
418 * 0.0001 on the lower left the 2D border sometimes
419 * obscures the 3D camera border */
420 /* NOTE: with VIEW3D_CAMERA_BORDER_HACK defined this error isn't noticeable
421 * but keep it here in case we need to remove the workaround */
422 x1i = int(x1 - 1.0001f);
423 y1i = int(y1 - 1.0001f);
424 x2i = int(x2 + (1.0f - 0.0001f));
425 y2i = int(y2 + (1.0f - 0.0001f));
426
427 uint shdr_pos = GPU_vertformat_attr_add(
428 immVertexFormat(), "pos", gpu::VertAttrType::SFLOAT_32_32);
429
430 /* First, solid lines. */
431 {
433
434 /* Apply roll. */
435 if (roll != 0.0f || is_flipped_x) {
437 const int center_x = region->winx / 2;
438 const int center_y = region->winy / 2;
439 GPU_matrix_translate_2f(center_x, center_y);
440 if (is_flipped_x) {
441 GPU_matrix_scale_2f(-1.0f, 1.0f);
442 }
443 if (roll != 0.0f) {
445 }
446 GPU_matrix_translate_2f(-center_x, -center_y);
447 }
448
449 /* passepartout, specified in camera edit buttons */
450 if (ca && (ca->flag & CAM_SHOWPASSEPARTOUT) && ca->passepartalpha > 0.000001f &&
452 {
453 const float winx = (region->winx + 1);
454 const float winy = (region->winy + 1);
455
456 float alpha = 1.0f;
457
458 if (ca->passepartalpha != 1.0f) {
460 alpha = ca->passepartalpha;
461 }
462
464
465 if (roll == 0.0f) {
466 if (x1i > 0.0f) {
467 immRectf(shdr_pos, 0.0f, winy, x1i, 0.0f);
468 }
469 if (x2i < winx) {
470 immRectf(shdr_pos, x2i, winy, winx, 0.0f);
471 }
472 if (y2i < winy) {
473 immRectf(shdr_pos, x1i, winy, x2i, y2i);
474 }
475 if (y2i > 0.0f) {
476 immRectf(shdr_pos, x1i, y1i, x2i, 0.0f);
477 }
478 }
479 else {
480 const float padding = math::max(winx, winy);
481
482 immRectf(shdr_pos, -padding, winy + padding, x1i, -padding);
483 immRectf(shdr_pos, x2i, winy + padding, winx + padding, -padding);
484 immRectf(shdr_pos, x1i, winy + padding, x2i, y2i);
485 immRectf(shdr_pos, x1i, y1i, x2i, -padding);
486 }
487
490 imm_draw_box_wire_2d(shdr_pos, x1i, y1i, x2i, y2i);
491 }
492
493#ifdef VIEW3D_CAMERA_BORDER_HACK
494 if (view3d_camera_border_hack_test == true) {
496 imm_draw_box_wire_2d(shdr_pos, x1i + 1, y1i + 1, x2i - 1, y2i - 1);
498 }
499#endif
500
502 }
503
504 /* When overlays are disabled, only show camera outline & passepartout. */
505 if (v3d->flag2 & V3D_HIDE_OVERLAYS || !(v3d->flag2 & V3D_SHOW_CAMERA_GUIDES)) {
506 if (roll != 0.0f || is_flipped_x) {
508 }
509 return;
510 }
511
512 /* And now, the dashed lines! */
514
515 {
516 float viewport_size[4];
517 GPU_viewport_size_get_f(viewport_size);
518 immUniform2f("viewport_size", viewport_size[2], viewport_size[3]);
519
520 immUniform1i("colors_len", 0); /* "simple" mode */
521 immUniform1f("dash_width", 6.0f);
522 immUniform1f("udash_factor", 0.5f);
523
524 /* outer line not to confuse with object selection */
525 if (v3d->flag2 & V3D_LOCK_CAMERA) {
527 imm_draw_box_wire_2d(shdr_pos, x1i - 1, y1i - 1, x2i + 1, y2i + 1);
528 }
529
531 imm_draw_box_wire_2d(shdr_pos, x1i, y1i, x2i, y2i);
532 }
533
534 /* Render Border. */
535 if (scene->r.mode & R_BORDER) {
536 float x3, y3, x4, y4;
537
538 x3 = floorf(x1 + (scene->r.border.xmin * (x2 - x1))) - 1;
539 y3 = floorf(y1 + (scene->r.border.ymin * (y2 - y1))) - 1;
540 x4 = floorf(x1 + (scene->r.border.xmax * (x2 - x1))) + (U.pixelsize - 1);
541 y4 = floorf(y1 + (scene->r.border.ymax * (y2 - y1))) + (U.pixelsize - 1);
542
543 immUniformColor3f(1.0f, 0.25f, 0.25f);
544 imm_draw_box_wire_2d(shdr_pos, x3, y3, x4, y4);
545 }
546
547 /* safety border */
548 if (ca && (v3d->flag2 & V3D_SHOW_CAMERA_GUIDES)) {
550
552 shdr_pos, ca->composition_guide_flags, &viewborder, ca->composition_guide_color);
553
554 if (ca->flag & CAM_SHOW_SAFE_MARGINS) {
555 rctf margins_rect{};
556 margins_rect.xmin = x1;
557 margins_rect.xmax = x2;
558 margins_rect.ymin = y1;
559 margins_rect.ymax = y2;
560
561 /* draw */
563
565 shdr_pos, &margins_rect, scene->safe_areas.title, scene->safe_areas.action);
566
567 if (ca->flag & CAM_SHOW_SAFE_CENTER) {
568 rctf center_rect{};
569 center_rect.xmin = x1;
570 center_rect.xmax = x2;
571 center_rect.ymin = y1;
572 center_rect.ymax = y2;
573 ui::draw_safe_areas(shdr_pos,
574 &center_rect,
577 }
578 }
579
580 if (ca->flag & CAM_SHOWSENSOR) {
581 /* determine sensor fit, and get sensor x/y, for auto fit we
582 * assume and square sensor and only use sensor_x */
583 float sizex = scene->r.xsch * scene->r.xasp;
584 float sizey = scene->r.ysch * scene->r.yasp;
585 int sensor_fit = BKE_camera_sensor_fit(ca->sensor_fit, sizex, sizey);
586 float sensor_x = ca->sensor_x;
587 float sensor_y = (ca->sensor_fit == CAMERA_SENSOR_FIT_AUTO) ? ca->sensor_x : ca->sensor_y;
588
589 /* determine sensor plane */
590 rctf rect;
591
592 if (sensor_fit == CAMERA_SENSOR_FIT_HOR) {
593 float sensor_scale = (x2i - x1i) / sensor_x;
594 float sensor_height = sensor_scale * sensor_y;
595
596 rect.xmin = x1i;
597 rect.xmax = x2i;
598 rect.ymin = (y1i + y2i) * 0.5f - sensor_height * 0.5f;
599 rect.ymax = rect.ymin + sensor_height;
600 }
601 else {
602 float sensor_scale = (y2i - y1i) / sensor_y;
603 float sensor_width = sensor_scale * sensor_x;
604
605 rect.xmin = (x1i + x2i) * 0.5f - sensor_width * 0.5f;
606 rect.xmax = rect.xmin + sensor_width;
607 rect.ymin = y1i;
608 rect.ymax = y2i;
609 }
610
611 /* draw */
613
614 /* TODO: Was using:
615 * `draw_roundbox_4fv(false, rect.xmin, rect.ymin, rect.xmax, rect.ymax, 2.0f, color);`
616 * We'll probably need a new imm_draw_line_roundbox_dashed or that - though in practice the
617 * 2.0f round corner effect was nearly not visible anyway. */
618 imm_draw_box_wire_2d(shdr_pos, rect.xmin, rect.ymin, rect.xmax, rect.ymax);
619 }
620
622 }
623
625 /* end dashed lines */
626
627 /* camera name - draw in highlighted text color */
628 if (ca && ((v3d->overlay.flag & V3D_OVERLAY_HIDE_TEXT) == 0) && (ca->flag & CAM_SHOWNAME)) {
631 y1i - (0.7f * U.widget_unit),
632 0.0f,
633 v3d->camera->id.name + 2,
634 sizeof(v3d->camera->id.name) - 2);
635 }
636
637 if (roll != 0.0f || is_flipped_x) {
639 }
640}
641
642static void drawrenderborder(ARegion *region, View3D *v3d)
643{
644 /* use the same program for everything */
645 uint shdr_pos = GPU_vertformat_attr_add(
646 immVertexFormat(), "pos", gpu::VertAttrType::SFLOAT_32_32);
647
648 GPU_line_width(1.0f);
649
651
652 float viewport_size[4];
653 GPU_viewport_size_get_f(viewport_size);
654 immUniform2f("viewport_size", viewport_size[2], viewport_size[3]);
655
656 immUniform1i("colors_len", 0); /* "simple" mode */
657 immUniform4f("color", 1.0f, 0.25f, 0.25f, 1.0f);
658 immUniform1f("dash_width", 6.0f);
659 immUniform1f("udash_factor", 0.5f);
660
661 imm_draw_box_wire_2d(shdr_pos,
662 v3d->render_border.xmin * region->winx,
663 v3d->render_border.ymin * region->winy,
664 v3d->render_border.xmax * region->winx,
665 v3d->render_border.ymax * region->winy);
666
668}
669
671
672/* -------------------------------------------------------------------- */
675
676float ED_scene_grid_scale(const Scene *scene, const char **r_grid_unit)
677{
678 /* apply units */
679 if (scene->unit.system) {
680 const void *usys;
681 int len;
682
684
685 if (usys) {
686 int i = BKE_unit_base_get(usys);
687 if (r_grid_unit) {
688 *r_grid_unit = IFACE_(BKE_unit_display_name_get(usys, i));
689 }
690 return float(BKE_unit_scalar_get(usys, i)) / scene->unit.scale_length;
691 }
692 }
693
694 return 1.0f;
695}
696
697float ED_view3d_grid_scale(const Scene *scene, const View3D *v3d, const char **r_grid_unit)
698{
699 return v3d->grid * ED_scene_grid_scale(scene, r_grid_unit);
700}
701
702#define STEPS_LEN 8
703static void view3d_grid_steps_ex(const Scene *scene,
704 const View3D *v3d,
705 const RegionView3D *rv3d,
706 float r_grid_steps[STEPS_LEN],
707 void const **r_usys_pt,
708 int *r_len)
709{
710 const void *usys;
711 int len;
713 float grid_scale = v3d->grid;
715
716 if (usys) {
717 if (rv3d->view == RV3D_VIEW_USER) {
718 /* Skip steps */
719 len = BKE_unit_base_get(usys) + 1;
720 }
721
722 grid_scale /= scene->unit.scale_length;
723
724 int i;
725 for (i = 0; i < len; i++) {
726 r_grid_steps[i] = float(BKE_unit_scalar_get(usys, len - 1 - i)) * grid_scale;
727 }
728 for (; i < STEPS_LEN; i++) {
729 /* Fill last slots */
730 r_grid_steps[i] = r_grid_steps[len - 1];
731 }
732 }
733 else {
734 len = STEPS_LEN;
735 if (rv3d->view != RV3D_VIEW_USER) {
736 /* Allow 3 more subdivisions. */
737 grid_scale /= powf(v3d->gridsubdiv, 3);
738 }
739 int subdiv = 1;
740 for (int i = 0;; i++) {
741 r_grid_steps[i] = grid_scale * subdiv;
742
743 if (i == STEPS_LEN - 1) {
744 break;
745 }
746 subdiv *= v3d->gridsubdiv;
747 }
748 }
749 if (r_usys_pt) {
750 *r_usys_pt = usys;
751 }
752 if (r_len) {
753 *r_len = len;
754 }
755}
756
757void ED_view3d_grid_steps(const Scene *scene,
758 const View3D *v3d,
759 const RegionView3D *rv3d,
760 float r_grid_steps[STEPS_LEN])
761{
762 view3d_grid_steps_ex(scene, v3d, rv3d, r_grid_steps, nullptr, nullptr);
763}
764
766 const View3D *v3d,
767 const ARegion *region,
768 const char **r_grid_unit)
769{
770 float grid_scale;
771 const RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata);
772 if (!rv3d->is_persp && RV3D_VIEW_IS_AXIS(rv3d->view)) {
773 /* Decrease the distance between grid snap points depending on zoom. */
774 float dist = 12.0f / (region->sizex * rv3d->winmat[0][0]);
775 float grid_steps[STEPS_LEN];
776 const void *usys;
777 int grid_steps_len;
778 view3d_grid_steps_ex(scene, v3d, rv3d, grid_steps, &usys, &grid_steps_len);
779 int i = 0;
780 while (true) {
781 grid_scale = grid_steps[i];
782 if (grid_scale > dist || i == (grid_steps_len - 1)) {
783 break;
784 }
785 i++;
786 }
787
788 if (r_grid_unit && usys) {
789 *r_grid_unit = IFACE_(BKE_unit_display_name_get(usys, grid_steps_len - i - 1));
790 }
791 }
792 else {
793 grid_scale = ED_view3d_grid_scale(scene, v3d, r_grid_unit);
794 }
795
796 return grid_scale;
797}
798
799#undef STEPS_LEN
800
801static void draw_view_axis(RegionView3D *rv3d, const rcti *rect)
802{
803 const float k = U.rvisize * UI_SCALE_FAC; /* axis size */
804 /* axis alpha offset (rvibright has range 0-10) */
805 const int bright = -20 * (10 - U.rvibright);
806
807 /* Axis center in screen coordinates.
808 *
809 * - Unit size offset so small text doesn't draw outside the screen
810 * - Extra X offset because of the panel expander.
811 */
812 const float startx = rect->xmax - (k + UI_UNIT_X * 1.5);
813 const float starty = rect->ymax - (k + UI_UNIT_Y);
814
815 float axis_pos[3][2];
816 float axis_col[3][4];
817
818 int axis_order[3] = {0, 1, 2};
819 axis_sort_v3(rv3d->viewinv[2], axis_order);
820
821 for (int axis_i = 0; axis_i < 3; axis_i++) {
822 int i = axis_order[axis_i];
823
824 /* get position of each axis tip on screen */
825 float vec[3] = {0.0f};
826 vec[i] = 1.0f;
827 mul_qt_v3(rv3d->viewquat, vec);
828 axis_pos[i][0] = startx + vec[0] * k;
829 axis_pos[i][1] = starty + vec[1] * k;
830
831 /* get color of each axis */
832 ui::theme::get_color_shade_3fv(TH_AXIS_X + i, bright, axis_col[i]); /* rgb */
833 axis_col[i][3] = hypotf(vec[0], vec[1]); /* alpha */
834 }
835
836 /* draw axis lines */
837 GPU_line_width(2.0f);
838 GPU_line_smooth(true);
840
841 GPUVertFormat *format = immVertexFormat();
842 uint pos = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32);
843 uint col = GPU_vertformat_attr_add(format, "color", gpu::VertAttrType::SFLOAT_32_32_32_32);
844
847
848 for (int axis_i = 0; axis_i < 3; axis_i++) {
849 int i = axis_order[axis_i];
850
851 immAttr4fv(col, axis_col[i]);
852 immVertex2f(pos, startx, starty);
853 immAttr4fv(col, axis_col[i]);
854 immVertex2fv(pos, axis_pos[i]);
855 }
856
857 immEnd();
859 GPU_line_smooth(false);
860
861 /* draw axis names */
862 for (int axis_i = 0; axis_i < 3; axis_i++) {
863 int i = axis_order[axis_i];
864
865 const char axis_text[2] = {char('x' + i), '\0'};
866 BLF_color4fv(BLF_default(), axis_col[i]);
867 BLF_draw_default(axis_pos[i][0] + 2, axis_pos[i][1] + 2, 0.0f, axis_text, 1);
868 }
869}
870
871#ifdef WITH_INPUT_NDOF
875static void draw_ndof_guide_orbit_axis(const RegionView3D *rv3d)
876{
877 float o[3]; /* center of rotation */
878 float end[3]; /* endpoints for drawing */
879
880 float color[4] = {0.0f, 0.42f, 1.0f, 1.0f}; /* bright blue so it matches device LEDs */
881
882 negate_v3_v3(o, rv3d->ofs);
883
885 GPU_depth_mask(false); /* Don't overwrite the Z-buffer. */
886
888 uint pos = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32_32);
889 uint col = GPU_vertformat_attr_add(format, "color", gpu::VertAttrType::SFLOAT_32_32_32_32);
890
892
893 if (rv3d->ndof_rot_angle != 0.0f) {
894 /* -- draw rotation axis -- */
895 float scaled_axis[3];
896 const float scale = rv3d->dist;
897 mul_v3_v3fl(scaled_axis, rv3d->ndof_rot_axis, scale);
898
900 color[3] = 0; /* more transparent toward the ends */
901 immAttr4fv(col, color);
902 add_v3_v3v3(end, o, scaled_axis);
903 immVertex3fv(pos, end);
904
905# if 0
906 color[3] = 0.2f + fabsf(rv3d->rot_angle); /* modulate opacity with angle */
907 /* ^^ neat idea, but angle is frame-rate dependent, so it's usually close to 0.2 */
908# endif
909
910 color[3] = 0.5f; /* more opaque toward the center */
911 immAttr4fv(col, color);
912 immVertex3fv(pos, o);
913
914 color[3] = 0;
915 immAttr4fv(col, color);
916 sub_v3_v3v3(end, o, scaled_axis);
917 immVertex3fv(pos, end);
918 immEnd();
919
920 /* -- draw ring around rotation center -- */
921 {
922# define ROT_AXIS_DETAIL 13
923
924 const float s = 0.05f * scale;
925 const float step = 2.0f * float(M_PI / ROT_AXIS_DETAIL);
926
927 float q[4]; /* rotate ring so it's perpendicular to axis */
928 const int upright = fabsf(rv3d->ndof_rot_axis[2]) >= 0.95f;
929 if (!upright) {
930 const float up[3] = {0.0f, 0.0f, 1.0f};
931 float vis_angle, vis_axis[3];
932
933 cross_v3_v3v3(vis_axis, up, rv3d->ndof_rot_axis);
934 vis_angle = acosf(dot_v3v3(up, rv3d->ndof_rot_axis));
935 axis_angle_to_quat(q, vis_axis, vis_angle);
936 }
937
938 immBegin(GPU_PRIM_LINE_LOOP, ROT_AXIS_DETAIL);
939 color[3] = 0.25f; /* somewhat faint */
940 immAttr4fv(col, color);
941 float angle = 0.0f;
942 for (int i = 0; i < ROT_AXIS_DETAIL; i++, angle += step) {
943 float p[3] = {s * cosf(angle), s * sinf(angle), 0.0f};
944
945 if (!upright) {
946 mul_qt_v3(q, p);
947 }
948
949 add_v3_v3(p, o);
950 immVertex3fv(pos, p);
951 }
952 immEnd();
953
954# undef ROT_AXIS_DETAIL
955 }
956
957 color[3] = 1.0f; /* solid dot */
958 }
959 else {
960 color[3] = 0.5f; /* see-through dot */
961 }
962
964
965 /* -- draw rotation center -- */
967 immUniform1f("size", 7.0f);
968 immUniform4fv("color", float4(color));
970 immAttr4fv(col, color);
971 immVertex3fv(pos, o);
972 immEnd();
974
976 GPU_depth_mask(true);
977}
978
979static void draw_ndof_guide_orbit_center(const RegionView3D *rv3d)
980{
981 uchar color[4] = {0, 108, 255, 255}; /* bright blue so it matches device LEDs */
983 GPU_depth_mask(false); /* Don't overwrite the Z-buffer. */
984
986 uint pos = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32_32);
987 uint col = GPU_vertformat_attr_add(format, "color", gpu::VertAttrType::UNORM_8_8_8_8);
988
990 immUniform1f("size", 7.0f);
991 immUniform4fv("color", float4(color));
993 immAttr4ubv(col, color);
994 float center[3];
995 negate_v3_v3(center, rv3d->ndof_ofs);
996 immVertex3fv(pos, center);
997 immEnd();
999
1001 GPU_depth_mask(true);
1002}
1003
1004#endif /* WITH_INPUT_NDOF */
1005
1009static void view3d_draw_border(const bContext *C, ARegion *region)
1010{
1011 Scene *scene = CTX_data_scene(C);
1012 Depsgraph *depsgraph = CTX_data_expect_evaluated_depsgraph(C);
1013 RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata);
1014 View3D *v3d = CTX_wm_view3d(C);
1015
1016 if (rv3d->persp == RV3D_CAMOB) {
1017 drawviewborder(scene, depsgraph, region, v3d);
1018 }
1019 else if (v3d->flag2 & V3D_RENDER_BORDER) {
1020 drawrenderborder(region, v3d);
1021 }
1022}
1023
1025
1026/* -------------------------------------------------------------------- */
1029
1033static void view3d_draw_grease_pencil(const bContext * /*C*/)
1034{
1035 /* TODO: viewport. */
1036}
1037
1041static const char *view3d_get_name(View3D *v3d, RegionView3D *rv3d)
1042{
1043 const char *name = nullptr;
1044 const bool is_locked = RV3D_LOCK_FLAGS(rv3d) & RV3D_LOCK_ROTATION;
1045
1046 switch (rv3d->view) {
1047 case RV3D_VIEW_FRONT:
1048 if (is_locked) {
1049 name = IFACE_("Front");
1050 }
1051 else if (rv3d->persp == RV3D_ORTHO) {
1052 name = IFACE_("Front Orthographic");
1053 }
1054 else {
1055 name = IFACE_("Front Perspective");
1056 }
1057 break;
1058 case RV3D_VIEW_BACK:
1059 if (is_locked) {
1060 name = IFACE_("Back");
1061 }
1062 else if (rv3d->persp == RV3D_ORTHO) {
1063 name = IFACE_("Back Orthographic");
1064 }
1065 else {
1066 name = IFACE_("Back Perspective");
1067 }
1068 break;
1069 case RV3D_VIEW_TOP:
1070 if (is_locked) {
1071 name = IFACE_("Top");
1072 }
1073 else if (rv3d->persp == RV3D_ORTHO) {
1074 name = IFACE_("Top Orthographic");
1075 }
1076 else {
1077 name = IFACE_("Top Perspective");
1078 }
1079 break;
1080 case RV3D_VIEW_BOTTOM:
1081 if (is_locked) {
1082 name = IFACE_("Bottom");
1083 }
1084 else if (rv3d->persp == RV3D_ORTHO) {
1085 name = IFACE_("Bottom Orthographic");
1086 }
1087 else {
1088 name = IFACE_("Bottom Perspective");
1089 }
1090 break;
1091 case RV3D_VIEW_RIGHT:
1092 if (is_locked) {
1093 name = IFACE_("Right");
1094 }
1095 else if (rv3d->persp == RV3D_ORTHO) {
1096 name = IFACE_("Right Orthographic");
1097 }
1098 else {
1099 name = IFACE_("Right Perspective");
1100 }
1101 break;
1102 case RV3D_VIEW_LEFT:
1103 if (is_locked) {
1104 name = IFACE_("Left");
1105 }
1106 else if (rv3d->persp == RV3D_ORTHO) {
1107 name = IFACE_("Left Orthographic");
1108 }
1109 else {
1110 name = IFACE_("Left Perspective");
1111 }
1112 break;
1113
1114 default:
1115 if (rv3d->persp == RV3D_CAMOB) {
1116 if ((v3d->camera) && (v3d->camera->type == OB_CAMERA)) {
1117 const Camera *cam = id_cast<const Camera *>(v3d->camera->data);
1118 if (cam->type == CAM_PERSP) {
1119 name = IFACE_("Camera Perspective");
1120 }
1121 else if (cam->type == CAM_ORTHO) {
1122 name = IFACE_("Camera Orthographic");
1123 }
1124 else if (cam->type == CAM_PANO) {
1125 name = IFACE_("Camera Panoramic");
1126 }
1127 else {
1128 BLI_assert(cam->type == CAM_CUSTOM);
1129 name = IFACE_("Camera Custom");
1130 }
1131 }
1132 else {
1133 name = IFACE_("Object as Camera");
1134 }
1135 }
1136 else {
1137 name = (rv3d->persp == RV3D_ORTHO) ? IFACE_("User Orthographic") :
1138 IFACE_("User Perspective");
1139 }
1140 }
1141
1142 return name;
1143}
1144
1145static void draw_viewport_name(ARegion *region, View3D *v3d, int xoffset, int *yoffset)
1146{
1147 RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata);
1148 /* Append text directly, the inline buffer avoids allocating in practice. */
1149 fmt::memory_buffer name;
1150 name.append(StringRef(view3d_get_name(v3d, rv3d)));
1151
1153 const char *axis_roll;
1154 switch (rv3d->view_axis_roll) {
1156 axis_roll = " 90\xC2\xB0";
1157 break;
1159 axis_roll = " 180\xC2\xB0";
1160 break;
1161 default:
1162 axis_roll = " -90\xC2\xB0";
1163 break;
1164 }
1165 name.append(StringRef(axis_roll));
1166 }
1167
1168 if (v3d->localvd) {
1169 name.append(StringRef(IFACE_(" (Local)")));
1170 }
1171
1172 /* Indicate that clipping region is enabled. */
1173 if (RV3D_CLIPPING_ENABLED(v3d, rv3d)) {
1174 name.append(StringRef(IFACE_(" (Clipped)")));
1175 }
1176
1177 /* Indicate that the view is flipped. */
1178 if (rv3d->persp == RV3D_CAMOB) {
1180
1181 switch (flip_roll) {
1183 name.append(StringRef(IFACE_(" (Flipped) (Rolled)")));
1184 break;
1186 name.append(StringRef(IFACE_(" (Flipped X)")));
1187 break;
1189 name.append(StringRef(IFACE_(" (Flipped Y)")));
1190 break;
1192 break;
1194 name.append(StringRef(IFACE_(" (90\xC2\xB0)")));
1195 break;
1197 name.append(StringRef(IFACE_(" (180\xC2\xB0)")));
1198 break;
1200 name.append(StringRef(IFACE_(" (-90\xC2\xB0)")));
1201 break;
1203 name.append(StringRef(IFACE_(" (Rolled)")));
1204 break;
1205 }
1206 }
1207
1208 *yoffset -= VIEW3D_OVERLAY_LINEHEIGHT;
1209 BLF_draw_default(xoffset, *yoffset, 0.0f, name.data(), name.size());
1210}
1211
1213{
1214 if (ob.type != OB_GREASE_PENCIL) {
1215 return false;
1216 }
1217
1218 using namespace blender::bke::greasepencil;
1219 const GreasePencil &grease_pencil = *id_cast<GreasePencil *>(ob.data);
1220 for (const Layer *layer : grease_pencil.layers()) {
1221 if (!layer->frames().is_empty()) {
1222 return true;
1223 }
1224 }
1225 return false;
1226}
1227
1232static void draw_selected_name(const Main &bmain,
1233 const View3D *v3d,
1234 Scene *scene,
1235 ViewLayer *view_layer,
1236 Object *ob,
1237 int xoffset,
1238 int *yoffset)
1239{
1240 const int cfra = scene->r.cfra;
1241 const char *msg_pin = " (Soloed)";
1242 const char *msg_sep = " : ";
1243 const char *msg_space = " ";
1244
1245 const int font_id = BLF_default();
1246
1247 const char *info_array[16];
1248 int i = 0;
1249
1250 struct {
1251 char frame[16];
1252 } info_buffers;
1253
1254 /* Info can contain:
1255 * - 1 frame number `(7 + 2)`.
1256 * - 1 collection name `(MAX_ID_NAME - 2 + 3)`.
1257 * - 1 object name `(MAX_ID_NAME - 2)`.
1258 * - 1 object data name `(MAX_ID_NAME - 2)`.
1259 * - 2 non-ID data names (bones, shape-keys...) `(MAX_NAME * 2)`.
1260 * - 2 BREAD_CRUMB_SEPARATOR(s) `(6)`.
1261 * - 1 SHAPE_KEY_PINNED marker and a trailing '\0' `(9+1)` - translated, so give some room!
1262 * - 1 marker name `(MAX_NAME + 3)`.
1263 */
1264
1265 SNPRINTF_UTF8(info_buffers.frame, "(%d)", cfra);
1266 info_array[i++] = info_buffers.frame;
1267
1268 if ((ob == nullptr) || (ob->mode == OB_MODE_OBJECT)) {
1269 BKE_view_layer_synced_ensure(bmain, scene, view_layer);
1270 LayerCollection *layer_collection = BKE_view_layer_active_collection_get(view_layer);
1271 info_array[i++] = msg_space;
1272 info_array[i++] = BKE_collection_ui_name_get(layer_collection->collection);
1273 if (ob != nullptr) {
1274 info_array[i++] = " |";
1275 }
1276 }
1277
1278 /* get name of marker on current frame (if available) */
1279 const char *markern = BKE_scene_find_marker_name(scene, cfra);
1280
1281 /* check if there is an object */
1282 if (ob) {
1283 info_array[i++] = msg_space;
1284 info_array[i++] = ob->id.name + 2;
1285
1286 /* Show object data name when not in object mode. */
1287 if (ob->mode != OB_MODE_OBJECT) {
1288 if (const ID *data_id = static_cast<const ID *>(ob->data)) {
1289 info_array[i++] = " | ";
1290 info_array[i++] = data_id->name + 2;
1291 }
1292 }
1293
1294 /* name(s) to display depends on type of object */
1295 if (ob->type == OB_ARMATURE) {
1296 bArmature *arm = id_cast<bArmature *>(ob->data);
1297
1298 /* show name of active bone too (if possible) */
1299 if (arm->edbo) {
1300 if (arm->act_edbone) {
1301 info_array[i++] = msg_sep;
1302 info_array[i++] = arm->act_edbone->name;
1303 }
1304 }
1305 else if (ob->mode & OB_MODE_POSE) {
1306 if (arm->act_bone) {
1307
1309 info_array[i++] = msg_sep;
1310 info_array[i++] = arm->act_bone->name;
1311 }
1312 }
1313 }
1314 }
1315 else if (ELEM(ob->type, OB_MESH, OB_LATTICE, OB_CURVES_LEGACY)) {
1316 /* Try to display active bone and active shape-key too (if they exist). */
1317
1318 if (ob->type == OB_MESH && ob->mode & OB_MODE_WEIGHT_PAINT) {
1320 if (armobj && armobj->mode & OB_MODE_POSE) {
1321 bArmature *arm = id_cast<bArmature *>(armobj->data);
1322 if (arm->act_bone) {
1324 info_array[i++] = msg_sep;
1325 info_array[i++] = arm->act_bone->name;
1326 }
1327 }
1328 }
1329 }
1330
1331 Key *key = BKE_key_from_object(ob);
1332 if (key) {
1333 KeyBlock *kb = static_cast<KeyBlock *>(BLI_findlink(&key->block, ob->shapenr - 1));
1334 if (kb) {
1335 info_array[i++] = msg_sep;
1336 info_array[i++] = kb->name;
1337 if (ob->shapeflag & OB_SHAPE_LOCK) {
1338 info_array[i++] = IFACE_(msg_pin);
1339 }
1340 }
1341 }
1342 }
1343
1344 /* color depends on whether there is a keyframe */
1347 }
1348
1349 if (animrig::id_frame_has_keyframe(id_cast<ID *>(ob),
1350 /* BKE_scene_ctime_get(scene) */ float(cfra)))
1351 {
1353 }
1354 }
1355
1356 if (markern) {
1357 info_array[i++] = " <";
1358 info_array[i++] = markern;
1359 info_array[i++] = ">";
1360 }
1361
1362 if (v3d->flag2 & V3D_SHOW_VIEWER) {
1363 if (!v3d->viewer_path.path.is_empty()) {
1364 info_array[i++] = IFACE_(" (Viewer)");
1365 }
1366 }
1367
1368 BLI_assert(i < int(ARRAY_SIZE(info_array)));
1369
1370 char info[MAX_ID_NAME * 4];
1371 /* It's expected there will be enough room for the whole string in the buffer.
1372 * If not, increase it. */
1373 BLI_assert(BLI_string_len_array(info_array, i) < sizeof(info));
1374
1375 BLI_string_join_array(info, sizeof(info), info_array, i);
1376
1377 *yoffset -= VIEW3D_OVERLAY_LINEHEIGHT;
1378 BLF_draw_default(xoffset, *yoffset, 0.0f, info, sizeof(info));
1379}
1380
1382 Scene *scene, ARegion *region, View3D *v3d, int xoffset, int *yoffset)
1383{
1384 RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata);
1385 if (!rv3d->is_persp && RV3D_VIEW_IS_AXIS(rv3d->view)) {
1386 const char *grid_unit = nullptr;
1387 ED_view3d_grid_view_scale(scene, v3d, region, &grid_unit);
1388
1389 if (grid_unit) {
1390 char numstr[32] = "";
1391 if (v3d->grid != 1.0f) {
1393 numstr, "%s " BLI_STR_UTF8_MULTIPLICATION_SIGN " %.4g", grid_unit, v3d->grid);
1394 }
1395
1396 *yoffset -= VIEW3D_OVERLAY_LINEHEIGHT;
1397 BLF_draw_default(xoffset, *yoffset, 0.0f, numstr[0] ? numstr : grid_unit, sizeof(numstr));
1398 }
1399 }
1400}
1401
1403{
1404 float col_alert[4];
1406
1407 /* Tint the text color with red alert, using the red alert alpha as blend factor. */
1408 ui::theme::get_color_blend_3f(TH_TEXT_HI, TH_REDALERT, col_alert[3], col_alert);
1409 col_alert[3] = 1.0f;
1410
1411 return col_alert;
1412}
1413
1414static void draw_performance_stats(Depsgraph *depsgraph,
1415 Scene *scene,
1416 View3D *v3d,
1417 const float text_color[4],
1418 const int xoffset,
1419 int *yoffset,
1420 const int line_height)
1421{
1422 const float fps_target = float(scene->frames_per_second());
1423 const float target_time = 1.0f / fps_target;
1424
1425 std::optional<double> last_eval_time = DEG_get_last_evaluation_time(depsgraph);
1426 const float sync_time = v3d->runtime.last_sync_time;
1427 const float submission_time = v3d->runtime.last_submission_time;
1428 const float total_time = (last_eval_time ? *last_eval_time : 0.0f) + sync_time + submission_time;
1429
1430 /* Translated labels for each stat row. */
1431 enum { EVAL_TIME, SYNC_TIME, TOTAL, MAX_LABELS_COUNT };
1432 std::string labels[MAX_LABELS_COUNT];
1433 labels[EVAL_TIME] = IFACE_("Evaluation");
1434 labels[SYNC_TIME] = IFACE_("Synchronization");
1435 labels[TOTAL] = IFACE_("Total");
1436
1437 const int font_id = BLF_default();
1438 float longest_label = 0;
1439 for (int i = 0; i < MAX_LABELS_COUNT; ++i) {
1440 longest_label = std::max(longest_label,
1441 BLF_width(font_id, labels[i].c_str(), labels[i].size()));
1442 }
1443
1444 const int xoffset2 = xoffset + int(longest_label) + (0.5f * U.widget_unit);
1445
1446 const auto draw_time_stat = [&](const StringRef label, const std::optional<float> time_value) {
1447 *yoffset -= line_height;
1448 BLF_draw_default(xoffset, *yoffset, 0.0f, label.data(), label.size());
1449 if (time_value) {
1450 /* Draw time in red when its over the target time per frame. */
1451 if (*time_value > target_time) {
1452 float4 alert_rgb = get_low_fps_color();
1453 BLF_color4fv(font_id, alert_rgb);
1454 }
1455 std::string value_string = fmt::format("{:.2f} ms", *time_value * 1000.0f);
1456 BLF_draw_default(xoffset2, *yoffset, 0.0f, value_string.c_str(), value_string.size());
1457 /* Reset the color. */
1458 BLF_color4fv(font_id, text_color);
1459 }
1460 };
1461
1462 *yoffset -= line_height;
1463 draw_time_stat(labels[EVAL_TIME], last_eval_time);
1464 draw_time_stat(labels[SYNC_TIME], sync_time);
1465 draw_time_stat(labels[TOTAL], total_time);
1466}
1467
1469{
1470 RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata);
1471 View3D *v3d = CTX_wm_view3d(C);
1472 Scene *scene = CTX_data_scene(C);
1474 Main *bmain = CTX_data_main(C);
1475 ViewLayer *view_layer = CTX_data_view_layer(C);
1476 Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);
1477
1478#ifdef WITH_INPUT_NDOF
1479 if (U.ndof_flag & NDOF_SHOW_GUIDE_ORBIT_AXIS) {
1480 if ((RV3D_LOCK_FLAGS(rv3d) & RV3D_LOCK_ROTATION) == 0) {
1481 /* It only makes sense to show when orbiting. */
1482 if (rv3d->ndof_rot_angle != 0.0f) {
1483 /* TODO: draw something else (but not this) during fly mode. */
1484 draw_ndof_guide_orbit_axis(rv3d);
1485 }
1486 }
1487 }
1488
1489 if (U.ndof_flag & NDOF_SHOW_GUIDE_ORBIT_CENTER) {
1490 /* Draw this only when orbiting and auto orbit-center is enabled */
1492 if (rv3d->ndof_flag & RV3D_NDOF_OFS_IS_VALID) {
1493 /* When the center is locked, the auto-center is not used. */
1494 if (!(v3d->ob_center_cursor || v3d->ob_center)) {
1495 /* It only makes sense to show when orbiting. */
1496 if (rv3d->ndof_rot_angle != 0.0f) {
1497 draw_ndof_guide_orbit_center(rv3d);
1498 }
1499 }
1500 }
1501 }
1502 }
1503#endif
1504
1505 /* correct projection matrix */
1506 ED_region_pixelspace(region);
1507
1508 /* local coordinate visible rect inside region, to accommodate overlapping ui */
1509 const rcti *rect = ED_region_visible_rect(region);
1510
1511 view3d_draw_border(C, region);
1513
1515
1517 /* pass */
1518 }
1519 else {
1520 switch (eUserpref_MiniAxisType(U.mini_axis_type)) {
1522 /* The gizmo handles its own drawing. */
1523 break;
1525 if (region->alignment != RGN_ALIGN_QSPLIT ||
1527 {
1528 draw_view_axis(rv3d, rect);
1529 }
1531 break;
1532 }
1533 }
1534
1535 if ((v3d->flag2 & V3D_HIDE_OVERLAYS) == 0) {
1536 int xoffset = rect->xmin + (0.5f * U.widget_unit);
1537 int yoffset = rect->ymax - (0.1f * U.widget_unit);
1538
1539 const uiFontStyle *fstyle = UI_FSTYLE_WIDGET;
1540 ui::fontstyle_set(fstyle);
1541 BLF_default_size(fstyle->points);
1543
1544 const int font_id = BLF_default();
1545 float text_color[4], shadow_color[4];
1546 ED_view3d_text_colors_get(scene, v3d, text_color, shadow_color);
1547 BLF_color4fv(font_id, text_color);
1548 BLF_enable(font_id, BLF_SHADOW);
1549 BLF_shadow_offset(font_id, 0, 0);
1550 BLF_shadow(font_id, FontShadowType::Outline, shadow_color);
1551
1552 /* If in Quad-view only draw on the top-left region. */
1553 bool region_ok = (region->alignment != RGN_ALIGN_QSPLIT ||
1555
1556 if ((v3d->overlay.flag & V3D_OVERLAY_HIDE_TEXT) == 0) {
1557 if ((U.uiflag & USER_SHOW_FPS) && ED_screen_animation_no_scrub(wm) && region_ok) {
1558 ED_scene_draw_fps(scene, xoffset, &yoffset);
1559 BLF_color4fv(font_id, text_color);
1560 }
1561 else if (U.uiflag & USER_SHOW_VIEWPORTNAME) {
1562 draw_viewport_name(region, v3d, xoffset, &yoffset);
1563 }
1564
1565 if (U.uiflag & USER_DRAWVIEWINFO && region_ok) {
1566 BKE_view_layer_synced_ensure(*bmain, scene, view_layer);
1567 Object *ob = BKE_view_layer_active_object_get(view_layer);
1568 draw_selected_name(*bmain, v3d, scene, view_layer, ob, xoffset, &yoffset);
1569 BLF_color4fv(font_id, text_color);
1570 }
1571
1572 if (v3d->gridflag & (V3D_SHOW_FLOOR | V3D_SHOW_X | V3D_SHOW_Y | V3D_SHOW_Z) && region_ok) {
1573 /* draw below the viewport name */
1574 draw_grid_unit_name(scene, region, v3d, xoffset, &yoffset);
1575 }
1576
1577 if (region_ok) {
1579 }
1580 }
1581
1582 if (v3d->overlay.flag & V3D_OVERLAY_PERFORMANCE && region_ok) {
1584 depsgraph, scene, v3d, text_color, xoffset, &yoffset, VIEW3D_OVERLAY_LINEHEIGHT);
1585 }
1586
1587 if (v3d->overlay.flag & V3D_OVERLAY_STATS && region_ok) {
1588 View3D *v3d_local = v3d->localvd ? v3d : nullptr;
1590 bmain, scene, view_layer, v3d_local, xoffset, &yoffset, VIEW3D_OVERLAY_LINEHEIGHT);
1591 }
1592
1593 /* Set the size back to the default hard-coded size. Otherwise anyone drawing after this,
1594 * without setting explicit size, will draw with widget size. That is probably ideal,
1595 * but size should be set at the calling site not just carried over from here. */
1597 BLF_disable(font_id, BLF_SHADOW);
1598 }
1599
1601}
1602
1604
1605/* -------------------------------------------------------------------- */
1608
1609static void view3d_draw_view(const bContext *C, ARegion *region)
1610{
1615 region,
1617 nullptr,
1618 nullptr,
1619 nullptr);
1620
1621 /* Only 100% compliant on new spec goes below */
1623}
1624
1626{
1627 /*
1628 * Temporary viewport draw modes until we have a proper system.
1629 * all modes are done in the draw manager, except external render
1630 * engines like Cycles.
1631 */
1632 RenderEngineType *type = RE_engines_find(scene->r.engine);
1633 if (drawtype == OB_MATERIAL && (type->flag & RE_USE_EEVEE_VIEWPORT)) {
1635 }
1636 return type;
1637}
1638
1640{
1641 View3D *v3d = CTX_wm_view3d(C);
1642 WorkSpace *workspace = CTX_wm_workspace(C);
1643 /* Always use viewer path from workspace, pinning is not supported currently. */
1644 if (!BKE_viewer_path_equal(&v3d->viewer_path, &workspace->viewer_path)) {
1646 BKE_viewer_path_copy(&v3d->viewer_path, &workspace->viewer_path);
1647 }
1648}
1649
1651{
1652 using namespace blender::draw;
1653 Main *bmain = CTX_data_main(C);
1654 View3D *v3d = CTX_wm_view3d(C);
1655
1657 view3d_draw_view(C, region);
1658
1662
1663 /* No depth test for drawing action zones afterwards. */
1665
1667 /* TODO: Clear cache? */
1668}
1669
1671
1672/* -------------------------------------------------------------------- */
1675
1676static void view3d_stereo3d_setup_offscreen(Depsgraph *depsgraph,
1677 const Scene *scene,
1678 View3D *v3d,
1679 ARegion *region,
1680 const float winmat[4][4],
1681 const char *viewname)
1682{
1683 /* update the viewport matrices with the new camera */
1685 float viewmat[4][4];
1686 const bool is_left = STREQ(viewname, STEREO_LEFT_NAME);
1687
1688 BKE_camera_multiview_view_matrix(&scene->r, v3d->camera, is_left, viewmat);
1689 view3d_main_region_setup_offscreen(depsgraph, scene, v3d, region, viewmat, winmat);
1690 }
1691 else { /* SCE_VIEWS_FORMAT_MULTIVIEW */
1692 float viewmat[4][4];
1694 *DEG_get_bmain(depsgraph), scene, v3d->camera, viewname);
1695
1696 BKE_camera_multiview_view_matrix(&scene->r, camera, false, viewmat);
1697 view3d_main_region_setup_offscreen(depsgraph, scene, v3d, region, viewmat, winmat);
1698 }
1699}
1700
1701void ED_view3d_draw_offscreen(Depsgraph *depsgraph,
1702 const Scene *scene,
1703 eDrawType drawtype,
1704 View3D *v3d,
1705 ARegion *region,
1706 bContext *context,
1707 int winx,
1708 int winy,
1709 const float viewmat[4][4],
1710 const float winmat[4][4],
1711 bool is_image_render,
1712 bool draw_background,
1713 const char *viewname,
1714 const bool do_color_management,
1715 const bool restore_rv3d_mats,
1716 GPUOffScreen *ofs,
1717 GPUViewport *viewport)
1718{
1719 using namespace blender::draw;
1720 RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata);
1721 RenderEngineType *engine_type = ED_view3d_engine_type(scene, drawtype);
1722
1723 /* Store `orig` variables. */
1724 struct {
1725 ui::theme::bThemeState theme_state;
1726
1727 /* #View3D */
1728 eDrawType v3d_shading_type;
1729
1730 /* #Region */
1731 int region_winx, region_winy;
1732 rcti region_winrct;
1733
1734 /* #RegionView3D */
1739 RV3DMatrixStore *rv3d_mats;
1740 eRegionView3D_Persp rv3d_persp;
1741 } orig{};
1742 orig.v3d_shading_type = eDrawType(v3d->shading.type);
1743 orig.region_winx = region->winx;
1744 orig.region_winy = region->winy;
1745 orig.region_winrct = region->winrct;
1746 orig.rv3d_persp = rv3d->persp;
1747 orig.rv3d_mats = ED_view3d_mats_rv3d_backup(static_cast<RegionView3D *>(region->regiondata));
1748
1749 ui::theme::theme_store(&orig.theme_state);
1751
1752 /* Set temporary new size. */
1753 region->winx = winx;
1754 region->winy = winy;
1755 region->winrct.xmin = 0;
1756 region->winrct.ymin = 0;
1757 region->winrct.xmax = winx;
1758 region->winrct.ymax = winy;
1759
1760 /* There are too many functions inside the draw manager that check the shading type,
1761 * so use a temporary override instead. */
1762 v3d->shading.type = drawtype;
1763
1764 /* Set flags. */
1766
1767 {
1768 /* Free images which can have changed on frame-change.
1769 * WARNING(@ideasman42): can be slow so only free animated images. */
1771 }
1772
1777
1778 if ((viewname != nullptr && viewname[0] != '\0') && (viewmat == nullptr) &&
1779 rv3d->persp == RV3D_CAMOB && v3d->camera)
1780 {
1781 view3d_stereo3d_setup_offscreen(depsgraph, scene, v3d, region, winmat, viewname);
1782 }
1783 else {
1784 view3d_main_region_setup_offscreen(depsgraph, scene, v3d, region, viewmat, winmat);
1785 }
1786
1787 if (viewport) {
1788 GPU_viewport_tag_update(viewport);
1789 }
1790
1791 /* main drawing call */
1793 engine_type,
1794 region,
1795 v3d,
1796 context,
1797 is_image_render,
1798 draw_background,
1799 do_color_management,
1800 ofs,
1801 viewport);
1805
1806 /* Restore all `orig` members. */
1807 region->winx = orig.region_winx;
1808 region->winy = orig.region_winy;
1809 region->winrct = orig.region_winrct;
1810
1811 /* Optionally do _not_ restore rv3d matrices (e.g. they are used/stored in the ImBuff for
1812 * reprojection, see texture_paint_image_from_view_exec()). */
1813 if (restore_rv3d_mats) {
1814 ED_view3d_mats_rv3d_restore(static_cast<RegionView3D *>(region->regiondata), orig.rv3d_mats);
1815 }
1816 MEM_delete(orig.rv3d_mats);
1817 rv3d->persp = orig.rv3d_persp;
1818
1819 ui::theme::theme_restore(&orig.theme_state);
1820
1821 v3d->shading.type = orig.v3d_shading_type;
1822
1824}
1825
1827{
1828 /* When rendering gpencil objects this opacity is used to mix vertex colors in. */
1830 /* Initialize wire-frame properties to the default so it renders properly. */
1831 v3d.overlay.wireframe_opacity = 1.0f;
1832 v3d.overlay.wireframe_threshold = 0.5f;
1833}
1834
1835void ED_view3d_draw_offscreen_simple(Depsgraph *depsgraph,
1836 Scene *scene,
1837 View3DShading *shading_override,
1838 bContext *context,
1839 eDrawType drawtype,
1840 int object_type_exclude_viewport_override,
1841 int object_type_exclude_select_override,
1842 int winx,
1843 int winy,
1844 uint draw_flags,
1845 const float viewmat[4][4],
1846 const float winmat[4][4],
1847 float clip_start,
1848 float clip_end,
1849 float xr_vignette_aperture,
1850 bool is_xr_surface,
1851 bool is_image_render,
1852 bool draw_background,
1853 const char *viewname,
1854 const bool do_color_management,
1855 Object *camera_override,
1856 GPUOffScreen *ofs,
1857 GPUViewport *viewport)
1858{
1860 ARegion region = {nullptr};
1861 bke::ARegionRuntime region_runtime{};
1862 region.runtime = &region_runtime;
1863 RegionView3D rv3d;
1864
1865 v3d.regionbase.first_ = v3d.regionbase.last_ = &region;
1866 region.regiondata = &rv3d;
1867 region.regiontype = RGN_TYPE_WINDOW;
1868
1869 View3DShading *source_shading_settings = &scene->display.shading;
1870 if (draw_flags & V3D_OFSDRAW_OVERRIDE_SCENE_SETTINGS && shading_override != nullptr) {
1871 source_shading_settings = shading_override;
1872 }
1873 memcpy(&v3d.shading, source_shading_settings, sizeof(View3DShading));
1875 v3d.shading.type = drawtype;
1876
1877 if (shading_override) {
1878 /* Pass. */
1879 }
1880 else if (drawtype == OB_MATERIAL) {
1882 }
1883
1886 }
1887 else {
1888 if (draw_flags & V3D_OFSDRAW_SHOW_ANNOTATION) {
1890 }
1891 if (draw_flags & V3D_OFSDRAW_SHOW_GRIDFLOOR) {
1893 v3d.grid = 1.0f;
1894 v3d.gridlines = 16;
1895 v3d.gridsubdiv = 10;
1896 }
1897 if (draw_flags & V3D_OFSDRAW_SHOW_SELECTION) {
1898 v3d.flag |= V3D_SELECT_OUTLINE;
1899 }
1900 if (draw_flags & V3D_OFSDRAW_XR_SHOW_CONTROLLERS) {
1902 }
1903 if (draw_flags & V3D_OFSDRAW_XR_SHOW_CUSTOM_OVERLAYS) {
1905 }
1906 if (draw_flags & V3D_OFSDRAW_XR_SHOW_PASSTHROUGH) {
1908 }
1909 /* Disable other overlays (set all available _HIDE_ flags). */
1912 if ((draw_flags & V3D_OFSDRAW_SHOW_OBJECT_EXTRAS) == 0) {
1914 }
1915 if ((object_type_exclude_viewport_override & (1 << OB_ARMATURE)) != 0) {
1917 }
1918 v3d.flag |= V3D_HIDE_HELPLINES;
1919 }
1920
1921 if (is_xr_surface) {
1923 }
1924
1925 v3d.object_type_exclude_viewport = object_type_exclude_viewport_override;
1926 v3d.object_type_exclude_select = object_type_exclude_select_override;
1927
1928 if (camera_override != nullptr) {
1929 /* Override the active View3D camera and force camera perspective. */
1930 rv3d.persp = RV3D_CAMOB;
1931 v3d.camera = camera_override;
1932 }
1933 else {
1934 rv3d.persp = RV3D_PERSP;
1935 }
1936 v3d.clip_start = clip_start;
1937 v3d.clip_end = clip_end;
1938 /* Actually not used since we pass in the projection matrix. */
1939 v3d.lens = 0;
1940 v3d.xr_vignette_aperture = xr_vignette_aperture;
1941
1942 ED_view3d_draw_offscreen(depsgraph,
1943 scene,
1944 drawtype,
1945 &v3d,
1946 &region,
1947 context,
1948 winx,
1949 winy,
1950 viewmat,
1951 winmat,
1952 is_image_render,
1953 draw_background,
1954 viewname,
1955 do_color_management,
1956 true,
1957 ofs,
1958 viewport);
1959}
1960
1962 Scene *scene,
1963 eDrawType drawtype,
1964 View3D *v3d,
1965 ARegion *region,
1966 int sizex,
1967 int sizey,
1968 ImBufFlags imbuf_flag,
1969 int alpha_mode,
1970 const char *viewname,
1971 const bool restore_rv3d_mats,
1972 GPUOffScreen *ofs,
1973 GPUViewport *viewport,
1974 const bool use_camera_view_bounds,
1975 /* output vars */
1976 char err_out[256])
1977{
1978 RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata);
1979 const bool draw_sky = (alpha_mode == R_ADDSKY);
1980
1981 /* view state */
1982 bool is_ortho = false;
1983 float winmat[4][4];
1984
1985 /* Guess format based on output buffer. */
1986 gpu::TextureFormat desired_format = flag_is_set(imbuf_flag, ImBufFlags::FloatData) ?
1987 gpu::TextureFormat::SFLOAT_16_16_16_16 :
1988 gpu::TextureFormat::UNORM_8_8_8_8;
1989
1990 if (ofs && ((GPU_offscreen_width(ofs) != sizex) || (GPU_offscreen_height(ofs) != sizey))) {
1991 /* If offscreen has already been created, recreate with the same format. */
1992 desired_format = GPU_offscreen_format(ofs);
1993 /* sizes differ, can't reuse */
1994 ofs = nullptr;
1995 }
1996
1998
1999 if (old_fb) {
2001 }
2002
2003 const bool own_ofs = (ofs == nullptr);
2005
2006 if (own_ofs) {
2007 /* bind */
2008 ofs = GPU_offscreen_create(sizex,
2009 sizey,
2010 true,
2011 desired_format,
2013 false,
2014 err_out);
2015 if (ofs == nullptr) {
2017 return nullptr;
2018 }
2019 }
2020
2021 GPU_offscreen_bind(ofs, true);
2022
2023 /* read in pixels & stamp */
2024 ImBuf *ibuf = IMB_allocImBuf(sizex, sizey, imbuf_flag);
2025
2026 /* render 3d view */
2027 if (use_camera_view_bounds && rv3d->persp == RV3D_CAMOB && v3d->camera) {
2028 CameraParams params;
2030 *DEG_get_bmain(depsgraph), scene, v3d->camera, viewname);
2031 const Object *camera_eval = DEG_get_evaluated(depsgraph, camera);
2032
2033 BKE_camera_params_init(&params);
2034 /* fallback for non camera objects */
2035 params.clip_start = v3d->clip_start;
2036 params.clip_end = v3d->clip_end;
2037 BKE_camera_params_from_object(&params, camera_eval);
2038 BKE_camera_multiview_params(&scene->r, &params, camera_eval, viewname);
2039 BKE_camera_params_compute_viewplane(&params, sizex, sizey, scene->r.xasp, scene->r.yasp);
2041
2042 is_ortho = params.is_ortho;
2043 copy_m4_m4(winmat, params.winmat);
2044 }
2045 else {
2046 rctf viewplane;
2047 float clip_start, clipend;
2048
2049 is_ortho = ED_view3d_viewplane_get(
2050 depsgraph, v3d, rv3d, sizex, sizey, &viewplane, &clip_start, &clipend, nullptr);
2051 if (is_ortho) {
2052 orthographic_m4(winmat,
2053 viewplane.xmin,
2054 viewplane.xmax,
2055 viewplane.ymin,
2056 viewplane.ymax,
2057 -clipend,
2058 clipend);
2059 }
2060 else {
2061 perspective_m4(winmat,
2062 viewplane.xmin,
2063 viewplane.xmax,
2064 viewplane.ymin,
2065 viewplane.ymax,
2066 clip_start,
2067 clipend);
2068 }
2069 }
2070
2071 /* XXX(jbakker): `do_color_management` should be controlled by the caller. Currently when doing a
2072 * viewport render animation and saving to an 8bit file format, color management would be applied
2073 * twice. Once here, and once when saving the saving to disk. In this case the Save As Render
2074 * option cannot be controlled either. But when doing an off-screen render you want to do the
2075 * color management here.
2076 *
2077 * This option was added here to increase the performance for quick view-port preview renders.
2078 * When using workbench the color differences haven't been reported as a bug. But users also use
2079 * the viewport rendering to render Eevee scenes. In the later situation the saved colors are
2080 * totally wrong. */
2081 const bool do_color_management = (ibuf->float_data() == nullptr);
2082 ED_view3d_draw_offscreen(depsgraph,
2083 scene,
2084 drawtype,
2085 v3d,
2086 region,
2087 nullptr,
2088 sizex,
2089 sizey,
2090 nullptr,
2091 winmat,
2092 true,
2093 draw_sky,
2094 viewname,
2095 do_color_management,
2096 restore_rv3d_mats,
2097 ofs,
2098 viewport);
2099
2100 if (ibuf->float_data()) {
2102 }
2103 else if (ibuf->byte_data()) {
2105 }
2106
2107 /* unbind */
2108 GPU_offscreen_unbind(ofs, true);
2109
2110 if (own_ofs) {
2111 GPU_offscreen_free(ofs);
2112 }
2113
2115
2116 if (old_fb) {
2117 GPU_framebuffer_bind(old_fb);
2118 }
2119
2120 if (ibuf->float_data() && ibuf->byte_data()) {
2121 IMB_byte_from_float(ibuf);
2122 }
2123
2124 return ibuf;
2125}
2126
2128 Scene *scene,
2129 View3DShading *shading_override,
2130 eDrawType drawtype,
2131 Object *camera,
2132 int width,
2133 int height,
2134 ImBufFlags imbuf_flag,
2135 eV3DOffscreenDrawFlag draw_flags,
2136 int alpha_mode,
2137 const char *viewname,
2138 GPUOffScreen *ofs,
2139 GPUViewport *viewport,
2140 char err_out[256])
2141{
2144
2145 ARegion region = {nullptr};
2146 bke::ARegionRuntime region_runtime{};
2147 region.runtime = &region_runtime;
2148 RegionView3D rv3d;
2149
2150 /* connect data */
2151 v3d.regionbase.first_ = v3d.regionbase.last_ = &region;
2152 region.regiondata = &rv3d;
2153 region.regiontype = RGN_TYPE_WINDOW;
2154
2155 v3d.camera = camera;
2156 View3DShading *source_shading_settings = &scene->display.shading;
2157 if (draw_flags & V3D_OFSDRAW_OVERRIDE_SCENE_SETTINGS && shading_override != nullptr) {
2158 source_shading_settings = shading_override;
2159 }
2160 memcpy(&v3d.shading, source_shading_settings, sizeof(View3DShading));
2161
2162 if (drawtype == OB_RENDER) {
2163 /* Don't use external engines for preview. Fall back to solid instead of Eevee as rendering
2164 * with Eevee is potentially slow due to compiling shaders and loading textures, and the
2165 * depsgraph may not have been updated to have all the right geometry attributes. */
2167 drawtype = OB_SOLID;
2168 }
2169 }
2170
2171 if (drawtype == OB_MATERIAL) {
2174 }
2175 else if (drawtype == OB_RENDER) {
2178 }
2179 else if (drawtype == OB_TEXTURE) {
2180 drawtype = OB_SOLID;
2183 }
2184 v3d.shading.type = drawtype;
2185
2187
2188 if (draw_flags & V3D_OFSDRAW_SHOW_ANNOTATION) {
2190 }
2191 if (draw_flags & V3D_OFSDRAW_SHOW_GRIDFLOOR) {
2193 }
2194
2195 if ((draw_flags & V3D_OFSDRAW_NO_WORLD_BACKGROUND_OVERRIDE) == 0) {
2197 }
2198
2199 rv3d.persp = RV3D_CAMOB;
2200
2201 copy_m4_m4(rv3d.viewinv, v3d.camera->object_to_world().ptr());
2202 normalize_m4(rv3d.viewinv);
2203 invert_m4_m4(rv3d.viewmat, rv3d.viewinv);
2204
2205 {
2206 CameraParams params;
2207 const Object *view_camera_eval = DEG_get_evaluated(
2208 depsgraph,
2209 BKE_camera_multiview_render(*DEG_get_bmain(depsgraph), scene, v3d.camera, viewname));
2210
2211 BKE_camera_params_init(&params);
2212 BKE_camera_params_from_object(&params, view_camera_eval);
2213 BKE_camera_multiview_params(&scene->r, &params, view_camera_eval, viewname);
2214 BKE_camera_params_compute_viewplane(&params, width, height, scene->r.xasp, scene->r.yasp);
2216
2217 copy_m4_m4(rv3d.winmat, params.winmat);
2218 v3d.clip_start = params.clip_start;
2219 v3d.clip_end = params.clip_end;
2220 v3d.lens = params.lens;
2221 }
2222
2223 mul_m4_m4m4(rv3d.persmat, rv3d.winmat, rv3d.viewmat);
2224 invert_m4_m4(rv3d.persinv, rv3d.viewinv);
2225
2226 return ED_view3d_draw_offscreen_imbuf(depsgraph,
2227 scene,
2228 eDrawType(v3d.shading.type),
2229 &v3d,
2230 &region,
2231 width,
2232 height,
2233 imbuf_flag,
2234 alpha_mode,
2235 viewname,
2236 true,
2237 ofs,
2238 viewport,
2239 true,
2240 err_out);
2241}
2242
2247
2249
2250/* -------------------------------------------------------------------- */
2253
2254static bool view3d_clipping_test(const float co[3], const float clip[6][4])
2255{
2256 if (plane_point_side_v3(clip[0], co) > 0.0f && plane_point_side_v3(clip[1], co) > 0.0f &&
2257 plane_point_side_v3(clip[2], co) > 0.0f && plane_point_side_v3(clip[3], co) > 0.0f)
2258 {
2259 return false;
2260 }
2261 return true;
2262}
2263
2264bool ED_view3d_clipping_test(const RegionView3D *rv3d, const float co[3], const bool is_local)
2265{
2266 return view3d_clipping_test(co, is_local ? rv3d->clip_local : rv3d->clip);
2267}
2268
2270
2271/* -------------------------------------------------------------------- */
2274
2278static void validate_object_select_id(const Main &bmain,
2279 Depsgraph *depsgraph,
2280 const Scene *scene,
2281 ViewLayer *view_layer,
2282 ARegion *region,
2283 View3D *v3d,
2284 Object *obact)
2285{
2286 /* TODO: Use a flag in the selection engine itself. */
2288 return;
2289 }
2290 Object *obact_eval = DEG_get_evaluated(depsgraph, obact);
2291
2293 UNUSED_VARS_NDEBUG(region);
2294
2295 if (obact_eval && (obact_eval->mode & (OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT) ||
2296 BKE_paint_select_face_test(obact_eval)))
2297 {
2298 /* do nothing */
2299 }
2300 /* texture paint mode sampling */
2301 else if (obact_eval && (obact_eval->mode & OB_MODE_TEXTURE_PAINT) &&
2302 (v3d->shading.type > OB_WIRE))
2303 {
2304 /* do nothing */
2305 }
2306 else if ((obact_eval && (obact_eval->mode & OB_MODE_PARTICLE_EDIT)) && !XRAY_ENABLED(v3d)) {
2307 /* do nothing */
2308 }
2309 else {
2311 return;
2312 }
2313
2314 if (obact_eval && ((obact_eval->base_flag & BASE_ENABLED_AND_MAYBE_VISIBLE_IN_VIEWPORT) != 0)) {
2315 BKE_view_layer_synced_ensure(bmain, scene, view_layer);
2316 Base *base = BKE_view_layer_base_find(view_layer, obact);
2317 DRW_select_buffer_context_create(depsgraph, {base}, -1);
2318 }
2319
2321}
2322
2323/* Avoid calling this function multiple times in sequence to prevent frequent CPU-GPU
2324 * synchronization (which can be very slow). */
2325static void view3d_gpu_read_Z_pixels(GPUViewport *viewport, rcti *rect, void *data)
2326{
2327 gpu::Texture *depth_tx = GPU_viewport_depth_texture(viewport);
2328
2329 gpu::FrameBuffer *depth_read_fb = nullptr;
2330 GPU_framebuffer_ensure_config(&depth_read_fb,
2331 {
2332 GPU_ATTACHMENT_TEXTURE(depth_tx),
2334 });
2335
2336 GPU_framebuffer_bind(depth_read_fb);
2337 GPU_framebuffer_read_depth(depth_read_fb,
2338 rect->xmin,
2339 rect->ymin,
2340 BLI_rcti_size_x(rect),
2341 BLI_rcti_size_y(rect),
2343 data);
2344
2346 GPU_framebuffer_free(depth_read_fb);
2347}
2348
2350{
2352 *vc->bmain, vc->depsgraph, vc->scene, vc->view_layer, vc->region, vc->v3d, vc->obact);
2353}
2354
2355int ED_view3d_backbuf_sample_size_clamp(ARegion *region, const float dist)
2356{
2357 return int(min_ff(ceilf(dist), float(max_ii(region->winx, region->winy))));
2358}
2359
2361
2362/* -------------------------------------------------------------------- */
2365
2367{
2368 /* clamp rect by region */
2369 rcti r{};
2370 r.xmin = 0;
2371 r.xmax = region->winx - 1;
2372 r.ymin = 0;
2373 r.ymax = region->winy - 1;
2374
2375 /* Constrain rect to depth bounds */
2376 BLI_rcti_isect(&r, rect, rect);
2377
2378 /* assign values to compare with the ViewDepths */
2379 int x = rect->xmin;
2380 int y = rect->ymin;
2381
2382 int w = BLI_rcti_size_x(rect);
2383 int h = BLI_rcti_size_y(rect);
2384
2385 if (w <= 0 || h <= 0) {
2386 r_d->depths = nullptr;
2387 return;
2388 }
2389
2390 r_d->x = x;
2391 r_d->y = y;
2392 r_d->w = w;
2393 r_d->h = h;
2394
2395 r_d->depths = MEM_new_array_uninitialized<float>(w * h, "View depths Subset");
2396
2397 {
2398 GPUViewport *viewport = WM_draw_region_get_viewport(region);
2399 view3d_gpu_read_Z_pixels(viewport, rect, r_d->depths);
2400 /* Range is assumed to be this as they are never changed. */
2401 r_d->depth_range[0] = 0.0;
2402 r_d->depth_range[1] = 1.0;
2403 }
2404}
2405
2406/* NOTE: with NOUVEAU drivers the #glReadPixels() is very slow. #24339. */
2408{
2409 ViewDepths *d = MEM_new_zeroed<ViewDepths>("ViewDepths");
2410
2411 GPUViewport *viewport = WM_draw_region_get_viewport(region);
2412 gpu::Texture *depth_tx = GPU_viewport_depth_texture(viewport);
2413 d->w = GPU_texture_width(depth_tx);
2414 d->h = GPU_texture_height(depth_tx);
2415 d->depths = static_cast<float *>(GPU_texture_read(depth_tx, GPU_DATA_FLOAT, 0));
2416 /* Assumed to be this as they are never changed. */
2417 d->depth_range[0] = 0.0;
2418 d->depth_range[1] = 1.0;
2419
2420 return d;
2421}
2422
2423float view3d_depth_near_ex(ViewDepths *d, int r_xy[2])
2424{
2425 /* Convert to float for comparisons. */
2426 const float near = float(d->depth_range[0]);
2427 const float far_real = float(d->depth_range[1]);
2428 float far = far_real;
2429
2430 const float *depths = d->depths;
2431 const int depth_num = int(d->w) * int(d->h); /* Cast to avoid short overflow. */
2432
2433 /* Far is both the starting 'far' value
2434 * and the closest value found. */
2435 if (r_xy != nullptr) {
2436 int index_found = -1;
2437 for (int i = 0; i < depth_num; i++) {
2438 const float depth = *depths++;
2439 if ((depth < far) && (depth > near)) {
2440 far = depth;
2441 index_found = i;
2442 }
2443 }
2444 if (index_found != -1) {
2445 r_xy[0] = d->x + (index_found % int(d->w));
2446 r_xy[1] = d->y + (index_found / int(d->w));
2447 }
2448 }
2449 else {
2450 for (int i = 0; i < depth_num; i++) {
2451 const float depth = depths[i];
2452 if ((depth < far) && (depth > near)) {
2453 far = depth;
2454 }
2455 }
2456 }
2457
2458 return far == far_real ? FLT_MAX : far;
2459}
2460
2462{
2463 return view3d_depth_near_ex(d, nullptr);
2464}
2465
2466void ED_view3d_depth_override(Depsgraph *depsgraph,
2467 ARegion *region,
2468 View3D *v3d,
2469 Object * /* obact */,
2471 bool use_overlay,
2472 ViewDepths **r_depths)
2473{
2475 /* Force redraw if `r_depths` is required. */
2476 if (!r_depths || *r_depths != nullptr) {
2477 return;
2478 }
2479 }
2480 ui::theme::bThemeState theme_state;
2481 Scene *scene = DEG_get_evaluated_scene(depsgraph);
2482 RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata);
2483
2484 eView3D_Flag flag = v3d->flag;
2485 eView3D_Flag2 flag2 = v3d->flag2;
2486 /* Setting these temporarily is not nice */
2487 v3d->flag &= ~V3D_SELECT_OUTLINE;
2488
2489 if (v3d->flag2 & V3D_HIDE_OVERLAYS) {
2490 use_overlay = false;
2491 }
2492
2493 if (!use_overlay) {
2494 v3d->flag2 |= V3D_HIDE_OVERLAYS;
2495 }
2496
2497 /* Tools may request depth outside of regular drawing code. */
2498 ui::theme::theme_store(&theme_state);
2500
2502 G_MAIN->wm.first(), nullptr, depsgraph, scene, region, v3d, nullptr, nullptr, nullptr);
2503
2504 /* get surface depth without bias */
2506
2507 /* Needed in cases the 3D Viewport isn't already setup. */
2510
2511 GPUViewport *viewport = WM_draw_region_get_viewport(region);
2512 /* When Blender is starting, a click event can trigger a depth test while the viewport is not
2513 * yet available. */
2514 if (viewport != nullptr) {
2515 switch (mode) {
2516 case V3D_DEPTH_ALL:
2517 DRW_draw_depth_loop(depsgraph, region, v3d, viewport, true, false, false);
2518 break;
2520 DRW_draw_depth_loop(depsgraph, region, v3d, viewport, false, false, false);
2521 break;
2523 DRW_draw_depth_loop(depsgraph, region, v3d, viewport, true, false, false);
2524 break;
2526 DRW_draw_depth_loop(depsgraph, region, v3d, viewport, false, false, true);
2527 break;
2529 DRW_draw_depth_loop(depsgraph, region, v3d, viewport, false, true, false);
2530 break;
2531 }
2532
2533 if (r_depths) {
2534 if (*r_depths) {
2535 ED_view3d_depths_free(*r_depths);
2536 }
2537 *r_depths = view3d_depths_create(region);
2538 }
2539 }
2540
2542
2544
2545 /* Restore. */
2546 v3d->flag = flag;
2547 v3d->flag2 = flag2;
2549
2550 ui::theme::theme_restore(&theme_state);
2551}
2552
2554{
2555 if (depths->depths) {
2556 MEM_delete(depths->depths);
2557 }
2558 MEM_delete(depths);
2559}
2560
2561bool ED_view3d_has_depth_buffer_updated(const Depsgraph *depsgraph, const View3D *v3d)
2562{
2563#ifdef REUSE_DEPTH_BUFFER
2564 /* Check if the depth buffer was drawn by any engine and thus can be reused.
2565 *
2566 * The idea is good, but it is too error prone.
2567 * Even when updated by an engine, the depth buffer can still be cleared by drawing callbacks and
2568 * by the GPU_select API used by gizmos.
2569 * Check #GPU_clear_depth to track when the depth buffer is cleared. */
2570 const char *engine_name = DEG_get_evaluated_scene(depsgraph)->r.engine;
2571 RenderEngineType *engine_type = RE_engines_find(engine_name);
2572
2573 bool is_viewport_wire_no_xray = v3d->shading.type < OB_SOLID && !XRAY_ENABLED(v3d);
2574 bool is_viewport_preview_solid = v3d->shading.type == OB_SOLID;
2575 bool is_viewport_preview_material = v3d->shading.type == OB_MATERIAL;
2576 bool is_viewport_render_eevee = v3d->shading.type == OB_RENDER &&
2577 (STREQ(engine_name, RE_engine_id_BLENDER_EEVEE));
2578 bool is_viewport_render_workbench = v3d->shading.type == OB_RENDER &&
2580 bool is_viewport_render_external_with_overlay = v3d->shading.type == OB_RENDER &&
2581 !(engine_type->flag & RE_INTERNAL) &&
2582 !(v3d->flag2 & V3D_HIDE_OVERLAYS);
2583
2584 return is_viewport_preview_solid || is_viewport_preview_material || is_viewport_wire_no_xray ||
2585 is_viewport_render_eevee || is_viewport_render_workbench ||
2586 is_viewport_render_external_with_overlay;
2587#else
2588 UNUSED_VARS(depsgraph, v3d);
2589 return false;
2590#endif
2591}
2592
2594
2595/* -------------------------------------------------------------------- */
2598
2599void ED_view3d_datamask(const Main &bmain,
2600 const Scene *scene,
2601 ViewLayer *view_layer,
2602 const View3D *v3d,
2603 CustomData_MeshMasks *r_cddata_masks)
2604{
2605 /* NOTE(@ideasman42): as this function runs continuously while idle
2606 * (from #wm_event_do_depsgraph) take care to avoid expensive lookups.
2607 * While they won't hurt performance noticeably, they will increase CPU usage while idle. */
2610 r_cddata_masks->vmask |= CD_MASK_ORCO | CD_MASK_PROP_COLOR;
2611 }
2612 else if (v3d->shading.type == OB_SOLID) {
2614 r_cddata_masks->lmask |= CD_MASK_PROP_FLOAT2;
2615 }
2617 r_cddata_masks->lmask |= CD_MASK_PROP_BYTE_COLOR;
2618 r_cddata_masks->vmask |= CD_MASK_ORCO | CD_MASK_PROP_COLOR;
2619 }
2620 }
2621
2622 BKE_view_layer_synced_ensure(bmain, scene, view_layer);
2623 Object *obact = BKE_view_layer_active_object_get(view_layer);
2624 if (obact) {
2625 switch (obact->type) {
2626 case OB_MESH: {
2627 switch (obact->mode) {
2628 case OB_MODE_EDIT: {
2630 r_cddata_masks->vmask |= CD_MASK_MDEFORMVERT;
2631 }
2632 break;
2633 }
2634 default:
2635 break;
2636 }
2637 break;
2638 }
2639 default:
2640 break;
2641 }
2642 }
2643}
2644
2646 const Scene *scene,
2647 ViewLayer *view_layer,
2648 const bScreen *screen,
2649 CustomData_MeshMasks *r_cddata_masks)
2650{
2652
2653 /* Check if we need UV or color data due to the view mode. */
2654 for (const ScrArea &area : screen->areabase) {
2655 if (area.spacetype == SPACE_VIEW3D) {
2657 bmain, scene, view_layer, area.spacedata.first_as<View3D>(), r_cddata_masks);
2658 }
2659 }
2660}
2661
2663
2664/* -------------------------------------------------------------------- */
2667
2676 float winmat[4][4];
2677 float viewmat[4][4];
2678 float viewinv[4][4];
2679 float persmat[4][4];
2680 float persinv[4][4];
2682 float pixsize;
2683};
2684
2686{
2688 copy_m4_m4(rv3dmat->winmat, rv3d->winmat);
2689 copy_m4_m4(rv3dmat->viewmat, rv3d->viewmat);
2690 copy_m4_m4(rv3dmat->persmat, rv3d->persmat);
2691 copy_m4_m4(rv3dmat->persinv, rv3d->persinv);
2692 copy_m4_m4(rv3dmat->viewinv, rv3d->viewinv);
2694 rv3dmat->pixsize = rv3d->pixsize;
2695 return rv3dmat;
2696}
2697
2699{
2700 RV3DMatrixStore *rv3dmat = rv3dmat_pt;
2701 copy_m4_m4(rv3d->winmat, rv3dmat->winmat);
2702 copy_m4_m4(rv3d->viewmat, rv3dmat->viewmat);
2703 copy_m4_m4(rv3d->persmat, rv3dmat->persmat);
2704 copy_m4_m4(rv3d->persinv, rv3dmat->persinv);
2705 copy_m4_m4(rv3d->viewinv, rv3dmat->viewinv);
2707 rv3d->pixsize = rv3dmat->pixsize;
2708}
2709
2711{
2712 MEM_delete(rv3d_mat);
2713}
2714
2716
2717/* -------------------------------------------------------------------- */
2720
2721void ED_scene_draw_fps(const Scene *scene, int xoffset, int *yoffset)
2722{
2723 *yoffset -= VIEW3D_OVERLAY_LINEHEIGHT;
2724
2726 if (!ED_scene_fps_average_calc(scene, &state)) {
2727 return;
2728 }
2729
2730 /* 8 4-bytes chars (complex writing systems like Devanagari in UTF8 encoding) */
2731 char printable[32];
2732 printable[0] = '\0';
2733
2734 bool show_fractional = state.fps_target_is_fractional;
2735
2736 const int font_id = BLF_default();
2737
2738 /* Is this more than half a frame behind? */
2739 if (state.fps_average + 0.5f < state.fps_target) {
2740 /* Always show fractional when under performing. */
2741 show_fractional = true;
2742 float4 alert_rgb = get_low_fps_color();
2743 BLF_color4fv(font_id, alert_rgb);
2744 }
2745
2746 if (show_fractional) {
2747 SNPRINTF_UTF8(printable, IFACE_("fps: %.2f"), state.fps_average);
2748 }
2749 else {
2750 SNPRINTF_UTF8(printable, IFACE_("fps: %i"), int(state.fps_average + 0.5f));
2751 }
2752
2753 BLF_draw_default(xoffset, *yoffset, 0.0f, printable, sizeof(printable));
2754}
2755
2757
2758/* -------------------------------------------------------------------- */
2761
2763{
2764 RenderEngineType *type = RE_engines_find(scene->r.engine);
2765 return (type && type->view_update && type->view_draw);
2766}
2767
2769 const Scene *scene, Depsgraph *depsgraph, View3D *v3d, ARegion *region, rcti *r_rect)
2770{
2771 const RegionView3D *rv3d = static_cast<const RegionView3D *>(region->regiondata);
2772
2773 /* Test if there is a 3d view rendering. */
2775 return false;
2776 }
2777
2778 rctf border;
2780 scene, depsgraph, v3d, rv3d, region->winx, region->winy, &border, nullptr))
2781 {
2782 return false;
2783 }
2784
2785 BLI_rcti_rctf_copy_floor(r_rect, &border);
2786
2787 BLI_rcti_translate(r_rect, region->winrct.xmin, region->winrct.ymin);
2788 BLI_rcti_isect(&region->winrct, r_rect, r_rect);
2789
2790 return true;
2791}
2792
2794
2795/* -------------------------------------------------------------------- */
2798
2800{
2801 GPUViewport *viewport = WM_draw_region_get_viewport(region);
2802 if (viewport == nullptr) {
2803 return false;
2804 }
2805
2806 gpu::Texture *color_tex = GPU_viewport_color_texture(viewport, 0);
2807 if (color_tex == nullptr) {
2808 return false;
2809 }
2810
2811 tex_w = GPU_texture_width(color_tex);
2812 tex_h = GPU_texture_height(color_tex);
2813 BLI_rcti_init(&valid_rect, 0, min_ii(region->winx, tex_w) - 1, 0, min_ii(region->winy, tex_h));
2814
2815 /* Copying pixels from textures only works when HOST_READ usage is enabled on them.
2816 * However, doing so can have performance impact, which we don't want for the viewport.
2817 * So, instead allocate a separate texture with HOST_READ here, copy to it, and then
2818 * copy that back to the host.
2819 * Since color picking is a fairly rare operation, the inefficiency here doesn't really
2820 * matter, and it means the viewport doesn't need HOST_READ. */
2821 tex = GPU_texture_create_2d("copy_tex",
2822 tex_w,
2823 tex_h,
2824 1,
2825 gpu::TextureFormat::SFLOAT_16_16_16_16,
2827 nullptr);
2828 if (tex == nullptr) {
2829 return false;
2830 }
2831
2832 GPU_texture_copy(tex, color_tex);
2834 data = static_cast<ushort4 *>(GPU_texture_read(tex, GPU_DATA_HALF_FLOAT, 0));
2835
2836 return true;
2837}
2838
2839bool ViewportColorSampleSession::sample(const int mval[2], float r_col[3])
2840{
2841 if (tex == nullptr || data == nullptr) {
2842 return false;
2843 }
2844
2845 if (!BLI_rcti_isect_pt_v(&valid_rect, mval)) {
2846 return false;
2847 }
2848
2849 ushort4 pixel = data[mval[1] * tex_w + mval[0]];
2850
2851 if (math::half_to_float(pixel.w) < 0.5f) {
2852 /* Background etc. are not rendered to the viewport texture, so fall back to basic color
2853 * picking for those. */
2854 return false;
2855 }
2856
2857 r_col[0] = math::half_to_float(pixel.x);
2858 r_col[1] = math::half_to_float(pixel.y);
2859 r_col[2] = math::half_to_float(pixel.z);
2860
2861 return true;
2862}
2863
2865{
2866 if (data != nullptr) {
2867 MEM_delete(data);
2868 }
2869 if (tex != nullptr) {
2870 GPU_texture_free(tex);
2871 }
2872}
2873
2875
2876} // namespace blender
C++ functions to deal with Armature collections (i.e. the successor of bone layers).
Functions to insert, delete or modify keyframes.
Camera data-block and utility functions.
CustomData interface, see also DNA_customdata_types.h.
#define G_MAIN
Low-level operations for grease pencil.
General operations, lookup, etc. for blender objects.
#define M_PI
#define RAD2DEG(_rad)
#define SNPRINTF_UTF8(dst, format,...)
#define BLI_STR_UTF8_MULTIPLICATION_SIGN
Platform independent time functions.
#define IFACE_(msgid)
#define MAX_ID_NAME
Definition DNA_ID.h:367
Object is a sort of wrapper for general info.
#define STEREO_LEFT_NAME
#define STEREO_RIGHT_NAME
#define UI_SCALE_FAC
#define NDOF_IS_ORBIT_AROUND_CENTER_MODE(userdef)
#define RV3D_VIEW_IS_AXIS(view)
#define RV3D_LOCK_FLAGS(rv3d)
#define RV3D_CLIPPING_ENABLED(v3d, rv3d)
#define XRAY_ENABLED(v3d)
#define GPU_ATTACHMENT_TEXTURE(_texture)
#define GPU_ATTACHMENT_NONE
#define GPU_framebuffer_ensure_config(_fb,...)
Read Blender memory allocation and freeing.
#define C
Definition RandGen.cpp:29
#define UI_UNIT_Y
#define UI_FSTYLE_WIDGET
#define UI_DEFAULT_TEXT_POINTS
#define UI_UNIT_X
#define UNUSED_VARS(...)
#define UNUSED_VARS_NDEBUG(...)
#define SET_FLAG_FROM_TEST(value, test, flag)
#define ELEM(...)
#define STREQ(a, b)
#define CD_MASK_PROP_BYTE_COLOR
#define CD_MASK_PROP_COLOR
#define CD_MASK_ORCO
#define CD_MASK_MDEFORMVERT
#define CD_MASK_PROP_FLOAT2
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition btQuadWord.h:119
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
Definition btVector3.h:356
Definition scene.h:133
constexpr StringRef()
bool sample(const int mval[2], float r_col[3])
constexpr int64_t size() const
constexpr const char * data() const
#define powf(x, y)
#define hypotf(x, y)
#define acosf(x)
#define FLT_MAX
#define layer
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
void camera(KernelGlobals &kg, const ShadingData &sd, float3 &outview, float &outdepth, float &outdist)
float3x3 scale(float3x3 mat, float2 scale)
const int state
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
Definition math_dual.h:263
bool id_frame_has_keyframe(ID *id, float frame)
internal::ShallowZeroInitializeTag shallow_zero_initialize()
Definition DNA_defs.h:159
T max(const T &a, const T &b)
float half_to_float(uint16_t v)
Definition math_half.cc:113
void font_theme_color_set(int fontid, int colorid)
void theme_store(bThemeState *theme_state)
void theme_set(int spacetype, int regionid)
void get_color_4fv(int colorid, float col[4])
void get_color_shade_3fv(int colorid, int offset, float col[3])
void get_color_blend_3f(int colorid1, int colorid2, float fac, float r_col[3])
void theme_restore(const bThemeState *theme_state)
void draw_safe_areas(uint pos, const rctf *rect, const float title_aspect[2], const float action_aspect[2])
void fontstyle_set(const uiFontStyle *fs)
BMesh Iterators.
void DRW_gpu_context_enable()
@ V3D_OVERLAY_HIDE_OBJECT_ORIGINS
@ V3D_OVERLAY_HIDE_MOTION_PATHS
@ V3D_OVERLAY_PERFORMANCE
@ V3D_OVERLAY_HIDE_OBJECT_XTRAS
@ V3D_OVERLAY_HIDE_CURSOR
MINLINE float min_ff(float a, float b)
void CustomData_MeshMasks_update(CustomData_MeshMasks *mask_dst, const CustomData_MeshMasks *mask_src)
Definition customdata.cc:89
void GPU_framebuffer_bind(gpu::FrameBuffer *fb)
void * MEM_new_uninitialized(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
UserDef U
Definition blender.cc:58
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void view3d_viewmatrix_set(const Depsgraph *depsgraph, const Scene *scene, const View3D *v3d, RegionView3D *rv3d, const float rect_scale[2])
bool ED_view3d_viewplane_get(const Depsgraph *depsgraph, const View3D *v3d, const RegionView3D *rv3d, int winx, int winy, rctf *r_viewplane, float *r_clip_start, float *r_clip_end, float *r_pixsize)
MINLINE void negate_v3_v3(float r[3], const float a[3])
gpu::Texture * GPU_viewport_color_texture(GPUViewport *viewport, int view)
static void draw_viewport_name(ARegion *region, View3D *v3d, int xoffset, int *yoffset)
double BKE_unit_scalar_get(const void *usys_pt, int index)
Definition unit.cc:2638
@ V3D_RUNTIME_DEPTHBUF_OVERRIDDEN
bool WM_xr_session_state_viewer_pose_matrix_info_get(const wmXrData *xr, float r_viewmat[4][4], float *r_focal_len)
gpu::FrameBuffer * GPU_framebuffer_active_get()
ImBuf * ED_view3d_draw_offscreen_imbuf(Depsgraph *depsgraph, Scene *scene, eDrawType drawtype, View3D *v3d, ARegion *region, int sizex, int sizey, ImBufFlags imbuf_flag, int alpha_mode, const char *viewname, bool restore_rv3d_mats, GPUOffScreen *ofs, GPUViewport *viewport, bool use_camera_view_bounds, char err_out[256])
bool ED_view3d_draw_offscreen_check_nested()
std::optional< double > DEG_get_last_evaluation_time(const Depsgraph *depsgraph)
static void draw_performance_stats(Depsgraph *depsgraph, Scene *scene, View3D *v3d, const float text_color[4], const int xoffset, int *yoffset, const int line_height)
static void validate_object_select_id(const Main &bmain, Depsgraph *depsgraph, const Scene *scene, ViewLayer *view_layer, ARegion *region, View3D *v3d, Object *obact)
void GPU_offscreen_free(GPUOffScreen *offscreen)
void DRW_draw_view(const bContext *C)
uint padding(uint offset, uint alignment)
Object * BKE_view_layer_active_object_get(const ViewLayer *view_layer)
void BLF_shadow_offset(int fontid, int x, int y)
Definition blf.cc:979
const CustomData_MeshMasks CD_MASK_BAREMESH
void immEnd()
void BKE_camera_multiview_view_matrix(const struct RenderData *rd, const struct Object *camera, bool is_left, float r_viewmat[4][4])
void GPU_framebuffer_restore()
void ED_draw_composition_guides(uint shdr_pos, eCompositionGuideFlags flag, const rctf *rect, const float color[4])
Definition ed_draw.cc:1196
float BLF_width(int fontid, const char *str, size_t str_len, ResultBLF *r_info=nullptr) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(2)
Definition blf.cc:835
void immUniformColor3f(float r, float g, float b)
unsigned int uint
Definition BKE_text.h:55
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
const char * BKE_collection_ui_name_get(Collection *collection)
void immAttr4ubv(uint attr_id, const unsigned char data[4])
WorkSpace * CTX_wm_workspace(const bContext *C)
void BLF_shadow(int fontid, FontShadowType type, const float rgba[4]=nullptr)
Definition blf.cc:967
void GPU_framebuffer_free(gpu::FrameBuffer *fb)
void ED_view3d_depths_free(ViewDepths *depths)
MINLINE void add_v3_v3v3(float r[3], const float a[3], const float b[3])
bool BLI_rcti_isect(const struct rcti *src1, const struct rcti *src2, struct rcti *dest)
void immUniform2f(const char *name, float x, float y)
@ BASE_ENABLED_AND_MAYBE_VISIBLE_IN_VIEWPORT
Depsgraph * CTX_data_depsgraph_pointer(const bContext *C)
void GPU_matrix_identity_set()
void GPU_viewport_tag_update(GPUViewport *viewport)
static bool view3d_stereo3d_active(wmWindow *win, const Scene *scene, View3D *v3d, RegionView3D *rv3d)
static void drawviewborder(Scene *scene, Depsgraph *depsgraph, ARegion *region, View3D *v3d)
@ NDOF_SHOW_GUIDE_ORBIT_CENTER
@ NDOF_SHOW_GUIDE_ORBIT_AXIS
GPUVertFormat * immVertexFormat()
void view3d_depths_rect_create(ARegion *region, rcti *rect, ViewDepths *r_d)
bool BKE_camera_view_render_border(const struct Scene *scene, const struct Depsgraph *depsgraph, const struct View3D *v3d, const struct RegionView3D *rv3d, int winx, int winy, rctf *r_border, rctf *r_unrolled_border)
static void view3d_main_region_setup_offscreen(Depsgraph *depsgraph, const Scene *scene, View3D *v3d, ARegion *region, const float viewmat[4][4], const float winmat[4][4])
@ GPU_DATA_HALF_FLOAT
float view3d_depth_near_ex(ViewDepths *d, int r_xy[2])
static ViewDepths * view3d_depths_create(ARegion *region)
void BLF_batch_draw_begin()
Definition blf.cc:536
static const char * view3d_get_name(View3D *v3d, RegionView3D *rv3d)
bool invert_m4_m4(float inverse[4][4], const float mat[4][4])
@ RE_INTERNAL
Definition RE_engine.h:45
@ RE_USE_EEVEE_VIEWPORT
Definition RE_engine.h:48
void ED_view3d_update_viewmat(const Depsgraph *depsgraph, const Scene *scene, View3D *v3d, ARegion *region, const float viewmat[4][4], const float winmat[4][4], const rcti *rect, bool offscreen)
void immBegin(GPUPrimType, uint vertex_len)
void GPU_texture_copy(gpu::Texture *dst, gpu::Texture *src)
void BKE_camera_params_compute_viewplane(CameraParams *params, int winx, int winy, float aspx, float aspy)
@ V3D_OFSDRAW_SHOW_OBJECT_EXTRAS
@ V3D_OFSDRAW_XR_SHOW_PASSTHROUGH
@ V3D_OFSDRAW_SHOW_SELECTION
@ V3D_OFSDRAW_OVERRIDE_SCENE_SETTINGS
@ V3D_OFSDRAW_XR_SHOW_CONTROLLERS
@ V3D_OFSDRAW_XR_SHOW_CUSTOM_OVERLAYS
@ V3D_OFSDRAW_NO_WORLD_BACKGROUND_OVERRIDE
@ V3D_OFSDRAW_SHOW_ANNOTATION
@ V3D_OFSDRAW_SHOW_GRIDFLOOR
static void view3d_draw_grease_pencil(const bContext *)
static void view3d_update_viewer_path(const bContext *C)
void GPU_line_smooth(bool enable)
Definition gpu_state.cc:80
void axis_angle_to_quat(float r[4], const float axis[3], float angle)
void ED_view3d_grid_steps(const Scene *scene, const View3D *v3d, const RegionView3D *rv3d, float r_grid_steps[8])
@ GPU_PRIM_LINE_STRIP
@ GPU_PRIM_LINE_LOOP
void GPU_depth_mask(bool depth)
Definition gpu_state.cc:107
void mul_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4])
wmWindow * CTX_wm_window(const bContext *C)
@ V3D_XR_SESSION_SURFACE
bool WM_stereo3d_enabled(wmWindow *win, bool skip_stereo3d_check)
Definition wm_stereo.cc:141
RenderEngineType * ED_view3d_engine_type(const Scene *scene, int drawtype)
MINLINE int max_ii(int a, int b)
@ TH_TIME_GP_KEYFRAME
@ TH_CAMERA_PASSEPARTOUT
@ TH_KEYTYPE_KEYFRAME_SELECT
static bool view3d_clipping_test(const float co[3], const float clip[6][4])
void GPU_matrix_rotate_2d(float deg)
bool ANIM_bonecoll_is_visible_actbone(const bArmature *armature)
@ CAMERA_SENSOR_FIT_AUTO
@ CAMERA_SENSOR_FIT_HOR
const rcti * ED_region_visible_rect(ARegion *region)
Definition area.cc:4791
static void view3d_stereo3d_setup_offscreen(Depsgraph *depsgraph, const Scene *scene, View3D *v3d, ARegion *region, const float winmat[4][4], const char *viewname)
int GPU_offscreen_width(const GPUOffScreen *offscreen)
void immUniformThemeColorAlpha(int color_id, float a)
void BLF_disable(int fontid, FontFlags flag)
Definition blf.cc:331
@ V3D_SHADING_SCENE_WORLD
@ V3D_SHADING_SCENE_LIGHTS
@ V3D_SHADING_SCENE_LIGHTS_RENDER
@ V3D_SHADING_SCENE_WORLD_RENDER
const char * RE_engine_id_BLENDER_WORKBENCH
Definition scene.cc:1719
static void view3d_main_region_setup_view(Depsgraph *depsgraph, Scene *scene, View3D *v3d, ARegion *region, const float viewmat[4][4], const float winmat[4][4], const rcti *rect)
void immUnbindProgram()
void perspective_m4(float mat[4][4], float left, float right, float bottom, float top, float nearClip, float farClip)
@ V3D_XR_SHOW_CONTROLLERS
@ V3D_XR_SHOW_CUSTOM_OVERLAYS
@ V3D_SHOW_CAMERA_PASSEPARTOUT
@ V3D_XR_SHOW_PASSTHROUGH
void DRW_cache_free_old_batches(Main *bmain)
void immUniformColor3ubv(const unsigned char rgb[3])
ViewLayer * CTX_data_view_layer(const bContext *C)
void WM_draw_region_viewport_bind(ARegion *region)
Definition wm_draw.cc:1837
void GPU_line_width(float width)
Definition gpu_state.cc:151
void GPU_matrix_scale_2f(float x, float y)
@ GPU_BLEND_NONE
Definition GPU_state.hh:88
@ GPU_BLEND_ALPHA
Definition GPU_state.hh:90
void normalize_m4(float R[4][4]) ATTR_NONNULL()
void BKE_camera_multiview_params(const struct RenderData *rd, struct CameraParams *params, const struct Object *camera, const char *viewname)
const char * RE_engine_id_BLENDER_EEVEE
Definition scene.cc:1717
@ RV3D_ZOFFSET_DISABLED
Global G
Definition blender.cc:57
static void view3d_draw_offscreen_set_overlay_defaults(View3D &v3d)
@ USER_MINI_AXIS_TYPE_GIZMO
@ USER_MINI_AXIS_TYPE_MINIMAL
VecBase< float, 4 > float4
void mul_qt_v3(const float q[4], float r[3])
void orthographic_m4(float mat[4][4], float left, float right, float bottom, float top, float nearClip, float farClip)
void immBindBuiltinProgram(GPUBuiltinShader shader_id)
@ RV3D_VIEW_AXIS_ROLL_180
void BKE_camera_params_compute_matrix(CameraParams *params)
float BKE_camera_multiview_shift_x(const struct RenderData *rd, const struct Object *camera, const char *viewname)
void * BLI_findlink(const ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:541
void DRW_gpu_context_disable()
int BLF_set_default()
void immUniformThemeColor(int color_id)
BLI_INLINE int BLI_rcti_size_y(const struct rcti *rct)
Definition BLI_rect.hh:207
bool DRW_draw_in_progress()
void ED_view3d_mats_rv3d_restore(RegionView3D *rv3d, RV3DMatrixStore *rv3dmat)
void immUniform1f(const char *name, float x)
@ GPU_DEPTH_NONE
Definition GPU_state.hh:132
LayerCollection * BKE_view_layer_active_collection_get(ViewLayer *view_layer)
int GPU_offscreen_height(const GPUOffScreen *offscreen)
bool BKE_scene_uses_blender_eevee(const Scene *scene)
Definition scene.cc:3077
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
struct Object * BKE_camera_multiview_render(const Main &bmain, const struct Scene *scene, struct Object *camera, const char *viewname)
void DRW_select_buffer_context_create(Depsgraph *depsgraph, Span< Base * > bases, short select_mode)
void immVertex2f(uint attr_id, float x, float y)
unsigned char uchar
Definition BKE_text.h:58
void ED_scene_draw_fps(const Scene *scene, int xoffset, int *yoffset)
void GPU_offscreen_unbind(GPUOffScreen *offscreen, bool restore)
@ GPU_TEXTURE_USAGE_SHADER_READ
@ GPU_TEXTURE_USAGE_HOST_READ
MINLINE void cross_v3_v3v3(float r[3], const float a[3], const float b[3])
void GPU_memory_barrier(GPUBarrier barrier)
Definition gpu_state.cc:305
void GPU_viewport_size_get_f(float coords[4])
Definition gpu_state.cc:258
Main * DEG_get_bmain(const Depsgraph *graph)
void immAttr4fv(uint attr_id, const float data[4])
@ OB_MODE_TEXTURE_PAINT
@ OB_MODE_PARTICLE_EDIT
BMesh const char void * data
void ED_view3D_mats_rv3d_free(RV3DMatrixStore *rv3d_mat)
Object * BKE_object_pose_armature_get(Object *ob)
Definition object.cc:2507
T * DEG_get_evaluated(const Depsgraph *depsgraph, T *id)
int BLF_default()
@ GPU_SHADER_3D_LINE_DASHED_UNIFORM_COLOR
@ GPU_SHADER_3D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA
void immUniform4fv(const char *name, const float data[4])
BLI_INLINE float BLI_rctf_size_y(const struct rctf *rct)
Definition BLI_rect.hh:215
wmWindowManager * CTX_wm_manager(const bContext *C)
static bool is_grease_pencil_with_layer_keyframe(const Object &ob)
void immUniformThemeColor3(int color_id)
void BKE_camera_params_from_object(CameraParams *params, const struct Object *cam_ob)
bool ED_view3d_calc_render_border(const Scene *scene, Depsgraph *depsgraph, View3D *v3d, ARegion *region, rcti *r_rect)
rctf BKE_camera_view_border(const struct Scene *scene, const struct Depsgraph *depsgraph, const struct View3D *v3d, const struct RegionView3D *rv3d, int winx, int winy, bool no_shift, bool no_zoom, bool no_roll)
void BKE_viewer_path_copy(ViewerPath *dst, const ViewerPath *src)
void DRW_draw_depth_loop(Depsgraph *depsgraph, ARegion *region, View3D *v3d, GPUViewport *viewport, const bool use_gpencil, const bool use_only_selected, const bool use_only_active_object)
float ED_view3d_grid_view_scale(const Scene *scene, const View3D *v3d, const ARegion *region, const char **r_grid_unit)
void BLI_rcti_translate(struct rcti *rect, int x, int y)
Definition rct.cc:580
int GPU_texture_width(const gpu::Texture *texture)
void DRW_draw_render_loop_offscreen(Depsgraph *depsgraph, RenderEngineType *engine_type, ARegion *region, View3D *v3d, bContext *context, bool is_image_render, bool draw_background, bool do_color_management, GPUOffScreen *ofs, GPUViewport *viewport)
constexpr size_t ARRAY_SIZE(const T(&arg)[N]) noexcept
bool BKE_view_layer_synced_ensure(const Main &bmain, const Scene *scene, ViewLayer *view_layer)
float ED_scene_grid_scale(const Scene *scene, const char **r_grid_unit)
MINLINE float plane_point_side_v3(const float plane[4], const float co[3])
float ED_view3d_grid_scale(const Scene *scene, const View3D *v3d, const char **r_grid_unit)
void DRW_draw_region_engine_info(int xoffset, int *yoffset, int line_height)
void ED_view3d_draw_offscreen_simple(Depsgraph *depsgraph, Scene *scene, View3DShading *shading_override, bContext *context, eDrawType drawtype, int object_type_exclude_viewport_override, int object_type_exclude_select_override, int winx, int winy, unsigned int draw_flags, const float viewmat[4][4], const float winmat[4][4], float clip_start, float clip_end, float xr_vignette_aperture, bool is_xr_surface, bool is_image_render, bool draw_background, const char *viewname, bool do_color_management, Object *camera_override, GPUOffScreen *ofs, GPUViewport *viewport)
static void draw_grid_unit_name(Scene *scene, ARegion *region, View3D *v3d, int xoffset, int *yoffset)
bool ED_scene_fps_average_calc(const Scene *scene, SceneFPS_State *r_state) ATTR_NONNULL(1
Definition scene_fps.cc:102
@ GPU_BARRIER_TEXTURE_UPDATE
Definition GPU_state.hh:42
void immUniformThemeColorShadeAlpha(int color_id, int color_offset, int alpha_offset)
bool view3d_camera_border_hack_test
Definition drawobject.cc:15
void BKE_image_free_old_buffers(Main *bmain)
void BKE_unit_system_get(int system, int type, const void **r_usys_pt, int *r_len)
Definition unit.cc:2576
bool BKE_paint_select_face_test(const Object *ob)
void GPU_offscreen_bind(GPUOffScreen *offscreen, bool save)
void ED_view3d_datamask(const Main &bmain, const Scene *scene, ViewLayer *view_layer, const View3D *v3d, CustomData_MeshMasks *r_cddata_masks)
void GPU_matrix_projection_set(const float m[4][4])
static float4 get_low_fps_color()
void WM_draw_region_viewport_ensure(Scene *scene, ARegion *region, short space_type)
Definition wm_draw.cc:1831
@ V3D_SHADING_VERTEX_COLOR
@ V3D_SHADING_TEXTURE_COLOR
void GPU_matrix_translate_2f(float x, float y)
void BLF_batch_draw_end()
Definition blf.cc:549
uint GPU_vertformat_attr_add(GPUVertFormat *format, StringRef name, gpu::VertAttrType type)
BLI_INLINE int BLI_rcti_size_x(const struct rcti *rct)
Definition BLI_rect.hh:203
int BKE_camera_sensor_fit(int sensor_fit, float sizex, float sizey)
bool BKE_scene_multiview_is_stereo3d(const RenderData *rd)
Definition scene.cc:3224
bool ED_view3d_has_depth_buffer_updated(const Depsgraph *depsgraph, const View3D *v3d)
RenderEngineType * RE_engines_find(const char *idname)
bool BKE_viewer_path_equal(const ViewerPath *a, const ViewerPath *b, ViewerPathEqualFlag flag=ViewerPathEqualFlag(0))
static void view3d_draw_view(const bContext *C, ARegion *region)
ImBuf * IMB_allocImBuf(unsigned int x, unsigned int y, ImBufFlags flags)
void BLI_rcti_init(struct rcti *rect, int xmin, int xmax, int ymin, int ymax)
Definition rct.cc:428
void ED_view3d_select_id_validate(const ViewContext *vc)
@ CAM_SHOW_SAFE_MARGINS
MINLINE void mul_v3_v3fl(float r[3], const float a[3], float f)
RV3DMatrixStore * ED_view3d_mats_rv3d_backup(RegionView3D *rv3d)
void BLF_draw_default(float x, float y, float z, const char *str, size_t str_len) ATTR_NONNULL()
static void view3d_gpu_read_Z_pixels(GPUViewport *viewport, rcti *rect, void *data)
@ V3D_SHADING_BACKGROUND_WORLD
MINLINE void add_v3_v3(float r[3], const float a[3])
void immVertex3fv(uint attr_id, const float data[3])
bScreen * ED_screen_animation_no_scrub(const wmWindowManager *wm)
void view3d_winmatrix_set(const Depsgraph *depsgraph, ARegion *region, const View3D *v3d, const rcti *rect)
void view3d_draw_region_info(const bContext *C, ARegion *region)
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
void ED_region_pixelspace(const ARegion *region)
Definition area.cc:96
bool ED_view3d_clipping_test(const RegionView3D *rv3d, const float co[3], bool is_local)
Depsgraph * CTX_data_expect_evaluated_depsgraph(const bContext *C)
void immUniform4f(const char *name, float x, float y, float z, float w)
bool BKE_scene_uses_blender_workbench(const Scene *scene)
Definition scene.cc:3082
@ G_FLAG_RENDER_VIEWPORT
Main * CTX_data_main(const bContext *C)
void size_t BLI_string_len_array(const char *strings[], uint strings_num) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
ATTR_WARN_UNUSED_RESULT const BMVert * v2
gpu::Texture * GPU_viewport_depth_texture(GPUViewport *viewport)
void IMB_byte_from_float(ImBuf *ibuf)
void GPU_matrix_pop_projection()
int BKE_unit_base_get(const void *usys_pt)
Definition unit.cc:2589
void imm_draw_box_wire_2d(uint pos, float x1, float y1, float x2, float y2)
BLI_INLINE float BLI_rctf_size_x(const struct rctf *rct)
Definition BLI_rect.hh:211
static bool view3d_main_region_do_render_draw(const Scene *scene)
int GPU_texture_height(const gpu::Texture *texture)
int ED_view3d_backbuf_sample_size_clamp(ARegion *region, float dist)
static void drawrenderborder(ARegion *region, View3D *v3d)
uchar view3d_camera_border_hack_col[3]
Definition drawobject.cc:14
void ED_view3d_depth_override(Depsgraph *depsgraph, ARegion *region, View3D *v3d, Object *obact, eV3DDepthOverrideMode mode, bool use_overlay, ViewDepths **r_depths)
void GPU_texture_free(gpu::Texture *texture)
static void view3d_grid_steps_ex(const Scene *scene, const View3D *v3d, const RegionView3D *rv3d, float r_grid_steps[STEPS_LEN], void const **r_usys_pt, int *r_len)
void axis_sort_v3(const float axis_values[3], int r_axis_order[3])
gpu::TextureFormat GPU_offscreen_format(const GPUOffScreen *offscreen)
MINLINE float len_squared_v3(const float v[3]) ATTR_WARN_UNUSED_RESULT
Base * BKE_view_layer_base_find(ViewLayer *view_layer, Object *ob)
eV3DDepthOverrideMode
Definition ED_view3d.hh:205
@ V3D_DEPTH_ALL
Definition ED_view3d.hh:207
@ V3D_DEPTH_OBJECT_ONLY
Definition ED_view3d.hh:213
@ V3D_DEPTH_GPENCIL_ONLY
Definition ED_view3d.hh:211
@ V3D_DEPTH_NO_GPENCIL
Definition ED_view3d.hh:209
@ V3D_DEPTH_SELECTED_ONLY
Definition ED_view3d.hh:215
@ V3D_OVERLAY_EDIT_WEIGHT
void BKE_image_free_anim_gpu_texture_caches(Main *bmain)
Definition image_gpu.cc:854
float view3d_depth_near(ViewDepths *d)
static void view3d_draw_border(const bContext *C, ARegion *region)
static void view3d_stereo3d_setup(Depsgraph *depsgraph, Scene *scene, View3D *v3d, ARegion *region, const rcti *rect)
Scene * CTX_data_scene(const bContext *C)
bool BLI_rcti_isect_pt_v(const struct rcti *rect, const int xy[2])
@ SCE_VIEWS_FORMAT_MULTIVIEW
@ SCE_VIEWS_FORMAT_STEREO_3D
void ED_view3d_draw_setup_view(const wmWindowManager *wm, wmWindow *win, Depsgraph *depsgraph, Scene *scene, ARegion *region, View3D *v3d, const float viewmat[4][4], const float winmat[4][4], const rcti *rect)
MINLINE void copy_v4_v4(float r[4], const float a[4])
void ED_info_draw_stats(Main *bmain, Scene *scene, ViewLayer *view_layer, View3D *v3d_local, int x, int *y, int height)
GPUOffScreen * GPU_offscreen_create(int width, int height, bool with_depth_buffer, gpu::TextureFormat format, eGPUTextureUsage usage, bool clear, char err_out[256])
void GPU_blend(GPUBlend blend)
Definition gpu_state.cc:44
static void draw_view_axis(RegionView3D *rv3d, const rcti *rect)
void * GPU_texture_read(gpu::Texture *texture, eGPUDataFormat data_format, int mip_level)
void copy_m4_m4(float m1[4][4], const float m2[4][4])
void immUniform1i(const char *name, int x)
ImBuf * ED_view3d_draw_offscreen_imbuf_simple(Depsgraph *depsgraph, Scene *scene, View3DShading *shading_override, eDrawType drawtype, Object *camera, int width, int height, ImBufFlags imbuf_flags, eV3DOffscreenDrawFlag draw_flags, int alpha_mode, const char *viewname, GPUOffScreen *ofs, GPUViewport *viewport, char err_out[256])
const char * BKE_unit_display_name_get(const void *usys_pt, int index)
Definition unit.cc:2615
Key * BKE_key_from_object(Object *ob)
Definition key.cc:1311
eRegionView3D_ViewFlipRoll
size_t BLI_string_join_array(char *result, size_t result_maxncpy, const char *strings[], uint strings_num) ATTR_NONNULL()
VecBase< uint16_t, 4 > ushort4
void BKE_camera_params_init(CameraParams *params)
void GPU_framebuffer_read_depth(gpu::FrameBuffer *fb, int x, int y, int width, int height, eGPUDataFormat data_format, void *r_data)
void ED_view3d_text_colors_get(const Scene *scene, const View3D *v3d, float r_text_color[4], float r_shadow_color[4])
void BKE_viewer_path_clear(ViewerPath *viewer_path)
void BLI_thread_unlock(int type)
Definition threads.cc:336
Scene * DEG_get_evaluated_scene(const Depsgraph *graph)
void immVertex2fv(uint attr_id, const float data[2])
@ B_UNIT_LENGTH
Definition BKE_unit.hh:166
void GPU_matrix_pop()
void view3d_main_region_draw(const bContext *C, ARegion *region)
void BLF_default_size(float size)
void GPU_matrix_push_projection()
GPUViewport * WM_draw_region_get_viewport(ARegion *region)
Definition wm_draw.cc:954
static void draw_selected_name(const Main &bmain, const View3D *v3d, Scene *scene, ViewLayer *view_layer, Object *ob, int xoffset, int *yoffset)
MINLINE int min_ii(int a, int b)
void GPU_depth_test(GPUDepthTest test)
Definition gpu_state.cc:70
void ED_view3d_screen_datamask(const Main &bmain, const Scene *scene, ViewLayer *view_layer, const bScreen *screen, CustomData_MeshMasks *r_cddata_masks)
MINLINE float dot_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
void immRectf(uint pos, float x1, float y1, float x2, float y2)
eRegionView3D_ViewFlipRoll ED_view3d_effective_flip_axis(const RegionView3D *rv3d)
void GPU_matrix_set(const float m[4][4])
@ V3D_GIZMO_HIDE_NAVIGATE
void WM_draw_region_viewport_unbind(ARegion *region)
Definition wm_draw.cc:1842
void BLF_enable(int fontid, FontFlags flag)
Definition blf.cc:322
const char * BKE_scene_find_marker_name(const Scene *scene, int frame)
Definition scene.cc:2491
View3D * CTX_wm_view3d(const bContext *C)
void ED_view3d_draw_offscreen(Depsgraph *depsgraph, const Scene *scene, eDrawType drawtype, View3D *v3d, ARegion *region, bContext *context, int winx, int winy, const float viewmat[4][4], const float winmat[4][4], bool is_image_render, bool draw_background, const char *viewname, bool do_color_management, bool restore_rv3d_mats, GPUOffScreen *ofs, GPUViewport *viewport)
@ BLF_SHADOW
Definition BLF_enums.hh:38
gpu::Texture * GPU_texture_create_2d(const char *name, int width, int height, int mip_len, gpu::TextureFormat format, eGPUTextureUsage usage, const float *data)
void GPU_matrix_push()
void BLI_thread_lock(int type)
Definition threads.cc:331
void BLF_color4fv(int fontid, const float rgba[4])
Definition blf.cc:507
void BLI_rcti_rctf_copy_floor(struct rcti *dst, const struct rctf *src)
void GPU_offscreen_read_color(GPUOffScreen *offscreen, eGPUDataFormat data_format, void *r_data)
std::string format(const std::string &fmt, Args &&...args)
Definition diagnostic.hh:43
#define floorf
#define fabsf
#define sqrtf
#define sinf
#define cosf
#define ceilf
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
bke::ARegionRuntime * runtime
eRegion_Alignment alignment
eRegion_Type regiontype
char name[258]
Definition DNA_ID.h:433
const uint8_t * byte_data() const
uint8_t * byte_data_for_write()
Definition allocimbuf.cc:60
const float * float_data() const
float * float_data_for_write()
Definition allocimbuf.cc:79
ListBaseT< KeyBlock > block
struct Collection * collection
eObject_ShapeFlag shapeflag
eRegionView3D_Flag rflag
eRegionView3D_ViewAxisRoll view_axis_roll
eRegionView3D_Persp persp
eRegionView3D_NDOFFlag ndof_flag
eRegionView3D_View view
eSceneViews_Format views_format
void(*) view_update(struct RenderEngine *engine, const struct bContext *context, struct Depsgraph *depsgraph)
Definition RE_engine.h:111
void(*) view_draw(struct RenderEngine *engine, const struct bContext *context, struct Depsgraph *depsgraph)
Definition RE_engine.h:114
struct SceneDisplay display
struct UnitSettings unit
struct DisplaySafeAreas safe_areas
struct RenderData r
ListBaseT< SpaceLink > spacedata
eView3DOverlay_Flag flag
eView3DOverlay_EditFlag edit_flag
eV3DShadingColorType color_type
eView3DShading_Flag flag
eV3DShadingBackgroundType background_type
eV3DShadingLightingMode light
eView3D_GridFlag gridflag
View3DOverlay overlay
eView3D_Flag2 flag2
struct Object * ob_center
struct Object * camera
View3DShading shading
ListBaseT< ARegion > regionbase
struct View3D * localvd
View3D_Runtime runtime
eView3D_GizmoFlag gizmo_flag
ViewLayer * view_layer
Definition ED_view3d.hh:80
Depsgraph * depsgraph
Definition ED_view3d.hh:78
unsigned short w
Definition ED_view3d.hh:92
unsigned short h
Definition ED_view3d.hh:92
double depth_range[2]
Definition ED_view3d.hh:96
ListBaseT< ViewerPathElem > path
ListBaseT< EditBone > * edbo
struct EditBone * act_edbone
ListBaseT< struct ScrArea > areabase
ARegionQuadviewIndex quadview_index
#define VIEW3D_OVERLAY_LINEHEIGHT
#define STEPS_LEN