From f994c6caee126f00f97e7da9fde79bdefadd27ec Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 4 Oct 2010 19:01:25 +0000 Subject: bugfix [#24133] r32303, Mirror Modifier + EditMode + VBO's Problem. drawing the triangle arrays were only broken up by hidden faces, but switches in material were ignored. now check for materual context changes. --- source/blender/blenkernel/intern/cdderivedmesh.c | 67 +++++++++++++++--------- 1 file changed, 42 insertions(+), 25 deletions(-) (limited to 'source/blender/blenkernel/intern/cdderivedmesh.c') diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c index ca81e216006..e2ecf21bd62 100644 --- a/source/blender/blenkernel/intern/cdderivedmesh.c +++ b/source/blender/blenkernel/intern/cdderivedmesh.c @@ -872,34 +872,51 @@ static void cdDM_drawMappedFaces(DerivedMesh *dm, int (*setDrawOptions)(void *us if( !GPU_buffer_legacy(dm) ) { int tottri = dm->drawObject->nelements/3; glShadeModel(GL_SMOOTH); - - for( i = 0; i < tottri; i++ ) { - int actualFace = dm->drawObject->faceRemap[i]; - int drawSmooth = (mf[actualFace].flag & ME_SMOOTH); - int draw = 1; - - if(index) { - orig = index[actualFace]; - if(setDrawOptions && orig == ORIGINDEX_NONE) + + if(tottri == 0) { + /* avoid buffer problems in following code */ + } + if(setDrawOptions == NULL) { + /* just draw the entire face array */ + glDrawArrays(GL_TRIANGLES, 0, (tottri-1) * 3); + } + else { + /* we need to check if the next material changes */ + int next_actualFace= dm->drawObject->faceRemap[0]; + + for( i = 0; i < tottri; i++ ) { + //int actualFace = dm->drawObject->faceRemap[i]; + int actualFace = next_actualFace; + int drawSmooth = (mf[actualFace].flag & ME_SMOOTH); + int draw = 1; + + if(i != tottri-1) + next_actualFace= dm->drawObject->faceRemap[i+1]; + + if(index) { + orig = index[actualFace]; + if(orig == ORIGINDEX_NONE) + draw = 0; + } + else + orig = actualFace; + + if(draw && !setDrawOptions(userData, orig, &drawSmooth)) draw = 0; - } - else - orig = actualFace; - - if(draw && setDrawOptions && !setDrawOptions(userData, orig, &drawSmooth)) - draw = 0; - - /* Goal is to draw as long of a contiguous triangle - array as possible, so draw when we hit either an - invisible triangle or at the end of the array */ - if(!draw || i == tottri - 1) { - if(prevstart != i) - /* Add one to the length (via `draw') - if we're drawing at the end of the array */ - glDrawArrays(GL_TRIANGLES,prevstart*3, (i-prevstart+draw)*3); - prevstart = i + 1; + + /* Goal is to draw as long of a contiguous triangle + array as possible, so draw when we hit either an + invisible triangle or at the end of the array */ + if(!draw || i == tottri - 1 || mf[actualFace].mat_nr != mf[next_actualFace].mat_nr) { + if(prevstart != i) + /* Add one to the length (via `draw') + if we're drawing at the end of the array */ + glDrawArrays(GL_TRIANGLES,prevstart*3, (i-prevstart+draw)*3); + prevstart = i + 1; + } } } + glShadeModel(GL_FLAT); } GPU_buffer_unbind(); -- cgit v1.2.3