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