diff options
author | Nicholas Bishop <nicholasbishop@gmail.com> | 2012-02-21 08:24:30 +0400 |
---|---|---|
committer | Nicholas Bishop <nicholasbishop@gmail.com> | 2012-02-21 08:24:30 +0400 |
commit | 88a2be1846d3cdca5c0a0f0dc68baad933a9f680 (patch) | |
tree | 232c1fa6420619f3da44853eb814059cbb9e3596 /source/blender | |
parent | a6dc47b0cae6bde63dfb3ec77cdae2d77a3e8b26 (diff) |
Another fix for non-VBO flat-shading in sculpt mode, this time for non-multires meshes.
As with multires, this change calculates face normals rather than
using vertex normals when the node is flat-shaded.
Flat-shading with VBO on non-multires meshes is still wrong, but
fixing that would require larger changes to our vertex buffers.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenlib/intern/pbvh.c | 3 | ||||
-rw-r--r-- | source/blender/gpu/GPU_buffers.h | 2 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_buffers.c | 39 |
3 files changed, 31 insertions, 13 deletions
diff --git a/source/blender/blenlib/intern/pbvh.c b/source/blender/blenlib/intern/pbvh.c index 0e3cc51dea5..56f0dff2847 100644 --- a/source/blender/blenlib/intern/pbvh.c +++ b/source/blender/blenlib/intern/pbvh.c @@ -1087,7 +1087,8 @@ static void pbvh_update_draw_buffers(PBVH *bvh, PBVHNode **nodes, int totnode, i bvh->verts, node->vert_indices, node->uniq_verts + - node->face_verts); + node->face_verts, + smooth); } node->flag &= ~PBVH_UpdateDrawBuffers; diff --git a/source/blender/gpu/GPU_buffers.h b/source/blender/gpu/GPU_buffers.h index 945b9d819ef..5c567c31163 100644 --- a/source/blender/gpu/GPU_buffers.h +++ b/source/blender/gpu/GPU_buffers.h @@ -163,7 +163,7 @@ GPU_Buffers *GPU_build_mesh_buffers(struct GHash *map, struct MFace *mface, int *face_indices, int totface, int uniq_verts); void GPU_update_mesh_buffers(GPU_Buffers *buffers, struct MVert *mvert, - int *vert_indices, int totvert); + int *vert_indices, int totvert, int smooth); GPU_Buffers *GPU_build_grid_buffers(struct DMGridData **grids, int *grid_indices, int totgrid, int gridsize); void GPU_update_grid_buffers(GPU_Buffers *buffers, struct DMGridData **grids, diff --git a/source/blender/gpu/intern/gpu_buffers.c b/source/blender/gpu/intern/gpu_buffers.c index 006baac0df5..0a4970a6a91 100644 --- a/source/blender/gpu/intern/gpu_buffers.c +++ b/source/blender/gpu/intern/gpu_buffers.c @@ -1298,7 +1298,7 @@ struct GPU_Buffers { }; void GPU_update_mesh_buffers(GPU_Buffers *buffers, MVert *mvert, - int *vert_indices, int totvert) + int *vert_indices, int totvert, int smooth) { VertexBufferFormat *vert_data; int i; @@ -1331,6 +1331,7 @@ void GPU_update_mesh_buffers(GPU_Buffers *buffers, MVert *mvert, } buffers->mvert = mvert; + buffers->smooth = smooth; } GPU_Buffers *GPU_build_mesh_buffers(GHash *map, MFace *mface, @@ -1558,22 +1559,38 @@ GPU_Buffers *GPU_build_grid_buffers(DMGridData **UNUSED(grids), int *UNUSED(grid static void gpu_draw_buffers_legacy_mesh(GPU_Buffers *buffers) { - int i; + const MVert *mvert = buffers->mvert; + int i, j; for(i = 0; i < buffers->totface; ++i) { MFace *f = buffers->mface + buffers->face_indices[i]; + int S = f->v4 ? 4 : 3; + unsigned int *fv = &f->v1; glBegin((f->v4)? GL_QUADS: GL_TRIANGLES); - glNormal3sv(buffers->mvert[f->v1].no); - glVertex3fv(buffers->mvert[f->v1].co); - glNormal3sv(buffers->mvert[f->v2].no); - glVertex3fv(buffers->mvert[f->v2].co); - glNormal3sv(buffers->mvert[f->v3].no); - glVertex3fv(buffers->mvert[f->v3].co); - if(f->v4) { - glNormal3sv(buffers->mvert[f->v4].no); - glVertex3fv(buffers->mvert[f->v4].co); + + if(buffers->smooth) { + for(j = 0; j < S; j++) { + glNormal3sv(mvert[fv[j]].no); + glVertex3fv(mvert[fv[j]].co); + } } + else { + float fno[3]; + + /* calculate face normal */ + if(f->v4) { + normal_quad_v3(fno, mvert[fv[0]].co, mvert[fv[1]].co, + mvert[fv[2]].co, mvert[fv[3]].co); + } + else + normal_tri_v3(fno, mvert[fv[0]].co, mvert[fv[1]].co, mvert[fv[2]].co); + glNormal3fv(fno); + + for(j = 0; j < S; j++) + glVertex3fv(mvert[fv[j]].co); + } + glEnd(); } } |