4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * The Original Code is Copyright (C) 2006 Blender Foundation.
21 * All rights reserved.
23 * The Original Code is: all of this file.
25 * Contributor(s): none yet.
27 * ***** END GPL LICENSE BLOCK *****
33 #include "DNA_listBase.h"
34 #include "DNA_vec_types.h"
35 #include "BKE_utildefines.h"
36 #include "RNA_types.h"
45 struct RenderEngineType;
49 struct SceneRenderLayer;
51 /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
52 /* this include is what is exposed of render to outside world */
53 /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
58 /* only used as handle */
59 typedef struct Render Render;
61 /* Render Result usage:
63 - render engine allocates/frees and delivers raw floating point rects
64 - right now it's full rects, but might become tiles or file
65 - the display client has to allocate display rects, sort out what to display,
66 and how it's converted
69 typedef struct RenderPass {
70 struct RenderPass *next, *prev;
71 int passtype, channels;
72 char name[16]; /* amount defined in openexr_multi.h */
73 char chan_id[8]; /* amount defined in openexr_multi.h */
78 /* a renderlayer is a full image, but with all passes and samples */
79 /* size of the rects is defined in RenderResult */
80 /* after render, the Combined pass is in rectf, for renderlayers read from files it is a real pass */
81 typedef struct RenderLayer {
82 struct RenderLayer *next, *prev;
84 /* copy of RenderData */
85 char name[RE_MAXNAME];
86 unsigned int lay, lay_zmask;
87 int layflag, passflag, pass_xor;
89 struct Material *mat_override;
90 struct Group *light_override;
92 float *rectf; /* 4 float, standard rgba buffer (read not above!) */
93 float *acolrect; /* 4 float, optional transparent buffer, needs storage for display updates */
94 float *scolrect; /* 4 float, optional strand buffer, needs storage for display updates */
101 typedef struct RenderResult {
102 struct RenderResult *next, *prev;
104 /* target image size */
106 short crop, sample_nr;
108 /* optional, 32 bits version of picture, used for ogl render and image curves */
110 /* if this exists, a copy of one of layers, or result of composited layers */
112 /* if this exists, a copy of one of layers, or result of composited layers */
115 /* coordinates within final image (after cropping) */
117 /* offset to apply to get a border render in full image */
120 /* the main buffers */
123 /* allowing live updates: */
124 volatile rcti renrect;
125 volatile RenderLayer *renlay;
127 /* optional saved endresult on disk */
130 /* for render results in Image, verify validity for sequences */
136 typedef struct RenderStats {
138 int totface, totvert, totstrand, tothalo, totlamp, totpart;
139 short curfield, curblur, curpart, partsdone, convertdone;
140 double starttime, lastframetime;
141 char *infostr, *statstr, scenename[32];
145 /* *********************** API ******************** */
147 /* the name is used as identifier, so elsewhere in blender the result can retrieved */
148 /* calling a new render with same name, frees automatic existing render */
149 struct Render *RE_NewRender (const char *name, int slot);
150 struct Render *RE_GetRender(const char *name, int slot);
152 /* render slots. for most cases like baking or preview render this will
153 always be default, for actual render multiple slots can be used. in
154 that case 'rendering' is the slot being rendered to, and 'view' is the
155 slot being viewed. these are always the same except if the currently
156 viewed slot is changed during render, at the end they will be synced. */
157 #define RE_SLOT_RENDERING -2
158 #define RE_SLOT_VIEW -1
159 #define RE_SLOT_DEFAULT 0
160 #define RE_SLOT_MAX 10
162 void RE_SetViewSlot(int slot);
163 int RE_GetViewSlot(void);
165 /* returns 1 while render is working (or renders called from within render) */
166 int RE_RenderInProgress(struct Render *re);
168 /* use free render as signal to do everything over (previews) */
169 void RE_FreeRender (struct Render *re);
170 /* only called on exit */
171 void RE_FreeAllRender (void);
173 /* get results and statistics */
174 void RE_FreeRenderResult(struct RenderResult *rr);
175 struct RenderResult *RE_AcquireResultRead(struct Render *re);
176 struct RenderResult *RE_AcquireResultWrite(struct Render *re);
177 void RE_ReleaseResult(struct Render *re);
178 void RE_AcquireResultImage(struct Render *re, struct RenderResult *rr);
179 void RE_ReleaseResultImage(struct Render *re);
180 struct RenderStats *RE_GetStats(struct Render *re);
181 void RE_ResultGet32(struct Render *re, unsigned int *rect);
182 struct RenderLayer *RE_GetRenderLayer(struct RenderResult *rr, const char *name);
183 float *RE_RenderLayerGetPass(struct RenderLayer *rl, int passtype);
185 /* obligatory initialize call, disprect is optional */
186 void RE_InitState (struct Render *re, struct Render *source, struct RenderData *rd, struct SceneRenderLayer *srl, int winx, int winy, rcti *disprect);
188 /* use this to change disprect of active render */
189 void RE_SetDispRect (struct Render *re, rcti *disprect);
191 /* set up the viewplane/perspective matrix, three choices */
192 void RE_SetCamera(struct Render *re, struct Object *camera);
193 void RE_SetWindow (struct Render *re, rctf *viewplane, float clipsta, float clipend);
194 void RE_SetOrtho (struct Render *re, rctf *viewplane, float clipsta, float clipend);
195 void RE_SetPixelSize(struct Render *re, float pixsize);
197 /* option to set viewmatrix before making dbase */
198 void RE_SetView (struct Render *re, float mat[][4]);
200 /* make or free the dbase */
201 void RE_Database_FromScene(struct Render *re, struct Scene *scene, int use_camera_view);
202 void RE_Database_Free (struct Render *re);
204 /* project dbase again, when viewplane/perspective changed */
205 void RE_DataBase_ApplyWindow(struct Render *re);
207 /* override the scene setting for amount threads, commandline */
208 void RE_set_max_threads(int threads);
210 /* set the render threads based on the commandline and autothreads setting */
211 void RE_init_threadcount(Render *re);
213 /* the main processor, assumes all was set OK! */
214 void RE_TileProcessor(struct Render *re, int firsttile, int threaded);
216 /* only RE_NewRender() needed, main Blender render calls */
217 void RE_BlenderFrame(struct Render *re, struct Scene *scene, struct SceneRenderLayer *srl, int frame);
218 void RE_BlenderAnim(struct Render *re, struct Scene *scene, int sfra, int efra, int tfra, struct ReportList *reports);
219 void RE_RenderFreestyleStrokes(struct Render *re, struct Scene *scene);
221 void RE_ReadRenderResult(struct Scene *scene, struct Scene *scenode);
222 void RE_WriteRenderResult(RenderResult *rr, char *filename, int compress);
223 struct RenderResult *RE_MultilayerConvert(void *exrhandle, int rectx, int recty);
225 /* do a full sample buffer compo */
226 void RE_MergeFullSample(struct Render *re, struct Scene *sce, struct bNodeTree *ntree);
228 /* ancient stars function... go away! */
229 void RE_make_stars(struct Render *re, struct Scene *scenev3d, void (*initfunc)(void),
230 void (*vertexfunc)(float*), void (*termfunc)(void));
232 /* display and event callbacks */
233 void RE_display_init_cb (struct Render *re, void *handle, void (*f)(void *handle, RenderResult *rr));
234 void RE_display_clear_cb(struct Render *re, void *handle, void (*f)(void *handle, RenderResult *rr));
235 void RE_display_draw_cb (struct Render *re, void *handle, void (*f)(void *handle, RenderResult *rr, volatile struct rcti *rect));
236 void RE_stats_draw_cb (struct Render *re, void *handle, void (*f)(void *handle, RenderStats *rs));
237 void RE_timecursor_cb (struct Render *re, void *handle, void (*f)(void *handle, int));
238 void RE_test_break_cb (struct Render *re, void *handle, int (*f)(void *handle));
239 void RE_error_cb (struct Render *re, void *handle, void (*f)(void *handle, char *str));
241 /* should move to kernel once... still unsure on how/where */
242 float RE_filter_value(int type, float x);
243 /* vector blur zbuffer method */
244 void RE_zbuf_accumulate_vecblur(struct NodeBlurData *nbd, int xsize, int ysize, float *newrect, float *imgrect, float *vecbufrect, float *zbufrect);
246 /* shaded view or baking options */
247 #define RE_BAKE_LIGHT 0
248 #define RE_BAKE_ALL 1
250 #define RE_BAKE_NORMALS 3
251 #define RE_BAKE_TEXTURE 4
252 #define RE_BAKE_DISPLACEMENT 5
253 #define RE_BAKE_SHADOW 6
255 void RE_Database_Baking(struct Render *re, struct Scene *scene, int type, struct Object *actob);
257 void RE_DataBase_GetView(struct Render *re, float mat[][4]);
258 void RE_GetCameraWindow(struct Render *re, struct Object *camera, int frame, float mat[][4]);
259 struct Scene *RE_GetScene(struct Render *re);
261 /* External Engine */
263 #define RE_INTERNAL 1
266 extern ListBase R_engines;
268 typedef struct RenderEngineType {
269 struct RenderEngineType *next, *prev;
272 char idname[64]; // best keep the same size as BKE_ST_MAXNAME
276 void (*render)(struct RenderEngine *engine, struct Scene *scene);
278 /* RNA integration */
282 typedef struct RenderEngine {
283 RenderEngineType *type;
288 void RE_layer_load_from_file(RenderLayer *layer, struct ReportList *reports, char *filename);
289 void RE_result_load_from_file(RenderResult *result, struct ReportList *reports, char *filename);
291 struct RenderResult *RE_engine_begin_result(RenderEngine *engine, int x, int y, int w, int h);
292 void RE_engine_update_result(RenderEngine *engine, struct RenderResult *result);
293 void RE_engine_end_result(RenderEngine *engine, struct RenderResult *result);
295 int RE_engine_test_break(RenderEngine *engine);
296 void RE_engine_update_stats(RenderEngine *engine, char *stats, char *info);
298 void RE_engines_init(void);
299 void RE_engines_exit(void);
301 #endif /* RE_PIPELINE_H */