Use GPU_Buffers to draw wireframe when in dynamic-topology sculpt mode
authorNicholas Bishop <nicholasbishop@gmail.com>
Sun, 30 Dec 2012 18:30:13 +0000 (18:30 +0000)
committerNicholas Bishop <nicholasbishop@gmail.com>
Sun, 30 Dec 2012 18:30:13 +0000 (18:30 +0000)
This adds an override to the CDDM edge drawing function that switches
to GPU_Buffers drawing for PBVHes of type PBVH_BMESH.

Within the GPU_Buffers code, glPolygonMode() is used to draw lines
instead of faces.

source/blender/blenkernel/BKE_pbvh.h
source/blender/blenkernel/intern/cdderivedmesh.c
source/blender/blenkernel/intern/pbvh.c
source/blender/blenkernel/intern/subsurf_ccg.c
source/blender/gpu/GPU_buffers.h
source/blender/gpu/intern/gpu_buffers.c

index 4abeed513df8dbc8760ee04f55a54e87273b2a21..7e5ebc9d0222a7cace8766698b352ea0647021f3 100644 (file)
@@ -102,7 +102,7 @@ int BLI_pbvh_node_raycast(PBVH *bvh, PBVHNode *node, float (*origco)[3], int use
 
 void BLI_pbvh_node_draw(PBVHNode *node, void *data);
 void BLI_pbvh_draw(PBVH *bvh, float (*planes)[4], float (*face_nors)[3],
-                   int (*setMaterial)(int, void *attribs));
+                   int (*setMaterial)(int, void *attribs), int wireframe);
 
 /* PBVH Access */
 typedef enum {
index 080e5fd857c747c174decf0d3eb630cd28445235..3d4cb7b4745fea2009c7385dd5b13ccd67d996ef 100644 (file)
@@ -425,6 +425,14 @@ static void cdDM_drawEdges(DerivedMesh *dm, int drawLooseEdges, int drawAllEdges
        MVert *mvert = cddm->mvert;
        MEdge *medge = cddm->medge;
        int i;
+
+       if (cddm->pbvh && cddm->pbvh_draw &&
+               BLI_pbvh_type(cddm->pbvh) == PBVH_BMESH)
+       {
+               BLI_pbvh_draw(cddm->pbvh, NULL, NULL, NULL, TRUE);
+
+               return;
+       }
        
        if (GPU_buffer_legacy(dm)) {
                DEBUG_VBO("Using legacy code. cdDM_drawEdges\n");
@@ -541,7 +549,8 @@ static void cdDM_drawFacesSolid(DerivedMesh *dm,
                if (dm->numTessFaceData) {
                        float (*face_nors)[3] = CustomData_get_layer(&dm->faceData, CD_NORMAL);
 
-                       BLI_pbvh_draw(cddm->pbvh, partial_redraw_planes, face_nors, setMaterial);
+                       BLI_pbvh_draw(cddm->pbvh, partial_redraw_planes, face_nors,
+                                                 setMaterial, FALSE);
                        glShadeModel(GL_FLAT);
                }
 
index 6e0209e768382bc051bc9ae8a1c1e4f21fbb13a1..1b6a544339dac0b2ce8f8646b25f46821b422e37 100644 (file)
@@ -1523,8 +1523,15 @@ int BLI_pbvh_node_raycast(PBVH *bvh, PBVHNode *node, float (*origco)[3], int use
 
 //#include <GL/glew.h>
 
-void BLI_pbvh_node_draw(PBVHNode *node, void *setMaterial)
+typedef struct {
+       DMSetMaterial setMaterial;
+       int wireframe;
+} PBVHNodeDrawData;
+
+void BLI_pbvh_node_draw(PBVHNode *node, void *data_v)
 {
+       PBVHNodeDrawData *data = data_v;
+
 #if 0
        /* XXX: Just some quick code to show leaf nodes in different colors */
        float col[3]; int i;
@@ -1543,7 +1550,9 @@ void BLI_pbvh_node_draw(PBVHNode *node, void *setMaterial)
 #endif
 
        if (!(node->flag & PBVH_FullyHidden))
-               GPU_draw_buffers(node->draw_buffers, setMaterial);
+               GPU_draw_buffers(node->draw_buffers,
+                                                data->setMaterial,
+                                                data->wireframe);
 }
 
 typedef enum {
@@ -1612,8 +1621,9 @@ static void pbvh_node_check_diffuse_changed(PBVH *bvh, PBVHNode *node)
 }
 
 void BLI_pbvh_draw(PBVH *bvh, float (*planes)[4], float (*face_nors)[3],
-                   DMSetMaterial setMaterial)
+                   DMSetMaterial setMaterial, int wireframe)
 {
+       PBVHNodeDrawData draw_data = {setMaterial, wireframe};
        PBVHNode **nodes;
        int a, totnode;
 
@@ -1630,10 +1640,10 @@ void BLI_pbvh_draw(PBVH *bvh, float (*planes)[4], float (*face_nors)[3],
 
        if (planes) {
                BLI_pbvh_search_callback(bvh, BLI_pbvh_node_planes_contain_AABB,
-                                        planes, BLI_pbvh_node_draw, setMaterial);
+                                        planes, BLI_pbvh_node_draw, &draw_data);
        }
        else {
-               BLI_pbvh_search_callback(bvh, NULL, NULL, BLI_pbvh_node_draw, setMaterial);
+               BLI_pbvh_search_callback(bvh, NULL, NULL, BLI_pbvh_node_draw, &draw_data);
        }
 }
 
index fdd115617de8daffdee84988862e5c0f689cec45..b72499b3b14d8b2c4096b94826207955dad0cbc9 100644 (file)
@@ -1707,7 +1707,8 @@ static void ccgDM_drawFacesSolid(DerivedMesh *dm, float (*partial_redraw_planes)
 
        if (ccgdm->pbvh && ccgdm->multires.mmd && !fast) {
                if (dm->numTessFaceData) {
-                       BLI_pbvh_draw(ccgdm->pbvh, partial_redraw_planes, NULL, setMaterial);
+                       BLI_pbvh_draw(ccgdm->pbvh, partial_redraw_planes, NULL,
+                                                 setMaterial, FALSE);
                        glShadeModel(GL_FLAT);
                }
 
index 70ca44c2a3aa249c95e7f3b03d31d97bb82237db..9f6f80585ab58bfd734d5bc76e82f7cffd9a5d07 100644 (file)
@@ -184,7 +184,8 @@ void GPU_update_grid_buffers(GPU_Buffers *buffers, struct CCGElem **grids,
                              int *grid_indices, int totgrid, const struct CCGKey *key,
                              int show_diffuse_color);
 
-void GPU_draw_buffers(GPU_Buffers *buffers, DMSetMaterial setMaterial);
+void GPU_draw_buffers(GPU_Buffers *buffers, DMSetMaterial setMaterial,
+                                         int wireframe);
 
 int GPU_buffers_diffuse_changed(GPU_Buffers *buffers, int show_diffuse_color);
 
index ba09013711823319c728b2194813f7fd1172e0c0..5f9f68e9c99d016fd45a9ee2317ba22261ed553c 100644 (file)
@@ -2312,7 +2312,8 @@ static void gpu_draw_buffers_legacy_grids(GPU_Buffers *buffers)
        }
 }
 
-void GPU_draw_buffers(GPU_Buffers *buffers, DMSetMaterial setMaterial)
+void GPU_draw_buffers(GPU_Buffers *buffers, DMSetMaterial setMaterial,
+                                         int wireframe)
 {
        if (buffers->totface) {
                const MFace *f = &buffers->mface[buffers->face_indices[0]];
@@ -2329,14 +2330,19 @@ void GPU_draw_buffers(GPU_Buffers *buffers, DMSetMaterial setMaterial)
 
        if (buffers->vert_buf) {
                glEnableClientState(GL_VERTEX_ARRAY);
-               glEnableClientState(GL_NORMAL_ARRAY);
-               gpu_colors_enable(VBO_ENABLED);
+               if (!wireframe) {
+                       glEnableClientState(GL_NORMAL_ARRAY);
+                       gpu_colors_enable(VBO_ENABLED);
+               }
 
                glBindBufferARB(GL_ARRAY_BUFFER_ARB, buffers->vert_buf);
 
                if (buffers->index_buf)
                        glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, buffers->index_buf);
 
+               if (wireframe)
+                       glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
+
                if (buffers->tot_quad) {
                        char *offset = 0;
                        int i, last = buffers->has_hidden ? 1 : buffers->totgrid;
@@ -2369,13 +2375,18 @@ void GPU_draw_buffers(GPU_Buffers *buffers, DMSetMaterial setMaterial)
                                glDrawArrays(GL_TRIANGLES, 0, totelem);
                }
 
+               if (wireframe)
+                       glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
+
                glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
                if (buffers->index_buf)
                        glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
 
                glDisableClientState(GL_VERTEX_ARRAY);
-               glDisableClientState(GL_NORMAL_ARRAY);
-               gpu_colors_disable(VBO_ENABLED);
+               if (!wireframe) {
+                       glDisableClientState(GL_NORMAL_ARRAY);
+                       gpu_colors_disable(VBO_ENABLED);
+               }
        }
        /* fallbacks if we are out of memory or VBO is disabled */
        else if (buffers->totface) {