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