Blender  V3.3
node_texture_common.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2006 Blender Foundation. All rights reserved. */
3 
8 #include "DNA_node_types.h"
9 
10 #include "BLI_utildefines.h"
11 
12 #include "BKE_node.h"
13 
14 #include "NOD_common.h"
15 #include "node_common.h"
16 #include "node_exec.h"
17 #include "node_texture_util.h"
18 
19 #include "RNA_access.h"
20 
22 {
23  if (to != from) {
24  copy_v4_v4(to->vec, from->vec);
25  to->data = from->data;
26  to->datatype = from->datatype;
27 
28  /* tag as copy to prevent freeing */
29  to->is_copy = 1;
30  }
31 }
32 
33 /**** GROUP ****/
34 
36 {
37  bNodeTree *ngroup = (bNodeTree *)node->id;
38  void *exec;
39 
40  if (!ngroup) {
41  return NULL;
42  }
43 
44  /* initialize the internal node tree execution */
46 
47  return exec;
48 }
49 
50 static void group_freeexec(void *nodedata)
51 {
52  bNodeTreeExec *gexec = (bNodeTreeExec *)nodedata;
53 
55 }
56 
57 /* Copy inputs to the internal stack.
58  * This is a shallow copy, no buffers are duplicated here!
59  */
60 static void group_copy_inputs(bNode *gnode, bNodeStack **in, bNodeStack *gstack)
61 {
62  bNodeTree *ngroup = (bNodeTree *)gnode->id;
63  bNode *node;
64  bNodeSocket *sock;
65  bNodeStack *ns;
66  int a;
67 
68  for (node = ngroup->nodes.first; node; node = node->next) {
69  if (node->type == NODE_GROUP_INPUT) {
70  for (sock = node->outputs.first, a = 0; sock; sock = sock->next, a++) {
71  if (in[a]) { /* shouldn't need to check this T36694. */
72  ns = node_get_socket_stack(gstack, sock);
73  if (ns) {
74  copy_stack(ns, in[a]);
75  }
76  }
77  }
78  }
79  }
80 }
81 
82 /* Copy internal results to the external outputs.
83  */
84 static void group_copy_outputs(bNode *gnode, bNodeStack **out, bNodeStack *gstack)
85 {
86  bNodeTree *ngroup = (bNodeTree *)gnode->id;
87  bNode *node;
88  bNodeSocket *sock;
89  bNodeStack *ns;
90  int a;
91 
92  for (node = ngroup->nodes.first; node; node = node->next) {
93  if (node->type == NODE_GROUP_OUTPUT && (node->flag & NODE_DO_OUTPUT)) {
94  for (sock = node->inputs.first, a = 0; sock; sock = sock->next, a++) {
95  if (out[a]) { /* shouldn't need to check this T36694. */
96  ns = node_get_socket_stack(gstack, sock);
97  if (ns) {
98  copy_stack(out[a], ns);
99  }
100  }
101  }
102  break; /* only one active output node */
103  }
104  }
105 }
106 
107 static void group_execute(void *data,
108  int thread,
109  struct bNode *node,
110  bNodeExecData *execdata,
111  struct bNodeStack **in,
112  struct bNodeStack **out)
113 {
114  bNodeTreeExec *exec = execdata->data;
115  bNodeThreadStack *nts;
116 
117  if (!exec) {
118  return;
119  }
120 
121  /* XXX same behavior as trunk: all nodes inside group are executed.
122  * it's stupid, but just makes it work. compo redesign will do this better.
123  */
124  {
125  bNode *inode;
126  for (inode = exec->nodetree->nodes.first; inode; inode = inode->next) {
127  inode->need_exec = 1;
128  }
129  }
130 
132 
133  group_copy_inputs(node, in, nts->stack);
136 
138 }
139 
141 {
142  static bNodeType ntype;
143 
144  /* NOTE: Cannot use #sh_node_type_base for node group, because it would map the node type
145  * to the shared #NODE_GROUP integer type id. */
146 
147  node_type_base_custom(&ntype, "TextureNodeGroup", "Group", NODE_CLASS_GROUP);
148  ntype.type = NODE_GROUP;
149  ntype.poll = tex_node_poll_default;
152  ntype.rna_ext.srna = RNA_struct_find("TextureNodeGroup");
153  BLI_assert(ntype.rna_ext.srna != NULL);
155 
156  node_type_size(&ntype, 140, 60, 400);
157  ntype.labelfunc = node_group_label;
160 
161  nodeRegisterType(&ntype);
162 }
void node_type_base_custom(struct bNodeType *ntype, const char *idname, const char *name, short nclass)
Definition: node.cc:4311
void node_type_size(struct bNodeType *ntype, int width, int minwidth, int maxwidth)
Definition: node.cc:4396
void node_type_group_update(struct bNodeType *ntype, void(*group_update_func)(struct bNodeTree *ntree, struct bNode *node))
Definition: node.cc:4449
#define NODE_CLASS_GROUP
Definition: BKE_node.h:350
#define NODE_GROUP_INPUT
Definition: BKE_node.h:987
void node_type_exec(struct bNodeType *ntype, NodeInitExecFunction init_exec_fn, NodeFreeExecFunction free_exec_fn, NodeExecFunction exec_fn)
Definition: node.cc:4455
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1357
#define BLI_assert(a)
Definition: BLI_assert.h:46
MINLINE void copy_v4_v4(float r[4], const float a[4])
#define NODE_DO_OUTPUT
NODE_GROUP_OUTPUT
NODE_GROUP
Definition: thread.h:34
OperationNode * node
StackEntry * from
static unsigned a[3]
Definition: RandGen.cpp:78
static const pxr::TfToken out("out", pxr::TfToken::Immortal)
void node_group_update(struct bNodeTree *ntree, struct bNode *node)
Definition: node_common.cc:213
bool node_group_poll_instance(bNode *node, bNodeTree *nodetree, const char **disabled_hint)
Definition: node_common.cc:71
void node_group_label(const bNodeTree *UNUSED(ntree), const bNode *node, char *label, int maxlen)
Definition: node_common.cc:66
bNodeStack * node_get_socket_stack(bNodeStack *stack, bNodeSocket *sock)
Definition: node_exec.cc:28
static void exec(void *data, int UNUSED(thread), bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out)
static void group_execute(void *data, int thread, struct bNode *node, bNodeExecData *execdata, struct bNodeStack **in, struct bNodeStack **out)
void register_node_type_tex_group(void)
static void * group_initexec(bNodeExecContext *context, bNode *node, bNodeInstanceKey key)
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)
bNodeThreadStack * ntreeGetThreadStack(bNodeTreeExec *exec, int thread)
bool ntreeExecThreadNodes(bNodeTreeExec *exec, bNodeThreadStack *nts, void *callerdata, int thread)
void ntreeTexEndExecTree_internal(bNodeTreeExec *exec)
bNodeTreeExec * ntreeTexBeginExecTree_internal(bNodeExecContext *context, bNodeTree *ntree, bNodeInstanceKey parent_key)
void ntreeReleaseThreadStack(bNodeThreadStack *nts)
bool tex_node_poll_default(bNodeType *UNUSED(ntype), bNodeTree *ntree, const char **r_disabled_hint)
void node_insert_link_default(bNodeTree *ntree, bNode *node, bNodeLink *link)
Definition: node_util.c:326
void RNA_struct_blender_type_set(StructRNA *srna, void *blender_type)
Definition: rna_access.c:902
StructRNA * RNA_struct_find(const char *identifier)
Definition: rna_access.c:581
StructRNA * srna
Definition: RNA_types.h:766
void * first
Definition: DNA_listBase.h:31
float vec[4]
short datatype
struct bNodeStack * stack
Definition: node_exec.h:54
ListBase nodes
Defines a node type.
Definition: BKE_node.h:226
bool(* poll)(struct bNodeType *ntype, struct bNodeTree *nodetree, const char **r_disabled_hint)
Definition: BKE_node.h:292
ExtensionRNA rna_ext
Definition: BKE_node.h:341
int type
Definition: BKE_node.h:228
void(* insert_link)(struct bNodeTree *ntree, struct bNode *node, struct bNodeLink *link)
Definition: BKE_node.h:301
void(* labelfunc)(const struct bNodeTree *ntree, const struct bNode *node, char *label, int maxlen)
Definition: BKE_node.h:256
bool(* poll_instance)(struct bNode *node, struct bNodeTree *nodetree, const char **r_disabled_hint)
Definition: BKE_node.h:296
struct ID * id
struct bNode * next
uint8_t need_exec