diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2010-03-22 20:17:36 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2010-03-22 20:17:36 +0300 |
commit | a2778a262b42cc6af2428cbd5196e9163d6673a9 (patch) | |
tree | 4173de3b77c76faace9e6c100e67ea575eb0c9cd | |
parent | 867cad85b7af1059b79b5ad70b046c3f68f17b69 (diff) |
Fix #20548: flat shading not drawing right in sculpt mode.
-rw-r--r-- | source/blender/blenkernel/intern/cdderivedmesh.c | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/subsurf_ccg.c | 2 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_pbvh.h | 2 | ||||
-rw-r--r-- | source/blender/blenlib/intern/pbvh.c | 25 | ||||
-rw-r--r-- | source/blender/gpu/gpu_buffers.h | 2 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_buffers.c | 25 |
6 files changed, 42 insertions, 16 deletions
diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c index 6399d55150a..b3e702ceee9 100644 --- a/source/blender/blenkernel/intern/cdderivedmesh.c +++ b/source/blender/blenkernel/intern/cdderivedmesh.c @@ -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); } diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c index 0cc574984b8..9078566f109 100644 --- a/source/blender/blenkernel/intern/subsurf_ccg.c +++ b/source/blender/blenkernel/intern/subsurf_ccg.c @@ -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); } diff --git a/source/blender/blenlib/BLI_pbvh.h b/source/blender/blenlib/BLI_pbvh.h index 313c1e36de6..0da5b8529bb 100644 --- a/source/blender/blenlib/BLI_pbvh.h +++ b/source/blender/blenlib/BLI_pbvh.h @@ -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 */ diff --git a/source/blender/blenlib/intern/pbvh.c b/source/blender/blenlib/intern/pbvh.c index c0f758187a4..67b75e95cf4 100644 --- a/source/blender/blenlib/intern/pbvh.c +++ b/source/blender/blenlib/intern/pbvh.c @@ -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, diff --git a/source/blender/gpu/gpu_buffers.h b/source/blender/gpu/gpu_buffers.h index 945cccced8d..98cefa7a696 100644 --- a/source/blender/gpu/gpu_buffers.h +++ b/source/blender/gpu/gpu_buffers.h @@ -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); diff --git a/source/blender/gpu/intern/gpu_buffers.c b/source/blender/gpu/intern/gpu_buffers.c index 868930f4056..74bef43e928 100644 --- a/source/blender/gpu/intern/gpu_buffers.c +++ b/source/blender/gpu/intern/gpu_buffers.c @@ -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; |