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