[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [22120] branches/soc-2009-imbusy/source/ blender: improved edit mode face rendering

Lukas Steiblys imbusy at imbusy.org
Sat Aug 1 15:13:44 CEST 2009


Revision: 22120
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=22120
Author:   imbusy
Date:     2009-08-01 15:13:44 +0200 (Sat, 01 Aug 2009)

Log Message:
-----------
improved edit mode face rendering

Modified Paths:
--------------
    branches/soc-2009-imbusy/source/blender/blenkernel/intern/DerivedMesh.c
    branches/soc-2009-imbusy/source/blender/editors/space_view3d/drawobject.c

Modified: branches/soc-2009-imbusy/source/blender/blenkernel/intern/DerivedMesh.c
===================================================================
--- branches/soc-2009-imbusy/source/blender/blenkernel/intern/DerivedMesh.c	2009-08-01 12:49:39 UTC (rev 22119)
+++ branches/soc-2009-imbusy/source/blender/blenkernel/intern/DerivedMesh.c	2009-08-01 13:13:44 UTC (rev 22120)
@@ -491,9 +491,12 @@
 		}
 		glEnd();
 	} else {
-		/*GPUBuffer *buffer = GPU_buffer_alloc( sizeof(float)*3*2*emdm->em->totedge, 0 );
+		GPUBuffer *buffer = 0;
 		float *varray;
-		if( (varray = GPU_buffer_lock( buffer )) ) {
+		if( setDrawOptions == 0 ) {
+			buffer = GPU_buffer_alloc( sizeof(float)*3*2*emdm->em->totedge, 0 );
+		}
+		if( buffer != 0 && (varray = GPU_buffer_lock( buffer )) ) {
 			int prevdraw = 0;
 			int numedges = 0;
 			int draw = 0;
@@ -525,7 +528,7 @@
 				glDrawArrays(GL_LINES,0,numedges*2);
 			}
 			GPU_buffer_unbind();
-		} else {*/
+		} else {
 			glBegin(GL_LINES);
 			for(i=0,eed= emdm->em->edges.first; eed; i++,eed= eed->next) {
 				if(!setDrawOptions || setDrawOptions(userData, i)) {
@@ -534,8 +537,9 @@
 				}
 			}
 			glEnd();
-		/*}
-		GPU_buffer_free( buffer, 0 );*/
+		}
+		if( buffer != 0 )
+			GPU_buffer_free( buffer, 0 );
 	}
 }
 static void emDM_drawEdges(DerivedMesh *dm, int drawLooseEdges)
@@ -696,10 +700,13 @@
 			}
 		}
 	} else {
-		/* 3 floats for position, 3 for normal and times two because the faces may actually be quads instead of triangles */
-		/*GPUBuffer *buffer = GPU_buffer_alloc( sizeof(float)*6*emdm->em->totface*3*2, 0 );
+		GPUBuffer *buffer = 0;
 		float *varray;
-		if( (varray = GPU_buffer_lock( buffer )) ) {
+		if( setDrawOptions == 0 ) {
+			/* 3 floats for position, 3 for normal and times two because the faces may actually be quads instead of triangles */
+			buffer = GPU_buffer_alloc( sizeof(float)*6*emdm->em->totface*3*2, 0 );
+		}
+		if( buffer != 0 && (varray = GPU_buffer_lock( buffer )) ) {
 			int prevdraw = 0;
 			int numfaces = 0;
 			int datatype[] = { GPU_BUFFER_INTER_V3F, GPU_BUFFER_INTER_N3F, GPU_BUFFER_INTER_END };
@@ -714,7 +721,6 @@
 					if( prevdraw==2 ) {
 						glEnable(GL_POLYGON_STIPPLE);
 		  				glPolygonStipple(stipple_quarttone);
-						glDisable(GL_POLYGON_STIPPLE);
 					}
 					GPU_buffer_unlock( buffer );
 					glDrawArrays(GL_TRIANGLES,0,numfaces*3);
@@ -784,7 +790,7 @@
 				}
 			}
 			GPU_buffer_unbind();
-		} else {*/
+		} else {
 			for (i=0,efa= emdm->em->faces.first; efa; i++,efa= efa->next) {
 				int drawSmooth = (efa->flag & ME_SMOOTH);
 				draw = setDrawOptions==NULL ? 1 : setDrawOptions(userData, i, &drawSmooth);
@@ -820,8 +826,9 @@
 						glDisable(GL_POLYGON_STIPPLE);
 				}
 			}
