Cycles: distance culling for objects.
[blender-staging.git] / intern / cycles / blender / blender_sync.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 __BLENDER_SYNC_H__
18 #define __BLENDER_SYNC_H__
19
20 #include "MEM_guardedalloc.h"
21 #include "RNA_types.h"
22 #include "RNA_access.h"
23 #include "RNA_blender_cpp.h"
24
25 #include "blender_util.h"
26
27 #include "scene.h"
28 #include "session.h"
29
30 #include "util_map.h"
31 #include "util_set.h"
32 #include "util_transform.h"
33 #include "util_vector.h"
34
35 CCL_NAMESPACE_BEGIN
36
37 class Background;
38 class Camera;
39 class Film;
40 class Light;
41 class Mesh;
42 class Object;
43 class ParticleSystem;
44 class Scene;
45 class Shader;
46 class ShaderGraph;
47 class ShaderNode;
48
49 class BlenderSync {
50 public:
51         BlenderSync(BL::RenderEngine& b_engine,
52                     BL::BlendData& b_data,
53                     BL::Scene& b_scene,
54                     Scene *scene,
55                     bool preview,
56                     Progress &progress,
57                     bool is_cpu);
58         ~BlenderSync();
59
60         /* sync */
61         bool sync_recalc();
62         void sync_data(BL::RenderSettings& b_render,
63                        BL::SpaceView3D& b_v3d,
64                        BL::Object& b_override,
65                        int width, int height,
66                        void **python_thread_state,
67                        const char *layer = 0);
68         void sync_render_layers(BL::SpaceView3D& b_v3d, const char *layer);
69         void sync_integrator();
70         void sync_camera(BL::RenderSettings& b_render,
71                          BL::Object& b_override,
72                          int width, int height,
73                          const char *viewname);
74         void sync_view(BL::SpaceView3D& b_v3d,
75                        BL::RegionView3D& b_rv3d,
76                        int width, int height);
77         inline int get_layer_samples() { return render_layer.samples; }
78         inline int get_layer_bound_samples() { return render_layer.bound_samples; }
79
80         /* get parameters */
81         static SceneParams get_scene_params(BL::Scene& b_scene,
82                                             bool background,
83                                             bool is_cpu);
84         static SessionParams get_session_params(BL::RenderEngine& b_engine,
85                                                 BL::UserPreferences& b_userpref,
86                                                 BL::Scene& b_scene,
87                                                 bool background);
88         static bool get_session_pause(BL::Scene& b_scene, bool background);
89         static BufferParams get_buffer_params(BL::RenderSettings& b_render,
90                                               BL::SpaceView3D& b_v3d,
91                                               BL::RegionView3D& b_rv3d,
92                                               Camera *cam,
93                                               int width, int height);
94
95 private:
96         /* sync */
97         void sync_lamps(bool update_all);
98         void sync_materials(bool update_all);
99         void sync_objects(BL::SpaceView3D& b_v3d, float motion_time = 0.0f);
100         void sync_motion(BL::RenderSettings& b_render,
101                          BL::SpaceView3D& b_v3d,
102                          BL::Object& b_override,
103                          int width, int height,
104                          void **python_thread_state);
105         void sync_film();
106         void sync_view();
107         void sync_world(bool update_all);
108         void sync_shaders();
109         void sync_curve_settings();
110
111         void sync_nodes(Shader *shader, BL::ShaderNodeTree& b_ntree);
112         Mesh *sync_mesh(BL::Object& b_ob, bool object_updated, bool hide_tris);
113         void sync_curves(Mesh *mesh,
114                          BL::Mesh& b_mesh,
115                          BL::Object& b_ob,
116                          bool motion,
117                          int time_index = 0);
118         Object *sync_object(BL::Object& b_parent,
119                             int persistent_id[OBJECT_PERSISTENT_ID_SIZE],
120                             BL::DupliObject& b_dupli_ob,
121                             Transform& tfm,
122                             uint layer_flag,
123                             float motion_time,
124                             bool hide_tris,
125                             bool use_camera_cull,
126                             bool use_distance_cull,
127                             float camera_cull_margin,
128                             float distance_cull_margin,
129                             bool *use_portal);
130         void sync_light(BL::Object& b_parent,
131                         int persistent_id[OBJECT_PERSISTENT_ID_SIZE],
132                         BL::Object& b_ob,
133                         Transform& tfm,
134                         bool *use_portal);
135         void sync_background_light(bool use_portal);
136         void sync_mesh_motion(BL::Object& b_ob,
137                               Object *object,
138                               float motion_time);
139         void sync_camera_motion(BL::RenderSettings& b_render,
140                                 BL::Object& b_ob,
141                                 int width, int height,
142                                 float motion_time);
143
144         /* particles */
145         bool sync_dupli_particle(BL::Object& b_ob,
146                                  BL::DupliObject& b_dup,
147                                  Object *object);
148
149         /* Images. */
150         void sync_images();
151
152         /* util */
153         void find_shader(BL::ID& id, vector<Shader*>& used_shaders, Shader *default_shader);
154         bool BKE_object_is_modified(BL::Object& b_ob);
155         bool object_is_mesh(BL::Object& b_ob);
156         bool object_is_light(BL::Object& b_ob);
157
158         /* variables */
159         BL::RenderEngine b_engine;
160         BL::BlendData b_data;
161         BL::Scene b_scene;
162
163         id_map<void*, Shader> shader_map;
164         id_map<ObjectKey, Object> object_map;
165         id_map<void*, Mesh> mesh_map;
166         id_map<ObjectKey, Light> light_map;
167         id_map<ParticleSystemKey, ParticleSystem> particle_system_map;
168         set<Mesh*> mesh_synced;
169         set<Mesh*> mesh_motion_synced;
170         set<float> motion_times;
171         void *world_map;
172         bool world_recalc;
173
174         Scene *scene;
175         bool preview;
176         bool experimental;
177         bool is_cpu;
178
179         float dicing_rate;
180         int max_subdivisions;
181
182         struct RenderLayerInfo {
183                 RenderLayerInfo()
184                 : scene_layer(0), layer(0),
185                   holdout_layer(0), exclude_layer(0),
186                   material_override(PointerRNA_NULL),
187                   use_background_shader(true),
188                   use_background_ao(true),
189                   use_surfaces(true),
190                   use_hair(true),
191                   use_viewport_visibility(false),
192                   samples(0), bound_samples(false)
193                 {}
194
195                 string name;
196                 uint scene_layer;
197                 uint layer;
198                 uint holdout_layer;
199                 uint exclude_layer;
200                 BL::Material material_override;
201                 bool use_background_shader;
202                 bool use_background_ao;
203                 bool use_surfaces;
204                 bool use_hair;
205                 bool use_viewport_visibility;
206                 int samples;
207                 bool bound_samples;
208         } render_layer;
209
210         Progress &progress;
211 };
212
213 CCL_NAMESPACE_END
214
215 #endif /* __BLENDER_SYNC_H__ */
216