Merge branch 'master' into blender2.8
[blender.git] / source / blender / depsgraph / DEG_depsgraph_query.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: Joshua Leung
22  * Contributor(s): Sergey Sharybin
23  *
24  * ***** END GPL LICENSE BLOCK *****
25  */
26
27 /** \file blender/depsgraph/DEG_depsgraph_query.h
28  *  \ingroup depsgraph
29  *
30  * Public API for Querying and Filtering Depsgraph.
31  */
32
33 #ifndef __DEG_DEPSGRAPH_QUERY_H__
34 #define __DEG_DEPSGRAPH_QUERY_H__
35
36 #include "DEG_depsgraph.h"
37
38 struct ID;
39
40 struct Base;
41 struct BLI_Iterator;
42 struct Depsgraph;
43 struct DupliObject;
44 struct ListBase;
45 struct Scene;
46 struct ViewLayer;
47
48 #ifdef __cplusplus
49 extern "C" {
50 #endif
51
52 /* Check if given ID type was tagged for update. */
53 bool DEG_id_type_tagged(struct Main *bmain, short id_type);
54
55 /* Get additional evaluation flags for the given ID. */
56 short DEG_get_eval_flags_for_id(const struct Depsgraph *graph, struct ID *id);
57
58 /* Get scene the despgraph is created for. */
59 struct Scene *DEG_get_evaluated_scene(const struct Depsgraph *graph);
60
61 /* Get scene layer the despgraph is created for. */
62 struct ViewLayer *DEG_get_evaluated_view_layer(const struct Depsgraph *graph);
63
64 /* Get evaluated version of object for given original one. */
65 struct Object *DEG_get_evaluated_object(const struct Depsgraph *depsgraph,
66                                         struct Object *object);
67
68 /* Get evaluated version of given ID datablock. */
69 struct ID *DEG_get_evaluated_id(const struct Depsgraph *depsgraph,
70                                 struct ID *id);
71
72 /* ************************ DEG iterators ********************* */
73
74 enum {
75         DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY   = (1 << 0),
76         DEG_ITER_OBJECT_FLAG_LINKED_INDIRECTLY = (1 << 1),
77         DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET    = (1 << 2),
78         DEG_ITER_OBJECT_FLAG_VISIBLE           = (1 << 3),
79         DEG_ITER_OBJECT_FLAG_DUPLI             = (1 << 4),
80 };
81
82 typedef enum eDepsObjectIteratorMode {
83         DEG_ITER_OBJECT_MODE_VIEWPORT = 0,
84         DEG_ITER_OBJECT_MODE_RENDER   = 1,
85 } eDepsObjectIteratorMode;
86
87 typedef struct DEGObjectIterData {
88         struct Depsgraph *graph;
89         struct Scene *scene;
90         struct EvaluationContext eval_ctx;
91
92         int flag;
93         eDepsObjectIteratorMode mode;
94
95         /* **** Iteration over dupli-list. *** */
96
97         /* Object which created the dupli-list. */
98         struct Object *dupli_parent;
99         /* List of duplicated objects. */
100         struct ListBase *dupli_list;
101         /* Next duplicated object to step into. */
102         struct DupliObject *dupli_object_next;
103         /* Corresponds to current object: current iterator object is evaluated from
104          * this duplicated object.
105          */
106         struct DupliObject *dupli_object_current;
107         /* Temporary storage to report fully populated DNA to the render engine or
108          * other users of the iterator.
109          */
110         struct Object temp_dupli_object;
111
112         /* **** Iteration ober ID nodes **** */
113         size_t id_node_index;
114         size_t num_id_nodes;
115 } DEGObjectIterData;
116
117 void DEG_iterator_objects_begin(struct BLI_Iterator *iter, DEGObjectIterData *data);
118 void DEG_iterator_objects_next(struct BLI_Iterator *iter);
119 void DEG_iterator_objects_end(struct BLI_Iterator *iter);
120
121 /**
122  * Note: Be careful with DEG_ITER_OBJECT_FLAG_LINKED_INDIRECTLY objects.
123  * Although they are available they have no overrides (collection_properties)
124  * and will crash if you try to access it.
125  */
126 #define DEG_OBJECT_ITER(graph_, instance_, mode_, flag_)                          \
127         {                                                                             \
128                 DEGObjectIterData data_ = {                                               \
129                         .graph = (graph_),                                                    \
130                         .mode = (mode_),                                                      \
131                         .flag = (flag_),                                                      \
132                 };                                                                        \
133                                                                                   \
134                 ITER_BEGIN(DEG_iterator_objects_begin,                                    \
135                            DEG_iterator_objects_next,                                     \
136                            DEG_iterator_objects_end,                                      \
137                            &data_, Object *, instance_)
138
139 #define DEG_OBJECT_ITER_END                                                       \
140                 ITER_END                                                                  \
141         }
142
143 /**
144   * Depsgraph objects iterator for draw manager and final render
145   */
146 #define DEG_OBJECT_ITER_FOR_RENDER_ENGINE(graph_, instance_, mode_) \
147         DEG_OBJECT_ITER(graph_, instance_, mode_,                \
148                 DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY  |          \
149                 DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET |            \
150                 DEG_ITER_OBJECT_FLAG_VISIBLE |                   \
151                 DEG_ITER_OBJECT_FLAG_DUPLI)
152
153 #define DEG_OBJECT_ITER_FOR_RENDER_ENGINE_END                \
154         DEG_OBJECT_ITER_END
155
156 /* ************************ DEG traversal ********************* */
157
158 typedef void (*DEGForeachIDCallback)(ID *id, void *user_data);
159
160 /* NOTE: Modifies runtime flags in depsgraph nodes, so can not be used in
161  * parallel. Keep an eye on that!
162  */
163 void DEG_foreach_dependent_ID(const Depsgraph *depsgraph,
164                               const ID *id,
165                               DEGForeachIDCallback callback, void *user_data);
166
167
168 #ifdef __cplusplus
169 } /* extern "C" */
170 #endif
171
172 #endif  /* __DEG_DEPSGRAPH_QUERY_H__ */