Cycles: svn merge -r41225:41232 ^/trunk/blender
[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         enum BVHType { BVH_DYNAMIC, BVH_STATIC } bvh_type;
104         bool use_bvh_cache;
105         bool use_bvh_spatial_split;
106         bool use_qbvh;
107
108         SceneParams()
109         {
110                 shadingsystem = SVM;
111                 bvh_type = BVH_DYNAMIC;
112                 use_bvh_cache = false;
113                 use_bvh_spatial_split = false;
114 #ifdef __QBVH__
115                 use_qbvh = true;
116 #else
117                 use_qbvh = false;
118 #endif
119         }
120
121         bool modified(const SceneParams& params)
122         { return !(shadingsystem == params.shadingsystem
123                 && bvh_type == params.bvh_type
124                 && use_bvh_cache == params.use_bvh_cache
125                 && use_bvh_spatial_split == params.use_bvh_spatial_split
126                 && use_qbvh == params.use_qbvh); }
127 };
128
129 /* Scene */
130
131 class Scene {
132 public:
133         /* data */
134         Camera *camera;
135         Filter *filter;
136         Film *film;
137         Background *background;
138         Integrator *integrator;
139
140         /* data lists */
141         vector<Object*> objects;
142         vector<Mesh*> meshes;
143         vector<Shader*> shaders;
144         vector<Light*> lights;
145
146         /* data managers */
147         ImageManager *image_manager;
148         LightManager *light_manager;
149         ShaderManager *shader_manager;
150         MeshManager *mesh_manager;
151         ObjectManager *object_manager;
152
153         /* default shaders */
154         int default_surface;
155         int default_light;
156         int default_background;
157
158         /* device */
159         Device *device;
160         DeviceScene dscene;
161
162         /* parameters */
163         SceneParams params;
164
165         /* mutex must be locked manually by callers */
166         thread_mutex mutex;
167
168         Scene(const SceneParams& params);
169         ~Scene();
170
171         void device_update(Device *device, Progress& progress);
172
173         bool need_update();
174         bool need_reset();
175 };
176
177 CCL_NAMESPACE_END
178
179 #endif /*  __SCENE_H__ */
180