[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [29397] branches/soc-2010-moguri/source/ blender: More work on CustomUniforms:

Mitchell Stokes mogurijin at gmail.com
Fri Jun 11 02:23:55 CEST 2010


Revision: 29397
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=29397
Author:   moguri
Date:     2010-06-11 02:23:53 +0200 (Fri, 11 Jun 2010)

Log Message:
-----------
More work on CustomUniforms:
 * Adding a sampler2D type (save/load not working with this yet)
 * Starting to pass data to the gpu (float only at the moment)

Modified Paths:
--------------
    branches/soc-2010-moguri/source/blender/gpu/intern/gpu_material.c
    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/source/blender/gpu/intern/gpu_material.c
===================================================================
--- branches/soc-2010-moguri/source/blender/gpu/intern/gpu_material.c	2010-06-10 23:53:13 UTC (rev 29396)
+++ branches/soc-2010-moguri/source/blender/gpu/intern/gpu_material.c	2010-06-11 00:23:53 UTC (rev 29397)
@@ -361,6 +361,8 @@
 {
 	if(material->pass) {
 		GPUShader *shader = GPU_pass_shader(material->pass);
+		CustomUniform *cu;
+		int loc;
 		LinkData *nlink;
 		GPULamp *lamp;
 		float invmat[4][4], col[4];
@@ -385,6 +387,13 @@
 			GPU_shader_uniform_vector(shader, material->obcolloc, 4, 1, col);
 		}
 
+		/* handle custom uniforms */
+		for(cu=material->ma->csi.uniforms.first; cu; cu=cu->next) {
+			loc = GPU_shader_get_uniform(shader, cu->name);
+			if(cu->type = MA_UNF_FLOAT)
+				GPU_shader_uniform_vector(shader, loc, 1, 1, (float*)(&cu->data));
+		}
+
 		/* update lamps */
 		for(nlink=material->lamps.first; nlink; nlink=nlink->next) {
 			lamp= nlink->data;

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-10 23:53:13 UTC (rev 29396)
+++ branches/soc-2010-moguri/source/blender/makesdna/DNA_material_types.h	2010-06-11 00:23:53 UTC (rev 29397)
@@ -238,6 +238,7 @@
 #define MA_UNF_BOOL		7
 #define MA_UNF_BVEC		8
 #define MA_UNF_MAT		9
+#define MA_UNF_SAMPLER2D 10
 
 /* 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-10 23:53:13 UTC (rev 29396)
+++ branches/soc-2010-moguri/source/blender/makesrna/intern/rna_material.c	2010-06-11 00:23:53 UTC (rev 29397)
@@ -185,6 +185,19 @@
 	*max= MAX2(0, *max);
 }
 
+static void rna_CustomUniform_type_set(struct PointerRNA *ptr, int value)
+{
+	CustomUniform *cu= (CustomUniform*)ptr->data;
+
+	if (value != cu->type)
+	{
+		// We'll get into trouble if we don't reset the value
+		cu->data = NULL;
+
+		cu->type = value;
+	}
+}
+
 static float rna_FloatUniform_value_get(struct PointerRNA *ptr)
 {
 	CustomUniform *cu= (CustomUniform*)ptr->data;
@@ -210,6 +223,8 @@
 		return &RNA_UIntUniform;
 	//case MA_UNF_BOOL:
 		//return &RNA_BoolUniform;
+	case MA_UNF_SAMPLER2D:
+		return &RNA_Sampler2DUniform;
 	default:
 		return &RNA_CustomUniform;
 	}
@@ -975,6 +990,13 @@
 		RNA_def_property_float_sdna(prop, NULL, "data");
 		RNA_def_property_float_funcs(prop, "rna_FloatUniform_value_get", "rna_FloatUniform_value_set", NULL);
 	}
+	else if (type == PROP_POINTER)
+	{	
+		RNA_def_property_pointer_sdna(prop, NULL, "data");
+		RNA_def_property_struct_type(prop, "Image");
+		RNA_def_property_flag(prop, PROP_EDITABLE);
+	}
+
 	RNA_def_property_ui_text(prop, "Value", "Uniform value");
 	RNA_def_property_update(prop, 0, "rna_Material_update");
 
@@ -997,8 +1019,9 @@
 		//{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_BOOL, "BOOL", 0, "bool", "bool"},
 		//{MA_UNF_BVEC, "BVEC", 0, "bvec", "bvec"},
+		{MA_UNF_SAMPLER2D, "SAMPLER2D", 0, "sampler2D", "sampler2D"},
 		{0, NULL, 0, NULL, NULL}};
 
 	srna= RNA_def_struct(brna, "CustomUniform", NULL);
@@ -1016,12 +1039,14 @@
 	prop= RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
 	RNA_def_property_enum_sdna(prop, NULL, "type");
 	RNA_def_property_enum_items(prop, prop_type_items);
+	RNA_def_property_enum_funcs(prop, NULL, "rna_CustomUniform_type_set", NULL);
 	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, "Sampler2DUniform", "Custom sampler2D uniform", PROP_POINTER, PROP_NONE, 1, 1);
 	//rna_def_uniformtype(brna, "BoolUniform", "Custom boolean uniform", PROP_BOOLEAN, PROP_NONE, 1, 1);
 
 }





More information about the Bf-blender-cvs mailing list