[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [53116] trunk/blender/source/blender/ editors: Fix #33599: VBO textured draw mode did not update correctly when an image filepath

Brecht Van Lommel brechtvanlommel at pandora.be
Tue Dec 18 13:42:20 CET 2012


Revision: 53116
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=53116
Author:   blendix
Date:     2012-12-18 12:42:13 +0000 (Tue, 18 Dec 2012)
Log Message:
-----------
Fix #33599: VBO textured draw mode did not update correctly when an image filepath
was changed to an invalid one. Also fixed Object Color not being displayed correctly
with VBO's.

The way it has to clear the VBO buffers here is quite poor though and slow, we
really need textures and materials in the depsgraph to do this quicker.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/render/render_update.c
    trunk/blender/source/blender/editors/space_view3d/drawmesh.c

Modified: trunk/blender/source/blender/editors/render/render_update.c
===================================================================
--- trunk/blender/source/blender/editors/render/render_update.c	2012-12-18 12:14:14 UTC (rev 53115)
+++ trunk/blender/source/blender/editors/render/render_update.c	2012-12-18 12:42:13 UTC (rev 53116)
@@ -33,6 +33,7 @@
 
 #include "DNA_lamp_types.h"
 #include "DNA_material_types.h"
+#include "DNA_meshdata_types.h"
 #include "DNA_node_types.h"
 #include "DNA_object_types.h"
 #include "DNA_scene_types.h"
@@ -46,6 +47,7 @@
 
 #include "BKE_context.h"
 #include "BKE_depsgraph.h"
+#include "BKE_derivedmesh.h"
 #include "BKE_icons.h"
 #include "BKE_image.h"
 #include "BKE_main.h"
@@ -56,6 +58,7 @@
 #include "BKE_world.h"
 
 #include "GPU_material.h"
+#include "GPU_buffers.h"
 
 #include "RE_engine.h"
 #include "RE_pipeline.h"
@@ -232,6 +235,9 @@
 static void material_changed(Main *bmain, Material *ma)
 {
 	Material *parent;
+	Object *ob;
+	Scene *scene;
+	int texture_draw = FALSE;
 
 	/* icons */
 	BKE_icon_changed(BKE_icon_getid(&ma->id));
@@ -254,6 +260,30 @@
 		if (parent->gpumaterial.first)
 			GPU_material_free(parent);
 	}
+
+	/* find if we have a scene with textured display */
+	for (scene = bmain->scene.first; scene; scene = scene->id.next)
+		if (scene->customdata_mask & CD_MASK_MTFACE)
+			texture_draw = TRUE;
+
+	/* find textured objects */
+	if (texture_draw && !(U.gameflags & USER_DISABLE_VBO)) {
+		for (ob = bmain->object.first; ob; ob = ob->id.next) {
+			DerivedMesh *dm = ob->derivedFinal;
+			Material ***material = give_matarar(ob);
+			short a, *totmaterial = give_totcolp(ob);
+
+			if (dm && totmaterial && material) {
+				for (a = 0; a < *totmaterial; a++) {
+					if ((*material)[a] == ma) {
+						GPU_drawobject_free(dm);
+						break;
+					}
+				}
+			}
+		}
+	}
+
 }
 
 static void lamp_changed(Main *bmain, Lamp *la)
@@ -277,28 +307,33 @@
 		GPU_material_free(&defmaterial);
 }
 
+static int material_uses_texture(Material *ma, Tex *tex)
+{
+	if (mtex_use_tex(ma->mtex, MAX_MTEX, tex))
+		return TRUE;
+	else if (ma->use_nodes && ma->nodetree && nodes_use_tex(ma->nodetree, tex))
+		return TRUE;
+	
+	return FALSE;
+}
+
 static void texture_changed(Main *bmain, Tex *tex)
 {
 	Material *ma;
 	Lamp *la;
 	World *wo;
 	Scene *scene;
+	Object *ob;
 	bNode *node;
+	int texture_draw = FALSE;
 
 	/* icons */
 	BKE_icon_changed(BKE_icon_getid(&tex->id));
 
 	/* find materials */
 	for (ma = bmain->mat.first; ma; ma = ma->id.next) {
-		if (mtex_use_tex(ma->mtex, MAX_MTEX, tex)) {
-			/* pass */
-		}
-		else if (ma->use_nodes && ma->nodetree && nodes_use_tex(ma->nodetree, tex)) {
-			/* pass */
-		}
-		else {
+		if (!material_uses_texture(ma, tex))
 			continue;
-		}
 
 		BKE_icon_changed(BKE_icon_getid(&ma->id));
 
@@ -342,7 +377,28 @@
 					ED_node_changed_update(&scene->id, node);
 			}
 		}
