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