[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [29230] branches/soc-2010-moguri: Working on storing data for custom uniforms.

Mitchell Stokes mogurijin at gmail.com
Sat Jun 5 02:17:51 CEST 2010


Revision: 29230
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=29230
Author:   moguri
Date:     2010-06-05 02:17:51 +0200 (Sat, 05 Jun 2010)

Log Message:
-----------
Working on storing data for custom uniforms. So far int, float and uint are working.

Modified Paths:
--------------
    branches/soc-2010-moguri/release/scripts/ui/properties_material.py
    branches/soc-2010-moguri/source/blender/makesdna/DNA_material_types.h
    branches/soc-2010-moguri/source/blender/makesrna/intern/rna_material.c

Modified: branches/soc-2010-moguri/release/scripts/ui/properties_material.py
===================================================================
--- branches/soc-2010-moguri/release/scripts/ui/properties_material.py	2010-06-04 23:38:59 UTC (rev 29229)
+++ branches/soc-2010-moguri/release/scripts/ui/properties_material.py	2010-06-05 00:17:51 UTC (rev 29230)
@@ -817,6 +817,10 @@
             #layout.label(text="")
             row.prop(lay, "name")
             row.prop(lay, "type", text="")
+            if hasattr(lay, "value"):
+                row = layout.row()
+                row.prop(lay, "value")
+                row.prop(lay, "size")
 
 class VolumeButtonsPanel(bpy.types.Panel):
     bl_space_type = 'PROPERTIES'

Modified: branches/soc-2010-moguri/source/blender/makesdna/DNA_material_types.h
===================================================================
--- branches/soc-2010-moguri/source/blender/makesdna/DNA_material_types.h	2010-06-04 23:38:59 UTC (rev 29229)
+++ branches/soc-2010-moguri/source/blender/makesdna/DNA_material_types.h	2010-06-05 00:17:51 UTC (rev 29230)
@@ -75,7 +75,7 @@
 typedef struct CustomUniform {
 	struct CustomUniform *next, *prev;
 	char name[64];
-	short type, pad[3];
+	short type, size, pad[2];
 	void *data;
 } CustomUniform;
 
@@ -230,13 +230,14 @@
 
 /* Uniform type */
 #define MA_UNF_FLOAT	1
-#define MA_UNF_VEC2		2
-#define MA_UNF_VEC3		3
-#define MA_UNF_VEC4		4
-#define MA_UNF_INT		5
-#define MA_UNF_IVEC2	6
-#define MA_UNF_IVEC3	7
-#define MA_UNF_IVEC4	8
+#define MA_UNF_VEC		2
+#define MA_UNF_INT		3
+#define MA_UNF_IVEC		4
+#define MA_UNF_UINT		5
+#define MA_UNF_UVEC		6
+#define MA_UNF_BOOL		7
+#define MA_UNF_BVEC		8
+#define MA_UNF_MAT		9
 
 /* mode (is int) */
 #define MA_TRACEBLE		1

Modified: branches/soc-2010-moguri/source/blender/makesrna/intern/rna_material.c
===================================================================
--- branches/soc-2010-moguri/source/blender/makesrna/intern/rna_material.c	2010-06-04 23:38:59 UTC (rev 29229)
+++ branches/soc-2010-moguri/source/blender/makesrna/intern/rna_material.c	2010-06-05 00:17:51 UTC (rev 29230)
@@ -185,6 +185,36 @@
 	*max= MAX2(0, *max);
 }
 
+static float rna_FloatUniform_value_get(struct PointerRNA *ptr)
+{
+	CustomUniform *cu= (CustomUniform*)ptr->data;
+	return *(float*)(&cu->data);
+}
+
+static void rna_FloatUniform_value_set(struct PointerRNA *ptr, float value)
+{
+	CustomUniform *cu= (CustomUniform*)ptr->data;
+	*(float*)(&cu->data)= value;
+}
+
+static StructRNA* rna_CustomUniform_refine(struct PointerRNA *ptr)
+{
+	CustomUniform *cu= (CustomUniform*)ptr->data;
+
+	switch(cu->type){
+	case MA_UNF_FLOAT:
+		return &RNA_FloatUniform;
+	case MA_UNF_INT:
+		return &RNA_IntUniform;
+	case MA_UNF_UINT:
+		return &RNA_UIntUniform;
+	//case MA_UNF_BOOL:
+		//return &RNA_BoolUniform;
+	default:
+		return &RNA_CustomUniform;
+	}
+}
+
 static void rna_MaterialStrand_start_size_range(PointerRNA *ptr, float *min, float *max)
 {
 	Material *ma= (Material*)ptr->id.data;
@@ -925,6 +955,36 @@
 	RNA_def_property_update(prop, 0, "rna_Material_update");
 }
 