+
+		if (scene->customdata_mask & CD_MASK_MTFACE)
+			texture_draw = TRUE;
 	}
+
+	/* find textured objects */
+	if (texture_draw && !(U.gameflags & USER_DISABLE_VBO)) {
+		for (ob = bmain->object.first; ob; ob = ob->id.next) {
+			DerivedMesh *dm = ob->derivedFinal;
+			Material ***material = give_matarar(ob);
+			short a, *totmaterial = give_totcolp(ob);
+
+			if (dm && totmaterial && material) {
+				for (a = 0; a < *totmaterial; a++) {
+					if (material_uses_texture((*material)[a], tex)) {
+						GPU_drawobject_free(dm);
+						break;
+					}
+				}
+			}
+		}
+	}
 }
 
 static void world_changed(Main *bmain, World *wo)

Modified: trunk/blender/source/blender/editors/space_view3d/drawmesh.c
===================================================================
--- trunk/blender/source/blender/editors/space_view3d/drawmesh.c	2012-12-18 12:14:14 UTC (rev 53115)
+++ trunk/blender/source/blender/editors/space_view3d/drawmesh.c	2012-12-18 12:42:13 UTC (rev 53116)
@@ -415,14 +415,14 @@
 static DMDrawOption draw_tface__set_draw_legacy(MTFace *tface, int has_mcol, int matnr)
 {
 	Material *ma = give_current_material(Gtexdraw.ob, matnr + 1);
-	int validtexture = 0;
+	int invalidtexture = 0;
 
 	if (ma && (ma->game.flag & GEMAT_INVISIBLE))
 		return DM_DRAW_OPTION_SKIP;
 
-	validtexture = set_draw_settings_cached(0, tface, ma, Gtexdraw);
+	invalidtexture = set_draw_settings_cached(0, tface, ma, Gtexdraw);
 
-	if (tface && validtexture) {
+	if (tface && invalidtexture) {
 		glColor3ub(0xFF, 0x00, 0xFF);
 		return DM_DRAW_OPTION_NO_MCOL; /* Don't set color */
 	}
@@ -457,25 +457,14 @@
 		return DM_DRAW_OPTION_NO_MCOL;
 }
 
-static DMDrawOption draw_tface__set_draw(MTFace *tface, int has_mcol, int matnr)
+static DMDrawOption draw_tface__set_draw(MTFace *UNUSED(tface), int UNUSED(has_mcol), int matnr)
 {
 	Material *ma = give_current_material(Gtexdraw.ob, matnr + 1);
 
 	if (ma && (ma->game.flag & GEMAT_INVISIBLE)) return 0;
 
-	if (tface && set_draw_settings_cached(0, tface, ma, Gtexdraw)) {
-		return DM_DRAW_OPTION_NO_MCOL; /* Don't set color */
-	}
-	else if (tface && (tface->mode & TF_OBCOL)) {
-		return DM_DRAW_OPTION_NO_MCOL; /* Don't set color */
-	}
-	else if (!has_mcol) {
-		/* XXX: this return value looks wrong (and doesn't match comment) */
-		return DM_DRAW_OPTION_NORMAL; /* Don't set color */
-	}
-	else {
-		return DM_DRAW_OPTION_NORMAL; /* Set color from mcol */
-	}
+	/* always use color from mcol, as set in update_tface_color_layer */
+	return DM_DRAW_OPTION_NORMAL;
 }
 
 static void update_tface_color_layer(DerivedMesh *dm)
@@ -517,11 +506,11 @@
 				finalCol[i * 4 + j].r = 255;
 			}
 		}
-		else if (tface && (tface->mode & TF_OBCOL)) {
+		else if (ma && (ma->shade_flag & MA_OBCOLOR)) {
 			for (j = 0; j < 4; j++) {
-				finalCol[i * 4 + j].b = FTOCHAR(Gtexdraw.obcol[0]);
-				finalCol[i * 4 + j].g = FTOCHAR(Gtexdraw.obcol[1]);
-				finalCol[i * 4 + j].r = FTOCHAR(Gtexdraw.obcol[2]);
+				finalCol[i * 4 + j].b = Gtexdraw.obcol[0];
+				finalCol[i * 4 + j].g = Gtexdraw.obcol[1];
+				finalCol[i * 4 + j].r = Gtexdraw.obcol[2];
 			}
 		}
 		else if (!mcol) {




More information about the Bf-blender-cvs mailing list