svn merge ^/trunk/blender -r42521:42550
[blender.git] / source / blender / blenkernel / intern / editderivedmesh.c
index 3297417eb8c27d367c5104c5a300f5d92007a4bb..89bf06be07ebb87329070776ca955e73bac08840 100644 (file)
@@ -619,7 +619,10 @@ static void emDM_drawMappedFaces(
 {
        EditDerivedBMesh *bmdm= (EditDerivedBMesh*) dm;
        BMFace *efa;
-       int i, draw;
+       struct BMLoop *(*looptris)[3]= bmdm->tc->looptris;
+       const int tottri= bmdm->tc->tottri;
+       const int lasttri= tottri - 1; /* compare agasint this a lot */
+       int i, draw, flush;
        const int skip_normals= !glIsEnabled(GL_LIGHTING); /* could be passed as an arg */
 
        /* GL_ZERO is used to detect if drawing has started or not */
@@ -639,8 +642,8 @@ static void emDM_drawMappedFaces(
 
                BM_ElemIndex_Ensure(bmdm->tc->bm, BM_VERT | BM_FACE);
 
-               for (i=0; i<bmdm->tc->tottri; i++) {
-                       BMLoop **l = bmdm->tc->looptris[i];
+               for (i=0; i < tottri; i++) {
+                       BMLoop **l = looptris[i];
                        int drawSmooth;
 
                        efa = l[0]->f;
@@ -695,7 +698,11 @@ static void emDM_drawMappedFaces(
                                        }
                                }
 
-                               if (draw==2) {
+                               flush= (draw==2);
+                               if (!skip_normals && !flush && (i != lasttri))
+                                       flush|= efa->mat_nr != looptris[i + 1][0]->f->mat_nr; /* TODO, make this neater */
+
+                               if (flush) {
                                        glEnd();
                                        poly_prev= GL_ZERO; /* force glBegin */
 
@@ -707,8 +714,8 @@ static void emDM_drawMappedFaces(
        else {
                BM_ElemIndex_Ensure(bmdm->tc->bm, BM_FACE);
 
-               for (i=0; i<bmdm->tc->tottri; i++) {
-                       BMLoop **l = bmdm->tc->looptris[i];
+               for (i=0; i < tottri; i++) {
+                       BMLoop **l = looptris[i];
                        int drawSmooth;
 
                        efa = l[0]->f;
@@ -763,8 +770,12 @@ static void emDM_drawMappedFaces(
                                        }
                                }
 
+                               flush= (draw==2);
+                               if (!skip_normals && !flush && (i != lasttri)) {
+                                       flush|= efa->mat_nr != looptris[i + 1][0]->f->mat_nr; /* TODO, make this neater */
+                               }
 
-                               if (draw==2) {
+                               if (flush) {
                                        glEnd();
                                        poly_prev= GL_ZERO; /* force glBegin */