[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [48424] branches/soc-2012-swiss_cheese/ source: OpenGL Regression Fixes: I focused on fixing several ugly regressions in edit mode.

Jason Wilkins Jason.A.Wilkins at gmail.com
Sat Jun 30 06:29:33 CEST 2012


Revision: 48424
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=48424
Author:   jwilkins
Date:     2012-06-30 04:29:16 +0000 (Sat, 30 Jun 2012)
Log Message:
-----------
OpenGL Regression Fixes: I focused on fixing several ugly regressions in edit mode.

Removed DM_DRAW_USE_COLORS flag from draw_dm_faces_sel, it seems to conflict with the setDrawOptions function.  However, not sure which one is right.

The "mapped" callback functions have to set their formats outside of the callback because only the caller really knows what format is needed.

Modified Paths:
--------------
    branches/soc-2012-swiss_cheese/source/blender/blenkernel/BKE_DerivedMesh.h
    branches/soc-2012-swiss_cheese/source/blender/blenkernel/intern/cdderivedmesh.c
    branches/soc-2012-swiss_cheese/source/blender/blenkernel/intern/editderivedmesh.c
    branches/soc-2012-swiss_cheese/source/blender/blenkernel/intern/subsurf_ccg.c
    branches/soc-2012-swiss_cheese/source/blender/editors/space_view3d/drawmesh.c
    branches/soc-2012-swiss_cheese/source/blender/editors/space_view3d/drawobject.c
    branches/soc-2012-swiss_cheese/source/blender/makesrna/intern/rna_modifier.c
    branches/soc-2012-swiss_cheese/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageIM.cpp

Modified: branches/soc-2012-swiss_cheese/source/blender/blenkernel/BKE_DerivedMesh.h
===================================================================
--- branches/soc-2012-swiss_cheese/source/blender/blenkernel/BKE_DerivedMesh.h	2012-06-30 04:10:52 UTC (rev 48423)
+++ branches/soc-2012-swiss_cheese/source/blender/blenkernel/BKE_DerivedMesh.h	2012-06-30 04:29:16 UTC (rev 48424)
@@ -125,8 +125,8 @@
 typedef enum DMDrawOption {
 	/* the element is hidden or otherwise non-drawable */
 	DM_DRAW_OPTION_SKIP = 0,
-	/* normal drawing */
-	DM_DRAW_OPTION_NORMAL = 1,
+	/* draw element normally */
+	DM_DRAW_OPTION_NORMALLY = 1,
 	/* draw, but don't set the color from mcol */
 	DM_DRAW_OPTION_NO_MCOL = 2,
 	/* used in drawMappedFaces, use GL stipple for the face */
@@ -142,7 +142,8 @@
 
 typedef enum DMDrawFlag {
 	DM_DRAW_USE_COLORS = 1,
-	DM_DRAW_ALWAYS_SMOOTH = 2
+	DM_DRAW_ALWAYS_SMOOTH = 2,
+	DM_DRAW_USE_NORMALS = 4,
 } DMDrawFlag;
 
 typedef enum DMDirtyFlag {

Modified: branches/soc-2012-swiss_cheese/source/blender/blenkernel/intern/cdderivedmesh.c
===================================================================
--- branches/soc-2012-swiss_cheese/source/blender/blenkernel/intern/cdderivedmesh.c	2012-06-30 04:10:52 UTC (rev 48423)
+++ branches/soc-2012-swiss_cheese/source/blender/blenkernel/intern/cdderivedmesh.c	2012-06-30 04:29:16 UTC (rev 48424)
@@ -760,7 +760,7 @@
 			/* lastFlag = 0; */ /* UNUSED */
 			for (i = 0; i < tottri; i++) {
 				int actualFace = next_actualFace;
-				DMDrawOption draw_option = DM_DRAW_OPTION_NORMAL;
+				DMDrawOption draw_option = DM_DRAW_OPTION_NORMALLY;
 				int flush = 0;
 
 				if (i != tottri - 1)
@@ -822,36 +822,59 @@
 	cdDM_drawFacesTex_common(dm, setDrawOptions, NULL, compareDrawOptions, userData);
 }
 
-static void cdDM_drawMappedFaces(DerivedMesh *dm,
-                                 DMSetDrawOptions setDrawOptions,
-                                 DMSetMaterial setMaterial,
-                                 DMCompareDrawOptions compareDrawOptions,
-                                 void *userData, DMDrawFlag flag)
+static void cdDM_drawMappedFaces(
+	DerivedMesh *dm,
+	DMSetDrawOptions setDrawOptions,
+	DMSetMaterial setMaterial,
+	DMCompareDrawOptions compareDrawOptions,
+	void *userData, 
+	DMDrawFlag flag)
 {
 	CDDerivedMesh *cddm = (CDDerivedMesh *) dm;
 	MVert *mv = cddm->mvert;
 	MFace *mf = cddm->mface;
-	MCol *mc;
-	float *nors = DM_get_tessface_data_layer(dm, CD_NORMAL);
-	int useColors = flag & DM_DRAW_USE_COLORS;
-	int i, orig, *index = DM_get_tessface_data_layer(dm, CD_ORIGINDEX);
 
-	mc = DM_get_tessface_data_layer(dm, CD_ID_MCOL);
-	if (!mc)
-		mc = DM_get_tessface_data_layer(dm, CD_PREVIEW_MCOL);
-	if (!mc)
-		mc = DM_get_tessface_data_layer(dm, CD_MCOL);
+	float *nors;
+	MCol *mc = NULL;
+	int *index;
 
-	cdDM_update_normals_from_pbvh(dm);
+	int i, orig;
 
+	if (flag & DM_DRAW_USE_NORMALS) {
+		nors = DM_get_tessface_data_layer(dm, CD_NORMAL);
+
+		cdDM_update_normals_from_pbvh(dm);
+	}
+	else {
+		nors = NULL;
+	}
+
+	if (flag & DM_DRAW_USE_COLORS) {
+		mc = DM_get_tessface_data_layer(dm, CD_ID_MCOL);
+
+		if (!mc) {
+			mc = DM_get_tessface_data_layer(dm, CD_PREVIEW_MCOL);
+
+			if (!mc) {
+				mc = DM_get_tessface_data_layer(dm, CD_MCOL);
+			}
+		}
+	}
+
+	index = DM_get_tessface_data_layer(dm, CD_ORIGINDEX);
+
 	/* back-buffer always uses legacy since VBO's would need the
 	 * color array temporarily overwritten for drawing, then reset. */
 	if (GPU_buffer_legacy(dm) || G.f & G_BACKBUFSEL) {
 		DEBUG_VBO("Using legacy code. cdDM_drawMappedFaces\n");
-		gpuImmediateFormat_C4_N3_V3();
+
+		/* no need to set shading mode to flat because
+		 *  normals are already used to change shading */
+		glShadeModel(GL_SMOOTH);
+
 		for (i = 0; i < dm->numTessFaceData; i++, mf++) {
 			int drawSmooth = (flag & DM_DRAW_ALWAYS_SMOOTH) ? 1 : (mf->flag & ME_SMOOTH);
-			DMDrawOption draw_option = DM_DRAW_OPTION_NORMAL;
+			DMDrawOption draw_option;
 
 			orig = (index == NULL) ? i : *index++;
 			
@@ -859,16 +882,15 @@
 				draw_option = setMaterial(mf->mat_nr + 1, NULL);
 			else if (setDrawOptions != NULL)
 				draw_option = setDrawOptions(userData, orig);
+			else
+				draw_option = DM_DRAW_OPTION_NORMALLY;
 
 			if (draw_option != DM_DRAW_OPTION_SKIP) {
 				unsigned char *cp = NULL;
 
-				if (useColors && mc)
+				if (mc)
 					cp = (unsigned char *)&mc[i * 4];
 
-				/* no need to set shading mode to flat because
-				 *  normals are already used to change shading */
-				glShadeModel(GL_SMOOTH);
 				gpuBegin(mf->v4 ? GL_QUADS : GL_TRIANGLES);
 
 				if (!drawSmooth) {
@@ -899,17 +921,17 @@
 				}
 				else {
 					if (cp) gpuColor3ub(cp[3], cp[2], cp[1]);
-					gpuNormal3sv(mv[mf->v1].no);
+					if (nors) gpuNormal3sv(mv[mf->v1].no);
 					gpuVertex3fv(mv[mf->v1].co);
 					if (cp) gpuColor3ub(cp[7], cp[6], cp[5]);
-					gpuNormal3sv(mv[mf->v2].no);
+					if (nors) gpuNormal3sv(mv[mf->v2].no);
 					gpuVertex3fv(mv[mf->v2].co);
 					if (cp) gpuColor3ub(cp[11], cp[10], cp[9]);
-					gpuNormal3sv(mv[mf->v3].no);
+					if (nors) gpuNormal3sv(mv[mf->v3].no);
 					gpuVertex3fv(mv[mf->v3].co);
 					if (mf->v4) {
 						if (cp) gpuColor3ub(cp[15], cp[14], cp[13]);
-						gpuNormal3sv(mv[mf->v4].no);
+						if (nors) gpuNormal3sv(mv[mf->v4].no);
 						gpuVertex3fv(mv[mf->v4].co);
 					}
 				}
@@ -923,10 +945,17 @@
 	}
 	else { /* use OpenGL VBOs or Vertex Arrays instead for better, faster rendering */
 		int prevstart = 0;
+
 		GPU_vertex_setup(dm);
-		GPU_normal_setup(dm);
-		if (useColors && mc)
+
+		if (nors) {
+			GPU_normal_setup(dm);
+		}
+
+		if (mc) {
 			GPU_color_setup(dm);
+		}
+
 		if (!GPU_buffer_legacy(dm)) {
 			int tottri = dm->drawObject->tot_triangle_point / 3;
 			glShadeModel(GL_SMOOTH);
@@ -947,7 +976,7 @@
 					int actualFace = next_actualFace;
 					MFace *mface = mf + actualFace;
 					/*int drawSmooth = (flag & DM_DRAW_ALWAYS_SMOOTH) ? 1 : (mface->flag & ME_SMOOTH);*/ /* UNUSED */
-					DMDrawOption draw_option = DM_DRAW_OPTION_NORMAL;
+					DMDrawOption draw_option = DM_DRAW_OPTION_NORMALLY;
 					int flush = 0;
 
 					if (i != tottri - 1)
@@ -1506,15 +1535,18 @@
 	MEdge *edge = cddm->medge;
 	int i, orig, *index = DM_get_edge_data_layer(dm, CD_ORIGINDEX);
 
-	gpuImmediateFormat_V3();
 	gpuBegin(GL_LINES);
 	for (i = 0; i < dm->numEdgeData; i++, edge++) {
 		if (index) {
 			orig = *index++;
-			if (setDrawOptions && orig == ORIGINDEX_NONE) continue;
+
+			if (setDrawOptions && orig == ORIGINDEX_NONE) {
+				continue;
+			}
 		}
-		else
+		else {
 			orig = i;
+		}
 
 		if (!setDrawOptions || (setDrawOptions(userData, orig) != DM_DRAW_OPTION_SKIP)) {
 			gpuVertex3fv(vert[edge->v1].co);
@@ -1522,7 +1554,6 @@
 		}
 	}
 	gpuEnd();
-	gpuImmediateUnformat();
 }
 
 static void cdDM_foreachMappedVert(

Modified: branches/soc-2012-swiss_cheese/source/blender/blenkernel/intern/editderivedmesh.c
===================================================================
--- branches/soc-2012-swiss_cheese/source/blender/blenkernel/intern/editderivedmesh.c	2012-06-30 04:10:52 UTC (rev 48423)
+++ branches/soc-2012-swiss_cheese/source/blender/blenkernel/intern/editderivedmesh.c	2012-06-30 04:29:16 UTC (rev 48424)
@@ -405,7 +405,6 @@
 	BMIter iter;
 	int i;
 
-	gpuImmediateFormat_V3();
 	gpuBegin(GL_LINES);
 
 	if (bmdm->vertexCos) {
@@ -428,7 +427,6 @@
 	}
 
 	gpuEnd();
-	gpuImmediateUnformat();
 }
 static void emDM_drawEdges(DerivedMesh *dm,
                            int UNUSED(drawLooseEdges),
@@ -500,9 +498,11 @@
 			if (luv) {
 				if (lastluv)
 					gpuVertex2fv(luv->uv);
+
 				gpuVertex2fv(luv->uv);
 
 				lastluv = luv;
+
 				if (!firstluv)
 					firstluv = luv;
 			}
@@ -570,12 +570,13 @@
 	}
 }
 
-static void emDM_drawMappedFaces(DerivedMesh *dm,
-                                 DMSetDrawOptions setDrawOptions,
-                                 DMSetMaterial setMaterial,
-                                 DMCompareDrawOptions compareDrawOptions,
-                                 void *userData,
-                                 DMDrawFlag flag)
+static void emDM_drawMappedFaces(
+	DerivedMesh *dm,
+	DMSetDrawOptions setDrawOptions,
+	DMSetMaterial setMaterial,
+	DMCompareDrawOptions compareDrawOptions,
+	void *userData,
+	DMDrawFlag flag)
 {
 	EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
 	BMFace *efa;
@@ -583,11 +584,11 @@
 	const int tottri = bmdm->tc->tottri;
 	const int lasttri = tottri - 1; /* compare agasint this a lot */
 	DMDrawOption draw_option;
+	int useNormals = flag & DM_DRAW_USE_NORMALS;
 	int i, flush;
-	const int skip_normals = !glIsEnabled(GL_LIGHTING); /* could be passed as an arg */
 
 	/* GL_NOOP is used to detect if drawing has started or not */
-	GLenum poly_prev = GL_NOOP;
+	GLenum poly_prev  = GL_NOOP;
 	GLenum shade_prev = GL_NOOP;
 
 	(void)setMaterial; /* UNUSED */
@@ -595,19 +596,12 @@
 	/* currently unused -- each original face is handled separately */
 	(void)compareDrawOptions;
 
-	if (skip_normals) {
 		if (flag & DM_DRAW_USE_COLORS)
 			gpuImmediateFormat_C4_V3();
 		else
-			gpuImmediateFormat_V3();
-	}
-	else {
 		if (flag & DM_DRAW_USE_COLORS)
 			gpuImmediateFormat_C4_N3_V3();
 		else
-			gpuImmediateFormat_N3_V3();
-	}
-
 	if (bmdm->vertexCos) {
 		/* add direct access */
 		float (*vertexCos)[3] = bmdm->vertexCos;
@@ -625,7 +619,7 @@
 			drawSmooth = (flag & DM_DRAW_ALWAYS_SMOOTH) ? 1 : BM_elem_flag_test(efa, BM_ELEM_SMOOTH);
 
 			draw_option = (!setDrawOptions ?
-			               DM_DRAW_OPTION_NORMAL :
+			               DM_DRAW_OPTION_NORMALLY :
 			               setDrawOptions(userData, BM_elem_index_get(efa)));
 			if (draw_option != DM_DRAW_OPTION_SKIP) {
 				const GLenum poly_type = GL_TRIANGLES; /* BMESH NOTE, this is odd but keep it for now to match trunk */
@@ -638,7 +632,7 @@
 					glPolygonStipple(stipple_quarttone);
 				}
 
-				if (skip_normals) {
+				if (!useNormals) {
 					if (poly_type != poly_prev) {
 						if (poly_prev != GL_NOOP) gpuEnd();
 						gpuBegin((poly_prev = poly_type)); /* BMesh: will always be GL_TRIANGLES */
@@ -676,7 +670,7 @@
 				}
 
 				flush = (draw_option == DM_DRAW_OPTION_STIPPLE);
-				if (!skip_normals && !flush && (i != lasttri))
+				if (useNormals && !flush && (i != lasttri))
 					flush |= efa->mat_nr != looptris[i + 1][0]->f->mat_nr;  /* TODO, make this neater */
 
 				if (flush) {
@@ -702,7 +696,7 @@
 			drawSmooth = (flag & DM_DRAW_ALWAYS_SMOOTH) ? 1 : BM_elem_flag_test(efa, BM_ELEM_SMOOTH);
 
 			draw_option = (!setDrawOptions ?
-			               DM_DRAW_OPTION_NORMAL :

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list