[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [21969] branches/soc-2009-imbusy/source/ blender: drawing loose edges now works with buffers

Lukas Steiblys imbusy at imbusy.org
Tue Jul 28 13:04:32 CEST 2009


Revision: 21969
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=21969
Author:   imbusy
Date:     2009-07-28 13:04:32 +0200 (Tue, 28 Jul 2009)

Log Message:
-----------
drawing loose edges now works with buffers

Modified Paths:
--------------
    branches/soc-2009-imbusy/source/blender/blenkernel/intern/cdderivedmesh.c
    branches/soc-2009-imbusy/source/blender/gpu/gpu_buffers.h
    branches/soc-2009-imbusy/source/blender/gpu/intern/gpu_buffers.c

Modified: branches/soc-2009-imbusy/source/blender/blenkernel/intern/cdderivedmesh.c
===================================================================
--- branches/soc-2009-imbusy/source/blender/blenkernel/intern/cdderivedmesh.c	2009-07-28 11:04:08 UTC (rev 21968)
+++ branches/soc-2009-imbusy/source/blender/blenkernel/intern/cdderivedmesh.c	2009-07-28 11:04:32 UTC (rev 21969)
@@ -259,8 +259,10 @@
 				else {
 					draw = 0;
 				}
-				if( prevdraw != draw && prevdraw > 0 && (i-prevstart) > 0) {
-					GPU_buffer_draw_elements( dm->drawObject->edges, GL_LINES, prevstart*2, (i-prevstart)*2  );
+				if( prevdraw != draw ) {
+					if( prevdraw > 0 && (i-prevstart) > 0 ) {
+						GPU_buffer_draw_elements( dm->drawObject->edges, GL_LINES, prevstart*2, (i-prevstart)*2  );
+					}
 					prevstart = i;
 				}
 				prevdraw = draw;
@@ -280,14 +282,45 @@
 	MEdge *medge = cddm->medge;
 	int i;
 
-	glBegin(GL_LINES);
-	for(i = 0; i < dm->numEdgeData; i++, medge++) {
-		if(medge->flag&ME_LOOSEEDGE) {
-			glVertex3fv(mvert[medge->v1].co);
-			glVertex3fv(mvert[medge->v2].co);
+	if( GPU_buffer_legacy(dm) ) {
+		DEBUG_VBO( "Using legacy code. cdDM_drawLooseEdges\n" );
+		glBegin(GL_LINES);
+		for(i = 0; i < dm->numEdgeData; i++, medge++) {
+			if(medge->flag&ME_LOOSEEDGE) {
+				glVertex3fv(mvert[medge->v1].co);
+				glVertex3fv(mvert[medge->v2].co);
+			}
 		}
+		glEnd();
 	}
-	glEnd();
+	else {
+		int prevstart = 0;
+		int prevdraw = 1;
+		int draw = 1;
+
+		GPU_edge_setup(dm);
+		if( !GPU_buffer_legacy(dm) ) {
+			for(i = 0; i < dm->numEdgeData; i++, medge++) {
+				if(medge->flag&ME_LOOSEEDGE) {
+					draw = 1;
+				} 
+				else {
+					draw = 0;
+				}
+				if( prevdraw != draw ) {
+					if( prevdraw > 0 && (i-prevstart) > 0) {
+						GPU_buffer_draw_elements( dm->drawObject->edges, GL_LINES, prevstart*2, (i-prevstart)*2  );
+					}
+					prevstart = i;
+				}
+				prevdraw = draw;
+			}
+			if( prevdraw > 0 && (i-prevstart) > 0 ) {
+				GPU_buffer_draw_elements( dm->drawObject->edges, GL_LINES, prevstart*2, (i-prevstart)*2  );
+			}
+		}
+		GPU_buffer_unbind();
+	}
 }
 
 static void cdDM_drawFacesSolid(DerivedMesh *dm, int (*setMaterial)(int, void *attribs))

Modified: branches/soc-2009-imbusy/source/blender/gpu/gpu_buffers.h
===================================================================
--- branches/soc-2009-imbusy/source/blender/gpu/gpu_buffers.h	2009-07-28 11:04:08 UTC (rev 21968)
+++ branches/soc-2009-imbusy/source/blender/gpu/gpu_buffers.h	2009-07-28 11:04:32 UTC (rev 21969)
@@ -89,7 +89,8 @@
 	GPUBufferMaterial *materials;
 
 	int nmaterials;
-	int nelements;
+	int nelements;	/* (number of faces) * 3 */
+	int nlooseverts;
 	int nedges;
 	int nindices;
 	int legacy;	/* if there was a failure allocating some buffer, use old rendering code */

Modified: branches/soc-2009-imbusy/source/blender/gpu/intern/gpu_buffers.c
===================================================================
--- branches/soc-2009-imbusy/source/blender/gpu/intern/gpu_buffers.c	2009-07-28 11:04:08 UTC (rev 21968)
+++ branches/soc-2009-imbusy/source/blender/gpu/intern/gpu_buffers.c	2009-07-28 11:04:32 UTC (rev 21969)
@@ -316,11 +316,17 @@
 
 			index[redir[mface[i].mat_nr+16383]]+=2;
 		}
-		else
-		{
+		else {
 			index[redir[mface[i].mat_nr+16383]]++;
 		}
 	}
+
+	for( i = 0; i < object->nindices; i++ ) {
+		if( object->indices[i].element == -1 ) {
+			object->indices[i].element = object->nelements + object->nlooseverts;
+			object->nlooseverts++;
+		}
+	}
 #undef ADDLINK
 
 	MEM_freeN(index);
@@ -342,6 +348,7 @@
 	GPU_buffer_free( object->normals, globalPool );
 	GPU_buffer_free( object->uv, globalPool );
 	GPU_buffer_free( object->colors, globalPool );
+	GPU_buffer_free( object->edges, globalPool );
 
 	MEM_freeN(object);
 }
@@ -436,7 +443,7 @@
 void GPU_buffer_copy_vertex( DerivedMesh *dm, float *varray, int *index, int *redir, void *user )
 {
 	int start;
-	int i;
+	int i, j;
 
 	MVert *mvert;
 	MFace *mface;
@@ -465,13 +472,20 @@
 			VECCOPY(&varray[start+15],mvert[mface[i].v1].co);
 		}
 	}
+	j = dm->drawObject->nelements*3;
+	for( i = 0; i < dm->drawObject->nindices; i++ ) {
+		if( dm->drawObject->indices[i].element >= dm->drawObject->nelements ) {
+			VECCOPY(&varray[j],mvert[i].co);
+			j+=3;
+		}
+	}
 }
 
 GPUBuffer *GPU_buffer_vertex( DerivedMesh *dm )
 {
 	DEBUG_VBO("GPU_buffer_vertex\n");
 
-	return GPU_buffer_setup( dm, dm->drawObject, sizeof(float)*3*dm->drawObject->nelements, GL_ARRAY_BUFFER_ARB, 0, GPU_buffer_copy_vertex);
+	return GPU_buffer_setup( dm, dm->drawObject, sizeof(float)*3*(dm->drawObject->nelements+dm->drawObject->nlooseverts), GL_ARRAY_BUFFER_ARB, 0, GPU_buffer_copy_vertex);
 }
 
 void GPU_buffer_copy_normal( DerivedMesh *dm, float *varray, int *index, int *redir, void *user )





More information about the Bf-blender-cvs mailing list