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 blender/editors/space_view3d/view3d_draw.c
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 lamps 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.clipsta = v3d->near;
317         params.clipend = v3d->far;
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                         float grid_distance = rv3d->dist;
794                         float lvl = (logf(grid_distance / grid_scale) / logf(grid_subdiv));
795
796                         /* 1.3f is a visually chosen offset for the
797                          * subdivision to match the visible grid. */
798                         lvl -= 1.3f;
799                         CLAMP_MIN(lvl, 0.0f);
800
801                         grid_scale *= pow(grid_subdiv, (int)lvl);
802                 }
803         }
804
805         return grid_scale;
806 }
807
808 static void draw_view_axis(RegionView3D *rv3d, const rcti *rect)
809 {
810         const float k = U.rvisize * U.pixelsize;  /* axis size */
811         /* axis alpha offset (rvibright has range 0-10) */
812         const int bright = - 20 * (10 - U.rvibright);
813
814         /* Axis center in screen coordinates.
815          *
816          * - Unit size offset so small text doesn't draw outside the screen
817          * - Extra X offset because of the panel expander.
818          */
819         const float startx = rect->xmax - (k + UI_UNIT_X * 1.5);
820         const float starty = rect->ymax - (k + UI_UNIT_Y);
821
822         float axis_pos[3][2];
823         unsigned char axis_col[3][4];
824
825         int axis_order[3] = {0, 1, 2};
826         axis_sort_v3(rv3d->viewinv[2], axis_order);
827
828         for (int axis_i = 0; axis_i < 3; axis_i++) {
829                 int i = axis_order[axis_i];
830
831                 /* get position of each axis tip on screen */
832                 float vec[3] = { 0.0f };
833                 vec[i] = 1.0f;
834                 mul_qt_v3(rv3d->viewquat, vec);
835                 axis_pos[i][0] = startx + vec[0] * k;
836                 axis_pos[i][1] = starty + vec[1] * k;
837
838                 /* get color of each axis */
839                 UI_GetThemeColorShade3ubv(TH_AXIS_X + i, bright, axis_col[i]); /* rgb */
840                 axis_col[i][3] = 255 * hypotf(vec[0], vec[1]); /* alpha */
841         }
842
843         /* draw axis lines */
844         GPU_line_width(2.0f);
845         GPU_line_smooth(true);
846         GPU_blend(true);
847         GPU_blend_set_func_separate(GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA, GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA);
848
849         GPUVertFormat *format = immVertexFormat();
850         uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT);
851         uint col = GPU_vertformat_attr_add(format, "color", GPU_COMP_U8, 4, GPU_FETCH_INT_TO_FLOAT_UNIT);
852
853         immBindBuiltinProgram(GPU_SHADER_2D_FLAT_COLOR);
854         immBegin(GPU_PRIM_LINES, 6);
855
856         for (int axis_i = 0; axis_i < 3; axis_i++) {
857                 int i = axis_order[axis_i];
858
859                 immAttr4ubv(col, axis_col[i]);
860                 immVertex2f(pos, startx, starty);
861                 immAttr4ubv(col, axis_col[i]);
862                 immVertex2fv(pos, axis_pos[i]);
863         }
864
865         immEnd();
866         immUnbindProgram();
867         GPU_line_smooth(false);
868
869         /* draw axis names */
870         for (int axis_i = 0; axis_i < 3; axis_i++) {
871                 int i = axis_order[axis_i];
872
873                 const char axis_text[2] = {'x' + i, '\0'};
874                 BLF_color4ubv(BLF_default(), axis_col[i]);
875                 BLF_draw_default_ascii(axis_pos[i][0] + 2, axis_pos[i][1] + 2, 0.0f, axis_text, 1);
876         }
877 }
878
879 #ifdef WITH_INPUT_NDOF
880 /* draw center and axis of rotation for ongoing 3D mouse navigation */
881 static void draw_rotation_guide(const RegionView3D *rv3d)
882 {
883         float o[3];    /* center of rotation */
884         float end[3];  /* endpoints for drawing */
885
886         GLubyte color[4] = {0, 108, 255, 255};  /* bright blue so it matches device LEDs */
887
888         negate_v3_v3(o, rv3d->ofs);
889
890         GPU_blend(true);
891         GPU_blend_set_func_separate(GPU_SRC_ALPHA, GPU_ONE_MINUS_SRC_ALPHA, GPU_ONE, GPU_ONE_MINUS_SRC_ALPHA);
892         glDepthMask(GL_FALSE);  /* don't overwrite zbuf */
893
894         GPUVertFormat *format = immVertexFormat();
895         uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 3, GPU_FETCH_FLOAT);
896         uint col = GPU_vertformat_attr_add(format, "color", GPU_COMP_U8, 4, GPU_FETCH_INT_TO_FLOAT_UNIT);
897
898         immBindBuiltinProgram(GPU_SHADER_3D_SMOOTH_COLOR);
899
900         if (rv3d->rot_angle != 0.0f) {
901                 /* -- draw rotation axis -- */
902                 float scaled_axis[3];
903                 const float scale = rv3d->dist;
904                 mul_v3_v3fl(scaled_axis, rv3d->rot_axis, scale);
905
906
907                 immBegin(GPU_PRIM_LINE_STRIP, 3);
908                 color[3] = 0; /* more transparent toward the ends */
909                 immAttr4ubv(col, color);
910                 add_v3_v3v3(end, o, scaled_axis);
911                 immVertex3fv(pos, end);
912
913 #if 0
914                 color[3] = 0.2f + fabsf(rv3d->rot_angle);  /* modulate opacity with angle */
915                 /* ^^ neat idea, but angle is frame-rate dependent, so it's usually close to 0.2 */
916 #endif
917
918                 color[3] = 127; /* more opaque toward the center */
919                 immAttr4ubv(col, color);
920                 immVertex3fv(pos, o);
921
922                 color[3] = 0;
923                 immAttr4ubv(col, color);
924                 sub_v3_v3v3(end, o, scaled_axis);
925                 immVertex3fv(pos, end);
926                 immEnd();
927
928                 /* -- draw ring around rotation center -- */
929                 {
930 #define     ROT_AXIS_DETAIL 13
931
932                         const float s = 0.05f * scale;
933                         const float step = 2.0f * (float)(M_PI / ROT_AXIS_DETAIL);
934
935                         float q[4];  /* rotate ring so it's perpendicular to axis */
936                         const int upright = fabsf(rv3d->rot_axis[2]) >= 0.95f;
937                         if (!upright) {
938                                 const float up[3] = {0.0f, 0.0f, 1.0f};
939                                 float vis_angle, vis_axis[3];
940
941                                 cross_v3_v3v3(vis_axis, up, rv3d->rot_axis);
942                                 vis_angle = acosf(dot_v3v3(up, rv3d->rot_axis));
943                                 axis_angle_to_quat(q, vis_axis, vis_angle);
944                         }
945
946                         immBegin(GPU_PRIM_LINE_LOOP, ROT_AXIS_DETAIL);
947                         color[3] = 63; /* somewhat faint */
948                         immAttr4ubv(col, color);
949                         float angle = 0.0f;
950                         for (int i = 0; i < ROT_AXIS_DETAIL; ++i, angle += step) {
951                                 float p[3] = {s * cosf(angle), s * sinf(angle), 0.0f};
952
953                                 if (!upright) {
954                                         mul_qt_v3(q, p);
955                                 }
956
957                                 add_v3_v3(p, o);
958                                 immVertex3fv(pos, p);
959                         }
960                         immEnd();
961
962 #undef      ROT_AXIS_DETAIL
963                 }
964
965                 color[3] = 255;  /* solid dot */
966         }
967         else
968                 color[3] = 127;  /* see-through dot */
969
970         immUnbindProgram();
971
972         /* -- draw rotation center -- */
973         immBindBuiltinProgram(GPU_SHADER_3D_POINT_FIXED_SIZE_VARYING_COLOR);
974         GPU_point_size(5.0f);
975         immBegin(GPU_PRIM_POINTS, 1);
976         immAttr4ubv(col, color);
977         immVertex3fv(pos, o);
978         immEnd();
979         immUnbindProgram();
980
981 #if 0
982         /* find screen coordinates for rotation center, then draw pretty icon */
983         mul_m4_v3(rv3d->persinv, rot_center);
984         UI_icon_draw(rot_center[0], rot_center[1], ICON_NDOF_TURN);
985         /* ^^ just playing around, does not work */
986 #endif
987
988         GPU_blend(false);
989         glDepthMask(GL_TRUE);
990 }
991 #endif /* WITH_INPUT_NDOF */
992
993 /* ******************** info ***************** */
994
995 /**
996  * Render and camera border
997  */
998 static void view3d_draw_border(const bContext *C, ARegion *ar)
999 {
1000         Scene *scene = CTX_data_scene(C);
1001         Depsgraph *depsgraph = CTX_data_depsgraph(C);
1002         RegionView3D *rv3d = ar->regiondata;
1003         View3D *v3d = CTX_wm_view3d(C);
1004
1005         if (rv3d->persp == RV3D_CAMOB) {
1006                 drawviewborder(scene, depsgraph, ar, v3d);
1007         }
1008         else if (v3d->flag2 & V3D_RENDER_BORDER) {
1009                 drawrenderborder(ar, v3d);
1010         }
1011 }
1012
1013 /**
1014  * Grease Pencil
1015  */
1016 static void view3d_draw_grease_pencil(const bContext *UNUSED(C))
1017 {
1018         /* TODO viewport */
1019 }
1020
1021 /**
1022  * Viewport Name
1023  */
1024 static const char *view3d_get_name(View3D *v3d, RegionView3D *rv3d)
1025 {
1026         const char *name = NULL;
1027
1028         switch (rv3d->view) {
1029                 case RV3D_VIEW_FRONT:
1030                         if (rv3d->persp == RV3D_ORTHO) name = IFACE_("Front Orthographic");
1031                         else name = IFACE_("Front Perspective");
1032                         break;
1033                 case RV3D_VIEW_BACK:
1034                         if (rv3d->persp == RV3D_ORTHO) name = IFACE_("Back Orthographic");
1035                         else name = IFACE_("Back Perspective");
1036                         break;
1037                 case RV3D_VIEW_TOP:
1038                         if (rv3d->persp == RV3D_ORTHO) name = IFACE_("Top Orthographic");
1039                         else name = IFACE_("Top Perspective");
1040                         break;
1041                 case RV3D_VIEW_BOTTOM:
1042                         if (rv3d->persp == RV3D_ORTHO) name = IFACE_("Bottom Orthographic");
1043                         else name = IFACE_("Bottom Perspective");
1044                         break;
1045                 case RV3D_VIEW_RIGHT:
1046                         if (rv3d->persp == RV3D_ORTHO) name = IFACE_("Right Orthographic");
1047                         else name = IFACE_("Right Perspective");
1048                         break;
1049                 case RV3D_VIEW_LEFT:
1050                         if (rv3d->persp == RV3D_ORTHO) name = IFACE_("Left Orthographic");
1051                         else name = IFACE_("Left Perspective");
1052                         break;
1053
1054                 default:
1055                         if (rv3d->persp == RV3D_CAMOB) {
1056                                 if ((v3d->camera) && (v3d->camera->type == OB_CAMERA)) {
1057                                         Camera *cam;
1058                                         cam = v3d->camera->data;
1059                                         if (cam->type == CAM_PERSP) {
1060                                                 name = IFACE_("Camera Perspective");
1061                                         }
1062                                         else if (cam->type == CAM_ORTHO) {
1063                                                 name = IFACE_("Camera Orthographic");
1064                                         }
1065                                         else {
1066                                                 BLI_assert(cam->type == CAM_PANO);
1067                                                 name = IFACE_("Camera Panoramic");
1068                                         }
1069                                 }
1070                                 else {
1071                                         name = IFACE_("Object as Camera");
1072                                 }
1073                         }
1074                         else {
1075                                 name = (rv3d->persp == RV3D_ORTHO) ? IFACE_("User Orthographic") : IFACE_("User Perspective");
1076                         }
1077         }
1078
1079         return name;
1080 }
1081
1082 static void draw_viewport_name(ARegion *ar, View3D *v3d, int xoffset, int *yoffset)
1083 {
1084         RegionView3D *rv3d = ar->regiondata;
1085         const char *name = view3d_get_name(v3d, rv3d);
1086         const int font_id = BLF_default();
1087
1088         /* increase size for unicode languages (Chinese in utf-8...) */
1089 #ifdef WITH_INTERNATIONAL
1090         char tmpstr[96];
1091 #else
1092         char tmpstr[32];
1093 #endif
1094
1095         BLF_enable(font_id, BLF_SHADOW);
1096         BLF_shadow(font_id, 5, (const float[4]){0.0f, 0.0f, 0.0f, 1.0f});
1097         BLF_shadow_offset(font_id, 1, -1);
1098
1099         if (v3d->localvd) {
1100                 BLI_snprintf(tmpstr, sizeof(tmpstr), IFACE_("%s (Local)"), name);
1101                 name = tmpstr;
1102         }
1103
1104         UI_FontThemeColor(BLF_default(), TH_TEXT_HI);
1105
1106         *yoffset -= U.widget_unit;
1107
1108 #ifdef WITH_INTERNATIONAL
1109         BLF_draw_default(xoffset, *yoffset, 0.0f, name, sizeof(tmpstr));
1110 #else
1111         BLF_draw_default_ascii(xoffset, *yoffset, 0.0f, name, sizeof(tmpstr));
1112 #endif
1113
1114         BLF_disable(font_id, BLF_SHADOW);
1115 }
1116
1117 /**
1118  * draw info beside axes in bottom left-corner:
1119  * framenum, collection, object name, bone name (if available), marker name (if available)
1120  */
1121
1122 static void draw_selected_name(Scene *scene, ViewLayer *view_layer, Object *ob, int xoffset, int *yoffset)
1123 {
1124         const int cfra = CFRA;
1125         const char *msg_pin = " (Pinned)";
1126         const char *msg_sep = " : ";
1127
1128         const int font_id = BLF_default();
1129
1130         char info[300];
1131         char *s = info;
1132
1133         s += sprintf(s, "(%d)", cfra);
1134
1135         if ((ob == NULL) || (ob->mode == OB_MODE_OBJECT)) {
1136                 LayerCollection *layer_collection = view_layer->active_collection;
1137                 s += sprintf(s, " %s%s", BKE_collection_ui_name_get(layer_collection->collection), (ob == NULL) ? "" : " |");
1138         }
1139
1140         /*
1141          * info can contain:
1142          * - a frame (7 + 2)
1143          * - a collection name (MAX_NAME + 3)
1144          * - 3 object names (MAX_NAME)
1145          * - 2 BREAD_CRUMB_SEPARATORs (6)
1146          * - a SHAPE_KEY_PINNED marker and a trailing '\0' (9+1) - translated, so give some room!
1147          * - a marker name (MAX_NAME + 3)
1148          */
1149
1150         /* get name of marker on current frame (if available) */
1151         const char *markern = BKE_scene_find_marker_name(scene, cfra);
1152
1153         /* check if there is an object */
1154         if (ob) {
1155                 *s++ = ' ';
1156                 s += BLI_strcpy_rlen(s, ob->id.name + 2);
1157
1158                 /* name(s) to display depends on type of object */
1159                 if (ob->type == OB_ARMATURE) {
1160                         bArmature *arm = ob->data;
1161
1162                         /* show name of active bone too (if possible) */
1163                         if (arm->edbo) {
1164                                 if (arm->act_edbone) {
1165                                         s += BLI_strcpy_rlen(s, msg_sep);
1166                                         s += BLI_strcpy_rlen(s, arm->act_edbone->name);
1167                                 }
1168                         }
1169                         else if (ob->mode & OB_MODE_POSE) {
1170                                 if (arm->act_bone) {
1171
1172                                         if (arm->act_bone->layer & arm->layer) {
1173                                                 s += BLI_strcpy_rlen(s, msg_sep);
1174                                                 s += BLI_strcpy_rlen(s, arm->act_bone->name);
1175                                         }
1176                                 }
1177                         }
1178                 }
1179                 else if (ELEM(ob->type, OB_MESH, OB_LATTICE, OB_CURVE)) {
1180                         /* try to display active bone and active shapekey too (if they exist) */
1181
1182                         if (ob->type == OB_MESH && ob->mode & OB_MODE_WEIGHT_PAINT) {
1183                                 Object *armobj = BKE_object_pose_armature_get(ob);
1184                                 if (armobj  && armobj->mode & OB_MODE_POSE) {
1185                                         bArmature *arm = armobj->data;
1186                                         if (arm->act_bone) {
1187                                                 if (arm->act_bone->layer & arm->layer) {
1188                                                         s += BLI_strcpy_rlen(s, msg_sep);
1189                                                         s += BLI_strcpy_rlen(s, arm->act_bone->name);
1190                                                 }
1191                                         }
1192                                 }
1193                         }
1194
1195                         Key *key = BKE_key_from_object(ob);
1196                         if (key) {
1197                                 KeyBlock *kb = BLI_findlink(&key->block, ob->shapenr - 1);
1198                                 if (kb) {
1199                                         s += BLI_strcpy_rlen(s, msg_sep);
1200                                         s += BLI_strcpy_rlen(s, kb->name);
1201                                         if (ob->shapeflag & OB_SHAPE_LOCK) {
1202                                                 s += BLI_strcpy_rlen(s, IFACE_(msg_pin));
1203                                         }
1204                                 }
1205                         }
1206                 }
1207
1208                 /* color depends on whether there is a keyframe */
1209                 if (id_frame_has_keyframe((ID *)ob, /* BKE_scene_frame_get(scene) */ (float)cfra, ANIMFILTER_KEYS_LOCAL)) {
1210                         UI_FontThemeColor(font_id, TH_TIME_KEYFRAME);
1211                 }
1212                 else if (ED_gpencil_has_keyframe_v3d(scene, ob, cfra)) {
1213                         UI_FontThemeColor(font_id, TH_TIME_GP_KEYFRAME);
1214                 }
1215                 else {
1216                         UI_FontThemeColor(font_id, TH_TEXT_HI);
1217                 }
1218         }
1219         else {
1220                 /* no object */
1221                 if (ED_gpencil_has_keyframe_v3d(scene, NULL, cfra))
1222                         UI_FontThemeColor(font_id, TH_TIME_GP_KEYFRAME);
1223                 else
1224                         UI_FontThemeColor(font_id, TH_TEXT_HI);
1225         }
1226
1227         if (markern) {
1228                 s += sprintf(s, " <%s>", markern);
1229         }
1230
1231         BLF_enable(font_id, BLF_SHADOW);
1232         BLF_shadow(font_id, 5, (const float[4]){0.0f, 0.0f, 0.0f, 1.0f});
1233         BLF_shadow_offset(font_id, 1, -1);
1234
1235         *yoffset -= U.widget_unit;
1236         BLF_draw_default(xoffset, *yoffset, 0.0f, info, sizeof(info));
1237
1238         BLF_disable(font_id, BLF_SHADOW);
1239 }
1240
1241 /* ******************** view loop ***************** */
1242
1243 /**
1244  * Information drawn on top of the solid plates and composed data
1245  */
1246 void view3d_draw_region_info(const bContext *C, ARegion *ar)
1247 {
1248         RegionView3D *rv3d = ar->regiondata;
1249         View3D *v3d = CTX_wm_view3d(C);
1250         Scene *scene = CTX_data_scene(C);
1251         wmWindowManager *wm = CTX_wm_manager(C);
1252
1253 #ifdef WITH_INPUT_NDOF
1254         if ((U.ndof_flag & NDOF_SHOW_GUIDE) &&
1255             ((rv3d->viewlock & RV3D_LOCKED) == 0) &&
1256             (rv3d->persp != RV3D_CAMOB))
1257         {
1258                 /* TODO: draw something else (but not this) during fly mode */
1259                 draw_rotation_guide(rv3d);
1260         }
1261 #endif
1262
1263         /* correct projection matrix */
1264         ED_region_pixelspace(ar);
1265
1266         /* local coordinate visible rect inside region, to accommodate overlapping ui */
1267         rcti rect;
1268         ED_region_visible_rect(ar, &rect);
1269
1270
1271         view3d_draw_border(C, ar);
1272         view3d_draw_grease_pencil(C);
1273
1274         BLF_batch_draw_begin();
1275
1276         if ((U.uiflag & USER_SHOW_GIZMO_AXIS) ||
1277             (v3d->flag2 & V3D_RENDER_OVERRIDE) ||
1278             /* No need to display gizmo and this info. */
1279             (v3d->gizmo_flag & (V3D_GIZMO_HIDE | V3D_GIZMO_HIDE_NAVIGATE)))
1280         {
1281                 /* pass */
1282         }
1283         else {
1284                 draw_view_axis(rv3d, &rect);
1285         }
1286
1287         int xoffset = rect.xmin + U.widget_unit;
1288         int yoffset = rect.ymax;
1289
1290         if ((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0 &&
1291             (v3d->overlay.flag & V3D_OVERLAY_HIDE_TEXT) == 0)
1292         {
1293                 if ((U.uiflag & USER_SHOW_FPS) && ED_screen_animation_no_scrub(wm)) {
1294                         ED_scene_draw_fps(scene, xoffset, &yoffset);
1295                 }
1296                 else if (U.uiflag & USER_SHOW_VIEWPORTNAME) {
1297                         draw_viewport_name(ar, v3d, xoffset, &yoffset);
1298                 }
1299
1300                 if (U.uiflag & USER_DRAWVIEWINFO) {
1301                         ViewLayer *view_layer = CTX_data_view_layer(C);
1302                         Object *ob = OBACT(view_layer);
1303                         draw_selected_name(scene, view_layer, ob, xoffset, &yoffset);
1304                 }
1305
1306 #if 0 /* TODO */
1307                 if (grid_unit) { /* draw below the viewport name */
1308                         char numstr[32] = "";
1309
1310                         UI_FontThemeColor(BLF_default(), TH_TEXT_HI);
1311                         if (v3d->grid != 1.0f) {
1312                                 BLI_snprintf(numstr, sizeof(numstr), "%s x %.4g", grid_unit, v3d->grid);
1313                         }
1314
1315                         *yoffset -= U.widget_unit;
1316                         BLF_draw_default_ascii(xoffset, *yoffset, numstr[0] ? numstr : grid_unit, sizeof(numstr));
1317                 }
1318 #endif
1319         }
1320
1321         if ((v3d->overlay.flag & V3D_OVERLAY_HIDE_TEXT) == 0) {
1322                 DRW_draw_region_engine_info(xoffset, yoffset);
1323         }
1324
1325         BLF_batch_draw_end();
1326 }
1327
1328 static void view3d_draw_view(const bContext *C, ARegion *ar)
1329 {
1330         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);
1331
1332         /* Only 100% compliant on new spec goes below */
1333         DRW_draw_view(C);
1334 }
1335
1336 RenderEngineType *ED_view3d_engine_type(Scene *scene, int drawtype)
1337 {
1338         /*
1339          * Temporary viewport draw modes until we have a proper system.
1340          * all modes are done in the draw manager, except
1341          * cycles material as it is an external render engine.
1342          */
1343         if (strcmp(scene->r.engine, RE_engine_id_CYCLES) == 0 && drawtype == OB_MATERIAL) {
1344                 return RE_engines_find(RE_engine_id_BLENDER_EEVEE);
1345         }
1346         return RE_engines_find(scene->r.engine);
1347 }
1348
1349 void view3d_main_region_draw(const bContext *C, ARegion *ar)
1350 {
1351         Main *bmain = CTX_data_main(C);
1352         View3D *v3d = CTX_wm_view3d(C);
1353
1354         view3d_draw_view(C, ar);
1355
1356         GPU_free_images_old(bmain);
1357         GPU_pass_cache_garbage_collect();
1358
1359         /* XXX This is in order to draw UI batches with the DRW
1360          * olg context since we now use it for drawing the entire area */
1361         gpu_batch_presets_reset();
1362
1363         /* No depth test for drawing action zones afterwards. */
1364         GPU_depth_test(false);
1365
1366         v3d->flag |= V3D_INVALID_BACKBUF;
1367 }
1368
1369 /* -------------------------------------------------------------------- */
1370 /** \name Offscreen Drawing
1371  * \{ */
1372
1373 static void view3d_stereo3d_setup_offscreen(
1374         Depsgraph *depsgraph, Scene *scene, View3D *v3d, ARegion *ar,
1375         float winmat[4][4], const char *viewname)
1376 {
1377         /* update the viewport matrices with the new camera */
1378         if (scene->r.views_format == SCE_VIEWS_FORMAT_STEREO_3D) {
1379                 float viewmat[4][4];
1380                 const bool is_left = STREQ(viewname, STEREO_LEFT_NAME);
1381
1382                 BKE_camera_multiview_view_matrix(&scene->r, v3d->camera, is_left, viewmat);
1383                 view3d_main_region_setup_view(depsgraph, scene, v3d, ar, viewmat, winmat, NULL);
1384         }
1385         else { /* SCE_VIEWS_FORMAT_MULTIVIEW */
1386                 float viewmat[4][4];
1387                 Object *camera = BKE_camera_multiview_render(scene, v3d->camera, viewname);
1388
1389                 BKE_camera_multiview_view_matrix(&scene->r, camera, false, viewmat);
1390                 view3d_main_region_setup_view(depsgraph, scene, v3d, ar, viewmat, winmat, NULL);
1391         }
1392 }
1393
1394 void ED_view3d_draw_offscreen(
1395         Depsgraph *depsgraph, Scene *scene,
1396         int drawtype,
1397         View3D *v3d, ARegion *ar, int winx, int winy,
1398         float viewmat[4][4], float winmat[4][4],
1399         bool do_sky, bool UNUSED(is_persp), const char *viewname,
1400         GPUFXSettings *UNUSED(fx_settings),
1401         GPUOffScreen *ofs, GPUViewport *viewport)
1402 {
1403         RegionView3D *rv3d = ar->regiondata;
1404         RenderEngineType *engine_type = ED_view3d_engine_type(scene, drawtype);
1405
1406         /* set temporary new size */
1407         int bwinx = ar->winx;
1408         int bwiny = ar->winy;
1409         rcti brect = ar->winrct;
1410
1411         ar->winx = winx;
1412         ar->winy = winy;
1413         ar->winrct.xmin = 0;
1414         ar->winrct.ymin = 0;
1415         ar->winrct.xmax = winx;
1416         ar->winrct.ymax = winy;
1417
1418         struct bThemeState theme_state;
1419         UI_Theme_Store(&theme_state);
1420         UI_SetTheme(SPACE_VIEW3D, RGN_TYPE_WINDOW);
1421
1422         /* set flags */
1423         G.f |= G_RENDER_OGL;
1424
1425         {
1426                 /* free images which can have changed on frame-change
1427                  * warning! can be slow so only free animated images - campbell */
1428                 GPU_free_images_anim(G.main);  /* XXX :((( */
1429         }
1430
1431         GPU_matrix_push_projection();
1432         GPU_matrix_identity_set();
1433         GPU_matrix_push();
1434         GPU_matrix_identity_set();
1435
1436         if ((viewname != NULL && viewname[0] != '\0') && (viewmat == NULL) && rv3d->persp == RV3D_CAMOB && v3d->camera)
1437                 view3d_stereo3d_setup_offscreen(depsgraph, scene, v3d, ar, winmat, viewname);
1438         else
1439                 view3d_main_region_setup_view(depsgraph, scene, v3d, ar, viewmat, winmat, NULL);
1440
1441         /* main drawing call */
1442         DRW_draw_render_loop_offscreen(
1443                 depsgraph, engine_type, ar, v3d,
1444                 do_sky, ofs, viewport);
1445
1446         /* restore size */
1447         ar->winx = bwinx;
1448         ar->winy = bwiny;
1449         ar->winrct = brect;
1450
1451         GPU_matrix_pop_projection();
1452         GPU_matrix_pop();
1453
1454         UI_Theme_Restore(&theme_state);
1455
1456         G.f &= ~G_RENDER_OGL;
1457 }
1458
1459 /**
1460  * Utility func for ED_view3d_draw_offscreen
1461  *
1462  * \param ofs: Optional off-screen buffer, can be NULL.
1463  * (avoids re-creating when doing multiple GL renders).
1464  */
1465 ImBuf *ED_view3d_draw_offscreen_imbuf(
1466         Depsgraph *depsgraph, Scene *scene,
1467         int drawtype,
1468         View3D *v3d, ARegion *ar, int sizex, int sizey,
1469         unsigned int flag, unsigned int draw_flags,
1470         int alpha_mode, int samples, const char *viewname,
1471         /* output vars */
1472         GPUOffScreen *ofs, char err_out[256])
1473 {
1474         RegionView3D *rv3d = ar->regiondata;
1475         const bool draw_sky = (alpha_mode == R_ADDSKY);
1476         const bool use_full_sample = (draw_flags & V3D_OFSDRAW_USE_FULL_SAMPLE);
1477
1478         /* view state */
1479         GPUFXSettings fx_settings = v3d->fx_settings;
1480         bool is_ortho = false;
1481         float winmat[4][4];
1482
1483         if (ofs && ((GPU_offscreen_width(ofs) != sizex) || (GPU_offscreen_height(ofs) != sizey))) {
1484                 /* sizes differ, can't reuse */
1485                 ofs = NULL;
1486         }
1487
1488         GPUFrameBuffer *old_fb = GPU_framebuffer_active_get();
1489
1490         if (old_fb)  {
1491                 GPU_framebuffer_restore();
1492         }
1493
1494         const bool own_ofs = (ofs == NULL);
1495         DRW_opengl_context_enable();
1496
1497         if (own_ofs) {
1498                 /* bind */
1499                 ofs = GPU_offscreen_create(sizex, sizey, use_full_sample ? 0 : samples, true, false, err_out);
1500                 if (ofs == NULL) {
1501                         DRW_opengl_context_disable();
1502                         return NULL;
1503                 }
1504         }
1505
1506         GPU_offscreen_bind(ofs, true);
1507
1508         /* read in pixels & stamp */
1509         ImBuf *ibuf = IMB_allocImBuf(sizex, sizey, 32, flag);
1510
1511         /* render 3d view */
1512         if (rv3d->persp == RV3D_CAMOB && v3d->camera) {
1513                 CameraParams params;
1514                 Object *camera = BKE_camera_multiview_render(scene, v3d->camera, viewname);
1515                 const Object *camera_eval = DEG_get_evaluated_object(
1516                                                 depsgraph,
1517                                                 camera);
1518
1519                 BKE_camera_params_init(&params);
1520                 /* fallback for non camera objects */
1521                 params.clipsta = v3d->near;
1522                 params.clipend = v3d->far;
1523                 BKE_camera_params_from_object(&params, camera_eval);
1524                 BKE_camera_multiview_params(&scene->r, &params, camera_eval, viewname);
1525                 BKE_camera_params_compute_viewplane(&params, sizex, sizey, scene->r.xasp, scene->r.yasp);
1526                 BKE_camera_params_compute_matrix(&params);
1527
1528                 BKE_camera_to_gpu_dof(camera, &fx_settings);
1529
1530                 is_ortho = params.is_ortho;
1531                 copy_m4_m4(winmat, params.winmat);
1532         }
1533         else {
1534                 rctf viewplane;
1535                 float clipsta, clipend;
1536
1537                 is_ortho = ED_view3d_viewplane_get(depsgraph, v3d, rv3d, sizex, sizey, &viewplane, &clipsta, &clipend, NULL);
1538                 if (is_ortho) {
1539                         orthographic_m4(winmat, viewplane.xmin, viewplane.xmax, viewplane.ymin, viewplane.ymax, -clipend, clipend);
1540                 }
1541                 else {
1542                         perspective_m4(winmat, viewplane.xmin, viewplane.xmax, viewplane.ymin, viewplane.ymax, clipsta, clipend);
1543                 }
1544         }
1545
1546         if ((samples && use_full_sample) == 0) {
1547                 /* Single-pass render, common case */
1548                 ED_view3d_draw_offscreen(
1549                         depsgraph, scene, drawtype,
1550                         v3d, ar, sizex, sizey, NULL, winmat,
1551                         draw_sky, !is_ortho, viewname,
1552                         &fx_settings, ofs, NULL);
1553
1554                 if (ibuf->rect_float) {
1555                         GPU_offscreen_read_pixels(ofs, GL_FLOAT, ibuf->rect_float);
1556                 }
1557                 else if (ibuf->rect) {
1558                         GPU_offscreen_read_pixels(ofs, GL_UNSIGNED_BYTE, ibuf->rect);
1559                 }
1560         }
1561         else {
1562                 /* Multi-pass render, use accumulation buffer & jitter for 'full' oversampling.
1563                  * Use because OpenGL may use a lower quality MSAA, and only over-sample edges. */
1564                 static float jit_ofs[32][2];
1565                 float winmat_jitter[4][4];
1566                 float *rect_temp = (ibuf->rect_float) ? ibuf->rect_float : MEM_mallocN(sizex * sizey * sizeof(float[4]), "rect_temp");
1567                 float *accum_buffer = MEM_mallocN(sizex * sizey * sizeof(float[4]), "accum_buffer");
1568                 GPUViewport *viewport = GPU_viewport_create_from_offscreen(ofs);
1569
1570                 BLI_jitter_init(jit_ofs, samples);
1571
1572                 /* first sample buffer, also initializes 'rv3d->persmat' */
1573                 ED_view3d_draw_offscreen(
1574                         depsgraph, scene, drawtype,
1575                         v3d, ar, sizex, sizey, NULL, winmat,
1576                         draw_sky, !is_ortho, viewname,
1577                         &fx_settings, ofs, viewport);
1578                 GPU_offscreen_read_pixels(ofs, GL_FLOAT, accum_buffer);
1579
1580                 /* skip the first sample */
1581                 for (int j = 1; j < samples; j++) {
1582                         copy_m4_m4(winmat_jitter, winmat);
1583                         window_translate_m4(
1584                                 winmat_jitter, rv3d->persmat,
1585                                 (jit_ofs[j][0] * 2.0f) / sizex,
1586                                 (jit_ofs[j][1] * 2.0f) / sizey);
1587
1588                         ED_view3d_draw_offscreen(
1589                                 depsgraph, scene, drawtype,
1590                                 v3d, ar, sizex, sizey, NULL, winmat_jitter,
1591                                 draw_sky, !is_ortho, viewname,
1592                                 &fx_settings, ofs, viewport);
1593                         GPU_offscreen_read_pixels(ofs, GL_FLOAT, rect_temp);
1594
1595                         unsigned int i = sizex * sizey * 4;
1596                         while (i--) {
1597                                 accum_buffer[i] += rect_temp[i];
1598                         }
1599                 }
1600
1601                 {
1602                         /* don't free data owned by 'ofs' */
1603                         GPU_viewport_clear_from_offscreen(viewport);
1604                         GPU_viewport_free(viewport);
1605                 }
1606
1607                 if (ibuf->rect_float == NULL) {
1608                         MEM_freeN(rect_temp);
1609                 }
1610
1611                 if (ibuf->rect_float) {
1612                         float *rect_float = ibuf->rect_float;
1613                         unsigned int i = sizex * sizey * 4;
1614                         while (i--) {
1615                                 rect_float[i] = accum_buffer[i] / samples;
1616                         }
1617                 }
1618                 else {
1619                         unsigned char *rect_ub = (unsigned char *)ibuf->rect;
1620                         unsigned int i = sizex * sizey * 4;
1621                         while (i--) {
1622                                 rect_ub[i] = (unsigned char)(255.0f * accum_buffer[i] / samples);
1623                         }
1624                 }
1625
1626                 MEM_freeN(accum_buffer);
1627         }
1628
1629         /* unbind */
1630         GPU_offscreen_unbind(ofs, true);
1631
1632         if (own_ofs) {
1633                 GPU_offscreen_free(ofs);
1634         }
1635
1636         DRW_opengl_context_disable();
1637
1638         if (old_fb)  {
1639                 GPU_framebuffer_bind(old_fb);
1640         }
1641
1642         if (ibuf->rect_float && ibuf->rect)
1643                 IMB_rect_from_float(ibuf);
1644
1645         return ibuf;
1646 }
1647
1648 /**
1649  * Creates own fake 3d views (wrapping #ED_view3d_draw_offscreen_imbuf)
1650  *
1651  * \param ofs: Optional off-screen buffer can be NULL.
1652  * (avoids re-creating when doing multiple GL renders).
1653  *
1654  * \note used by the sequencer
1655  */
1656 ImBuf *ED_view3d_draw_offscreen_imbuf_simple(
1657         Depsgraph *depsgraph, Scene *scene,
1658         int drawtype,
1659         Object *camera, int width, int height,
1660         unsigned int flag, unsigned int draw_flags,
1661         int alpha_mode, int samples, const char *viewname,
1662         GPUOffScreen *ofs, char err_out[256])
1663 {
1664         View3D v3d = {NULL};
1665         ARegion ar = {NULL};
1666         RegionView3D rv3d = {{{0}}};
1667
1668         /* connect data */
1669         v3d.regionbase.first = v3d.regionbase.last = &ar;
1670         ar.regiondata = &rv3d;
1671         ar.regiontype = RGN_TYPE_WINDOW;
1672
1673         v3d.camera = camera;
1674         v3d.shading.type = drawtype;
1675         v3d.flag2 = V3D_RENDER_OVERRIDE;
1676
1677         if (draw_flags & V3D_OFSDRAW_USE_GPENCIL) {
1678                 v3d.flag2 |= V3D_SHOW_ANNOTATION;
1679         }
1680
1681         v3d.shading.background_type = V3D_SHADING_BACKGROUND_WORLD;
1682
1683         if (draw_flags & V3D_OFSDRAW_USE_CAMERA_DOF) {
1684                 if (camera->type == OB_CAMERA) {
1685                         v3d.fx_settings.dof = &((Camera *)camera->data)->gpu_dof;
1686                         v3d.fx_settings.fx_flag |= GPU_FX_FLAG_DOF;
1687                 }
1688         }
1689
1690         rv3d.persp = RV3D_CAMOB;
1691
1692         copy_m4_m4(rv3d.viewinv, v3d.camera->obmat);
1693         normalize_m4(rv3d.viewinv);
1694         invert_m4_m4(rv3d.viewmat, rv3d.viewinv);
1695
1696         {
1697                 CameraParams params;
1698                 const Object *view_camera_eval = DEG_get_evaluated_object(
1699                                                      depsgraph,
1700                                                      BKE_camera_multiview_render(scene, v3d.camera, viewname));
1701
1702                 BKE_camera_params_init(&params);
1703                 BKE_camera_params_from_object(&params, view_camera_eval);
1704                 BKE_camera_multiview_params(&scene->r, &params, view_camera_eval, viewname);
1705                 BKE_camera_params_compute_viewplane(&params, width, height, scene->r.xasp, scene->r.yasp);
1706                 BKE_camera_params_compute_matrix(&params);
1707
1708                 copy_m4_m4(rv3d.winmat, params.winmat);
1709                 v3d.near = params.clipsta;
1710                 v3d.far = params.clipend;
1711                 v3d.lens = params.lens;
1712         }
1713
1714         mul_m4_m4m4(rv3d.persmat, rv3d.winmat, rv3d.viewmat);
1715         invert_m4_m4(rv3d.persinv, rv3d.viewinv);
1716
1717         return ED_view3d_draw_offscreen_imbuf(
1718                 depsgraph, scene, drawtype,
1719                 &v3d, &ar, width, height, flag,
1720                 draw_flags, alpha_mode, samples, viewname, ofs, err_out);
1721 }
1722
1723 /** \} */
1724
1725 /* -------------------------------------------------------------------- */
1726 /** \name Viewport Clipping
1727  * \{ */
1728
1729 static bool view3d_clipping_test(const float co[3], const float clip[6][4])
1730 {
1731         if (plane_point_side_v3(clip[0], co) > 0.0f)
1732                 if (plane_point_side_v3(clip[1], co) > 0.0f)
1733                         if (plane_point_side_v3(clip[2], co) > 0.0f)
1734                                 if (plane_point_side_v3(clip[3], co) > 0.0f)
1735                                         return false;
1736
1737         return true;
1738 }
1739
1740 /* for 'local' ED_view3d_clipping_local must run first
1741  * then all comparisons can be done in localspace */
1742 bool ED_view3d_clipping_test(const RegionView3D *rv3d, const float co[3], const bool is_local)
1743 {
1744         return view3d_clipping_test(co, is_local ? rv3d->clip_local : rv3d->clip);
1745 }
1746
1747
1748 /** \} */