[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [34682] trunk/blender/source/blender: A simplified way of defining bNodeType structs.

Lukas Toenne lukas.toenne at googlemail.com
Mon Feb 7 10:33:38 CET 2011


Revision: 34682
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=34682
Author:   lukastoenne
Date:     2011-02-07 09:33:36 +0000 (Mon, 07 Feb 2011)
Log Message:
-----------
A simplified way of defining bNodeType structs. Instead of doing full struct member initialization for each node, this uses a couple of helper functions now. This will make it easier to change and extend the bNodeSocket interface in the future. Two examples (normal and mapping shader nodes) included, the rest should be converted too.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_node.h
    trunk/blender/source/blender/blenkernel/intern/node.c
    trunk/blender/source/blender/nodes/SHD_node.h
    trunk/blender/source/blender/nodes/intern/SHD_nodes/SHD_mapping.c
    trunk/blender/source/blender/nodes/intern/SHD_nodes/SHD_normal.c
    trunk/blender/source/blender/nodes/intern/SHD_util.h

Modified: trunk/blender/source/blender/blenkernel/BKE_node.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_node.h	2011-02-07 08:13:28 UTC (rev 34681)
+++ trunk/blender/source/blender/blenkernel/BKE_node.h	2011-02-07 09:33:36 UTC (rev 34682)
@@ -206,6 +206,18 @@
 
 /* ************** COMMON NODES *************** */
 
+/* Init a new node type struct with default values and callbacks */
+void			node_type_init(struct bNodeType *ntype, int type, const char *name, short nclass, short flag,
+							   struct bNodeSocketType *inputs, struct bNodeSocketType *outputs);
+void			node_type_size(struct bNodeType *ntype, int width, int minwidth, int maxwidth);
+void			node_type_storage(struct bNodeType *ntype,
+								  const char *storagename,
+								  void (*initfunc)(struct bNode *),
+								  void (*freestoragefunc)(struct bNode *),
+								  void (*copystoragefunc)(struct bNode *, struct bNode *));
+void			node_type_exec(struct bNodeType *ntype, void (*execfunc)(void *data, struct bNode *, struct bNodeStack **, struct bNodeStack **));
+void			node_type_gpu(struct bNodeType *ntype, int (*gpufunc)(struct GPUMaterial *mat, struct bNode *node, struct GPUNodeStack *in, struct GPUNodeStack *out));
+
 #define NODE_GROUP		2
 #define NODE_GROUP_MENU		1000
 #define NODE_DYNAMIC_MENU	4000

Modified: trunk/blender/source/blender/blenkernel/intern/node.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/node.c	2011-02-07 08:13:28 UTC (rev 34681)
+++ trunk/blender/source/blender/blenkernel/intern/node.c	2011-02-07 09:33:36 UTC (rev 34682)
@@ -43,6 +43,7 @@
 #include "BKE_animsys.h"
 #include "BKE_action.h"
 #include "BKE_fcurve.h"
+#include "BKE_node.h"
 #include "BKE_utildefines.h"
 
 #include "PIL_time.h"
@@ -3232,6 +3233,51 @@
 
 /* ************* node definition init ********** */
 
+void node_type_init(bNodeType *ntype, int type, const char *name, short nclass, short flag,
+					struct bNodeSocketType *inputs, struct bNodeSocketType *outputs)
+{
+	memset(ntype, 0, sizeof(bNodeType));
+	
+	ntype->type = type;
+	ntype->name = name;
+	ntype->nclass = nclass;
+	ntype->flag = flag;
+	
+	ntype->inputs = inputs;
+	ntype->outputs = outputs;
+	
+	/* default size values */
+	ntype->width = 140;
+	ntype->minwidth = 100;
+	ntype->maxwidth = 320;
+}
+
+void node_type_size(struct bNodeType *ntype, int width, int minwidth, int maxwidth)
+{
+	ntype->width = width;
+	ntype->minwidth = minwidth;
+	ntype->maxwidth = maxwidth;
+}
+
+void node_type_storage(bNodeType *ntype, const char *storagename, void (*initfunc)(struct bNode *), void (*freestoragefunc)(struct bNode *), void (*copystoragefunc)(struct bNode *, struct bNode *))
+{
+	strncpy(ntype->storagename, storagename, sizeof(ntype->storagename));
+	ntype->initfunc = initfunc;
+	ntype->copystoragefunc = copystoragefunc;
+	ntype->freestoragefunc = freestoragefunc;
+}
+
+void node_type_exec(struct bNodeType *ntype, void (*execfunc)(void *data, struct bNode *, struct bNodeStack **, struct bNodeStack **))
+{
+	ntype->execfunc = execfunc;
+}
+
+void node_type_gpu(struct bNodeType *ntype, int (*gpufunc)(struct GPUMaterial *mat, struct bNode *node, struct GPUNodeStack *in, struct GPUNodeStack *out))
+{
+	ntype->gpufunc = gpufunc;
+}
+
+
 static bNodeType *is_nodetype_registered(ListBase *typelist, int type, ID *id) 
 {
 	bNodeType *ntype= typelist->first;
@@ -3337,9 +3383,9 @@
 	nodeRegisterType(ntypelist, &sh_node_mix_rgb);
 	nodeRegisterType(ntypelist, &sh_node_valtorgb);
 	nodeRegisterType(ntypelist, &sh_node_rgbtobw);
-	nodeRegisterType(ntypelist, &sh_node_normal);
+	register_node_type_sh_normal(ntypelist);
 	nodeRegisterType(ntypelist, &sh_node_geom);
-	nodeRegisterType(ntypelist, &sh_node_mapping);
+	register_node_type_sh_mapping(ntypelist);
 	nodeRegisterType(ntypelist, &sh_node_curve_vec);
 	nodeRegisterType(ntypelist, &sh_node_curve_rgb);
 	nodeRegisterType(ntypelist, &sh_node_math);

Modified: trunk/blender/source/blender/nodes/SHD_node.h
===================================================================
--- trunk/blender/source/blender/nodes/SHD_node.h	2011-02-07 08:13:28 UTC (rev 34681)
+++ trunk/blender/source/blender/nodes/SHD_node.h	2011-02-07 09:33:36 UTC (rev 34682)
@@ -48,9 +48,9 @@
 extern bNodeType sh_node_valtorgb;
 extern bNodeType sh_node_rgbtobw;
 extern bNodeType sh_node_texture;
-extern bNodeType sh_node_normal;
+void register_node_type_sh_normal(ListBase *lb);
 extern bNodeType sh_node_geom;
-extern bNodeType sh_node_mapping;
+void register_node_type_sh_mapping(ListBase *lb);
 extern bNodeType sh_node_curve_vec;
 extern bNodeType sh_node_curve_rgb;
 extern bNodeType sh_node_math;

Modified: trunk/blender/source/blender/nodes/intern/SHD_nodes/SHD_mapping.c
===================================================================
--- trunk/blender/source/blender/nodes/intern/SHD_nodes/SHD_mapping.c	2011-02-07 08:13:28 UTC (rev 34681)
+++ trunk/blender/source/blender/nodes/intern/SHD_nodes/SHD_mapping.c	2011-02-07 09:33:36 UTC (rev 34682)
@@ -83,22 +83,16 @@
 	return GPU_stack_link(mat, "mapping", in, out, tmat, tmin, tmax, tdomin, tdomax);
 }
 
-bNodeType sh_node_mapping= {
-	/* *next,*prev */	NULL, NULL,
-	/* type code   */	SH_NODE_MAPPING,
-	/* name        */	"Mapping",
-	/* width+range */	240, 160, 320,
-	/* class+opts  */	NODE_CLASS_OP_VECTOR, NODE_OPTIONS,
-	/* input sock  */	sh_node_mapping_in,
-	/* output sock */	sh_node_mapping_out,
-	/* storage     */	"TexMapping",
-	/* execfunc    */	node_shader_exec_mapping,
-	/* butfunc     */	NULL,
-	/* initfunc    */	node_shader_init_mapping,
-	/* freestoragefunc    */	node_free_standard_storage,
-	/* copystoragefunc    */	node_copy_standard_storage,
-	/* id          */	NULL, NULL, NULL,
-	/* gpufunc     */	gpu_shader_mapping
+void register_node_type_sh_mapping(ListBase *lb)
+{
+	static bNodeType ntype;
 	
-};
-
+	node_type_init(&ntype, SH_NODE_MAPPING, "Mapping", NODE_CLASS_OP_VECTOR, NODE_OPTIONS,
+				   sh_node_mapping_in, sh_node_mapping_out);
+	node_type_size(&ntype, 240, 160, 320);
+	node_type_storage(&ntype, "TexMapping", node_shader_init_mapping, node_free_standard_storage, node_copy_standard_storage);
+	node_type_exec(&ntype, node_shader_exec_mapping);
+	node_type_gpu(&ntype, gpu_shader_mapping);
+	
+	nodeRegisterType(lb, &ntype);
+}

Modified: trunk/blender/source/blender/nodes/intern/SHD_nodes/SHD_normal.c
===================================================================
--- trunk/blender/source/blender/nodes/intern/SHD_nodes/SHD_normal.c	2011-02-07 08:13:28 UTC (rev 34681)
+++ trunk/blender/source/blender/nodes/intern/SHD_nodes/SHD_normal.c	2011-02-07 09:33:36 UTC (rev 34682)
@@ -65,21 +65,14 @@
 	return GPU_stack_link(mat, "normal", in, out, vec);
 }
 
