Blender V5.3
node_texture_common.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2006 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "DNA_node_types.h"
10
11#include "BLI_listbase.hh"
12#include "BLI_math_vector_c.hh"
13
14#include "BKE_node.hh"
15#include "BKE_node_runtime.hh"
16
17#include "NOD_common.hh"
18#include "node_common.h"
19#include "node_exec.hh"
20#include "node_texture_util.hh"
21
22#include "RNA_access.hh"
23
24namespace blender {
25
26static void copy_stack(bNodeStack *to, bNodeStack *from)
27{
28 if (to != from) {
29 copy_v4_v4(to->vec, from->vec);
30 to->data = from->data;
31 to->datatype = from->datatype;
32
33 /* tag as copy to prevent freeing */
34 to->is_copy = 1;
35 }
36}
37
38/**** GROUP ****/
39
41{
42 bNodeTree *ngroup = id_cast<bNodeTree *>(node->id);
43 void *exec;
44
45 if (!ngroup) {
46 return nullptr;
47 }
48
49 /* initialize the internal node tree execution */
50 exec = ntreeTexBeginExecTree_internal(context, ngroup, key);
51
52 return exec;
53}
54
55static void group_freeexec(void *nodedata)
56{
57 bNodeTreeExec *gexec = static_cast<bNodeTreeExec *>(nodedata);
58
60}
61
62/* Copy inputs to the internal stack.
63 * This is a shallow copy, no buffers are duplicated here!
64 */
65static void group_copy_inputs(bNode *gnode, bNodeStack **in, bNodeStack *gstack)
66{
67 bNodeTree *ngroup = id_cast<bNodeTree *>(gnode->id);
68 bNodeSocket *sock;
69 bNodeStack *ns;
70 int a;
71
72 for (bNode &node : ngroup->nodes) {
73 if (node.is_group_input()) {
74 for (sock = node.outputs.first(), a = 0; sock; sock = sock->next, a++) {
75 if (in[a]) { /* shouldn't need to check this #36694. */
76 ns = node_get_socket_stack(gstack, sock);
77 if (ns) {
78 copy_stack(ns, in[a]);
79 }
80 }
81 }
82 }
83 }
84}
85
86/* Copy internal results to the external outputs.
87 */
88static void group_copy_outputs(bNode *gnode, bNodeStack **out, bNodeStack *gstack)
89{
90 bNodeTree &ngroup = *reinterpret_cast<bNodeTree *>(gnode->id);
91
92 ngroup.ensure_topology_cache();
93 bNode *group_output_node = ngroup.group_output_node();
94 if (!group_output_node) {
95 return;
96 }
97
98 for (auto [a, sock] : group_output_node->inputs.enumerate()) {
99 if (!out[a]) {
100 /* shouldn't need to check this #36694. */
101 continue;
102 }
103
104 bNodeStack *ns = node_get_socket_stack(gstack, &sock);
105 if (ns) {
106 copy_stack(out[a], ns);
107 }
108 }
109}
110
111static void group_execute(void *data,
112 int thread,
113 bNode *node,
114 bNodeExecData *execdata,
115 bNodeStack **in,
116 bNodeStack **out)
117{
118 bNodeTreeExec *exec = static_cast<bNodeTreeExec *>(execdata->data);
119 bNodeThreadStack *nts;
120
121 if (!exec) {
122 return;
123 }
124
125 /* XXX same behavior as trunk: all nodes inside group are executed.
126 * it's stupid, but just makes it work. compo redesign will do this better.
127 */
128 for (bNode &inode : exec->nodetree->nodes) {
129 inode.runtime->need_exec = 1;
130 }
131
132 nts = ntreeGetThreadStack(exec, thread);
133
135 ntreeExecThreadNodes(exec, nts, data, thread);
137
139}
140
142{
143 static bke::bNodeType ntype;
144
145 /* NOTE: Cannot use #sh_node_type_base for node group, because it would map the node type
146 * to the shared #NODE_GROUP integer type id. */
147
148 bke::node_type_base_custom(ntype, "TextureNodeGroup", "Group", "GROUP", NODE_CLASS_GROUP);
149 ntype.enum_name_legacy = "GROUP";
150 ntype.type_legacy = NODE_GROUP;
154 ntype.rna_ext.srna = RNA_struct_find("TextureNodeGroup");
155 BLI_assert(ntype.rna_ext.srna != nullptr);
157
163 ntype.exec_fn = group_execute;
164
166}
167
168} // namespace blender
#define NODE_GROUP
Definition BKE_node.hh:865
#define NODE_CLASS_GROUP
Definition BKE_node.hh:483
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
void node_type_base_custom(bNodeType &ntype, StringRefNull idname, StringRefNull name, StringRefNull enum_name, short nclass)
Definition node.cc:5896
void node_group_declare(NodeDeclarationBuilder &b)
BMesh Iterators.
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
static void group_execute(void *data, int thread, bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out)
void ntreeTexEndExecTree_internal(bNodeTreeExec *exec)
void node_group_label(const bNodeTree *, const bNode *node, char *label, int label_maxncpy)
StructRNA * RNA_struct_find(const char *identifier)
static void * group_initexec(bNodeExecContext *context, bNode *node, bNodeInstanceKey key)
static void group_copy_inputs(bNode *gnode, bNodeStack **in, bNodeStack *gstack)
bNodeTreeExec * ntreeTexBeginExecTree_internal(bNodeExecContext *context, bNodeTree *ntree, bNodeInstanceKey parent_key)
BMesh const char void * data
static void copy_stack(bNodeStack *to, bNodeStack *from)
bNodeStack * node_get_socket_stack(bNodeStack *stack, bNodeSocket *sock)
Definition node_exec.cc:39
bool node_insert_link_default(bke::NodeInsertLinkParams &)
Definition node_util.cc:223
bool ntreeExecThreadNodes(bNodeTreeExec *exec, bNodeThreadStack *nts, void *callerdata, int thread)
static void group_freeexec(void *nodedata)
bool tex_node_poll_default(const bke::bNodeType *, const bNodeTree *ntree, const char **r_disabled_hint)
static void group_copy_outputs(bNode *gnode, bNodeStack **out, bNodeStack *gstack)
void RNA_struct_blender_type_set(StructRNA *srna, void *blender_type)
bNodeThreadStack * ntreeGetThreadStack(bNodeTreeExec *exec, int thread)
MINLINE void copy_v4_v4(float r[4], const float a[4])
bool node_group_poll_instance(const bNode *node, const bNodeTree *nodetree, const char **r_disabled_hint)
void register_node_type_tex_group()
void ntreeReleaseThreadStack(bNodeThreadStack *nts)
struct bNodeSocket * next
eNodeStack_Datatype datatype
ListBaseT< bNode > nodes
bke::bNodeRuntime * runtime
ListBaseT< bNodeSocket > inputs
static constexpr int GroupMin
Definition BKE_node.hh:256
Defines a node type.
Definition BKE_node.hh:265
NodeFreeExecFunction free_exec_fn
Definition BKE_node.hh:370
NodeExecFunction exec_fn
Definition BKE_node.hh:371
void(*) labelfunc(const bNodeTree *ntree, const bNode *node, char *label, int label_maxncpy)
Definition BKE_node.hh:301
bool(*) poll(const bNodeType *ntype, const bNodeTree *nodetree, const char **r_disabled_hint)
Definition BKE_node.hh:352
const char * enum_name_legacy
Definition BKE_node.hh:274
NodeDeclareFunction declare
Definition BKE_node.hh:393
NodeInitExecFunction init_exec_fn
Definition BKE_node.hh:369
bool(*) insert_link(NodeInsertLinkParams &params)
Definition BKE_node.hh:364
bool(*) poll_instance(const bNode *node, const bNodeTree *nodetree, const char **r_disabled_hint)
Definition BKE_node.hh:359