Fix #20548: flat shading not drawing right in sculpt mode.

This commit is contained in:
2010-03-22 17:17:36 +00:00
parent 867cad85b7
commit a2778a262b
6 changed files with 42 additions and 16 deletions

View File

@@ -426,7 +426,7 @@ static void cdDM_drawFacesSolid(DerivedMesh *dm,
return;
glShadeModel((mface->flag & ME_SMOOTH)? GL_SMOOTH: GL_FLAT);
BLI_pbvh_draw(cddm->pbvh, partial_redraw_planes, face_nors);
BLI_pbvh_draw(cddm->pbvh, partial_redraw_planes, face_nors, (mface->flag & ME_SMOOTH));
glShadeModel(GL_FLAT);
}

View File

@@ -1251,7 +1251,7 @@ static void ccgDM_drawFacesSolid(DerivedMesh *dm, float (*partial_redraw_planes)
return;
glShadeModel((faceFlags[0] & ME_SMOOTH)? GL_SMOOTH: GL_FLAT);
BLI_pbvh_draw(ccgdm->pbvh, partial_redraw_planes, NULL);
BLI_pbvh_draw(ccgdm->pbvh, partial_redraw_planes, NULL, (faceFlags[0] & ME_SMOOTH));
glShadeModel(GL_FLAT);
}

View File

