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 */
133 /* for acquire image, to indicate if it is compo/seq result */
136 /* render info text */
142 typedef struct RenderStats {
144 int totface, totvert, totstrand, tothalo, totlamp, totpart;
145 short curfield, curblur, curpart, partsdone, convertdone;
146 double starttime, lastframetime;
147 char *infostr, *statstr, scenename[32];
151 /* *********************** API ******************** */
153 /* the name is used as identifier, so elsewhere in blender the result can retrieved */
154 /* calling a new render with same name, frees automatic existing render */
155 struct Render *RE_NewRender (const char *name);
156 struct Render *RE_GetRender(const char *name);
158 /* returns 1 while render is working (or renders called from within render) */
159 int RE_RenderInProgress(struct Render *re);
161 /* use free render as signal to do everything over (previews) */
162 void RE_FreeRender (struct Render *re);
163 /* only called on exit */
164 void RE_FreeAllRender (void);
166 /* get results and statistics */
167 void RE_FreeRenderResult(struct RenderResult *rr);
168 struct RenderResult *RE_AcquireResultRead(struct Render *re);
169 struct RenderResult *RE_AcquireResultWrite(struct Render *re);
170 void RE_ReleaseResult(struct Render *re);
171 void RE_AcquireResultImage(struct Render *re, struct RenderResult *rr);
172 void RE_ReleaseResultImage(struct Render *re);
173 void RE_SwapResult(struct Render *re, struct RenderResult **rr);
174 struct RenderStats *RE_GetStats(struct Render *re);
175 void RE_ResultGet32(struct Render *re, unsigned int *rect);
176 struct RenderLayer *RE_GetRenderLayer(struct RenderResult *rr, const char *name);
177 float *RE_RenderLayerGetPass(struct RenderLayer *rl, int passtype);
179 /* obligatory initialize call, disprect is optional */
180 void RE_InitState (struct Render *re, struct Render *source, struct RenderData *rd, struct SceneRenderLayer *srl, int winx, int winy, rcti *disprect);
182 /* use this to change disprect of active render */
183 void RE_SetDispRect (struct Render *re, rcti *disprect);
185 /* set up the viewplane/perspective matrix, three choices */
186 void RE_SetCamera(struct Render *re, struct Object *camera);
187 void RE_SetWindow (struct Render *re, rctf *viewplane, float clipsta, float clipend);
188 void RE_SetOrtho (struct Render *re, rctf *viewplane, float clipsta, float clipend);
189 void RE_SetPixelSize(struct Render *re, float pixsize);
191 /* option to set viewmatrix before making dbase */
192 void RE_SetView (struct Render *re, float mat[][4]);
194 /* make or free the dbase */
195 void RE_Database_FromScene(struct Render *re, struct Scene *scene, unsigned int lay, int use_camera_view);
196 void RE_Database_Free (struct Render *re);
198 /* project dbase again, when viewplane/perspective changed */
199 void RE_DataBase_ApplyWindow(struct Render *re);
201 /* override the scene setting for amount threads, commandline */
202 void RE_set_max_threads(int threads);
204 /* set the render threads based on the commandline and autothreads setting */
205 void RE_init_threadcount(Render *re);
207 /* the main processor, assumes all was set OK! */
208 void RE_TileProcessor(struct Render *re);
210 /* only RE_NewRender() needed, main Blender render calls */
211 void RE_BlenderFrame(struct Render *re, struct Scene *scene, struct SceneRenderLayer *srl, unsigned int lay, int frame);
212 void RE_BlenderAnim(struct Render *re, struct Scene *scene, unsigned int lay, int sfra, int efra, int tfra, struct ReportList *reports);
213 void RE_RenderFreestyleStrokes(struct Render *re, struct Scene *scene);
215 /* main preview render call */
216 void RE_PreviewRender(struct Render *re, struct Scene *scene);
218 void RE_ReadRenderResult(struct Scene *scene, struct Scene *scenode);
219 void RE_WriteRenderResult(RenderResult *rr, char *filename, int compress);
220 struct RenderResult *RE_MultilayerConvert(void *exrhandle, int rectx, int recty);
222 /* do a full sample buffer compo */
223 void RE_MergeFullSample(struct Render *re, struct Scene *sce, struct bNodeTree *ntree);
225 /* ancient stars function... go away! */
226 void RE_make_stars(struct Render *re, struct Scene *scenev3d, void (*initfunc)(void),
227 void (*vertexfunc)(float*), void (*termfunc)(void));
229 /* display and event callbacks */
230 void RE_display_init_cb (struct Render *re, void *handle, void (*f)(void *handle, RenderResult *rr));
231 void RE_display_clear_cb(struct Render *re, void *handle, void (*f)(void *handle, RenderResult *rr));
232 void RE_display_draw_cb (struct Render *re, void *handle, void (*f)(void *handle, RenderResult *rr, volatile struct rcti *rect));
233 void RE_stats_draw_cb (struct Render *re, void *handle, void (*f)(void *handle, RenderStats *rs));
234 void RE_timecursor_cb (struct Render *re, void *handle, void (*f)(void *handle, int));
235 void RE_test_break_cb (struct Render *re, void *handle, int (*f)(void *handle));
236 void RE_error_cb (struct Render *re, void *handle, void (*f)(void *handle, char *str));
238 /* should move to kernel once... still unsure on how/where */
239 float RE_filter_value(int type, float x);
240 /* vector blur zbuffer method */
241 void RE_zbuf_accumulate_vecblur(struct NodeBlurData *nbd, int xsize, int ysize, float *newrect, float *imgrect, float *vecbufrect, float *zbufrect);
243 /* shaded view or baking options */
244 #define RE_BAKE_LIGHT 0
245 #define RE_BAKE_ALL 1
247 #define RE_BAKE_NORMALS 3
248 #define RE_BAKE_TEXTURE 4
249 #define RE_BAKE_DISPLACEMENT 5
250 #define RE_BAKE_SHADOW 6
252 void RE_Database_Baking(struct Render *re, struct Scene *scene, unsigned int lay, int type, struct Object *actob);
254 void RE_DataBase_GetView(struct Render *re, float mat[][4]);
255 void RE_GetCameraWindow(struct Render *re, struct Object *camera, int frame, float mat[][4]);
256 struct Scene *RE_GetScene(struct Render *re);
258 /* External Engine */
260 #define RE_INTERNAL 1
262 #define RE_DO_PREVIEW 4
265 extern ListBase R_engines;
267 typedef struct RenderEngineType {
268 struct RenderEngineType *next, *prev;
271 char idname[64]; // best keep the same size as BKE_ST_MAXNAME
275 void (*render)(struct RenderEngine *engine, struct Scene *scene);
277 /* RNA integration */
281 typedef struct RenderEngine {
282 RenderEngineType *type;
287 void RE_layer_load_from_file(RenderLayer *layer, struct ReportList *reports, char *filename);
288 void RE_result_load_from_file(RenderResult *result, struct ReportList *reports, char *filename);
290 struct RenderResult *RE_engine_begin_result(RenderEngine *engine, int x, int y, int w, int h);
291 void RE_engine_update_result(RenderEngine *engine, struct RenderResult *result);
292 void RE_engine_end_result(RenderEngine *engine, struct RenderResult *result);
294 int RE_engine_test_break(RenderEngine *engine);
295 void RE_engine_update_stats(RenderEngine *engine, char *stats, char *info);
297 void RE_engines_init(void);
298 void RE_engines_exit(void);
300 #endif /* RE_PIPELINE_H */