Fix T74095: crash deleting all faces in edit mode with Cycles rendering
[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, const vector<Shader *> &used_shaders);
141
142   /* Mesh */
143   void sync_mesh(BL::Depsgraph b_depsgraph,
144                  BL::Object b_ob,
145                  Mesh *mesh,
146                  const vector<Shader *> &used_shaders);
147   void sync_mesh_motion(BL::Depsgraph b_depsgraph, BL::Object b_ob, Mesh *mesh, int motion_step);
148
149   /* Hair */
150   void sync_hair(BL::Depsgraph b_depsgraph,
151                  BL::Object b_ob,
152                  Geometry *geom,
153                  const vector<Shader *> &used_shaders);
154   void sync_hair_motion(BL::Depsgraph b_depsgraph,
155                         BL::Object b_ob,
156                         Geometry *geom,
157                         int motion_step);
158   void sync_particle_hair(
159       Geometry *geom, BL::Mesh &b_mesh, BL::Object &b_ob, bool motion, int motion_step = 0);
160   void sync_curve_settings();
161   bool object_has_particle_hair(BL::Object b_ob);
162
163   /* Camera */
164   void sync_camera_motion(
165       BL::RenderSettings &b_render, BL::Object &b_ob, int width, int height, float motion_time);
166
167   /* Geometry */
168   Geometry *sync_geometry(BL::Depsgraph &b_depsgrpah,
169                           BL::Object &b_ob,
170                           BL::Object &b_ob_instance,
171                           bool object_updated,
172                           bool use_particle_hair);
173   void sync_geometry_motion(BL::Depsgraph &b_depsgraph,
174                             BL::Object &b_ob,
175                             Object *object,
176                             float motion_time,
177                             bool use_particle_hair);
178
179   /* Light */
180   void sync_light(BL::Object &b_parent,
181                   int persistent_id[OBJECT_PERSISTENT_ID_SIZE],
182                   BL::Object &b_ob,
183                   BL::Object &b_ob_instance,
184                   int random_id,
185                   Transform &tfm,
186                   bool *use_portal);
187   void sync_background_light(BL::SpaceView3D &b_v3d, bool use_portal);
188
189   /* Particles */
190   bool sync_dupli_particle(BL::Object &b_ob,
191                            BL::DepsgraphObjectInstance &b_instance,
192                            Object *object);
193
194   /* Images. */
195   void sync_images();
196
197   /* Early data free. */
198   void free_data_after_sync(BL::Depsgraph &b_depsgraph);
199
200   /* util */
201   void find_shader(BL::ID &id, vector<Shader *> &used_shaders, Shader *default_shader);
202   bool BKE_object_is_modified(BL::Object &b_ob);
203   bool object_is_mesh(BL::Object &b_ob);
204   bool object_is_light(BL::Object &b_ob);
205
206   /* variables */
207   BL::RenderEngine b_engine;
208   BL::BlendData b_data;
209   BL::Scene b_scene;
210
211   id_map<void *, Shader> shader_map;
212   id_map<ObjectKey, Object> object_map;
213   id_map<GeometryKey, Geometry> geometry_map;
214   id_map<ObjectKey, Light> light_map;
215   id_map<ParticleSystemKey, ParticleSystem> particle_system_map;
216   set<Geometry *> geometry_synced;
217   set<Geometry *> geometry_motion_synced;
218   set<float> motion_times;
219   void *world_map;
220   bool world_recalc;
221   BlenderViewportParameters viewport_parameters;
222
223   Scene *scene;
224   bool preview;
225   bool experimental;
226
227   float dicing_rate;
228   int max_subdivisions;
229
230   struct RenderLayerInfo {
231     RenderLayerInfo()
232         : material_override(PointerRNA_NULL),
233           use_background_shader(true),
234           use_background_ao(true),
235           use_surfaces(true),
236           use_hair(true),
237           samples(0),
238           bound_samples(false)
239     {
240     }
241
242     string name;
243     BL::Material material_override;
244     bool use_background_shader;
245     bool use_background_ao;
246     bool use_surfaces;
247     bool use_hair;
248     int samples;
249     bool bound_samples;
250   } view_layer;
251
252   Progress &progress;
253 };
254
255 CCL_NAMESPACE_END
256
257 #endif /* __BLENDER_SYNC_H__ */