Merging r50049 through r50076 from trunk into soc-2011-tomato
[blender.git] / intern / cycles / render / scene.h
1 /*
2  * Copyright 2011, Blender Foundation.
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
19 #ifndef __SCENE_H__
20 #define __SCENE_H__
21
22 #include "image.h"
23
24 #include "device_memory.h"
25
26 #include "kernel_types.h"
27
28 #include "util_param.h"
29 #include "util_string.h"
30 #include "util_thread.h"
31 #include "util_types.h"
32 #include "util_vector.h"
33
34 CCL_NAMESPACE_BEGIN
35
36 class AttributeRequestSet;
37 class Background;
38 class Camera;
39 class Device;
40 class DeviceInfo;
41 class Film;
42 class Filter;
43 class Integrator;
44 class Light;
45 class LightManager;
46 class Mesh;
47 class MeshManager;
48 class Object;
49 class ObjectManager;
50 class Shader;
51 class ShaderManager;
52 class Progress;
53
54 /* Scene Device Data */
55
56 class DeviceScene {
57 public:
58         /* BVH */
59         device_vector<float4> bvh_nodes;
60         device_vector<uint> object_node;
61         device_vector<float4> tri_woop;
62         device_vector<uint> prim_visibility;
63         device_vector<uint> prim_index;
64         device_vector<uint> prim_object;
65
66         /* mesh */
67         device_vector<float4> tri_normal;
68         device_vector<float4> tri_vnormal;
69         device_vector<float4> tri_vindex;
70         device_vector<float4> tri_verts;
71
72         /* objects */
73         device_vector<float4> objects;
74
75         /* attributes */
76         device_vector<uint4> attributes_map;
77         device_vector<float> attributes_float;
78         device_vector<float4> attributes_float3;
79
80         /* lights */
81         device_vector<float4> light_distribution;
82         device_vector<float4> light_data;
83         device_vector<float2> light_background_marginal_cdf;
84         device_vector<float2> light_background_conditional_cdf;
85
86         /* particles */
87         device_vector<float4> particles;
88
89         /* shaders */
90         device_vector<uint4> svm_nodes;
91         device_vector<uint> shader_flag;
92         device_vector<uint> object_flag;
93
94         /* filter */
95         device_vector<float> filter_table;
96
97         /* integrator */
98         device_vector<uint> sobol_directions;
99
100         /* images */
101         device_vector<uchar4> tex_image[TEX_EXTENDED_NUM_IMAGES];
102         device_vector<float4> tex_float_image[TEX_EXTENDED_NUM_FLOAT_IMAGES];
103
104         /* opencl images */
105         device_vector<uchar4> tex_image_packed;
106         device_vector<uint4> tex_image_packed_info;
107
108         KernelData data;
109 };
110
111 /* Scene Parameters */
112
113 class SceneParams {
114 public:
115         enum { OSL, SVM } shadingsystem;
116         enum BVHType { BVH_DYNAMIC, BVH_STATIC } bvh_type;
117         bool use_bvh_cache;
118         bool use_bvh_spatial_split;
119         bool use_qbvh;
120
121         SceneParams()
122         {
123                 shadingsystem = SVM;
124                 bvh_type = BVH_DYNAMIC;
125                 use_bvh_cache = false;
126                 use_bvh_spatial_split = false;
127 #ifdef __QBVH__
128                 use_qbvh = true;
129 #else
130                 use_qbvh = false;
131 #endif
132         }
133
134         bool modified(const SceneParams& params)
135         { return !(shadingsystem == params.shadingsystem
136                 && bvh_type == params.bvh_type
137                 && use_bvh_cache == params.use_bvh_cache
138                 && use_bvh_spatial_split == params.use_bvh_spatial_split
139                 && use_qbvh == params.use_qbvh); }
140 };
141
142 /* Scene */
143
144 class Scene {
145 public:
146         /* data */
147         Camera *camera;
148         Filter *filter;
149         Film *film;
150         Background *background;
151         Integrator *integrator;
152
153         /* data lists */
154         vector<Object*> objects;
155         vector<Mesh*> meshes;
156         vector<Shader*> shaders;
157         vector<Light*> lights;
158
159         /* data managers */
160         ImageManager *image_manager;
161         LightManager *light_manager;
162         ShaderManager *shader_manager;
163         MeshManager *mesh_manager;
164         ObjectManager *object_manager;
165
166         /* default shaders */
167         int default_surface;
168         int default_light;
169         int default_background;
170         int default_holdout;
171         int default_empty;
172
173         /* device */
174         Device *device;
175         DeviceScene dscene;
176
177         /* parameters */
178         SceneParams params;
179
180         /* mutex must be locked manually by callers */
181         thread_mutex mutex;
182
183         Scene(const SceneParams& params, const DeviceInfo& device_info);
184         ~Scene();
185
186         void device_update(Device *device, Progress& progress);
187
188         bool need_global_attribute(AttributeStandard std);
189         void need_global_attributes(AttributeRequestSet& attributes);
190
191         enum MotionType { MOTION_NONE = 0, MOTION_PASS, MOTION_BLUR };
192         MotionType need_motion();
193
194         bool need_update();
195         bool need_reset();
196 };
197
198 CCL_NAMESPACE_END
199
200 #endif /*  __SCENE_H__ */
201