Merge branch 'master' into blender2.8
[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"  /* used for DEG_depsgraph_use_copy_on_write() */
37
38 struct Base;
39 struct CacheFile;
40 struct bGPdata;
41 struct ListBase;
42 struct GHash;
43 struct ID;
44 struct Image;
45 struct FCurve;
46 struct Group;
47 struct Key;
48 struct LayerCollection;
49 struct Main;
50 struct Material;
51 struct Mask;
52 struct MTex;
53 struct MovieClip;
54 struct bNodeTree;
55 struct Object;
56 struct ParticleSettings;
57 struct Probe;
58 struct bPoseChannel;
59 struct bConstraint;
60 struct Scene;
61 struct Tex;
62 struct World;
63
64 struct PropertyRNA;
65
66 namespace DEG {
67
68 struct Depsgraph;
69 struct DepsNode;
70 struct IDDepsNode;
71 struct TimeSourceDepsNode;
72 struct ComponentDepsNode;
73 struct OperationDepsNode;
74
75 struct DepsgraphNodeBuilder {
76         DepsgraphNodeBuilder(Main *bmain, Depsgraph *graph);
77         ~DepsgraphNodeBuilder();
78
79         /* For given original ID get ID which is created by CoW system. */
80         ID *get_cow_id(const ID *id_orig) const;
81         /* Similar to above, but for the cases when there is no ID node we create
82          * one.
83          */
84         ID *ensure_cow_id(ID *id_orig);
85
86         /* Helper wrapper function which wraps get_cow_id with a needed type cast. */
87         template<typename T>
88         T *get_cow_datablock(const T *orig) const {
89                 return (T *)get_cow_id(&orig->id);
90         }
91
92         /* Get fully expanded (ready for use) copy-on-write datablock for the given
93          * original datablock.
94          */
95         ID *expand_cow_id(IDDepsNode *id_node);
96         ID *expand_cow_id(ID *id_orig);
97         template<typename T>
98         T *expand_cow_datablock(T *orig) {
99                 return (T *)expand_cow_id(&orig->id);
100         }
101
102         /* For a given COW datablock get corresponding original one. */
103         template<typename T>
104         T *get_orig_datablock(const T *cow) const {
105                 if (DEG_depsgraph_use_copy_on_write()) {
106                         return (T *)cow->id.orig_id;
107                 }
108                 else {
109                         return (T *)cow;
110                 }
111         }
112
113         void begin_build();
114         void end_build();
115
116         IDDepsNode *add_id_node(ID *id);
117         IDDepsNode *find_id_node(ID *id);
118         TimeSourceDepsNode *add_time_source();
119
120         ComponentDepsNode *add_component_node(ID *id,
121                                               eDepsNode_Type comp_type,
122                                               const char *comp_name = "");
123
124         OperationDepsNode *add_operation_node(ComponentDepsNode *comp_node,
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 char *comp_name,
132                                               const DepsEvalOperationCb& op,
133                                               eDepsOperation_Code opcode,
134                                               const char *name = "",
135                                               int name_tag = -1);
136         OperationDepsNode *add_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         OperationDepsNode *ensure_operation_node(ID *id,
144                                                  eDepsNode_Type comp_type,
145                                                  const DepsEvalOperationCb& op,
146                                                  eDepsOperation_Code opcode,
147                                                  const char *name = "",
148                                                  int name_tag = -1);
149
150         bool has_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                                                const char *comp_name,
160                                                eDepsOperation_Code opcode,
161                                                const char *name = "",
162                                                int name_tag = -1);
163
164         OperationDepsNode *find_operation_node(ID *id,
165                                                eDepsNode_Type comp_type,
166                                                eDepsOperation_Code opcode,
167                                                const char *name = "",
168                                                int name_tag = -1);
169
170         void build_view_layer(Scene *scene,
171                                ViewLayer *view_layer,
172                                eDepsNode_LinkedState_Type linked_state);
173         void build_group(Group *group);
174         void build_object(Base *base,
175                           Object *object,
176                           eDepsNode_LinkedState_Type linked_state);
177         void build_object_flags(Base *base,
178                                 Object *object,
179                                 eDepsNode_LinkedState_Type linked_state);
180         void build_object_data(Object *object);
181         void build_object_transform(Object *object);
182         void build_object_constraints(Object *object);
183         void build_pose_constraints(Object *object, bPoseChannel *pchan, int pchan_index);
184         void build_rigidbody(Scene *scene);
185         void build_particles(Object *object);
186         void build_particle_settings(ParticleSettings *part);
187         void build_cloth(Object *object);
188         void build_animdata(ID *id);
189         void build_driver(ID *id, FCurve *fcurve);
190         void build_driver_variables(ID *id, FCurve *fcurve);
191         void build_driver_id_property(ID *id, const char *rna_path);
192         void build_ik_pose(Object *object,
193                            bPoseChannel *pchan,
194                            bConstraint *con);
195         void build_splineik_pose(Object *object,
196                                  bPoseChannel *pchan,
197                                  bConstraint *con);
198         void build_rig(Object *object);
199         void build_proxy_rig(Object *object);
200         void build_shapekeys(Key *key);
201         void build_obdata_geom(Object *object);
202         void build_camera(Object *object);
203         void build_lamp(Object *object);
204         void build_nodetree(bNodeTree *ntree);
205         void build_material(Material *ma);
206         void build_texture(Tex *tex);
207         void build_texture_stack(MTex **texture_stack);
208         void build_image(Image *image);
209         void build_world(World *world);
210         void build_compositor(Scene *scene);
211         void build_gpencil(bGPdata *gpd);
212         void build_cachefile(CacheFile *cache_file);
213         void build_mask(Mask *mask);
214         void build_movieclip(MovieClip *clip);
215         void build_lightprobe(Object *object);
216
217         struct LayerCollectionState {
218                 int index;
219                 LayerCollection *parent;
220         };
221         void build_layer_collection(ID *owner_id,
222                                     LayerCollection *layer_collection,
223                                     LayerCollectionState *state);
224         void build_layer_collections(ID *owner_id,
225                                      ListBase *layer_collections,
226                                      LayerCollectionState *state);
227         void build_view_layer_collections(ID *owner_id, ViewLayer *view_layer);
228 protected:
229         struct SavedEntryTag {
230                 ID *id;
231                 eDepsNode_Type component_type;
232                 eDepsOperation_Code opcode;
233         };
234         vector<SavedEntryTag> saved_entry_tags_;
235
236         /* State which never changes, same for the whole builder time. */
237         Main *bmain_;
238         Depsgraph *graph_;
239
240         /* State which demotes currently built entities. */
241         Scene *scene_;
242
243         GHash *cow_id_hash_;
244         BuilderMap built_map_;
245 };
246
247 }  // namespace DEG