-		/*}
-		GPU_buffer_free( buffer, 0 );*/
+		}
+		if( buffer != 0 )
+			GPU_buffer_free( buffer, 0 );
 	}
 }
 

Modified: branches/soc-2009-imbusy/source/blender/editors/space_view3d/drawobject.c
===================================================================
--- branches/soc-2009-imbusy/source/blender/editors/space_view3d/drawobject.c	2009-08-01 12:49:39 UTC (rev 22119)
+++ branches/soc-2009-imbusy/source/blender/editors/space_view3d/drawobject.c	2009-08-01 13:13:44 UTC (rev 22120)
@@ -2349,13 +2349,167 @@
 			}
 		}
 		else {
+			EditMeshDerivedMesh *emdm= (EditMeshDerivedMesh*) finalDM;
+			/* 3 floats for position, 3 for normal and times two because the faces may actually be quads instead of triangles */
+			GPUBuffer *buffer = GPU_buffer_alloc( sizeof(float)*6*emdm->em->totface*3*2, 0 );
+			float *varray;
+			EditFace *efa;
+			int i, curmat = 0, draw = 0;
+
 			glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, me->flag & ME_TWOSIDED);
 
 			glEnable(GL_LIGHTING);
 			glFrontFace((ob->transflag&OB_NEG_SCALE)?GL_CW:GL_CCW);
 
