[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [15595] branches/apricot: Apricot Branch

Brecht Van Lommel brechtvanlommel at pandora.be
Tue Jul 15 23:59:46 CEST 2008


Revision: 15595
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=15595
Author:   blendix
Date:     2008-07-15 23:59:46 +0200 (Tue, 15 Jul 2008)

Log Message:
-----------
Apricot Branch
==============

* Made in game switching of GLSL options work. There is still
  a one frame flicker that needs to be fixed.
* Added access to the estimated average framerate in the game
  engine: GameLogic.getAverageFrameRate().
* Added acces to the blender build info from python:
  Blender.Get("buildinfo")
* Various GLSL optimizations to allow more constant folding in
  the glsl compiler, use glsl shadow functions to do shadow,
  instead of own code, and fix an issue with opengl texture
  color range.

Modified Paths:
--------------
    branches/apricot/release/scripts/sysinfo.py
    branches/apricot/source/blender/gpu/GPU_material.h
    branches/apricot/source/blender/gpu/intern/gpu_codegen.c
    branches/apricot/source/blender/gpu/intern/gpu_extensions.c
    branches/apricot/source/blender/gpu/intern/gpu_material.c
    branches/apricot/source/blender/gpu/intern/gpu_shader_material.glsl
    branches/apricot/source/blender/gpu/intern/gpu_shader_material.glsl.c
    branches/apricot/source/blender/python/CMakeLists.txt
    branches/apricot/source/blender/python/SConscript
    branches/apricot/source/blender/python/api2_2x/Blender.c
    branches/apricot/source/blender/python/api2_2x/Makefile
    branches/apricot/source/blender/src/drawobject.c
    branches/apricot/source/blender/src/drawview.c
    branches/apricot/source/gameengine/Ketsji/BL_BlenderShader.cpp
    branches/apricot/source/gameengine/Ketsji/BL_BlenderShader.h
    branches/apricot/source/gameengine/Ketsji/KX_KetsjiEngine.cpp
    branches/apricot/source/gameengine/Ketsji/KX_KetsjiEngine.h
    branches/apricot/source/gameengine/Ketsji/KX_PythonInit.cpp
    branches/apricot/source/gameengine/Ketsji/KX_Scene.cpp
    branches/apricot/source/gameengine/PyDoc/GameLogic.py
    branches/apricot/source/gameengine/Rasterizer/RAS_BucketManager.cpp
    branches/apricot/source/gameengine/Rasterizer/RAS_BucketManager.h

Modified: branches/apricot/release/scripts/sysinfo.py
===================================================================
--- branches/apricot/release/scripts/sysinfo.py	2008-07-15 21:08:39 UTC (rev 15594)
+++ branches/apricot/release/scripts/sysinfo.py	2008-07-15 21:59:46 UTC (rev 15595)
@@ -94,6 +94,8 @@
 
 output.write(header + "\n\n")
 
+output.write("%s\n\n" % Blender.Get('buildinfo'))
+
 output.write("Platform: %s\n========\n\n" % sys.platform)
 
 output.write("Python:\n======\n\n")

Modified: branches/apricot/source/blender/gpu/GPU_material.h
===================================================================
--- branches/apricot/source/blender/gpu/GPU_material.h	2008-07-15 21:08:39 UTC (rev 15594)
+++ branches/apricot/source/blender/gpu/GPU_material.h	2008-07-15 21:59:46 UTC (rev 15595)
@@ -70,6 +70,7 @@
 	GPU_MAT4 = 16,
 	GPU_TEX1D = 1001,
 	GPU_TEX2D = 1002,
+	GPU_SHADOW2D = 1003,
 	GPU_ATTRIB = 3001
 } GPUType;
 

