Blender  V2.93
node_texture_common.c
Go to the documentation of this file.
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) 2006 Blender Foundation.
17  * All rights reserved.
18  * Juho Vepsäläinen
19  */
20 
25 #include "DNA_node_types.h"
26 
27 #include "BLI_utildefines.h"
28 
29 #include "BKE_node.h"
30 
31 #include "NOD_common.h"
32 #include "node_common.h"
33 #include "node_exec.h"
34 #include "node_texture_util.h"
35 
36 #include "RNA_access.h"
37 
39 {
40  if (to != from) {
41  copy_v4_v4(to->vec, from->vec);
42  to->data = from->data;
43  to->datatype = from->datatype;
44 
45  /* tag as copy to prevent freeing */
46  to->is_copy = 1;
47  }
48 }
49 
50 /**** GROUP ****/
51 
53 {
54  bNodeTree *ngroup = (bNodeTree *)node->id;
55  void *exec;
56 
57  if (!ngroup) {
58  return NULL;
59  }
60 
61  /* initialize the internal node tree execution */
63 
64  return exec;
65 }
66 
67 static void group_freeexec(void *nodedata)
68 {
69  bNodeTreeExec *gexec = (bNodeTreeExec *)nodedata;
70 
72 }
73 
74 /* Copy inputs to the internal stack.
75  * This is a shallow copy, no buffers are duplicated here!
76  */
77 static void group_copy_inputs(bNode *gnode, bNodeStack **in, bNodeStack *gstack)
78 {
79  bNodeTree *ngroup = (bNodeTree *)gnode->id;
80  bNode *node;
81  bNodeSocket *sock;
82  bNodeStack *ns;
83  int a;
84 
85  for (node = ngroup->nodes.first; node; node = node->next) {
86  if (node->type == NODE_GROUP_INPUT) {
87  for (sock = node->outputs.first, a = 0; sock; sock = sock->next, a++) {
88  if (in[a]) { /* shouldn't need to check this T36694. */
89  ns = node_get_socket_stack(gstack, sock);
90  if (ns) {
91  copy_stack(ns, in[a]);
92  }
93  }
94  }
95  }
96  }
97 }
98 
99 /* Copy internal results to the external outputs.
100  */
101 static void group_copy_outputs(bNode *gnode, bNodeStack **out, bNodeStack *gstack)
102 {
103  bNodeTree *ngroup = (bNodeTree *)gnode->id;
104  bNode *node;
105  bNodeSocket *sock;
106  bNodeStack *ns;
107  int a;
108 
109  for (node = ngroup->nodes.first; node; node = node->next) {
110  if (node->type == NODE_GROUP_OUTPUT && (node->flag & NODE_DO_OUTPUT)) {
111  for (sock = node->inputs.first, a = 0; sock; sock = sock->next, a++) {
112  if (out[a]) { /* shouldn't need to check this T36694. */
113  ns = node_get_socket_stack(gstack, sock);
114  if (ns) {
115  copy_stack(out[a], ns);
116  }
117  }
118  }
119  break; /* only one active output node */
120  }
121  }
122 }
123 
124 static void group_execute(void *data,
125  int thread,
126  struct bNode *node,
127  bNodeExecData *execdata,
128  struct bNodeStack **in,
129  struct bNodeStack **out)
130 {
131  bNodeTreeExec *exec = execdata->data;
132  bNodeThreadStack *nts;
133 
134  if (!exec) {
135  return;
136  }
137 
138  /* XXX same behavior as trunk: all nodes inside group are executed.
139  * it's stupid, but just makes it work. compo redesign will do this better.
140  */
141  {
142  bNode *inode;
143  for (inode = exec->nodetree->nodes.first; inode; inode = inode->next) {
144  inode->need_exec = 1;
145  }
146  }
147 
149 
150  group_copy_inputs(node, in, nts->stack);
152  group_copy_outputs(node, out, nts->stack);
153 
155 }
156 
158 {
159  static bNodeType ntype;
160 
161  /* NB: cannot use sh_node_type_base for node group, because it would map the node type
162  * to the shared NODE_GROUP integer type id.
163  */
164  node_type_base_custom(&ntype, "TextureNodeGroup", "Group", NODE_CLASS_GROUP, NODE_CONST_OUTPUT);
165  ntype.type = NODE_GROUP;
166  ntype.poll = tex_node_poll_default;
170  ntype.rna_ext.srna = RNA_struct_find("TextureNodeGroup");
171  BLI_assert(ntype.rna_ext.srna != NULL);
173 
175  node_type_size(&ntype, 140, 60, 400);
179 
180  nodeRegisterType(&ntype);
181 }
void node_type_size(struct bNodeType *ntype, int width, int minwidth, int maxwidth)
Definition: node.cc:4565
void node_type_socket_templates(struct bNodeType *ntype, struct bNodeSocketTemplate *inputs, struct bNodeSocketTemplate *outputs)
Definition: node.cc:4527
void node_type_base_custom(struct bNodeType *ntype, const char *idname, const char *name, short nclass, short flag)
Definition: node.cc:4478
void node_type_group_update(struct bNodeType *ntype, void(*group_update_func)(struct bNodeTree *ntree, struct bNode *node))
Definition: node.cc:4629
#define NODE_CLASS_GROUP
Definition: BKE_node.h:339
#define NODE_GROUP_INPUT
Definition: BKE_node.h:874
void node_type_exec(struct bNodeType *ntype, NodeInitExecFunction init_exec_fn, NodeFreeExecFunction free_exec_fn, NodeExecFunction exec_fn)
Definition: node.cc:4635
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1298
void node_type_label(struct bNodeType *ntype, void(*labelfunc)(struct bNodeTree *ntree, struct bNode *, char *label, int maxlen))
#define BLI_assert(a)
Definition: BLI_assert.h:58
MINLINE void copy_v4_v4(float r[4], const float a[4])
#define NODE_DO_OUTPUT
#define NODE_CONST_OUTPUT
NODE_GROUP_OUTPUT
NODE_GROUP
OperationNode * node
StackEntry * from
static unsigned a[3]
Definition: RandGen.cpp:92
void node_group_update(struct bNodeTree *ntree, struct bNode *node)
Definition: node_common.c:187
bool node_group_poll_instance(bNode *node, bNodeTree *nodetree, const char **disabled_hint)
Definition: node_common.c:82
void node_group_label(bNodeTree *UNUSED(ntree), bNode *node, char *label, int maxlen)
Definition: node_common.c:77
bNodeThreadStack * ntreeGetThreadStack(bNodeTreeExec *exec, int thread)
Definition: node_exec.cc:283
bool ntreeExecThreadNodes(bNodeTreeExec *exec, bNodeThreadStack *nts, void *callerdata, int thread)
Definition: node_exec.cc:310
void ntreeReleaseThreadStack(bNodeThreadStack *nts)
Definition: node_exec.cc:305
bNodeStack * node_get_socket_stack(bNodeStack *stack, bNodeSocket *sock)
Definition: node_exec.cc:45
struct bNodeTreeExec * ntreeTexBeginExecTree_internal(struct bNodeExecContext *context, struct bNodeTree *ntree, bNodeInstanceKey parent_key)
void ntreeTexEndExecTree_internal(struct bNodeTreeExec *exec)
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)
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:305
void node_update_internal_links_default(bNodeTree *ntree, bNode *node)
Definition: node_util.c:503
void RNA_struct_blender_type_set(StructRNA *srna, void *blender_type)
Definition: rna_access.c:1044
StructRNA * RNA_struct_find(const char *identifier)
Definition: rna_access.c:718
struct SELECTID_Context context
Definition: select_engine.c:47
StructRNA * srna
Definition: RNA_types.h:681
void * first
Definition: DNA_listBase.h:47
void * data
Definition: node_util.h:53
float vec[4]
short datatype
struct bNodeStack * stack
Definition: node_exec.h:70
ListBase nodes
Defines a node type.
Definition: BKE_node.h:221
bool(* poll)(struct bNodeType *ntype, struct bNodeTree *nodetree, const char **r_disabled_hint)
Definition: BKE_node.h:301
void(* update_internal_links)(struct bNodeTree *, struct bNode *node)
Definition: BKE_node.h:312
ExtensionRNA rna_ext
Definition: BKE_node.h:330
int type
Definition: BKE_node.h:225
void(* insert_link)(struct bNodeTree *ntree, struct bNode *node, struct bNodeLink *link)
Definition: BKE_node.h:310
bool(* poll_instance)(struct bNode *node, struct bNodeTree *nodetree, const char **r_disabled_hint)
Definition: BKE_node.h:305
struct ID * id
struct bNode * next
uint8_t need_exec