9c3c6ce6c04f31a0cfc4c23b60f198f72fd8577e
[blender-staging.git] / source / blender / makesrna / intern / rna_render.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * Contributor(s): Blender Foundation (2009)
19  *
20  * ***** END GPL LICENSE BLOCK *****
21  */
22
23 /** \file blender/makesrna/intern/rna_render.c
24  *  \ingroup RNA
25  */
26
27 #include <stdlib.h>
28
29 #include "DNA_scene_types.h"
30
31 #include "BLI_utildefines.h"
32 #include "BLI_path_util.h"
33
34 #include "RNA_define.h"
35 #include "RNA_enum_types.h"
36
37 #include "rna_internal.h"
38
39 #include "RE_engine.h"
40 #include "RE_pipeline.h"
41
42
43 #ifdef RNA_RUNTIME
44
45 #include "MEM_guardedalloc.h"
46
47 #include "RNA_access.h"
48
49 #include "BKE_context.h"
50 #include "BKE_report.h"
51
52 #include "IMB_colormanagement.h"
53 #include "GPU_extensions.h"
54
55 /* RenderEngine Callbacks */
56
57 static void engine_tag_redraw(RenderEngine *engine)
58 {
59         engine->flag |= RE_ENGINE_DO_DRAW;
60 }
61
62 static void engine_tag_update(RenderEngine *engine)
63 {
64         engine->flag |= RE_ENGINE_DO_UPDATE;
65 }
66
67 static int engine_support_display_space_shader(RenderEngine *UNUSED(engine), Scene *scene)
68 {
69         return IMB_colormanagement_support_glsl_draw(&scene->view_settings);
70 }
71
72 static void engine_bind_display_space_shader(RenderEngine *UNUSED(engine), Scene *scene)
73 {
74         IMB_colormanagement_setup_glsl_draw(&scene->view_settings,
75                                             &scene->display_settings,
76                                             false);
77 }
78
79 static void engine_unbind_display_space_shader(RenderEngine *UNUSED(engine))
80 {
81         IMB_colormanagement_finish_glsl_draw();
82 }
83
84 static void engine_update(RenderEngine *engine, Main *bmain, Scene *scene)
85 {
86         extern FunctionRNA rna_RenderEngine_update_func;
87         PointerRNA ptr;
88         ParameterList list;
89         FunctionRNA *func;
90
91         RNA_pointer_create(NULL, engine->type->ext.srna, engine, &ptr);
92         func = &rna_RenderEngine_update_func;
93
94         RNA_parameter_list_create(&list, &ptr, func);
95         RNA_parameter_set_lookup(&list, "data", &bmain);
96         RNA_parameter_set_lookup(&list, "scene", &scene);
97         engine->type->ext.call(NULL, &ptr, func, &list);
98
99         RNA_parameter_list_free(&list);
100 }
101
102 static void engine_render(RenderEngine *engine, struct Scene *scene)
103 {
104         extern FunctionRNA rna_RenderEngine_render_func;
105         PointerRNA ptr;
106         ParameterList list;
107         FunctionRNA *func;
108
109         RNA_pointer_create(NULL, engine->type->ext.srna, engine, &ptr);
110         func = &rna_RenderEngine_render_func;
111
112         RNA_parameter_list_create(&list, &ptr, func);
113         RNA_parameter_set_lookup(&list, "scene", &scene);
114         engine->type->ext.call(NULL, &ptr, func, &list);
115
116         RNA_parameter_list_free(&list);
117 }
118
119 static void engine_view_update(RenderEngine *engine, const struct bContext *context)
120 {
121         extern FunctionRNA rna_RenderEngine_view_update_func;
122         PointerRNA ptr;
123         ParameterList list;
124         FunctionRNA *func;
125
126         RNA_pointer_create(NULL, engine->type->ext.srna, engine, &ptr);
127         func = &rna_RenderEngine_view_update_func;
128
129         RNA_parameter_list_create(&list, &ptr, func);
130         RNA_parameter_set_lookup(&list, "context", &context);
131         engine->type->ext.call(NULL, &ptr, func, &list);
132
133         RNA_parameter_list_free(&list);
134 }
135
136 static void engine_view_draw(RenderEngine *engine, const struct bContext *context)
137 {
138         extern FunctionRNA rna_RenderEngine_view_draw_func;
139         PointerRNA ptr;
140         ParameterList list;
141         FunctionRNA *func;
142
143         RNA_pointer_create(NULL, engine->type->ext.srna, engine, &ptr);
144         func = &rna_RenderEngine_view_draw_func;
145
146         RNA_parameter_list_create(&list, &ptr, func);
147         RNA_parameter_set_lookup(&list, "context", &context);
148         engine->type->ext.call(NULL, &ptr, func, &list);
149
150         RNA_parameter_list_free(&list);
151 }
152
153 static void engine_update_script_node(RenderEngine *engine, struct bNodeTree *ntree, struct bNode *node)
154 {
155         extern FunctionRNA rna_RenderEngine_update_script_node_func;
156         PointerRNA ptr, nodeptr;
157         ParameterList list;
158         FunctionRNA *func;
159
160         RNA_pointer_create(NULL, engine->type->ext.srna, engine, &ptr);
161         RNA_pointer_create((ID *)ntree, &RNA_Node, node, &nodeptr);
162         func = &rna_RenderEngine_update_script_node_func;
163
164         RNA_parameter_list_create(&list, &ptr, func);
165         RNA_parameter_set_lookup(&list, "node", &nodeptr);
166         engine->type->ext.call(NULL, &ptr, func, &list);
167
168         RNA_parameter_list_free(&list);
169 }
170
171 /* RenderEngine registration */
172
173 static void rna_RenderEngine_unregister(Main *UNUSED(bmain), StructRNA *type)
174 {
175         RenderEngineType *et = RNA_struct_blender_type_get(type);
176
177         if (!et)
178                 return;
179         
180         RNA_struct_free_extension(type, &et->ext);
181         BLI_freelinkN(&R_engines, et);
182         RNA_struct_free(&BLENDER_RNA, type);
183 }
184
185 static StructRNA *rna_RenderEngine_register(Main *bmain, ReportList *reports, void *data, const char *identifier,
186                                             StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free)
187 {
188         RenderEngineType *et, dummyet = {NULL};
189         RenderEngine dummyengine = {NULL};
190         PointerRNA dummyptr;
191         int have_function[5];
192
193         /* setup dummy engine & engine type to store static properties in */
194         dummyengine.type = &dummyet;
195         RNA_pointer_create(NULL, &RNA_RenderEngine, &dummyengine, &dummyptr);
196
197         /* validate the python class */
198         if (validate(&dummyptr, data, have_function) != 0)
199                 return NULL;
200
201         if (strlen(identifier) >= sizeof(dummyet.idname)) {
202                 BKE_reportf(reports, RPT_ERROR, "Registering render engine class: '%s' is too long, maximum length is %d",
203                             identifier, (int)sizeof(dummyet.idname));
204                 return NULL;
205         }
206
207         /* check if we have registered this engine type before, and remove it */
208         for (et = R_engines.first; et; et = et->next) {
209                 if (strcmp(et->idname, dummyet.idname) == 0) {
210                         if (et->ext.srna)
211                                 rna_RenderEngine_unregister(bmain, et->ext.srna);
212                         break;
213                 }
214         }
215         
216         /* create a new engine type */
217         et = MEM_callocN(sizeof(RenderEngineType), "python render engine");
218         memcpy(et, &dummyet, sizeof(dummyet));
219
220         et->ext.srna = RNA_def_struct_ptr(&BLENDER_RNA, et->idname, &RNA_RenderEngine);
221         et->ext.data = data;
222         et->ext.call = call;
223         et->ext.free = free;
224         RNA_struct_blender_type_set(et->ext.srna, et);
225
226         et->update = (have_function[0]) ? engine_update : NULL;
227         et->render = (have_function[1]) ? engine_render : NULL;
228         et->view_update = (have_function[2]) ? engine_view_update : NULL;
229         et->view_draw = (have_function[3]) ? engine_view_draw : NULL;
230         et->update_script_node = (have_function[4]) ? engine_update_script_node : NULL;
231
232         BLI_addtail(&R_engines, et);
233
234         return et->ext.srna;
235 }
236
237 static void **rna_RenderEngine_instance(PointerRNA *ptr)
238 {
239         RenderEngine *engine = ptr->data;
240         return &engine->py_instance;
241 }
242
243 static StructRNA *rna_RenderEngine_refine(PointerRNA *ptr)
244 {
245         RenderEngine *engine = (RenderEngine *)ptr->data;
246         return (engine->type && engine->type->ext.srna) ? engine->type->ext.srna : &RNA_RenderEngine;
247 }
248
249 static PointerRNA rna_RenderEngine_render_get(PointerRNA *ptr)
250 {
251         RenderEngine *engine = (RenderEngine *)ptr->data;
252
253         if (engine->re) {
254                 RenderData *r = RE_engine_get_render_data(engine->re);
255
256                 return rna_pointer_inherit_refine(ptr, &RNA_RenderSettings, r);
257         }
258         else {
259                 return rna_pointer_inherit_refine(ptr, &RNA_RenderSettings, NULL);
260         }
261 }
262
263 static void rna_RenderResult_layers_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
264 {
265         RenderResult *rr = (RenderResult *)ptr->data;
266         rna_iterator_listbase_begin(iter, &rr->layers, NULL);
267 }
268
269 static void rna_RenderLayer_passes_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
270 {
271         RenderLayer *rl = (RenderLayer *)ptr->data;
272         rna_iterator_listbase_begin(iter, &rl->passes, NULL);
273 }
274
275 static int rna_RenderLayer_rect_get_length(PointerRNA *ptr, int length[RNA_MAX_ARRAY_DIMENSION])
276 {
277         RenderLayer *rl = (RenderLayer *)ptr->data;
278
279         length[0] = rl->rectx * rl->recty;
280         length[1] = 4;
281
282         return length[0] * length[1];
283 }
284
285 static void rna_RenderLayer_rect_get(PointerRNA *ptr, float *values)
286 {
287         RenderLayer *rl = (RenderLayer *)ptr->data;
288         memcpy(values, rl->rectf, sizeof(float) * rl->rectx * rl->recty * 4);
289 }
290
291 void rna_RenderLayer_rect_set(PointerRNA *ptr, const float *values)
292 {
293         RenderLayer *rl = (RenderLayer *)ptr->data;
294         memcpy(rl->rectf, values, sizeof(float) * rl->rectx * rl->recty * 4);
295 }
296
297 static int rna_RenderPass_rect_get_length(PointerRNA *ptr, int length[RNA_MAX_ARRAY_DIMENSION])
298 {
299         RenderPass *rpass = (RenderPass *)ptr->data;
300
301         length[0] = rpass->rectx * rpass->recty;
302         length[1] = rpass->channels;
303
304         return length[0] * length[1];
305 }
306
307 static void rna_RenderPass_rect_get(PointerRNA *ptr, float *values)
308 {
309         RenderPass *rpass = (RenderPass *)ptr->data;
310         memcpy(values, rpass->rect, sizeof(float) * rpass->rectx * rpass->recty * rpass->channels);
311 }
312
313 void rna_RenderPass_rect_set(PointerRNA *ptr, const float *values)
314 {
315         RenderPass *rpass = (RenderPass *)ptr->data;
316         memcpy(rpass->rect, values, sizeof(float) * rpass->rectx * rpass->recty * rpass->channels);
317 }
318
319 #else /* RNA_RUNTIME */
320
321 static void rna_def_render_engine(BlenderRNA *brna)
322 {
323         StructRNA *srna;
324         PropertyRNA *prop;
325         FunctionRNA *func;
326         
327         srna = RNA_def_struct(brna, "RenderEngine", NULL);
328         RNA_def_struct_sdna(srna, "RenderEngine");
329         RNA_def_struct_ui_text(srna, "Render Engine", "Render engine");
330         RNA_def_struct_refine_func(srna, "rna_RenderEngine_refine");
331         RNA_def_struct_register_funcs(srna, "rna_RenderEngine_register", "rna_RenderEngine_unregister",
332                                       "rna_RenderEngine_instance");
333
334         /* final render callbacks */
335         func = RNA_def_function(srna, "update", NULL);
336         RNA_def_function_ui_description(func, "Export scene data for render");
337         RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL | FUNC_ALLOW_WRITE);
338         RNA_def_pointer(func, "data", "BlendData", "", "");
339         RNA_def_pointer(func, "scene", "Scene", "", "");
340
341         func = RNA_def_function(srna, "render", NULL);
342         RNA_def_function_ui_description(func, "Render scene into an image");
343         RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL | FUNC_ALLOW_WRITE);
344         RNA_def_pointer(func, "scene", "Scene", "", "");
345
346         /* viewport render callbacks */
347         func = RNA_def_function(srna, "view_update", NULL);
348         RNA_def_function_ui_description(func, "Update on data changes for viewport render");
349         RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL | FUNC_ALLOW_WRITE);
350         RNA_def_pointer(func, "context", "Context", "", "");
351
352         func = RNA_def_function(srna, "view_draw", NULL);
353         RNA_def_function_ui_description(func, "Draw viewport render");
354         RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL);
355         RNA_def_pointer(func, "context", "Context", "", "");
356
357         /* shader script callbacks */
358         func = RNA_def_function(srna, "update_script_node", NULL);
359         RNA_def_function_ui_description(func, "Compile shader script node");
360         RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL | FUNC_ALLOW_WRITE);
361         prop = RNA_def_pointer(func, "node", "Node", "", "");
362         RNA_def_property_flag(prop, PROP_RNAPTR);
363
364         /* tag for redraw */
365         func = RNA_def_function(srna, "tag_redraw", "engine_tag_redraw");
366         RNA_def_function_ui_description(func, "Request redraw for viewport rendering");
367
368         /* tag for update */
369         func = RNA_def_function(srna, "tag_update", "engine_tag_update");
370         RNA_def_function_ui_description(func, "Request update call for viewport rendering");
371
372         func = RNA_def_function(srna, "begin_result", "RE_engine_begin_result");
373         RNA_def_function_ui_description(func, "Create render result to write linear floating point render layers and passes");
374         prop = RNA_def_int(func, "x", 0, 0, INT_MAX, "X", "", 0, INT_MAX);
375         RNA_def_property_flag(prop, PROP_REQUIRED);
376         prop = RNA_def_int(func, "y", 0, 0, INT_MAX, "Y", "", 0, INT_MAX);
377         RNA_def_property_flag(prop, PROP_REQUIRED);
378         prop = RNA_def_int(func, "w", 0, 0, INT_MAX, "Width", "", 0, INT_MAX);
379         RNA_def_property_flag(prop, PROP_REQUIRED);
380         prop = RNA_def_int(func, "h", 0, 0, INT_MAX, "Height", "", 0, INT_MAX);
381         RNA_def_property_flag(prop, PROP_REQUIRED);
382         RNA_def_string(func, "layer", "", 0, "Layer", "Single layer to get render result for");  /* NULL ok here */
383         prop = RNA_def_pointer(func, "result", "RenderResult", "Result", "");
384         RNA_def_function_return(func, prop);
385
386         func = RNA_def_function(srna, "update_result", "RE_engine_update_result");
387         RNA_def_function_ui_description(func, "Signal that pixels have been updated and can be redrawn in the user interface");
388         prop = RNA_def_pointer(func, "result", "RenderResult", "Result", "");
389         RNA_def_property_flag(prop, PROP_REQUIRED);
390
391         func = RNA_def_function(srna, "end_result", "RE_engine_end_result");
392         RNA_def_function_ui_description(func, "All pixels in the render result have been set and are final");
393         prop = RNA_def_pointer(func, "result", "RenderResult", "Result", "");
394         RNA_def_property_flag(prop, PROP_REQUIRED);
395         RNA_def_boolean(func, "cancel", 0, "Cancel", "Don't merge back results");
396
397         func = RNA_def_function(srna, "test_break", "RE_engine_test_break");
398         RNA_def_function_ui_description(func, "Test if the render operation should been canceled, this is a fast call that should be used regularly for responsiveness");
399         prop = RNA_def_boolean(func, "do_break", 0, "Break", "");
400         RNA_def_function_return(func, prop);
401
402         func = RNA_def_function(srna, "update_stats", "RE_engine_update_stats");
403         RNA_def_function_ui_description(func, "Update and signal to redraw render status text");
404         prop = RNA_def_string(func, "stats", "", 0, "Stats", "");
405         RNA_def_property_flag(prop, PROP_REQUIRED);
406         prop = RNA_def_string(func, "info", "", 0, "Info", "");
407         RNA_def_property_flag(prop, PROP_REQUIRED);
408
409         func = RNA_def_function(srna, "update_progress", "RE_engine_update_progress");
410         RNA_def_function_ui_description(func, "Update progress percentage of render");
411         prop = RNA_def_float(func, "progress", 0, 0.0f, 1.0f, "", "Percentage of render that's done", 0.0f, 1.0f);
412         RNA_def_property_flag(prop, PROP_REQUIRED);
413
414         func = RNA_def_function(srna, "update_memory_stats", "RE_engine_update_memory_stats");
415         RNA_def_function_ui_description(func, "Update memory usage statistics");
416         RNA_def_float(func, "memory_used", 0, 0.0f, FLT_MAX, "", "Current memory usage in megabytes", 0.0f, FLT_MAX);
417         RNA_def_float(func, "memory_peak", 0, 0.0f, FLT_MAX, "", "Peak memory usage in megabytes", 0.0f, FLT_MAX);
418         RNA_def_property_flag(prop, PROP_REQUIRED);
419
420         func = RNA_def_function(srna, "report", "RE_engine_report");
421         RNA_def_function_ui_description(func, "Report info, warning or error messages");
422         prop = RNA_def_enum_flag(func, "type", wm_report_items, 0, "Type", "");
423         RNA_def_property_flag(prop, PROP_REQUIRED);
424         prop = RNA_def_string(func, "message", "", 0, "Report Message", "");
425         RNA_def_property_flag(prop, PROP_REQUIRED);
426
427         func = RNA_def_function(srna, "bind_display_space_shader", "engine_bind_display_space_shader");
428         RNA_def_function_ui_description(func, "Bind GLSL fragment shader that converts linear colors to display space colors using scene color management settings");
429         prop = RNA_def_pointer(func, "scene", "Scene", "", "");
430         RNA_def_property_flag(prop, PROP_REQUIRED);
431
432         func = RNA_def_function(srna, "unbind_display_space_shader", "engine_unbind_display_space_shader");
433         RNA_def_function_ui_description(func, "Unbind GLSL display space shader, must always be called after binding the shader");
434
435         func = RNA_def_function(srna, "support_display_space_shader", "engine_support_display_space_shader");
436         RNA_def_function_ui_description(func, "Test if GLSL display space shader is supported for the combination of graphics card and scene settings");
437         prop = RNA_def_pointer(func, "scene", "Scene", "", "");
438         RNA_def_property_flag(prop, PROP_REQUIRED);
439         prop = RNA_def_boolean(func, "supported", 0, "Supported", "");
440         RNA_def_function_return(func, prop);
441
442         RNA_define_verify_sdna(0);
443
444         prop = RNA_def_property(srna, "is_animation", PROP_BOOLEAN, PROP_NONE);
445         RNA_def_property_boolean_sdna(prop, NULL, "flag", RE_ENGINE_ANIMATION);
446
447         prop = RNA_def_property(srna, "is_preview", PROP_BOOLEAN, PROP_NONE);
448         RNA_def_property_boolean_sdna(prop, NULL, "flag", RE_ENGINE_PREVIEW);
449
450         prop = RNA_def_property(srna, "camera_override", PROP_POINTER, PROP_NONE);
451         RNA_def_property_pointer_sdna(prop, NULL, "camera_override");
452         RNA_def_property_struct_type(prop, "Object");
453
454         prop = RNA_def_property(srna, "tile_x", PROP_INT, PROP_UNSIGNED);
455         RNA_def_property_int_sdna(prop, NULL, "tile_x");
456         prop = RNA_def_property(srna, "tile_y", PROP_INT, PROP_UNSIGNED);
457         RNA_def_property_int_sdna(prop, NULL, "tile_y");
458
459         prop = RNA_def_property(srna, "resolution_x", PROP_INT, PROP_PIXEL);
460         RNA_def_property_int_sdna(prop, NULL, "resolution_x");
461         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
462
463         prop = RNA_def_property(srna, "resolution_y", PROP_INT, PROP_PIXEL);
464         RNA_def_property_int_sdna(prop, NULL, "resolution_y");
465         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
466
467         /* Render Data */
468         prop = RNA_def_property(srna, "render", PROP_POINTER, PROP_NONE);
469         RNA_def_property_struct_type(prop, "RenderSettings");
470         RNA_def_property_pointer_funcs(prop, "rna_RenderEngine_render_get", NULL, NULL, NULL);
471         RNA_def_property_ui_text(prop, "Render Data", "");
472
473         prop = RNA_def_property(srna, "use_highlight_tiles", PROP_BOOLEAN, PROP_NONE);
474         RNA_def_property_boolean_sdna(prop, NULL, "flag", RE_ENGINE_HIGHLIGHT_TILES);
475
476         /* registration */
477
478         prop = RNA_def_property(srna, "bl_idname", PROP_STRING, PROP_NONE);
479         RNA_def_property_string_sdna(prop, NULL, "type->idname");
480         RNA_def_property_flag(prop, PROP_REGISTER | PROP_NEVER_CLAMP);
481
482         prop = RNA_def_property(srna, "bl_label", PROP_STRING, PROP_NONE);
483         RNA_def_property_string_sdna(prop, NULL, "type->name");
484         RNA_def_property_flag(prop, PROP_REGISTER);
485
486         prop = RNA_def_property(srna, "bl_use_preview", PROP_BOOLEAN, PROP_NONE);
487         RNA_def_property_boolean_sdna(prop, NULL, "type->flag", RE_USE_PREVIEW);
488         RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL);
489
490         prop = RNA_def_property(srna, "bl_use_postprocess", PROP_BOOLEAN, PROP_NONE);
491         RNA_def_property_boolean_negative_sdna(prop, NULL, "type->flag", RE_USE_POSTPROCESS);
492         RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL);
493
494         prop = RNA_def_property(srna, "bl_use_shading_nodes", PROP_BOOLEAN, PROP_NONE);
495         RNA_def_property_boolean_sdna(prop, NULL, "type->flag", RE_USE_SHADING_NODES);
496         RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL);
497
498         prop = RNA_def_property(srna, "bl_use_exclude_layers", PROP_BOOLEAN, PROP_NONE);
499         RNA_def_property_boolean_sdna(prop, NULL, "type->flag", RE_USE_EXCLUDE_LAYERS);
500         RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL);
501
502         prop = RNA_def_property(srna, "bl_use_save_buffers", PROP_BOOLEAN, PROP_NONE);
503         RNA_def_property_boolean_sdna(prop, NULL, "type->flag", RE_USE_SAVE_BUFFERS);
504         RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL);
505
506         RNA_define_verify_sdna(1);
507 }
508
509 static void rna_def_render_result(BlenderRNA *brna)
510 {
511         StructRNA *srna;
512         FunctionRNA *func;
513         PropertyRNA *parm;
514         
515         srna = RNA_def_struct(brna, "RenderResult", NULL);
516         RNA_def_struct_ui_text(srna, "Render Result", "Result of rendering, including all layers and passes");
517
518         func = RNA_def_function(srna, "load_from_file", "RE_result_load_from_file");
519         RNA_def_function_ui_description(func, "Copies the pixels of this render result from an image file");
520         RNA_def_function_flag(func, FUNC_USE_REPORTS);
521         parm = RNA_def_string_file_name(func, "filename", "", FILE_MAX, "File Name",
522                                         "Filename to load into this render tile, must be no smaller than "
523                                         "the render result");
524         RNA_def_property_flag(parm, PROP_REQUIRED);
525
526         RNA_define_verify_sdna(0);
527
528         parm = RNA_def_property(srna, "resolution_x", PROP_INT, PROP_PIXEL);
529         RNA_def_property_int_sdna(parm, NULL, "rectx");
530         RNA_def_property_clear_flag(parm, PROP_EDITABLE);
531
532         parm = RNA_def_property(srna, "resolution_y", PROP_INT, PROP_PIXEL);
533         RNA_def_property_int_sdna(parm, NULL, "recty");
534         RNA_def_property_clear_flag(parm, PROP_EDITABLE);
535
536         parm = RNA_def_property(srna, "layers", PROP_COLLECTION, PROP_NONE);
537         RNA_def_property_struct_type(parm, "RenderLayer");
538         RNA_def_property_collection_funcs(parm, "rna_RenderResult_layers_begin", "rna_iterator_listbase_next",
539                                           "rna_iterator_listbase_end", "rna_iterator_listbase_get",
540                                           NULL, NULL, NULL, NULL);
541
542         RNA_define_verify_sdna(1);
543 }
544
545 static void rna_def_render_layer(BlenderRNA *brna)
546 {
547         StructRNA *srna;
548         PropertyRNA *prop;
549         FunctionRNA *func;
550         
551         srna = RNA_def_struct(brna, "RenderLayer", NULL);
552         RNA_def_struct_ui_text(srna, "Render Layer", "");
553
554         func = RNA_def_function(srna, "load_from_file", "RE_layer_load_from_file");
555         RNA_def_function_ui_description(func, "Copies the pixels of this renderlayer from an image file");
556         RNA_def_function_flag(func, FUNC_USE_REPORTS);
557         prop = RNA_def_string(func, "filename", "", 0, "Filename",
558                               "Filename to load into this render tile, must be no smaller than the renderlayer");
559         RNA_def_property_flag(prop, PROP_REQUIRED);
560         RNA_def_int(func, "x", 0, 0, INT_MAX, "Offset X",
561                     "Offset the position to copy from if the image is larger than the render layer", 0, INT_MAX);
562         RNA_def_int(func, "y", 0, 0, INT_MAX, "Offset Y",
563                     "Offset the position to copy from if the image is larger than the render layer", 0, INT_MAX);
564
565         RNA_define_verify_sdna(0);
566
567         rna_def_render_layer_common(srna, 0);
568
569         prop = RNA_def_property(srna, "passes", PROP_COLLECTION, PROP_NONE);
570         RNA_def_property_struct_type(prop, "RenderPass");
571         RNA_def_property_collection_funcs(prop, "rna_RenderLayer_passes_begin", "rna_iterator_listbase_next",
572                                           "rna_iterator_listbase_end", "rna_iterator_listbase_get",
573                                           NULL, NULL, NULL, NULL);
574
575         prop = RNA_def_property(srna, "rect", PROP_FLOAT, PROP_NONE);
576         RNA_def_property_flag(prop, PROP_DYNAMIC);
577         RNA_def_property_multi_array(prop, 2, NULL);
578         RNA_def_property_dynamic_array_funcs(prop, "rna_RenderLayer_rect_get_length");
579         RNA_def_property_float_funcs(prop, "rna_RenderLayer_rect_get", "rna_RenderLayer_rect_set", NULL);
580
581         RNA_define_verify_sdna(1);
582 }
583
584 static void rna_def_render_pass(BlenderRNA *brna)
585 {
586         StructRNA *srna;
587         PropertyRNA *prop;
588
589         static EnumPropertyItem pass_type_items[] = {
590                 {SCE_PASS_COMBINED, "COMBINED", 0, "Combined", ""},
591                 {SCE_PASS_Z, "Z", 0, "Z", ""},
592                 {SCE_PASS_RGBA, "COLOR", 0, "Color", ""},
593                 {SCE_PASS_DIFFUSE, "DIFFUSE", 0, "Diffuse", ""},
594                 {SCE_PASS_SPEC, "SPECULAR", 0, "Specular", ""},
595                 {SCE_PASS_SHADOW, "SHADOW", 0, "Shadow", ""},
596                 {SCE_PASS_AO, "AO", 0, "AO", ""},
597                 {SCE_PASS_REFLECT, "REFLECTION", 0, "Reflection", ""},
598                 {SCE_PASS_NORMAL, "NORMAL", 0, "Normal", ""},
599                 {SCE_PASS_VECTOR, "VECTOR", 0, "Vector", ""},
600                 {SCE_PASS_REFRACT, "REFRACTION", 0, "Refraction", ""},
601                 {SCE_PASS_INDEXOB, "OBJECT_INDEX", 0, "Object Index", ""},
602                 {SCE_PASS_UV, "UV", 0, "UV", ""},
603                 {SCE_PASS_MIST, "MIST", 0, "Mist", ""},
604                 {SCE_PASS_EMIT, "EMIT", 0, "Emit", ""},
605                 {SCE_PASS_ENVIRONMENT, "ENVIRONMENT", 0, "Environment", ""},
606                 {SCE_PASS_INDEXMA, "MATERIAL_INDEX", 0, "Material Index", ""},
607                 {SCE_PASS_DIFFUSE_DIRECT, "DIFFUSE_DIRECT", 0, "Diffuse Direct", ""},
608                 {SCE_PASS_DIFFUSE_INDIRECT, "DIFFUSE_INDIRECT", 0, "Diffuse Indirect", ""},
609                 {SCE_PASS_DIFFUSE_COLOR, "DIFFUSE_COLOR", 0, "Diffuse Color", ""},
610                 {SCE_PASS_GLOSSY_DIRECT, "GLOSSY_DIRECT", 0, "Glossy Direct", ""},
611                 {SCE_PASS_GLOSSY_INDIRECT, "GLOSSY_INDIRECT", 0, "Glossy Indirect", ""},
612                 {SCE_PASS_GLOSSY_COLOR, "GLOSSY_COLOR", 0, "Glossy Color", ""},
613                 {SCE_PASS_TRANSM_DIRECT, "TRANSMISSION_DIRECT", 0, "Transmission Direct", ""},
614                 {SCE_PASS_TRANSM_INDIRECT, "TRANSMISSION_INDIRECT", 0, "Transmission Indirect", ""},
615                 {SCE_PASS_TRANSM_COLOR, "TRANSMISSION_COLOR", 0, "Transmission Color", ""},
616                 {SCE_PASS_SUBSURFACE_DIRECT, "SUBSURFACE_DIRECT", 0, "Subsurface Direct", ""},
617                 {SCE_PASS_SUBSURFACE_INDIRECT, "SUBSURFACE_INDIRECT", 0, "Subsurface Indirect", ""},
618                 {SCE_PASS_SUBSURFACE_COLOR, "SUBSURFACE_COLOR", 0, "Subsurface Color", ""},
619                 {0, NULL, 0, NULL, NULL}
620         };
621         
622         srna = RNA_def_struct(brna, "RenderPass", NULL);
623         RNA_def_struct_ui_text(srna, "Render Pass", "");
624
625         RNA_define_verify_sdna(0);
626
627         prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
628         RNA_def_property_string_sdna(prop, NULL, "name");
629         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
630         RNA_def_struct_name_property(srna, prop);
631
632         prop = RNA_def_property(srna, "channel_id", PROP_STRING, PROP_NONE);
633         RNA_def_property_string_sdna(prop, NULL, "chan_id");
634         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
635
636         prop = RNA_def_property(srna, "channels", PROP_INT, PROP_NONE);
637         RNA_def_property_int_sdna(prop, NULL, "channels");
638         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
639
640         prop = RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
641         RNA_def_property_enum_sdna(prop, NULL, "passtype");
642         RNA_def_property_enum_items(prop, pass_type_items);
643         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
644
645         prop = RNA_def_property(srna, "rect", PROP_FLOAT, PROP_NONE);
646         RNA_def_property_flag(prop, PROP_DYNAMIC);
647         RNA_def_property_multi_array(prop, 2, NULL);
648         RNA_def_property_dynamic_array_funcs(prop, "rna_RenderPass_rect_get_length");
649         RNA_def_property_float_funcs(prop, "rna_RenderPass_rect_get", "rna_RenderPass_rect_set", NULL);
650
651         RNA_define_verify_sdna(1);
652 }
653
654 void RNA_def_render(BlenderRNA *brna)
655 {
656         rna_def_render_engine(brna);
657         rna_def_render_result(brna);
658         rna_def_render_layer(brna);
659         rna_def_render_pass(brna);
660 }
661
662 #endif /* RNA_RUNTIME */