Modified: branches/apricot/source/blender/gpu/intern/gpu_codegen.c
===================================================================
--- branches/apricot/source/blender/gpu/intern/gpu_codegen.c	2008-07-15 21:08:39 UTC (rev 15594)
+++ branches/apricot/source/blender/gpu/intern/gpu_codegen.c	2008-07-15 21:59:46 UTC (rev 15595)
@@ -71,7 +71,6 @@
 
 typedef enum GPUDataSource {
 	GPU_SOURCE_VEC_UNIFORM,
-	GPU_SOURCE_ARRAY_UNIFORM,
 	GPU_SOURCE_BUILTIN,
 	GPU_SOURCE_TEX_PIXEL,
 	GPU_SOURCE_TEX,
@@ -131,7 +130,6 @@
 	GPUNode *node;
 
 	int type;				/* datatype */
-	int arraysize;			/* number of elements in an array */
 	int source;				/* data source */
 
 	int id;					/* unique id as created by code generator */
@@ -140,6 +138,7 @@
 	int bindtex;			/* input is responsible for binding the texture? */
 	int definetex;			/* input is responsible for defining the pixel? */
 	int textarget;			/* GL_TEXTURE_* */
+	int textype;			/* datatype */
 
 	struct Image *ima;		/* image */
 	struct ImageUser *iuser;/* image user */
@@ -267,6 +266,8 @@
 				}
 			}
 
+			if(!type && gpu_str_prefix(code, "sampler2DShadow"))
+				type= GPU_SHADOW2D;
 			if(!type && gpu_str_prefix(code, "sampler1D"))
 				type= GPU_TEX1D;
 			if(!type && gpu_str_prefix(code, "sampler2D"))
@@ -323,6 +324,8 @@
 				BLI_dynstr_append(ds, "sampler1D");
 			else if(function->paramtype[a] == GPU_TEX2D)
 				BLI_dynstr_append(ds, "sampler2D");
+			else if(function->paramtype[a] == GPU_SHADOW2D)
+				BLI_dynstr_append(ds, "sampler2DShadow");
 			else
 				BLI_dynstr_append(ds, GPU_DATATYPE_STR[function->paramtype[a]]);
 				
@@ -422,6 +425,21 @@
 	}
 }
 
+static void codegen_print_datatype(DynStr *ds, int type, float *data)
+{
+	int i;
+
+	BLI_dynstr_printf(ds, "%s(", GPU_DATATYPE_STR[type]);
+
+	for(i=0; i<type; i++) {
+		BLI_dynstr_printf(ds, "%f", data[i]);
+		if(i == type-1)
+			BLI_dynstr_append(ds, ")");
+		else
+			BLI_dynstr_append(ds, ", ");
+	}
+}
+
 static int codegen_input_has_texture(GPUInput *input)
 {
 	if (input->link)
@@ -541,7 +559,8 @@
 				/* create exactly one sampler for each texture */
 				if (codegen_input_has_texture(input) && input->bindtex)
 					BLI_dynstr_printf(ds, "uniform %s samp%d;\n",
-						(input->textarget == GL_TEXTURE_1D)? "sampler1D": "sampler2D",
+						(input->textype == GPU_TEX1D)? "sampler1D":
+						(input->textype == GPU_TEX2D)? "sampler2D": "sampler2DShadow",
 						input->texid);
 			}
 			else if(input->source == GPU_SOURCE_BUILTIN) {
@@ -561,14 +580,19 @@
 				}
 			}
 			else if (input->source == GPU_SOURCE_VEC_UNIFORM) {
-				/* and create uniform vectors or matrices for all vectors */
-				BLI_dynstr_printf(ds, "uniform %s unf%d;\n",
-					GPU_DATATYPE_STR[input->type], input->id);
+				if(input->dynamicvec) {
+					/* only create uniforms for dynamic vectors */
+					BLI_dynstr_printf(ds, "uniform %s unf%d;\n",
+						GPU_DATATYPE_STR[input->type], input->id);
+				}
+				else {
+					/* for others use const so the compiler can do folding */
+					BLI_dynstr_printf(ds, "const %s cons%d = ",
+						GPU_DATATYPE_STR[input->type], input->id);
+					codegen_print_datatype(ds, input->type, input->vec);
+					BLI_dynstr_append(ds, ";\n");
+				}
 			}
