Audaspace: port bugfix from upstream.
[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 #pragma once
24
25 #include "BLI_sys_types.h" /* for bool */
26
27 #include "DNA_object_enums.h"
28
29 #include "DRW_engine_types.h"
30
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34
35 struct ARegion;
36 struct DRWInstanceDataList;
37 struct Depsgraph;
38 struct DrawEngineType;
39 struct GHash;
40 struct GPUMaterial;
41 struct GPUOffScreen;
42 struct GPUViewport;
43 struct ID;
44 struct Main;
45 struct Object;
46 struct Render;
47 struct RenderEngine;
48 struct RenderEngineType;
49 struct Scene;
50 struct View3D;
51 struct ViewLayer;
52 struct bContext;
53 struct rcti;
54
55 void DRW_engines_register(void);
56 void DRW_engines_free(void);
57
58 bool DRW_engine_render_support(struct DrawEngineType *draw_engine_type);
59 void DRW_engine_register(struct DrawEngineType *draw_engine_type);
60 void DRW_engine_viewport_data_size_get(
61     const void *engine_type, int *r_fbl_len, int *r_txl_len, int *r_psl_len, int *r_stl_len);
62
63 typedef struct DRWUpdateContext {
64   struct Main *bmain;
65   struct Depsgraph *depsgraph;
66   struct Scene *scene;
67   struct ViewLayer *view_layer;
68   struct ARegion *region;
69   struct View3D *v3d;
70   struct RenderEngineType *engine_type;
71 } DRWUpdateContext;
72 void DRW_notify_view_update(const DRWUpdateContext *update_ctx);
73
74 typedef enum eDRWSelectStage {
75   DRW_SELECT_PASS_PRE = 1,
76   DRW_SELECT_PASS_POST,
77 } eDRWSelectStage;
78 typedef bool (*DRW_SelectPassFn)(eDRWSelectStage stage, void *user_data);
79 typedef bool (*DRW_ObjectFilterFn)(struct Object *ob, void *user_data);
80
81 void DRW_draw_view(const struct bContext *C);
82 void DRW_draw_region_engine_info(int xoffset, int *yoffset, int line_height);
83
84 void DRW_draw_render_loop_ex(struct Depsgraph *depsgraph,
85                              struct RenderEngineType *engine_type,
86                              struct ARegion *region,
87                              struct View3D *v3d,
88                              struct GPUViewport *viewport,
89                              const struct bContext *evil_C);
90 void DRW_draw_render_loop(struct Depsgraph *depsgraph,
91                           struct ARegion *region,
92                           struct View3D *v3d,
93                           struct GPUViewport *viewport);
94 void DRW_draw_render_loop_offscreen(struct Depsgraph *depsgraph,
95                                     struct RenderEngineType *engine_type,
96                                     struct ARegion *region,
97                                     struct View3D *v3d,
98                                     const bool is_image_render,
99                                     const bool draw_background,
100                                     const bool do_color_management,
101                                     struct GPUOffScreen *ofs,
102                                     struct GPUViewport *viewport);
103 void DRW_draw_render_loop_2d_ex(struct Depsgraph *depsgraph,
104                                 struct ARegion *region,
105                                 struct GPUViewport *viewport,
106                                 const struct bContext *evil_C);
107 void DRW_draw_select_loop(struct Depsgraph *depsgraph,
108                           struct ARegion *region,
109                           struct View3D *v3d,
110                           bool use_obedit_skip,
111                           bool draw_surface,
112                           bool use_nearest,
113                           const bool do_material_sub_selection,
114                           const struct rcti *rect,
115                           DRW_SelectPassFn select_pass_fn,
116                           void *select_pass_user_data,
117                           DRW_ObjectFilterFn object_filter_fn,
118                           void *object_filter_user_data);
119 void DRW_draw_depth_loop(struct Depsgraph *depsgraph,
120                          struct ARegion *region,
121                          struct View3D *v3d,
122                          struct GPUViewport *viewport);
123 void DRW_draw_depth_loop_gpencil(struct Depsgraph *depsgraph,
124                                  struct ARegion *region,
125                                  struct View3D *v3d,
126                                  struct GPUViewport *viewport);
127 void DRW_draw_depth_object(struct Scene *scene,
128                            struct ARegion *region,
129                            struct View3D *v3d,
130                            struct GPUViewport *viewport,
131                            struct Object *object);
132 void DRW_draw_select_id(struct Depsgraph *depsgraph,
133                         struct ARegion *region,
134                         struct View3D *v3d,
135                         const struct rcti *rect);
136
137 /* grease pencil render */
138 bool DRW_render_check_grease_pencil(struct Depsgraph *depsgraph);
139 void DRW_render_gpencil(struct RenderEngine *engine, struct Depsgraph *depsgraph);
140
141 /* This is here because GPUViewport needs it */
142 struct DRWInstanceDataList *DRW_instance_data_list_create(void);
143 void DRW_instance_data_list_free(struct DRWInstanceDataList *idatalist);
144 void DRW_uniform_attrs_pool_free(struct GHash *table);
145
146 void DRW_render_context_enable(struct Render *render);
147 void DRW_render_context_disable(struct Render *render);
148
149 void DRW_opengl_context_create(void);
150 void DRW_opengl_context_destroy(void);
151 void DRW_opengl_context_enable(void);
152 void DRW_opengl_context_disable(void);
153
154 #ifdef WITH_XR_OPENXR
155 /* XXX see comment on DRW_xr_opengl_context_get() */
156 void *DRW_xr_opengl_context_get(void);
157 void *DRW_xr_gpu_context_get(void);
158 void DRW_xr_drawing_begin(void);
159 void DRW_xr_drawing_end(void);
160 #endif
161
162 /* For garbage collection */
163 void DRW_cache_free_old_batches(struct Main *bmain);
164
165 /* Never use this. Only for closing blender. */
166 void DRW_opengl_context_enable_ex(bool restore);
167 void DRW_opengl_context_disable_ex(bool restore);
168
169 void DRW_opengl_render_context_enable(void *re_gl_context);
170 void DRW_opengl_render_context_disable(void *re_gl_context);
171 void DRW_gpu_render_context_enable(void *re_gpu_context);
172 void DRW_gpu_render_context_disable(void *re_gpu_context);
173
174 void DRW_deferred_shader_remove(struct GPUMaterial *mat);
175
176 struct DrawDataList *DRW_drawdatalist_from_id(struct ID *id);
177 void DRW_drawdata_free(struct ID *id);
178
179 bool DRW_opengl_context_release(void);
180 void DRW_opengl_context_activate(bool drw_state);
181
182 #ifdef __cplusplus
183 }
184 #endif