Cleanup: clang-format
[blender.git] / source / blender / draw / DRW_engine.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  * Copyright 2016, Blender Foundation.
17  */
18
19 /** \file
20  * \ingroup draw
21  */
22
23 #ifndef __DRW_ENGINE_H__
24 #define __DRW_ENGINE_H__
25
26 #include "BLI_sys_types.h" /* for bool */
27
28 struct ARegion;
29 struct DRWInstanceDataList;
30 struct DRWPass;
31 struct Depsgraph;
32 struct DrawEngineType;
33 struct GPUMaterial;
34 struct GPUOffScreen;
35 struct GPUViewport;
36 struct ID;
37 struct IDProperty;
38 struct Main;
39 struct Material;
40 struct Object;
41 struct RegionView3D;
42 struct RenderEngine;
43 struct RenderEngineType;
44 struct Scene;
45 struct View3D;
46 struct ViewContext;
47 struct ViewLayer;
48 struct ViewportEngineData;
49 struct WorkSpace;
50 struct bContext;
51 struct rcti;
52
53 #include "DNA_object_enums.h"
54
55 /* Buffer and textures used by the viewport by default */
56 typedef struct DefaultFramebufferList {
57   struct GPUFrameBuffer *default_fb;
58   struct GPUFrameBuffer *color_only_fb;
59   struct GPUFrameBuffer *depth_only_fb;
60   struct GPUFrameBuffer *multisample_fb;
61 } DefaultFramebufferList;
62
63 typedef struct DefaultTextureList {
64   struct GPUTexture *color;
65   struct GPUTexture *depth;
66   struct GPUTexture *multisample_color;
67   struct GPUTexture *multisample_depth;
68 } DefaultTextureList;
69
70 void DRW_engines_register(void);
71 void DRW_engines_free(void);
72
73 bool DRW_engine_render_support(struct DrawEngineType *draw_engine_type);
74 void DRW_engine_register(struct DrawEngineType *draw_engine_type);
75 void DRW_engine_viewport_data_size_get(
76     const void *engine_type, int *r_fbl_len, int *r_txl_len, int *r_psl_len, int *r_stl_len);
77
78 typedef struct DRWUpdateContext {
79   struct Main *bmain;
80   struct Depsgraph *depsgraph;
81   struct Scene *scene;
82   struct ViewLayer *view_layer;
83   struct ARegion *ar;
84   struct View3D *v3d;
85   struct RenderEngineType *engine_type;
86 } DRWUpdateContext;
87 void DRW_notify_view_update(const DRWUpdateContext *update_ctx);
88
89 typedef enum eDRWSelectStage {
90   DRW_SELECT_PASS_PRE = 1,
91   DRW_SELECT_PASS_POST,
92 } eDRWSelectStage;
93 typedef bool (*DRW_SelectPassFn)(eDRWSelectStage stage, void *user_data);
94 typedef bool (*DRW_ObjectFilterFn)(struct Object *ob, void *user_data);
95
96 void DRW_draw_view(const struct bContext *C);
97 void DRW_draw_region_engine_info(int xoffset, int yoffset);
98
99 void DRW_draw_render_loop_ex(struct Depsgraph *depsgraph,
100                              struct RenderEngineType *engine_type,
101                              struct ARegion *ar,
102                              struct View3D *v3d,
103                              struct GPUViewport *viewport,
104                              const struct bContext *evil_C);
105 void DRW_draw_render_loop(struct Depsgraph *depsgraph,
106                           struct ARegion *ar,
107                           struct View3D *v3d,
108                           struct GPUViewport *viewport);
109 void DRW_draw_render_loop_offscreen(struct Depsgraph *depsgraph,
110                                     struct RenderEngineType *engine_type,
111                                     struct ARegion *ar,
112                                     struct View3D *v3d,
113                                     const bool draw_background,
114                                     const bool do_color_management,
115                                     struct GPUOffScreen *ofs,
116                                     struct GPUViewport *viewport);
117 void DRW_draw_select_loop(struct Depsgraph *depsgraph,
118                           struct ARegion *ar,
119                           struct View3D *v3d,
120                           bool use_obedit_skip,
121                           bool draw_surface,
122                           bool use_nearest,
123                           const struct rcti *rect,
124                           DRW_SelectPassFn select_pass_fn,
125                           void *select_pass_user_data,
126                           DRW_ObjectFilterFn object_filter_fn,
127                           void *object_filter_user_data);
128 void DRW_draw_depth_loop(struct Depsgraph *depsgraph,
129                          struct ARegion *ar,
130                          struct View3D *v3d,
131                          struct GPUViewport *viewport);
132 void DRW_draw_depth_loop_gpencil(struct Depsgraph *depsgraph,
133                                  struct ARegion *ar,
134                                  struct View3D *v3d,
135                                  struct GPUViewport *viewport);
136 void DRW_draw_depth_object(struct ARegion *ar,
137                            struct GPUViewport *viewport,
138                            struct Object *object);
139 void DRW_draw_select_id_object(struct Scene *scene,
140                                struct RegionView3D *rv3d,
141                                struct Object *ob,
142                                short select_mode,
143                                bool draw_facedot,
144                                uint initial_offset,
145                                uint *r_vert_offset,
146                                uint *r_edge_offset,
147                                uint *r_face_offset);
148
149 void DRW_framebuffer_select_id_setup(struct ARegion *ar, const bool clear);
150 void DRW_framebuffer_select_id_release(struct ARegion *ar);
151 void DRW_framebuffer_select_id_read(const struct rcti *rect, uint *r_buf);
152
153 /* grease pencil render */
154 bool DRW_render_check_grease_pencil(struct Depsgraph *depsgraph);
155 void DRW_render_gpencil(struct RenderEngine *engine, struct Depsgraph *depsgraph);
156 void DRW_gpencil_freecache(struct Object *ob);
157
158 /* This is here because GPUViewport needs it */
159 struct DRWInstanceDataList *DRW_instance_data_list_create(void);
160 void DRW_instance_data_list_free(struct DRWInstanceDataList *idatalist);
161
162 void DRW_opengl_context_create(void);
163 void DRW_opengl_context_destroy(void);
164 void DRW_opengl_context_enable(void);
165 void DRW_opengl_context_disable(void);
166
167 /* For garbage collection */
168 void DRW_cache_free_old_batches(struct Main *bmain);
169
170 /* Never use this. Only for closing blender. */
171 void DRW_opengl_context_enable_ex(bool restore);
172 void DRW_opengl_context_disable_ex(bool restore);
173
174 void DRW_opengl_render_context_enable(void *re_gl_context);
175 void DRW_opengl_render_context_disable(void *re_gl_context);
176 void DRW_gawain_render_context_enable(void *re_gpu_context);
177 void DRW_gawain_render_context_disable(void *re_gpu_context);
178
179 void DRW_deferred_shader_remove(struct GPUMaterial *mat);
180
181 struct DrawDataList *DRW_drawdatalist_from_id(struct ID *id);
182 void DRW_drawdata_free(struct ID *id);
183
184 #endif /* __DRW_ENGINE_H__ */