Blender V4.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
9#include "DNA_node_types.h"
10
11#include "BLI_math_vector.h"
12#include "BLI_utildefines.h"
13
14#include "BKE_node.hh"
15#include "BKE_node_runtime.hh"
16
17#include "NOD_common.h"
18#include "node_common.h"
19#include "node_exec.hh"
20#include "node_texture_util.hh"
21
22#include "RNA_access.hh"
23
24static void copy_stack(bNodeStack *to, bNodeStack *from)
25{
26 if (to != from) {
27 copy_v4_v4(to->vec, from->vec);
28 to->data = from->data;
29 to->datatype = from->datatype;
30
31 /* tag as copy to prevent freeing */
32 to->is_copy = 1;
33 }
34}
35
36/**** GROUP ****/
37
38static void *group_initexec(bNodeExecContext *context, bNode *node, bNodeInstanceKey key)
39{
40 bNodeTree *ngroup = (bNodeTree *)node->id;
41 void *exec;
42
43 if (!ngroup) {
44 return nullptr;
45 }
46
47 /* initialize the internal node tree execution */
48 exec = ntreeTexBeginExecTree_internal(context, ngroup, key);
49
50 return exec;
51}
52
53static void group_freeexec(void *nodedata)
54{
55 bNodeTreeExec *gexec = (bNodeTreeExec *)nodedata;
56
58}
59
60/* Copy inputs to the internal stack.
61 * This is a shallow copy, no buffers are duplicated here!
62 */
63static void group_copy_inputs(bNode *gnode, bNodeStack **in, bNodeStack *gstack)
64{
65 bNodeTree *ngroup = (bNodeTree *)gnode->id;
66 bNodeSocket *sock;
67 bNodeStack *ns;
68 int a;
69
70 LISTBASE_FOREACH (bNode *, node, &ngroup->nodes) {
71 if (node->type == NODE_GROUP_INPUT) {
72 for (sock = static_cast<bNodeSocket *>(node->outputs.first), a = 0; sock;
73 sock = sock->next, a++)
74 {
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 const bNodeTree &ngroup = *reinterpret_cast<bNodeTree *>(gnode->id);
91
92 ngroup.ensure_topology_cache();
93 const bNode *group_output_node = ngroup.group_output_node();
94 if (!group_output_node) {
95 return;
96 }
97
98 int a;
99 LISTBASE_FOREACH_INDEX (bNodeSocket *, sock, &group_output_node->inputs, a) {
100 if (!out[a]) {
101 /* shouldn't need to check this #36694. */
102 continue;
103 }
104
105 bNodeStack *ns = node_get_socket_stack(gstack, sock);
106 if (ns) {
107 copy_stack(out[a], ns);
108 }
109 }
110}
111
112static void group_execute(void *data,
113 int thread,
114 bNode *node,
115 bNodeExecData *execdata,
116 bNodeStack **in,
117 bNodeStack **out)
118{
119 bNodeTreeExec *exec = static_cast<bNodeTreeExec *>(execdata->data);
120 bNodeThreadStack *nts;
121
122 if (!exec) {
123 return;
124 }
125
126 /* XXX same behavior as trunk: all nodes inside group are executed.
127 * it's stupid, but just makes it work. compo redesign will do this better.
128 */
129 LISTBASE_FOREACH (bNode *, inode, &exec->nodetree->nodes) {
130 inode->runtime->need_exec = 1;
131 }
132
134
135 group_copy_inputs(node, in, nts->stack);
136 ntreeExecThreadNodes(exec, nts, data, thread);
137 group_copy_outputs(node, out, nts->stack);
138
140}
141
143{
144 static blender::bke::bNodeType ntype;
145
146 /* NOTE: Cannot use #sh_node_type_base for node group, because it would map the node type
147 * to the shared #NODE_GROUP integer type id. */
148
150 &ntype, "TextureNodeGroup", "Group", "GROUP", NODE_CLASS_GROUP);
151 ntype.type = NODE_GROUP;
155 ntype.rna_ext.srna = RNA_struct_find("TextureNodeGroup");
156 BLI_assert(ntype.rna_ext.srna != nullptr);
158
159 blender::bke::node_type_size(&ntype, 140, 60, 400);
164 ntype.exec_fn = group_execute;
165
167}
#define NODE_GROUP
Definition BKE_node.hh:800
#define NODE_CLASS_GROUP
Definition BKE_node.hh:409
#define NODE_GROUP_INPUT
Definition BKE_node.hh:805
#define BLI_assert(a)
Definition BLI_assert.h:50
#define LISTBASE_FOREACH(type, var, list)
#define LISTBASE_FOREACH_INDEX(type, var, list, index_var)
MINLINE void copy_v4_v4(float r[4], const float a[4])
void node_type_size(bNodeType *ntype, int width, int minwidth, int maxwidth)
Definition node.cc:4602
void node_register_type(bNodeType *ntype)
Definition node.cc:1708
void node_type_base_custom(bNodeType *ntype, const char *idname, const char *name, const char *enum_name, short nclass)
Definition node.cc:4364
void node_group_declare(NodeDeclarationBuilder &b)
void node_group_label(const bNodeTree *, const bNode *node, char *label, int label_maxncpy)
bool node_group_poll_instance(const bNode *node, const bNodeTree *nodetree, const char **r_disabled_hint)
bNodeStack * node_get_socket_stack(bNodeStack *stack, bNodeSocket *sock)
Definition node_exec.cc:29
static void exec(void *data, int, bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out)
static void group_execute(void *data, int thread, bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out)
static void group_copy_inputs(bNode *gnode, bNodeStack **in, bNodeStack *gstack)
static void group_freeexec(void *nodedata)
static void group_copy_outputs(bNode *gnode, bNodeStack **out, bNodeStack *gstack)
static void copy_stack(bNodeStack *to, bNodeStack *from)
void register_node_type_tex_group()
static void * group_initexec(bNodeExecContext *context, bNode *node, bNodeInstanceKey key)
bNodeThreadStack * ntreeGetThreadStack(bNodeTreeExec *exec, int thread)
bool ntreeExecThreadNodes(bNodeTreeExec *exec, bNodeThreadStack *nts, void *callerdata, int thread)
bNodeTreeExec * ntreeTexBeginExecTree_internal(bNodeExecContext *context, bNodeTree *ntree, bNodeInstanceKey parent_key)
void ntreeTexEndExecTree_internal(bNodeTreeExec *exec)
void ntreeReleaseThreadStack(bNodeThreadStack *nts)
bool tex_node_poll_default(const blender::bke::bNodeType *, const bNodeTree *ntree, const char **r_disabled_hint)
bool node_insert_link_default(bNodeTree *, bNode *, bNodeLink *)
Definition node_util.cc:281
StructRNA * RNA_struct_find(const char *identifier)
void RNA_struct_blender_type_set(StructRNA *srna, void *blender_type)
StructRNA * srna
Definition RNA_types.hh:780
struct bNodeSocket * next
bNodeStack * stack
Definition node_exec.hh:51
ListBase nodes
ListBase inputs
struct ID * id
Defines a node type.
Definition BKE_node.hh:218
NodeFreeExecFunction free_exec_fn
Definition BKE_node.hh:315
NodeExecFunction exec_fn
Definition BKE_node.hh:316
bool(* poll_instance)(const bNode *node, const bNodeTree *nodetree, const char **r_disabled_hint)
Definition BKE_node.hh:304
void(* labelfunc)(const bNodeTree *ntree, const bNode *node, char *label, int label_maxncpy)
Definition BKE_node.hh:249
bool(* poll)(const bNodeType *ntype, const bNodeTree *nodetree, const char **r_disabled_hint)
Definition BKE_node.hh:299
bool(* insert_link)(bNodeTree *ntree, bNode *node, bNodeLink *link)
Definition BKE_node.hh:309
NodeDeclareFunction declare
Definition BKE_node.hh:347
NodeInitExecFunction init_exec_fn
Definition BKE_node.hh:314