[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [44294] trunk/blender/source/blender: Another fix for non-VBO flat-shading in sculpt mode, this time for non-multires meshes.
Nicholas Bishop
nicholasbishop at gmail.com
Tue Feb 21 05:24:33 CET 2012
Revision: 44294
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=44294
Author: nicholasbishop
Date: 2012-02-21 04:24:30 +0000 (Tue, 21 Feb 2012)
Log Message:
-----------
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.
Modified Paths:
--------------
trunk/blender/source/blender/blenlib/intern/pbvh.c
trunk/blender/source/blender/gpu/GPU_buffers.h
trunk/blender/source/blender/gpu/intern/gpu_buffers.c
Modified: trunk/blender/source/blender/blenlib/intern/pbvh.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/pbvh.c 2012-02-21 04:16:27 UTC (rev 44293)
+++ trunk/blender/source/blender/blenlib/intern/pbvh.c 2012-02-21 04:24:30 UTC (rev 44294)
@@ -1087,7 +1087,8 @@
bvh->verts,
node->vert_indices,
node->uniq_verts +
- node->face_verts);
+ node->face_verts,
+ smooth);
}
node->flag &= ~PBVH_UpdateDrawBuffers;
Modified: trunk/blender/source/blender/gpu/GPU_buffers.h
===================================================================
--- trunk/blender/source/blender/gpu/GPU_buffers.h 2012-02-21 04:16:27 UTC (rev 44293)
+++ trunk/blender/source/blender/gpu/GPU_buffers.h 2012-02-21 04:24:30 UTC (rev 44294)
@@ -163,7 +163,7 @@
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,
Modified: trunk/blender/source/blender/gpu/intern/gpu_buffers.c
===================================================================
--- trunk/blender/source/blender/gpu/intern/gpu_buffers.c 2012-02-21 04:16:27 UTC (rev 44293)
+++ trunk/blender/source/blender/gpu/intern/gpu_buffers.c 2012-02-21 04:24:30 UTC (rev 44294)
@@ -1298,7 +1298,7 @@
};
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 @@
}
buffers->mvert = mvert;
+ buffers->smooth = smooth;
}
GPU_Buffers *GPU_build_mesh_buffers(GHash *map, MFace *mface,
@@ -1558,22 +1559,38 @@
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();
}
}
More information about the Bf-blender-cvs
mailing list