-			else if (input->source == GPU_SOURCE_ARRAY_UNIFORM) {
-				BLI_dynstr_printf(ds, "uniform %s unf%d[%d];\n",
-					GPU_DATATYPE_STR[input->type], input->id, input->arraysize);
-			}
 			else if (input->source == GPU_SOURCE_ATTRIB && input->attribfirst) {
 				BLI_dynstr_printf(ds, "varying %s var%d;\n",
 					GPU_DATATYPE_STR[input->type], input->attribid);
@@ -631,9 +655,12 @@
 			}
 			else if(input->source == GPU_SOURCE_BUILTIN)
 				BLI_dynstr_printf(ds, "%s", GPU_builtin_name(input->builtin));
-			else if ((input->source == GPU_SOURCE_VEC_UNIFORM) ||
-			         (input->source == GPU_SOURCE_ARRAY_UNIFORM))
-				BLI_dynstr_printf(ds, "unf%d", input->id);
+			else if(input->source == GPU_SOURCE_VEC_UNIFORM) {
+				if(input->dynamicvec)
+					BLI_dynstr_printf(ds, "unf%d", input->id);
+				else
+					BLI_dynstr_printf(ds, "cons%d", input->id);
+			}
 			else if (input->source == GPU_SOURCE_ATTRIB)
 				BLI_dynstr_printf(ds, "var%d", input->attribid);
 
@@ -768,20 +795,8 @@
 				if (input->bindtex)
 					extract = 1;
 			}
-			else if (input->arraysize) {
-				if(input->dynamicvec)
-					extract = 1;
-				else
-					GPU_shader_uniform_vector(shader, input->shadername, input->type,
-						input->arraysize, input->vec);
-			}
-			else {
-				if(input->dynamicvec)
-					extract = 1;
-				else
-					GPU_shader_uniform_vector(shader, input->shadername, input->type, 1,
-						input->vec);
-			}
+			else if(input->dynamicvec)
+				extract = 1;
 
 			/* extract nodes */
 			if(extract) {
@@ -828,18 +843,11 @@
 	if (!shader)
 		return;
 
-	/* pass dynamic inputs to opengl, others were already done */
-	for (input=inputs->first; input; input=input->next) {
-		if(input->ima || input->tex);
-		else if (input->arraysize) {
-			GPU_shader_uniform_vector(shader, input->shadername, input->type,
-				input->arraysize, input->dynamicvec);
-		}
-		else {
+	/* pass dynamic inputs to opengl, others were removed */
+	for (input=inputs->first; input; input=input->next)
+		if(!(input->ima || input->tex))
 			GPU_shader_uniform_vector(shader, input->shadername, input->type, 1,
 				input->dynamicvec);
-		}
-	}
 }
 
 void GPU_pass_unbind(GPUPass *pass)
@@ -946,6 +954,7 @@
 
 		input->tex = link->dynamictex;
 		input->textarget = GL_TEXTURE_2D;
+		input->textype = type;
 		input->dynamictex = 1;
 		MEM_freeN(link);
 	}
@@ -953,6 +962,7 @@
 		/* small texture created on the fly, like for colorbands */
 		input->type = GPU_VEC4;
 		input->source = GPU_SOURCE_TEX;
