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.
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.
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.
16 * The Original Code is Copyright (C) 2013 Blender Foundation.
17 * All rights reserved.
20 /** \file blender/depsgraph/DEG_depsgraph_query.h
23 * Public API for Querying and Filtering Depsgraph.
26 #ifndef __DEG_DEPSGRAPH_QUERY_H__
27 #define __DEG_DEPSGRAPH_QUERY_H__
29 #include "DEG_depsgraph.h"
30 #include "DEG_depsgraph_build.h"
46 /* *********************** DEG input data ********************* */
48 /* Get scene that depsgraph was built for. */
49 struct Scene *DEG_get_input_scene(const Depsgraph *graph);
51 /* Get view layer that depsgraph was built for. */
52 struct ViewLayer *DEG_get_input_view_layer(const Depsgraph *graph);
54 /* Get evaluation mode that depsgraph was built for. */
55 eEvaluationMode DEG_get_mode(const Depsgraph *graph);
57 /* Get time that depsgraph is being evaluated or was last evaluated at. */
58 float DEG_get_ctime(const Depsgraph *graph);
60 /* ********************* DEG evaluated data ******************* */
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);
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);
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);
73 /* Get scene the despgraph is created for. */
74 struct Scene *DEG_get_evaluated_scene(const struct Depsgraph *graph);
76 /* Get scene layer the despgraph is created for. */
77 struct ViewLayer *DEG_get_evaluated_view_layer(const struct Depsgraph *graph);
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);
83 /* Get evaluated version of given ID datablock. */
84 struct ID *DEG_get_evaluated_id(const struct Depsgraph *depsgraph,
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);
92 /* Get original version of object for given evaluated one. */
93 struct Object *DEG_get_original_object(struct Object *object);
95 /* Get original version of given evaluated ID datablock. */
96 struct ID *DEG_get_original_id(struct ID *id);
98 /* ************************ DEG object iterators ********************* */
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),
108 typedef struct DEGObjectIterData {
109 struct Depsgraph *graph;
114 eEvaluationMode eval_mode;
116 /* **** Iteration over dupli-list. *** */
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;
131 /* **** Iteration over ID nodes **** */
132 size_t id_node_index;
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);
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.
145 #define DEG_OBJECT_ITER_BEGIN(graph_, instance_, flag_) \
147 DEGObjectIterData data_ = { \
152 ITER_BEGIN(DEG_iterator_objects_begin, \
153 DEG_iterator_objects_next, \
154 DEG_iterator_objects_end, \
155 &data_, Object *, instance_)
157 #define DEG_OBJECT_ITER_END \
162 * Depsgraph objects iterator for draw manager and final render
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)
171 #define DEG_OBJECT_ITER_FOR_RENDER_ENGINE_END \
175 /* ************************ DEG ID iterators ********************* */
177 typedef struct DEGIDIterData {
178 struct Depsgraph *graph;
181 size_t id_node_index;
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);
189 /* ************************ DEG traversal ********************* */
191 typedef void (*DEGForeachIDCallback)(ID *id, void *user_data);
193 /* NOTE: Modifies runtime flags in depsgraph nodes, so can not be used in
194 * parallel. Keep an eye on that!
196 void DEG_foreach_ancestor_ID(const Depsgraph *depsgraph,
198 DEGForeachIDCallback callback, void *user_data);
199 void DEG_foreach_dependent_ID(const Depsgraph *depsgraph,
201 DEGForeachIDCallback callback, void *user_data);
203 void DEG_foreach_ID(const Depsgraph *depsgraph,
204 DEGForeachIDCallback callback, void *user_data);
206 /* ********************* DEG graph filtering ****************** */
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;
213 /* TODO: component identifiers - Component Type, Subdata/Component Name */
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;
223 typedef struct DEG_FilterQuery {
224 /* List of DEG_FilterTarget's */
225 struct ListBase targets;
227 /* Level of detail in the resulting graph */
228 eDEG_FilterQuery_Granularity detail_level;
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.
235 Depsgraph *DEG_graph_filter(const Depsgraph *depsgraph, struct Main *bmain, DEG_FilterQuery *query);
242 #endif /* __DEG_DEPSGRAPH_QUERY_H__ */