Blender  V2.93
node_shader_script.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) 2005 Blender Foundation.
17  * All rights reserved.
18  */
19 
24 #include "node_shader_util.h"
25 
26 /* **************** Script ******************** */
27 
28 static void init(bNodeTree *UNUSED(ntree), bNode *node)
29 {
30  NodeShaderScript *nss = MEM_callocN(sizeof(NodeShaderScript), "shader script node");
31  node->storage = nss;
32 }
33 
35 {
36  NodeShaderScript *nss = node->storage;
37 
38  if (nss) {
39  if (nss->bytecode) {
40  MEM_freeN(nss->bytecode);
41  }
42 
43  MEM_freeN(nss);
44  }
45 }
46 
47 static void node_copy_script(bNodeTree *UNUSED(dest_ntree),
48  bNode *dest_node,
49  const bNode *src_node)
50 {
51  NodeShaderScript *src_nss = src_node->storage;
52  NodeShaderScript *dest_nss = MEM_dupallocN(src_nss);
53 
54  if (src_nss->bytecode) {
55  dest_nss->bytecode = MEM_dupallocN(src_nss->bytecode);
56  }
57 
58  dest_node->storage = dest_nss;
59 }
60 
62 {
63  static bNodeType ntype;
64 
65  sh_node_type_base(&ntype, SH_NODE_SCRIPT, "Script", NODE_CLASS_SCRIPT, 0);
66  node_type_init(&ntype, init);
67  node_type_storage(&ntype, "NodeShaderScript", node_free_script, node_copy_script);
68 
69  nodeRegisterType(&ntype);
70 }
void node_type_init(struct bNodeType *ntype, void(*initfunc)(struct bNodeTree *ntree, struct bNode *node))
Definition: node.cc:4559
void node_type_storage(struct bNodeType *ntype, const char *storagename, void(*freefunc)(struct bNode *node), void(*copyfunc)(struct bNodeTree *dest_ntree, struct bNode *dest_node, const struct bNode *src_node))
Definition: node.cc:4599
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1298
#define SH_NODE_SCRIPT
Definition: BKE_node.h:1036
#define NODE_CLASS_SCRIPT
Definition: BKE_node.h:356
#define UNUSED(x)
OperationNode * node
bNodeTree * ntree
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:41
void *(* MEM_dupallocN)(const void *vmemh)
Definition: mallocn.c:42
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:45
static void node_free_script(bNode *node)
void register_node_type_sh_script(void)
static void node_copy_script(bNodeTree *UNUSED(dest_ntree), bNode *dest_node, const bNode *src_node)
static void init(bNodeTree *UNUSED(ntree), bNode *node)
void sh_node_type_base(struct bNodeType *ntype, int type, const char *name, short nclass, short flag)
Defines a node type.
Definition: BKE_node.h:221
void * storage