Cycles Bake
[blender-staging.git] / intern / cycles / render / scene.h
1 /*
2  * Copyright 2011-2013 Blender Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License
15  */
16
17 #ifndef __SCENE_H__
18 #define __SCENE_H__
19
20 #include "image.h"
21
22 #include "device_memory.h"
23
24 #include "kernel_types.h"
25
26 #include "util_param.h"
27 #include "util_string.h"
28 #include "util_thread.h"
29 #include "util_types.h"
30 #include "util_vector.h"
31
32 CCL_NAMESPACE_BEGIN
33
34 class AttributeRequestSet;
35 class Background;
36 class Camera;
37 class Device;
38 class DeviceInfo;
39 class Film;
40 class Integrator;
41 class Light;
42 class LightManager;
43 class LookupTables;
44 class Mesh;
45 class MeshManager;
46 class Object;
47 class ObjectManager;
48 class ParticleSystemManager;
49 class ParticleSystem;
50 class CurveSystemManager;
51 class Shader;
52 class ShaderManager;
53 class Progress;
54 class BakeManager;
55 class BakeData;
56
57 /* Scene Device Data */
58
59 class DeviceScene {
60 public:
61         /* BVH */
62         device_vector<float4> bvh_nodes;
63         device_vector<uint> object_node;
64         device_vector<float4> tri_woop;
65         device_vector<uint> prim_type;
66         device_vector<uint> prim_visibility;
67         device_vector<uint> prim_index;
68         device_vector<uint> prim_object;
69
70         /* mesh */
71         device_vector<float4> tri_normal;
72         device_vector<float4> tri_vnormal;
73         device_vector<float4> tri_vindex;
74         device_vector<float4> tri_verts;
75
76         device_vector<float4> curves;
77         device_vector<float4> curve_keys;
78
79         /* objects */
80         device_vector<float4> objects;
81         device_vector<float4> objects_vector;
82
83         /* attributes */
84         device_vector<uint4> attributes_map;
85         device_vector<float> attributes_float;
86         device_vector<float4> attributes_float3;
87
88         /* lights */
89         device_vector<float4> light_distribution;
90         device_vector<float4> light_data;
91         device_vector<float2> light_background_marginal_cdf;
92         device_vector<float2> light_background_conditional_cdf;
93
94         /* particles */
95         device_vector<float4> particles;
96
97         /* shaders */
98         device_vector<uint4> svm_nodes;
99         device_vector<uint> shader_flag;
100         device_vector<uint> object_flag;
101
102         /* lookup tables */
103         device_vector<float> lookup_table;
104
105         /* integrator */
106         device_vector<uint> sobol_directions;
107
108         /* images */
109         device_vector<uchar4> tex_image[TEX_EXTENDED_NUM_IMAGES];
110         device_vector<float4> tex_float_image[TEX_EXTENDED_NUM_FLOAT_IMAGES];
111
112         /* opencl images */
113         device_vector<uchar4> tex_image_packed;
114         device_vector<uint4> tex_image_packed_info;
115
116         KernelData data;
117 };
118
119 /* Scene Parameters */
120
121 class SceneParams {
122 public:
123         enum { OSL, SVM } shadingsystem;
124         enum BVHType { BVH_DYNAMIC, BVH_STATIC } bvh_type;
125         bool use_bvh_cache;
126         bool use_bvh_spatial_split;
127         bool use_qbvh;
128         bool persistent_data;
129
130         SceneParams()
131         {
132                 shadingsystem = SVM;
133                 bvh_type = BVH_DYNAMIC;
134                 use_bvh_cache = false;
135                 use_bvh_spatial_split = false;
136 #ifdef __QBVH__
137                 use_qbvh = true;
138 #else
139                 use_qbvh = false;
140 #endif
141                 persistent_data = false;
142         }
143
144         bool modified(const SceneParams& params)
145         { return !(shadingsystem == params.shadingsystem
146                 && bvh_type == params.bvh_type
147                 && use_bvh_cache == params.use_bvh_cache
148                 && use_bvh_spatial_split == params.use_bvh_spatial_split
149                 && use_qbvh == params.use_qbvh
150                 && persistent_data == params.persistent_data); }
151 };
152
153 /* Scene */
154
155 class Scene {
156 public:
157         /* data */
158         Camera *camera;
159         LookupTables *lookup_tables;
160         Film *film;
161         Background *background;
162         Integrator *integrator;
163
164         /* data lists */
165         vector<Object*> objects;
166         vector<Mesh*> meshes;
167         vector<Shader*> shaders;
168         vector<Light*> lights;
169         vector<ParticleSystem*> particle_systems;
170
171         /* data managers */
172         ImageManager *image_manager;
173         LightManager *light_manager;
174         ShaderManager *shader_manager;
175         MeshManager *mesh_manager;
176         ObjectManager *object_manager;
177         ParticleSystemManager *particle_system_manager;
178         CurveSystemManager *curve_system_manager;
179         BakeManager *bake_manager;
180
181         /* default shaders */
182         int default_surface;
183         int default_light;
184         int default_background;
185         int default_empty;
186
187         /* device */
188         Device *device;
189         DeviceScene dscene;
190
191         /* parameters */
192         SceneParams params;
193
194         /* mutex must be locked manually by callers */
195         thread_mutex mutex;
196
197         Scene(const SceneParams& params, const DeviceInfo& device_info);
198         ~Scene();
199
200         void device_update(Device *device, Progress& progress);
201
202         bool need_global_attribute(AttributeStandard std);
203         void need_global_attributes(AttributeRequestSet& attributes);
204
205         enum MotionType { MOTION_NONE = 0, MOTION_PASS, MOTION_BLUR };
206         MotionType need_motion(bool advanced_shading = true);
207
208         bool need_update();
209         bool need_reset();
210
211         void reset();
212         void device_free();
213
214 protected:
215         void free_memory(bool final);
216 };
217
218 CCL_NAMESPACE_END
219
220 #endif /*  __SCENE_H__ */
221