Revision: 21801
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=21801
Author:   imbusy
Date:     2009-07-22 18:28:27 +0200 (Wed, 22 Jul 2009)

Log Message:
-----------
edge drawing now uses buffer code

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-22 14:14:26 UTC (rev 21800)
+++ branches/soc-2009-imbusy/source/blender/blenkernel/intern/cdderivedmesh.c   
2009-07-22 16:28:27 UTC (rev 21801)
@@ -222,16 +222,46 @@
        MVert *mvert = cddm->mvert;
        MEdge *medge = cddm->medge;
        int i;
-               
-       glBegin(GL_LINES);
-       for(i = 0; i < dm->numEdgeData; i++, medge++) {
-               if((medge->flag&ME_EDGEDRAW)
-                  && (drawLooseEdges || !(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_drawEdges\n" );
+               glBegin(GL_LINES);
+               for(i = 0; i < dm->numEdgeData; i++, medge++) {
+                       if((medge->flag&ME_EDGEDRAW)
+                          && (drawLooseEdges || !(medge->flag&ME_LOOSEEDGE))) {
+                               glVertex3fv(mvert[medge->v1].co);
+                               glVertex3fv(mvert[medge->v2].co);
+                       }
                }
+               glEnd();
        }
-       glEnd();
+       else {  /* use OpenGL VBOs or Vertex Arrays instead for better, faster 
rendering */
+               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_EDGEDRAW)
+                                  && (drawLooseEdges || 
!(medge->flag&ME_LOOSEEDGE))) {
+                                       draw = 1;
+                               } 
+                               else {
+                                       draw = 0;
+                               }
+                               if( prevdraw != draw && prevdraw > 0 && 
(i-prevstart) > 0) {
+                                       
glDrawArrays(GL_LINES,prevstart*2,(i-prevstart)*2);
+                                       prevstart = i;
+                               }
+                               prevdraw = draw;
+                       }
+                       if( prevdraw > 0 && (i-prevstart) > 0 ) {
+                               
glDrawArrays(GL_LINES,prevstart*2,(i-prevstart)*2);
+                       }
+               }
+               GPU_buffer_unbind();
+       }
 }
 
 static void cdDM_drawLooseEdges(DerivedMesh *dm)

Modified: branches/soc-2009-imbusy/source/blender/gpu/gpu_buffers.h
===================================================================
--- branches/soc-2009-imbusy/source/blender/gpu/gpu_buffers.h   2009-07-22 
14:14:26 UTC (rev 21800)
+++ branches/soc-2009-imbusy/source/blender/gpu/gpu_buffers.h   2009-07-22 
16:28:27 UTC (rev 21801)
@@ -78,6 +78,8 @@
        GPUBuffer *normals;
        GPUBuffer *uv;
        GPUBuffer *colors;
+       GPUBuffer *edges;
+
        int     *faceRemap;                     /* at what index was the face 
originally in DerivedMesh */
        IndexLink *indices;             /* given an index, find all elements 
using it */
        IndexLink *indexMem;    /* for faster memory allocation/freeing */
@@ -88,6 +90,7 @@
 
        int nmaterials;
        int nelements;
+       int nedges;
        int nindices;
        int legacy;     /* if there was a failure allocating some buffer, use 
old rendering code */
 
@@ -107,6 +110,7 @@
 void GPU_normal_setup( struct DerivedMesh *dm );
 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_buffer_lock( GPUBuffer *buffer );
 void GPU_buffer_unlock( 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-22 14:14:26 UTC (rev 21800)
+++ branches/soc-2009-imbusy/source/blender/gpu/intern/gpu_buffers.c    
2009-07-22 16:28:27 UTC (rev 21801)
@@ -243,6 +243,8 @@
        object = MEM_callocN(sizeof(GPUDrawObject),"GPU_drawobject_new_object");
        object->nindices = dm->getNumVerts(dm);
        object->indices = MEM_mallocN(sizeof(IndexLink)*object->nindices, 
"GPU_drawobject_new_indices");
+       object->nedges = dm->getNumEdges(dm);
+
        for( i = 0; i < object->nindices; i++ ) {
                object->indices[i].element = -1;
                object->indices[i].next = 0;
@@ -355,8 +357,15 @@
 
        DEBUG_VBO("GPU_buffer_setup\n");
 
-       if( globalPool == 0 )
+       if( globalPool == 0 ) {
                globalPool = GPU_buffer_pool_new();
+
+               /* somehow GL_NORMAL_ARRAY is enabled on startup and causes 
edge drawing code to crash */
+               glDisableClientState( GL_VERTEX_ARRAY );
+               glDisableClientState( GL_NORMAL_ARRAY );
+               glDisableClientState( GL_TEXTURE_COORD_ARRAY );
+               glDisableClientState( GL_COLOR_ARRAY );
+       }
        buffer = GPU_buffer_alloc(size,globalPool);
        if( buffer == 0 ) {
                dm->drawObject->legacy = 1;
@@ -665,6 +674,31 @@
        return result;
 }
 
+void GPU_buffer_copy_edge( DerivedMesh *dm, float *varray, int *index, int 
*redir, void *user )
+{
+       int i;
+
+       MVert *mvert;
+       MEdge *medge;
+ 
+       DEBUG_VBO("GPU_buffer_copy_edge\n");
+
+       mvert = dm->getVertArray(dm);
+       medge = dm->getEdgeArray(dm);
+
+       for(i = 0; i < dm->getNumEdges(dm); i++) {
+               VECCOPY(&varray[i*6],mvert[medge[i].v1].co);
+               VECCOPY(&varray[i*6+3],mvert[medge[i].v2].co);
+       }
+}
+
+GPUBuffer *GPU_buffer_edge( DerivedMesh *dm )
+{
+       DEBUG_VBO("GPU_buffer_edge\n");
+
+       return GPU_buffer_setup( dm, dm->drawObject, 
sizeof(float)*6*dm->drawObject->nedges, 0, GPU_buffer_copy_edge);
+}
+
 void GPU_vertex_setup( DerivedMesh *dm )
 {
        DEBUG_VBO("GPU_buffer_vertex_setup\n");
@@ -757,6 +791,29 @@
        GLStates |= GPU_BUFFER_COLOR_STATE;
 }
 
+void GPU_edge_setup( DerivedMesh *dm )
+{
+       DEBUG_VBO("GPU_buffer_edge_setup\n");
+       if( dm->drawObject == 0 )
+               dm->drawObject = GPU_drawobject_new( dm );
+       if( dm->drawObject->edges == 0 )
+               dm->drawObject->edges = GPU_buffer_edge( dm );
+       if( dm->drawObject->edges == 0 ) {
+               DEBUG_VBO( "Failed to setup edges\n" );
+               return;
+       }
+       glEnableClientState( GL_VERTEX_ARRAY );
+       if( useVBOs ) {
+               glBindBufferARB( GL_ARRAY_BUFFER_ARB, dm->drawObject->edges->id 
);
+               glVertexPointer( 3, GL_FLOAT, 0, 0 );
+       }
+       else {
+               glVertexPointer( 3, GL_FLOAT, 0, dm->drawObject->edges->pointer 
);
+       }
+
+       GLStates |= GPU_BUFFER_VERTEX_STATE;
+}
+
 void GPU_buffer_unbind()
 {
        DEBUG_VBO("GPU_buffer_unbind\n");


_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to