@@ -79,7 +79,7 @@ int BLI_pbvh_node_raycast(PBVH *bvh, PBVHNode *node, float (*origco)[3],
void BLI_pbvh_node_draw(PBVHNode *node, void *data);
int BLI_pbvh_node_planes_contain_AABB(PBVHNode *node, void *data);
void BLI_pbvh_draw(PBVH *bvh, float (*planes)[4], float (*face_nors)[3]);
void BLI_pbvh_draw(PBVH *bvh, float (*planes)[4], float (*face_nors)[3], int smooth);
/* Node Access */

View File

@@ -353,6 +353,8 @@ static void build_mesh_leaf_node(PBVH *bvh, PBVHNode *node)
node->uniq_verts,
node->uniq_verts + node->face_verts);
node->flag |= PBVH_UpdateDrawBuffers;
BLI_ghash_free(map, NULL, NULL);
}
@@ -361,6 +363,8 @@ static void build_grids_leaf_node(PBVH *bvh, PBVHNode *node)
node->draw_buffers =
GPU_build_grid_buffers(bvh->grids, node->prim_indices,
node->totprim, bvh->gridsize);
node->flag |= PBVH_UpdateDrawBuffers;
}
/* Recursively build a node in the tree
@@ -855,7 +859,7 @@ static void pbvh_update_BB_redraw(PBVH *bvh, PBVHNode **nodes,
}
}
static void pbvh_update_draw_buffers(PBVH *bvh, PBVHNode **nodes, int totnode)
static void pbvh_update_draw_buffers(PBVH *bvh, PBVHNode **nodes, int totnode, int smooth)
{
PBVHNode *node;
int n;
@@ -870,7 +874,8 @@ static void pbvh_update_draw_buffers(PBVH *bvh, PBVHNode **nodes, int totnode)
bvh->grids,
node->prim_indices,
node->totprim,
bvh->gridsize);
bvh->gridsize,
smooth);
}
else {
GPU_update_mesh_buffers(node->draw_buffers,
@@ -930,9 +935,6 @@ void BLI_pbvh_update(PBVH *bvh, int flag, float (*face_nors)[3])
if(flag & (PBVH_UpdateBB|PBVH_UpdateOriginalBB|PBVH_UpdateRedraw))
pbvh_update_BB_redraw(bvh, nodes, totnode, flag);
if(flag & PBVH_UpdateDrawBuffers)
pbvh_update_draw_buffers(bvh, nodes, totnode);
if(flag & (PBVH_UpdateBB|PBVH_UpdateOriginalBB))
pbvh_flush_bb(bvh, bvh->nodes, flag);
@@ -1297,9 +1299,18 @@ int BLI_pbvh_node_planes_contain_AABB(PBVHNode *node, void *data)
return 1;
}
void BLI_pbvh_draw(PBVH *bvh, float (*planes)[4], float (*face_nors)[3])
void BLI_pbvh_draw(PBVH *bvh, float (*planes)[4], float (*face_nors)[3], int smooth)
{
BLI_pbvh_update(bvh, PBVH_UpdateNormals|PBVH_UpdateDrawBuffers, face_nors);
PBVHNode **nodes;
int totnode;
BLI_pbvh_search_gather(bvh, update_search_cb, SET_INT_IN_POINTER(PBVH_UpdateNormals|PBVH_UpdateDrawBuffers),
&nodes, &totnode);
pbvh_update_normals(bvh, nodes, totnode, face_nors);
pbvh_update_draw_buffers(bvh, nodes, totnode, smooth);
if(nodes) MEM_freeN(nodes);
if(planes) {
BLI_pbvh_search_callback(bvh, BLI_pbvh_node_planes_contain_AABB,

View File

@@ -137,7 +137,7 @@ void GPU_update_mesh_buffers(void *buffers, struct MVert *mvert,
void *GPU_build_grid_buffers(struct DMGridData **grids,
int *grid_indices, int totgrid, int gridsize);
void GPU_update_grid_buffers(void *buffers_v, struct DMGridData **grids,
int *grid_indices, int totgrid, int gridsize);
int *grid_indices, int totgrid, int gridsize, int smooth);
void GPU_draw_buffers(void *buffers);
void GPU_free_buffers(void *buffers);

View File

@@ -520,11 +520,11 @@ void *GPU_build_mesh_buffers(GHash *map, MVert *mvert, MFace *mface,
}
void GPU_update_grid_buffers(void *buffers_v, DMGridData **grids,
int *grid_indices, int totgrid, int gridsize)
int *grid_indices, int totgrid, int gridsize, int smooth)
{
GPU_Buffers *buffers = buffers_v;
DMGridData *vert_data;
int i, totvert;
int i, j, k, totvert;
totvert= gridsize*gridsize*totgrid;
@@ -539,6 +539,22 @@ void GPU_update_grid_buffers(void *buffers_v, DMGridData **grids,
for(i = 0; i < totgrid; ++i) {
DMGridData *grid= grids[grid_indices[i]];
memcpy(vert_data, grid, sizeof(DMGridData)*gridsize*gridsize);
if(!smooth) {
/* for flat shading, recalc normals and set the last vertex of
each quad in the index buffer to have the flat normal as
that is what opengl will use */
for(j = 0; j < gridsize-1; ++j) {
for(k = 0; k < gridsize-1; ++k) {
normal_quad_v3(vert_data[(j+1)*gridsize + (k+1)].no,
vert_data[(j+1)*gridsize + k].co,
vert_data[(j+1)*gridsize + k+1].co,
vert_data[j*gridsize + k+1].co,
vert_data[j*gridsize + k].co);
}
}
}
vert_data += gridsize*gridsize;
}
glUnmapBufferARB(GL_ARRAY_BUFFER_ARB);
@@ -589,10 +605,10 @@ void *GPU_build_grid_buffers(DMGridData **grids,
for(i = 0; i < totgrid; ++i) {
for(j = 0; j < gridsize-1; ++j) {
for(k = 0; k < gridsize-1; ++k) {
*(quad_data++)= offset + j*gridsize + k+1;
*(quad_data++)= offset + j*gridsize + k;
*(quad_data++)= offset + (j+1)*gridsize + k;
*(quad_data++)= offset + (j+1)*gridsize + k+1;
*(quad_data++)= offset + j*gridsize + k+1;
}
}
@@ -619,10 +635,10 @@ void *GPU_build_grid_buffers(DMGridData **grids,
for(i = 0; i < totgrid; ++i) {
for(j = 0; j < gridsize-1; ++j) {
for(k = 0; k < gridsize-1; ++k) {
*(quad_data++)= offset + j*gridsize + k+1;
*(quad_data++)= offset + j*gridsize + k;
*(quad_data++)= offset + (j+1)*gridsize + k;
*(quad_data++)= offset + (j+1)*gridsize + k+1;
*(quad_data++)= offset + j*gridsize + k+1;
}
}
@@ -642,7 +658,6 @@ void *GPU_build_grid_buffers(DMGridData **grids,
/* Build VBO */
if(buffers->index_buf)
glGenBuffersARB(1, &buffers->vert_buf);
GPU_update_grid_buffers(buffers, grids, grid_indices, totgrid, gridsize);
buffers->tot_quad = totquad;