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