Merge branch 'blender2.7'
[blender.git] / source / blender / depsgraph / DEG_depsgraph_query.h
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2013 Blender Foundation.
17  * All rights reserved.
18  */
19
20 /** \file blender/depsgraph/DEG_depsgraph_query.h
21  *  \ingroup depsgraph
22  *
23  * Public API for Querying and Filtering Depsgraph.
24  */
25
26 #ifndef __DEG_DEPSGRAPH_QUERY_H__
27 #define __DEG_DEPSGRAPH_QUERY_H__
28
29 #include "DEG_depsgraph.h"
30 #include "DEG_depsgraph_build.h"
31
32 struct ID;
33
34 struct BLI_Iterator;
35 struct Base;
36 struct Depsgraph;
37 struct DupliObject;
38 struct ListBase;
39 struct Scene;
40 struct ViewLayer;
41
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45
46 /* *********************** DEG input data ********************* */
47
48 /* Get scene that depsgraph was built for. */
49 struct Scene *DEG_get_input_scene(const Depsgraph *graph);
50
51 /* Get view layer that depsgraph was built for. */
52 struct ViewLayer *DEG_get_input_view_layer(const Depsgraph *graph);
53
54 /* Get evaluation mode that depsgraph was built for. */
55 eEvaluationMode DEG_get_mode(const Depsgraph *graph);
56
57 /* Get time that depsgraph is being evaluated or was last evaluated at. */
58 float DEG_get_ctime(const Depsgraph *graph);
59
60 /* ********************* DEG evaluated data ******************* */
61
62 /* Check if given ID type was tagged for update. */
63 bool DEG_id_type_updated(const struct Depsgraph *depsgraph, short id_type);
64 bool DEG_id_type_any_updated(const struct Depsgraph *depsgraph);
65
66 /* Get additional evaluation flags for the given ID. */
67 uint32_t DEG_get_eval_flags_for_id(const struct Depsgraph *graph, struct ID *id);
68
69 /* Get additional mesh CustomDataMask flags for the given object. */
70 uint64_t DEG_get_customdata_mask_for_object(const struct Depsgraph *graph,
71                                             struct Object *object);
72
73 /* Get scene the despgraph is created for. */
74 struct Scene *DEG_get_evaluated_scene(const struct Depsgraph *graph);
75
76 /* Get scene layer the despgraph is created for. */
77 struct ViewLayer *DEG_get_evaluated_view_layer(const struct Depsgraph *graph);
78
79 /* Get evaluated version of object for given original one. */
80 struct Object *DEG_get_evaluated_object(const struct Depsgraph *depsgraph,
81                                         struct Object *object);
82
83 /* Get evaluated version of given ID datablock. */
84 struct ID *DEG_get_evaluated_id(const struct Depsgraph *depsgraph,
85                                 struct ID *id);
86
87 /* Get evaluated version of data pointed to by RNA pointer */
88 void DEG_get_evaluated_rna_pointer(const struct Depsgraph *depsgraph,
89                                    struct PointerRNA *ptr,
90                                    struct PointerRNA *r_ptr_eval);
91
92 /* Get original version of object for given evaluated one. */
93 struct Object *DEG_get_original_object(struct Object *object);
94
95 /* Get original version of given evaluated ID datablock. */
96 struct ID *DEG_get_original_id(struct ID *id);
97
98 /* ************************ DEG object iterators ********************* */
99
100 enum {
101         DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY   = (1 << 0),
102         DEG_ITER_OBJECT_FLAG_LINKED_INDIRECTLY = (1 << 1),
103         DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET    = (1 << 2),
104         DEG_ITER_OBJECT_FLAG_VISIBLE           = (1 << 3),
105         DEG_ITER_OBJECT_FLAG_DUPLI             = (1 << 4),
106 };
107
108 typedef struct DEGObjectIterData {
109         struct Depsgraph *graph;
110         int flag;
111
112         struct Scene *scene;
113
114         eEvaluationMode eval_mode;
115
116         /* **** Iteration over dupli-list. *** */
117
118         /* Object which created the dupli-list. */
119         struct Object *dupli_parent;
120         /* List of duplicated objects. */
121         struct ListBase *dupli_list;
122         /* Next duplicated object to step into. */
123         struct DupliObject *dupli_object_next;
124         /* Corresponds to current object: current iterator object is evaluated from
125          * this duplicated object. */
126         struct DupliObject *dupli_object_current;
127         /* Temporary storage to report fully populated DNA to the render engine or
128          * other users of the iterator. */
129         struct Object temp_dupli_object;
130
131         /* **** Iteration over ID nodes **** */
132         size_t id_node_index;
133         size_t num_id_nodes;
134 } DEGObjectIterData;
135
136 void DEG_iterator_objects_begin(struct BLI_Iterator *iter, DEGObjectIterData *data);
137 void DEG_iterator_objects_next(struct BLI_Iterator *iter);
138 void DEG_iterator_objects_end(struct BLI_Iterator *iter);
139
140 /**
141  * Note: Be careful with DEG_ITER_OBJECT_FLAG_LINKED_INDIRECTLY objects.
142  * Although they are available they have no overrides (collection_properties)
143  * and will crash if you try to access it.
144  */
145 #define DEG_OBJECT_ITER_BEGIN(graph_, instance_, flag_)                           \
146         {                                                                             \
147                 DEGObjectIterData data_ = {                                               \
148                         graph_,                                                               \
149                         flag_                                                                 \
150                 };                                                                        \
151                                                                                   \
152                 ITER_BEGIN(DEG_iterator_objects_begin,                                    \
153                            DEG_iterator_objects_next,                                     \
154                            DEG_iterator_objects_end,                                      \
155                            &data_, Object *, instance_)
156
157 #define DEG_OBJECT_ITER_END                                                       \
158                 ITER_END;                                                                 \
159         }
160
161 /**
162   * Depsgraph objects iterator for draw manager and final render
163   */
164 #define DEG_OBJECT_ITER_FOR_RENDER_ENGINE_BEGIN(graph_, instance_)        \
165         DEG_OBJECT_ITER_BEGIN(graph_, instance_,                              \
166                 DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY |                        \
167                 DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET |                         \
168                 DEG_ITER_OBJECT_FLAG_VISIBLE |                                \
169                 DEG_ITER_OBJECT_FLAG_DUPLI)
170
171 #define DEG_OBJECT_ITER_FOR_RENDER_ENGINE_END                             \
172         DEG_OBJECT_ITER_END
173
174
175 /* ************************ DEG ID iterators ********************* */
176
177 typedef struct DEGIDIterData {
178         struct Depsgraph *graph;
179         bool only_updated;
180
181         size_t id_node_index;
182         size_t num_id_nodes;
183 } DEGIDIterData;
184
185 void DEG_iterator_ids_begin(struct BLI_Iterator *iter, DEGIDIterData *data);
186 void DEG_iterator_ids_next(struct BLI_Iterator *iter);
187 void DEG_iterator_ids_end(struct BLI_Iterator *iter);
188
189 /* ************************ DEG traversal ********************* */
190
191 typedef void (*DEGForeachIDCallback)(ID *id, void *user_data);
192
193 /* NOTE: Modifies runtime flags in depsgraph nodes, so can not be used in
194  * parallel. Keep an eye on that!
195  */
196 void DEG_foreach_ancestor_ID(const Depsgraph *depsgraph,
197                              const ID *id,
198                              DEGForeachIDCallback callback, void *user_data);
199 void DEG_foreach_dependent_ID(const Depsgraph *depsgraph,
200                               const ID *id,
201                               DEGForeachIDCallback callback, void *user_data);
202
203 void DEG_foreach_ID(const Depsgraph *depsgraph,
204                     DEGForeachIDCallback callback, void *user_data);
205
206 /* ********************* DEG graph filtering ****************** */
207
208 /* ComponentKey for nodes we want to be able to evaluate in the filtered graph */
209 typedef struct DEG_FilterTarget {
210         struct DEG_FilterTarget *next, *prev;
211
212         struct ID *id;
213         /* TODO: component identifiers - Component Type, Subdata/Component Name */
214 } DEG_FilterTarget;
215
216 typedef enum eDEG_FilterQuery_Granularity {
217         DEG_FILTER_NODES_ALL           = 0,
218         DEG_FILTER_NODES_NO_OPS        = 1,
219         DEG_FILTER_NODES_ID_ONLY       = 2,
220 } eDEG_FilterQuery_Granularity;
221
222
223 typedef struct DEG_FilterQuery {
224         /* List of DEG_FilterTarget's */
225         struct ListBase targets;
226
227         /* Level of detail in the resulting graph */
228         eDEG_FilterQuery_Granularity detail_level;
229 } DEG_FilterQuery;
230
231 /* Obtain a new graph instance that only contains the subset of desired nodes
232  * WARNING: Do NOT pass an already filtered depsgraph through this function again,
233  *          as we are currently unable to accurately recreate it.
234  */
235 Depsgraph *DEG_graph_filter(const Depsgraph *depsgraph, struct Main *bmain, DEG_FilterQuery *query);
236
237
238 #ifdef __cplusplus
239 } /* extern "C" */
240 #endif
241
242 #endif  /* __DEG_DEPSGRAPH_QUERY_H__ */