add BLI_strcpy_rlen, replace strcat, which was used in misleading way.
[blender.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 DeviceInfo;
41 class Film;
42 class Integrator;
43 class Light;
44 class LightManager;
45 class LookupTables;
46 class Mesh;
47 class MeshManager;
48 class Object;
49 class ObjectManager;
50 class ParticleSystemManager;
51 class ParticleSystem;
52 class CurveSystemManager;
53 class Shader;
54 class ShaderManager;
55 class Progress;
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_segment;
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         }
142
143         bool modified(const SceneParams& params)
144         { return !(shadingsystem == params.shadingsystem
145                 && bvh_type == params.bvh_type
146                 && use_bvh_cache == params.use_bvh_cache
147                 && use_bvh_spatial_split == params.use_bvh_spatial_split
148                 && use_qbvh == params.use_qbvh
149                 && persistent_data == params.persistent_data); }
150 };
151
152 /* Scene */
153
154 class Scene {
155 public:
156         /* data */
157         Camera *camera;
158         LookupTables *lookup_tables;
159         Film *film;
160         Background *background;
161         Integrator *integrator;
162
163         /* data lists */
164         vector<Object*> objects;
165         vector<Mesh*> meshes;
166         vector<Shader*> shaders;
167         vector<Light*> lights;
168         vector<ParticleSystem*> particle_systems;
169
170         /* data managers */
171         ImageManager *image_manager;
172         LightManager *light_manager;
173         ShaderManager *shader_manager;
174         MeshManager *mesh_manager;
175         ObjectManager *object_manager;
176         ParticleSystemManager *particle_system_manager;
177         CurveSystemManager *curve_system_manager;
178
179         /* default shaders */
180         int default_surface;
181         int default_light;
182         int default_background;
183         int default_holdout;
184         int default_empty;
185
186         /* device */
187         Device *device;
188         DeviceScene dscene;
189
190         /* parameters */
191         SceneParams params;
192
193         /* mutex must be locked manually by callers */
194         thread_mutex mutex;
195
196         Scene(const SceneParams& params, const DeviceInfo& device_info);
197         ~Scene();
198
199         void device_update(Device *device, Progress& progress);
200
201         bool need_global_attribute(AttributeStandard std);
202         void need_global_attributes(AttributeRequestSet& attributes);
203
204         enum MotionType { MOTION_NONE = 0, MOTION_PASS, MOTION_BLUR };
205         MotionType need_motion(bool advanced_shading = true);
206
207         bool need_update();
208         bool need_reset();
209
210         void reset();
211         void device_free();
212
213 protected:
214         void free_memory(bool final);
215 };
216
217 CCL_NAMESPACE_END
218
219 #endif /*  __SCENE_H__ */
220