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 
24 #pragma once
25 
26 #include "BLI_ghash.h"
27 #include "BLI_sys_types.h"
28 #include "DNA_ID.h"
29 #include "intern/node/deg_node.h"
30 
31 namespace blender {
32 namespace deg {
33 
34 struct ComponentNode;
35 
36 typedef uint64_t IDComponentsMask;
37 
38 /* NOTE: We use max comparison to mark an id node that is linked more than once
39  * So keep this enum ordered accordingly. */
40 enum eDepsNode_LinkedState_Type {
41   /* Generic indirectly linked id node. */
42   DEG_ID_LINKED_INDIRECTLY = 0,
43   /* Id node present in the set (background) only. */
44   DEG_ID_LINKED_VIA_SET = 1,
45   /* Id node directly linked via the SceneLayer. */
46   DEG_ID_LINKED_DIRECTLY = 2,
47 };
48 const char *linkedStateAsString(eDepsNode_LinkedState_Type linked_state);
49 
50 /* ID-Block Reference */
51 struct IDNode : public Node {
52   struct ComponentIDKey {
53     ComponentIDKey(NodeType type, const char *name = "");
54     uint64_t hash() const;
55     bool operator==(const ComponentIDKey &other) const;
56 
57     NodeType type;
58     const char *name;
59   };
60 
61   virtual void init(const ID *id, const char *subdata) override;
62   void init_copy_on_write(ID *id_cow_hint = nullptr);
63   ~IDNode();
64   void destroy();
65 
66   virtual string identifier() const override;
67 
68   ComponentNode *find_component(NodeType type, const char *name = "") const;
69   ComponentNode *add_component(NodeType type, const char *name = "");
70 
71   virtual void tag_update(Depsgraph *graph, eUpdateSource source) override;
72 
73   void finalize_build(Depsgraph *graph);
74 
75   IDComponentsMask get_visible_components_mask() const;
76 
77   /* ID Block referenced. */
78   /* Type of the ID stored separately, so it's possible to perform check whether CoW is needed
79    * without de-referencing the id_cow (which is not safe when ID is NOT covered by CoW and has
80    * been deleted from the main database.) */
81   ID_Type id_type;
82   ID *id_orig;
83   ID *id_cow;
84 
85   /* Hash to make it faster to look up components. */
86   Map<ComponentIDKey, ComponentNode *> components;
87 
88   /* Additional flags needed for scene evaluation.
89    * TODO(sergey): Only needed for until really granular updates
90    * of all the entities. */
91   uint32_t eval_flags;
92   uint32_t previous_eval_flags;
93 
94   /* Extra customdata mask which needs to be evaluated for the mesh object. */
95   DEGCustomDataMeshMasks customdata_masks;
96   DEGCustomDataMeshMasks previous_customdata_masks;
97 
98   eDepsNode_LinkedState_Type linked_state;
99 
100   /* Indicates the datablock is visible in the evaluated scene. */
101   bool is_directly_visible;
102 
103   /* For the collection type of ID, denotes whether collection was fully
104    * recursed into. */
105   bool is_collection_fully_expanded;
106 
107   /* Is used to figure out whether object came to the dependency graph via a base. */
108   bool has_base;
109 
110   /* Accumulated flag from operation. Is initialized and used during updates flush. */
111   bool is_user_modified;
112 
113   IDComponentsMask visible_components_mask;
114   IDComponentsMask previously_visible_components_mask;
115 
116   DEG_DEPSNODE_DECLARE;
117 };
118 
119 }  // namespace deg
120 }  // namespace blender
121