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