[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [21994] branches/soc-2009-imbusy/source/ blender: made cdDM_drawUVEdges use buffers, but I can only guess if it works, because I couldn' t find a way to test this function

Lukas Steiblys imbusy at imbusy.org
Tue Jul 28 21:42:11 CEST 2009


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

Log Message:
-----------
made cdDM_drawUVEdges use buffers, but I can only guess if it works, because I couldn't find a way to test this function

Modified Paths:
--------------
    branches/soc-2009-imbusy/source/blender/blenkernel/intern/DerivedMesh.c
    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/DerivedMesh.c
===================================================================
--- branches/soc-2009-imbusy/source/blender/blenkernel/intern/DerivedMesh.c	2009-07-28 19:32:46 UTC (rev 21993)
+++ branches/soc-2009-imbusy/source/blender/blenkernel/intern/DerivedMesh.c	2009-07-28 19:42:11 UTC (rev 21994)
@@ -218,7 +218,7 @@
 {
 	if (dm->needsFree) {
 		bvhcache_free(&dm->bvhCache);
-		GPU_drawobject_free( dm->drawObject );
+		GPU_drawobject_free( dm );
 		CustomData_free(&dm->vertData, dm->numVertData);
 		CustomData_free(&dm->edgeData, dm->numEdgeData);
 		CustomData_free(&dm->faceData, dm->numFaceData);

Modified: branches/soc-2009-imbusy/source/blender/blenkernel/intern/cdderivedmesh.c
===================================================================
--- branches/soc-2009-imbusy/source/blender/blenkernel/intern/cdderivedmesh.c	2009-07-28 19:32:46 UTC (rev 21993)
+++ branches/soc-2009-imbusy/source/blender/blenkernel/intern/cdderivedmesh.c	2009-07-28 19:42:11 UTC (rev 21994)
@@ -200,28 +200,65 @@
 	int i;
 
 	if(mf) {
-		glBegin(GL_LINES);
-		for(i = 0; i < dm->numFaceData; i++, mf++, tf++) {
-			if(!(mf->flag&ME_HIDE)) {
-				glVertex2fv(tf->uv[0]);
-				glVertex2fv(tf->uv[1]);
+		if( GPU_buffer_legacy(dm) ) {
+			glBegin(GL_LINES);
+			for(i = 0; i < dm->numFaceData; i++, mf++, tf++) {
+				if(!(mf->flag&ME_HIDE)) {
+					glVertex2fv(tf->uv[0]);
+					glVertex2fv(tf->uv[1]);
 
-				glVertex2fv(tf->uv[1]);
-				glVertex2fv(tf->uv[2]);
-
-				if(!mf->v4) {
+					glVertex2fv(tf->uv[1]);
 					glVertex2fv(tf->uv[2]);
-					glVertex2fv(tf->uv[0]);
-				} else {
-					glVertex2fv(tf->uv[2]);
-					glVertex2fv(tf->uv[3]);
 
-					glVertex2fv(tf->uv[3]);
-					glVertex2fv(tf->uv[0]);
+					if(!mf->v4) {
+						glVertex2fv(tf->uv[2]);
+						glVertex2fv(tf->uv[0]);
+					} else {
+						glVertex2fv(tf->uv[2]);
+						glVertex2fv(tf->uv[3]);
+
+						glVertex2fv(tf->uv[3]);
+						glVertex2fv(tf->uv[0]);
+					}
 				}
 			}
+			glEnd();
 		}
-		glEnd();
+		else {
+			int prevstart = 0;
+			int prevdraw = 1;
+			int draw = 1;
+			int curpos = 0;
+
+			GPU_uvedge_setup(dm);
+			if( !GPU_buffer_legacy(dm) ) {
+				for(i = 0; i < dm->numFaceData; i++, mf++) {
+					if(mf->flag&ME_LOOSEEDGE) {
+						draw = 1;
+					} 
+					else {
+						draw = 0;
+					}
+					if( prevdraw != draw ) {
+						if( prevdraw > 0 && (curpos-prevstart) > 0) {
+							glDrawArrays(GL_LINES,prevstart,curpos-prevstart);
+						}
+						prevstart = curpos;
+					}
+					if( mf->v4 ) {
+						curpos += 8;
+					}
+					else {
+						curpos += 6;
+					}
+					prevdraw = draw;
+				}
+				if( prevdraw > 0 && (curpos-prevstart) > 0 ) {
+					glDrawArrays(GL_LINES,prevstart,curpos-prevstart);
+				}
+			}
+			GPU_buffer_unbind();
+		}
 	}
 }
 
@@ -293,7 +330,7 @@
 		}
 		glEnd();
 	}
-	else {
+	else {	/* use OpenGL VBOs or Vertex Arrays instead for better, faster rendering */
 		int prevstart = 0;
 		int prevdraw = 1;
 		int draw = 1;
@@ -938,7 +975,7 @@
 		}
 		glEnd();
 	}
-	else {  /* use OpenGL VBOs or Vertex Arrays instead for better, faster rendering */
+	else {  /* TODO */
 		memset(&attribs, 0, sizeof(attribs));
 
 		for(a = 0; a < dm->numFaceData; a++, mface++) {

Modified: branches/soc-2009-imbusy/source/blender/gpu/gpu_buffers.h
===================================================================
--- branches/soc-2009-imbusy/source/blender/gpu/gpu_buffers.h	2009-07-28 19:32:46 UTC (rev 21993)
+++ branches/soc-2009-imbusy/source/blender/gpu/gpu_buffers.h	2009-07-28 19:42:11 UTC (rev 21994)
@@ -79,6 +79,7 @@
 	GPUBuffer *uv;
 	GPUBuffer *colors;
 	GPUBuffer *edges;
+	GPUBuffer *uvedges;
 
 	int	*faceRemap;			/* at what index was the face originally in DerivedMesh */
 	IndexLink *indices;		/* given an index, find all elements using it */
@@ -104,7 +105,7 @@
 void GPU_buffer_free( GPUBuffer *buffer, GPUBufferPool *pool );
 
 GPUDrawObject *GPU_drawobject_new( struct DerivedMesh *dm );
-void GPU_drawobject_free( GPUDrawObject *object );
+void GPU_drawobject_free( struct DerivedMesh *dm );
 
 /* called before drawing */
 void GPU_vertex_setup( struct DerivedMesh *dm );
@@ -112,6 +113,7 @@
 void GPU_uv_setup( struct DerivedMesh *dm );
 void GPU_color_setup( struct DerivedMesh *dm );
 void GPU_edge_setup( struct DerivedMesh *dm );	/* does not mix with other data */
+void GPU_uvedge_setup( struct DerivedMesh *dm );
 
 void GPU_buffer_draw_elements( GPUBuffer *elements, unsigned int mode, int start, int count );
 void *GPU_buffer_lock( GPUBuffer *buffer );

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 19:32:46 UTC (rev 21993)
+++ branches/soc-2009-imbusy/source/blender/gpu/intern/gpu_buffers.c	2009-07-28 19:42:11 UTC (rev 21994)
@@ -333,13 +333,18 @@
 	return object;
 }
 
-void GPU_drawobject_free( GPUDrawObject *object )
+void GPU_drawobject_free( DerivedMesh *dm )
 {
+	GPUDrawObject *object;
+
+	DEBUG_VBO("GPU_drawobject_free\n");
+
+	if( dm == 0 )
+		return;
+	object = dm->drawObject;
 	if( object == 0 )
 		return;
 
-	DEBUG_VBO("GPU_drawobject_free\n");
-
 	MEM_freeN(object->materials);
 	MEM_freeN(object->faceRemap);
 	MEM_freeN(object->indices);
@@ -351,6 +356,7 @@
 	GPU_buffer_free( object->edges, globalPool );
 
 	MEM_freeN(object);
+	dm->drawObject = 0;
 }
 
 GPUBuffer *GPU_buffer_setup( DerivedMesh *dm, GPUDrawObject *object, int size, GLenum target, void *user, void (*copy_f)(DerivedMesh *, float *, int *, int *, void *) )
@@ -715,9 +721,54 @@
 	return GPU_buffer_setup( dm, dm->drawObject, sizeof(int)*2*dm->drawObject->nedges, GL_ELEMENT_ARRAY_BUFFER_ARB, 0, GPU_buffer_copy_edge);
 }
 
+void GPU_buffer_copy_uvedge( DerivedMesh *dm, float *varray, int *index, int *redir, void *user )
+{
+	MTFace *tf = DM_get_face_data_layer(dm, CD_MTFACE);
+	int i, j=0;
+
+	DEBUG_VBO("GPU_buffer_copy_uvedge\n");
+
+	if(tf) {
+		for(i = 0; i < dm->numFaceData; i++, tf++) {
+			MFace mf;
+			dm->getFace(dm,i,&mf);
+
+			VECCOPY2D(&varray[j],tf->uv[0]);
+			VECCOPY2D(&varray[j+2],tf->uv[1]);
+
+			VECCOPY2D(&varray[j+4],tf->uv[1]);
+			VECCOPY2D(&varray[j+6],tf->uv[2]);
+
+			if(!mf.v4) {
+				VECCOPY2D(&varray[j+8],tf->uv[2]);
+				VECCOPY2D(&varray[j+10],tf->uv[0]);
+				j+=12;
+			} else {
+				VECCOPY2D(&varray[j+8],tf->uv[2]);
+				VECCOPY2D(&varray[j+10],tf->uv[3]);
+
+				VECCOPY2D(&varray[j+12],tf->uv[3]);
+				VECCOPY2D(&varray[j+14],tf->uv[0]);
+				j+=16;
+			}
+		}
+	}
+	else {
+		DEBUG_VBO("Could not get MTFACE data layer");
+	}
+}
+
+GPUBuffer *GPU_buffer_uvedge( DerivedMesh *dm )
+{
+	DEBUG_VBO("GPU_buffer_uvedge\n");
+
+	return GPU_buffer_setup( dm, dm->drawObject, sizeof(float)*2*(dm->drawObject->nelements/3)*2, GL_ARRAY_BUFFER_ARB, 0, GPU_buffer_copy_uvedge);
+}
+
+
 void GPU_vertex_setup( DerivedMesh *dm )
 {
-	DEBUG_VBO("GPU_buffer_vertex_setup\n");
+	DEBUG_VBO("GPU_vertex_setup\n");
 	if( dm->drawObject == 0 )
 		dm->drawObject = GPU_drawobject_new( dm );
 	if( dm->drawObject->vertices == 0 )
@@ -741,7 +792,7 @@
 
 void GPU_normal_setup( DerivedMesh *dm )
 {
-	DEBUG_VBO("GPU_buffer_normal_setup\n");
+	DEBUG_VBO("GPU_normal_setup\n");
 	if( dm->drawObject == 0 )
 		dm->drawObject = GPU_drawobject_new( dm );
 	if( dm->drawObject->normals == 0 )
@@ -764,7 +815,7 @@
 
 void GPU_uv_setup( DerivedMesh *dm )
 {
-	DEBUG_VBO("GPU_buffer_uv_setup\n");
+	DEBUG_VBO("GPU_uv_setup\n");
 	if( dm->drawObject == 0 )
 		dm->drawObject = GPU_drawobject_new( dm );
 	if( dm->drawObject->uv == 0 )
@@ -786,7 +837,7 @@
 
 void GPU_color_setup( DerivedMesh *dm )
 {
-	DEBUG_VBO("GPU_buffer_color_setup\n");
+	DEBUG_VBO("GPU_color_setup\n");
 	if( dm->drawObject == 0 )
 		dm->drawObject = GPU_drawobject_new( dm );
 	if( dm->drawObject->colors == 0 )
@@ -809,7 +860,7 @@
 
 void GPU_edge_setup( DerivedMesh *dm )
 {
-	DEBUG_VBO("GPU_buffer_edge_setup\n");
+	DEBUG_VBO("GPU_edge_setup\n");
 	if( dm->drawObject == 0 )
 		dm->drawObject = GPU_drawobject_new( dm );
 	if( dm->drawObject->edges == 0 )
@@ -843,6 +894,30 @@
 	GLStates |= GPU_BUFFER_ELEMENT_STATE;
 }
 
+void GPU_uvedge_setup( DerivedMesh *dm )
+{
+	DEBUG_VBO("GPU_uvedge_setup\n");
+	if( dm->drawObject == 0 )
+		dm->drawObject = GPU_drawobject_new( dm );
+	if( dm->drawObject->uvedges == 0 )
+		dm->drawObject->uvedges = GPU_buffer_uvedge( dm );
+	if( dm->drawObject->uvedges == 0 ) {
+		DEBUG_VBO( "Failed to setup UV edges\n" );
+		return;
+	}
+
+	glEnableClientState( GL_VERTEX_ARRAY );
+	if( useVBOs ) {
+		glBindBufferARB( GL_ARRAY_BUFFER_ARB, dm->drawObject->uvedges->id );
+		glVertexPointer( 2, GL_FLOAT, 0, 0 );
+	}
+	else {
+		glVertexPointer( 2, GL_FLOAT, 0, dm->drawObject->uvedges->pointer );
+	}
+	
+	GLStates |= GPU_BUFFER_VERTEX_STATE;
+}
+
 void GPU_buffer_unbind()
 {
 	DEBUG_VBO("GPU_buffer_unbind\n");





More information about the Bf-blender-cvs mailing list