Use GPU_Buffers to draw wireframe when in dynamic-topology sculpt mode
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.
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user