055bd3643b637ceac4bf1bb7d0aa9fedf9288647
[blender.git] / source / blender / editors / include / ED_view3d.h
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2008 Blender Foundation.
17  * All rights reserved.
18  */
19
20 /** \file
21  * \ingroup editors
22  */
23
24 #ifndef __ED_VIEW3D_H__
25 #define __ED_VIEW3D_H__
26
27 /* ********* exports for space_view3d/ module ********** */
28 struct ARegion;
29 struct BMEdge;
30 struct BMElem;
31 struct BMFace;
32 struct BMVert;
33 struct BPoint;
34 struct Base;
35 struct BezTriple;
36 struct BoundBox;
37 struct Camera;
38 struct CustomData_MeshMasks;
39 struct Depsgraph;
40 struct EditBone;
41 struct GPUFX;
42 struct GPUFXSettings;
43 struct GPUOffScreen;
44 struct GPUViewport;
45 struct ID;
46 struct ImBuf;
47 struct MVert;
48 struct Main;
49 struct MetaElem;
50 struct Nurb;
51 struct Object;
52 struct RV3DMatrixStore;
53 struct RegionView3D;
54 struct RenderEngineType;
55 struct Scene;
56 struct ScrArea;
57 struct View3D;
58 struct View3DShading;
59 struct ViewContext;
60 struct ViewLayer;
61 struct WorkSpace;
62 struct bContext;
63 struct bPoseChannel;
64 struct bScreen;
65 struct rctf;
66 struct rcti;
67 struct wmGizmo;
68 struct wmOperator;
69 struct wmOperatorType;
70 struct wmWindow;
71 struct wmWindowManager;
72
73 enum eGPUFXFlags;
74
75 /* for derivedmesh drawing callbacks, for view3d_select, .... */
76 typedef struct ViewContext {
77   struct bContext *C;
78   struct Main *bmain;
79   struct Depsgraph *depsgraph;
80   struct Scene *scene;
81   struct ViewLayer *view_layer;
82   struct Object *obact;
83   struct Object *obedit;
84   struct ARegion *ar;
85   struct View3D *v3d;
86   struct wmWindow *win;
87   struct RegionView3D *rv3d;
88   struct BMEditMesh *em;
89   int mval[2];
90 } ViewContext;
91
92 typedef struct ViewDepths {
93   unsigned short w, h;
94   short x, y; /* only for temp use for sub-rects, added to ar->winx/y */
95   float *depths;
96   double depth_range[2];
97
98   bool damaged;
99 } ViewDepths;
100
101 /* Rotate 3D cursor on placement. */
102 enum eV3DCursorOrient {
103   V3D_CURSOR_ORIENT_NONE = 0,
104   V3D_CURSOR_ORIENT_VIEW,
105   V3D_CURSOR_ORIENT_XFORM,
106   V3D_CURSOR_ORIENT_GEOM,
107 };
108
109 void ED_view3d_background_color_get(const struct Scene *scene,
110                                     const struct View3D *v3d,
111                                     float r_color[3]);
112 void ED_view3d_cursor3d_position(struct bContext *C,
113                                  const int mval[2],
114                                  const bool use_depth,
115                                  float cursor_co[3]);
116 void ED_view3d_cursor3d_position_rotation(struct bContext *C,
117                                           const int mval[2],
118                                           const bool use_depth,
119                                           enum eV3DCursorOrient orientation,
120                                           float cursor_co[3],
121                                           float cursor_quat[4]);
122 void ED_view3d_cursor3d_update(struct bContext *C,
123                                const int mval[2],
124                                const bool use_depth,
125                                enum eV3DCursorOrient orientation);
126
127 struct Camera *ED_view3d_camera_data_get(struct View3D *v3d, struct RegionView3D *rv3d);
128
129 void ED_view3d_to_m4(float mat[4][4], const float ofs[3], const float quat[4], const float dist);
130 void ED_view3d_from_m4(const float mat[4][4], float ofs[3], float quat[4], float *dist);
131
132 void ED_view3d_from_object(
133     const struct Object *ob, float ofs[3], float quat[4], float *dist, float *lens);
134 void ED_view3d_to_object(const struct Depsgraph *depsgraph,
135                          struct Object *ob,
136                          const float ofs[3],
137                          const float quat[4],
138                          const float dist);
139
140 void ED_view3d_lastview_store(struct RegionView3D *rv3d);
141
142 /* Depth buffer */
143 void ED_view3d_depth_update(struct ARegion *ar);
144 float ED_view3d_depth_read_cached(const struct ViewContext *vc, const int mval[2]);
145 bool ED_view3d_depth_read_cached_normal(const ViewContext *vc,
146                                         const int mval[2],
147                                         float r_normal[3]);
148 bool ED_view3d_depth_unproject(const struct ARegion *ar,
149                                const int mval[2],
150                                const double depth,
151                                float r_location_world[3]);
152 void ED_view3d_depth_tag_update(struct RegionView3D *rv3d);
153
154 /* Projection */
155 #define IS_CLIPPED 12000
156
157 /* return values for ED_view3d_project_...() */
158 typedef enum {
159   V3D_PROJ_RET_OK = 0,
160   /** can't avoid this when in perspective mode, (can't avoid) */
161   V3D_PROJ_RET_CLIP_NEAR = 1,
162   /** so close to zero we can't apply a perspective matrix usefully */
163   V3D_PROJ_RET_CLIP_ZERO = 2,
164   /** bounding box clip - RV3D_CLIPPING */
165   V3D_PROJ_RET_CLIP_BB = 3,
166   /** outside window bounds */
167   V3D_PROJ_RET_CLIP_WIN = 4,
168   /** outside range (mainly for short), (can't avoid) */
169   V3D_PROJ_RET_OVERFLOW = 5,
170 } eV3DProjStatus;
171
172 /* some clipping tests are optional */
173 typedef enum {
174   V3D_PROJ_TEST_NOP = 0,
175   V3D_PROJ_TEST_CLIP_BB = (1 << 0),
176   V3D_PROJ_TEST_CLIP_WIN = (1 << 1),
177   V3D_PROJ_TEST_CLIP_NEAR = (1 << 2),
178   V3D_PROJ_TEST_CLIP_ZERO = (1 << 3),
179 } eV3DProjTest;
180
181 #define V3D_PROJ_TEST_CLIP_DEFAULT \
182   (V3D_PROJ_TEST_CLIP_BB | V3D_PROJ_TEST_CLIP_WIN | V3D_PROJ_TEST_CLIP_NEAR)
183 #define V3D_PROJ_TEST_ALL \
184   (V3D_PROJ_TEST_CLIP_BB | V3D_PROJ_TEST_CLIP_WIN | V3D_PROJ_TEST_CLIP_NEAR | \
185    V3D_PROJ_TEST_CLIP_ZERO)
186
187 /* view3d_iterators.c */
188
189 /* foreach iterators */
190 void meshobject_foreachScreenVert(
191     struct ViewContext *vc,
192     void (*func)(void *userData, struct MVert *eve, const float screen_co[2], int index),
193     void *userData,
194     const eV3DProjTest clip_flag);
195 void mesh_foreachScreenVert(
196     struct ViewContext *vc,
197     void (*func)(void *userData, struct BMVert *eve, const float screen_co[2], int index),
198     void *userData,
199     const eV3DProjTest clip_flag);
200 void mesh_foreachScreenEdge(struct ViewContext *vc,
201                             void (*func)(void *userData,
202                                          struct BMEdge *eed,
203                                          const float screen_co_a[2],
204                                          const float screen_co_b[2],
205                                          int index),
206                             void *userData,
207                             const eV3DProjTest clip_flag);
208 void mesh_foreachScreenFace(
209     struct ViewContext *vc,
210     void (*func)(void *userData, struct BMFace *efa, const float screen_co[2], int index),
211     void *userData,
212     const eV3DProjTest clip_flag);
213 void nurbs_foreachScreenVert(struct ViewContext *vc,
214                              void (*func)(void *userData,
215                                           struct Nurb *nu,
216                                           struct BPoint *bp,
217                                           struct BezTriple *bezt,
218                                           int beztindex,
219                                           const float screen_co[2]),
220                              void *userData,
221                              const eV3DProjTest clip_flag);
222 void mball_foreachScreenElem(struct ViewContext *vc,
223                              void (*func)(void *userData,
224                                           struct MetaElem *ml,
225                                           const float screen_co[2]),
226                              void *userData,
227                              const eV3DProjTest clip_flag);
228 void lattice_foreachScreenVert(struct ViewContext *vc,
229                                void (*func)(void *userData,
230                                             struct BPoint *bp,
231                                             const float screen_co[2]),
232                                void *userData,
233                                const eV3DProjTest clip_flag);
234 void armature_foreachScreenBone(struct ViewContext *vc,
235                                 void (*func)(void *userData,
236                                              struct EditBone *ebone,
237                                              const float screen_co_a[2],
238                                              const float screen_co_b[2]),
239                                 void *userData,
240                                 const eV3DProjTest clip_flag);
241 void pose_foreachScreenBone(struct ViewContext *vc,
242                             void (*func)(void *userData,
243                                          struct bPoseChannel *pchan,
244                                          const float screen_co_a[2],
245                                          const float screen_co_b[2]),
246                             void *userData,
247                             const eV3DProjTest clip_flag);
248 /* *** end iterators *** */
249
250 /* view3d_project.c */
251 void ED_view3d_project_float_v2_m4(const struct ARegion *ar,
252                                    const float co[3],
253                                    float r_co[2],
254                                    float mat[4][4]);
255 void ED_view3d_project_float_v3_m4(const struct ARegion *ar,
256                                    const float co[3],
257                                    float r_co[3],
258                                    float mat[4][4]);
259
260 eV3DProjStatus ED_view3d_project_base(const struct ARegion *ar, struct Base *base);
261
262 /* *** short *** */
263 eV3DProjStatus ED_view3d_project_short_ex(const struct ARegion *ar,
264                                           float perspmat[4][4],
265                                           const bool is_local,
266                                           const float co[3],
267                                           short r_co[2],
268                                           const eV3DProjTest flag);
269 eV3DProjStatus ED_view3d_project_short_global(const struct ARegion *ar,
270                                               const float co[3],
271                                               short r_co[2],
272                                               const eV3DProjTest flag);
273 eV3DProjStatus ED_view3d_project_short_object(const struct ARegion *ar,
274                                               const float co[3],
275                                               short r_co[2],
276                                               const eV3DProjTest flag);
277
278 /* *** int *** */
279 eV3DProjStatus ED_view3d_project_int_ex(const struct ARegion *ar,
280                                         float perspmat[4][4],
281                                         const bool is_local,
282                                         const float co[3],
283                                         int r_co[2],
284                                         const eV3DProjTest flag);
285 eV3DProjStatus ED_view3d_project_int_global(const struct ARegion *ar,
286                                             const float co[3],
287                                             int r_co[2],
288                                             const eV3DProjTest flag);
289 eV3DProjStatus ED_view3d_project_int_object(const struct ARegion *ar,
290                                             const float co[3],
291                                             int r_co[2],
292                                             const eV3DProjTest flag);
293
294 /* *** float *** */
295 eV3DProjStatus ED_view3d_project_float_ex(const struct ARegion *ar,
296                                           float perspmat[4][4],
297                                           const bool is_local,
298                                           const float co[3],
299                                           float r_co[2],
300                                           const eV3DProjTest flag);
301 eV3DProjStatus ED_view3d_project_float_global(const struct ARegion *ar,
302                                               const float co[3],
303                                               float r_co[2],
304                                               const eV3DProjTest flag);
305 eV3DProjStatus ED_view3d_project_float_object(const struct ARegion *ar,
306                                               const float co[3],
307                                               float r_co[2],
308                                               const eV3DProjTest flag);
309
310 float ED_view3d_pixel_size(const struct RegionView3D *rv3d, const float co[3]);
311 float ED_view3d_pixel_size_no_ui_scale(const struct RegionView3D *rv3d, const float co[3]);
312
313 float ED_view3d_calc_zfac(const struct RegionView3D *rv3d, const float co[3], bool *r_flip);
314 bool ED_view3d_clip_segment(const struct RegionView3D *rv3d, float ray_start[3], float ray_end[3]);
315 bool ED_view3d_win_to_ray_clipped(struct Depsgraph *depsgraph,
316                                   const struct ARegion *ar,
317                                   const struct View3D *v3d,
318                                   const float mval[2],
319                                   float ray_start[3],
320                                   float ray_normal[3],
321                                   const bool do_clip);
322 bool ED_view3d_win_to_ray_clipped_ex(struct Depsgraph *depsgraph,
323                                      const struct ARegion *ar,
324                                      const struct View3D *v3d,
325                                      const float mval[2],
326                                      float r_ray_co[3],
327                                      float r_ray_normal[3],
328                                      float r_ray_start[3],
329                                      bool do_clip);
330 void ED_view3d_win_to_ray(const struct ARegion *ar,
331                           const float mval[2],
332                           float r_ray_start[3],
333                           float r_ray_normal[3]);
334 void ED_view3d_global_to_vector(const struct RegionView3D *rv3d,
335                                 const float coord[3],
336                                 float vec[3]);
337 void ED_view3d_win_to_3d(const struct View3D *v3d,
338                          const struct ARegion *ar,
339                          const float depth_pt[3],
340                          const float mval[2],
341                          float r_out[3]);
342 void ED_view3d_win_to_3d_int(const struct View3D *v3d,
343                              const struct ARegion *ar,
344                              const float depth_pt[3],
345                              const int mval[2],
346                              float r_out[3]);
347 bool ED_view3d_win_to_3d_on_plane(const struct ARegion *ar,
348                                   const float plane[4],
349                                   const float mval[2],
350                                   const bool do_clip,
351                                   float r_out[3]);
352 bool ED_view3d_win_to_3d_on_plane_int(const struct ARegion *ar,
353                                       const float plane[4],
354                                       const int mval[2],
355                                       const bool do_clip,
356                                       float r_out[3]);
357 void ED_view3d_win_to_delta(const struct ARegion *ar,
358                             const float mval[2],
359                             float out[3],
360                             const float zfac);
361 void ED_view3d_win_to_origin(const struct ARegion *ar, const float mval[2], float out[3]);
362 void ED_view3d_win_to_vector(const struct ARegion *ar, const float mval[2], float out[3]);
363 bool ED_view3d_win_to_segment_clipped(struct Depsgraph *depsgraph,
364                                       const struct ARegion *ar,
365                                       struct View3D *v3d,
366                                       const float mval[2],
367                                       float r_ray_start[3],
368                                       float r_ray_end[3],
369                                       const bool do_clip);
370 void ED_view3d_ob_project_mat_get(const struct RegionView3D *v3d,
371                                   struct Object *ob,
372                                   float pmat[4][4]);
373 void ED_view3d_ob_project_mat_get_from_obmat(const struct RegionView3D *rv3d,
374                                              float obmat[4][4],
375                                              float pmat[4][4]);
376
377 void ED_view3d_project(const struct ARegion *ar, const float world[3], float region[3]);
378 bool ED_view3d_unproject(
379     const struct ARegion *ar, float regionx, float regiony, float regionz, float world[3]);
380
381 /* end */
382
383 void ED_view3d_dist_range_get(const struct View3D *v3d, float r_dist_range[2]);
384 bool ED_view3d_clip_range_get(struct Depsgraph *depsgraph,
385                               const struct View3D *v3d,
386                               const struct RegionView3D *rv3d,
387                               float *r_clipsta,
388                               float *r_clipend,
389                               const bool use_ortho_factor);
390 bool ED_view3d_viewplane_get(struct Depsgraph *depsgraph,
391                              const struct View3D *v3d,
392                              const struct RegionView3D *rv3d,
393                              int winxi,
394                              int winyi,
395                              struct rctf *r_viewplane,
396                              float *r_clipsta,
397                              float *r_clipend,
398                              float *r_pixsize);
399
400 void ED_view3d_polygon_offset(const struct RegionView3D *rv3d, const float dist);
401
402 void ED_view3d_calc_camera_border(const struct Scene *scene,
403                                   struct Depsgraph *depsgraph,
404                                   const struct ARegion *ar,
405                                   const struct View3D *v3d,
406                                   const struct RegionView3D *rv3d,
407                                   struct rctf *r_viewborder,
408                                   const bool no_shift);
409 void ED_view3d_calc_camera_border_size(const struct Scene *scene,
410                                        struct Depsgraph *depsgraph,
411                                        const struct ARegion *ar,
412                                        const struct View3D *v3d,
413                                        const struct RegionView3D *rv3d,
414                                        float r_size[2]);
415 bool ED_view3d_calc_render_border(const struct Scene *scene,
416                                   struct Depsgraph *depsgraph,
417                                   struct View3D *v3d,
418                                   struct ARegion *ar,
419                                   struct rcti *rect);
420
421 void ED_view3d_clipping_calc_from_boundbox(float clip[6][4],
422                                            const struct BoundBox *clipbb,
423                                            const bool is_flip);
424 void ED_view3d_clipping_calc(struct BoundBox *bb,
425                              float planes[4][4],
426                              const struct ARegion *ar,
427                              const struct Object *ob,
428                              const struct rcti *rect);
429 void ED_view3d_clipping_local(struct RegionView3D *rv3d, float mat[4][4]);
430 bool ED_view3d_clipping_test(const struct RegionView3D *rv3d,
431                              const float co[3],
432                              const bool is_local);
433 void ED_view3d_clipping_set(struct RegionView3D *rv3d);
434 void ED_view3d_clipping_enable(void);
435 void ED_view3d_clipping_disable(void);
436
437 float ED_view3d_radius_to_dist_persp(const float angle, const float radius);
438 float ED_view3d_radius_to_dist_ortho(const float lens, const float radius);
439 float ED_view3d_radius_to_dist(const struct View3D *v3d,
440                                const struct ARegion *ar,
441                                const struct Depsgraph *depsgraph,
442                                const char persp,
443                                const bool use_aspect,
444                                const float radius);
445
446 void imm_drawcircball(const float cent[3], float rad, const float tmat[4][4], unsigned pos);
447
448 /* backbuffer select and draw support */
449 void ED_view3d_backbuf_depth_validate(struct ViewContext *vc);
450 int ED_view3d_backbuf_sample_size_clamp(struct ARegion *ar, const float dist);
451
452 void ED_view3d_select_id_validate(struct ViewContext *vc);
453
454 uint *ED_view3d_select_id_read(int xmin, int ymin, int xmax, int ymax, uint *r_buf_len);
455 uint *ED_view3d_select_id_read_rect(const struct rcti *rect, uint *r_buf_len);
456
457 bool ED_view3d_autodist(struct Depsgraph *depsgraph,
458                         struct ARegion *ar,
459                         struct View3D *v3d,
460                         const int mval[2],
461                         float mouse_worldloc[3],
462                         const bool alphaoverride,
463                         const float fallback_depth_pt[3]);
464
465 /* only draw so ED_view3d_autodist_simple can be called many times after */
466 void ED_view3d_autodist_init(struct Depsgraph *depsgraph,
467                              struct ARegion *ar,
468                              struct View3D *v3d,
469                              int mode);
470 bool ED_view3d_autodist_simple(struct ARegion *ar,
471                                const int mval[2],
472                                float mouse_worldloc[3],
473                                int margin,
474                                float *force_depth);
475 bool ED_view3d_autodist_depth(struct ARegion *ar, const int mval[2], int margin, float *depth);
476 bool ED_view3d_autodist_depth_seg(
477     struct ARegion *ar, const int mval_sta[2], const int mval_end[2], int margin, float *depth);
478
479 /* select */
480 #define MAXPICKELEMS 2500
481 #define MAXPICKBUF (4 * MAXPICKELEMS)
482
483 typedef enum {
484   /* all elements in the region, ignore depth */
485   VIEW3D_SELECT_ALL = 0,
486   /* pick also depth sorts (only for small regions!) */
487   VIEW3D_SELECT_PICK_ALL = 1,
488   /* sorts and only returns visible objects (only for small regions!) */
489   VIEW3D_SELECT_PICK_NEAREST = 2,
490 } eV3DSelectMode;
491
492 typedef enum {
493   /** Don't exclude anything. */
494   VIEW3D_SELECT_FILTER_NOP = 0,
495   /** Don't select objects outside the current mode. */
496   VIEW3D_SELECT_FILTER_OBJECT_MODE_LOCK = 1,
497   /** A version of #VIEW3D_SELECT_FILTER_OBJECT_MODE_LOCK that allows pose-bone selection. */
498   VIEW3D_SELECT_FILTER_WPAINT_POSE_MODE_LOCK = 2,
499 } eV3DSelectObjectFilter;
500
501 eV3DSelectObjectFilter ED_view3d_select_filter_from_mode(const struct Scene *scene,
502                                                          const struct Object *obact);
503
504 void view3d_opengl_select_cache_begin(void);
505 void view3d_opengl_select_cache_end(void);
506
507 int view3d_opengl_select(struct ViewContext *vc,
508                          unsigned int *buffer,
509                          unsigned int bufsize,
510                          const struct rcti *input,
511                          eV3DSelectMode select_mode,
512                          eV3DSelectObjectFilter select_filter);
513
514 /* view3d_select.c */
515 float ED_view3d_select_dist_px(void);
516 void ED_view3d_viewcontext_init(struct bContext *C, struct ViewContext *vc);
517 void ED_view3d_viewcontext_init_object(struct ViewContext *vc, struct Object *obact);
518 void view3d_operator_needs_opengl(const struct bContext *C);
519 void view3d_region_operator_needs_opengl(struct wmWindow *win, struct ARegion *ar);
520
521 /* XXX should move to BLI_math */
522 bool edge_inside_circle(const float cent[2],
523                         float radius,
524                         const float screen_co_a[2],
525                         const float screen_co_b[2]);
526
527 /* get 3d region from context, also if mouse is in header or toolbar */
528 struct RegionView3D *ED_view3d_context_rv3d(struct bContext *C);
529 bool ED_view3d_context_user_region(struct bContext *C,
530                                    struct View3D **r_v3d,
531                                    struct ARegion **r_ar);
532 bool ED_operator_rv3d_user_region_poll(struct bContext *C);
533
534 void ED_view3d_init_mats_rv3d(struct Object *ob, struct RegionView3D *rv3d);
535 void ED_view3d_init_mats_rv3d_gl(struct Object *ob, struct RegionView3D *rv3d);
536 #ifdef DEBUG
537 void ED_view3d_clear_mats_rv3d(struct RegionView3D *rv3d);
538 void ED_view3d_check_mats_rv3d(struct RegionView3D *rv3d);
539 #else
540 #  define ED_view3d_clear_mats_rv3d(rv3d) (void)(rv3d)
541 #  define ED_view3d_check_mats_rv3d(rv3d) (void)(rv3d)
542 #endif
543
544 struct RV3DMatrixStore *ED_view3d_mats_rv3d_backup(struct RegionView3D *rv3d);
545 void ED_view3d_mats_rv3d_restore(struct RegionView3D *rv3d, struct RV3DMatrixStore *rv3dmat);
546
547 void ED_draw_object_facemap(struct Depsgraph *depsgraph,
548                             struct Object *ob,
549                             const float col[4],
550                             const int facemap);
551
552 struct RenderEngineType *ED_view3d_engine_type(struct Scene *scene, int drawtype);
553
554 bool ED_view3d_context_activate(struct bContext *C);
555 void ED_view3d_draw_offscreen(struct Depsgraph *depsgraph,
556                               struct Scene *scene,
557                               int drawtype,
558                               struct View3D *v3d,
559                               struct ARegion *ar,
560                               int winx,
561                               int winy,
562                               float viewmat[4][4],
563                               float winmat[4][4],
564                               bool do_sky,
565                               bool is_persp,
566                               const char *viewname,
567                               const bool do_color_managment,
568                               struct GPUOffScreen *ofs,
569                               struct GPUViewport *viewport);
570 void ED_view3d_draw_setup_view(struct wmWindow *win,
571                                struct Depsgraph *depsgraph,
572                                struct Scene *scene,
573                                struct ARegion *ar,
574                                struct View3D *v3d,
575                                float viewmat[4][4],
576                                float winmat[4][4],
577                                const struct rcti *rect);
578
579 struct ImBuf *ED_view3d_draw_offscreen_imbuf(struct Depsgraph *depsgraph,
580                                              struct Scene *scene,
581                                              int drawtype,
582                                              struct View3D *v3d,
583                                              struct ARegion *ar,
584                                              int sizex,
585                                              int sizey,
586                                              unsigned int flag,
587                                              unsigned int draw_flags,
588                                              int alpha_mode,
589                                              int samples,
590                                              const char *viewname,
591                                              struct GPUOffScreen *ofs,
592                                              char err_out[256]);
593 struct ImBuf *ED_view3d_draw_offscreen_imbuf_simple(struct Depsgraph *depsgraph,
594                                                     struct Scene *scene,
595                                                     struct View3DShading *shading_override,
596                                                     int drawtype,
597                                                     struct Object *camera,
598                                                     int width,
599                                                     int height,
600                                                     unsigned int flag,
601                                                     unsigned int draw_flags,
602                                                     int alpha_mode,
603                                                     int samples,
604                                                     const char *viewname,
605                                                     struct GPUOffScreen *ofs,
606                                                     char err_out[256]);
607
608 struct Base *ED_view3d_give_base_under_cursor(struct bContext *C, const int mval[2]);
609 struct Object *ED_view3d_give_object_under_cursor(struct bContext *C, const int mval[2]);
610 bool ED_view3d_is_object_under_cursor(struct bContext *C, const int mval[2]);
611 void ED_view3d_quadview_update(struct ScrArea *sa, struct ARegion *ar, bool do_clip);
612 void ED_view3d_update_viewmat(struct Depsgraph *depsgraph,
613                               struct Scene *scene,
614                               struct View3D *v3d,
615                               struct ARegion *ar,
616                               float viewmat[4][4],
617                               float winmat[4][4],
618                               const struct rcti *rect,
619                               bool offscreen);
620 bool ED_view3d_quat_from_axis_view(const char view, float quat[4]);
621 char ED_view3d_quat_to_axis_view(const float quat[4], const float epsilon);
622 char ED_view3d_lock_view_from_index(int index);
623 char ED_view3d_axis_view_opposite(char view);
624 bool ED_view3d_lock(struct RegionView3D *rv3d);
625
626 void ED_view3d_datamask(const struct bContext *C,
627                         const struct Scene *scene,
628                         const struct View3D *v3d,
629                         struct CustomData_MeshMasks *r_cddata_masks);
630 void ED_view3d_screen_datamask(const struct bContext *C,
631                                const struct Scene *scene,
632                                const struct bScreen *screen,
633                                struct CustomData_MeshMasks *r_cddata_masks);
634
635 bool ED_view3d_offset_lock_check(const struct View3D *v3d, const struct RegionView3D *rv3d);
636 void ED_view3d_persp_switch_from_camera(const struct Depsgraph *depsgraph,
637                                         struct View3D *v3d,
638                                         struct RegionView3D *rv3d,
639                                         const char persp);
640 bool ED_view3d_persp_ensure(const struct Depsgraph *depsgraph,
641                             struct View3D *v3d,
642                             struct ARegion *ar);
643
644 /* camera lock functions */
645 bool ED_view3d_camera_lock_check(const struct View3D *v3d, const struct RegionView3D *rv3d);
646 /* copy the camera to the view before starting a view transformation */
647 void ED_view3d_camera_lock_init_ex(const struct Depsgraph *depsgraph,
648                                    struct View3D *v3d,
649                                    struct RegionView3D *rv3d,
650                                    const bool calc_dist);
651 void ED_view3d_camera_lock_init(const struct Depsgraph *depsgraph,
652                                 struct View3D *v3d,
653                                 struct RegionView3D *rv3d);
654 /* copy the view to the camera, return true if */
655 bool ED_view3d_camera_lock_sync(const struct Depsgraph *depsgraph,
656                                 struct View3D *v3d,
657                                 struct RegionView3D *rv3d);
658
659 bool ED_view3d_camera_autokey(struct Scene *scene,
660                               struct ID *id_key,
661                               struct bContext *C,
662                               const bool do_rotate,
663                               const bool do_translate);
664 bool ED_view3d_camera_lock_autokey(struct View3D *v3d,
665                                    struct RegionView3D *rv3d,
666                                    struct bContext *C,
667                                    const bool do_rotate,
668                                    const bool do_translate);
669
670 void ED_view3d_lock_clear(struct View3D *v3d);
671
672 #define VIEW3D_MARGIN 1.4f
673 #define VIEW3D_DIST_FALLBACK 1.0f
674
675 float ED_view3d_offset_distance(float mat[4][4], const float ofs[3], const float dist_fallback);
676 void ED_view3d_distance_set(struct RegionView3D *rv3d, const float dist);
677
678 float ED_scene_grid_scale(struct Scene *scene, const char **grid_unit);
679 float ED_view3d_grid_scale(struct Scene *scene, struct View3D *v3d, const char **grid_unit);
680 float ED_view3d_grid_view_scale(struct Scene *scene,
681                                 struct View3D *v3d,
682                                 struct RegionView3D *rv3d,
683                                 const char **grid_unit);
684
685 void ED_scene_draw_fps(struct Scene *scene, int xoffset, int *yoffset);
686
687 /* view matrix properties utilities */
688 /* unused */
689 #if 0
690 void ED_view3d_operator_properties_viewmat(struct wmOperatorType *ot);
691 void ED_view3d_operator_properties_viewmat_set(struct bContext *C, struct wmOperator *op);
692 void ED_view3d_operator_properties_viewmat_get(struct wmOperator *op,
693                                                int *winx,
694                                                int *winy,
695                                                float persmat[4][4]);
696 #endif
697
698 /* render */
699 void ED_view3d_stop_render_preview(struct wmWindowManager *wm, struct ARegion *ar);
700 void ED_view3d_shade_update(struct Main *bmain, struct View3D *v3d, struct ScrArea *sa);
701
702 #define XRAY_ALPHA(v3d) \
703   (((v3d)->shading.type == OB_WIRE) ? (v3d)->shading.xray_alpha_wire : (v3d)->shading.xray_alpha)
704 #define XRAY_FLAG(v3d) \
705   (((v3d)->shading.type == OB_WIRE) ? V3D_SHADING_XRAY_BONE : V3D_SHADING_XRAY)
706 #define XRAY_FLAG_ENABLED(v3d) (((v3d)->shading.flag & XRAY_FLAG(v3d)) != 0)
707 #define XRAY_ENABLED(v3d) (XRAY_FLAG_ENABLED(v3d) && (XRAY_ALPHA(v3d) < 1.0f))
708 #define XRAY_ACTIVE(v3d) (XRAY_ENABLED(v3d) && ((v3d)->shading.type < OB_MATERIAL))
709
710 /* view3d_draw_legacy.c */
711 /* Try avoid using these more move out of legacy. */
712 void ED_view3d_draw_bgpic_test(struct Scene *scene,
713                                struct Depsgraph *depsgraph,
714                                struct ARegion *ar,
715                                struct View3D *v3d,
716                                const bool do_foreground,
717                                const bool do_camera_frame);
718
719 /* view3d_gizmo_preselect_type.c */
720 void ED_view3d_gizmo_mesh_preselect_get_active(struct bContext *C,
721                                                struct wmGizmo *gz,
722                                                struct Base **r_base,
723                                                struct BMElem **r_ele);
724
725 /* space_view3d.c */
726 void ED_view3d_buttons_region_layout_ex(const struct bContext *C,
727                                         struct ARegion *ar,
728                                         const char *category_override);
729
730 #endif /* __ED_VIEW3D_H__ */