+		input->textype = type;
 
 		if (type == GPU_TEX1D) {
 			input->tex = GPU_texture_create_1D(link->texturesize, link->ptr1, 1);
@@ -973,6 +983,7 @@
 
 		input->ima = link->ptr1;
 		input->textarget = GL_TEXTURE_2D;
+		input->textype = GPU_TEX2D;
 		MEM_freeN(link);
 	}
 	else if(link->attribtype) {

Modified: branches/apricot/source/blender/gpu/intern/gpu_extensions.c
===================================================================
--- branches/apricot/source/blender/gpu/intern/gpu_extensions.c	2008-07-15 21:08:39 UTC (rev 15594)
+++ branches/apricot/source/blender/gpu/intern/gpu_extensions.c	2008-07-15 21:59:46 UTC (rev 15595)
@@ -324,7 +324,10 @@
 
 	if(depth) {
 		glTexParameteri(tex->target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-		glTexParameteri(tex->target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+		glTexParameteri(tex->target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+		glTexParameteri(tex->target, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE);
+		glTexParameteri(tex->target, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LEQUAL);
+		glTexParameteri(tex->target, GL_DEPTH_TEXTURE_MODE_ARB, GL_INTENSITY);  
 	}
 	else {
 		glTexParameteri(tex->target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
@@ -426,7 +429,7 @@
 {
 	GPUTexture *tex;
 	GLint w, h, border, lastbindcode;
-		
+
 	if(ima->gputexture)
 		return ima->gputexture;
 

Modified: branches/apricot/source/blender/gpu/intern/gpu_material.c
===================================================================
--- branches/apricot/source/blender/gpu/intern/gpu_material.c	2008-07-15 21:08:39 UTC (rev 15594)
+++ branches/apricot/source/blender/gpu/intern/gpu_material.c	2008-07-15 21:59:46 UTC (rev 15595)
@@ -48,6 +48,7 @@
 #include "BKE_global.h"
 #include "BKE_main.h"
 #include "BKE_node.h"
+#include "BKE_scene.h"
 #include "BKE_texture.h"
 #include "BKE_utildefines.h"
 
@@ -598,7 +599,7 @@
 			
 			if(lamp->mode & LA_ONLYSHADOW) {
 				GPU_link(mat, "shade_only_shadow", i, shadfac,
-					GPU_dynamic_uniform(&lamp->dynenergy), shadfac, shi->rgb, shi->specrgb,
+					GPU_dynamic_uniform(&lamp->dynenergy), shi->rgb, shi->specrgb,
 					shr->diff, shr->spec, &shr->diff, &shr->spec);
 				
 				BLI_linklist_append(&mat->lamps, lamp);
@@ -671,8 +672,9 @@
 {
 	Base *base;
 	Object *ob;
+	Scene *sce;
 	
-	for(base=shi->gpumat->scene->base.first; base; base=base->next) {
+	for(SETLOOPER(shi->gpumat->scene, base)) {
 		ob= base->object;
 
 		if(ob->type==OB_LAMP) {
@@ -779,13 +781,26 @@
 	MTex *mtex;
 	Tex *tex;
 	GPUNodeLink *texco, *tin, *trgb, *tnor, *tcol, *stencil = NULL;
+	GPUNodeLink *texco_norm, *texco_orco, *texco_object, *texco_tangent;
+	GPUNodeLink *texco_global, *texco_uv = NULL;
 	GPUNodeLink *colfac, *newnor, *varfac, *orn;
+	char *lastuvname = NULL;
 	float one = 1.0f, norfac, ofs[3];
 	int tex_nr, rgbnor, talpha;
 
-	GPU_link(mat, "texco_norm", GPU_builtin(GPU_VIEW_NORMAL), &orn);
 	GPU_link(mat, "set_value", GPU_uniform(&one), &stencil);
 
+	GPU_link(mat, "texco_norm", GPU_builtin(GPU_VIEW_NORMAL), &texco_norm);
+	GPU_link(mat, "texco_orco", GPU_attribute(CD_ORCO, ""), &texco_orco);
+	GPU_link(mat, "texco_object", GPU_builtin(GPU_INVERSE_VIEW_MATRIX),
+		GPU_builtin(GPU_INVERSE_OBJECT_MATRIX),
+		GPU_builtin(GPU_VIEW_POSITION), &texco_object);
+	GPU_link(mat, "texco_tangent", GPU_attribute(CD_TANGENT, ""), &texco_tangent);
+	GPU_link(mat, "texco_global", GPU_builtin(GPU_INVERSE_VIEW_MATRIX),
+		GPU_builtin(GPU_VIEW_POSITION), &texco_global);
+
+	orn= texco_norm;
+
 	/* go over texture slots */
 	for(tex_nr=0; tex_nr<MAX_MTEX; tex_nr++) {
 		/* separate tex switching */
@@ -799,24 +814,29 @@
 
 			/* which coords */
 			if(mtex->texco==TEXCO_ORCO)
-				GPU_link(mat, "texco_orco", GPU_attribute(CD_ORCO, ""), &texco);
+				texco= texco_orco;
 			else if(mtex->texco==TEXCO_OBJECT)
-				GPU_link(mat, "texco_object", GPU_builtin(GPU_INVERSE_VIEW_MATRIX),
-					GPU_builtin(GPU_INVERSE_OBJECT_MATRIX),

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list