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