Cycles: Make all #include statements relative to cycles source directory
[blender.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 "render/image.h"
21 #include "render/shader.h"
22
23 #include "device/device_memory.h"
24
25 #include "util/util_param.h"
26 #include "util/util_string.h"
27 #include "util/util_system.h"
28 #include "util/util_texture.h"
29 #include "util/util_thread.h"
30 #include "util/util_types.h"
31 #include "util/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<uint> prim_tri_index;
67         device_vector<float4> prim_tri_verts;
68         device_vector<uint> prim_type;
69         device_vector<uint> prim_visibility;
70         device_vector<uint> prim_index;
71         device_vector<uint> prim_object;
72         device_vector<float2> prim_time;
73
74         /* mesh */
75         device_vector<uint> tri_shader;
76         device_vector<float4> tri_vnormal;
77         device_vector<uint4> tri_vindex;
78         device_vector<uint> tri_patch;
79         device_vector<float2> tri_patch_uv;
80
81         device_vector<float4> curves;
82         device_vector<float4> curve_keys;
83
84         device_vector<uint> patches;
85
86         /* objects */
87         device_vector<float4> objects;
88         device_vector<float4> objects_vector;
89
90         /* attributes */
91         device_vector<uint4> attributes_map;
92         device_vector<float> attributes_float;
93         device_vector<float4> attributes_float3;
94         device_vector<uchar4> attributes_uchar4;
95
96         /* lights */
97         device_vector<float4> light_distribution;
98         device_vector<float4> light_data;
99         device_vector<float2> light_background_marginal_cdf;
100         device_vector<float2> light_background_conditional_cdf;
101
102         /* particles */
103         device_vector<float4> particles;
104
105         /* shaders */
106         device_vector<uint4> svm_nodes;
107         device_vector<uint> shader_flag;
108         device_vector<uint> object_flag;
109
110         /* lookup tables */
111         device_vector<float> lookup_table;
112
113         /* integrator */
114         device_vector<uint> sobol_directions;
115
116         /* cpu images */
117         device_vector<uchar4> tex_byte4_image[TEX_NUM_BYTE4_CPU];
118         device_vector<float4> tex_float4_image[TEX_NUM_FLOAT4_CPU];
119         device_vector<float> tex_float_image[TEX_NUM_FLOAT_CPU];
120         device_vector<uchar> tex_byte_image[TEX_NUM_BYTE_CPU];
121         device_vector<half4> tex_half4_image[TEX_NUM_HALF4_CPU];
122         device_vector<half> tex_half_image[TEX_NUM_HALF_CPU];
123
124         /* opencl images */
125         device_vector<uchar4> tex_image_byte4_packed;
126         device_vector<float4> tex_image_float4_packed;
127         device_vector<uchar> tex_image_byte_packed;
128         device_vector<float> tex_image_float_packed;
129         device_vector<uint4> tex_image_packed_info;
130
131         KernelData data;
132 };
133
134 /* Scene Parameters */
135
136 class SceneParams {
137 public:
138         ShadingSystem shadingsystem;
139         enum BVHType {
140                 BVH_DYNAMIC = 0,
141                 BVH_STATIC = 1,
142
143                 BVH_NUM_TYPES,
144         } bvh_type;
145         bool use_bvh_spatial_split;
146         bool use_bvh_unaligned_nodes;
147         int num_bvh_time_steps;
148         bool use_qbvh;
149         bool persistent_data;
150         int texture_limit;
151
152         SceneParams()
153         {
154                 shadingsystem = SHADINGSYSTEM_SVM;
155                 bvh_type = BVH_DYNAMIC;
156                 use_bvh_spatial_split = false;
157                 use_bvh_unaligned_nodes = true;
158                 num_bvh_time_steps = 0;
159                 use_qbvh = false;
160                 persistent_data = false;
161                 texture_limit = 0;
162         }
163
164         bool modified(const SceneParams& params)
165         { return !(shadingsystem == params.shadingsystem
166                 && bvh_type == params.bvh_type
167                 && use_bvh_spatial_split == params.use_bvh_spatial_split
168                 && use_bvh_unaligned_nodes == params.use_bvh_unaligned_nodes
169                 && num_bvh_time_steps == params.num_bvh_time_steps
170                 && use_qbvh == params.use_qbvh
171                 && persistent_data == params.persistent_data
172                 && texture_limit == params.texture_limit); }
173 };
174
175 /* Scene */
176
177 class Scene {
178 public:
179         /* data */
180         Camera *camera;
181         LookupTables *lookup_tables;
182         Film *film;
183         Background *background;
184         Integrator *integrator;
185
186         /* data lists */
187         vector<Object*> objects;
188         vector<Mesh*> meshes;
189         vector<Shader*> shaders;
190         vector<Light*> lights;
191         vector<ParticleSystem*> particle_systems;
192
193         /* data managers */
194         ImageManager *image_manager;
195         LightManager *light_manager;
196         ShaderManager *shader_manager;
197         MeshManager *mesh_manager;
198         ObjectManager *object_manager;
199         ParticleSystemManager *particle_system_manager;
200         CurveSystemManager *curve_system_manager;
201         BakeManager *bake_manager;
202
203         /* default shaders */
204         Shader *default_surface;
205         Shader *default_light;
206         Shader *default_background;
207         Shader *default_empty;
208
209         /* device */
210         Device *device;
211         DeviceScene dscene;
212
213         /* parameters */
214         SceneParams params;
215
216         /* mutex must be locked manually by callers */
217         thread_mutex mutex;
218
219         Scene(const SceneParams& params, const DeviceInfo& device_info);
220         ~Scene();
221
222         void device_update(Device *device, Progress& progress);
223
224         bool need_global_attribute(AttributeStandard std);
225         void need_global_attributes(AttributeRequestSet& attributes);
226
227         enum MotionType { MOTION_NONE = 0, MOTION_PASS, MOTION_BLUR };
228         MotionType need_motion(bool advanced_shading = true);
229         float motion_shutter_time();
230
231         bool need_update();
232         bool need_reset();
233
234         void reset();
235         void device_free();
236
237 protected:
238         /* Check if some heavy data worth logging was updated.
239          * Mainly used to suppress extra annoying logging.
240          */
241         bool need_data_update();
242
243         void free_memory(bool final);
244 };
245
246 CCL_NAMESPACE_END
247
248 #endif /*  __SCENE_H__ */
249