Blender  V3.3
sync.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: Apache-2.0
2  * Copyright 2011-2022 Blender Foundation */
3 
4 #ifndef __BLENDER_SYNC_H__
5 #define __BLENDER_SYNC_H__
6 
7 #include "MEM_guardedalloc.h"
8 #include "RNA_access.h"
9 #include "RNA_blender_cpp.h"
10 #include "RNA_path.h"
11 #include "RNA_types.h"
12 
13 #include "blender/id_map.h"
14 #include "blender/util.h"
15 #include "blender/viewport.h"
16 
17 #include "scene/scene.h"
18 #include "session/session.h"
19 
20 #include "util/map.h"
21 #include "util/set.h"
22 #include "util/transform.h"
23 #include "util/vector.h"
24 
26 
27 class Background;
30 class Camera;
31 class Film;
32 class Hair;
33 class Light;
34 class Mesh;
35 class Object;
36 class ParticleSystem;
37 class Scene;
38 class ViewLayer;
39 class Shader;
40 class ShaderGraph;
41 class ShaderNode;
42 class TaskPool;
43 
44 class BlenderSync {
45  public:
46  BlenderSync(BL::RenderEngine &b_engine,
47  BL::BlendData &b_data,
48  BL::Scene &b_scene,
49  Scene *scene,
50  bool preview,
51  bool use_developer_ui,
52  Progress &progress);
53  ~BlenderSync();
54 
55  void reset(BL::BlendData &b_data, BL::Scene &b_scene);
56 
57  void tag_update();
58 
59  /* sync */
60  void sync_recalc(BL::Depsgraph &b_depsgraph, BL::SpaceView3D &b_v3d);
61  void sync_data(BL::RenderSettings &b_render,
62  BL::Depsgraph &b_depsgraph,
63  BL::SpaceView3D &b_v3d,
64  BL::Object &b_override,
65  int width,
66  int height,
67  void **python_thread_state);
68  void sync_view_layer(BL::ViewLayer &b_view_layer);
69  void sync_render_passes(BL::RenderLayer &b_render_layer, BL::ViewLayer &b_view_layer);
70  void sync_integrator(BL::ViewLayer &b_view_layer, bool background);
71  void sync_camera(BL::RenderSettings &b_render,
72  BL::Object &b_override,
73  int width,
74  int height,
75  const char *viewname);
76  void sync_view(BL::SpaceView3D &b_v3d, BL::RegionView3D &b_rv3d, int width, int height);
77  inline int get_layer_samples()
78  {
79  return view_layer.samples;
80  }
82  {
83  return view_layer.bound_samples;
84  }
85 
86  /* get parameters */
87  static SceneParams get_scene_params(BL::Scene &b_scene, bool background);
89  BL::Preferences &b_userpref,
90  BL::Scene &b_scene,
91  bool background);
92  static bool get_session_pause(BL::Scene &b_scene, bool background);
94  BL::SpaceView3D &b_v3d, BL::RegionView3D &b_rv3d, Camera *cam, int width, int height);
95 
97  BL::ViewLayer &b_view_layer,
98  bool background);
99 
100  private:
101  /* sync */
102  void sync_lights(BL::Depsgraph &b_depsgraph, bool update_all);
103  void sync_materials(BL::Depsgraph &b_depsgraph, bool update_all);
104  void sync_objects(BL::Depsgraph &b_depsgraph, BL::SpaceView3D &b_v3d, float motion_time = 0.0f);
105  void sync_motion(BL::RenderSettings &b_render,
106  BL::Depsgraph &b_depsgraph,
107  BL::SpaceView3D &b_v3d,
108  BL::Object &b_override,
109  int width,
110  int height,
111  void **python_thread_state);
112  void sync_film(BL::ViewLayer &b_view_layer, BL::SpaceView3D &b_v3d);
113  void sync_view();
114 
115  /* Shader */
116  array<Node *> find_used_shaders(BL::Object &b_ob);
117  void sync_world(BL::Depsgraph &b_depsgraph, BL::SpaceView3D &b_v3d, bool update_all);
118  void sync_shaders(BL::Depsgraph &b_depsgraph, BL::SpaceView3D &b_v3d, bool update_all);
119  void sync_nodes(Shader *shader, BL::ShaderNodeTree &b_ntree);
120 
121  /* Object */
122  Object *sync_object(BL::Depsgraph &b_depsgraph,
123  BL::ViewLayer &b_view_layer,
124  BL::DepsgraphObjectInstance &b_instance,
125  float motion_time,
126  bool use_particle_hair,
127  bool show_lights,
128  BlenderObjectCulling &culling,
129  bool *use_portal,
130  TaskPool *geom_task_pool);
131  void sync_object_motion_init(BL::Object &b_parent, BL::Object &b_ob, Object *object);
132 
133  void sync_procedural(BL::Object &b_ob,
134  BL::MeshSequenceCacheModifier &b_mesh_cache,
135  bool has_subdivision);
136 
137  bool sync_object_attributes(BL::DepsgraphObjectInstance &b_instance, Object *object);
138 
139  /* Volume */
140  void sync_volume(BObjectInfo &b_ob_info, Volume *volume);
141 
142  /* Mesh */
143  void sync_mesh(BL::Depsgraph b_depsgraph, BObjectInfo &b_ob_info, Mesh *mesh);
144  void sync_mesh_motion(BL::Depsgraph b_depsgraph,
145  BObjectInfo &b_ob_info,
146  Mesh *mesh,
147  int motion_step);
148 
149  /* Hair */
150  void sync_hair(BL::Depsgraph b_depsgraph, BObjectInfo &b_ob_info, Hair *hair);
151  void sync_hair_motion(BL::Depsgraph b_depsgraph,
152  BObjectInfo &b_ob_info,
153  Hair *hair,
154  int motion_step);
155  void sync_hair(Hair *hair, BObjectInfo &b_ob_info, bool motion, int motion_step = 0);
156  void sync_particle_hair(
157  Hair *hair, BL::Mesh &b_mesh, BObjectInfo &b_ob_info, bool motion, int motion_step = 0);
158  bool object_has_particle_hair(BL::Object b_ob);
159 
160  /* Point Cloud */
161  void sync_pointcloud(PointCloud *pointcloud, BObjectInfo &b_ob_info);
162  void sync_pointcloud_motion(PointCloud *pointcloud, BObjectInfo &b_ob_info, int motion_step = 0);
163 
164  /* Camera */
165  void sync_camera_motion(
166  BL::RenderSettings &b_render, BL::Object &b_ob, int width, int height, float motion_time);
167 
168  /* Geometry */
169  Geometry *sync_geometry(BL::Depsgraph &b_depsgraph,
170  BObjectInfo &b_ob_info,
171  bool object_updated,
172  bool use_particle_hair,
174 
175  void sync_geometry_motion(BL::Depsgraph &b_depsgraph,
176  BObjectInfo &b_ob_info,
177  Object *object,
178  float motion_time,
179  bool use_particle_hair,
181 
182  /* Light */
183  void sync_light(BL::Object &b_parent,
184  int persistent_id[OBJECT_PERSISTENT_ID_SIZE],
185  BObjectInfo &b_ob_info,
186  int random_id,
187  Transform &tfm,
188  bool *use_portal);
189  void sync_background_light(BL::SpaceView3D &b_v3d, bool use_portal);
190 
191  /* Particles */
192  bool sync_dupli_particle(BL::Object &b_ob,
193  BL::DepsgraphObjectInstance &b_instance,
194  Object *object);
195 
196  /* Images. */
197  void sync_images();
198 
199  /* Early data free. */
200  void free_data_after_sync(BL::Depsgraph &b_depsgraph);
201 
202  /* util */
203  void find_shader(BL::ID &id, array<Node *> &used_shaders, Shader *default_shader);
204  bool BKE_object_is_modified(BL::Object &b_ob);
205  bool object_is_geometry(BObjectInfo &b_ob_info);
206  bool object_can_have_geometry(BL::Object &b_ob);
207  bool object_is_light(BL::Object &b_ob);
208 
209  /* variables */
210  BL::RenderEngine b_engine;
211  BL::BlendData b_data;
212  BL::Scene b_scene;
213 
214  id_map<void *, Shader> shader_map;
215  id_map<ObjectKey, Object> object_map;
216  id_map<void *, Procedural> procedural_map;
217  id_map<GeometryKey, Geometry> geometry_map;
218  id_map<ObjectKey, Light> light_map;
219  id_map<ParticleSystemKey, ParticleSystem> particle_system_map;
220  set<Geometry *> geometry_synced;
221  set<Geometry *> geometry_motion_synced;
222  set<Geometry *> geometry_motion_attribute_synced;
224  map<void *, set<BL::ID>> instance_geometries_by_object;
225  set<float> motion_times;
226  void *world_map;
227  bool world_recalc;
228  BlenderViewportParameters viewport_parameters;
229 
230  Scene *scene;
231  bool preview;
232  bool experimental;
233  bool use_developer_ui;
234 
235  float dicing_rate;
236  int max_subdivisions;
237 
238  struct RenderLayerInfo {
239  RenderLayerInfo()
240  : material_override(PointerRNA_NULL),
241  use_background_shader(true),
242  use_surfaces(true),
243  use_hair(true),
244  use_volumes(true),
245  use_motion_blur(true),
246  samples(0),
247  bound_samples(false)
248  {
249  }
250 
251  string name;
252  BL::Material material_override;
253  bool use_background_shader;
254  bool use_surfaces;
255  bool use_hair;
256  bool use_volumes;
257  bool use_motion_blur;
258  int samples;
259  bool bound_samples;
260  } view_layer;
261 
262  Progress &progress;
263 
264  /* Indicates that `sync_recalc()` detected changes in the scene.
265  * If this flag is false then the data is considered to be up-to-date and will not be
266  * synchronized at all. */
267  bool has_updates_ = true;
268 };
269 
271 
272 #endif /* __BLENDER_SYNC_H__ */
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:35
struct ID ID
struct ViewLayer ViewLayer
struct Material Material
struct Mesh Mesh
struct Object Object
struct Scene Scene
struct RegionView3D RegionView3D
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei height
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei width
Read Guarded memory(de)allocation.
struct RenderEngine RenderEngine
struct RenderLayer RenderLayer
BlenderSync(BL::RenderEngine &b_engine, BL::BlendData &b_data, BL::Scene &b_scene, Scene *scene, bool preview, bool use_developer_ui, Progress &progress)
Definition: sync.cpp:38
static DenoiseParams get_denoise_params(BL::Scene &b_scene, BL::ViewLayer &b_view_layer, bool background)
Definition: sync.cpp:955
~BlenderSync()
Definition: sync.cpp:71
static bool get_session_pause(BL::Scene &b_scene, bool background)
Definition: sync.cpp:857
void sync_recalc(BL::Depsgraph &b_depsgraph, BL::SpaceView3D &b_v3d)
Definition: sync.cpp:92
void tag_update()
Definition: sync.cpp:85
static SceneParams get_scene_params(BL::Scene &b_scene, bool background)
Definition: sync.cpp:808
void sync_camera(BL::RenderSettings &b_render, BL::Object &b_override, int width, int height, const char *viewname)
void sync_render_passes(BL::RenderLayer &b_render_layer, BL::ViewLayer &b_view_layer)
Definition: sync.cpp:631
int get_layer_bound_samples()
Definition: sync.h:81
void sync_view_layer(BL::ViewLayer &b_view_layer)
Definition: sync.cpp:495
static BufferParams get_buffer_params(BL::SpaceView3D &b_v3d, BL::RegionView3D &b_rv3d, Camera *cam, int width, int height)
void sync_view(BL::SpaceView3D &b_v3d, BL::RegionView3D &b_rv3d, int width, int height)
void sync_data(BL::RenderSettings &b_render, BL::Depsgraph &b_depsgraph, BL::SpaceView3D &b_v3d, BL::Object &b_override, int width, int height, void **python_thread_state)
Definition: sync.cpp:241
void reset(BL::BlendData &b_data, BL::Scene &b_scene)
Definition: sync.cpp:75
int get_layer_samples()
Definition: sync.h:77
static SessionParams get_session_params(BL::RenderEngine &b_engine, BL::Preferences &b_userpref, BL::Scene &b_scene, bool background)
Definition: sync.cpp:863
void sync_integrator(BL::ViewLayer &b_view_layer, bool background)
Definition: sync.cpp:295
Definition: film.h:29
Definition: hair.h:13
#define CCL_NAMESPACE_END
Definition: cuda/compat.h:9
Scene scene
TaskPool * task_pool
@ OBJECT_PERSISTENT_ID_SIZE
Definition: id_map.h:186
const PointerRNA PointerRNA_NULL
Definition: rna_access.c:61