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