-			finalDM->drawMappedFaces(finalDM, draw_em_fancy__setFaceOpts, 0, 0);
+			if( (varray = GPU_buffer_lock( buffer )) ) {
+				int prevdraw = 0, prevmat = 0;
+				int numfaces = 0;
+				int datatype[] = { GPU_BUFFER_INTER_V3F, GPU_BUFFER_INTER_N3F, GPU_BUFFER_INTER_END };
+				GPU_buffer_unlock( buffer );
+				GPU_interleaved_setup( buffer, datatype );
+				glShadeModel(GL_SMOOTH);
+				GPU_buffer_lock( buffer );
+				for (i=0,efa= emdm->em->faces.first; efa; i++,efa= efa->next) {
+					int drawSmooth = (efa->flag & ME_SMOOTH);
+					if( efa->h == 0 ) {
+						curmat = efa->mat_nr+1;
+						draw = 1;
+					} 
+					else {
+						draw = 0;
+					}
+					if( ((prevdraw != draw) || (curmat != prevmat)) && prevdraw != 0 && numfaces > 0) {
+						if( prevdraw==2 ) {
+							glEnable(GL_POLYGON_STIPPLE);
+		  					glPolygonStipple(stipple_quarttone);
+						}
+						GPU_buffer_unlock( buffer );
+						GPU_enable_material(prevmat, NULL);
+						glDrawArrays(GL_TRIANGLES,0,numfaces*3);
+						if( prevdraw==2 ) {
+							glDisable(GL_POLYGON_STIPPLE);
+						}
+						varray = GPU_buffer_lock( buffer );
+						numfaces = 0;
+					}
+					if( draw != 0 ) {
+						if(!drawSmooth) {
+							if( emdm->vertexCos )
+							{
+								VECCOPY(&varray[numfaces*18],emdm->vertexCos[(int) efa->v1->tmp.l]);
+								VECCOPY(&varray[numfaces*18+3],emdm->faceNos[i]);
 
+								VECCOPY(&varray[numfaces*18+6],emdm->vertexCos[(int) efa->v2->tmp.l]);
+								VECCOPY(&varray[numfaces*18+9],emdm->faceNos[i]);
+
+								VECCOPY(&varray[numfaces*18+12],emdm->vertexCos[(int) efa->v3->tmp.l]);
+								VECCOPY(&varray[numfaces*18+15],emdm->faceNos[i]);
+								numfaces++;
+								if( efa->v4 ) {
+									VECCOPY(&varray[numfaces*18],emdm->vertexCos[(int) efa->v3->tmp.l]);
+									VECCOPY(&varray[numfaces*18+3],emdm->faceNos[i]);
+
+									VECCOPY(&varray[numfaces*18+6],emdm->vertexCos[(int) efa->v4->tmp.l]);
+									VECCOPY(&varray[numfaces*18+9],emdm->faceNos[i]);
+
+									VECCOPY(&varray[numfaces*18+12],emdm->vertexCos[(int) efa->v1->tmp.l]);
+									VECCOPY(&varray[numfaces*18+15],emdm->faceNos[i]);
+									numfaces++;
+								}
+							}
+							else {
+								VECCOPY(&varray[numfaces*18],efa->v1->co);
+								VECCOPY(&varray[numfaces*18+3],efa->n);
+
+								VECCOPY(&varray[numfaces*18+6],efa->v2->co);
+								VECCOPY(&varray[numfaces*18+9],efa->n);
+
+								VECCOPY(&varray[numfaces*18+12],efa->v3->co);
+								VECCOPY(&varray[numfaces*18+15],efa->n);
+								numfaces++;
+								if( efa->v4 ) {
+									VECCOPY(&varray[numfaces*18],efa->v3->co);
+									VECCOPY(&varray[numfaces*18+3],efa->n);
+
+									VECCOPY(&varray[numfaces*18+6],efa->v4->co);
+									VECCOPY(&varray[numfaces*18+9],efa->n);
+
+									VECCOPY(&varray[numfaces*18+12],efa->v1->co);
+									VECCOPY(&varray[numfaces*18+15],efa->n);
+									numfaces++;
+								}
+							}
+						}
+						else {
+							if( emdm->vertexCos )
+							{
+								VECCOPY(&varray[numfaces*18],emdm->vertexCos[(int) efa->v1->tmp.l]);
+								VECCOPY(&varray[numfaces*18+3],emdm->vertexNos[(int) efa->v1->tmp.l]);
+
+								VECCOPY(&varray[numfaces*18+6],emdm->vertexCos[(int) efa->v2->tmp.l]);
+								VECCOPY(&varray[numfaces*18+9],emdm->vertexNos[(int) efa->v2->tmp.l]);
+
+								VECCOPY(&varray[numfaces*18+12],emdm->vertexCos[(int) efa->v3->tmp.l]);
+								VECCOPY(&varray[numfaces*18+15],emdm->vertexNos[(int) efa->v3->tmp.l]);
+								numfaces++;
+								if( efa->v4 ) {
+									VECCOPY(&varray[numfaces*18],emdm->vertexCos[(int) efa->v3->tmp.l]);
+									VECCOPY(&varray[numfaces*18+3],emdm->vertexNos[(int) efa->v3->tmp.l]);
+
+									VECCOPY(&varray[numfaces*18+6],emdm->vertexCos[(int) efa->v4->tmp.l]);
+									VECCOPY(&varray[numfaces*18+9],emdm->vertexNos[(int) efa->v4->tmp.l]);
+
+									VECCOPY(&varray[numfaces*18+12],emdm->vertexCos[(int) efa->v1->tmp.l]);
+									VECCOPY(&varray[numfaces*18+15],emdm->vertexNos[(int) efa->v1->tmp.l]);
+									numfaces++;
+								}
+							}
+							else {
+								VECCOPY(&varray[numfaces*18],efa->v1->co);
+								VECCOPY(&varray[numfaces*18+3],efa->v1->no);
+
+								VECCOPY(&varray[numfaces*18+6],efa->v2->co);
+								VECCOPY(&varray[numfaces*18+9],efa->v2->no);
+
+								VECCOPY(&varray[numfaces*18+12],efa->v3->co);
+								VECCOPY(&varray[numfaces*18+15],efa->v3->no);
+								numfaces++;
+								if( efa->v4 ) {
+									VECCOPY(&varray[numfaces*18],efa->v3->co);
+									VECCOPY(&varray[numfaces*18+3],efa->v3->no);
+
+									VECCOPY(&varray[numfaces*18+6],efa->v4->co);
+									VECCOPY(&varray[numfaces*18+9],efa->v4->no);
+
+									VECCOPY(&varray[numfaces*18+12],efa->v1->co);
+									VECCOPY(&varray[numfaces*18+15],efa->v1->no);
+									numfaces++;
+								}
+							}
+						}
+					}
+					prevdraw = draw;
+					prevmat = curmat;
+				}
+				GPU_buffer_unlock( buffer );
+				if( prevdraw != 0 && numfaces > 0) {
+					if( prevdraw==2 ) {
+						glEnable(GL_POLYGON_STIPPLE);
+	  					glPolygonStipple(stipple_quarttone);
+					}
+					GPU_enable_material(prevmat, NULL);
+					glDrawArrays(GL_TRIANGLES,0,numfaces*3);
+					if( prevdraw==2 ) {
+						glDisable(GL_POLYGON_STIPPLE);
+					}
+				}
+				GPU_buffer_unbind();
+			}
+			else {
+				finalDM->drawMappedFaces(finalDM, draw_em_fancy__setFaceOpts, 0, 0);
+			}
+			GPU_buffer_free(buffer,0);
+
 			glFrontFace(GL_CCW);
 			glDisable(GL_LIGHTING);
 		}





More information about the Bf-blender-cvs mailing list