1db3f5d4e99a4c67c6791f090090ec9d8a1b2e1b
[blender.git] / source / blender / depsgraph / intern / builder / deg_builder_nodes.h
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2013 Blender Foundation.
19  * All rights reserved.
20  *
21  * Original Author: Lukas Toenne
22  * Contributor(s): None Yet
23  *
24  * ***** END GPL LICENSE BLOCK *****
25  */
26
27 /** \file blender/depsgraph/intern/builder/deg_builder_nodes.h
28  *  \ingroup depsgraph
29  */
30
31 #pragma once
32
33 #include "intern/builder/deg_builder_map.h"
34 #include "intern/depsgraph_types.h"
35
36 #include "DEG_depsgraph.h"
37
38 #include "intern/nodes/deg_node_id.h"
39
40 struct Base;
41 struct CacheFile;
42 struct Camera;
43 struct Collection;
44 struct FCurve;
45 struct GHash;
46 struct ID;
47 struct Image;
48 struct Key;
49 struct Lamp;
50 struct LayerCollection;
51 struct LightProbe;
52 struct ListBase;
53 struct MTex;
54 struct Main;
55 struct Mask;
56 struct Material;
57 struct MovieClip;
58 struct Object;
59 struct ParticleSettings;
60 struct Probe;
61 struct Scene;
62 struct Speaker;
63 struct Tex;
64 struct World;
65 struct bAction;
66 struct bArmature;
67 struct bConstraint;
68 struct bGPdata;
69 struct bNodeTree;
70 struct bPoseChannel;
71
72 struct PropertyRNA;
73
74 namespace DEG {
75
76 struct ComponentDepsNode;
77 struct DepsNode;
78 struct Depsgraph;
79 struct IDDepsNode;
80 struct OperationDepsNode;
81 struct TimeSourceDepsNode;
82
83 struct DepsgraphNodeBuilder {
84         DepsgraphNodeBuilder(Main *bmain, Depsgraph *graph);
85         ~DepsgraphNodeBuilder();
86
87         /* For given original ID get ID which is created by CoW system. */
88         ID *get_cow_id(const ID *id_orig) const;
89         /* Similar to above, but for the cases when there is no ID node we create
90          * one.
91          */
92         ID *ensure_cow_id(ID *id_orig);
93
94         /* Helper wrapper function which wraps get_cow_id with a needed type cast. */
95         template<typename T>
96         T *get_cow_datablock(const T *orig) const {
97                 return (T *)get_cow_id(&orig->id);
98         }
99
100         /* For a given COW datablock get corresponding original one. */
101         template<typename T>
102         T *get_orig_datablock(const T *cow) const {
103                 return (T *)cow->id.orig_id;
104         }
105
106         void begin_build();
107         void end_build();
108
109         IDDepsNode *add_id_node(ID *id);
110         IDDepsNode *find_id_node(ID *id);
111         TimeSourceDepsNode *add_time_source();
112
113         ComponentDepsNode *add_component_node(ID *id,
114                                               eDepsNode_Type comp_type,
115                                               const char *comp_name = "");
116
117         OperationDepsNode *add_operation_node(ComponentDepsNode *comp_node,
118                                               const DepsEvalOperationCb& op,
119                                               eDepsOperation_Code opcode,
120                                               const char *name = "",
121                                               int name_tag = -1);
122         OperationDepsNode *add_operation_node(ID *id,
123                                               eDepsNode_Type comp_type,
124                                               const char *comp_name,
125                                               const DepsEvalOperationCb& op,
126                                               eDepsOperation_Code opcode,
127                                               const char *name = "",
128                                               int name_tag = -1);
129         OperationDepsNode *add_operation_node(ID *id,
130                                               eDepsNode_Type comp_type,
131                                               const DepsEvalOperationCb& op,
132                                               eDepsOperation_Code opcode,
133                                               const char *name = "",
134                                               int name_tag = -1);
135
136         OperationDepsNode *ensure_operation_node(ID *id,
137                                                  eDepsNode_Type comp_type,
138                                                  const DepsEvalOperationCb& op,
139                                                  eDepsOperation_Code opcode,
140                                                  const char *name = "",
141                                                  int name_tag = -1);
142
143         bool has_operation_node(ID *id,
144                                 eDepsNode_Type comp_type,
145                                 const char *comp_name,
146                                 eDepsOperation_Code opcode,
147                                 const char *name = "",
148                                 int name_tag = -1);
149
150         OperationDepsNode *find_operation_node(ID *id,
151                                                eDepsNode_Type comp_type,
152                                                const char *comp_name,
153                                                eDepsOperation_Code opcode,
154                                                const char *name = "",
155                                                int name_tag = -1);
156
157         OperationDepsNode *find_operation_node(ID *id,
158                                                eDepsNode_Type comp_type,
159                                                eDepsOperation_Code opcode,
160                                                const char *name = "",
161                                                int name_tag = -1);
162
163         void build_id(ID *id);
164         void build_layer_collections(ListBase *lb);
165         void build_view_layer(Scene *scene,
166                               ViewLayer *view_layer,
167                               eDepsNode_LinkedState_Type linked_state);
168         void build_collection(LayerCollection *from_layer_collection,
169                               Collection *collection);
170         void build_object(int base_index,
171                           Object *object,
172                           eDepsNode_LinkedState_Type linked_state,
173                           bool is_visible);
174         void build_object_flags(int base_index,
175                                 Object *object,
176                                 eDepsNode_LinkedState_Type linked_state);
177         void build_object_data(Object *object, bool is_object_visible);
178         void build_object_data_camera(Object *object);
179         void build_object_data_geometry(Object *object, bool is_object_visible);
180         void build_object_data_geometry_datablock(ID *obdata,
181                                                   bool is_object_visible);
182         void build_object_data_lamp(Object *object);
183         void build_object_data_lightprobe(Object *object);
184         void build_object_data_speaker(Object *object);
185         void build_object_transform(Object *object);
186         void build_object_constraints(Object *object);
187         void build_object_pointcache(Object *object);
188         void build_pose_constraints(Object *object,
189                                     bPoseChannel *pchan,
190                                     int pchan_index,
191                                     bool is_object_visible);
192         void build_rigidbody(Scene *scene);
193         void build_particle_systems(Object *object, bool is_object_visible);
194         void build_particle_settings(ParticleSettings *part);
195         void build_animdata(ID *id);
196         void build_animdata_nlastrip_targets(ListBase *strips);
197         void build_action(bAction *action);
198         void build_driver(ID *id, FCurve *fcurve, int driver_index);
199         void build_driver_variables(ID *id, FCurve *fcurve);
200         void build_driver_id_property(ID *id, const char *rna_path);
201         void build_ik_pose(Object *object,
202                            bPoseChannel *pchan,
203                            bConstraint *con);
204         void build_splineik_pose(Object *object,
205                                  bPoseChannel *pchan,
206                                  bConstraint *con);
207         void build_rig(Object *object, bool is_object_visible);
208         void build_proxy_rig(Object *object);
209         void build_armature(bArmature *armature);
210         void build_shapekeys(Key *key);
211         void build_camera(Camera *camera);
212         void build_lamp(Lamp *lamp);
213         void build_nodetree(bNodeTree *ntree);
214         void build_material(Material *ma);
215         void build_texture(Tex *tex);
216         void build_image(Image *image);
217         void build_world(World *world);
218         void build_compositor(Scene *scene);
219         void build_gpencil(bGPdata *gpd);
220         void build_cachefile(CacheFile *cache_file);
221         void build_mask(Mask *mask);
222         void build_movieclip(MovieClip *clip);
223         void build_lightprobe(LightProbe *probe);
224         void build_speaker(Speaker *speaker);
225
226         /* Per-ID information about what was already in the dependency graph.
227          * Allows to re-use certain values, to speed up following evaluation.
228          */
229         struct IDInfo {
230                 /* Copy-on-written pointer of the corresponding ID. */
231                 ID *id_cow;
232                 /* Mask of visible components from previous state of the
233                  * dependency graph.
234                  */
235                 IDComponentsMask previously_visible_components_mask;
236                 /* Special evaluation flag mask from the previous depsgraph. */
237                 uint32_t previous_eval_flags;
238                 /* Mesh CustomData mask from the previous depsgraph. */
239                 uint64_t previous_customdata_mask;
240         };
241
242 protected:
243         /* Allows to identify an operation which was tagged for update at the time
244          * relations are being updated. We can not reuse operation node pointer
245          * since it will change during dependency graph construction.
246          */
247         struct SavedEntryTag {
248                 ID *id_orig;
249                 eDepsNode_Type component_type;
250                 eDepsOperation_Code opcode;
251                 const char *name;
252                 int name_tag;
253         };
254         vector<SavedEntryTag> saved_entry_tags_;
255
256         struct BuilderWalkUserData {
257                 DepsgraphNodeBuilder *builder;
258                 /* Denotes whether object the walk is invoked from is visible. */
259                 bool is_parent_visible;
260         };
261         static void modifier_walk(void *user_data,
262                                   struct Object *object,
263                                   struct ID **idpoin,
264                                   int cb_flag);
265         static void constraint_walk(bConstraint *constraint,
266                                     ID **idpoin,
267                                     bool is_reference,
268                                     void *user_data);
269
270         /* State which never changes, same for the whole builder time. */
271         Main *bmain_;
272         Depsgraph *graph_;
273
274         /* State which demotes currently built entities. */
275         Scene *scene_;
276         ViewLayer *view_layer_;
277         int view_layer_index_;
278         /* NOTE: Collection are possibly built recursively, so be careful when
279          * setting the current state.
280          */
281         Collection *collection_;
282         /* Accumulated flag over the hierarchy opf currently building collections.
283          * Denotes whether all the hierarchy from parent of collection_ to the
284          * very root is visible (aka not restricted.).
285          */
286         bool is_parent_collection_visible_;
287
288         /* Indexed by original ID, values are IDInfo. */
289         GHash *id_info_hash_;
290
291         /* Set of IDs which were already build. Makes it easier to keep track of
292          * what was already built and what was not.
293          */
294         BuilderMap built_map_;
295 };
296
297 }  // namespace DEG