-bNodeType sh_node_normal= {
-	/* *next,*prev */	NULL, NULL,
-	/* type code   */	SH_NODE_NORMAL,
-	/* name        */	"Normal",
-	/* width+range */	100, 60, 200,
-	/* class+opts  */	NODE_CLASS_OP_VECTOR, NODE_OPTIONS,
-	/* input sock  */	sh_node_normal_in,
-	/* output sock */	sh_node_normal_out,
-	/* storage     */	"",
-	/* execfunc    */	node_shader_exec_normal,
-	/* butfunc     */	NULL,
-	/* initfunc    */	NULL,
-	/* freestoragefunc    */	NULL,
-	/* copystoragefunc    */	NULL,
-	/* id          */	NULL, NULL, NULL,
-	/* gpufunc     */	gpu_shader_normal
-};
-
+void register_node_type_sh_normal(ListBase *lb)
+{
+	static bNodeType ntype;
+	
+	node_type_init(&ntype, SH_NODE_NORMAL, "Normal", NODE_CLASS_OP_VECTOR, NODE_OPTIONS,
+				   sh_node_normal_in, sh_node_normal_out);
+	node_type_exec(&ntype, node_shader_exec_normal);
+	node_type_gpu(&ntype, gpu_shader_normal);
+	
+	nodeRegisterType(lb, &ntype);
+}

Modified: trunk/blender/source/blender/nodes/intern/SHD_util.h
===================================================================
--- trunk/blender/source/blender/nodes/intern/SHD_util.h	2011-02-07 08:13:28 UTC (rev 34681)
+++ trunk/blender/source/blender/nodes/intern/SHD_util.h	2011-02-07 09:33:36 UTC (rev 34682)
@@ -51,6 +51,7 @@
 #include "BKE_image.h"
 #include "BKE_main.h"
 #include "BKE_material.h"
+#include "BKE_node.h"
 #include "BKE_texture.h"
 
 #include "BKE_library.h"




More information about the Bf-blender-cvs mailing list