b29aff88c01c3803a2376198a50039f8b5fcbcba
[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 #include "shader.h"
22
23 #include "device_memory.h"
24
25 #include "util_param.h"
26 #include "util_string.h"
27 #include "util_system.h"
28 #include "util_texture.h"
29 #include "util_thread.h"
30 #include "util_types.h"
31 #include "util_vector.h"
32
33 CCL_NAMESPACE_BEGIN
34
35 class AttributeRequestSet;
36 class Background;
37 class Camera;
38 class Device;
39 class DeviceInfo;
40 class Film;
41 class Integrator;
42 class Light;
43 class LightManager;
44 class LookupTables;
45 class Mesh;
46 class MeshManager;
47 class Object;
48 class ObjectManager;
49 class ParticleSystemManager;
50 class ParticleSystem;
51 class CurveSystemManager;
52 class Shader;
53 class ShaderManager;
54 class Progress;
55 class BakeManager;
56 class BakeData;
57
58 /* Scene Device Data */
59
60 class DeviceScene {
61 public:
62         /* BVH */
63         device_vector<float4> bvh_nodes;
64         device_vector<float4> bvh_leaf_nodes;
65         device_vector<uint> object_node;
66         device_vector<float4> tri_storage;
67         device_vector<uint> prim_type;
68         device_vector<uint> prim_visibility;
69         device_vector<uint> prim_index;
70         device_vector<uint> prim_object;
71
72         /* mesh */
73         device_vector<uint> tri_shader;
74         device_vector<float4> tri_vnormal;
75         device_vector<float4> tri_vindex;
76         device_vector<float4> tri_verts;
77
78         device_vector<float4> curves;
79         device_vector<float4> curve_keys;
80
81         /* objects */
82         device_vector<float4> objects;
83         device_vector<float4> objects_vector;
84
85         /* attributes */
86         device_vector<uint4> attributes_map;
87         device_vector<float> attributes_float;
88         device_vector<float4> attributes_float3;
89         device_vector<uchar4> attributes_uchar4;
90
91         /* lights */
92         device_vector<float4> light_distribution;
93         device_vector<float4> light_data;
94         device_vector<float2> light_background_marginal_cdf;
95         device_vector<float2> light_background_conditional_cdf;
96
97         /* particles */
98         device_vector<float4> particles;
99
100         /* shaders */
101         device_vector<uint4> svm_nodes;
102         device_vector<uint> shader_flag;
103         device_vector<uint> object_flag;
104
105         /* lookup tables */
106         device_vector<float> lookup_table;
107
108         /* integrator */
109         device_vector<uint> sobol_directions;
110
111         /* cpu images */
112         device_vector<uchar4> tex_image[TEX_NUM_BYTE_IMAGES_CPU];
113         device_vector<float4> tex_float_image[TEX_NUM_FLOAT_IMAGES_CPU];
114
115         /* opencl images */
116         device_vector<uchar4> tex_image_packed;
117         device_vector<uint4> tex_image_packed_info;
118
119         KernelData data;
120 };
121
122 /* Scene Parameters */
123
124 class SceneParams {
125 public:
126         ShadingSystem shadingsystem;
127         enum BVHType {
128                 BVH_DYNAMIC = 0,
129                 BVH_STATIC = 1,
130
131                 BVH_NUM_TYPES,
132         } bvh_type;
133         bool use_bvh_spatial_split;
134         bool use_qbvh;
135         bool persistent_data;
136
137         SceneParams()
138         {
139                 shadingsystem = SHADINGSYSTEM_SVM;
140                 bvh_type = BVH_DYNAMIC;
141                 use_bvh_spatial_split = false;
142                 use_qbvh = false;
143                 persistent_data = false;
144         }
145
146         bool modified(const SceneParams& params)
147         { return !(shadingsystem == params.shadingsystem
148                 && bvh_type == params.bvh_type
149                 && use_bvh_spatial_split == params.use_bvh_spatial_split
150                 && use_qbvh == params.use_qbvh
151                 && persistent_data == params.persistent_data); }
152 };
153
154 /* Scene */
155
156 class Scene {
157 public:
158         /* data */
159         Camera *camera;
160         LookupTables *lookup_tables;
161         Film *film;
162         Background *background;
163         Integrator *integrator;
164
165         /* data lists */
166         vector<Object*> objects;
167         vector<Mesh*> meshes;
168         vector<Shader*> shaders;
169         vector<Light*> lights;
170         vector<ParticleSystem*> particle_systems;
171
172         /* data managers */
173         ImageManager *image_manager;
174         LightManager *light_manager;
175         ShaderManager *shader_manager;
176         MeshManager *mesh_manager;
177         ObjectManager *object_manager;
178         ParticleSystemManager *particle_system_manager;
179         CurveSystemManager *curve_system_manager;
180         BakeManager *bake_manager;
181
182         /* default shaders */
183         int default_surface;
184         int default_light;
185         int default_background;
186         int default_empty;
187
188         /* device */
189         Device *device;
190         DeviceScene dscene;
191
192         /* parameters */
193         SceneParams params;
194
195         /* mutex must be locked manually by callers */
196         thread_mutex mutex;
197
198         Scene(const SceneParams& params, const DeviceInfo& device_info);
199         ~Scene();
200
201         void device_update(Device *device, Progress& progress);
202
203         bool need_global_attribute(AttributeStandard std);
204         void need_global_attributes(AttributeRequestSet& attributes);
205
206         enum MotionType { MOTION_NONE = 0, MOTION_PASS, MOTION_BLUR };
207         MotionType need_motion(bool advanced_shading = true);
208
209         bool need_update();
210         bool need_reset();
211
212         void reset();
213         void device_free();
214
215 protected:
216         /* Check if some heavy data worth logging was updated.
217          * Mainly used to suppress extra annoying logging.
218          */
219         bool need_data_update();
220
221         void free_memory(bool final);
222 };
223
224 CCL_NAMESPACE_END
225
226 #endif /*  __SCENE_H__ */
227