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