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