diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2011-08-29 20:07:44 +0400 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2011-08-29 20:07:44 +0400 |
commit | 88a538048bf7671db6a51fa2791ed1c87fa88611 (patch) | |
tree | 15a400e318b1a4550d872243ebc7c47597289652 /source/blender/blenkernel/intern/cdderivedmesh.c | |
parent | 6cf447a29c0c8dbdb318e28e3c8c8f95f92f5152 (diff) |
Fix #28347: VBO's highlights wrong faces when Mirror modifier is in use
Added callback to drawMappedFaces which checks if two faces have got equal draw options.
After discussion with Brecht we found it's nicest solution for now:
- Disabling VBOs in edit mode for this case wouldn't be nicer for this case -
some additional flag stored in DM should be added in this case.
- Adding new callback in DM isn't nicer that this solution.
- Handling face selection in drawobject would lead to duplicated code
which is also not nice.
Hopefully, this callback could handle all cases in the future.
Also, Brecht mentioned current VBO implementation isn't perfect, so maybe
when we'll redesign this area dealing with edit mode wouldn't be so tricky.
Diffstat (limited to 'source/blender/blenkernel/intern/cdderivedmesh.c')
-rw-r--r-- | source/blender/blenkernel/intern/cdderivedmesh.c | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c index 12fb11c68b3..5eb97630e83 100644 --- a/source/blender/blenkernel/intern/cdderivedmesh.c +++ b/source/blender/blenkernel/intern/cdderivedmesh.c @@ -843,7 +843,8 @@ static void cdDM_drawFacesTex(DerivedMesh *dm, int (*setDrawOptions)(MTFace *tfa cdDM_drawFacesTex_common(dm, setDrawOptions, NULL, NULL); } -static void cdDM_drawMappedFaces(DerivedMesh *dm, int (*setDrawOptions)(void *userData, int index, int *drawSmooth_r), void *userData, int useColors, int (*setMaterial)(int, void *attribs)) +static void cdDM_drawMappedFaces(DerivedMesh *dm, int (*setDrawOptions)(void *userData, int index, int *drawSmooth_r), void *userData, int useColors, int (*setMaterial)(int, void *attribs), + int (*compareDrawOptions)(void *userData, int cur_index, int next_index)) { CDDerivedMesh *cddm = (CDDerivedMesh*) dm; MVert *mv = cddm->mvert; @@ -958,6 +959,7 @@ static void cdDM_drawMappedFaces(DerivedMesh *dm, int (*setDrawOptions)(void *us MFace *mface= mf + actualFace; int drawSmooth= (mface->flag & ME_SMOOTH); int draw = 1; + int flush = 0; if(i != tottri-1) next_actualFace= dm->drawObject->triangle_to_mface[i+1]; @@ -972,11 +974,28 @@ static void cdDM_drawMappedFaces(DerivedMesh *dm, int (*setDrawOptions)(void *us /* 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); + + /* flush buffer if current triangle isn't drawable or it's last triangle... */ + flush= !draw || i == tottri - 1; + + /* ... or when material setting is dissferent */ + flush|= mf[actualFace].mat_nr != mf[next_actualFace].mat_nr; + + if(!flush && compareDrawOptions) { + int next_orig= (index==NULL) ? next_actualFace : index[next_actualFace]; + + /* also compare draw options and flush buffer if they're different + need for face selection highlight in edit mode */ + flush|= compareDrawOptions(userData, orig, next_orig) == 0; + } + + if(flush) { + int first= prevstart*3; + int count= (i-prevstart+(draw ? 1 : 0))*3; /* Add one to the length if we're drawing at the end of the array */ + + if(count) + glDrawArrays(GL_TRIANGLES, first, count); + prevstart = i + 1; } } |