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 21 * \ingroup depsgraph 22 * 23 * Public API for Depsgraph 24 * 25 * Dependency Graph 26 * ================ 27 * 28 * The dependency graph tracks relations between various pieces of data in 29 * a Blender file, but mainly just those which make up scene data. It is used 30 * to determine the set of operations need to ensure that all data has been 31 * correctly evaluated in response to changes, based on dependencies and visibility 32 * of affected data. 33 * Evaluation Engine 34 * ================= 35 * 36 * The evaluation takes the operation-nodes the Depsgraph has tagged for updating, 37 * and schedules them up for being evaluated/executed such that the all dependency 38 * relationship constraints are satisfied. 39 */ 40 41 /* ************************************************* */ 42 /* Forward-defined typedefs for core types 43 * - These are used in all depsgraph code and by all callers of Depsgraph API... 44 */ 45 46 #pragma once 47 48 #include "DNA_ID.h" 49 50 /* Dependency Graph */ 51 typedef struct Depsgraph Depsgraph; 52 53 /* ------------------------------------------------ */ 54 55 struct Main; 56 57 struct Scene; 58 struct ViewLayer; 59 60 typedef enum eEvaluationMode { 61 DAG_EVAL_VIEWPORT = 0, /* evaluate for OpenGL viewport */ 62 DAG_EVAL_RENDER = 1, /* evaluate for render purposes */ 63 } eEvaluationMode; 64 65 /* DagNode->eval_flags */ 66 enum { 67 /* Regardless to curve->path animation flag path is to be evaluated anyway, 68 * to meet dependencies with such a things as curve modifier and other guys 69 * who're using curve deform, where_on_path and so. */ 70 DAG_EVAL_NEED_CURVE_PATH = (1 << 0), 71 /* A shrinkwrap modifier or constraint targeting this mesh needs information 72 * about non-manifold boundary edges for the Target Normal Project mode. */ 73 DAG_EVAL_NEED_SHRINKWRAP_BOUNDARY = (1 << 1), 74 }; 75 76 #ifdef __cplusplus 77 extern "C" { 78 #endif 79 80 /* ************************************************ */ 81 /* Depsgraph API */ 82 83 /* CRUD ------------------------------------------- */ 84 85 // Get main depsgraph instance from context! 86 87 /* Create new Depsgraph instance */ 88 // TODO: what args are needed here? What's the building-graph entry point? 89 Depsgraph *DEG_graph_new(struct Main *bmain, 90 struct Scene *scene, 91 struct ViewLayer *view_layer, 92 eEvaluationMode mode); 93 94 void DEG_graph_replace_owners(struct Depsgraph *depsgraph, 95 struct Main *bmain, 96 struct Scene *scene, 97 struct ViewLayer *view_layer); 98 99 /* Free Depsgraph itself and all its data */ 100 void DEG_graph_free(Depsgraph *graph); 101 102 /* Node Types Registry ---------------------------- */ 103 104 /* Register all node types */ 105 void DEG_register_node_types(void); 106 107 /* Free node type registry on exit */ 108 void DEG_free_node_types(void); 109 110 /* Update Tagging -------------------------------- */ 111 112 /* Update dependency graph when visible scenes/layers changes. */ 113 void DEG_graph_on_visible_update(struct Main *bmain, Depsgraph *depsgraph, const bool do_time); 114 115 /* Update all dependency graphs when visible scenes/layers changes. */ 116 void DEG_on_visible_update(struct Main *bmain, const bool do_time); 117 118 /* NOTE: Will return NULL if the flag is not known, allowing to gracefully handle situations 119 * when recalc flag has been removed. */ 120 const char *DEG_update_tag_as_string(IDRecalcFlag flag); 121 122 void DEG_id_tag_update(struct ID *id, int flag); 123 void DEG_id_tag_update_ex(struct Main *bmain, struct ID *id, int flag); 124 125 void DEG_graph_id_tag_update(struct Main *bmain, 126 struct Depsgraph *depsgraph, 127 struct ID *id, 128 int flag); 129 130 /* Tag all dependency graphs when time has changed. */ 131 void DEG_time_tag_update(struct Main *bmain); 132 133 /* Tag a dependency graph when time has changed. */ 134 void DEG_graph_time_tag_update(struct Depsgraph *depsgraph); 135 136 /* Mark a particular datablock type as having changing. This does 137 * not cause any updates but is used by external render engines to detect if for 138 * example a datablock was removed. */ 139 void DEG_graph_id_type_tag(struct Depsgraph *depsgraph, short id_type); 140 void DEG_id_type_tag(struct Main *bmain, short id_type); 141 142 void DEG_ids_clear_recalc(struct Main *bmain, Depsgraph *depsgraph); 143 144 /* Check if something was changed in the database and inform 145 * editors about this. 146 */ 147 void DEG_ids_check_recalc(struct Main *bmain, 148 struct Depsgraph *depsgraph, 149 struct Scene *scene, 150 struct ViewLayer *view_layer, 151 bool time); 152 153 /* ************************************************ */ 154 /* Evaluation Engine API */ 155 156 /* Graph Evaluation ----------------------------- */ 157 158 /* Frame changed recalculation entry point. */ 159 void DEG_evaluate_on_framechange(Depsgraph *graph, float ctime); 160 161 /* Data changed recalculation entry point. */ 162 void DEG_evaluate_on_refresh(Depsgraph *graph); 163 164 /* Editors Integration -------------------------- */ 165 166 /* Mechanism to allow editors to be informed of depsgraph updates, 167 * to do their own updates based on changes. 168 */ 169 170 typedef struct DEGEditorUpdateContext { 171 struct Main *bmain; 172 struct Depsgraph *depsgraph; 173 struct Scene *scene; 174 struct ViewLayer *view_layer; 175 } DEGEditorUpdateContext; 176 177 typedef void (*DEG_EditorUpdateIDCb)(const DEGEditorUpdateContext *update_ctx, struct ID *id); 178 typedef void (*DEG_EditorUpdateSceneCb)(const DEGEditorUpdateContext *update_ctx, int updated); 179 180 /* Set callbacks which are being called when depsgraph changes. */ 181 void DEG_editors_set_update_cb(DEG_EditorUpdateIDCb id_func, DEG_EditorUpdateSceneCb scene_func); 182 183 /* Evaluation ----------------------------------- */ 184 185 bool DEG_is_evaluating(const struct Depsgraph *depsgraph); 186 187 bool DEG_is_active(const struct Depsgraph *depsgraph); 188 void DEG_make_active(struct Depsgraph *depsgraph); 189 void DEG_make_inactive(struct Depsgraph *depsgraph); 190 191 /* Evaluation Debug ------------------------------ */ 192 193 void DEG_debug_print_begin(struct Depsgraph *depsgraph); 194 195 void DEG_debug_print_eval(struct Depsgraph *depsgraph, 196 const char *function_name, 197 const char *object_name, 198 const void *object_address); 199 200 void DEG_debug_print_eval_subdata(struct Depsgraph *depsgraph, 201 const char *function_name, 202 const char *object_name, 203 const void *object_address, 204 const char *subdata_comment, 205 const char *subdata_name, 206 const void *subdata_address); 207 208 void DEG_debug_print_eval_subdata_index(struct Depsgraph *depsgraph, 209 const char *function_name, 210 const char *object_name, 211 const void *object_address, 212 const char *subdata_comment, 213 const char *subdata_name, 214 const void *subdata_address, 215 const int subdata_index); 216 217 void DEG_debug_print_eval_parent_typed(struct Depsgraph *depsgraph, 218 const char *function_name, 219 const char *object_name, 220 const void *object_address, 221 const char *parent_comment, 222 const char *parent_name, 223 const void *parent_address); 224 225 void DEG_debug_print_eval_time(struct Depsgraph *depsgraph, 226 const char *function_name, 227 const char *object_name, 228 const void *object_address, 229 float time); 230 231 #ifdef __cplusplus 232 } /* extern "C" */ 233 #endif 234