+/* Helper function for defining the different uniform data types */
+static void rna_def_uniformtype(BlenderRNA *brna, const char *name, const char *doc, int type, int subtype, int min, int max)
+{
+	PropertyRNA *prop;
+	StructRNA *srna;
+
+	srna= RNA_def_struct(brna, name, "CustomUniform");
+	RNA_def_struct_ui_text(srna, name, doc);
+	RNA_def_struct_sdna(srna, "CustomUniform");
+
+	prop= RNA_def_property(srna, "value", type, subtype);
+	if (type == PROP_INT)
+		RNA_def_property_int_sdna(prop, NULL, "data");
+	else if (type == PROP_BOOLEAN)
+		RNA_def_property_boolean_sdna(prop, NULL, "data", 1);
+	else if (type == PROP_FLOAT)
+	{
+		RNA_def_property_float_sdna(prop, NULL, "data");
+		RNA_def_property_float_funcs(prop, "rna_FloatUniform_value_get", "rna_FloatUniform_value_set", NULL);
+	}
+	RNA_def_property_ui_text(prop, "Value", "Uniform value");
+	RNA_def_property_update(prop, 0, "rna_Material_update");
+
+	prop= RNA_def_property(srna, "size", PROP_INT, PROP_NONE);
+	RNA_def_property_int_sdna(prop, NULL, "size");
+	RNA_def_property_range(prop, min, max);
+	RNA_def_property_ui_text(prop, "Size", "The number of elements in the uniform");
+	RNA_def_property_update(prop, 0, "rna_Material_update");
+}
+
 static void rna_def_material_uniform(BlenderRNA *brna)
 {
 	StructRNA *srna;
@@ -932,19 +992,20 @@
 
 	static EnumPropertyItem prop_type_items[] = {
 		{MA_UNF_FLOAT, "FLOAT", 0, "float", "float"},
-		{MA_UNF_VEC2, "VEC2", 0, "vec2", "vec2"},
-		{MA_UNF_VEC3, "VEC3", 0, "vec3", "vec3"},
-		{MA_UNF_VEC4, "VEC4", 0, "vec4", "vec4"},
+		//{MA_UNF_VEC, "VEC", 0, "vec", "vec"},
 		{MA_UNF_INT, "INT", 0, "int", "int"},
-		{MA_UNF_IVEC2, "IVEC2", 0, "ivec2", "ivec2"},
-		{MA_UNF_IVEC3, "IVEC3", 0, "ivec3", "ivec3"},
-		{MA_UNF_IVEC4, "IVEC4", 0, "ivec4", "ivec4"},
+		//{MA_UNF_IVEC2, "IVEC", 0, "ivec", "ivec"},
+		{MA_UNF_UINT, "UINT", 0, "uint", "uint"},
+		//{MA_UNF_UVEC, "UVEC", 0, "uvec", "uvec"},
+		{MA_UNF_BOOL, "BOOL", 0, "bool", "bool"},
+		//{MA_UNF_BVEC, "BVEC", 0, "bvec", "bvec"},
 		{0, NULL, 0, NULL, NULL}};
 
 	srna= RNA_def_struct(brna, "CustomUniform", NULL);
 	RNA_def_struct_sdna(srna, "CustomUniform");
 	RNA_def_struct_nested(brna, srna, "Material");
 	RNA_def_struct_ui_text(srna, "Uniform", "Uniform data for custom shaders.");
+	RNA_def_struct_refine_func(srna, "rna_CustomUniform_refine");
 
 	prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
 	RNA_def_struct_name_property(srna, prop);
@@ -957,8 +1018,13 @@
 	RNA_def_property_enum_items(prop, prop_type_items);
 	RNA_def_property_ui_text(prop, "Uniform type", "The data type of the uniform");
 	RNA_def_property_update(prop, 0, "rna_Material_update");
+
+	rna_def_uniformtype(brna, "FloatUniform", "Custom float uniform", PROP_FLOAT, PROP_NONE, 1, 1);
+	rna_def_uniformtype(brna, "IntUniform", "Custom integer uniform", PROP_INT, PROP_NONE, 1, 1);
+	rna_def_uniformtype(brna, "UIntUniform", "Custom unsigned integer uniform", PROP_INT, PROP_UNSIGNED, 1, 1);
+	//rna_def_uniformtype(brna, "BoolUniform", "Custom boolean uniform", PROP_BOOLEAN, PROP_NONE, 1, 1);
+
 }
-
 static void rna_def_material_raymirror(BlenderRNA *brna)
 {
 	StructRNA *srna;





More information about the Bf-blender-cvs mailing list