Blender V4.5
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
11#include "BLI_listbase.h"
12#include "BLI_math_geom.h"
13#include "BLI_math_half.hh"
14#include "BLI_math_matrix.h"
15#include "BLI_math_rotation.h"
16#include "BLI_rect.h"
17#include "BLI_string.h"
18#include "BLI_string_utils.hh"
19#include "BLI_threads.h"
20
21#include "BKE_armature.hh"
22#include "BKE_camera.h"
23#include "BKE_collection.hh"
24#include "BKE_context.hh"
25#include "BKE_customdata.hh"
26#include "BKE_global.hh"
27#include "BKE_grease_pencil.hh"
28#include "BKE_image.hh"
29#include "BKE_key.hh"
30#include "BKE_layer.hh"
31#include "BKE_main.hh"
32#include "BKE_object.hh"
33#include "BKE_paint.hh"
34#include "BKE_scene.hh"
35#include "BKE_screen.hh"
36#include "BKE_unit.hh"
37#include "BKE_viewer_path.hh"
38
39#include "BLF_api.hh"
40
41#include "BLT_translation.hh"
42
43#include "DNA_armature_types.h"
44#include "DNA_camera_types.h"
45#include "DNA_key_types.h"
46#include "DNA_object_types.h"
47#include "DNA_view3d_types.h"
49
50#include "DRW_engine.hh"
51#include "DRW_select_buffer.hh"
52
53#include "ED_gpencil_legacy.hh"
54#include "ED_info.hh"
55#include "ED_scene.hh"
56#include "ED_screen.hh"
58#include "ED_viewer_path.hh"
59
61
63
64#include "GPU_framebuffer.hh"
65#include "GPU_immediate.hh"
66#include "GPU_immediate_util.hh"
67#include "GPU_matrix.hh"
68#include "GPU_state.hh"
69#include "GPU_viewport.hh"
70
71#include "MEM_guardedalloc.h"
72
73#include "UI_interface.hh"
74#include "UI_resources.hh"
75
76#include "RE_engine.h"
77
78#include "WM_api.hh"
79#include "WM_types.hh"
80
81#include "IMB_imbuf.hh"
82#include "IMB_imbuf_types.hh"
83
84#include "ANIM_keyframing.hh"
85
86#include "view3d_intern.hh" /* own include */
87
88using blender::float4;
89
90#define M_GOLDEN_RATIO_CONJUGATE 0.618033988749895f
91
92#define VIEW3D_OVERLAY_LINEHEIGHT (UI_style_get()->widget.points * UI_SCALE_FAC * 1.6f)
93
94/* -------------------------------------------------------------------- */
97
98void ED_view3d_update_viewmat(const Depsgraph *depsgraph,
99 const Scene *scene,
100 View3D *v3d,
101 ARegion *region,
102 const float viewmat[4][4],
103 const float winmat[4][4],
104 const rcti *rect,
105 bool offscreen)
106{
107 RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata);
108
109 /* setup window matrices */
110 if (winmat) {
111 copy_m4_m4(rv3d->winmat, winmat);
112 }
113 else {
114 view3d_winmatrix_set(depsgraph, region, v3d, rect);
115 }
116
117 /* setup view matrix */
118 if (viewmat) {
119 copy_m4_m4(rv3d->viewmat, viewmat);
120 }
121 else {
122 float rect_scale[2];
123 if (rect) {
124 rect_scale[0] = float(BLI_rcti_size_x(rect)) / float(region->winx);
125 rect_scale[1] = float(BLI_rcti_size_y(rect)) / float(region->winy);
126 }
127 /* NOTE: calls BKE_object_where_is_calc for camera... */
128 view3d_viewmatrix_set(depsgraph, scene, v3d, rv3d, rect ? rect_scale : nullptr);
129 }
130 /* update utility matrices */
131 mul_m4_m4m4(rv3d->persmat, rv3d->winmat, rv3d->viewmat);
132 invert_m4_m4(rv3d->persinv, rv3d->persmat);
133 invert_m4_m4(rv3d->viewinv, rv3d->viewmat);
134
135 /* calculate GLSL view dependent values */
136
137 /* store window coordinates scaling/offset */
138 if (!offscreen && rv3d->persp == RV3D_CAMOB && v3d->camera) {
139 rctf cameraborder;
140 ED_view3d_calc_camera_border(scene, depsgraph, region, v3d, rv3d, false, &cameraborder);
141 rv3d->viewcamtexcofac[0] = float(region->winx) / BLI_rctf_size_x(&cameraborder);
142 rv3d->viewcamtexcofac[1] = float(region->winy) / BLI_rctf_size_y(&cameraborder);
143
144 rv3d->viewcamtexcofac[2] = -rv3d->viewcamtexcofac[0] * cameraborder.xmin / float(region->winx);
145 rv3d->viewcamtexcofac[3] = -rv3d->viewcamtexcofac[1] * cameraborder.ymin / float(region->winy);
146 }
147 else {
148 rv3d->viewcamtexcofac[0] = rv3d->viewcamtexcofac[1] = 1.0f;
149 rv3d->viewcamtexcofac[2] = rv3d->viewcamtexcofac[3] = 0.0f;
150 }
151
152 /* Calculate pixel-size factor once, this is used for lights and object-centers. */
153 {
154 /* NOTE: '1.0f / len_v3(v1)' replaced 'len_v3(rv3d->viewmat[0])'
155 * because of float point precision problems at large values #23908. */
156 float v1[3], v2[3];
157 float len_px, len_sc;
158
159 v1[0] = rv3d->persmat[0][0];
160 v1[1] = rv3d->persmat[1][0];
161 v1[2] = rv3d->persmat[2][0];
162
163 v2[0] = rv3d->persmat[0][1];
164 v2[1] = rv3d->persmat[1][1];
165 v2[2] = rv3d->persmat[2][1];
166
167 len_px = 2.0f / sqrtf(min_ff(len_squared_v3(v1), len_squared_v3(v2)));
168
169 if (rect) {
170 len_sc = float(max_ii(BLI_rcti_size_x(rect), BLI_rcti_size_y(rect)));
171 }
172 else {
173 len_sc = float(std::max(region->winx, region->winy));
174 }
175
176 rv3d->pixsize = len_px / len_sc;
177 }
178}
179
181 Scene *scene,
182 View3D *v3d,
183 ARegion *region,
184 const float viewmat[4][4],
185 const float winmat[4][4],
186 const rcti *rect)
187{
188 RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata);
189
190 ED_view3d_update_viewmat(depsgraph, scene, v3d, region, viewmat, winmat, rect, false);
191
192 /* Set for GPU drawing. */
194 GPU_matrix_set(rv3d->viewmat);
195}
196
198 const Scene *scene,
199 View3D *v3d,
200 ARegion *region,
201 const float viewmat[4][4],
202 const float winmat[4][4])
203{
204 RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata);
205 ED_view3d_update_viewmat(depsgraph, scene, v3d, region, viewmat, winmat, nullptr, true);
206
207 /* Set for GPU drawing. */
209 GPU_matrix_set(rv3d->viewmat);
210}
211
213 const Scene *scene,
214 View3D *v3d,
215 RegionView3D *rv3d)
216{
217 if ((scene->r.scemode & R_MULTIVIEW) == 0) {
218 return false;
219 }
220
221 if ((v3d->camera == nullptr) || (v3d->camera->type != OB_CAMERA) || rv3d->persp != RV3D_CAMOB) {
222 return false;
223 }
224
225 switch (v3d->stereo3d_camera) {
226 case STEREO_MONO_ID:
227 return false;
228 break;
229 case STEREO_3D_ID:
230 /* win will be nullptr when calling this from the selection or draw loop. */
231 if ((win == nullptr) || (WM_stereo3d_enabled(win, true) == false)) {
232 return false;
233 }
234 if (((scene->r.views_format & SCE_VIEWS_FORMAT_MULTIVIEW) != 0) &&
236 {
237 return false;
238 }
239 break;
240 /* We always need the stereo calculation for left and right cameras. */
241 case STEREO_LEFT_ID:
242 case STEREO_RIGHT_ID:
243 default:
244 break;
245 }
246 return true;
247}
248
249/* setup the view and win matrices for the multiview cameras
250 *
251 * unlike view3d_stereo3d_setup_offscreen, when view3d_stereo3d_setup is called
252 * we have no winmatrix (i.e., projection matrix) defined at that time.
253 * Since the camera and the camera shift are needed for the winmat calculation
254 * we do a small hack to replace it temporarily so we don't need to change the
255 * view3d)main_region_setup_view() code to account for that.
256 */
258 Depsgraph *depsgraph, Scene *scene, View3D *v3d, ARegion *region, const rcti *rect)
259{
260 bool is_left;
261 const char *names[2] = {STEREO_LEFT_NAME, STEREO_RIGHT_NAME};
262 const char *viewname;
263
264 /* show only left or right camera */
265 if (v3d->stereo3d_camera != STEREO_3D_ID) {
266 v3d->multiview_eye = v3d->stereo3d_camera;
267 }
268
270 viewname = names[is_left ? STEREO_LEFT_ID : STEREO_RIGHT_ID];
271
272 /* update the viewport matrices with the new camera */
274 Camera *data, *data_eval;
275 float viewmat[4][4];
276 float shiftx;
277
278 data = (Camera *)v3d->camera->data;
279 data_eval = DEG_get_evaluated(depsgraph, data);
280
281 shiftx = data_eval->shiftx;
282
284 data_eval->shiftx = BKE_camera_multiview_shift_x(&scene->r, v3d->camera, viewname);
285
286 BKE_camera_multiview_view_matrix(&scene->r, v3d->camera, is_left, viewmat);
287 view3d_main_region_setup_view(depsgraph, scene, v3d, region, viewmat, nullptr, rect);
288
289 data_eval->shiftx = shiftx;
291 }
292 else { /* SCE_VIEWS_FORMAT_MULTIVIEW */
293 float viewmat[4][4];
294 Object *view_ob = v3d->camera;
295 Object *camera = BKE_camera_multiview_render(scene, v3d->camera, viewname);
296
298 v3d->camera = camera;
299
300 BKE_camera_multiview_view_matrix(&scene->r, camera, false, viewmat);
301 view3d_main_region_setup_view(depsgraph, scene, v3d, region, viewmat, nullptr, rect);
302
303 v3d->camera = view_ob;
305 }
306}
307
308#ifdef WITH_XR_OPENXR
309static void view3d_xr_mirror_setup(const wmWindowManager *wm,
310 Depsgraph *depsgraph,
311 Scene *scene,
312 View3D *v3d,
313 ARegion *region,
314 const rcti *rect)
315{
316 RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata);
317 float viewmat[4][4];
318 const float lens_old = v3d->lens;
319
320 if (!WM_xr_session_state_viewer_pose_matrix_info_get(&wm->xr, viewmat, &v3d->lens)) {
321 /* Can't get info from XR session, use fallback values. */
322 copy_m4_m4(viewmat, rv3d->viewmat);
323 v3d->lens = lens_old;
324 }
325 view3d_main_region_setup_view(depsgraph, scene, v3d, region, viewmat, nullptr, rect);
326
327 /* Set draw flags. */
333 0,
335 /* Hide navigation gizmo since it gets distorted if the view matrix has a scale factor. */
337
338 /* Reset overridden View3D data. */
339 v3d->lens = lens_old;
340}
341#endif /* WITH_XR_OPENXR */
342
344 wmWindow *win,
345 Depsgraph *depsgraph,
346 Scene *scene,
347 ARegion *region,
348 View3D *v3d,
349 const float viewmat[4][4],
350 const float winmat[4][4],
351 const rcti *rect)
352{
353 RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata);
354
355#ifdef WITH_XR_OPENXR
356 /* Setup the view matrix. */
357 if (ED_view3d_is_region_xr_mirror_active(wm, v3d, region)) {
358 view3d_xr_mirror_setup(wm, depsgraph, scene, v3d, region, rect);
359 }
360 else
361#endif
362 if (view3d_stereo3d_active(win, scene, v3d, rv3d))
363 {
364 view3d_stereo3d_setup(depsgraph, scene, v3d, region, rect);
365 }
366 else {
367 view3d_main_region_setup_view(depsgraph, scene, v3d, region, viewmat, winmat, rect);
368 }
369
370#ifndef WITH_XR_OPENXR
371 UNUSED_VARS(wm);
372#endif
373}
374
376
377/* -------------------------------------------------------------------- */
380
381static void view3d_camera_border(const Scene *scene,
382 const Depsgraph *depsgraph,
383 const ARegion *region,
384 const View3D *v3d,
385 const RegionView3D *rv3d,
386 rctf *r_viewborder,
387 const bool no_shift,
388 const bool no_zoom)
389{
391 rctf rect_view, rect_camera;
392 Object *camera_eval = DEG_get_evaluated(depsgraph, v3d->camera);
393
394 /* get viewport viewplane */
397 if (no_zoom) {
398 params.zoom = 1.0f;
399 }
400 BKE_camera_params_compute_viewplane(&params, region->winx, region->winy, 1.0f, 1.0f);
401 rect_view = params.viewplane;
402
403 /* get camera viewplane */
405 /* fallback for non camera objects */
406 params.clip_start = v3d->clip_start;
407 params.clip_end = v3d->clip_end;
409 if (no_shift) {
410 params.shiftx = 0.0f;
411 params.shifty = 0.0f;
412 }
414 &params, scene->r.xsch, scene->r.ysch, scene->r.xasp, scene->r.yasp);
415 rect_camera = params.viewplane;
416
417 /* get camera border within viewport */
418 r_viewborder->xmin = ((rect_camera.xmin - rect_view.xmin) / BLI_rctf_size_x(&rect_view)) *
419 region->winx;
420 r_viewborder->xmax = ((rect_camera.xmax - rect_view.xmin) / BLI_rctf_size_x(&rect_view)) *
421 region->winx;
422 r_viewborder->ymin = ((rect_camera.ymin - rect_view.ymin) / BLI_rctf_size_y(&rect_view)) *
423 region->winy;
424 r_viewborder->ymax = ((rect_camera.ymax - rect_view.ymin) / BLI_rctf_size_y(&rect_view)) *
425 region->winy;
426}
427
429 Depsgraph *depsgraph,
430 const ARegion *region,
431 const View3D *v3d,
432 const RegionView3D *rv3d,
433 float r_size[2])
434{
435 rctf viewborder;
436
437 view3d_camera_border(scene, depsgraph, region, v3d, rv3d, &viewborder, true, true);
438 r_size[0] = BLI_rctf_size_x(&viewborder);
439 r_size[1] = BLI_rctf_size_y(&viewborder);
440}
441
443 const Depsgraph *depsgraph,
444 const ARegion *region,
445 const View3D *v3d,
446 const RegionView3D *rv3d,
447 const bool no_shift,
448 rctf *r_viewborder)
449{
450 view3d_camera_border(scene, depsgraph, region, v3d, rv3d, r_viewborder, no_shift, false);
451}
452
453static void drawviewborder_grid3(uint shdr_pos, float x1, float x2, float y1, float y2, float fac)
454{
455 float x3, y3, x4, y4;
456
457 x3 = x1 + fac * (x2 - x1);
458 y3 = y1 + fac * (y2 - y1);
459 x4 = x1 + (1.0f - fac) * (x2 - x1);
460 y4 = y1 + (1.0f - fac) * (y2 - y1);
461
463
464 immVertex2f(shdr_pos, x1, y3);
465 immVertex2f(shdr_pos, x2, y3);
466
467 immVertex2f(shdr_pos, x1, y4);
468 immVertex2f(shdr_pos, x2, y4);
469
470 immVertex2f(shdr_pos, x3, y1);
471 immVertex2f(shdr_pos, x3, y2);
472
473 immVertex2f(shdr_pos, x4, y1);
474 immVertex2f(shdr_pos, x4, y2);
475
476 immEnd();
477}
478
479/* harmonious triangle */
481 uint shdr_pos, float x1, float x2, float y1, float y2, const char golden, const char dir)
482{
483 float ofs;
484 float w = x2 - x1;
485 float h = y2 - y1;
486
488
489 if (w > h) {
490 if (golden) {
491 ofs = w * (1.0f - M_GOLDEN_RATIO_CONJUGATE);
492 }
493 else {
494 ofs = h * (h / w);
495 }
496 if (dir == 'B') {
497 std::swap(y1, y2);
498 }
499
500 immVertex2f(shdr_pos, x1, y1);
501 immVertex2f(shdr_pos, x2, y2);
502
503 immVertex2f(shdr_pos, x2, y1);
504 immVertex2f(shdr_pos, x1 + (w - ofs), y2);
505
506 immVertex2f(shdr_pos, x1, y2);
507 immVertex2f(shdr_pos, x1 + ofs, y1);
508 }
509 else {
510 if (golden) {
511 ofs = h * (1.0f - M_GOLDEN_RATIO_CONJUGATE);
512 }
513 else {
514 ofs = w * (w / h);
515 }
516 if (dir == 'B') {
517 std::swap(x1, x2);
518 }
519
520 immVertex2f(shdr_pos, x1, y1);
521 immVertex2f(shdr_pos, x2, y2);
522
523 immVertex2f(shdr_pos, x2, y1);
524 immVertex2f(shdr_pos, x1, y1 + ofs);
525
526 immVertex2f(shdr_pos, x1, y2);
527 immVertex2f(shdr_pos, x2, y1 + (h - ofs));
528 }
529
530 immEnd();
531}
532
533static void drawviewborder(Scene *scene, Depsgraph *depsgraph, ARegion *region, View3D *v3d)
534{
535 float x1, x2, y1, y2;
536 float x1i, x2i, y1i, y2i;
537
538 rctf viewborder;
539 Camera *ca = nullptr;
540 RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata);
541
542 if (v3d->camera == nullptr) {
543 return;
544 }
545 if (v3d->camera->type == OB_CAMERA) {
546 ca = static_cast<Camera *>(v3d->camera->data);
547 }
548
549 ED_view3d_calc_camera_border(scene, depsgraph, region, v3d, rv3d, false, &viewborder);
550 /* the offsets */
551 x1 = viewborder.xmin;
552 y1 = viewborder.ymin;
553 x2 = viewborder.xmax;
554 y2 = viewborder.ymax;
555
556 GPU_line_width(1.0f);
557
558 /* apply offsets so the real 3D camera shows through */
559
560 /* NOTE: quite un-scientific but without this bit extra
561 * 0.0001 on the lower left the 2D border sometimes
562 * obscures the 3D camera border */
563 /* NOTE: with VIEW3D_CAMERA_BORDER_HACK defined this error isn't noticeable
564 * but keep it here in case we need to remove the workaround */
565 x1i = int(x1 - 1.0001f);
566 y1i = int(y1 - 1.0001f);
567 x2i = int(x2 + (1.0f - 0.0001f));
568 y2i = int(y2 + (1.0f - 0.0001f));
569
570 uint shdr_pos = GPU_vertformat_attr_add(
572
573 /* First, solid lines. */
574 {
576
577 /* passepartout, specified in camera edit buttons */
578 if (ca && (ca->flag & CAM_SHOWPASSEPARTOUT) && ca->passepartalpha > 0.000001f &&
580 {
581 const float winx = (region->winx + 1);
582 const float winy = (region->winy + 1);
583
584 float alpha = 1.0f;
585
586 if (ca->passepartalpha != 1.0f) {
588 alpha = ca->passepartalpha;
589 }
590
592
593 if (x1i > 0.0f) {
594 immRectf(shdr_pos, 0.0f, winy, x1i, 0.0f);
595 }
596 if (x2i < winx) {
597 immRectf(shdr_pos, x2i, winy, winx, 0.0f);
598 }
599 if (y2i < winy) {
600 immRectf(shdr_pos, x1i, winy, x2i, y2i);
601 }
602 if (y2i > 0.0f) {
603 immRectf(shdr_pos, x1i, y1i, x2i, 0.0f);
604 }
605
608 imm_draw_box_wire_2d(shdr_pos, x1i, y1i, x2i, y2i);
609 }
610
611#ifdef VIEW3D_CAMERA_BORDER_HACK
612 if (view3d_camera_border_hack_test == true) {
614 imm_draw_box_wire_2d(shdr_pos, x1i + 1, y1i + 1, x2i - 1, y2i - 1);
616 }
617#endif
618
620 }
621
622 /* When overlays are disabled, only show camera outline & passepartout. */
623 if (v3d->flag2 & V3D_HIDE_OVERLAYS || !(v3d->flag2 & V3D_SHOW_CAMERA_GUIDES)) {
624 return;
625 }
626
627 /* And now, the dashed lines! */
629
630 {
631 float viewport_size[4];
632 GPU_viewport_size_get_f(viewport_size);
633 immUniform2f("viewport_size", viewport_size[2], viewport_size[3]);
634
635 immUniform1i("colors_len", 0); /* "simple" mode */
636 immUniform1f("dash_width", 6.0f);
637 immUniform1f("udash_factor", 0.5f);
638
639 /* outer line not to confuse with object selection */
640 if (v3d->flag2 & V3D_LOCK_CAMERA) {
642 imm_draw_box_wire_2d(shdr_pos, x1i - 1, y1i - 1, x2i + 1, y2i + 1);
643 }
644
646 imm_draw_box_wire_2d(shdr_pos, x1i, y1i, x2i, y2i);
647 }
648
649 /* Render Border. */
650 if (scene->r.mode & R_BORDER) {
651 float x3, y3, x4, y4;
652
653 x3 = floorf(x1 + (scene->r.border.xmin * (x2 - x1))) - 1;
654 y3 = floorf(y1 + (scene->r.border.ymin * (y2 - y1))) - 1;
655 x4 = floorf(x1 + (scene->r.border.xmax * (x2 - x1))) + (U.pixelsize - 1);
656 y4 = floorf(y1 + (scene->r.border.ymax * (y2 - y1))) + (U.pixelsize - 1);
657
658 immUniformColor3f(1.0f, 0.25f, 0.25f);
659 imm_draw_box_wire_2d(shdr_pos, x3, y3, x4, y4);
660 }
661
662 /* safety border */
663 if (ca && (v3d->flag2 & V3D_SHOW_CAMERA_GUIDES)) {
666
667 if (ca->dtx & CAM_DTX_CENTER) {
668 float x3, y3;
669
670 x3 = x1 + 0.5f * (x2 - x1);
671 y3 = y1 + 0.5f * (y2 - y1);
672
674
675 immVertex2f(shdr_pos, x1, y3);
676 immVertex2f(shdr_pos, x2, y3);
677
678 immVertex2f(shdr_pos, x3, y1);
679 immVertex2f(shdr_pos, x3, y2);
680
681 immEnd();
682 }
683
684 if (ca->dtx & CAM_DTX_CENTER_DIAG) {
686
687 immVertex2f(shdr_pos, x1, y1);
688 immVertex2f(shdr_pos, x2, y2);
689
690 immVertex2f(shdr_pos, x1, y2);
691 immVertex2f(shdr_pos, x2, y1);
692
693 immEnd();
694 }
695
696 if (ca->dtx & CAM_DTX_THIRDS) {
697 drawviewborder_grid3(shdr_pos, x1, x2, y1, y2, 1.0f / 3.0f);
698 }
699
700 if (ca->dtx & CAM_DTX_GOLDEN) {
701 drawviewborder_grid3(shdr_pos, x1, x2, y1, y2, 1.0f - M_GOLDEN_RATIO_CONJUGATE);
702 }
703
704 if (ca->dtx & CAM_DTX_GOLDEN_TRI_A) {
705 drawviewborder_triangle(shdr_pos, x1, x2, y1, y2, 0, 'A');
706 }
707
708 if (ca->dtx & CAM_DTX_GOLDEN_TRI_B) {
709 drawviewborder_triangle(shdr_pos, x1, x2, y1, y2, 0, 'B');
710 }
711
712 if (ca->dtx & CAM_DTX_HARMONY_TRI_A) {
713 drawviewborder_triangle(shdr_pos, x1, x2, y1, y2, 1, 'A');
714 }
715
716 if (ca->dtx & CAM_DTX_HARMONY_TRI_B) {
717 drawviewborder_triangle(shdr_pos, x1, x2, y1, y2, 1, 'B');
718 }
719
720 if (ca->flag & CAM_SHOW_SAFE_MARGINS) {
721 rctf margins_rect{};
722 margins_rect.xmin = x1;
723 margins_rect.xmax = x2;
724 margins_rect.ymin = y1;
725 margins_rect.ymax = y2;
726
728 shdr_pos, &margins_rect, scene->safe_areas.title, scene->safe_areas.action);
729
730 if (ca->flag & CAM_SHOW_SAFE_CENTER) {
731 rctf center_rect{};
732 center_rect.xmin = x1;
733 center_rect.xmax = x2;
734 center_rect.ymin = y1;
735 center_rect.ymax = y2;
736 UI_draw_safe_areas(shdr_pos,
737 &center_rect,
740 }
741 }
742
743 if (ca->flag & CAM_SHOWSENSOR) {
744 /* determine sensor fit, and get sensor x/y, for auto fit we
745 * assume and square sensor and only use sensor_x */
746 float sizex = scene->r.xsch * scene->r.xasp;
747 float sizey = scene->r.ysch * scene->r.yasp;
748 int sensor_fit = BKE_camera_sensor_fit(ca->sensor_fit, sizex, sizey);
749 float sensor_x = ca->sensor_x;
750 float sensor_y = (ca->sensor_fit == CAMERA_SENSOR_FIT_AUTO) ? ca->sensor_x : ca->sensor_y;
751
752 /* determine sensor plane */
753 rctf rect;
754
755 if (sensor_fit == CAMERA_SENSOR_FIT_HOR) {
756 float sensor_scale = (x2i - x1i) / sensor_x;
757 float sensor_height = sensor_scale * sensor_y;
758
759 rect.xmin = x1i;
760 rect.xmax = x2i;
761 rect.ymin = (y1i + y2i) * 0.5f - sensor_height * 0.5f;
762 rect.ymax = rect.ymin + sensor_height;
763 }
764 else {
765 float sensor_scale = (y2i - y1i) / sensor_y;
766 float sensor_width = sensor_scale * sensor_x;
767
768 rect.xmin = (x1i + x2i) * 0.5f - sensor_width * 0.5f;
769 rect.xmax = rect.xmin + sensor_width;
770 rect.ymin = y1i;
771 rect.ymax = y2i;
772 }
773
774 /* draw */
776
777 /* TODO: Was using:
778 * `UI_draw_roundbox_4fv(false, rect.xmin, rect.ymin, rect.xmax, rect.ymax, 2.0f, color);`
779 * We'll probably need a new imm_draw_line_roundbox_dashed or that - though in practice the
780 * 2.0f round corner effect was nearly not visible anyway. */
781 imm_draw_box_wire_2d(shdr_pos, rect.xmin, rect.ymin, rect.xmax, rect.ymax);
782 }
783
785 }
786
788 /* end dashed lines */
789
790 /* camera name - draw in highlighted text color */
791 if (ca && ((v3d->overlay.flag & V3D_OVERLAY_HIDE_TEXT) == 0) && (ca->flag & CAM_SHOWNAME)) {
794 y1i - (0.7f * U.widget_unit),
795 0.0f,
796 v3d->camera->id.name + 2,
797 sizeof(v3d->camera->id.name) - 2);
798 }
799}
800
801static void drawrenderborder(ARegion *region, View3D *v3d)
802{
803 /* use the same program for everything */
804 uint shdr_pos = GPU_vertformat_attr_add(
806
807 GPU_line_width(1.0f);
808
810
811 float viewport_size[4];
812 GPU_viewport_size_get_f(viewport_size);
813 immUniform2f("viewport_size", viewport_size[2], viewport_size[3]);
814
815 immUniform1i("colors_len", 0); /* "simple" mode */
816 immUniform4f("color", 1.0f, 0.25f, 0.25f, 1.0f);
817 immUniform1f("dash_width", 6.0f);
818 immUniform1f("udash_factor", 0.5f);
819
820 imm_draw_box_wire_2d(shdr_pos,
821 v3d->render_border.xmin * region->winx,
822 v3d->render_border.ymin * region->winy,
823 v3d->render_border.xmax * region->winx,
824 v3d->render_border.ymax * region->winy);
825
827}
828
830
831/* -------------------------------------------------------------------- */
834
835float ED_scene_grid_scale(const Scene *scene, const char **r_grid_unit)
836{
837 /* apply units */
838 if (scene->unit.system) {
839 const void *usys;
840 int len;
841
843
844 if (usys) {
845 int i = BKE_unit_base_get(usys);
846 if (r_grid_unit) {
847 *r_grid_unit = IFACE_(BKE_unit_display_name_get(usys, i));
848 }
849 return float(BKE_unit_scalar_get(usys, i)) / scene->unit.scale_length;
850 }
851 }
852
853 return 1.0f;
854}
855
856float ED_view3d_grid_scale(const Scene *scene, const View3D *v3d, const char **r_grid_unit)
857{
858 return v3d->grid * ED_scene_grid_scale(scene, r_grid_unit);
859}
860
861#define STEPS_LEN 8
862static void view3d_grid_steps_ex(const Scene *scene,
863 const View3D *v3d,
864 const RegionView3D *rv3d,
865 float r_grid_steps[STEPS_LEN],
866 void const **r_usys_pt,
867 int *r_len)
868{
869 const void *usys;
870 int len;
872 float grid_scale = v3d->grid;
874
875 if (usys) {
876 if (rv3d->view == RV3D_VIEW_USER) {
877 /* Skip steps */
878 len = BKE_unit_base_get(usys) + 1;
879 }
880
881 grid_scale /= scene->unit.scale_length;
882
883 int i;
884 for (i = 0; i < len; i++) {
885 r_grid_steps[i] = float(BKE_unit_scalar_get(usys, len - 1 - i)) * grid_scale;
886 }
887 for (; i < STEPS_LEN; i++) {
888 /* Fill last slots */
889 r_grid_steps[i] = r_grid_steps[len - 1];
890 }
891 }
892 else {
893 if (rv3d->view != RV3D_VIEW_USER) {
894 /* Allow 3 more subdivisions. */
895 grid_scale /= powf(v3d->gridsubdiv, 3);
896 }
897 int subdiv = 1;
898 for (int i = 0;; i++) {
899 r_grid_steps[i] = grid_scale * subdiv;
900
901 if (i == STEPS_LEN - 1) {
902 break;
903 }
904 subdiv *= v3d->gridsubdiv;
905 }
906 }
907 if (r_usys_pt) {
908 *r_usys_pt = usys;
909 }
910 if (r_len) {
911 *r_len = len;
912 }
913}
914
915void ED_view3d_grid_steps(const Scene *scene,
916 const View3D *v3d,
917 const RegionView3D *rv3d,
918 float r_grid_steps[STEPS_LEN])
919{
920 view3d_grid_steps_ex(scene, v3d, rv3d, r_grid_steps, nullptr, nullptr);
921}
922
924 const View3D *v3d,
925 const ARegion *region,
926 const char **r_grid_unit)
927{
928 float grid_scale;
929 const RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata);
930 if (!rv3d->is_persp && RV3D_VIEW_IS_AXIS(rv3d->view)) {
931 /* Decrease the distance between grid snap points depending on zoom. */
932 float dist = 12.0f / (region->sizex * rv3d->winmat[0][0]);
933 float grid_steps[STEPS_LEN];
934 const void *usys;
935 int grid_steps_len;
936 view3d_grid_steps_ex(scene, v3d, rv3d, grid_steps, &usys, &grid_steps_len);
937 int i = 0;
938 while (true) {
939 grid_scale = grid_steps[i];
940 if (grid_scale > dist || i == (grid_steps_len - 1)) {
941 break;
942 }
943 i++;
944 }
945
946 if (r_grid_unit && usys) {
947 *r_grid_unit = IFACE_(BKE_unit_display_name_get(usys, grid_steps_len - i - 1));
948 }
949 }
950 else {
951 grid_scale = ED_view3d_grid_scale(scene, v3d, r_grid_unit);
952 }
953
954 return grid_scale;
955}
956
957#undef STEPS_LEN
958
959static void draw_view_axis(RegionView3D *rv3d, const rcti *rect)
960{
961 const float k = U.rvisize * UI_SCALE_FAC; /* axis size */
962 /* axis alpha offset (rvibright has range 0-10) */
963 const int bright = -20 * (10 - U.rvibright);
964
965 /* Axis center in screen coordinates.
966 *
967 * - Unit size offset so small text doesn't draw outside the screen
968 * - Extra X offset because of the panel expander.
969 */
970 const float startx = rect->xmax - (k + UI_UNIT_X * 1.5);
971 const float starty = rect->ymax - (k + UI_UNIT_Y);
972
973 float axis_pos[3][2];
974 float axis_col[3][4];
975
976 int axis_order[3] = {0, 1, 2};
977 axis_sort_v3(rv3d->viewinv[2], axis_order);
978
979 for (int axis_i = 0; axis_i < 3; axis_i++) {
980 int i = axis_order[axis_i];
981
982 /* get position of each axis tip on screen */
983 float vec[3] = {0.0f};
984 vec[i] = 1.0f;
985 mul_qt_v3(rv3d->viewquat, vec);
986 axis_pos[i][0] = startx + vec[0] * k;
987 axis_pos[i][1] = starty + vec[1] * k;
988
989 /* get color of each axis */
990 UI_GetThemeColorShade3fv(TH_AXIS_X + i, bright, axis_col[i]); /* rgb */
991 axis_col[i][3] = hypotf(vec[0], vec[1]); /* alpha */
992 }
993
994 /* draw axis lines */
995 GPU_line_width(2.0f);
996 GPU_line_smooth(true);
998
1002
1005
1006 for (int axis_i = 0; axis_i < 3; axis_i++) {
1007 int i = axis_order[axis_i];
1008
1009 immAttr4fv(col, axis_col[i]);
1010 immVertex2f(pos, startx, starty);
1011 immAttr4fv(col, axis_col[i]);
1012 immVertex2fv(pos, axis_pos[i]);
1013 }
1014
1015 immEnd();
1017 GPU_line_smooth(false);
1018
1019 /* draw axis names */
1020 for (int axis_i = 0; axis_i < 3; axis_i++) {
1021 int i = axis_order[axis_i];
1022
1023 const char axis_text[2] = {char('x' + i), '\0'};
1024 BLF_color4fv(BLF_default(), axis_col[i]);
1025 BLF_draw_default(axis_pos[i][0] + 2, axis_pos[i][1] + 2, 0.0f, axis_text, 1);
1026 }
1027}
1028
1029#ifdef WITH_INPUT_NDOF
1033static void draw_ndof_guide_orbit_axis(const RegionView3D *rv3d)
1034{
1035 float o[3]; /* center of rotation */
1036 float end[3]; /* endpoints for drawing */
1037
1038 float color[4] = {0.0f, 0.42f, 1.0f, 1.0f}; /* bright blue so it matches device LEDs */
1039
1040 negate_v3_v3(o, rv3d->ofs);
1041
1043 GPU_depth_mask(false); /* Don't overwrite the Z-buffer. */
1044
1048
1050
1051 if (rv3d->ndof_rot_angle != 0.0f) {
1052 /* -- draw rotation axis -- */
1053 float scaled_axis[3];
1054 const float scale = rv3d->dist;
1055 mul_v3_v3fl(scaled_axis, rv3d->ndof_rot_axis, scale);
1056
1058 color[3] = 0; /* more transparent toward the ends */
1059 immAttr4fv(col, color);
1060 add_v3_v3v3(end, o, scaled_axis);
1061 immVertex3fv(pos, end);
1062
1063# if 0
1064 color[3] = 0.2f + fabsf(rv3d->rot_angle); /* modulate opacity with angle */
1065 /* ^^ neat idea, but angle is frame-rate dependent, so it's usually close to 0.2 */
1066# endif
1067
1068 color[3] = 0.5f; /* more opaque toward the center */
1069 immAttr4fv(col, color);
1070 immVertex3fv(pos, o);
1071
1072 color[3] = 0;
1073 immAttr4fv(col, color);
1074 sub_v3_v3v3(end, o, scaled_axis);
1075 immVertex3fv(pos, end);
1076 immEnd();
1077
1078 /* -- draw ring around rotation center -- */
1079 {
1080# define ROT_AXIS_DETAIL 13
1081
1082 const float s = 0.05f * scale;
1083 const float step = 2.0f * float(M_PI / ROT_AXIS_DETAIL);
1084
1085 float q[4]; /* rotate ring so it's perpendicular to axis */
1086 const int upright = fabsf(rv3d->ndof_rot_axis[2]) >= 0.95f;
1087 if (!upright) {
1088 const float up[3] = {0.0f, 0.0f, 1.0f};
1089 float vis_angle, vis_axis[3];
1090
1091 cross_v3_v3v3(vis_axis, up, rv3d->ndof_rot_axis);
1092 vis_angle = acosf(dot_v3v3(up, rv3d->ndof_rot_axis));
1093 axis_angle_to_quat(q, vis_axis, vis_angle);
1094 }
1095
1096 immBegin(GPU_PRIM_LINE_LOOP, ROT_AXIS_DETAIL);
1097 color[3] = 0.25f; /* somewhat faint */
1098 immAttr4fv(col, color);
1099 float angle = 0.0f;
1100 for (int i = 0; i < ROT_AXIS_DETAIL; i++, angle += step) {
1101 float p[3] = {s * cosf(angle), s * sinf(angle), 0.0f};
1102
1103 if (!upright) {
1104 mul_qt_v3(q, p);
1105 }
1106
1107 add_v3_v3(p, o);
1108 immVertex3fv(pos, p);
1109 }
1110 immEnd();
1111
1112# undef ROT_AXIS_DETAIL
1113 }
1114
1115 color[3] = 1.0f; /* solid dot */
1116 }
1117 else {
1118 color[3] = 0.5f; /* see-through dot */
1119 }
1120
1122
1123 /* -- draw rotation center -- */
1125 immUniform1f("size", 7.0f);
1126 immUniform4fv("color", float4(color));
1128 immAttr4fv(col, color);
1129 immVertex3fv(pos, o);
1130 immEnd();
1132
1134 GPU_depth_mask(true);
1135}
1136
1137static void draw_ndof_guide_orbit_center(const RegionView3D *rv3d)
1138{
1139 uchar color[4] = {0, 108, 255, 255}; /* bright blue so it matches device LEDs */
1141 GPU_depth_mask(false); /* Don't overwrite the Z-buffer. */
1142
1146
1148 immUniform1f("size", 7.0f);
1149 immUniform4fv("color", float4(color));
1151 immAttr4ubv(col, color);
1152 float center[3];
1153 negate_v3_v3(center, rv3d->ndof_ofs);
1154 immVertex3fv(pos, center);
1155 immEnd();
1157
1159 GPU_depth_mask(true);
1160}
1161
1162#endif /* WITH_INPUT_NDOF */
1163
1167static void view3d_draw_border(const bContext *C, ARegion *region)
1168{
1169 Scene *scene = CTX_data_scene(C);
1171 RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata);
1172 View3D *v3d = CTX_wm_view3d(C);
1173
1174 if (rv3d->persp == RV3D_CAMOB) {
1175 drawviewborder(scene, depsgraph, region, v3d);
1176 }
1177 else if (v3d->flag2 & V3D_RENDER_BORDER) {
1178 drawrenderborder(region, v3d);
1179 }
1180}
1181
1183
1184/* -------------------------------------------------------------------- */
1187
1191static void view3d_draw_grease_pencil(const bContext * /*C*/)
1192{
1193 /* TODO: viewport. */
1194}
1195
1199static const char *view3d_get_name(View3D *v3d, RegionView3D *rv3d)
1200{
1201 const char *name = nullptr;
1202
1203 switch (rv3d->view) {
1204 case RV3D_VIEW_FRONT:
1205 if (rv3d->persp == RV3D_ORTHO) {
1206 name = IFACE_("Front Orthographic");
1207 }
1208 else {
1209 name = IFACE_("Front Perspective");
1210 }
1211 break;
1212 case RV3D_VIEW_BACK:
1213 if (rv3d->persp == RV3D_ORTHO) {
1214 name = IFACE_("Back Orthographic");
1215 }
1216 else {
1217 name = IFACE_("Back Perspective");
1218 }
1219 break;
1220 case RV3D_VIEW_TOP:
1221 if (rv3d->persp == RV3D_ORTHO) {
1222 name = IFACE_("Top Orthographic");
1223 }
1224 else {
1225 name = IFACE_("Top Perspective");
1226 }
1227 break;
1228 case RV3D_VIEW_BOTTOM:
1229 if (rv3d->persp == RV3D_ORTHO) {
1230 name = IFACE_("Bottom Orthographic");
1231 }
1232 else {
1233 name = IFACE_("Bottom Perspective");
1234 }
1235 break;
1236 case RV3D_VIEW_RIGHT:
1237 if (rv3d->persp == RV3D_ORTHO) {
1238 name = IFACE_("Right Orthographic");
1239 }
1240 else {
1241 name = IFACE_("Right Perspective");
1242 }
1243 break;
1244 case RV3D_VIEW_LEFT:
1245 if (rv3d->persp == RV3D_ORTHO) {
1246 name = IFACE_("Left Orthographic");
1247 }
1248 else {
1249 name = IFACE_("Left Perspective");
1250 }
1251 break;
1252
1253 default:
1254 if (rv3d->persp == RV3D_CAMOB) {
1255 if ((v3d->camera) && (v3d->camera->type == OB_CAMERA)) {
1256 const Camera *cam = static_cast<const Camera *>(v3d->camera->data);
1257 if (cam->type == CAM_PERSP) {
1258 name = IFACE_("Camera Perspective");
1259 }
1260 else if (cam->type == CAM_ORTHO) {
1261 name = IFACE_("Camera Orthographic");
1262 }
1263 else if (cam->type == CAM_PANO) {
1264 name = IFACE_("Camera Panoramic");
1265 }
1266 else {
1267 BLI_assert(cam->type == CAM_CUSTOM);
1268 name = IFACE_("Camera Custom");
1269 }
1270 }
1271 else {
1272 name = IFACE_("Object as Camera");
1273 }
1274 }
1275 else {
1276 name = (rv3d->persp == RV3D_ORTHO) ? IFACE_("User Orthographic") :
1277 IFACE_("User Perspective");
1278 }
1279 }
1280
1281 return name;
1282}
1283
1284static void draw_viewport_name(ARegion *region, View3D *v3d, int xoffset, int *yoffset)
1285{
1286 RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata);
1287 const char *name = view3d_get_name(v3d, rv3d);
1288 const char *name_array[3] = {name, nullptr, nullptr};
1289 int name_array_len = 1;
1290
1291 /* 6 is the maximum size of the axis roll text. */
1292 /* increase size for unicode languages (Chinese in UTF8...). */
1293 char tmpstr[96 + 6];
1294
1296 const char *axis_roll;
1297 switch (rv3d->view_axis_roll) {
1299 axis_roll = " 90\xC2\xB0";
1300 break;
1302 axis_roll = " 180\xC2\xB0";
1303 break;
1304 default:
1305 axis_roll = " -90\xC2\xB0";
1306 break;
1307 }
1308 name_array[name_array_len++] = axis_roll;
1309 }
1310
1311 if (v3d->localvd) {
1312 name_array[name_array_len++] = IFACE_(" (Local)");
1313 }
1314
1315 /* Indicate that clipping region is enabled. */
1316 if (rv3d->rflag & RV3D_CLIPPING) {
1317 name_array[name_array_len++] = IFACE_(" (Clipped)");
1318 }
1319
1320 if (name_array_len > 1) {
1321 BLI_string_join_array(tmpstr, sizeof(tmpstr), name_array, name_array_len);
1322 name = tmpstr;
1323 }
1324 *yoffset -= VIEW3D_OVERLAY_LINEHEIGHT;
1325 BLF_draw_default(xoffset, *yoffset, 0.0f, name, sizeof(tmpstr));
1326}
1327
1329{
1330 if (ob.type != OB_GREASE_PENCIL) {
1331 return false;
1332 }
1333
1334 using namespace blender::bke::greasepencil;
1335 const GreasePencil &grease_pencil = *static_cast<GreasePencil *>(ob.data);
1336 for (const Layer *layer : grease_pencil.layers()) {
1337 if (!layer->frames().is_empty()) {
1338 return true;
1339 }
1340 }
1341 return false;
1342}
1343
1349 const View3D *v3d, Scene *scene, ViewLayer *view_layer, Object *ob, int xoffset, int *yoffset)
1350{
1351 const int cfra = scene->r.cfra;
1352 const char *msg_pin = " (Soloed)";
1353 const char *msg_sep = " : ";
1354 const char *msg_space = " ";
1355
1356 const int font_id = BLF_default();
1357
1358 const char *info_array[16];
1359 int i = 0;
1360
1361 struct {
1362 char frame[16];
1363 } info_buffers;
1364
1365 SNPRINTF(info_buffers.frame, "(%d)", cfra);
1366 info_array[i++] = info_buffers.frame;
1367
1368 if ((ob == nullptr) || (ob->mode == OB_MODE_OBJECT)) {
1369 BKE_view_layer_synced_ensure(scene, view_layer);
1370 LayerCollection *layer_collection = BKE_view_layer_active_collection_get(view_layer);
1371 info_array[i++] = msg_space;
1372 info_array[i++] = BKE_collection_ui_name_get(layer_collection->collection);
1373 if (ob != nullptr) {
1374 info_array[i++] = " |";
1375 }
1376 }
1377
1378 /* Info can contain:
1379 * - A frame `(7 + 2)`.
1380 * - A collection name `(MAX_NAME + 3)`.
1381 * - 3 object names `(MAX_NAME)`.
1382 * - 2 BREAD_CRUMB_SEPARATOR(s) `(6)`.
1383 * - A SHAPE_KEY_PINNED marker and a trailing '\0' `(9+1)` - translated, so give some room!
1384 * - A marker name `(MAX_NAME + 3)`.
1385 */
1386
1387 /* get name of marker on current frame (if available) */
1388 const char *markern = BKE_scene_find_marker_name(scene, cfra);
1389
1390 /* check if there is an object */
1391 if (ob) {
1392 info_array[i++] = msg_space;
1393 info_array[i++] = ob->id.name + 2;
1394
1395 /* Show object data name when not in object mode. */
1396 if (ob->mode != OB_MODE_OBJECT) {
1397 if (const ID *data_id = static_cast<const ID *>(ob->data)) {
1398 info_array[i++] = " | ";
1399 info_array[i++] = data_id->name + 2;
1400 }
1401 }
1402
1403 /* name(s) to display depends on type of object */
1404 if (ob->type == OB_ARMATURE) {
1405 bArmature *arm = static_cast<bArmature *>(ob->data);
1406
1407 /* show name of active bone too (if possible) */
1408 if (arm->edbo) {
1409 if (arm->act_edbone) {
1410 info_array[i++] = msg_sep;
1411 info_array[i++] = arm->act_edbone->name;
1412 }
1413 }
1414 else if (ob->mode & OB_MODE_POSE) {
1415 if (arm->act_bone) {
1416
1418 info_array[i++] = msg_sep;
1419 info_array[i++] = arm->act_bone->name;
1420 }
1421 }
1422 }
1423 }
1424 else if (ELEM(ob->type, OB_MESH, OB_LATTICE, OB_CURVES_LEGACY)) {
1425 /* Try to display active bone and active shape-key too (if they exist). */
1426
1427 if (ob->type == OB_MESH && ob->mode & OB_MODE_WEIGHT_PAINT) {
1429 if (armobj && armobj->mode & OB_MODE_POSE) {
1430 bArmature *arm = static_cast<bArmature *>(armobj->data);
1431 if (arm->act_bone) {
1433 info_array[i++] = msg_sep;
1434 info_array[i++] = arm->act_bone->name;
1435 }
1436 }
1437 }
1438 }
1439
1440 Key *key = BKE_key_from_object(ob);
1441 if (key) {
1442 KeyBlock *kb = static_cast<KeyBlock *>(BLI_findlink(&key->block, ob->shapenr - 1));
1443 if (kb) {
1444 info_array[i++] = msg_sep;
1445 info_array[i++] = kb->name;
1446 if (ob->shapeflag & OB_SHAPE_LOCK) {
1447 info_array[i++] = IFACE_(msg_pin);
1448 }
1449 }
1450 }
1451 }
1452
1453 /* color depends on whether there is a keyframe */
1456 }
1457
1459 /* BKE_scene_ctime_get(scene) */ float(cfra)))
1460 {
1462 }
1463 }
1464
1465 if (markern) {
1466 info_array[i++] = " <";
1467 info_array[i++] = markern;
1468 info_array[i++] = ">";
1469 }
1470
1471 if (v3d->flag2 & V3D_SHOW_VIEWER) {
1473 info_array[i++] = IFACE_(" (Viewer)");
1474 }
1475 }
1476
1477 BLI_assert(i < int(ARRAY_SIZE(info_array)));
1478 char info[300];
1479 /* It's expected there will be enough room for the buffer (if not, increase it). */
1480 BLI_assert(BLI_string_len_array(info_array, i) < sizeof(info));
1481 BLI_string_join_array(info, sizeof(info), info_array, i);
1482
1483 *yoffset -= VIEW3D_OVERLAY_LINEHEIGHT;
1484 BLF_draw_default(xoffset, *yoffset, 0.0f, info, sizeof(info));
1485}
1486
1488 Scene *scene, ARegion *region, View3D *v3d, int xoffset, int *yoffset)
1489{
1490 RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata);
1491 if (!rv3d->is_persp && RV3D_VIEW_IS_AXIS(rv3d->view)) {
1492 const char *grid_unit = nullptr;
1493 ED_view3d_grid_view_scale(scene, v3d, region, &grid_unit);
1494
1495 if (grid_unit) {
1496 char numstr[32] = "";
1497 if (v3d->grid != 1.0f) {
1498 SNPRINTF(numstr, "%s " BLI_STR_UTF8_MULTIPLICATION_SIGN " %.4g", grid_unit, v3d->grid);
1499 }
1500
1501 *yoffset -= VIEW3D_OVERLAY_LINEHEIGHT;
1502 BLF_draw_default(xoffset, *yoffset, 0.0f, numstr[0] ? numstr : grid_unit, sizeof(numstr));
1503 }
1504 }
1505}
1506
1508{
1509 RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata);
1510 View3D *v3d = CTX_wm_view3d(C);
1511 Scene *scene = CTX_data_scene(C);
1513 Main *bmain = CTX_data_main(C);
1514 ViewLayer *view_layer = CTX_data_view_layer(C);
1515
1516#ifdef WITH_INPUT_NDOF
1517 if (U.ndof_flag & NDOF_SHOW_GUIDE_ORBIT_AXIS) {
1518 if ((RV3D_LOCK_FLAGS(rv3d) & RV3D_LOCK_ROTATION) == 0) {
1519 /* It only makes sense to show when orbiting. */
1520 if (rv3d->ndof_rot_angle != 0.0f) {
1521 /* TODO: draw something else (but not this) during fly mode. */
1522 draw_ndof_guide_orbit_axis(rv3d);
1523 }
1524 }
1525 }
1526
1527 if (U.ndof_flag & NDOF_SHOW_GUIDE_ORBIT_CENTER) {
1528 /* Draw this only when orbiting and auto orbit-center is enabled */
1530 if (rv3d->ndof_flag & RV3D_NDOF_OFS_IS_VALID) {
1531 /* When the center is locked, the auto-center is not used. */
1532 if (!(v3d->ob_center_cursor || v3d->ob_center)) {
1533 /* It only makes sense to show when orbiting. */
1534 if (rv3d->ndof_rot_angle != 0.0f) {
1535 draw_ndof_guide_orbit_center(rv3d);
1536 }
1537 }
1538 }
1539 }
1540 }
1541#endif
1542
1543 /* correct projection matrix */
1544 ED_region_pixelspace(region);
1545
1546 /* local coordinate visible rect inside region, to accommodate overlapping ui */
1547 const rcti *rect = ED_region_visible_rect(region);
1548
1549 view3d_draw_border(C, region);
1551
1553
1555 /* pass */
1556 }
1557 else {
1558 switch ((eUserpref_MiniAxisType)U.mini_axis_type) {
1560 /* The gizmo handles its own drawing. */
1561 break;
1563 draw_view_axis(rv3d, rect);
1565 break;
1566 }
1567 }
1568
1569 if ((v3d->flag2 & V3D_HIDE_OVERLAYS) == 0) {
1570 int xoffset = rect->xmin + (0.5f * U.widget_unit);
1571 int yoffset = rect->ymax - (0.1f * U.widget_unit);
1572
1573 const uiFontStyle *fstyle = UI_FSTYLE_WIDGET;
1574 UI_fontstyle_set(fstyle);
1575 BLF_default_size(fstyle->points);
1577
1578 const int font_id = BLF_default();
1579 float text_color[4], shadow_color[4];
1580 ED_view3d_text_colors_get(scene, v3d, text_color, shadow_color);
1581 BLF_color4fv(font_id, text_color);
1582 BLF_enable(font_id, BLF_SHADOW);
1583 BLF_shadow_offset(font_id, 0, 0);
1584 BLF_shadow(font_id, FontShadowType::Outline, shadow_color);
1585
1586 if ((v3d->overlay.flag & V3D_OVERLAY_HIDE_TEXT) == 0) {
1587 if ((U.uiflag & USER_SHOW_FPS) && ED_screen_animation_no_scrub(wm)) {
1588 ED_scene_draw_fps(scene, xoffset, &yoffset);
1589 BLF_color4fv(font_id, text_color);
1590 }
1591 else if (U.uiflag & USER_SHOW_VIEWPORTNAME) {
1592 draw_viewport_name(region, v3d, xoffset, &yoffset);
1593 }
1594
1595 if (U.uiflag & USER_DRAWVIEWINFO) {
1596 BKE_view_layer_synced_ensure(scene, view_layer);
1597 Object *ob = BKE_view_layer_active_object_get(view_layer);
1598 draw_selected_name(v3d, scene, view_layer, ob, xoffset, &yoffset);
1599 BLF_color4fv(font_id, text_color);
1600 }
1601
1603 /* draw below the viewport name */
1604 draw_grid_unit_name(scene, region, v3d, xoffset, &yoffset);
1605 }
1606
1608 }
1609
1610 if (v3d->overlay.flag & V3D_OVERLAY_STATS) {
1611 View3D *v3d_local = v3d->localvd ? v3d : nullptr;
1613 bmain, scene, view_layer, v3d_local, xoffset, &yoffset, VIEW3D_OVERLAY_LINEHEIGHT);
1614 }
1615
1616 /* Set the size back to the default hard-coded size. Otherwise anyone drawing after this,
1617 * without setting explicit size, will draw with widget size. That is probably ideal,
1618 * but size should be set at the calling site not just carried over from here. */
1620 BLF_disable(font_id, BLF_SHADOW);
1621 }
1622
1624}
1625
1627
1628/* -------------------------------------------------------------------- */
1631
1632static void view3d_draw_view(const bContext *C, ARegion *region)
1633{
1638 region,
1640 nullptr,
1641 nullptr,
1642 nullptr);
1643
1644 /* Only 100% compliant on new spec goes below */
1646}
1647
1649{
1650 /*
1651 * Temporary viewport draw modes until we have a proper system.
1652 * all modes are done in the draw manager, except external render
1653 * engines like Cycles.
1654 */
1655 RenderEngineType *type = RE_engines_find(scene->r.engine);
1656 if (drawtype == OB_MATERIAL && (type->flag & RE_USE_EEVEE_VIEWPORT)) {
1658 }
1659 return type;
1660}
1661
1663{
1664 View3D *v3d = CTX_wm_view3d(C);
1665 WorkSpace *workspace = CTX_wm_workspace(C);
1666 /* Always use viewer path from workspace, pinning is not supported currently. */
1667 if (!BKE_viewer_path_equal(&v3d->viewer_path, &workspace->viewer_path)) {
1669 BKE_viewer_path_copy(&v3d->viewer_path, &workspace->viewer_path);
1670 }
1671}
1672
1674{
1675 using namespace blender::draw;
1676 Main *bmain = CTX_data_main(C);
1677 View3D *v3d = CTX_wm_view3d(C);
1678
1680 view3d_draw_view(C, region);
1681
1685
1686 /* No depth test for drawing action zones afterwards. */
1688
1690 /* TODO: Clear cache? */
1691}
1692
1694
1695/* -------------------------------------------------------------------- */
1698
1700 const Scene *scene,
1701 View3D *v3d,
1702 ARegion *region,
1703 const float winmat[4][4],
1704 const char *viewname)
1705{
1706 /* update the viewport matrices with the new camera */
1708 float viewmat[4][4];
1709 const bool is_left = STREQ(viewname, STEREO_LEFT_NAME);
1710
1711 BKE_camera_multiview_view_matrix(&scene->r, v3d->camera, is_left, viewmat);
1712 view3d_main_region_setup_offscreen(depsgraph, scene, v3d, region, viewmat, winmat);
1713 }
1714 else { /* SCE_VIEWS_FORMAT_MULTIVIEW */
1715 float viewmat[4][4];
1716 Object *camera = BKE_camera_multiview_render(scene, v3d->camera, viewname);
1717
1718 BKE_camera_multiview_view_matrix(&scene->r, camera, false, viewmat);
1719 view3d_main_region_setup_offscreen(depsgraph, scene, v3d, region, viewmat, winmat);
1720 }
1721}
1722
1724 const Scene *scene,
1725 eDrawType drawtype,
1726 View3D *v3d,
1727 ARegion *region,
1728 int winx,
1729 int winy,
1730 const float viewmat[4][4],
1731 const float winmat[4][4],
1732 bool is_image_render,
1733 bool draw_background,
1734 const char *viewname,
1735 const bool do_color_management,
1736 const bool restore_rv3d_mats,
1737 GPUOffScreen *ofs,
1738 GPUViewport *viewport)
1739{
1740 using namespace blender::draw;
1741 RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata);
1742 RenderEngineType *engine_type = ED_view3d_engine_type(scene, drawtype);
1743
1744 /* Store `orig` variables. */
1745 struct {
1746 bThemeState theme_state;
1747
1748 /* #View3D */
1749 eDrawType v3d_shading_type;
1750 Object *v3d_camera;
1751 float v3d_lens;
1752
1753 /* #Region */
1754 int region_winx, region_winy;
1755 rcti region_winrct;
1756
1757 /* #RegionView3D */
1762 RV3DMatrixStore *rv3d_mats;
1763 char rv3d_persp;
1764 } orig{};
1765 orig.v3d_shading_type = eDrawType(v3d->shading.type);
1766 orig.v3d_camera = v3d->camera;
1767 orig.v3d_lens = v3d->lens;
1768 orig.region_winx = region->winx;
1769 orig.region_winy = region->winy;
1770 orig.region_winrct = region->winrct;
1771 orig.rv3d_persp = rv3d->persp;
1772 orig.rv3d_mats = ED_view3d_mats_rv3d_backup(static_cast<RegionView3D *>(region->regiondata));
1773
1774 UI_Theme_Store(&orig.theme_state);
1776
1777 /* Set temporary new size. */
1778 region->winx = winx;
1779 region->winy = winy;
1780 region->winrct.xmin = 0;
1781 region->winrct.ymin = 0;
1782 region->winrct.xmax = winx;
1783 region->winrct.ymax = winy;
1784
1785 /* There are too many functions inside the draw manager that check the shading type,
1786 * so use a temporary override instead. */
1787 v3d->shading.type = drawtype;
1788
1789 /* Set flags. */
1791
1792 {
1793 /* Free images which can have changed on frame-change.
1794 * WARNING(@ideasman42): can be slow so only free animated images. */
1796 }
1797
1798 if (viewmat) {
1799 /* WORKAROUND: Disable camera view to avoid EEVEE being confused and try to
1800 * get the projection matrix from the camera.
1801 * Set the `lens` parameter to 0 to make EEVEE prefer the `winmat` from the rv3d instead of
1802 * trying to rederive it. Note that this produces incorrect result with over-scan. */
1803 rv3d->persp = (winmat[3][3] == 0.0f) ? RV3D_PERSP : RV3D_ORTHO;
1804 v3d->camera = nullptr;
1805 v3d->lens = 0.0f;
1806 }
1807
1812
1813 if ((viewname != nullptr && viewname[0] != '\0') && (viewmat == nullptr) &&
1814 rv3d->persp == RV3D_CAMOB && v3d->camera)
1815 {
1816 view3d_stereo3d_setup_offscreen(depsgraph, scene, v3d, region, winmat, viewname);
1817 }
1818 else {
1819 view3d_main_region_setup_offscreen(depsgraph, scene, v3d, region, viewmat, winmat);
1820 }
1821
1822 if (viewport) {
1823 GPU_viewport_tag_update(viewport);
1824 }
1825
1826 /* main drawing call */
1828 engine_type,
1829 region,
1830 v3d,
1831 is_image_render,
1833 do_color_management,
1834 ofs,
1835 viewport);
1839
1840 /* Restore all `orig` members. */
1841 region->winx = orig.region_winx;
1842 region->winy = orig.region_winy;
1843 region->winrct = orig.region_winrct;
1844
1845 /* Optionally do _not_ restore rv3d matrices (e.g. they are used/stored in the ImBuff for
1846 * reprojection, see texture_paint_image_from_view_exec(). */
1847 if (restore_rv3d_mats) {
1848 ED_view3d_mats_rv3d_restore(static_cast<RegionView3D *>(region->regiondata), orig.rv3d_mats);
1849 }
1850 MEM_freeN(orig.rv3d_mats);
1851 rv3d->persp = orig.rv3d_persp;
1852
1853 UI_Theme_Restore(&orig.theme_state);
1854
1855 v3d->shading.type = orig.v3d_shading_type;
1856 v3d->camera = orig.v3d_camera;
1857 v3d->lens = orig.v3d_lens;
1858
1860}
1861
1863 Scene *scene,
1864 View3DShading *shading_override,
1865 eDrawType drawtype,
1866 int object_type_exclude_viewport_override,
1867 int object_type_exclude_select_override,
1868 int winx,
1869 int winy,
1870 uint draw_flags,
1871 const float viewmat[4][4],
1872 const float winmat[4][4],
1873 float clip_start,
1874 float clip_end,
1875 bool is_xr_surface,
1876 bool is_image_render,
1877 bool draw_background,
1878 const char *viewname,
1879 const bool do_color_management,
1880 GPUOffScreen *ofs,
1881 GPUViewport *viewport)
1882{
1883 View3D v3d = blender::dna::shallow_zero_initialize();
1884 ARegion ar = {nullptr};
1885 blender::bke::ARegionRuntime region_runtime{};
1886 ar.runtime = &region_runtime;
1887 RegionView3D rv3d = {{{0}}};
1888
1889 v3d.regionbase.first = v3d.regionbase.last = &ar;
1890 ar.regiondata = &rv3d;
1892
1893 View3DShading *source_shading_settings = &scene->display.shading;
1894 if (draw_flags & V3D_OFSDRAW_OVERRIDE_SCENE_SETTINGS && shading_override != nullptr) {
1895 source_shading_settings = shading_override;
1896 }
1897 memcpy(&v3d.shading, source_shading_settings, sizeof(View3DShading));
1898 v3d.shading.type = drawtype;
1899
1900 if (shading_override) {
1901 /* Pass. */
1902 }
1903 else if (drawtype == OB_MATERIAL) {
1905 }
1906
1909 }
1910 else {
1911 if (draw_flags & V3D_OFSDRAW_SHOW_ANNOTATION) {
1913 }
1914 if (draw_flags & V3D_OFSDRAW_SHOW_GRIDFLOOR) {
1916 v3d.grid = 1.0f;
1917 v3d.gridlines = 16;
1918 v3d.gridsubdiv = 10;
1919 }
1920 if (draw_flags & V3D_OFSDRAW_SHOW_SELECTION) {
1921 v3d.flag |= V3D_SELECT_OUTLINE;
1922 }
1923 if (draw_flags & V3D_OFSDRAW_XR_SHOW_CONTROLLERS) {
1925 }
1926 if (draw_flags & V3D_OFSDRAW_XR_SHOW_CUSTOM_OVERLAYS) {
1928 }
1929 if (draw_flags & V3D_OFSDRAW_XR_SHOW_PASSTHROUGH) {
1931 }
1932 /* Disable other overlays (set all available _HIDE_ flags). */
1935 if ((draw_flags & V3D_OFSDRAW_SHOW_OBJECT_EXTRAS) == 0) {
1937 }
1938 if ((object_type_exclude_viewport_override & (1 << OB_ARMATURE)) != 0) {
1940 }
1941 v3d.flag |= V3D_HIDE_HELPLINES;
1942 }
1943
1944 if (is_xr_surface) {
1946 }
1947
1948 v3d.object_type_exclude_viewport = object_type_exclude_viewport_override;
1949 v3d.object_type_exclude_select = object_type_exclude_select_override;
1950
1951 rv3d.persp = RV3D_PERSP;
1952 v3d.clip_start = clip_start;
1953 v3d.clip_end = clip_end;
1954 /* Actually not used since we pass in the projection matrix. */
1955 v3d.lens = 0;
1956
1957 /* WORKAROUND: Disable overscan because it is not supported for arbitrary input matrices.
1958 * The proper fix to this would be to support arbitrary matrices in `eevee::Camera::sync()`. */
1959 float overscan = scene->eevee.overscan;
1960 scene->eevee.overscan = 0.0f;
1961
1963 scene,
1964 drawtype,
1965 &v3d,
1966 &ar,
1967 winx,
1968 winy,
1969 viewmat,
1970 winmat,
1971 is_image_render,
1973 viewname,
1974 do_color_management,
1975 true,
1976 ofs,
1977 viewport);
1978
1979 /* Restore overscan. */
1980 scene->eevee.overscan = overscan;
1981}
1982
1984 Scene *scene,
1985 eDrawType drawtype,
1986 View3D *v3d,
1987 ARegion *region,
1988 int sizex,
1989 int sizey,
1990 eImBufFlags imbuf_flag,
1991 int alpha_mode,
1992 const char *viewname,
1993 const bool restore_rv3d_mats,
1994 GPUOffScreen *ofs,
1995 GPUViewport *viewport,
1996 /* output vars */
1997 char err_out[256])
1998{
1999 RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata);
2000 const bool draw_sky = (alpha_mode == R_ADDSKY);
2001
2002 /* view state */
2003 bool is_ortho = false;
2004 float winmat[4][4];
2005
2006 /* Guess format based on output buffer. */
2007 eGPUTextureFormat desired_format = (imbuf_flag & IB_float_data) ? GPU_RGBA16F : GPU_RGBA8;
2008
2009 if (ofs && ((GPU_offscreen_width(ofs) != sizex) || (GPU_offscreen_height(ofs) != sizey))) {
2010 /* If offscreen has already been created, recreate with the same format. */
2011 desired_format = GPU_offscreen_format(ofs);
2012 /* sizes differ, can't reuse */
2013 ofs = nullptr;
2014 }
2015
2016 GPUFrameBuffer *old_fb = GPU_framebuffer_active_get();
2017
2018 if (old_fb) {
2020 }
2021
2022 const bool own_ofs = (ofs == nullptr);
2024
2025 if (own_ofs) {
2026 /* bind */
2027 ofs = GPU_offscreen_create(sizex,
2028 sizey,
2029 true,
2030 desired_format,
2032 false,
2033 err_out);
2034 if (ofs == nullptr) {
2036 return nullptr;
2037 }
2038 }
2039
2040 GPU_offscreen_bind(ofs, true);
2041
2042 /* read in pixels & stamp */
2043 ImBuf *ibuf = IMB_allocImBuf(sizex, sizey, 32, imbuf_flag);
2044
2045 /* render 3d view */
2046 if (rv3d->persp == RV3D_CAMOB && v3d->camera) {
2048 Object *camera = BKE_camera_multiview_render(scene, v3d->camera, viewname);
2049 const Object *camera_eval = DEG_get_evaluated(depsgraph, camera);
2050
2052 /* fallback for non camera objects */
2053 params.clip_start = v3d->clip_start;
2054 params.clip_end = v3d->clip_end;
2056 BKE_camera_multiview_params(&scene->r, &params, camera_eval, viewname);
2057 BKE_camera_params_compute_viewplane(&params, sizex, sizey, scene->r.xasp, scene->r.yasp);
2059
2060 is_ortho = params.is_ortho;
2061 copy_m4_m4(winmat, params.winmat);
2062 }
2063 else {
2064 rctf viewplane;
2065 float clip_start, clipend;
2066
2067 is_ortho = ED_view3d_viewplane_get(
2068 depsgraph, v3d, rv3d, sizex, sizey, &viewplane, &clip_start, &clipend, nullptr);
2069 if (is_ortho) {
2070 orthographic_m4(winmat,
2071 viewplane.xmin,
2072 viewplane.xmax,
2073 viewplane.ymin,
2074 viewplane.ymax,
2075 -clipend,
2076 clipend);
2077 }
2078 else {
2079 perspective_m4(winmat,
2080 viewplane.xmin,
2081 viewplane.xmax,
2082 viewplane.ymin,
2083 viewplane.ymax,
2084 clip_start,
2085 clipend);
2086 }
2087 }
2088
2089 /* XXX(jbakker): `do_color_management` should be controlled by the caller. Currently when doing a
2090 * viewport render animation and saving to an 8bit file format, color management would be applied
2091 * twice. Once here, and once when saving the saving to disk. In this case the Save As Render
2092 * option cannot be controlled either. But when doing an off-screen render you want to do the
2093 * color management here.
2094 *
2095 * This option was added here to increase the performance for quick view-port preview renders.
2096 * When using workbench the color differences haven't been reported as a bug. But users also use
2097 * the viewport rendering to render Eevee scenes. In the later situation the saved colors are
2098 * totally wrong. */
2099 const bool do_color_management = (ibuf->float_buffer.data == nullptr);
2101 scene,
2102 drawtype,
2103 v3d,
2104 region,
2105 sizex,
2106 sizey,
2107 nullptr,
2108 winmat,
2109 true,
2110 draw_sky,
2111 viewname,
2112 do_color_management,
2113 restore_rv3d_mats,
2114 ofs,
2115 viewport);
2116
2117 if (ibuf->float_buffer.data) {
2119 }
2120 else if (ibuf->byte_buffer.data) {
2122 }
2123
2124 /* unbind */
2125 GPU_offscreen_unbind(ofs, true);
2126
2127 if (own_ofs) {
2128 GPU_offscreen_free(ofs);
2129 }
2130
2132
2133 if (old_fb) {
2134 GPU_framebuffer_bind(old_fb);
2135 }
2136
2137 if (ibuf->float_buffer.data && ibuf->byte_buffer.data) {
2138 IMB_byte_from_float(ibuf);
2139 }
2140
2141 return ibuf;
2142}
2143
2145 Scene *scene,
2146 View3DShading *shading_override,
2147 eDrawType drawtype,
2148 Object *camera,
2149 int width,
2150 int height,
2151 eImBufFlags imbuf_flag,
2152 eV3DOffscreenDrawFlag draw_flags,
2153 int alpha_mode,
2154 const char *viewname,
2155 GPUOffScreen *ofs,
2156 GPUViewport *viewport,
2157 char err_out[256])
2158{
2159 View3D v3d = blender::dna::shallow_zero_initialize();
2160 ARegion region = {nullptr};
2161 blender::bke::ARegionRuntime region_runtime{};
2162 region.runtime = &region_runtime;
2163 RegionView3D rv3d = {{{0}}};
2164
2165 /* connect data */
2166 v3d.regionbase.first = v3d.regionbase.last = &region;
2167 region.regiondata = &rv3d;
2168 region.regiontype = RGN_TYPE_WINDOW;
2169
2170 v3d.camera = camera;
2171 View3DShading *source_shading_settings = &scene->display.shading;
2172 if (draw_flags & V3D_OFSDRAW_OVERRIDE_SCENE_SETTINGS && shading_override != nullptr) {
2173 source_shading_settings = shading_override;
2174 }
2175 memcpy(&v3d.shading, source_shading_settings, sizeof(View3DShading));
2176
2177 if (drawtype == OB_RENDER) {
2178 /* Don't use external engines for preview. Fall back to solid instead of Eevee as rendering
2179 * with Eevee is potentially slow due to compiling shaders and loading textures, and the
2180 * depsgraph may not have been updated to have all the right geometry attributes. */
2182 drawtype = OB_SOLID;
2183 }
2184 }
2185
2186 if (drawtype == OB_MATERIAL) {
2189 }
2190 else if (drawtype == OB_RENDER) {
2193 }
2194 else if (drawtype == OB_TEXTURE) {
2195 drawtype = OB_SOLID;
2198 }
2199 v3d.shading.type = drawtype;
2200
2202 /* HACK: When rendering gpencil objects this opacity is used to mix vertex colors in when not in
2203 * render mode (e.g. in the sequencer). */
2205
2206 /* Also initialize wire-frame properties to the default so it renders properly in sequencer.
2207 * Should find some way to use the viewport's current opacity and threshold,
2208 * but this is a start. */
2209 v3d.overlay.wireframe_opacity = 1.0f;
2210 v3d.overlay.wireframe_threshold = 0.5f;
2211
2212 if (draw_flags & V3D_OFSDRAW_SHOW_ANNOTATION) {
2214 }
2215 if (draw_flags & V3D_OFSDRAW_SHOW_GRIDFLOOR) {
2217 }
2218
2220
2221 rv3d.persp = RV3D_CAMOB;
2222
2223 copy_m4_m4(rv3d.viewinv, v3d.camera->object_to_world().ptr());
2224 normalize_m4(rv3d.viewinv);
2225 invert_m4_m4(rv3d.viewmat, rv3d.viewinv);
2226
2227 {
2229 const Object *view_camera_eval = DEG_get_evaluated(
2230 depsgraph, BKE_camera_multiview_render(scene, v3d.camera, viewname));
2231
2233 BKE_camera_params_from_object(&params, view_camera_eval);
2234 BKE_camera_multiview_params(&scene->r, &params, view_camera_eval, viewname);
2235 BKE_camera_params_compute_viewplane(&params, width, height, scene->r.xasp, scene->r.yasp);
2237
2238 copy_m4_m4(rv3d.winmat, params.winmat);
2239 v3d.clip_start = params.clip_start;
2240 v3d.clip_end = params.clip_end;
2241 v3d.lens = params.lens;
2242 }
2243
2244 mul_m4_m4m4(rv3d.persmat, rv3d.winmat, rv3d.viewmat);
2245 invert_m4_m4(rv3d.persinv, rv3d.viewinv);
2246
2248 scene,
2249 eDrawType(v3d.shading.type),
2250 &v3d,
2251 &region,
2252 width,
2253 height,
2254 imbuf_flag,
2255 alpha_mode,
2256 viewname,
2257 true,
2258 ofs,
2259 viewport,
2260 err_out);
2261}
2262
2267
2269
2270/* -------------------------------------------------------------------- */
2273
2274static bool view3d_clipping_test(const float co[3], const float clip[6][4])
2275{
2276 if (plane_point_side_v3(clip[0], co) > 0.0f && plane_point_side_v3(clip[1], co) > 0.0f &&
2277 plane_point_side_v3(clip[2], co) > 0.0f && plane_point_side_v3(clip[3], co) > 0.0f)
2278 {
2279 return false;
2280 }
2281 return true;
2282}
2283
2284bool ED_view3d_clipping_test(const RegionView3D *rv3d, const float co[3], const bool is_local)
2285{
2286 return view3d_clipping_test(co, is_local ? rv3d->clip_local : rv3d->clip);
2287}
2288
2290
2291/* -------------------------------------------------------------------- */
2294
2299 const Scene *scene,
2300 ViewLayer *view_layer,
2301 ARegion *region,
2302 View3D *v3d,
2303 Object *obact)
2304{
2305 /* TODO: Use a flag in the selection engine itself. */
2307 return;
2308 }
2309 Object *obact_eval = DEG_get_evaluated(depsgraph, obact);
2310
2312 UNUSED_VARS_NDEBUG(region);
2313
2314 if (obact_eval && (obact_eval->mode & (OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT) ||
2315 BKE_paint_select_face_test(obact_eval)))
2316 {
2317 /* do nothing */
2318 }
2319 /* texture paint mode sampling */
2320 else if (obact_eval && (obact_eval->mode & OB_MODE_TEXTURE_PAINT) &&
2321 (v3d->shading.type > OB_WIRE))
2322 {
2323 /* do nothing */
2324 }
2325 else if ((obact_eval && (obact_eval->mode & OB_MODE_PARTICLE_EDIT)) && !XRAY_ENABLED(v3d)) {
2326 /* do nothing */
2327 }
2328 else {
2330 return;
2331 }
2332
2333 if (obact_eval && ((obact_eval->base_flag & BASE_ENABLED_AND_MAYBE_VISIBLE_IN_VIEWPORT) != 0)) {
2334 BKE_view_layer_synced_ensure(scene, view_layer);
2335 Base *base = BKE_view_layer_base_find(view_layer, obact);
2337 }
2338
2340}
2341
2342/* Avoid calling this function multiple times in sequence to prevent frequent CPU-GPU
2343 * synchronization (which can be very slow). */
2344static void view3d_gpu_read_Z_pixels(GPUViewport *viewport, rcti *rect, void *data)
2345{
2346 GPUTexture *depth_tx = GPU_viewport_depth_texture(viewport);
2347
2348 GPUFrameBuffer *depth_read_fb = nullptr;
2349 GPU_framebuffer_ensure_config(&depth_read_fb,
2350 {
2351 GPU_ATTACHMENT_TEXTURE(depth_tx),
2353 });
2354
2355 GPU_framebuffer_bind(depth_read_fb);
2356 GPU_framebuffer_read_depth(depth_read_fb,
2357 rect->xmin,
2358 rect->ymin,
2359 BLI_rcti_size_x(rect),
2360 BLI_rcti_size_y(rect),
2362 data);
2363
2365 GPU_framebuffer_free(depth_read_fb);
2366}
2367
2369{
2371 vc->depsgraph, vc->scene, vc->view_layer, vc->region, vc->v3d, vc->obact);
2372}
2373
2374int ED_view3d_backbuf_sample_size_clamp(ARegion *region, const float dist)
2375{
2376 return int(min_ff(ceilf(dist), float(max_ii(region->winx, region->winx))));
2377}
2378
2380
2381/* -------------------------------------------------------------------- */
2384
2386{
2387 /* clamp rect by region */
2388 rcti r{};
2389 r.xmin = 0;
2390 r.xmax = region->winx - 1;
2391 r.ymin = 0;
2392 r.ymax = region->winy - 1;
2393
2394 /* Constrain rect to depth bounds */
2395 BLI_rcti_isect(&r, rect, rect);
2396
2397 /* assign values to compare with the ViewDepths */
2398 int x = rect->xmin;
2399 int y = rect->ymin;
2400
2401 int w = BLI_rcti_size_x(rect);
2402 int h = BLI_rcti_size_y(rect);
2403
2404 if (w <= 0 || h <= 0) {
2405 r_d->depths = nullptr;
2406 return;
2407 }
2408
2409 r_d->x = x;
2410 r_d->y = y;
2411 r_d->w = w;
2412 r_d->h = h;
2413
2414 r_d->depths = MEM_malloc_arrayN<float>(w * h, "View depths Subset");
2415
2416 {
2417 GPUViewport *viewport = WM_draw_region_get_viewport(region);
2418 view3d_gpu_read_Z_pixels(viewport, rect, r_d->depths);
2419 /* Range is assumed to be this as they are never changed. */
2420 r_d->depth_range[0] = 0.0;
2421 r_d->depth_range[1] = 1.0;
2422 }
2423}
2424
2425/* NOTE: with NOUVEAU drivers the #glReadPixels() is very slow. #24339. */
2427{
2428 ViewDepths *d = MEM_callocN<ViewDepths>("ViewDepths");
2429
2430 {
2431 GPUViewport *viewport = WM_draw_region_get_viewport(region);
2432 GPUTexture *depth_tx = GPU_viewport_depth_texture(viewport);
2433 uint32_t *int_depths = static_cast<uint32_t *>(
2434 GPU_texture_read(depth_tx, GPU_DATA_UINT_24_8, 0));
2435 d->w = GPU_texture_width(depth_tx);
2436 d->h = GPU_texture_height(depth_tx);
2437 d->depths = (float *)int_depths;
2438 /* Convert in-place. */
2439 int pixel_count = d->w * d->h;
2440 for (int i = 0; i < pixel_count; i++) {
2441 d->depths[i] = (int_depths[i] >> 8u) / float(0xFFFFFF);
2442 }
2443 /* Assumed to be this as they are never changed. */
2444 d->depth_range[0] = 0.0;
2445 d->depth_range[1] = 1.0;
2446 }
2447 return d;
2448}
2449
2451{
2452 /* Convert to float for comparisons. */
2453 const float near = float(d->depth_range[0]);
2454 const float far_real = float(d->depth_range[1]);
2455 float far = far_real;
2456
2457 const float *depths = d->depths;
2458 float depth = FLT_MAX;
2459 int i = int(d->w) * int(d->h); /* Cast to avoid short overflow. */
2460
2461 /* Far is both the starting 'far' value
2462 * and the closest value found. */
2463 while (i--) {
2464 depth = *depths++;
2465 if ((depth < far) && (depth > near)) {
2466 far = depth;
2467 }
2468 }
2469
2470 return far == far_real ? FLT_MAX : far;
2471}
2472
2474 ARegion *region,
2475 View3D *v3d,
2476 Object * /* obact */,
2478 bool use_overlay,
2479 ViewDepths **r_depths)
2480{
2482 /* Force redraw if `r_depths` is required. */
2483 if (!r_depths || *r_depths != nullptr) {
2484 return;
2485 }
2486 }
2487 bThemeState theme_state;
2489 RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata);
2490
2491 short flag = v3d->flag;
2492 int flag2 = v3d->flag2;
2493 /* Setting these temporarily is not nice */
2494 v3d->flag &= ~V3D_SELECT_OUTLINE;
2495
2496 if (v3d->flag2 & V3D_HIDE_OVERLAYS) {
2497 use_overlay = false;
2498 }
2499
2500 if (!use_overlay) {
2501 v3d->flag2 |= V3D_HIDE_OVERLAYS;
2502 }
2503
2504 /* Tools may request depth outside of regular drawing code. */
2505 UI_Theme_Store(&theme_state);
2507
2508 ED_view3d_draw_setup_view(static_cast<wmWindowManager *>(G_MAIN->wm.first),
2509 nullptr,
2510 depsgraph,
2511 scene,
2512 region,
2513 v3d,
2514 nullptr,
2515 nullptr,
2516 nullptr);
2517
2518 /* get surface depth without bias */
2520
2521 /* Needed in cases the 3D Viewport isn't already setup. */
2524
2525 GPUViewport *viewport = WM_draw_region_get_viewport(region);
2526 /* When Blender is starting, a click event can trigger a depth test while the viewport is not
2527 * yet available. */
2528 if (viewport != nullptr) {
2529 switch (mode) {
2530 case V3D_DEPTH_ALL:
2531 DRW_draw_depth_loop(depsgraph, region, v3d, viewport, true, false, false);
2532 break;
2534 DRW_draw_depth_loop(depsgraph, region, v3d, viewport, false, false, false);
2535 break;
2537 DRW_draw_depth_loop(depsgraph, region, v3d, viewport, true, false, false);
2538 break;
2540 DRW_draw_depth_loop(depsgraph, region, v3d, viewport, false, false, true);
2541 break;
2543 DRW_draw_depth_loop(depsgraph, region, v3d, viewport, false, true, false);
2544 break;
2545 }
2546
2547 if (r_depths) {
2548 if (*r_depths) {
2549 ED_view3d_depths_free(*r_depths);
2550 }
2551 *r_depths = view3d_depths_create(region);
2552 }
2553 }
2554
2556
2558
2559 /* Restore. */
2560 v3d->flag = flag;
2561 v3d->flag2 = flag2;
2563
2564 UI_Theme_Restore(&theme_state);
2565}
2566
2568{
2569 if (depths->depths) {
2570 MEM_freeN(depths->depths);
2571 }
2572 MEM_freeN(depths);
2573}
2574
2575bool ED_view3d_has_depth_buffer_updated(const Depsgraph *depsgraph, const View3D *v3d)
2576{
2577#ifdef REUSE_DEPTH_BUFFER
2578 /* Check if the depth buffer was drawn by any engine and thus can be reused.
2579 *
2580 * The idea is good, but it is too error prone.
2581 * Even when updated by an engine, the depth buffer can still be cleared by drawing callbacks and
2582 * by the GPU_select API used by gizmos.
2583 * Check #GPU_clear_depth to track when the depth buffer is cleared. */
2584 const char *engine_name = DEG_get_evaluated_scene(depsgraph)->r.engine;
2585 RenderEngineType *engine_type = RE_engines_find(engine_name);
2586
2587 bool is_viewport_wire_no_xray = v3d->shading.type < OB_SOLID && !XRAY_ENABLED(v3d);
2588 bool is_viewport_preview_solid = v3d->shading.type == OB_SOLID;
2589 bool is_viewport_preview_material = v3d->shading.type == OB_MATERIAL;
2590 bool is_viewport_render_eevee = v3d->shading.type == OB_RENDER &&
2591 (STREQ(engine_name, RE_engine_id_BLENDER_EEVEE_NEXT));
2592 bool is_viewport_render_workbench = v3d->shading.type == OB_RENDER &&
2594 bool is_viewport_render_external_with_overlay = v3d->shading.type == OB_RENDER &&
2595 !(engine_type->flag & RE_INTERNAL) &&
2596 !(v3d->flag2 & V3D_HIDE_OVERLAYS);
2597
2598 return is_viewport_preview_solid || is_viewport_preview_material || is_viewport_wire_no_xray ||
2599 is_viewport_render_eevee || is_viewport_render_workbench ||
2600 is_viewport_render_external_with_overlay;
2601#else
2602 UNUSED_VARS(depsgraph, v3d);
2603 return false;
2604#endif
2605}
2606
2608
2609/* -------------------------------------------------------------------- */
2612
2613void ED_view3d_datamask(const Scene *scene,
2614 ViewLayer *view_layer,
2615 const View3D *v3d,
2616 CustomData_MeshMasks *r_cddata_masks)
2617{
2618 /* NOTE(@ideasman42): as this function runs continuously while idle
2619 * (from #wm_event_do_depsgraph) take care to avoid expensive lookups.
2620 * While they won't hurt performance noticeably, they will increase CPU usage while idle. */
2623 r_cddata_masks->vmask |= CD_MASK_ORCO | CD_MASK_PROP_COLOR;
2624 }
2625 else if (v3d->shading.type == OB_SOLID) {
2627 r_cddata_masks->lmask |= CD_MASK_PROP_FLOAT2;
2628 }
2630 r_cddata_masks->lmask |= CD_MASK_PROP_BYTE_COLOR;
2631 r_cddata_masks->vmask |= CD_MASK_ORCO | CD_MASK_PROP_COLOR;
2632 }
2633 }
2634
2635 BKE_view_layer_synced_ensure(scene, view_layer);
2636 Object *obact = BKE_view_layer_active_object_get(view_layer);
2637 if (obact) {
2638 switch (obact->type) {
2639 case OB_MESH: {
2640 switch (obact->mode) {
2641 case OB_MODE_EDIT: {
2643 r_cddata_masks->vmask |= CD_MASK_MDEFORMVERT;
2644 }
2645 break;
2646 }
2647 }
2648 break;
2649 }
2650 }
2651 }
2652}
2653
2655 ViewLayer *view_layer,
2656 const bScreen *screen,
2657 CustomData_MeshMasks *r_cddata_masks)
2658{
2660
2661 /* Check if we need UV or color data due to the view mode. */
2662 LISTBASE_FOREACH (const ScrArea *, area, &screen->areabase) {
2663 if (area->spacetype == SPACE_VIEW3D) {
2665 scene, view_layer, static_cast<View3D *>(area->spacedata.first), r_cddata_masks);
2666 }
2667 }
2668}
2669
2671
2672/* -------------------------------------------------------------------- */
2675
2684 float winmat[4][4];
2685 float viewmat[4][4];
2686 float viewinv[4][4];
2687 float persmat[4][4];
2688 float persinv[4][4];
2690 float pixsize;
2691};
2692
2694{
2695 RV3DMatrixStore *rv3dmat = static_cast<RV3DMatrixStore *>(
2696 MEM_mallocN(sizeof(*rv3dmat), __func__));
2697 copy_m4_m4(rv3dmat->winmat, rv3d->winmat);
2698 copy_m4_m4(rv3dmat->viewmat, rv3d->viewmat);
2699 copy_m4_m4(rv3dmat->persmat, rv3d->persmat);
2700 copy_m4_m4(rv3dmat->persinv, rv3d->persinv);
2701 copy_m4_m4(rv3dmat->viewinv, rv3d->viewinv);
2703 rv3dmat->pixsize = rv3d->pixsize;
2704 return rv3dmat;
2705}
2706
2708{
2709 RV3DMatrixStore *rv3dmat = rv3dmat_pt;
2710 copy_m4_m4(rv3d->winmat, rv3dmat->winmat);
2711 copy_m4_m4(rv3d->viewmat, rv3dmat->viewmat);
2712 copy_m4_m4(rv3d->persmat, rv3dmat->persmat);
2713 copy_m4_m4(rv3d->persinv, rv3dmat->persinv);
2714 copy_m4_m4(rv3d->viewinv, rv3dmat->viewinv);
2716 rv3d->pixsize = rv3dmat->pixsize;
2717}
2718
2720{
2721 MEM_freeN(rv3d_mat);
2722}
2723
2725
2726/* -------------------------------------------------------------------- */
2729
2730void ED_scene_draw_fps(const Scene *scene, int xoffset, int *yoffset)
2731{
2732 *yoffset -= VIEW3D_OVERLAY_LINEHEIGHT;
2733
2735 if (!ED_scene_fps_average_calc(scene, &state)) {
2736 return;
2737 }
2738
2739 /* 8 4-bytes chars (complex writing systems like Devanagari in UTF8 encoding) */
2740 char printable[32];
2741 printable[0] = '\0';
2742
2743 bool show_fractional = state.fps_target_is_fractional;
2744
2745 const int font_id = BLF_default();
2746
2747 /* Is this more than half a frame behind? */
2748 if (state.fps_average + 0.5f < state.fps_target) {
2749 /* Always show fractional when under performing. */
2750 show_fractional = true;
2751 float alert_rgb[4];
2752 float alert_hsv[4];
2753 UI_GetThemeColor4fv(TH_REDALERT, alert_rgb);
2754 /* Brighten since we favor dark shadows to increase contrast.
2755 * This gives similar results to the old hardcoded 225, 36, 36. */
2756 rgb_to_hsv_v(alert_rgb, alert_hsv);
2757 alert_hsv[2] = 1.0;
2758 hsv_to_rgb_v(alert_hsv, alert_rgb);
2759 BLF_color4fv(font_id, alert_rgb);
2760 }
2761
2762 if (show_fractional) {
2763 SNPRINTF(printable, IFACE_("fps: %.2f"), state.fps_average);
2764 }
2765 else {
2766 SNPRINTF(printable, IFACE_("fps: %i"), int(state.fps_average + 0.5f));
2767 }
2768
2769 BLF_draw_default(xoffset, *yoffset, 0.0f, printable, sizeof(printable));
2770}
2771
2773
2774/* -------------------------------------------------------------------- */
2777
2779{
2780 RenderEngineType *type = RE_engines_find(scene->r.engine);
2781 return (type && type->view_update && type->view_draw);
2782}
2783
2785 const Scene *scene, Depsgraph *depsgraph, View3D *v3d, ARegion *region, rcti *r_rect)
2786{
2787 RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata);
2788 bool use_border;
2789
2790 /* Test if there is a 3d view rendering. */
2792 return false;
2793 }
2794
2795 /* Test if there is a border render. */
2796 if (rv3d->persp == RV3D_CAMOB) {
2797 use_border = (scene->r.mode & R_BORDER) != 0;
2798 }
2799 else {
2800 use_border = (v3d->flag2 & V3D_RENDER_BORDER) != 0;
2801 }
2802
2803 if (!use_border) {
2804 return false;
2805 }
2806
2807 /* Compute border. */
2808 if (rv3d->persp == RV3D_CAMOB) {
2809 rctf viewborder;
2810 ED_view3d_calc_camera_border(scene, depsgraph, region, v3d, rv3d, false, &viewborder);
2811
2812 r_rect->xmin = viewborder.xmin + scene->r.border.xmin * BLI_rctf_size_x(&viewborder);
2813 r_rect->ymin = viewborder.ymin + scene->r.border.ymin * BLI_rctf_size_y(&viewborder);
2814 r_rect->xmax = viewborder.xmin + scene->r.border.xmax * BLI_rctf_size_x(&viewborder);
2815 r_rect->ymax = viewborder.ymin + scene->r.border.ymax * BLI_rctf_size_y(&viewborder);
2816 }
2817 else {
2818 r_rect->xmin = v3d->render_border.xmin * region->winx;
2819 r_rect->xmax = v3d->render_border.xmax * region->winx;
2820 r_rect->ymin = v3d->render_border.ymin * region->winy;
2821 r_rect->ymax = v3d->render_border.ymax * region->winy;
2822 }
2823
2824 BLI_rcti_translate(r_rect, region->winrct.xmin, region->winrct.ymin);
2825 BLI_rcti_isect(&region->winrct, r_rect, r_rect);
2826
2827 return true;
2828}
2829
2831
2832/* -------------------------------------------------------------------- */
2835
2837{
2838 GPUViewport *viewport = WM_draw_region_get_viewport(region);
2839 if (viewport == nullptr) {
2840 return false;
2841 }
2842
2843 GPUTexture *color_tex = GPU_viewport_color_texture(viewport, 0);
2844 if (color_tex == nullptr) {
2845 return false;
2846 }
2847
2848 tex_w = GPU_texture_width(color_tex);
2849 tex_h = GPU_texture_height(color_tex);
2850 BLI_rcti_init(&valid_rect, 0, min_ii(region->winx, tex_w) - 1, 0, min_ii(region->winy, tex_h));
2851
2852 /* Copying pixels from textures only works when HOST_READ usage is enabled on them.
2853 * However, doing so can have performance impact, which we don't want for the viewport.
2854 * So, instead allocate a separate texture with HOST_READ here, copy to it, and then
2855 * copy that back to the host.
2856 * Since color picking is a fairly rare operation, the inefficiency here doesn't really
2857 * matter, and it means the viewport doesn't need HOST_READ. */
2859 "copy_tex", tex_w, tex_h, 1, GPU_RGBA16F, GPU_TEXTURE_USAGE_HOST_READ, nullptr);
2860 if (tex == nullptr) {
2861 return false;
2862 }
2863
2864 GPU_texture_copy(tex, color_tex);
2866 data = static_cast<blender::ushort4 *>(GPU_texture_read(tex, GPU_DATA_HALF_FLOAT, 0));
2867
2868 return true;
2869}
2870
2871bool ViewportColorSampleSession::sample(const int mval[2], float r_col[3])
2872{
2873 if (tex == nullptr || data == nullptr) {
2874 return false;
2875 }
2876
2877 if (!BLI_rcti_isect_pt_v(&valid_rect, mval)) {
2878 return false;
2879 }
2880
2881 blender::ushort4 pixel = data[mval[1] * tex_w + mval[0]];
2882
2883 if (blender::math::half_to_float(pixel.w) < 0.5f) {
2884 /* Background etc. are not rendered to the viewport texture, so fall back to basic color
2885 * picking for those. */
2886 return false;
2887 }
2888
2889 r_col[0] = blender::math::half_to_float(pixel.x);
2890 r_col[1] = blender::math::half_to_float(pixel.y);
2891 r_col[2] = blender::math::half_to_float(pixel.z);
2892
2893 return true;
2894}
2895
2897{
2898 if (data != nullptr) {
2899 MEM_freeN(data);
2900 }
2901 if (tex != nullptr) {
2902 GPU_texture_free(tex);
2903 }
2904}
2905
C++ functions to deal with Armature collections (i.e. the successor of bone layers).
bool ANIM_bonecoll_is_visible_actbone(const bArmature *armature)
Functions to insert, delete or modify keyframes.
Camera data-block and utility functions.
void BKE_camera_multiview_params(const struct RenderData *rd, struct CameraParams *params, const struct Object *camera, const char *viewname)
float BKE_camera_multiview_shift_x(const struct RenderData *rd, const struct Object *camera, const char *viewname)
struct Object * BKE_camera_multiview_render(const struct Scene *scene, struct Object *camera, const char *viewname)
int BKE_camera_sensor_fit(int sensor_fit, float sizex, float sizey)
void BKE_camera_params_init(CameraParams *params)
void BKE_camera_multiview_view_matrix(const struct RenderData *rd, const struct Object *camera, bool is_left, float r_viewmat[4][4])
void BKE_camera_params_from_view3d(CameraParams *params, const struct Depsgraph *depsgraph, const struct View3D *v3d, const struct RegionView3D *rv3d)
void BKE_camera_params_from_object(CameraParams *params, const struct Object *cam_ob)
void BKE_camera_params_compute_viewplane(CameraParams *params, int winx, int winy, float aspx, float aspy)
void BKE_camera_params_compute_matrix(CameraParams *params)
const char * BKE_collection_ui_name_get(Collection *collection)
Depsgraph * CTX_data_expect_evaluated_depsgraph(const bContext *C)
WorkSpace * CTX_wm_workspace(const bContext *C)
wmWindow * CTX_wm_window(const bContext *C)
Scene * CTX_data_scene(const bContext *C)
Main * CTX_data_main(const bContext *C)
wmWindowManager * CTX_wm_manager(const bContext *C)
View3D * CTX_wm_view3d(const bContext *C)
ViewLayer * CTX_data_view_layer(const bContext *C)
CustomData interface, see also DNA_customdata_types.h.
void CustomData_MeshMasks_update(CustomData_MeshMasks *mask_dst, const CustomData_MeshMasks *mask_src)
Definition customdata.cc:94
const CustomData_MeshMasks CD_MASK_BAREMESH
@ G_FLAG_RENDER_VIEWPORT
#define G_MAIN
Low-level operations for grease pencil.
void BKE_image_free_anim_gputextures(Main *bmain)
Definition image_gpu.cc:584
void BKE_image_free_old_gputextures(Main *bmain)
Definition image_gpu.cc:595
Key * BKE_key_from_object(Object *ob)
Definition key.cc:1824
void BKE_view_layer_synced_ensure(const Scene *scene, ViewLayer *view_layer)
LayerCollection * BKE_view_layer_active_collection_get(ViewLayer *view_layer)
Object * BKE_view_layer_active_object_get(const ViewLayer *view_layer)
Base * BKE_view_layer_base_find(ViewLayer *view_layer, Object *ob)
General operations, lookup, etc. for blender objects.
Object * BKE_object_pose_armature_get(Object *ob)
bool BKE_paint_select_face_test(const Object *ob)
Definition paint.cc:1599
bool BKE_scene_multiview_is_stereo3d(const RenderData *rd)
Definition scene.cc:2983
bool BKE_scene_uses_blender_workbench(const Scene *scene)
Definition scene.cc:2827
bool BKE_scene_uses_blender_eevee(const Scene *scene)
Definition scene.cc:2821
const char * BKE_scene_find_marker_name(const Scene *scene, int frame)
Definition scene.cc:2278
void BKE_unit_system_get(int system, int type, const void **r_usys_pt, int *r_len)
Definition unit.cc:2513
const char * BKE_unit_display_name_get(const void *usys_pt, int index)
Definition unit.cc:2542
int BKE_unit_base_get(const void *usys_pt)
Definition unit.cc:2526
double BKE_unit_scalar_get(const void *usys_pt, int index)
Definition unit.cc:2559
@ B_UNIT_LENGTH
Definition BKE_unit.hh:124
void BKE_viewer_path_copy(ViewerPath *dst, const ViewerPath *src)
void BKE_viewer_path_clear(ViewerPath *viewer_path)
bool BKE_viewer_path_equal(const ViewerPath *a, const ViewerPath *b, ViewerPathEqualFlag flag=ViewerPathEqualFlag(0))
int BLF_set_default()
void BLF_shadow(int fontid, FontShadowType type, const float rgba[4]=nullptr)
Definition blf.cc:928
@ BLF_SHADOW
Definition BLF_api.hh:435
void BLF_color4fv(int fontid, const float rgba[4])
Definition blf.cc:502
void BLF_shadow_offset(int fontid, int x, int y)
Definition blf.cc:940
void BLF_batch_draw_begin()
Definition blf.cc:531
void BLF_disable(int fontid, int option)
Definition blf.cc:329
int BLF_default()
void BLF_batch_draw_end()
Definition blf.cc:544
void BLF_default_size(float size)
void BLF_enable(int fontid, int option)
Definition blf.cc:320
void BLF_draw_default(float x, float y, float z, const char *str, size_t str_len) ATTR_NONNULL()
#define BLI_assert(a)
Definition BLI_assert.h:46
void * BLI_findlink(const ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:534
#define LISTBASE_FOREACH(type, var, list)
BLI_INLINE bool BLI_listbase_is_empty(const ListBase *lb)
MINLINE int min_ii(int a, int b)
MINLINE float min_ff(float a, float b)
MINLINE int max_ii(int a, int b)
void hsv_to_rgb_v(const float hsv[3], float r_rgb[3])
Definition math_color.cc:57
void rgb_to_hsv_v(const float rgb[3], float r_hsv[3])
#define M_PI
void orthographic_m4(float mat[4][4], float left, float right, float bottom, float top, float nearClip, float farClip)
void perspective_m4(float mat[4][4], float left, float right, float bottom, float top, float nearClip, float farClip)
MINLINE float plane_point_side_v3(const float plane[4], const float co[3])
void mul_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4])
void copy_m4_m4(float m1[4][4], const float m2[4][4])
bool invert_m4_m4(float inverse[4][4], const float mat[4][4])
void normalize_m4(float R[4][4]) ATTR_NONNULL()
void axis_angle_to_quat(float r[4], const float axis[3], float angle)
void mul_qt_v3(const float q[4], float r[3])
MINLINE void copy_v4_v4(float r[4], const float a[4])
void axis_sort_v3(const float axis_values[3], int r_axis_order[3])
MINLINE float len_squared_v3(const float v[3]) ATTR_WARN_UNUSED_RESULT
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void negate_v3_v3(float r[3], const float a[3])
MINLINE float dot_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
MINLINE void add_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void cross_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void mul_v3_v3fl(float r[3], const float a[3], float f)
MINLINE void add_v3_v3(float r[3], const float a[3])
bool BLI_rcti_isect_pt_v(const struct rcti *rect, const int xy[2])
BLI_INLINE int BLI_rcti_size_y(const struct rcti *rct)
Definition BLI_rect.h:198
void BLI_rcti_translate(struct rcti *rect, int x, int y)
Definition rct.cc:566
void BLI_rcti_init(struct rcti *rect, int xmin, int xmax, int ymin, int ymax)
Definition rct.cc:414
bool BLI_rcti_isect(const struct rcti *src1, const struct rcti *src2, struct rcti *dest)
BLI_INLINE int BLI_rcti_size_x(const struct rcti *rct)
Definition BLI_rect.h:194
BLI_INLINE float BLI_rctf_size_x(const struct rctf *rct)
Definition BLI_rect.h:202
BLI_INLINE float BLI_rctf_size_y(const struct rctf *rct)
Definition BLI_rect.h:206
#define SNPRINTF(dst, format,...)
Definition BLI_string.h:599
#define BLI_STR_UTF8_MULTIPLICATION_SIGN
size_t BLI_string_join_array(char *result, size_t result_maxncpy, const char *strings[], uint strings_num) ATTR_NONNULL()
void size_t BLI_string_len_array(const char *strings[], uint strings_num) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
unsigned char uchar
unsigned int uint
void BLI_thread_unlock(int type)
Definition threads.cc:333
void BLI_thread_lock(int type)
Definition threads.cc:328
@ LOCK_VIEW3D
Definition BLI_threads.h:71
#define ARRAY_SIZE(arr)
#define UNUSED_VARS(...)
#define UNUSED_VARS_NDEBUG(...)
#define SET_FLAG_FROM_TEST(value, test, flag)
#define ELEM(...)
#define STREQ(a, b)
#define IFACE_(msgid)
Scene * DEG_get_evaluated_scene(const Depsgraph *graph)
T * DEG_get_evaluated(const Depsgraph *depsgraph, T *id)
@ CAMERA_SENSOR_FIT_HOR
@ CAMERA_SENSOR_FIT_AUTO
@ CAM_DTX_GOLDEN_TRI_A
@ CAM_DTX_CENTER
@ CAM_DTX_HARMONY_TRI_A
@ CAM_DTX_GOLDEN
@ CAM_DTX_GOLDEN_TRI_B
@ CAM_DTX_HARMONY_TRI_B
@ CAM_DTX_CENTER_DIAG
@ CAM_DTX_THIRDS
@ CAM_SHOWPASSEPARTOUT
@ CAM_SHOW_SAFE_MARGINS
@ CAM_SHOW_SAFE_CENTER
@ CAM_SHOWNAME
@ CAM_SHOWSENSOR
@ CAM_PERSP
@ CAM_PANO
@ CAM_CUSTOM
@ CAM_ORTHO
@ BASE_ENABLED_AND_MAYBE_VISIBLE_IN_VIEWPORT
eDrawType
@ OB_WIRE
@ OB_TEXTURE
@ OB_SOLID
@ OB_RENDER
@ OB_MATERIAL
@ OB_MODE_PARTICLE_EDIT
@ OB_MODE_EDIT
@ OB_MODE_WEIGHT_PAINT
@ OB_MODE_POSE
@ OB_MODE_TEXTURE_PAINT
@ OB_MODE_OBJECT
@ OB_MODE_VERTEX_PAINT
Object is a sort of wrapper for general info.
@ OB_SHAPE_LOCK
@ OB_LATTICE
@ OB_CAMERA
@ OB_GREASE_PENCIL
@ OB_ARMATURE
@ OB_MESH
@ OB_CURVES_LEGACY
#define STEREO_LEFT_NAME
@ SCE_VIEWS_FORMAT_STEREO_3D
@ SCE_VIEWS_FORMAT_MULTIVIEW
@ R_BORDER
#define STEREO_RIGHT_NAME
@ STEREO_MONO_ID
@ STEREO_LEFT_ID
@ STEREO_RIGHT_ID
@ STEREO_3D_ID
@ R_MULTIVIEW
@ R_ADDSKY
@ SCE_PASS_COMBINED
@ RGN_TYPE_WINDOW
@ SPACE_VIEW3D
#define UI_SCALE_FAC
#define NDOF_IS_ORBIT_AROUND_CENTER_MODE(userdef)
@ USER_SHOW_VIEWPORTNAME
@ USER_DRAWVIEWINFO
@ USER_SHOW_FPS
@ NDOF_SHOW_GUIDE_ORBIT_AXIS
@ NDOF_ORBIT_CENTER_AUTO
@ NDOF_SHOW_GUIDE_ORBIT_CENTER
eUserpref_MiniAxisType
@ USER_MINI_AXIS_TYPE_GIZMO
@ USER_MINI_AXIS_TYPE_MINIMAL
@ USER_MINI_AXIS_TYPE_NONE
eV3DOffscreenDrawFlag
@ V3D_OFSDRAW_NONE
@ V3D_OFSDRAW_SHOW_OBJECT_EXTRAS
@ V3D_OFSDRAW_OVERRIDE_SCENE_SETTINGS
@ V3D_OFSDRAW_XR_SHOW_CUSTOM_OVERLAYS
@ V3D_OFSDRAW_SHOW_GRIDFLOOR
@ V3D_OFSDRAW_XR_SHOW_PASSTHROUGH
@ V3D_OFSDRAW_SHOW_ANNOTATION
@ V3D_OFSDRAW_SHOW_SELECTION
@ V3D_OFSDRAW_XR_SHOW_CONTROLLERS
@ V3D_SHADING_BACKGROUND_WORLD
@ V3D_SHADING_TEXTURE_COLOR
@ V3D_SHADING_VERTEX_COLOR
@ V3D_LIGHTING_STUDIO
#define RV3D_VIEW_IS_AXIS(view)
@ RV3D_CAMOB
@ RV3D_PERSP
@ RV3D_ORTHO
@ RV3D_VIEW_AXIS_ROLL_180
@ RV3D_VIEW_AXIS_ROLL_90
@ RV3D_VIEW_AXIS_ROLL_0
#define RV3D_LOCK_FLAGS(rv3d)
@ V3D_XR_SESSION_SURFACE
@ V3D_SELECT_OUTLINE
@ V3D_HIDE_HELPLINES
@ V3D_OVERLAY_HIDE_OBJECT_ORIGINS
@ V3D_OVERLAY_HIDE_BONES
@ V3D_OVERLAY_HIDE_MOTION_PATHS
@ V3D_OVERLAY_HIDE_OBJECT_XTRAS
@ V3D_OVERLAY_HIDE_CURSOR
@ V3D_OVERLAY_HIDE_TEXT
@ V3D_OVERLAY_STATS
@ V3D_SHOW_VIEWER
@ V3D_SHOW_CAMERA_PASSEPARTOUT
@ V3D_XR_SHOW_CUSTOM_OVERLAYS
@ V3D_HIDE_OVERLAYS
@ V3D_SHOW_ANNOTATION
@ V3D_RENDER_BORDER
@ V3D_LOCK_CAMERA
@ V3D_SHOW_CAMERA_GUIDES
@ V3D_XR_SHOW_PASSTHROUGH
@ V3D_XR_SHOW_CONTROLLERS
@ RV3D_LOCK_ROTATION
@ RV3D_VIEW_FRONT
@ RV3D_VIEW_BOTTOM
@ RV3D_VIEW_LEFT
@ RV3D_VIEW_RIGHT
@ RV3D_VIEW_TOP
@ RV3D_VIEW_BACK
@ RV3D_VIEW_USER
@ V3D_GIZMO_HIDE
@ V3D_GIZMO_HIDE_NAVIGATE
@ RV3D_NDOF_OFS_IS_VALID
@ RV3D_ZOFFSET_DISABLED
@ RV3D_CLIPPING
@ V3D_OVERLAY_EDIT_WEIGHT
@ V3D_SHADING_SCENE_WORLD_RENDER
@ V3D_SHADING_SCENE_WORLD
@ V3D_SHADING_SCENE_LIGHTS
@ V3D_SHADING_SCENE_LIGHTS_RENDER
@ V3D_SHOW_FLOOR
@ V3D_SHOW_Z
@ V3D_SHOW_X
@ V3D_SHOW_Y
@ V3D_RUNTIME_DEPTHBUF_OVERRIDDEN
void DRW_draw_region_engine_info(int xoffset, int *yoffset, int line_height)
bool DRW_draw_in_progress()
void DRW_draw_view(const bContext *C)
void DRW_gpu_context_disable()
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)
void DRW_cache_free_old_batches(Main *bmain)
void DRW_draw_render_loop_offscreen(Depsgraph *depsgraph, RenderEngineType *engine_type, ARegion *region, View3D *v3d, bool is_image_render, bool draw_background, bool do_color_management, GPUOffScreen *ofs, GPUViewport *viewport)
void DRW_gpu_context_enable()
void DRW_select_buffer_context_create(Depsgraph *depsgraph, blender::Span< Base * > bases, short select_mode)
void ED_info_draw_stats(Main *bmain, Scene *scene, ViewLayer *view_layer, View3D *v3d_local, int x, int *y, int height)
bool ED_scene_fps_average_calc(const Scene *scene, SceneFPS_State *r_state) ATTR_NONNULL(1
const rcti * ED_region_visible_rect(ARegion *region)
Definition area.cc:4114
bScreen * ED_screen_animation_no_scrub(const wmWindowManager *wm)
void ED_region_pixelspace(const ARegion *region)
Definition area.cc:123
#define XRAY_ENABLED(v3d)
eV3DDepthOverrideMode
Definition ED_view3d.hh:188
@ V3D_DEPTH_ALL
Definition ED_view3d.hh:190
@ V3D_DEPTH_SELECTED_ONLY
Definition ED_view3d.hh:198
@ V3D_DEPTH_NO_GPENCIL
Definition ED_view3d.hh:192
@ V3D_DEPTH_GPENCIL_ONLY
Definition ED_view3d.hh:194
@ V3D_DEPTH_OBJECT_ONLY
Definition ED_view3d.hh:196
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)
void ED_view3d_text_colors_get(const Scene *scene, const View3D *v3d, float r_text_color[4], float r_shadow_color[4])
#define GPU_ATTACHMENT_TEXTURE(_texture)
GPUFrameBuffer * GPU_framebuffer_active_get()
int GPU_offscreen_width(const GPUOffScreen *offscreen)
void GPU_offscreen_bind(GPUOffScreen *offscreen, bool save)
void GPU_framebuffer_restore()
void GPU_framebuffer_read_depth(GPUFrameBuffer *fb, int x, int y, int width, int height, eGPUDataFormat data_format, void *r_data)
#define GPU_ATTACHMENT_NONE
int GPU_offscreen_height(const GPUOffScreen *offscreen)
GPUOffScreen * GPU_offscreen_create(int width, int height, bool with_depth_buffer, eGPUTextureFormat format, eGPUTextureUsage usage, bool clear, char err_out[256])
void GPU_framebuffer_free(GPUFrameBuffer *fb)
void GPU_framebuffer_bind(GPUFrameBuffer *fb)
void GPU_offscreen_free(GPUOffScreen *offscreen)
eGPUTextureFormat GPU_offscreen_format(const GPUOffScreen *offscreen)
#define GPU_framebuffer_ensure_config(_fb,...)
void GPU_offscreen_read_color(GPUOffScreen *offscreen, eGPUDataFormat data_format, void *r_data)
void GPU_offscreen_unbind(GPUOffScreen *offscreen, bool restore)
void immUniform4f(const char *name, float x, float y, float z, float w)
void immUniformThemeColorAlpha(int color_id, float a)
void immEnd()
void immUnbindProgram()
void immAttr4fv(uint attr_id, const float data[4])
void immUniform2f(const char *name, float x, float y)
void immUniformThemeColorShadeAlpha(int color_id, int color_offset, int alpha_offset)
void immAttr4ubv(uint attr_id, const unsigned char data[4])
void immVertex2f(uint attr_id, float x, float y)
void immUniformThemeColor(int color_id)
void immBindBuiltinProgram(eGPUBuiltinShader shader_id)
void immVertex2fv(uint attr_id, const float data[2])
void immUniformColor3ubv(const unsigned char rgb[3])
void immUniform1i(const char *name, int x)
void immUniformThemeColor3(int color_id)
void immUniform1f(const char *name, float x)
GPUVertFormat * immVertexFormat()
void immUniformColor3f(float r, float g, float b)
void immUniform4fv(const char *name, const float data[4])
void immVertex3fv(uint attr_id, const float data[3])
void immBegin(GPUPrimType, uint vertex_len)
void imm_draw_box_wire_2d(uint pos, float x1, float y1, float x2, float y2)
void immRectf(uint pos, float x1, float y1, float x2, float y2)
void GPU_matrix_identity_set()
#define GPU_matrix_set(x)
void GPU_matrix_push()
void GPU_matrix_push_projection()
void GPU_matrix_pop_projection()
#define GPU_matrix_projection_set(x)
void GPU_matrix_pop()
@ GPU_PRIM_LINE_LOOP
@ GPU_PRIM_LINES
@ GPU_PRIM_POINTS
@ GPU_PRIM_LINE_STRIP
@ GPU_SHADER_3D_SMOOTH_COLOR
@ GPU_SHADER_3D_LINE_DASHED_UNIFORM_COLOR
@ GPU_SHADER_3D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA
@ GPU_SHADER_3D_UNIFORM_COLOR
@ GPU_SHADER_3D_FLAT_COLOR
void GPU_memory_barrier(eGPUBarrier barrier)
Definition gpu_state.cc:385
@ GPU_BLEND_NONE
Definition GPU_state.hh:85
@ GPU_BLEND_ALPHA
Definition GPU_state.hh:87
void GPU_blend(eGPUBlend blend)
Definition gpu_state.cc:42
void GPU_line_width(float width)
Definition gpu_state.cc:166
void GPU_line_smooth(bool enable)
Definition gpu_state.cc:78
void GPU_depth_mask(bool depth)
Definition gpu_state.cc:110
@ GPU_BARRIER_TEXTURE_UPDATE
Definition GPU_state.hh:39
@ GPU_DEPTH_NONE
Definition GPU_state.hh:111
void GPU_depth_test(eGPUDepthTest test)
Definition gpu_state.cc:68
void GPU_viewport_size_get_f(float coords[4])
Definition gpu_state.cc:273
int GPU_texture_height(const GPUTexture *texture)
GPUTexture * GPU_texture_create_2d(const char *name, int width, int height, int mip_len, eGPUTextureFormat format, eGPUTextureUsage usage, const float *data)
void GPU_texture_free(GPUTexture *texture)
int GPU_texture_width(const GPUTexture *texture)
void GPU_texture_copy(GPUTexture *dst, GPUTexture *src)
void * GPU_texture_read(GPUTexture *texture, eGPUDataFormat data_format, int mip_level)
@ GPU_DATA_HALF_FLOAT
@ GPU_DATA_UINT_24_8
@ GPU_DATA_UBYTE
@ GPU_DATA_FLOAT
@ GPU_TEXTURE_USAGE_SHADER_READ
@ GPU_TEXTURE_USAGE_HOST_READ
eGPUTextureFormat
@ GPU_RGBA16F
@ GPU_RGBA8
@ GPU_FETCH_FLOAT
@ GPU_FETCH_INT_TO_FLOAT_UNIT
uint GPU_vertformat_attr_add(GPUVertFormat *, blender::StringRef name, GPUVertCompType, uint comp_len, GPUVertFetchMode)
@ GPU_COMP_F32
@ GPU_COMP_U8
GPUTexture * GPU_viewport_color_texture(GPUViewport *viewport, int view)
GPUTexture * GPU_viewport_depth_texture(GPUViewport *viewport)
void GPU_viewport_tag_update(GPUViewport *viewport)
static double angle(const Eigen::Vector3d &v1, const Eigen::Vector3d &v2)
Definition IK_Math.h:117
void IMB_byte_from_float(ImBuf *ibuf)
ImBuf * IMB_allocImBuf(unsigned int x, unsigned int y, unsigned char planes, unsigned int flags)
eImBufFlags
@ IB_float_data
Read Guarded memory(de)allocation.
@ RE_INTERNAL
Definition RE_engine.h:43
@ RE_USE_EEVEE_VIEWPORT
Definition RE_engine.h:46
#define C
Definition RandGen.cpp:29
#define UI_UNIT_Y
void UI_draw_safe_areas(uint pos, const rctf *rect, const float title_aspect[2], const float action_aspect[2])
void UI_fontstyle_set(const uiFontStyle *fs)
#define UI_FSTYLE_WIDGET
#define UI_DEFAULT_TEXT_POINTS
#define UI_UNIT_X
void UI_Theme_Store(bThemeState *theme_state)
void UI_Theme_Restore(const bThemeState *theme_state)
@ TH_TIME_KEYFRAME
@ TH_BACK
@ TH_TIME_GP_KEYFRAME
@ TH_REDALERT
@ TH_CAMERA_PASSEPARTOUT
@ TH_AXIS_X
@ TH_VIEW_OVERLAY
@ TH_TEXT_HI
void UI_GetThemeColorShade3fv(int colorid, int offset, float col[3])
void UI_GetThemeColor4fv(int colorid, float col[4])
void UI_FontThemeColor(int fontid, int colorid)
void UI_SetTheme(int spacetype, int regionid)
#define U
BMesh const char void * data
ATTR_WARN_UNUSED_RESULT const BMVert * v2
BPy_StructRNA * depsgraph
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition btQuadWord.h:119
bool init(ARegion *region)
bool sample(const int mval[2], float r_col[3])
static float is_left(const float p0[2], const float p1[2], const float p2[2])
#define sinf(x)
#define cosf(x)
#define powf(x, y)
#define ceilf(x)
#define hypotf(x, y)
#define floorf(x)
#define acosf(x)
#define fabsf(x)
#define sqrtf(x)
uchar view3d_camera_border_hack_col[3]
Definition drawobject.cc:12
bool view3d_camera_border_hack_test
Definition drawobject.cc:13
uint pos
uint col
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
#define CD_MASK_PROP_BYTE_COLOR
#define CD_MASK_PROP_COLOR
#define CD_MASK_ORCO
#define CD_MASK_MDEFORMVERT
#define CD_MASK_PROP_FLOAT2
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
RenderEngineType * RE_engines_find(const char *idname)
format
void * MEM_mallocN(size_t len, const char *str)
Definition mallocn.cc:128
void * MEM_callocN(size_t len, const char *str)
Definition mallocn.cc:118
void * MEM_malloc_arrayN(size_t len, size_t size, const char *str)
Definition mallocn.cc:133
void MEM_freeN(void *vmemh)
Definition mallocn.cc:113
static ulong state[N]
#define G(x, y, z)
bool id_frame_has_keyframe(ID *id, float frame)
MatBase< T, NumCol, NumRow > scale(const MatBase< T, NumCol, NumRow > &mat, const VectorT &scale)
float half_to_float(uint16_t v)
Definition math_half.cc:91
VecBase< float, 4 > float4
blender::VecBase< uint16_t, 4 > ushort4
const char * RE_engine_id_BLENDER_EEVEE_NEXT
Definition scene.cc:1626
const char * RE_engine_id_BLENDER_WORKBENCH
Definition scene.cc:1627
#define FLT_MAX
Definition stdcycles.h:14
void * regiondata
ARegionRuntimeHandle * runtime
char name[64]
char sensor_fit
float sensor_y
float passepartalpha
float sensor_x
char name[64]
Definition DNA_ID.h:404
char name[66]
Definition DNA_ID.h:415
ImBufFloatBuffer float_buffer
ImBufByteBuffer byte_buffer
char name[64]
ListBase block
struct Collection * collection
void * last
void * first
short base_flag
float viewinv[4][4]
float persinv[4][4]
float viewmat[4][4]
float persmat[4][4]
float viewcamtexcofac[4]
float winmat[4][4]
float viewcamtexcofac[4]
float ndof_rot_axis[3]
float persmat[4][4]
float clip[6][4]
float persinv[4][4]
float viewmat[4][4]
float clip_local[6][4]
float viewinv[4][4]
float winmat[4][4]
char engine[32]
void(* view_draw)(struct RenderEngine *engine, const struct bContext *context, struct Depsgraph *depsgraph)
Definition RE_engine.h:104
void(* view_update)(struct RenderEngine *engine, const struct bContext *context, struct Depsgraph *depsgraph)
Definition RE_engine.h:101
View3DShading shading
struct SceneDisplay display
struct RenderData r
struct UnitSettings unit
struct DisplaySafeAreas safe_areas
struct SceneEEVEE eevee
float gpencil_vertex_paint_opacity
char multiview_eye
View3DOverlay overlay
rctf render_border
View3D_Runtime runtime
struct Object * camera
short gridsubdiv
char stereo3d_camera
struct View3D * localvd
ViewerPath viewer_path
short gridlines
int object_type_exclude_select
short ob_center_cursor
struct Object * ob_center
int object_type_exclude_viewport
ListBase regionbase
View3DShading shading
float clip_start
ARegion * region
Definition ED_view3d.hh:77
Scene * scene
Definition ED_view3d.hh:73
ViewLayer * view_layer
Definition ED_view3d.hh:74
View3D * v3d
Definition ED_view3d.hh:78
Object * obact
Definition ED_view3d.hh:75
Depsgraph * depsgraph
Definition ED_view3d.hh:72
unsigned short w
Definition ED_view3d.hh:86
float * depths
Definition ED_view3d.hh:89
double depth_range[2]
Definition ED_view3d.hh:90
unsigned short h
Definition ED_view3d.hh:86
ViewerPath viewer_path
struct EditBone * act_edbone
ListBase * edbo
ListBase areabase
float xmax
float xmin
float ymax
float ymin
int ymin
int ymax
int xmin
int xmax
XrSessionSettings session_settings
i
Definition text_draw.cc:230
static void draw_background(const rcti *rect)
uint len
static void draw_viewport_name(ARegion *region, View3D *v3d, int xoffset, int *yoffset)
void ED_view3d_calc_camera_border_size(const Scene *scene, Depsgraph *depsgraph, const ARegion *region, const View3D *v3d, const RegionView3D *rv3d, float r_size[2])
static void draw_selected_name(const View3D *v3d, Scene *scene, ViewLayer *view_layer, Object *ob, int xoffset, int *yoffset)
void ED_view3d_datamask(const Scene *scene, ViewLayer *view_layer, const View3D *v3d, CustomData_MeshMasks *r_cddata_masks)
RV3DMatrixStore * ED_view3d_mats_rv3d_backup(RegionView3D *rv3d)
float ED_view3d_grid_scale(const Scene *scene, const View3D *v3d, const char **r_grid_unit)
static void view3d_draw_border(const bContext *C, ARegion *region)
static void drawviewborder(Scene *scene, Depsgraph *depsgraph, ARegion *region, View3D *v3d)
float ED_view3d_grid_view_scale(const Scene *scene, const View3D *v3d, const ARegion *region, const char **r_grid_unit)
void ED_view3d_depth_override(Depsgraph *depsgraph, ARegion *region, View3D *v3d, Object *, eV3DDepthOverrideMode mode, bool use_overlay, ViewDepths **r_depths)
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)
ImBuf * ED_view3d_draw_offscreen_imbuf_simple(Depsgraph *depsgraph, Scene *scene, View3DShading *shading_override, eDrawType drawtype, Object *camera, int width, int height, eImBufFlags imbuf_flag, eV3DOffscreenDrawFlag draw_flags, int alpha_mode, const char *viewname, GPUOffScreen *ofs, GPUViewport *viewport, char err_out[256])
static bool view3d_stereo3d_active(wmWindow *win, const Scene *scene, View3D *v3d, RegionView3D *rv3d)
static void view3d_update_viewer_path(const bContext *C)
void view3d_draw_region_info(const bContext *C, ARegion *region)
void ED_view3d_screen_datamask(const Scene *scene, ViewLayer *view_layer, const bScreen *screen, CustomData_MeshMasks *r_cddata_masks)
static void view3d_gpu_read_Z_pixels(GPUViewport *viewport, rcti *rect, void *data)
static void validate_object_select_id(Depsgraph *depsgraph, const Scene *scene, ViewLayer *view_layer, ARegion *region, View3D *v3d, Object *obact)
bool ED_view3d_draw_offscreen_check_nested()
static void view3d_stereo3d_setup(Depsgraph *depsgraph, Scene *scene, View3D *v3d, ARegion *region, const rcti *rect)
void view3d_main_region_draw(const bContext *C, ARegion *region)
static void view3d_stereo3d_setup_offscreen(Depsgraph *depsgraph, const Scene *scene, View3D *v3d, ARegion *region, const float winmat[4][4], const char *viewname)
static void view3d_camera_border(const Scene *scene, const Depsgraph *depsgraph, const ARegion *region, const View3D *v3d, const RegionView3D *rv3d, rctf *r_viewborder, const bool no_shift, const bool no_zoom)
void view3d_depths_rect_create(ARegion *region, rcti *rect, ViewDepths *r_d)
static ViewDepths * view3d_depths_create(ARegion *region)
bool ED_view3d_has_depth_buffer_updated(const Depsgraph *depsgraph, const View3D *v3d)
void ED_view3d_select_id_validate(const ViewContext *vc)
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])
static void view3d_draw_grease_pencil(const bContext *)
float view3d_depth_near(ViewDepths *d)
#define VIEW3D_OVERLAY_LINEHEIGHT
void ED_view3d_grid_steps(const Scene *scene, const View3D *v3d, const RegionView3D *rv3d, float r_grid_steps[STEPS_LEN])
void ED_view3D_mats_rv3d_free(RV3DMatrixStore *rv3d_mat)
static bool view3d_clipping_test(const float co[3], const float clip[6][4])
void ED_view3d_calc_camera_border(const Scene *scene, const Depsgraph *depsgraph, const ARegion *region, const View3D *v3d, const RegionView3D *rv3d, const bool no_shift, rctf *r_viewborder)
static void view3d_draw_view(const bContext *C, ARegion *region)
void ED_view3d_mats_rv3d_restore(RegionView3D *rv3d, RV3DMatrixStore *rv3dmat_pt)
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)
static void draw_grid_unit_name(Scene *scene, ARegion *region, View3D *v3d, int xoffset, int *yoffset)
#define STEPS_LEN
int ED_view3d_backbuf_sample_size_clamp(ARegion *region, const float dist)
void ED_view3d_depths_free(ViewDepths *depths)
void ED_view3d_draw_offscreen(Depsgraph *depsgraph, const Scene *scene, eDrawType drawtype, View3D *v3d, ARegion *region, int winx, int winy, const float viewmat[4][4], const float winmat[4][4], bool is_image_render, bool draw_background, const char *viewname, const bool do_color_management, const bool restore_rv3d_mats, GPUOffScreen *ofs, GPUViewport *viewport)
static const char * view3d_get_name(View3D *v3d, RegionView3D *rv3d)
static bool view3d_main_region_do_render_draw(const Scene *scene)
bool ED_view3d_clipping_test(const RegionView3D *rv3d, const float co[3], const bool is_local)
static void draw_view_axis(RegionView3D *rv3d, const rcti *rect)
ImBuf * ED_view3d_draw_offscreen_imbuf(Depsgraph *depsgraph, Scene *scene, eDrawType drawtype, View3D *v3d, ARegion *region, int sizex, int sizey, eImBufFlags imbuf_flag, int alpha_mode, const char *viewname, const bool restore_rv3d_mats, GPUOffScreen *ofs, GPUViewport *viewport, char err_out[256])
static void drawviewborder_grid3(uint shdr_pos, float x1, float x2, float y1, float y2, float fac)
static void drawviewborder_triangle(uint shdr_pos, float x1, float x2, float y1, float y2, const char golden, const char dir)
RenderEngineType * ED_view3d_engine_type(const Scene *scene, int drawtype)
bool ED_view3d_calc_render_border(const Scene *scene, Depsgraph *depsgraph, View3D *v3d, ARegion *region, rcti *r_rect)
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)
#define M_GOLDEN_RATIO_CONJUGATE
void ED_view3d_draw_offscreen_simple(Depsgraph *depsgraph, Scene *scene, View3DShading *shading_override, eDrawType drawtype, int object_type_exclude_viewport_override, int object_type_exclude_select_override, int winx, int winy, uint draw_flags, const float viewmat[4][4], const float winmat[4][4], float clip_start, float clip_end, bool is_xr_surface, bool is_image_render, bool draw_background, const char *viewname, const bool do_color_management, GPUOffScreen *ofs, GPUViewport *viewport)
void ED_scene_draw_fps(const Scene *scene, int xoffset, int *yoffset)
static void drawrenderborder(ARegion *region, View3D *v3d)
static bool is_grease_pencil_with_layer_keyframe(const Object &ob)
float ED_scene_grid_scale(const Scene *scene, const char **r_grid_unit)
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 view3d_viewmatrix_set(const Depsgraph *depsgraph, const Scene *scene, const View3D *v3d, RegionView3D *rv3d, const float rect_scale[2])
void view3d_winmatrix_set(const Depsgraph *depsgraph, ARegion *region, const View3D *v3d, const rcti *rect)
void WM_draw_region_viewport_unbind(ARegion *region)
Definition wm_draw.cc:1697
void WM_draw_region_viewport_ensure(Scene *scene, ARegion *region, short space_type)
Definition wm_draw.cc:1686
GPUViewport * WM_draw_region_get_viewport(ARegion *region)
Definition wm_draw.cc:912
void WM_draw_region_viewport_bind(ARegion *region)
Definition wm_draw.cc:1692
bool WM_stereo3d_enabled(wmWindow *win, bool skip_stereo3d_check)
Definition wm_stereo.cc:138
uint8_t flag
Definition wm_window.cc:139
bool WM_xr_session_state_viewer_pose_matrix_info_get(const wmXrData *xr, float r_viewmat[4][4], float *r_focal_len)