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