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