Merge branch 'blender2.7'
[blender.git] / source / blender / editors / space_view3d / view3d_draw.c
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2008 Blender Foundation.
17  * All rights reserved.
18  */
19
20 /** \file
21  * \ingroup spview3d
22  */
23
24 #include <math.h>
25
26 #include "BLI_listbase.h"
27 #include "BLI_math.h"
28 #include "BLI_rect.h"
29 #include "BLI_string.h"
30 #include "BLI_threads.h"
31 #include "BLI_jitter_2d.h"
32
33
34 #include "BKE_camera.h"
35 #include "BKE_collection.h"
36 #include "BKE_context.h"
37 #include "BKE_global.h"
38 #include "BKE_key.h"
39 #include "BKE_main.h"
40 #include "BKE_scene.h"
41 #include "BKE_object.h"
42 #include "BKE_paint.h"
43 #include "BKE_unit.h"
44
45 #include "BLF_api.h"
46
47 #include "BLT_translation.h"
48
49 #include "DNA_armature_types.h"
50 #include "DNA_brush_types.h"
51 #include "DNA_camera_types.h"
52 #include "DNA_key_types.h"
53 #include "DNA_mesh_types.h"
54 #include "DNA_object_types.h"
55 #include "DNA_view3d_types.h"
56 #include "DNA_windowmanager_types.h"
57
58 #include "DRW_engine.h"
59
60 #include "ED_armature.h"
61 #include "ED_keyframing.h"
62 #include "ED_gpencil.h"
63 #include "ED_screen.h"
64 #include "ED_transform.h"
65
66 #include "DEG_depsgraph_query.h"
67
68 #include "GPU_batch.h"
69 #include "GPU_batch_presets.h"
70 #include "GPU_draw.h"
71 #include "GPU_matrix.h"
72 #include "GPU_immediate.h"
73 #include "GPU_immediate_util.h"
74 #include "GPU_material.h"
75 #include "GPU_viewport.h"
76 #include "GPU_state.h"
77 #include "GPU_framebuffer.h"
78
79 #include "MEM_guardedalloc.h"
80
81 #include "UI_interface.h"
82 #include "UI_resources.h"
83
84 #include "RE_engine.h"
85
86 #include "WM_api.h"
87 #include "WM_types.h"
88
89 #include "RNA_access.h"
90
91 #include "IMB_imbuf.h"
92 #include "IMB_imbuf_types.h"
93
94 #include "view3d_intern.h"  /* own include */
95
96 /* ******************** general functions ***************** */
97
98 /**
99  * \note keep this synced with #ED_view3d_mats_rv3d_backup/#ED_view3d_mats_rv3d_restore
100  */
101 void ED_view3d_update_viewmat(
102         Depsgraph *depsgraph, Scene *scene, View3D *v3d, ARegion *ar,
103         float viewmat[4][4], float winmat[4][4], const rcti *rect)
104 {
105         RegionView3D *rv3d = ar->regiondata;
106
107         /* setup window matrices */
108         if (winmat)
109                 copy_m4_m4(rv3d->winmat, winmat);
110         else
111                 view3d_winmatrix_set(depsgraph, ar, v3d, rect);
112
113         /* setup view matrix */
114         if (viewmat) {
115                 copy_m4_m4(rv3d->viewmat, viewmat);
116         }
117         else {
118                 float rect_scale[2];
119                 if (rect) {
120                         rect_scale[0] = (float)BLI_rcti_size_x(rect) / (float)ar->winx;
121                         rect_scale[1] = (float)BLI_rcti_size_y(rect) / (float)ar->winy;
122                 }
123                 /* note: calls BKE_object_where_is_calc for camera... */
124                 view3d_viewmatrix_set(depsgraph, scene, v3d, rv3d, rect ? rect_scale : NULL);
125         }
126         /* update utility matrices */
127         mul_m4_m4m4(rv3d->persmat, rv3d->winmat, rv3d->viewmat);
128         invert_m4_m4(rv3d->persinv, rv3d->persmat);
129         invert_m4_m4(rv3d->viewinv, rv3d->viewmat);
130
131         /* calculate GLSL view dependent values */
132
133         /* store window coordinates scaling/offset */
134         if (rv3d->persp == RV3D_CAMOB && v3d->camera) {
135                 rctf cameraborder;
136                 ED_view3d_calc_camera_border(scene, depsgraph, ar, v3d, rv3d, &cameraborder, false);
137                 rv3d->viewcamtexcofac[0] = (float)ar->winx / BLI_rctf_size_x(&cameraborder);
138                 rv3d->viewcamtexcofac[1] = (float)ar->winy / BLI_rctf_size_y(&cameraborder);
139
140                 rv3d->viewcamtexcofac[2] = -rv3d->viewcamtexcofac[0] * cameraborder.xmin / (float)ar->winx;
141                 rv3d->viewcamtexcofac[3] = -rv3d->viewcamtexcofac[1] * cameraborder.ymin / (float)ar->winy;
142         }
143         else {
144                 rv3d->viewcamtexcofac[0] = rv3d->viewcamtexcofac[1] = 1.0f;
145                 rv3d->viewcamtexcofac[2] = rv3d->viewcamtexcofac[3] = 0.0f;
146         }
147
148         /* calculate pixelsize factor once, is used for lights and obcenters */
149         {
150                 /* note:  '1.0f / len_v3(v1)'  replaced  'len_v3(rv3d->viewmat[0])'
151                  * because of float point precision problems at large values [#23908] */
152                 float v1[3], v2[3];
153                 float len_px, len_sc;
154
155                 v1[0] = rv3d->persmat[0][0];
156                 v1[1] = rv3d->persmat[1][0];
157                 v1[2] = rv3d->persmat[2][0];
158
159                 v2[0] = rv3d->persmat[0][1];
160                 v2[1] = rv3d->persmat[1][1];
161                 v2[2] = rv3d->persmat[2][1];
162
163                 len_px = 2.0f / sqrtf(min_ff(len_squared_v3(v1), len_squared_v3(v2)));
164                 len_sc = (float)MAX2(ar->winx, ar->winy);
165
166                 rv3d->pixsize = len_px / len_sc;
167         }
168 }
169
170 static void view3d_main_region_setup_view(
171         Depsgraph *depsgraph, Scene *scene,
172         View3D *v3d, ARegion *ar, float viewmat[4][4], float winmat[4][4], const rcti *rect)
173 {
174         RegionView3D *rv3d = ar->regiondata;
175
176         ED_view3d_update_viewmat(depsgraph, scene, v3d, ar, viewmat, winmat, rect);
177
178         /* set for opengl */
179         GPU_matrix_projection_set(rv3d->winmat);
180         GPU_matrix_set(rv3d->viewmat);
181 }
182
183 static bool view3d_stereo3d_active(wmWindow *win, Scene *scene, View3D *v3d, RegionView3D *rv3d)
184 {
185         if ((scene->r.scemode & R_MULTIVIEW) == 0) {
186                 return false;
187         }
188
189         if ((v3d->camera == NULL) || (v3d->camera->type != OB_CAMERA) || rv3d->persp != RV3D_CAMOB) {
190                 return false;
191         }
192
193         switch (v3d->stereo3d_camera) {
194                 case STEREO_MONO_ID:
195                         return false;
196                         break;
197                 case STEREO_3D_ID:
198                         /* win will be NULL when calling this from the selection or draw loop. */
199                         if ((win == NULL) || (WM_stereo3d_enabled(win, true) == false)) {
200                                 return false;
201                         }
202                         if (((scene->r.views_format & SCE_VIEWS_FORMAT_MULTIVIEW) != 0) &&
203                             !BKE_scene_multiview_is_stereo3d(&scene->r))
204                         {
205                                 return false;
206                         }
207                         break;
208                 /* We always need the stereo calculation for left and right cameras. */
209                 case STEREO_LEFT_ID:
210                 case STEREO_RIGHT_ID:
211                 default:
212                         break;
213         }
214         return true;
215 }
216
217
218 /* setup the view and win matrices for the multiview cameras
219  *
220  * unlike view3d_stereo3d_setup_offscreen, when view3d_stereo3d_setup is called
221  * we have no winmatrix (i.e., projection matrix) defined at that time.
222  * Since the camera and the camera shift are needed for the winmat calculation
223  * we do a small hack to replace it temporarily so we don't need to change the
224  * view3d)main_region_setup_view() code to account for that.
225  */
226 static void view3d_stereo3d_setup(
227         Depsgraph *depsgraph, Scene *scene, View3D *v3d, ARegion *ar, const rcti *rect)
228 {
229         bool is_left;
230         const char *names[2] = { STEREO_LEFT_NAME, STEREO_RIGHT_NAME };
231         const char *viewname;
232
233         /* show only left or right camera */
234         if (v3d->stereo3d_camera != STEREO_3D_ID)
235                 v3d->multiview_eye = v3d->stereo3d_camera;
236
237         is_left = v3d->multiview_eye == STEREO_LEFT_ID;
238         viewname = names[is_left ? STEREO_LEFT_ID : STEREO_RIGHT_ID];
239
240         /* update the viewport matrices with the new camera */
241         if (scene->r.views_format == SCE_VIEWS_FORMAT_STEREO_3D) {
242                 Camera *data, *data_eval;
243                 float viewmat[4][4];
244                 float shiftx;
245
246                 data = (Camera *)v3d->camera->data;
247                 data_eval = (Camera *)DEG_get_evaluated_id(depsgraph, &data->id);
248
249                 shiftx = data_eval->shiftx;
250
251                 BLI_thread_lock(LOCK_VIEW3D);
252                 data_eval->shiftx = BKE_camera_multiview_shift_x(&scene->r, v3d->camera, viewname);
253
254                 BKE_camera_multiview_view_matrix(&scene->r, v3d->camera, is_left, viewmat);
255                 view3d_main_region_setup_view(depsgraph, scene, v3d, ar, viewmat, NULL, rect);
256
257                 data_eval->shiftx = shiftx;
258                 BLI_thread_unlock(LOCK_VIEW3D);
259         }
260         else { /* SCE_VIEWS_FORMAT_MULTIVIEW */
261                 float viewmat[4][4];
262                 Object *view_ob = v3d->camera;
263                 Object *camera = BKE_camera_multiview_render(scene, v3d->camera, viewname);
264
265                 BLI_thread_lock(LOCK_VIEW3D);
266                 v3d->camera = camera;
267
268                 BKE_camera_multiview_view_matrix(&scene->r, camera, false, viewmat);
269                 view3d_main_region_setup_view(depsgraph, scene, v3d, ar, viewmat, NULL, rect);
270
271                 v3d->camera = view_ob;
272                 BLI_thread_unlock(LOCK_VIEW3D);
273         }
274 }
275
276 /**
277  * Set the correct matrices
278  */
279 void ED_view3d_draw_setup_view(
280         wmWindow *win, Depsgraph *depsgraph, Scene *scene, ARegion *ar, View3D *v3d,
281         float viewmat[4][4], float winmat[4][4], const rcti *rect)
282 {
283         RegionView3D *rv3d = ar->regiondata;
284
285         /* Setup the view matrix. */
286         if (view3d_stereo3d_active(win, scene, v3d, rv3d)) {
287                 view3d_stereo3d_setup(depsgraph, scene, v3d, ar, rect);
288         }
289         else {
290                 view3d_main_region_setup_view(depsgraph, scene, v3d, ar, viewmat, winmat, rect);
291         }
292 }
293
294 /* ******************** view border ***************** */
295
296 static void view3d_camera_border(
297         const Scene *scene, struct Depsgraph *depsgraph,
298         const ARegion *ar, const View3D *v3d, const RegionView3D *rv3d,
299         rctf *r_viewborder, const bool no_shift, const bool no_zoom)
300 {
301         CameraParams params;
302         rctf rect_view, rect_camera;
303         Object *camera_eval = DEG_get_evaluated_object(depsgraph, v3d->camera);
304
305         /* get viewport viewplane */
306         BKE_camera_params_init(&params);
307         BKE_camera_params_from_view3d(&params, depsgraph, v3d, rv3d);
308         if (no_zoom)
309                 params.zoom = 1.0f;
310         BKE_camera_params_compute_viewplane(&params, ar->winx, ar->winy, 1.0f, 1.0f);
311         rect_view = params.viewplane;
312
313         /* get camera viewplane */
314         BKE_camera_params_init(&params);
315         /* fallback for non camera objects */
316         params.clip_start = v3d->clip_start;
317         params.clip_end = v3d->clip_end;
318         BKE_camera_params_from_object(&params, camera_eval);
319         if (no_shift) {
320                 params.shiftx = 0.0f;
321                 params.shifty = 0.0f;
322         }
323         BKE_camera_params_compute_viewplane(&params, scene->r.xsch, scene->r.ysch, scene->r.xasp, scene->r.yasp);
324         rect_camera = params.viewplane;
325
326         /* get camera border within viewport */
327         r_viewborder->xmin = ((rect_camera.xmin - rect_view.xmin) / BLI_rctf_size_x(&rect_view)) * ar->winx;
328         r_viewborder->xmax = ((rect_camera.xmax - rect_view.xmin) / BLI_rctf_size_x(&rect_view)) * ar->winx;
329         r_viewborder->ymin = ((rect_camera.ymin - rect_view.ymin) / BLI_rctf_size_y(&rect_view)) * ar->winy;
330         r_viewborder->ymax = ((rect_camera.ymax - rect_view.ymin) / BLI_rctf_size_y(&rect_view)) * ar->winy;
331 }
332
333 void ED_view3d_calc_camera_border_size(
334         const Scene *scene, Depsgraph *depsgraph,
335         const ARegion *ar, const View3D *v3d, const RegionView3D *rv3d,
336         float r_size[2])
337 {
338         rctf viewborder;
339
340         view3d_camera_border(scene, depsgraph, ar, v3d, rv3d, &viewborder, true, true);
341         r_size[0] = BLI_rctf_size_x(&viewborder);
342         r_size[1] = BLI_rctf_size_y(&viewborder);
343 }
344
345 void ED_view3d_calc_camera_border(
346         const Scene *scene, Depsgraph *depsgraph,
347         const ARegion *ar, const View3D *v3d, const RegionView3D *rv3d,
348         rctf *r_viewborder, const bool no_shift)
349 {
350         view3d_camera_border(scene, depsgraph, ar, v3d, rv3d, r_viewborder, no_shift, false);
351 }
352
353 static void drawviewborder_grid3(uint shdr_pos, float x1, float x2, float y1, float y2, float fac)
354 {
355         float x3, y3, x4, y4;
356
357         x3 = x1 + fac * (x2 - x1);
358         y3 = y1 + fac * (y2 - y1);
359         x4 = x1 + (1.0f - fac) * (x2 - x1);
360         y4 = y1 + (1.0f - fac) * (y2 - y1);
361
362         immBegin(GPU_PRIM_LINES, 8);
363
364         immVertex2f(shdr_pos, x1, y3);
365         immVertex2f(shdr_pos, x2, y3);
366
367         immVertex2f(shdr_pos, x1, y4);
368         immVertex2f(shdr_pos, x2, y4);
369
370         immVertex2f(shdr_pos, x3, y1);
371         immVertex2f(shdr_pos, x3, y2);
372
373         immVertex2f(shdr_pos, x4, y1);
374         immVertex2f(shdr_pos, x4, y2);
375
376         immEnd();
377 }
378
379 /* harmonious triangle */
380 static void drawviewborder_triangle(
381         uint shdr_pos, float x1, float x2, float y1, float y2, const char golden, const char dir)
382 {
383         float ofs;
384         float w = x2 - x1;
385         float h = y2 - y1;
386
387         immBegin(GPU_PRIM_LINES, 6);
388
389         if (w > h) {
390                 if (golden) {
391                         ofs = w * (1.0f - (1.0f / 1.61803399f));
392                 }
393                 else {
394                         ofs = h * (h / w);
395                 }
396                 if (dir == 'B') SWAP(float, y1, y2);
397
398                 immVertex2f(shdr_pos, x1, y1);
399                 immVertex2f(shdr_pos, x2, y2);
400
401                 immVertex2f(shdr_pos, x2, y1);
402                 immVertex2f(shdr_pos, x1 + (w - ofs), y2);
403
404                 immVertex2f(shdr_pos, x1, y2);
405                 immVertex2f(shdr_pos, x1 + ofs, y1);
406         }
407         else {
408                 if (golden) {
409                         ofs = h * (1.0f - (1.0f / 1.61803399f));
410                 }
411                 else {
412                         ofs = w * (w / h);
413                 }
414                 if (dir == 'B') SWAP(float, x1, x2);
415
416                 immVertex2f(shdr_pos, x1, y1);
417                 immVertex2f(shdr_pos, x2, y2);
418
419                 immVertex2f(shdr_pos, x2, y1);
420                 immVertex2f(shdr_pos, x1, y1 + ofs);
421
422                 immVertex2f(shdr_pos, x1, y2);
423                 immVertex2f(shdr_pos, x2, y1 + (h - ofs));
424         }
425
426         immEnd();
427 }
428
429 static void drawviewborder(Scene *scene, Depsgraph *depsgraph, ARegion *ar, View3D *v3d)
430 {
431         float x1, x2, y1, y2;
432         float x1i, x2i, y1i, y2i;
433
434         rctf viewborder;
435         Camera *ca = NULL;
436         RegionView3D *rv3d = ar->regiondata;
437
438         if (v3d->camera == NULL)
439                 return;
440         if (v3d->camera->type == OB_CAMERA)
441                 ca = v3d->camera->data;
442
443         ED_view3d_calc_camera_border(scene, depsgraph, ar, v3d, rv3d, &viewborder, false);
444         /* the offsets */
445         x1 = viewborder.xmin;
446         y1 = viewborder.ymin;
447         x2 = viewborder.xmax;
448         y2 = viewborder.ymax;
449
450         GPU_line_width(1.0f);
451
452         /* apply offsets so the real 3D camera shows through */
453
454         /* note: quite un-scientific but without this bit extra
455          * 0.0001 on the lower left the 2D border sometimes
456          * obscures the 3D camera border */
457         /* note: with VIEW3D_CAMERA_BORDER_HACK defined this error isn't noticeable
458          * but keep it here in case we need to remove the workaround */
459         x1i = (int)(x1 - 1.0001f);
460         y1i = (int)(y1 - 1.0001f);
461         x2i = (int)(x2 + (1.0f - 0.0001f));
462         y2i = (int)(y2 + (1.0f - 0.0001f));
463
464         uint shdr_pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
465
466         /* First, solid lines. */
467         {
468                 immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
469
470                 /* passepartout, specified in camera edit buttons */
471                 if (ca && (ca->flag & CAM_SHOWPASSEPARTOUT) && ca->passepartalpha > 0.000001f) {
472                         const float winx = (ar->winx + 1);
473                         const float winy = (ar->winy + 1);
474
475                         float alpha = 1.0f;
476
477                         if (ca->passepartalpha != 1.0f) {
478                                 GPU_blend_set_func_separate(GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA, GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA);
479                                 GPU_blend(true);
480                                 alpha = ca->passepartalpha;
481                         }
482
483                         immUniformColor4f(0.0f, 0.0f, 0.0f, alpha);
484
485                         if (x1i > 0.0f)
486                                 immRectf(shdr_pos, 0.0f, winy, x1i, 0.0f);
487                         if (x2i < winx)
488                                 immRectf(shdr_pos, x2i, winy, winx, 0.0f);
489                         if (y2i < winy)
490                                 immRectf(shdr_pos, x1i, winy, x2i, y2i);
491                         if (y2i > 0.0f)
492                                 immRectf(shdr_pos, x1i, y1i, x2i, 0.0f);
493
494                         GPU_blend(false);
495                 }
496
497                 immUniformThemeColor(TH_BACK);
498                 imm_draw_box_wire_2d(shdr_pos, x1i, y1i, x2i, y2i);
499
500 #ifdef VIEW3D_CAMERA_BORDER_HACK
501                 if (view3d_camera_border_hack_test == true) {
502                         immUniformColor3ubv(view3d_camera_border_hack_col);
503                         imm_draw_box_wire_2d(shdr_pos, x1i + 1, y1i + 1, x2i - 1, y2i - 1);
504                         view3d_camera_border_hack_test = false;
505                 }
506 #endif
507
508                 immUnbindProgram();
509         }
510
511         /* When overlays are disabled, only show camera outline & passepartout. */
512         if (v3d->flag2 & V3D_RENDER_OVERRIDE) {
513                 return;
514         }
515
516         /* And now, the dashed lines! */
517         immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR);
518
519         {
520                 float viewport_size[4];
521                 GPU_viewport_size_get_f(viewport_size);
522                 immUniform2f("viewport_size", viewport_size[2], viewport_size[3]);
523
524                 immUniform1i("colors_len", 0);  /* "simple" mode */
525                 immUniform1f("dash_width", 6.0f);
526                 immUniform1f("dash_factor", 0.5f);
527
528                 /* outer line not to confuse with object selection */
529                 if (v3d->flag2 & V3D_LOCK_CAMERA) {
530                         immUniformThemeColor(TH_REDALERT);
531                         imm_draw_box_wire_2d(shdr_pos, x1i - 1, y1i - 1, x2i + 1, y2i + 1);
532                 }
533
534                 immUniformThemeColor(TH_VIEW_OVERLAY);
535                 imm_draw_box_wire_2d(shdr_pos, x1i, y1i, x2i, y2i);
536         }
537
538         /* Render Border. */
539         if (scene->r.mode & R_BORDER) {
540                 float x3, y3, x4, y4;
541
542                 x3 = floorf(x1 + (scene->r.border.xmin * (x2 - x1))) - 1;
543                 y3 = floorf(y1 + (scene->r.border.ymin * (y2 - y1))) - 1;
544                 x4 = floorf(x1 + (scene->r.border.xmax * (x2 - x1))) + (U.pixelsize - 1);
545                 y4 = floorf(y1 + (scene->r.border.ymax * (y2 - y1))) + (U.pixelsize - 1);
546
547                 immUniformColor3f(1.0f, 0.25f, 0.25f);
548                 imm_draw_box_wire_2d(shdr_pos, x3, y3, x4, y4);
549         }
550
551         /* safety border */
552         if (ca) {
553                 immUniformThemeColorBlend(TH_VIEW_OVERLAY, TH_BACK, 0.25f);
554
555                 if (ca->dtx & CAM_DTX_CENTER) {
556                         float x3, y3;
557
558                         x3 = x1 + 0.5f * (x2 - x1);
559                         y3 = y1 + 0.5f * (y2 - y1);
560
561                         immBegin(GPU_PRIM_LINES, 4);
562
563                         immVertex2f(shdr_pos, x1, y3);
564                         immVertex2f(shdr_pos, x2, y3);
565
566                         immVertex2f(shdr_pos, x3, y1);
567                         immVertex2f(shdr_pos, x3, y2);
568
569                         immEnd();
570                 }
571
572                 if (ca->dtx & CAM_DTX_CENTER_DIAG) {
573                         immBegin(GPU_PRIM_LINES, 4);
574
575                         immVertex2f(shdr_pos, x1, y1);
576                         immVertex2f(shdr_pos, x2, y2);
577
578                         immVertex2f(shdr_pos, x1, y2);
579                         immVertex2f(shdr_pos, x2, y1);
580
581                         immEnd();
582                 }
583
584                 if (ca->dtx & CAM_DTX_THIRDS) {
585                         drawviewborder_grid3(shdr_pos, x1, x2, y1, y2, 1.0f / 3.0f);
586                 }
587
588                 if (ca->dtx & CAM_DTX_GOLDEN) {
589                         drawviewborder_grid3(shdr_pos, x1, x2, y1, y2, 1.0f - (1.0f / 1.61803399f));
590                 }
591
592                 if (ca->dtx & CAM_DTX_GOLDEN_TRI_A) {
593                         drawviewborder_triangle(shdr_pos, x1, x2, y1, y2, 0, 'A');
594                 }
595
596                 if (ca->dtx & CAM_DTX_GOLDEN_TRI_B) {
597                         drawviewborder_triangle(shdr_pos, x1, x2, y1, y2, 0, 'B');
598                 }
599
600                 if (ca->dtx & CAM_DTX_HARMONY_TRI_A) {
601                         drawviewborder_triangle(shdr_pos, x1, x2, y1, y2, 1, 'A');
602                 }
603
604                 if (ca->dtx & CAM_DTX_HARMONY_TRI_B) {
605                         drawviewborder_triangle(shdr_pos, x1, x2, y1, y2, 1, 'B');
606                 }
607
608                 if (ca->flag & CAM_SHOW_SAFE_MARGINS) {
609                         UI_draw_safe_areas(
610                                 shdr_pos, x1, x2, y1, y2,
611                                 scene->safe_areas.title, scene->safe_areas.action);
612
613                         if (ca->flag & CAM_SHOW_SAFE_CENTER) {
614                                 UI_draw_safe_areas(
615                                         shdr_pos, x1, x2, y1, y2,
616                                         scene->safe_areas.title_center, scene->safe_areas.action_center);
617                         }
618                 }
619
620                 if (ca->flag & CAM_SHOWSENSOR) {
621                         /* determine sensor fit, and get sensor x/y, for auto fit we
622                          * assume and square sensor and only use sensor_x */
623                         float sizex = scene->r.xsch * scene->r.xasp;
624                         float sizey = scene->r.ysch * scene->r.yasp;
625                         int sensor_fit = BKE_camera_sensor_fit(ca->sensor_fit, sizex, sizey);
626                         float sensor_x = ca->sensor_x;
627                         float sensor_y = (ca->sensor_fit == CAMERA_SENSOR_FIT_AUTO) ? ca->sensor_x : ca->sensor_y;
628
629                         /* determine sensor plane */
630                         rctf rect;
631
632                         if (sensor_fit == CAMERA_SENSOR_FIT_HOR) {
633                                 float sensor_scale = (x2i - x1i) / sensor_x;
634                                 float sensor_height = sensor_scale * sensor_y;
635
636                                 rect.xmin = x1i;
637                                 rect.xmax = x2i;
638                                 rect.ymin = (y1i + y2i) * 0.5f - sensor_height * 0.5f;
639                                 rect.ymax = rect.ymin + sensor_height;
640                         }
641                         else {
642                                 float sensor_scale = (y2i - y1i) / sensor_y;
643                                 float sensor_width = sensor_scale * sensor_x;
644
645                                 rect.xmin = (x1i + x2i) * 0.5f - sensor_width * 0.5f;
646                                 rect.xmax = rect.xmin + sensor_width;
647                                 rect.ymin = y1i;
648                                 rect.ymax = y2i;
649                         }
650
651                         /* draw */
652                         immUniformThemeColorShade(TH_VIEW_OVERLAY, 100);
653
654                         /* TODO Was using UI_draw_roundbox_4fv(false, rect.xmin, rect.ymin, rect.xmax, rect.ymax, 2.0f, color).
655                          * We'll probably need a new imm_draw_line_roundbox_dashed dor that - though in practice the
656                          * 2.0f round corner effect was nearly not visible anyway... */
657                         imm_draw_box_wire_2d(shdr_pos, rect.xmin, rect.ymin, rect.xmax, rect.ymax);
658                 }
659         }
660
661         immUnbindProgram();
662         /* end dashed lines */
663
664         /* camera name - draw in highlighted text color */
665         if (ca && ((v3d->overlay.flag & V3D_OVERLAY_HIDE_TEXT) == 0) && (ca->flag & CAM_SHOWNAME)) {
666                 UI_FontThemeColor(BLF_default(), TH_TEXT_HI);
667                 BLF_draw_default(
668                         x1i, y1i - (0.7f * U.widget_unit), 0.0f,
669                         v3d->camera->id.name + 2, sizeof(v3d->camera->id.name) - 2);
670         }
671 }
672
673 static void drawrenderborder(ARegion *ar, View3D *v3d)
674 {
675         /* use the same program for everything */
676         uint shdr_pos = GPU_vertformat_attr_add(immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
677
678         GPU_line_width(1.0f);
679
680         immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR);
681
682         float viewport_size[4];
683         GPU_viewport_size_get_f(viewport_size);
684         immUniform2f("viewport_size", viewport_size[2], viewport_size[3]);
685
686         immUniform1i("colors_len", 0);  /* "simple" mode */
687         immUniform4f("color", 1.0f, 0.25f, 0.25f, 1.0f);
688         immUniform1f("dash_width", 6.0f);
689         immUniform1f("dash_factor", 0.5f);
690
691         imm_draw_box_wire_2d(shdr_pos,
692                           v3d->render_border.xmin * ar->winx, v3d->render_border.ymin * ar->winy,
693                           v3d->render_border.xmax * ar->winx, v3d->render_border.ymax * ar->winy);
694
695         immUnbindProgram();
696 }
697
698 void ED_view3d_draw_depth(
699         Depsgraph *depsgraph,
700         ARegion *ar, View3D *v3d, bool alphaoverride)
701 {
702         struct bThemeState theme_state;
703         Scene *scene = DEG_get_evaluated_scene(depsgraph);
704         RegionView3D *rv3d = ar->regiondata;
705
706         short flag = v3d->flag;
707         float glalphaclip = U.glalphaclip;
708         int obcenter_dia = U.obcenter_dia;
709         /* temp set drawtype to solid */
710         /* Setting these temporarily is not nice */
711         v3d->flag &= ~V3D_SELECT_OUTLINE;
712
713         /* not that nice but means we wont zoom into billboards */
714         U.glalphaclip = alphaoverride ? 0.5f : glalphaclip;
715
716         U.obcenter_dia = 0;
717
718         /* Tools may request depth outside of regular drawing code. */
719         UI_Theme_Store(&theme_state);
720         UI_SetTheme(SPACE_VIEW3D, RGN_TYPE_WINDOW);
721
722         ED_view3d_draw_setup_view(NULL, depsgraph, scene, ar, v3d, NULL, NULL, NULL);
723
724         GPU_clear(GPU_DEPTH_BIT);
725
726         if (rv3d->rflag & RV3D_CLIPPING) {
727                 ED_view3d_clipping_set(rv3d);
728         }
729         /* get surface depth without bias */
730         rv3d->rflag |= RV3D_ZOFFSET_DISABLED;
731
732         GPU_depth_test(true);
733
734         DRW_draw_depth_loop(depsgraph, ar, v3d);
735
736         if (rv3d->rflag & RV3D_CLIPPING) {
737                 ED_view3d_clipping_disable();
738         }
739         rv3d->rflag &= ~RV3D_ZOFFSET_DISABLED;
740
741         /* Reset default for UI */
742         GPU_depth_test(false);
743
744         U.glalphaclip = glalphaclip;
745         v3d->flag = flag;
746         U.obcenter_dia = obcenter_dia;
747
748         UI_Theme_Restore(&theme_state);
749 }
750
751 /* ******************** other elements ***************** */
752
753 /** could move this elsewhere, but tied into #ED_view3d_grid_scale */
754 float ED_scene_grid_scale(Scene *scene, const char **grid_unit)
755 {
756         /* apply units */
757         if (scene->unit.system) {
758                 const void *usys;
759                 int len;
760
761                 bUnit_GetSystem(scene->unit.system, B_UNIT_LENGTH, &usys, &len);
762
763                 if (usys) {
764                         int i = bUnit_GetBaseUnit(usys);
765                         if (grid_unit)
766                                 *grid_unit = bUnit_GetNameDisplay(usys, i);
767                         return (float)bUnit_GetScaler(usys, i) / scene->unit.scale_length;
768                 }
769         }
770
771         return 1.0f;
772 }
773
774 float ED_view3d_grid_scale(Scene *scene, View3D *v3d, const char **grid_unit)
775 {
776         return v3d->grid * ED_scene_grid_scale(scene, grid_unit);
777 }
778
779 /* Simulates the grid scale that is actually viewed.
780  * The actual code is seen in `object_grid_frag.glsl` (see `grid_res`).
781  * Currently the simulation is only done when RV3D_VIEW_IS_AXIS. */
782 float ED_view3d_grid_view_scale(
783         Scene *scene, View3D *v3d, RegionView3D *rv3d, const char **grid_unit)
784 {
785         float grid_scale = ED_view3d_grid_scale(scene, v3d, grid_unit);
786         if (!rv3d->is_persp && RV3D_VIEW_IS_AXIS(rv3d->view)) {
787                 /* Decrease the distance between grid snap points depending on zoom. */
788                 float grid_subdiv = v3d->gridsubdiv;
789                 if (grid_subdiv > 1) {
790                         /* Allow 3 more subdivisions (see OBJECT_engine_init). */
791                         grid_scale /= powf(grid_subdiv, 3);
792
793                         /* `3.0` was a value obtained by trial and error in order to get
794                          * a nice snap distance.*/
795                         float grid_res = 3.0 * (rv3d->dist / v3d->lens);
796                         float lvl = (logf(grid_res / grid_scale) / logf(grid_subdiv));
797
798                         CLAMP_MIN(lvl, 0.0f);
799
800                         grid_scale *= pow(grid_subdiv, (int)lvl);
801                 }
802         }
803
804         return grid_scale;
805 }
806
807 static void draw_view_axis(RegionView3D *rv3d, const rcti *rect)
808 {
809         const float k = U.rvisize * U.pixelsize;  /* axis size */
810         /* axis alpha offset (rvibright has range 0-10) */
811         const int bright = - 20 * (10 - U.rvibright);
812
813         /* Axis center in screen coordinates.
814          *
815          * - Unit size offset so small text doesn't draw outside the screen
816          * - Extra X offset because of the panel expander.
817          */
818         const float startx = rect->xmax - (k + UI_UNIT_X * 1.5);
819         const float starty = rect->ymax - (k + UI_UNIT_Y);
820
821         float axis_pos[3][2];
822         uchar axis_col[3][4];
823
824         int axis_order[3] = {0, 1, 2};
825         axis_sort_v3(rv3d->viewinv[2], axis_order);
826
827         for (int axis_i = 0; axis_i < 3; axis_i++) {
828                 int i = axis_order[axis_i];
829
830                 /* get position of each axis tip on screen */
831                 float vec[3] = { 0.0f };
832                 vec[i] = 1.0f;
833                 mul_qt_v3(rv3d->viewquat, vec);
834                 axis_pos[i][0] = startx + vec[0] * k;
835                 axis_pos[i][1] = starty + vec[1] * k;
836
837                 /* get color of each axis */
838                 UI_GetThemeColorShade3ubv(TH_AXIS_X + i, bright, axis_col[i]); /* rgb */
839                 axis_col[i][3] = 255 * hypotf(vec[0], vec[1]); /* alpha */
840         }
841
842         /* draw axis lines */
843         GPU_line_width(2.0f);
844         GPU_line_smooth(true);
845         GPU_blend(true);
846         GPU_blend_set_func_separate(GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA, GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA);
847
848         GPUVertFormat *format = immVertexFormat();
849         uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
850         uint col = GPU_vertformat_attr_add(format, "color", GPU_COMP_U8, 4, GPU_FETCH_INT_TO_FLOAT_UNIT);
851
852         immBindBuiltinProgram(GPU_SHADER_2D_FLAT_COLOR);
853         immBegin(GPU_PRIM_LINES, 6);
854
855         for (int axis_i = 0; axis_i < 3; axis_i++) {
856                 int i = axis_order[axis_i];
857
858                 immAttr4ubv(col, axis_col[i]);
859                 immVertex2f(pos, startx, starty);
860                 immAttr4ubv(col, axis_col[i]);
861                 immVertex2fv(pos, axis_pos[i]);
862         }
863
864         immEnd();
865         immUnbindProgram();
866         GPU_line_smooth(false);
867
868         /* draw axis names */
869         for (int axis_i = 0; axis_i < 3; axis_i++) {
870                 int i = axis_order[axis_i];
871
872                 const char axis_text[2] = {'x' + i, '\0'};
873                 BLF_color4ubv(BLF_default(), axis_col[i]);
874                 BLF_draw_default_ascii(axis_pos[i][0] + 2, axis_pos[i][1] + 2, 0.0f, axis_text, 1);
875         }
876 }
877
878 #ifdef WITH_INPUT_NDOF
879 /* draw center and axis of rotation for ongoing 3D mouse navigation */
880 static void draw_rotation_guide(const RegionView3D *rv3d)
881 {
882         float o[3];    /* center of rotation */
883         float end[3];  /* endpoints for drawing */
884
885         GLubyte color[4] = {0, 108, 255, 255};  /* bright blue so it matches device LEDs */
886
887         negate_v3_v3(o, rv3d->ofs);
888
889         GPU_blend(true);
890         GPU_blend_set_func_separate(GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA, GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA);
891         glDepthMask(GL_FALSE);  /* don't overwrite zbuf */
892
893         GPUVertFormat *format = immVertexFormat();
894         uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
895         uint col = GPU_vertformat_attr_add(format, "color", GPU_COMP_U8, 4, GPU_FETCH_INT_TO_FLOAT_UNIT);
896
897         immBindBuiltinProgram(GPU_SHADER_3D_SMOOTH_COLOR);
898
899         if (rv3d->rot_angle != 0.0f) {
900                 /* -- draw rotation axis -- */
901                 float scaled_axis[3];
902                 const float scale = rv3d->dist;
903                 mul_v3_v3fl(scaled_axis, rv3d->rot_axis, scale);
904
905
906                 immBegin(GPU_PRIM_LINE_STRIP, 3);
907                 color[3] = 0; /* more transparent toward the ends */
908                 immAttr4ubv(col, color);
909                 add_v3_v3v3(end, o, scaled_axis);
910                 immVertex3fv(pos, end);
911
912 #if 0
913                 color[3] = 0.2f + fabsf(rv3d->rot_angle);  /* modulate opacity with angle */
914                 /* ^^ neat idea, but angle is frame-rate dependent, so it's usually close to 0.2 */
915 #endif
916
917                 color[3] = 127; /* more opaque toward the center */
918                 immAttr4ubv(col, color);
919                 immVertex3fv(pos, o);
920
921                 color[3] = 0;
922                 immAttr4ubv(col, color);
923                 sub_v3_v3v3(end, o, scaled_axis);
924                 immVertex3fv(pos, end);
925                 immEnd();
926
927                 /* -- draw ring around rotation center -- */
928                 {
929 #define     ROT_AXIS_DETAIL 13
930
931                         const float s = 0.05f * scale;
932                         const float step = 2.0f * (float)(M_PI / ROT_AXIS_DETAIL);
933
934                         float q[4];  /* rotate ring so it's perpendicular to axis */
935                         const int upright = fabsf(rv3d->rot_axis[2]) >= 0.95f;
936                         if (!upright) {
937                                 const float up[3] = {0.0f, 0.0f, 1.0f};
938                                 float vis_angle, vis_axis[3];
939
940                                 cross_v3_v3v3(vis_axis, up, rv3d->rot_axis);
941                                 vis_angle = acosf(dot_v3v3(up, rv3d->rot_axis));
942                                 axis_angle_to_quat(q, vis_axis, vis_angle);
943                         }
944
945                         immBegin(GPU_PRIM_LINE_LOOP, ROT_AXIS_DETAIL);
946                         color[3] = 63; /* somewhat faint */
947                         immAttr4ubv(col, color);
948                         float angle = 0.0f;
949                         for (int i = 0; i < ROT_AXIS_DETAIL; ++i, angle += step) {
950                                 float p[3] = {s * cosf(angle), s * sinf(angle), 0.0f};
951
952                                 if (!upright) {
953                                         mul_qt_v3(q, p);
954                                 }
955
956                                 add_v3_v3(p, o);
957                                 immVertex3fv(pos, p);
958                         }
959                         immEnd();
960
961 #undef      ROT_AXIS_DETAIL
962                 }
963
964                 color[3] = 255;  /* solid dot */
965         }
966         else
967                 color[3] = 127;  /* see-through dot */
968
969         immUnbindProgram();
970
971         /* -- draw rotation center -- */
972         immBindBuiltinProgram(GPU_SHADER_3D_POINT_FIXED_SIZE_VARYING_COLOR);
973         GPU_point_size(5.0f);
974         immBegin(GPU_PRIM_POINTS, 1);
975         immAttr4ubv(col, color);
976         immVertex3fv(pos, o);
977         immEnd();
978         immUnbindProgram();
979
980 #if 0
981         /* find screen coordinates for rotation center, then draw pretty icon */
982         mul_m4_v3(rv3d->persinv, rot_center);
983         UI_icon_draw(rot_center[0], rot_center[1], ICON_NDOF_TURN);
984         /* ^^ just playing around, does not work */
985 #endif
986
987         GPU_blend(false);
988         glDepthMask(GL_TRUE);
989 }
990 #endif /* WITH_INPUT_NDOF */
991
992 /* ******************** info ***************** */
993
994 /**
995  * Render and camera border
996  */
997 static void view3d_draw_border(const bContext *C, ARegion *ar)
998 {
999         Scene *scene = CTX_data_scene(C);
1000         Depsgraph *depsgraph = CTX_data_depsgraph(C);
1001         RegionView3D *rv3d = ar->regiondata;
1002         View3D *v3d = CTX_wm_view3d(C);
1003
1004         if (rv3d->persp == RV3D_CAMOB) {
1005                 drawviewborder(scene, depsgraph, ar, v3d);
1006         }
1007         else if (v3d->flag2 & V3D_RENDER_BORDER) {
1008                 drawrenderborder(ar, v3d);
1009         }
1010 }
1011
1012 /**
1013  * Grease Pencil
1014  */
1015 static void view3d_draw_grease_pencil(const bContext *UNUSED(C))
1016 {
1017         /* TODO viewport */
1018 }
1019
1020 /**
1021  * Viewport Name
1022  */
1023 static const char *view3d_get_name(View3D *v3d, RegionView3D *rv3d)
1024 {
1025         const char *name = NULL;
1026
1027         switch (rv3d->view) {
1028                 case RV3D_VIEW_FRONT:
1029                         if (rv3d->persp == RV3D_ORTHO) name = IFACE_("Front Orthographic");
1030                         else name = IFACE_("Front Perspective");
1031                         break;
1032                 case RV3D_VIEW_BACK:
1033                         if (rv3d->persp == RV3D_ORTHO) name = IFACE_("Back Orthographic");
1034                         else name = IFACE_("Back Perspective");
1035                         break;
1036                 case RV3D_VIEW_TOP:
1037                         if (rv3d->persp == RV3D_ORTHO) name = IFACE_("Top Orthographic");
1038                         else name = IFACE_("Top Perspective");
1039                         break;
1040                 case RV3D_VIEW_BOTTOM:
1041                         if (rv3d->persp == RV3D_ORTHO) name = IFACE_("Bottom Orthographic");
1042                         else name = IFACE_("Bottom Perspective");
1043                         break;
1044                 case RV3D_VIEW_RIGHT:
1045                         if (rv3d->persp == RV3D_ORTHO) name = IFACE_("Right Orthographic");
1046                         else name = IFACE_("Right Perspective");
1047                         break;
1048                 case RV3D_VIEW_LEFT:
1049                         if (rv3d->persp == RV3D_ORTHO) name = IFACE_("Left Orthographic");
1050                         else name = IFACE_("Left Perspective");
1051                         break;
1052
1053                 default:
1054                         if (rv3d->persp == RV3D_CAMOB) {
1055                                 if ((v3d->camera) && (v3d->camera->type == OB_CAMERA)) {
1056                                         Camera *cam;
1057                                         cam = v3d->camera->data;
1058                                         if (cam->type == CAM_PERSP) {
1059                                                 name = IFACE_("Camera Perspective");
1060                                         }
1061                                         else if (cam->type == CAM_ORTHO) {
1062                                                 name = IFACE_("Camera Orthographic");
1063                                         }
1064                                         else {
1065                                                 BLI_assert(cam->type == CAM_PANO);
1066                                                 name = IFACE_("Camera Panoramic");
1067                                         }
1068                                 }
1069                                 else {
1070                                         name = IFACE_("Object as Camera");
1071                                 }
1072                         }
1073                         else {
1074                                 name = (rv3d->persp == RV3D_ORTHO) ? IFACE_("User Orthographic") : IFACE_("User Perspective");
1075                         }
1076         }
1077
1078         return name;
1079 }
1080
1081 static void draw_viewport_name(ARegion *ar, View3D *v3d, int xoffset, int *yoffset)
1082 {
1083         RegionView3D *rv3d = ar->regiondata;
1084         const char *name = view3d_get_name(v3d, rv3d);
1085         const int font_id = BLF_default();
1086
1087         /* increase size for unicode languages (Chinese in utf-8...) */
1088 #ifdef WITH_INTERNATIONAL
1089         char tmpstr[96];
1090 #else
1091         char tmpstr[32];
1092 #endif
1093
1094         BLF_enable(font_id, BLF_SHADOW);
1095         BLF_shadow(font_id, 5, (const float[4]){0.0f, 0.0f, 0.0f, 1.0f});
1096         BLF_shadow_offset(font_id, 1, -1);
1097
1098         if (v3d->localvd) {
1099                 BLI_snprintf(tmpstr, sizeof(tmpstr), IFACE_("%s (Local)"), name);
1100                 name = tmpstr;
1101         }
1102
1103         UI_FontThemeColor(BLF_default(), TH_TEXT_HI);
1104
1105         *yoffset -= U.widget_unit;
1106
1107 #ifdef WITH_INTERNATIONAL
1108         BLF_draw_default(xoffset, *yoffset, 0.0f, name, sizeof(tmpstr));
1109 #else
1110         BLF_draw_default_ascii(xoffset, *yoffset, 0.0f, name, sizeof(tmpstr));
1111 #endif
1112
1113         BLF_disable(font_id, BLF_SHADOW);
1114 }
1115
1116 /**
1117  * draw info beside axes in bottom left-corner:
1118  * framenum, collection, object name, bone name (if available), marker name (if available)
1119  */
1120
1121 static void draw_selected_name(Scene *scene, ViewLayer *view_layer, Object *ob, int xoffset, int *yoffset)
1122 {
1123         const int cfra = CFRA;
1124         const char *msg_pin = " (Pinned)";
1125         const char *msg_sep = " : ";
1126
1127         const int font_id = BLF_default();
1128
1129         char info[300];
1130         char *s = info;
1131
1132         s += sprintf(s, "(%d)", cfra);
1133
1134         if ((ob == NULL) || (ob->mode == OB_MODE_OBJECT)) {
1135                 LayerCollection *layer_collection = view_layer->active_collection;
1136                 s += sprintf(s, " %s%s", BKE_collection_ui_name_get(layer_collection->collection), (ob == NULL) ? "" : " |");
1137         }
1138
1139         /*
1140          * info can contain:
1141          * - a frame (7 + 2)
1142          * - a collection name (MAX_NAME + 3)
1143          * - 3 object names (MAX_NAME)
1144          * - 2 BREAD_CRUMB_SEPARATORs (6)
1145          * - a SHAPE_KEY_PINNED marker and a trailing '\0' (9+1) - translated, so give some room!
1146          * - a marker name (MAX_NAME + 3)
1147          */
1148
1149         /* get name of marker on current frame (if available) */
1150         const char *markern = BKE_scene_find_marker_name(scene, cfra);
1151
1152         /* check if there is an object */
1153         if (ob) {
1154                 *s++ = ' ';
1155                 s += BLI_strcpy_rlen(s, ob->id.name + 2);
1156
1157                 /* name(s) to display depends on type of object */
1158                 if (ob->type == OB_ARMATURE) {
1159                         bArmature *arm = ob->data;
1160
1161                         /* show name of active bone too (if possible) */
1162                         if (arm->edbo) {
1163                                 if (arm->act_edbone) {
1164                                         s += BLI_strcpy_rlen(s, msg_sep);
1165                                         s += BLI_strcpy_rlen(s, arm->act_edbone->name);
1166                                 }
1167                         }
1168                         else if (ob->mode & OB_MODE_POSE) {
1169                                 if (arm->act_bone) {
1170
1171                                         if (arm->act_bone->layer & arm->layer) {
1172                                                 s += BLI_strcpy_rlen(s, msg_sep);
1173                                                 s += BLI_strcpy_rlen(s, arm->act_bone->name);
1174                                         }
1175                                 }
1176                         }
1177                 }
1178                 else if (ELEM(ob->type, OB_MESH, OB_LATTICE, OB_CURVE)) {
1179                         /* try to display active bone and active shapekey too (if they exist) */
1180
1181                         if (ob->type == OB_MESH && ob->mode & OB_MODE_WEIGHT_PAINT) {
1182                                 Object *armobj = BKE_object_pose_armature_get(ob);
1183                                 if (armobj  && armobj->mode & OB_MODE_POSE) {
1184                                         bArmature *arm = armobj->data;
1185                                         if (arm->act_bone) {
1186                                                 if (arm->act_bone->layer & arm->layer) {
1187                                                         s += BLI_strcpy_rlen(s, msg_sep);
1188                                                         s += BLI_strcpy_rlen(s, arm->act_bone->name);
1189                                                 }
1190                                         }
1191                                 }
1192                         }
1193
1194                         Key *key = BKE_key_from_object(ob);
1195                         if (key) {
1196                                 KeyBlock *kb = BLI_findlink(&key->block, ob->shapenr - 1);
1197                                 if (kb) {
1198                                         s += BLI_strcpy_rlen(s, msg_sep);
1199                                         s += BLI_strcpy_rlen(s, kb->name);
1200                                         if (ob->shapeflag & OB_SHAPE_LOCK) {
1201                                                 s += BLI_strcpy_rlen(s, IFACE_(msg_pin));
1202                                         }
1203                                 }
1204                         }
1205                 }
1206
1207                 /* color depends on whether there is a keyframe */
1208                 if (id_frame_has_keyframe((ID *)ob, /* BKE_scene_frame_get(scene) */ (float)cfra, ANIMFILTER_KEYS_LOCAL)) {
1209                         UI_FontThemeColor(font_id, TH_TIME_KEYFRAME);
1210                 }
1211                 else if (ED_gpencil_has_keyframe_v3d(scene, ob, cfra)) {
1212                         UI_FontThemeColor(font_id, TH_TIME_GP_KEYFRAME);
1213                 }
1214                 else {
1215                         UI_FontThemeColor(font_id, TH_TEXT_HI);
1216                 }
1217         }
1218         else {
1219                 /* no object */
1220                 if (ED_gpencil_has_keyframe_v3d(scene, NULL, cfra))
1221                         UI_FontThemeColor(font_id, TH_TIME_GP_KEYFRAME);
1222                 else
1223                         UI_FontThemeColor(font_id, TH_TEXT_HI);
1224         }
1225
1226         if (markern) {
1227                 s += sprintf(s, " <%s>", markern);
1228         }
1229
1230         BLF_enable(font_id, BLF_SHADOW);
1231         BLF_shadow(font_id, 5, (const float[4]){0.0f, 0.0f, 0.0f, 1.0f});
1232         BLF_shadow_offset(font_id, 1, -1);
1233
1234         *yoffset -= U.widget_unit;
1235         BLF_draw_default(xoffset, *yoffset, 0.0f, info, sizeof(info));
1236
1237         BLF_disable(font_id, BLF_SHADOW);
1238 }
1239
1240 /* ******************** view loop ***************** */
1241
1242 /**
1243  * Information drawn on top of the solid plates and composed data
1244  */
1245 void view3d_draw_region_info(const bContext *C, ARegion *ar)
1246 {
1247         RegionView3D *rv3d = ar->regiondata;
1248         View3D *v3d = CTX_wm_view3d(C);
1249         Scene *scene = CTX_data_scene(C);
1250         wmWindowManager *wm = CTX_wm_manager(C);
1251
1252 #ifdef WITH_INPUT_NDOF
1253         if ((U.ndof_flag & NDOF_SHOW_GUIDE) &&
1254             ((rv3d->viewlock & RV3D_LOCKED) == 0) &&
1255             (rv3d->persp != RV3D_CAMOB))
1256         {
1257                 /* TODO: draw something else (but not this) during fly mode */
1258                 draw_rotation_guide(rv3d);
1259         }
1260 #endif
1261
1262         /* correct projection matrix */
1263         ED_region_pixelspace(ar);
1264
1265         /* local coordinate visible rect inside region, to accommodate overlapping ui */
1266         rcti rect;
1267         ED_region_visible_rect(ar, &rect);
1268
1269
1270         view3d_draw_border(C, ar);
1271         view3d_draw_grease_pencil(C);
1272
1273         BLF_batch_draw_begin();
1274
1275         if ((U.uiflag & USER_SHOW_GIZMO_AXIS) ||
1276             (v3d->flag2 & V3D_RENDER_OVERRIDE) ||
1277             /* No need to display gizmo and this info. */
1278             (v3d->gizmo_flag & (V3D_GIZMO_HIDE | V3D_GIZMO_HIDE_NAVIGATE)))
1279         {
1280                 /* pass */
1281         }
1282         else {
1283                 draw_view_axis(rv3d, &rect);
1284         }
1285
1286         int xoffset = rect.xmin + U.widget_unit;
1287         int yoffset = rect.ymax;
1288
1289         if ((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0 &&
1290             (v3d->overlay.flag & V3D_OVERLAY_HIDE_TEXT) == 0)
1291         {
1292                 if ((U.uiflag & USER_SHOW_FPS) && ED_screen_animation_no_scrub(wm)) {
1293                         ED_scene_draw_fps(scene, xoffset, &yoffset);
1294                 }
1295                 else if (U.uiflag & USER_SHOW_VIEWPORTNAME) {
1296                         draw_viewport_name(ar, v3d, xoffset, &yoffset);
1297                 }
1298
1299                 if (U.uiflag & USER_DRAWVIEWINFO) {
1300                         ViewLayer *view_layer = CTX_data_view_layer(C);
1301                         Object *ob = OBACT(view_layer);
1302                         draw_selected_name(scene, view_layer, ob, xoffset, &yoffset);
1303                 }
1304
1305 #if 0 /* TODO */
1306                 if (grid_unit) { /* draw below the viewport name */
1307                         char numstr[32] = "";
1308
1309                         UI_FontThemeColor(BLF_default(), TH_TEXT_HI);
1310                         if (v3d->grid != 1.0f) {
1311                                 BLI_snprintf(numstr, sizeof(numstr), "%s x %.4g", grid_unit, v3d->grid);
1312                         }
1313
1314                         *yoffset -= U.widget_unit;
1315                         BLF_draw_default_ascii(xoffset, *yoffset, numstr[0] ? numstr : grid_unit, sizeof(numstr));
1316                 }
1317 #endif
1318         }
1319
1320         if ((v3d->overlay.flag & V3D_OVERLAY_HIDE_TEXT) == 0) {
1321                 DRW_draw_region_engine_info(xoffset, yoffset);
1322         }
1323
1324         BLF_batch_draw_end();
1325 }
1326
1327 static void view3d_draw_view(const bContext *C, ARegion *ar)
1328 {
1329         ED_view3d_draw_setup_view(CTX_wm_window(C), CTX_data_depsgraph(C), CTX_data_scene(C), ar, CTX_wm_view3d(C), NULL, NULL, NULL);
1330
1331         /* Only 100% compliant on new spec goes below */
1332         DRW_draw_view(C);
1333 }
1334
1335 RenderEngineType *ED_view3d_engine_type(Scene *scene, int drawtype)
1336 {
1337         /*
1338          * Temporary viewport draw modes until we have a proper system.
1339          * all modes are done in the draw manager, except
1340          * cycles material as it is an external render engine.
1341          */
1342         if (strcmp(scene->r.engine, RE_engine_id_CYCLES) == 0 && drawtype == OB_MATERIAL) {
1343                 return RE_engines_find(RE_engine_id_BLENDER_EEVEE);
1344         }
1345         return RE_engines_find(scene->r.engine);
1346 }
1347
1348 void view3d_main_region_draw(const bContext *C, ARegion *ar)
1349 {
1350         Main *bmain = CTX_data_main(C);
1351         View3D *v3d = CTX_wm_view3d(C);
1352
1353         view3d_draw_view(C, ar);
1354
1355         GPU_free_images_old(bmain);
1356         GPU_pass_cache_garbage_collect();
1357
1358         /* XXX This is in order to draw UI batches with the DRW
1359          * olg context since we now use it for drawing the entire area */
1360         gpu_batch_presets_reset();
1361
1362         /* No depth test for drawing action zones afterwards. */
1363         GPU_depth_test(false);
1364
1365         v3d->flag |= V3D_INVALID_BACKBUF;
1366 }
1367
1368 /* -------------------------------------------------------------------- */
1369 /** \name Offscreen Drawing
1370  * \{ */
1371
1372 static void view3d_stereo3d_setup_offscreen(
1373         Depsgraph *depsgraph, Scene *scene, View3D *v3d, ARegion *ar,
1374         float winmat[4][4], const char *viewname)
1375 {
1376         /* update the viewport matrices with the new camera */
1377         if (scene->r.views_format == SCE_VIEWS_FORMAT_STEREO_3D) {
1378                 float viewmat[4][4];
1379                 const bool is_left = STREQ(viewname, STEREO_LEFT_NAME);
1380
1381                 BKE_camera_multiview_view_matrix(&scene->r, v3d->camera, is_left, viewmat);
1382                 view3d_main_region_setup_view(depsgraph, scene, v3d, ar, viewmat, winmat, NULL);
1383         }
1384         else { /* SCE_VIEWS_FORMAT_MULTIVIEW */
1385                 float viewmat[4][4];
1386                 Object *camera = BKE_camera_multiview_render(scene, v3d->camera, viewname);
1387
1388                 BKE_camera_multiview_view_matrix(&scene->r, camera, false, viewmat);
1389                 view3d_main_region_setup_view(depsgraph, scene, v3d, ar, viewmat, winmat, NULL);
1390         }
1391 }
1392
1393 void ED_view3d_draw_offscreen(
1394         Depsgraph *depsgraph, Scene *scene,
1395         int drawtype,
1396         View3D *v3d, ARegion *ar, int winx, int winy,
1397         float viewmat[4][4], float winmat[4][4],
1398         bool do_sky, bool UNUSED(is_persp), const char *viewname,
1399         GPUFXSettings *UNUSED(fx_settings),
1400         GPUOffScreen *ofs, GPUViewport *viewport)
1401 {
1402         RegionView3D *rv3d = ar->regiondata;
1403         RenderEngineType *engine_type = ED_view3d_engine_type(scene, drawtype);
1404
1405         /* set temporary new size */
1406         int bwinx = ar->winx;
1407         int bwiny = ar->winy;
1408         rcti brect = ar->winrct;
1409
1410         ar->winx = winx;
1411         ar->winy = winy;
1412         ar->winrct.xmin = 0;
1413         ar->winrct.ymin = 0;
1414         ar->winrct.xmax = winx;
1415         ar->winrct.ymax = winy;
1416
1417         struct bThemeState theme_state;
1418         UI_Theme_Store(&theme_state);
1419         UI_SetTheme(SPACE_VIEW3D, RGN_TYPE_WINDOW);
1420
1421         /* set flags */
1422         G.f |= G_FLAG_RENDER_VIEWPORT;
1423
1424         {
1425                 /* free images which can have changed on frame-change
1426                  * warning! can be slow so only free animated images - campbell */
1427                 GPU_free_images_anim(G.main);  /* XXX :((( */
1428         }
1429
1430         GPU_matrix_push_projection();
1431         GPU_matrix_identity_set();
1432         GPU_matrix_push();
1433         GPU_matrix_identity_set();
1434
1435         if ((viewname != NULL && viewname[0] != '\0') && (viewmat == NULL) && rv3d->persp == RV3D_CAMOB && v3d->camera)
1436                 view3d_stereo3d_setup_offscreen(depsgraph, scene, v3d, ar, winmat, viewname);
1437         else
1438                 view3d_main_region_setup_view(depsgraph, scene, v3d, ar, viewmat, winmat, NULL);
1439
1440         /* main drawing call */
1441         DRW_draw_render_loop_offscreen(
1442                 depsgraph, engine_type, ar, v3d,
1443                 do_sky, ofs, viewport);
1444
1445         /* restore size */
1446         ar->winx = bwinx;
1447         ar->winy = bwiny;
1448         ar->winrct = brect;
1449
1450         GPU_matrix_pop_projection();
1451         GPU_matrix_pop();
1452
1453         UI_Theme_Restore(&theme_state);
1454
1455         G.f &= ~G_FLAG_RENDER_VIEWPORT;
1456 }
1457
1458 /**
1459  * Utility func for ED_view3d_draw_offscreen
1460  *
1461  * \param ofs: Optional off-screen buffer, can be NULL.
1462  * (avoids re-creating when doing multiple GL renders).
1463  */
1464 ImBuf *ED_view3d_draw_offscreen_imbuf(
1465         Depsgraph *depsgraph, Scene *scene,
1466         int drawtype,
1467         View3D *v3d, ARegion *ar, int sizex, int sizey,
1468         uint flag, uint draw_flags,
1469         int alpha_mode, int samples, const char *viewname,
1470         /* output vars */
1471         GPUOffScreen *ofs, char err_out[256])
1472 {
1473         RegionView3D *rv3d = ar->regiondata;
1474         const bool draw_sky = (alpha_mode == R_ADDSKY);
1475         const bool use_full_sample = (draw_flags & V3D_OFSDRAW_USE_FULL_SAMPLE);
1476
1477         /* view state */
1478         GPUFXSettings fx_settings = v3d->fx_settings;
1479         bool is_ortho = false;
1480         float winmat[4][4];
1481
1482         if (ofs && ((GPU_offscreen_width(ofs) != sizex) || (GPU_offscreen_height(ofs) != sizey))) {
1483                 /* sizes differ, can't reuse */
1484                 ofs = NULL;
1485         }
1486
1487         GPUFrameBuffer *old_fb = GPU_framebuffer_active_get();
1488
1489         if (old_fb)  {
1490                 GPU_framebuffer_restore();
1491         }
1492
1493         const bool own_ofs = (ofs == NULL);
1494         DRW_opengl_context_enable();
1495
1496         if (own_ofs) {
1497                 /* bind */
1498                 ofs = GPU_offscreen_create(sizex, sizey, use_full_sample ? 0 : samples, true, false, err_out);
1499                 if (ofs == NULL) {
1500                         DRW_opengl_context_disable();
1501                         return NULL;
1502                 }
1503         }
1504
1505         GPU_offscreen_bind(ofs, true);
1506
1507         /* read in pixels & stamp */
1508         ImBuf *ibuf = IMB_allocImBuf(sizex, sizey, 32, flag);
1509
1510         /* render 3d view */
1511         if (rv3d->persp == RV3D_CAMOB && v3d->camera) {
1512                 CameraParams params;
1513                 Object *camera = BKE_camera_multiview_render(scene, v3d->camera, viewname);
1514                 const Object *camera_eval = DEG_get_evaluated_object(
1515                                                 depsgraph,
1516                                                 camera);
1517
1518                 BKE_camera_params_init(&params);
1519                 /* fallback for non camera objects */
1520                 params.clip_start = v3d->clip_start;
1521                 params.clip_end = v3d->clip_end;
1522                 BKE_camera_params_from_object(&params, camera_eval);
1523                 BKE_camera_multiview_params(&scene->r, &params, camera_eval, viewname);
1524                 BKE_camera_params_compute_viewplane(&params, sizex, sizey, scene->r.xasp, scene->r.yasp);
1525                 BKE_camera_params_compute_matrix(&params);
1526
1527                 BKE_camera_to_gpu_dof(camera, &fx_settings);
1528
1529                 is_ortho = params.is_ortho;
1530                 copy_m4_m4(winmat, params.winmat);
1531         }
1532         else {
1533                 rctf viewplane;
1534                 float clip_start, clipend;
1535
1536                 is_ortho = ED_view3d_viewplane_get(depsgraph, v3d, rv3d, sizex, sizey, &viewplane, &clip_start, &clipend, NULL);
1537                 if (is_ortho) {
1538                         orthographic_m4(winmat, viewplane.xmin, viewplane.xmax, viewplane.ymin, viewplane.ymax, -clipend, clipend);
1539                 }
1540                 else {
1541                         perspective_m4(winmat, viewplane.xmin, viewplane.xmax, viewplane.ymin, viewplane.ymax, clip_start, clipend);
1542                 }
1543         }
1544
1545         if ((samples && use_full_sample) == 0) {
1546                 /* Single-pass render, common case */
1547                 ED_view3d_draw_offscreen(
1548                         depsgraph, scene, drawtype,
1549                         v3d, ar, sizex, sizey, NULL, winmat,
1550                         draw_sky, !is_ortho, viewname,
1551                         &fx_settings, ofs, NULL);
1552
1553                 if (ibuf->rect_float) {
1554                         GPU_offscreen_read_pixels(ofs, GL_FLOAT, ibuf->rect_float);
1555                 }
1556                 else if (ibuf->rect) {
1557                         GPU_offscreen_read_pixels(ofs, GL_UNSIGNED_BYTE, ibuf->rect);
1558                 }
1559         }
1560         else {
1561                 /* Multi-pass render, use accumulation buffer & jitter for 'full' oversampling.
1562                  * Use because OpenGL may use a lower quality MSAA, and only over-sample edges. */
1563                 static float jit_ofs[32][2];
1564                 float winmat_jitter[4][4];
1565                 float *rect_temp = (ibuf->rect_float) ? ibuf->rect_float : MEM_mallocN(sizex * sizey * sizeof(float[4]), "rect_temp");
1566                 float *accum_buffer = MEM_mallocN(sizex * sizey * sizeof(float[4]), "accum_buffer");
1567                 GPUViewport *viewport = GPU_viewport_create_from_offscreen(ofs);
1568
1569                 BLI_jitter_init(jit_ofs, samples);
1570
1571                 /* first sample buffer, also initializes 'rv3d->persmat' */
1572                 ED_view3d_draw_offscreen(
1573                         depsgraph, scene, drawtype,
1574                         v3d, ar, sizex, sizey, NULL, winmat,
1575                         draw_sky, !is_ortho, viewname,
1576                         &fx_settings, ofs, viewport);
1577                 GPU_offscreen_read_pixels(ofs, GL_FLOAT, accum_buffer);
1578
1579                 /* skip the first sample */
1580                 for (int j = 1; j < samples; j++) {
1581                         copy_m4_m4(winmat_jitter, winmat);
1582                         window_translate_m4(
1583                                 winmat_jitter, rv3d->persmat,
1584                                 (jit_ofs[j][0] * 2.0f) / sizex,
1585                                 (jit_ofs[j][1] * 2.0f) / sizey);
1586
1587                         ED_view3d_draw_offscreen(
1588                                 depsgraph, scene, drawtype,
1589                                 v3d, ar, sizex, sizey, NULL, winmat_jitter,
1590                                 draw_sky, !is_ortho, viewname,
1591                                 &fx_settings, ofs, viewport);
1592                         GPU_offscreen_read_pixels(ofs, GL_FLOAT, rect_temp);
1593
1594                         uint i = sizex * sizey * 4;
1595                         while (i--) {
1596                                 accum_buffer[i] += rect_temp[i];
1597                         }
1598                 }
1599
1600                 {
1601                         /* don't free data owned by 'ofs' */
1602                         GPU_viewport_clear_from_offscreen(viewport);
1603                         GPU_viewport_free(viewport);
1604                 }
1605
1606                 if (ibuf->rect_float == NULL) {
1607                         MEM_freeN(rect_temp);
1608                 }
1609
1610                 if (ibuf->rect_float) {
1611                         float *rect_float = ibuf->rect_float;
1612                         uint i = sizex * sizey * 4;
1613                         while (i--) {
1614                                 rect_float[i] = accum_buffer[i] / samples;
1615                         }
1616                 }
1617                 else {
1618                         uchar *rect_ub = (uchar *)ibuf->rect;
1619                         uint i = sizex * sizey * 4;
1620                         while (i--) {
1621                                 rect_ub[i] = (uchar)(255.0f * accum_buffer[i] / samples);
1622                         }
1623                 }
1624
1625                 MEM_freeN(accum_buffer);
1626         }
1627
1628         /* unbind */
1629         GPU_offscreen_unbind(ofs, true);
1630
1631         if (own_ofs) {
1632                 GPU_offscreen_free(ofs);
1633         }
1634
1635         DRW_opengl_context_disable();
1636
1637         if (old_fb)  {
1638                 GPU_framebuffer_bind(old_fb);
1639         }
1640
1641         if (ibuf->rect_float && ibuf->rect)
1642                 IMB_rect_from_float(ibuf);
1643
1644         return ibuf;
1645 }
1646
1647 /**
1648  * Creates own fake 3d views (wrapping #ED_view3d_draw_offscreen_imbuf)
1649  *
1650  * \param ofs: Optional off-screen buffer can be NULL.
1651  * (avoids re-creating when doing multiple GL renders).
1652  *
1653  * \note used by the sequencer
1654  */
1655 ImBuf *ED_view3d_draw_offscreen_imbuf_simple(
1656         Depsgraph *depsgraph, Scene *scene,
1657         int drawtype,
1658         Object *camera, int width, int height,
1659         uint flag, uint draw_flags,
1660         int alpha_mode, int samples, const char *viewname,
1661         GPUOffScreen *ofs, char err_out[256])
1662 {
1663         View3D v3d = {NULL};
1664         ARegion ar = {NULL};
1665         RegionView3D rv3d = {{{0}}};
1666
1667         /* connect data */
1668         v3d.regionbase.first = v3d.regionbase.last = &ar;
1669         ar.regiondata = &rv3d;
1670         ar.regiontype = RGN_TYPE_WINDOW;
1671
1672         v3d.camera = camera;
1673         v3d.shading.type = drawtype;
1674         v3d.flag2 = V3D_RENDER_OVERRIDE;
1675
1676         if (draw_flags & V3D_OFSDRAW_USE_GPENCIL) {
1677                 v3d.flag2 |= V3D_SHOW_ANNOTATION;
1678         }
1679
1680         v3d.shading.background_type = V3D_SHADING_BACKGROUND_WORLD;
1681
1682         if (draw_flags & V3D_OFSDRAW_USE_CAMERA_DOF) {
1683                 if (camera->type == OB_CAMERA) {
1684                         v3d.fx_settings.dof = &((Camera *)camera->data)->gpu_dof;
1685                         v3d.fx_settings.fx_flag |= GPU_FX_FLAG_DOF;
1686                 }
1687         }
1688
1689         rv3d.persp = RV3D_CAMOB;
1690
1691         copy_m4_m4(rv3d.viewinv, v3d.camera->obmat);
1692         normalize_m4(rv3d.viewinv);
1693         invert_m4_m4(rv3d.viewmat, rv3d.viewinv);
1694
1695         {
1696                 CameraParams params;
1697                 const Object *view_camera_eval = DEG_get_evaluated_object(
1698                                                      depsgraph,
1699                                                      BKE_camera_multiview_render(scene, v3d.camera, viewname));
1700
1701                 BKE_camera_params_init(&params);
1702                 BKE_camera_params_from_object(&params, view_camera_eval);
1703                 BKE_camera_multiview_params(&scene->r, &params, view_camera_eval, viewname);
1704                 BKE_camera_params_compute_viewplane(&params, width, height, scene->r.xasp, scene->r.yasp);
1705                 BKE_camera_params_compute_matrix(&params);
1706
1707                 copy_m4_m4(rv3d.winmat, params.winmat);
1708                 v3d.clip_start = params.clip_start;
1709                 v3d.clip_end = params.clip_end;
1710                 v3d.lens = params.lens;
1711         }
1712
1713         mul_m4_m4m4(rv3d.persmat, rv3d.winmat, rv3d.viewmat);
1714         invert_m4_m4(rv3d.persinv, rv3d.viewinv);
1715
1716         return ED_view3d_draw_offscreen_imbuf(
1717                 depsgraph, scene, drawtype,
1718                 &v3d, &ar, width, height, flag,
1719                 draw_flags, alpha_mode, samples, viewname, ofs, err_out);
1720 }
1721
1722 /** \} */
1723
1724 /* -------------------------------------------------------------------- */
1725 /** \name Viewport Clipping
1726  * \{ */
1727
1728 static bool view3d_clipping_test(const float co[3], const float clip[6][4])
1729 {
1730         if (plane_point_side_v3(clip[0], co) > 0.0f)
1731                 if (plane_point_side_v3(clip[1], co) > 0.0f)
1732                         if (plane_point_side_v3(clip[2], co) > 0.0f)
1733                                 if (plane_point_side_v3(clip[3], co) > 0.0f)
1734                                         return false;
1735
1736         return true;
1737 }
1738
1739 /* for 'local' ED_view3d_clipping_local must run first
1740  * then all comparisons can be done in localspace */
1741 bool ED_view3d_clipping_test(const RegionView3D *rv3d, const float co[3], const bool is_local)
1742 {
1743         return view3d_clipping_test(co, is_local ? rv3d->clip_local : rv3d->clip);
1744 }
1745
1746
1747 /** \} */