Merge branch 'blender-v2.81-release'
[blender.git] / source / blender / render / extern / include / RE_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  * The Original Code is Copyright (C) 2006 Blender Foundation.
17  * All rights reserved.
18  */
19
20 /** \file
21  * \ingroup render
22  */
23
24 #ifndef __RE_ENGINE_H__
25 #define __RE_ENGINE_H__
26
27 #include "DNA_listBase.h"
28 #include "DNA_scene_types.h"
29 #include "RNA_types.h"
30 #include "RE_bake.h"
31
32 #include "BLI_threads.h"
33
34 struct BakePixel;
35 struct Depsgraph;
36 struct Main;
37 struct Object;
38 struct Render;
39 struct RenderData;
40 struct RenderEngine;
41 struct RenderEngineType;
42 struct RenderLayer;
43 struct RenderResult;
44 struct ReportList;
45 struct Scene;
46 struct ViewLayer;
47 struct bNode;
48 struct bNodeTree;
49
50 /* External Engine */
51
52 /* RenderEngineType.flag */
53 #define RE_INTERNAL 1
54 /* #define RE_FLAG_DEPRECATED   2 */
55 #define RE_USE_PREVIEW 4
56 #define RE_USE_POSTPROCESS 8
57 #define RE_USE_EEVEE_VIEWPORT 16
58 #define RE_USE_SAVE_BUFFERS 32
59 #define RE_USE_SHADING_NODES_CUSTOM 64
60 #define RE_USE_SPHERICAL_STEREO 128
61
62 /* RenderEngine.flag */
63 #define RE_ENGINE_ANIMATION 1
64 #define RE_ENGINE_PREVIEW 2
65 #define RE_ENGINE_DO_DRAW 4
66 #define RE_ENGINE_DO_UPDATE 8
67 #define RE_ENGINE_RENDERING 16
68 #define RE_ENGINE_HIGHLIGHT_TILES 32
69 #define RE_ENGINE_USED_FOR_VIEWPORT 64
70
71 extern ListBase R_engines;
72
73 typedef struct RenderEngineType {
74   struct RenderEngineType *next, *prev;
75
76   /* type info */
77   char idname[64];  // best keep the same size as BKE_ST_MAXNAME
78   char name[64];
79   int flag;
80
81   void (*update)(struct RenderEngine *engine, struct Main *bmain, struct Depsgraph *depsgraph);
82   void (*render)(struct RenderEngine *engine, struct Depsgraph *depsgraph);
83   void (*bake)(struct RenderEngine *engine,
84                struct Depsgraph *depsgraph,
85                struct Object *object,
86                const int pass_type,
87                const int pass_filter,
88                const int object_id,
89                const struct BakePixel *pixel_array,
90                const int num_pixels,
91                const int depth,
92                void *result);
93
94   void (*view_update)(struct RenderEngine *engine,
95                       const struct bContext *context,
96                       struct Depsgraph *depsgraph);
97   void (*view_draw)(struct RenderEngine *engine,
98                     const struct bContext *context,
99                     struct Depsgraph *depsgraph);
100
101   void (*update_script_node)(struct RenderEngine *engine,
102                              struct bNodeTree *ntree,
103                              struct bNode *node);
104   void (*update_render_passes)(struct RenderEngine *engine,
105                                struct Scene *scene,
106                                struct ViewLayer *view_layer);
107
108   struct DrawEngineType *draw_engine;
109
110   /* RNA integration */
111   ExtensionRNA ext;
112 } RenderEngineType;
113
114 typedef void (*update_render_passes_cb_t)(void *userdata,
115                                           struct Scene *scene,
116                                           struct ViewLayer *view_layer,
117                                           const char *name,
118                                           int channels,
119                                           const char *chanid,
120                                           int type);
121
122 typedef struct RenderEngine {
123   RenderEngineType *type;
124   void *py_instance;
125
126   int flag;
127   struct Object *camera_override;
128   unsigned int layer_override;
129
130   int tile_x;
131   int tile_y;
132
133   struct Render *re;
134   ListBase fullresult;
135   char text[512]; /* IMA_MAX_RENDER_TEXT */
136
137   int resolution_x, resolution_y;
138
139   struct ReportList *reports;
140
141   /* Depsgraph */
142   struct Depsgraph *depsgraph;
143
144   /* callback for render pass query */
145   ThreadMutex update_render_passes_mutex;
146   update_render_passes_cb_t update_render_passes_cb;
147   void *update_render_passes_data;
148
149   rctf last_viewplane;
150   rcti last_disprect;
151   float last_viewmat[4][4];
152   int last_winx, last_winy;
153 } RenderEngine;
154
155 RenderEngine *RE_engine_create(RenderEngineType *type);
156 RenderEngine *RE_engine_create_ex(RenderEngineType *type, bool use_for_viewport);
157 void RE_engine_free(RenderEngine *engine);
158
159 void RE_layer_load_from_file(
160     struct RenderLayer *layer, struct ReportList *reports, const char *filename, int x, int y);
161 void RE_result_load_from_file(struct RenderResult *result,
162                               struct ReportList *reports,
163                               const char *filename);
164
165 struct RenderResult *RE_engine_begin_result(
166     RenderEngine *engine, int x, int y, int w, int h, const char *layername, const char *viewname);
167 void RE_engine_update_result(RenderEngine *engine, struct RenderResult *result);
168 void RE_engine_add_pass(RenderEngine *engine,
169                         const char *name,
170                         int channels,
171                         const char *chan_id,
172                         const char *layername);
173 void RE_engine_end_result(RenderEngine *engine,
174                           struct RenderResult *result,
175                           bool cancel,
176                           bool highlight,
177                           bool merge_results);
178 struct RenderResult *RE_engine_get_result(struct RenderEngine *engine);
179
180 const char *RE_engine_active_view_get(RenderEngine *engine);
181 void RE_engine_active_view_set(RenderEngine *engine, const char *viewname);
182 float RE_engine_get_camera_shift_x(RenderEngine *engine,
183                                    struct Object *camera,
184                                    bool use_spherical_stereo);
185 void RE_engine_get_camera_model_matrix(RenderEngine *engine,
186                                        struct Object *camera,
187                                        bool use_spherical_stereo,
188                                        float *r_modelmat);
189 bool RE_engine_get_spherical_stereo(RenderEngine *engine, struct Object *camera);
190
191 bool RE_engine_test_break(RenderEngine *engine);
192 void RE_engine_update_stats(RenderEngine *engine, const char *stats, const char *info);
193 void RE_engine_update_progress(RenderEngine *engine, float progress);
194 void RE_engine_update_memory_stats(RenderEngine *engine, float mem_used, float mem_peak);
195 void RE_engine_report(RenderEngine *engine, int type, const char *msg);
196 void RE_engine_set_error_message(RenderEngine *engine, const char *msg);
197
198 int RE_engine_render(struct Render *re, int do_all);
199
200 bool RE_engine_is_external(struct Render *re);
201
202 void RE_engine_frame_set(struct RenderEngine *engine, int frame, float subframe);
203
204 void RE_engine_update_render_passes(struct RenderEngine *engine,
205                                     struct Scene *scene,
206                                     struct ViewLayer *view_layer,
207                                     update_render_passes_cb_t callback,
208                                     void *callback_data);
209 void RE_engine_register_pass(struct RenderEngine *engine,
210                              struct Scene *scene,
211                              struct ViewLayer *view_layer,
212                              const char *name,
213                              int channels,
214                              const char *chanid,
215                              int type);
216
217 /* Engine Types */
218
219 void RE_engines_init(void);
220 void RE_engines_exit(void);
221 void RE_engines_register(RenderEngineType *render_type);
222
223 bool RE_engine_is_opengl(RenderEngineType *render_type);
224
225 RenderEngineType *RE_engines_find(const char *idname);
226
227 rcti *RE_engine_get_current_tiles(struct Render *re, int *r_total_tiles, bool *r_needs_free);
228 struct RenderData *RE_engine_get_render_data(struct Render *re);
229 void RE_bake_engine_set_engine_parameters(struct Render *re,
230                                           struct Main *bmain,
231                                           struct Scene *scene);
232
233 void RE_engine_free_blender_memory(struct RenderEngine *engine);
234
235 #endif /* __RE_ENGINE_H__ */