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_util.h"
26
27 #include "scene.h"
28 #include "session.h"
29
30 #include "util_map.h"
31 #include "util_set.h"
32 #include "util_transform.h"
33 #include "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 Shader;
47 class ShaderGraph;
48 class ShaderNode;
49
50 class BlenderSync {
51 public:
52         BlenderSync(BL::RenderEngine& b_engine,
53                     BL::BlendData& b_data,
54                     BL::Scene& b_scene,
55                     Scene *scene,
56                     bool preview,
57                     Progress &progress,
58                     bool is_cpu);
59         ~BlenderSync();
60
61         /* sync */
62         bool sync_recalc();
63         void sync_data(BL::RenderSettings& b_render,
64                        BL::SpaceView3D& b_v3d,
65                        BL::Object& b_override,
66                        int width, int height,
67                        void **python_thread_state,
68                        const char *layer = 0);
69         void sync_render_layers(BL::SpaceView3D& b_v3d, const char *layer);
70         void sync_integrator();
71         void sync_camera(BL::RenderSettings& b_render,
72                          BL::Object& b_override,
73                          int width, int height,
74                          const char *viewname);
75         void sync_view(BL::SpaceView3D& b_v3d,
76                        BL::RegionView3D& b_rv3d,
77                        int width, int height);
78         inline int get_layer_samples() { return render_layer.samples; }
79         inline int get_layer_bound_samples() { return render_layer.bound_samples; }
80
81         /* get parameters */
82         static SceneParams get_scene_params(BL::Scene& b_scene,
83                                             bool background,
84                                             bool is_cpu);
85         static SessionParams get_session_params(BL::RenderEngine& b_engine,
86                                                 BL::UserPreferences& b_userpref,
87                                                 BL::Scene& b_scene,
88                                                 bool background);
89         static bool get_session_pause(BL::Scene& b_scene, bool background);
90         static BufferParams get_buffer_params(BL::RenderSettings& b_render,
91                                               BL::SpaceView3D& b_v3d,
92                                               BL::RegionView3D& b_rv3d,
93                                               Camera *cam,
94                                               int width, int height);
95
96 private:
97         /* sync */
98         void sync_lamps(bool update_all);
99         void sync_materials(bool update_all);
100         void sync_objects(BL::SpaceView3D& b_v3d, float motion_time = 0.0f);
101         void sync_motion(BL::RenderSettings& b_render,
102                          BL::SpaceView3D& b_v3d,
103                          BL::Object& b_override,
104                          int width, int height,
105                          void **python_thread_state);
106         void sync_film();
107         void sync_view();
108         void sync_world(bool update_all);
109         void sync_shaders();
110         void sync_curve_settings();
111
112         void sync_nodes(Shader *shader, BL::ShaderNodeTree& b_ntree);
113         Mesh *sync_mesh(BL::Object& b_ob, bool object_updated, bool hide_tris);
114         void sync_curves(Mesh *mesh,
115                          BL::Mesh& b_mesh,
116                          BL::Object& b_ob,
117                          bool motion,
118                          int time_index = 0);
119         Object *sync_object(BL::Object& b_parent,
120                             int persistent_id[OBJECT_PERSISTENT_ID_SIZE],
121                             BL::DupliObject& b_dupli_ob,
122                             Transform& tfm,
123                             uint layer_flag,
124                             float motion_time,
125                             bool hide_tris,
126                             BlenderObjectCulling& culling,
127                             bool *use_portal);
128         void sync_light(BL::Object& b_parent,
129                         int persistent_id[OBJECT_PERSISTENT_ID_SIZE],
130                         BL::Object& b_ob,
131                         Transform& tfm,
132                         bool *use_portal);
133         void sync_background_light(bool use_portal);
134         void sync_mesh_motion(BL::Object& b_ob,
135                               Object *object,
136                               float motion_time);
137         void sync_camera_motion(BL::RenderSettings& b_render,
138                                 BL::Object& b_ob,
139                                 int width, int height,
140                                 float motion_time);
141
142         /* Images. */
143         void sync_images();
144
145         /* util */
146         void find_shader(BL::ID& id, vector<Shader*>& used_shaders, Shader *default_shader);
147         bool BKE_object_is_modified(BL::Object& b_ob);
148         bool object_is_mesh(BL::Object& b_ob);
149         bool object_is_light(BL::Object& b_ob);
150
151         /* variables */
152         BL::RenderEngine b_engine;
153         BL::BlendData b_data;
154         BL::Scene b_scene;
155
156         id_map<void*, Shader> shader_map;
157         id_map<ObjectKey, Object> object_map;
158         id_map<void*, Mesh> mesh_map;
159         id_map<ObjectKey, Light> light_map;
160         set<Mesh*> mesh_synced;
161         set<Mesh*> mesh_motion_synced;
162         set<float> motion_times;
163         void *world_map;
164         bool world_recalc;
165
166         Scene *scene;
167         bool preview;
168         bool experimental;
169         bool is_cpu;
170
171         float dicing_rate;
172         int max_subdivisions;
173
174         struct RenderLayerInfo {
175                 RenderLayerInfo()
176                 : scene_layer(0), layer(0),
177                   holdout_layer(0), exclude_layer(0),
178                   material_override(PointerRNA_NULL),
179                   use_background_shader(true),
180                   use_background_ao(true),
181                   use_surfaces(true),
182                   use_hair(true),
183                   use_viewport_visibility(false),
184                   samples(0), bound_samples(false)
185                 {}
186
187                 string name;
188                 uint scene_layer;
189                 uint layer;
190                 uint holdout_layer;
191                 uint exclude_layer;
192                 BL::Material material_override;
193                 bool use_background_shader;
194                 bool use_background_ao;
195                 bool use_surfaces;
196                 bool use_hair;
197                 bool use_viewport_visibility;
198                 int samples;
199                 bool bound_samples;
200         } render_layer;
201
202         Progress &progress;
203 };
204
205 CCL_NAMESPACE_END
206
207 #endif /* __BLENDER_SYNC_H__ */
208