7eacb4079e57521871609f43d8211c3e57aad395
[blender-staging.git] / source / blender / makesrna / intern / rna_render.c
1 /**
2  * $Id: rna_render.c 21648 2009-07-17 02:31:28Z campbellbarton $
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
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.
10  *
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.
15  *
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19  *
20  * Contributor(s): Blender Foundation (2009)
21  *
22  * ***** END GPL LICENSE BLOCK *****
23  */
24
25 #include <stdlib.h>
26
27 #include "DNA_scene_types.h"
28
29 #include "RNA_define.h"
30 #include "RNA_types.h"
31
32 #include "rna_internal.h"
33
34 #include "WM_types.h"
35
36 #include "RE_pipeline.h"
37 #include "RE_render_ext.h"
38
39 #ifdef RNA_RUNTIME
40
41 #include "MEM_guardedalloc.h"
42
43 #include "RNA_access.h"
44
45 #include "BKE_context.h"
46 #include "BKE_report.h"
47
48 #include "WM_api.h"
49
50 static void rna_RenderResult_layers_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
51 {
52         RenderResult *rr= (RenderResult*)ptr->data;
53         rna_iterator_listbase_begin(iter, &rr->layers, NULL);
54 }
55
56 static void rna_RenderLayer_passes_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
57 {
58         RenderLayer *rl= (RenderLayer*)ptr->data;
59         rna_iterator_listbase_begin(iter, &rl->passes, NULL);
60 }
61
62 static float rna_RenderValue_value_get(PointerRNA *ptr)
63 {
64         return *(float*)ptr->data;
65 }
66
67 static void rna_RenderValue_value_set(PointerRNA *ptr, float value)
68 {
69         *(float*)ptr->data= value;
70 }
71
72 static void rna_RenderLayer_rect_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
73 {
74         RenderLayer *rl= (RenderLayer*)ptr->data;
75         rna_iterator_array_begin(iter, (void*)rl->rectf, sizeof(float), rl->rectx*rl->recty*4, 0, NULL);
76 }
77
78 static int rna_RenderLayer_rect_length(PointerRNA *ptr)
79 {
80         RenderLayer *rl= (RenderLayer*)ptr->data;
81         return rl->rectx*rl->recty*4;
82 }
83
84 static void rna_RenderPass_rect_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
85 {
86         RenderPass *rpass= (RenderPass*)ptr->data;
87         rna_iterator_array_begin(iter, (void*)rpass->rect, sizeof(float), rpass->rectx*rpass->recty*rpass->channels, 0, NULL);
88 }
89
90 static int rna_RenderPass_rect_length(PointerRNA *ptr)
91 {
92         RenderPass *rpass= (RenderPass*)ptr->data;
93         return rpass->rectx*rpass->recty*rpass->channels;
94 }
95
96
97 #else // RNA_RUNTIME
98
99 static void rna_def_render_result(BlenderRNA *brna)
100 {
101         StructRNA *srna;
102         PropertyRNA *prop;
103         
104         srna= RNA_def_struct(brna, "RenderResult", NULL);
105         RNA_def_struct_ui_text(srna, "Render Result", "Result of rendering, including all layers and passes.");
106
107         RNA_define_verify_sdna(0);
108
109         prop= RNA_def_property(srna, "resolution_x", PROP_INT, PROP_NONE);
110         RNA_def_property_int_sdna(prop, NULL, "rectx");
111         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
112
113         prop= RNA_def_property(srna, "resolution_y", PROP_INT, PROP_NONE);
114         RNA_def_property_int_sdna(prop, NULL, "recty");
115         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
116
117         prop= RNA_def_property(srna, "layers", PROP_COLLECTION, PROP_NONE);
118         RNA_def_property_struct_type(prop, "RenderLayer");
119         RNA_def_property_collection_funcs(prop, "rna_RenderResult_layers_begin", "rna_iterator_listbase_next", "rna_iterator_listbase_end", "rna_iterator_listbase_get", 0, 0, 0, 0, 0);
120
121         RNA_define_verify_sdna(1);
122 }
123
124 static void rna_def_render_layer(BlenderRNA *brna)
125 {
126         StructRNA *srna;
127         PropertyRNA *prop;
128         
129         srna= RNA_def_struct(brna, "RenderLayer", NULL);
130         RNA_def_struct_ui_text(srna, "Render Layer", "");
131
132         RNA_define_verify_sdna(0);
133
134         rna_def_render_layer_common(srna, 0);
135
136         prop= RNA_def_property(srna, "passes", PROP_COLLECTION, PROP_NONE);
137         RNA_def_property_struct_type(prop, "RenderPass");
138         RNA_def_property_collection_funcs(prop, "rna_RenderLayer_passes_begin", "rna_iterator_listbase_next", "rna_iterator_listbase_end", "rna_iterator_listbase_get", 0, 0, 0, 0, 0);
139
140         prop= RNA_def_property(srna, "rect", PROP_COLLECTION, PROP_NONE);
141         RNA_def_property_struct_type(prop, "RenderValue");
142         RNA_def_property_collection_funcs(prop, "rna_RenderLayer_rect_begin", "rna_iterator_array_next", "rna_iterator_array_end", "rna_iterator_array_get", "rna_RenderLayer_rect_length", 0, 0, 0, 0);
143
144         /* value */
145         srna= RNA_def_struct(brna, "RenderValue", NULL);
146         RNA_def_struct_ui_text(srna, "Render Value", "");
147
148         prop= RNA_def_property(srna, "value", PROP_FLOAT, PROP_NONE);
149         RNA_def_property_float_funcs(prop, "rna_RenderValue_value_get", "rna_RenderValue_value_set", NULL);
150
151         RNA_define_verify_sdna(1);
152 }
153
154 static void rna_def_render_pass(BlenderRNA *brna)
155 {
156         StructRNA *srna;
157         PropertyRNA *prop;
158
159         static EnumPropertyItem pass_type_items[]= {
160                 {SCE_PASS_COMBINED, "COMBINED", 0, "Combined", ""},
161                 {SCE_PASS_Z, "Z", 0, "Z", ""},
162                 {SCE_PASS_RGBA, "COLOR", 0, "Color", ""},
163                 {SCE_PASS_DIFFUSE, "DIFFUSE", 0, "Diffuse", ""},
164                 {SCE_PASS_SPEC, "SPECULAR", 0, "Specular", ""},
165                 {SCE_PASS_SHADOW, "SHADOW", 0, "Shadow", ""},
166                 {SCE_PASS_AO, "AO", 0, "AO", ""},
167                 {SCE_PASS_REFLECT, "REFLECTION", 0, "Reflection", ""},
168                 {SCE_PASS_NORMAL, "NORMAL", 0, "Normal", ""},
169                 {SCE_PASS_VECTOR, "VECTOR", 0, "Vecotr", ""},
170                 {SCE_PASS_REFRACT, "REFRACTION", 0, "Refraction", ""},
171                 {SCE_PASS_INDEXOB, "OBJECT_INDEX", 0, "Object Index", ""},
172                 {SCE_PASS_UV, "UV", 0, "UV", ""},
173                 {SCE_PASS_MIST, "MIST", 0, "Mist", ""},
174                 {0, NULL, 0, NULL, NULL}};
175         
176         srna= RNA_def_struct(brna, "RenderPass", NULL);
177         RNA_def_struct_ui_text(srna, "Render Pass", "");
178
179         RNA_define_verify_sdna(0);
180
181         prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
182         RNA_def_property_string_sdna(prop, NULL, "name");
183         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
184         RNA_def_struct_name_property(srna, prop);
185
186         prop= RNA_def_property(srna, "channel_id", PROP_STRING, PROP_NONE);
187         RNA_def_property_string_sdna(prop, NULL, "chan_id");
188         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
189
190         prop= RNA_def_property(srna, "channels", PROP_INT, PROP_NONE);
191         RNA_def_property_int_sdna(prop, NULL, "channels");
192         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
193
194         prop= RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
195         RNA_def_property_enum_sdna(prop, NULL, "passtype");
196         RNA_def_property_enum_items(prop, pass_type_items);
197         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
198
199         prop= RNA_def_property(srna, "rect", PROP_COLLECTION, PROP_NONE);
200         RNA_def_property_struct_type(prop, "RenderValue");
201         RNA_def_property_collection_funcs(prop, "rna_RenderPass_rect_begin", "rna_iterator_array_next", "rna_iterator_array_end", "rna_iterator_array_get", "rna_RenderPass_rect_length", 0, 0, 0, 0);
202
203         RNA_define_verify_sdna(1);
204 }
205
206 void RNA_def_render(BlenderRNA *brna)
207 {
208         rna_def_render_result(brna);
209         rna_def_render_layer(brna);
210         rna_def_render_pass(brna);
211 }
212
213 #endif // RNA_RUNTIME
214