svn merge ^/trunk/blender -r42009:42053
[blender.git] / source / blender / blenkernel / intern / subsurf_ccg.c
index 5f23b54..a23037c 100644 (file)
@@ -1412,8 +1412,6 @@ static void ccgdm_pbvh_update(CCGDerivedMesh *ccgdm)
 static void ccgDM_drawEdges(DerivedMesh *dm, int drawLooseEdges, int UNUSED(drawAllEdges)) {
        CCGDerivedMesh *ccgdm = (CCGDerivedMesh*) dm;
        CCGSubSurf *ss = ccgdm->ss;
-       CCGEdgeIterator *ei = ccgSubSurf_getEdgeIterator(ss);
-       CCGFaceIterator *fi = ccgSubSurf_getFaceIterator(ss);
        int i, j, edgeSize = ccgSubSurf_getEdgeSize(ss);
        int totedge = ccgSubSurf_getNumEdges(ss);
        int gridSize = ccgSubSurf_getGridSize(ss);
@@ -1451,8 +1449,10 @@ static void ccgDM_drawEdges(DerivedMesh *dm, int drawLooseEdges, int UNUSED(draw
        }
 
        if (ccgdm->drawInteriorEdges) {
-               for (; !ccgFaceIterator_isStopped(fi); ccgFaceIterator_next(fi)) {
-                       CCGFace *f = ccgFaceIterator_getCurrent(fi);
+               int totface = ccgSubSurf_getNumFaces(ss);
+
+               for(j = 0; j < totface; j++) {
+                       CCGFace *f = ccgdm->faceMap[j].face;
                        int S, x, y, numVerts = ccgSubSurf_getFaceNumVerts(f);
 
                        for (S=0; S<numVerts; S++) {
@@ -1477,18 +1477,15 @@ static void ccgDM_drawEdges(DerivedMesh *dm, int drawLooseEdges, int UNUSED(draw
                        }
                }
        }
-
-       ccgFaceIterator_free(fi);
-       ccgEdgeIterator_free(ei);
 }
 static void ccgDM_drawLooseEdges(DerivedMesh *dm) {
        CCGDerivedMesh *cgdm = (CCGDerivedMesh*) dm;
        CCGSubSurf *ss = cgdm->ss;
-       CCGEdgeIterator *ei = ccgSubSurf_getEdgeIterator(ss);
-       int i, edgeSize = ccgSubSurf_getEdgeSize(ss);
+       int totedge = ccgSubSurf_getNumEdges(ss);
+       int i, j, edgeSize = ccgSubSurf_getEdgeSize(ss);
 
-       for (; !ccgEdgeIterator_isStopped(ei); ccgEdgeIterator_next(ei)) {
-               CCGEdge *e = ccgEdgeIterator_getCurrent(ei);
+       for (j=0; j< totedge; j++) {
+               CCGEdge *e = ccgdm->edgeMap[j].edge;
                DMGridData *edgeData = ccgSubSurf_getEdgeDataArray(ss, e);
 
                if (!ccgSubSurf_getEdgeNumFaces(e)) {
@@ -1500,8 +1497,6 @@ static void ccgDM_drawLooseEdges(DerivedMesh *dm) {
                        glEnd();
                }
        }
-
-       ccgEdgeIterator_free(ei);
 }
 
 static void ccgDM_glNormalFast(float *a, float *b, float *c, float *d)
@@ -1522,10 +1517,11 @@ static void ccgDM_glNormalFast(float *a, float *b, float *c, float *d)
 static void ccgDM_drawFacesSolid(DerivedMesh *dm, float (*partial_redraw_planes)[4], int fast, int (*setMaterial)(int, void *attribs)) {
        CCGDerivedMesh *ccgdm = (CCGDerivedMesh*) dm;
        CCGSubSurf *ss = ccgdm->ss;
-       CCGFaceIterator *fi;
        int gridSize = ccgSubSurf_getGridSize(ss);
        char *faceFlags = ccgdm->faceFlags;
        int step = (fast)? gridSize-1: 1;
+       int i, totface = ccgSubSurf_getNumFaces(ss);
+       int drawcurrent = 0, matnr = -1, shademodel = -1;
 
        ccgdm_pbvh_update(ccgdm);
 
@@ -1543,30 +1539,37 @@ static void ccgDM_drawFacesSolid(DerivedMesh *dm, float (*partial_redraw_planes)
                return;
        }
 
-       fi = ccgSubSurf_getFaceIterator(ss);
-       for (; !ccgFaceIterator_isStopped(fi); ccgFaceIterator_next(fi)) {
-               CCGFace *f = ccgFaceIterator_getCurrent(fi);
+       for(i = 0; i < totface; i++) {
+               CCGFace *f = ccgdm->faceMap[i].face;
                int S, x, y, numVerts = ccgSubSurf_getFaceNumVerts(f);
                int index = GET_INT_FROM_POINTER(ccgSubSurf_getFaceFaceHandle(ss, f));
-               int drawSmooth, mat_nr;
+               int new_matnr, new_shademodel;
 
                if(faceFlags) {
-                       drawSmooth = (faceFlags[index*2] & ME_SMOOTH);
-                       mat_nr= faceFlags[index*2 + 1];
+                       new_shademodel = (faceFlags[index*2] & ME_SMOOTH)? GL_SMOOTH: GL_FLAT;
+                       new_matnr= faceFlags[index*2 + 1];
                }
                else {
-                       drawSmooth = 1;
-                       mat_nr= 0;
+                       new_shademodel = GL_SMOOTH;
+                       new_matnr= 0;
                }
                
-               if (!setMaterial(mat_nr+1, NULL))
+               if(shademodel != new_shademodel || matnr != new_matnr) {
+                       matnr= new_matnr;
+                       shademodel= new_shademodel;
+
+                       drawcurrent= setMaterial(matnr+1, NULL);
+
+                       glShadeModel(shademodel);
+               }
+
+               if(!drawcurrent)
                        continue;
 
-               glShadeModel(drawSmooth? GL_SMOOTH: GL_FLAT);
                for (S=0; S<numVerts; S++) {
                        DMGridData *faceGridData = ccgSubSurf_getFaceGridDataArray(ss, f, S);
 
-                       if (drawSmooth) {
+                       if (shademodel == GL_SMOOTH) {
                                for (y=0; y<gridSize-1; y+=step) {
                                        glBegin(GL_QUAD_STRIP);
                                        for (x=0; x<gridSize; x+=step) {
@@ -1601,15 +1604,12 @@ static void ccgDM_drawFacesSolid(DerivedMesh *dm, float (*partial_redraw_planes)
                        }
                }
        }
-
-       ccgFaceIterator_free(fi);
 }
 
        /* Only used by non-editmesh types */
 static void cgdm_drawMappedFacesGLSL(DerivedMesh *dm, int (*setMaterial)(int, void *attribs), int (*setDrawOptions)(void *userData, int index), void *userData) {
        CCGDerivedMesh *cgdm = (CCGDerivedMesh*) dm;
        CCGSubSurf *ss = cgdm->ss;
-       CCGFaceIterator *fi = ccgSubSurf_getFaceIterator(ss);
        GPUVertexAttribs gattribs;
        DMVertexAttribs attribs= {{{NULL}}};
        /* MTFace *tf = dm->getTessFaceDataArray(dm, CD_MTFACE); */ /* UNUSED */
@@ -1742,8 +1742,6 @@ static void cgdm_drawMappedFacesGLSL(DerivedMesh *dm, int (*setMaterial)(int, vo
        }
 
 #undef PASSATTRIB
-
-       ccgFaceIterator_free(fi);
 }
 
 static void cgdm_drawFacesGLSL(DerivedMesh *dm, int (*setMaterial)(int, void *attribs)) {
@@ -1754,7 +1752,6 @@ static void cgdm_drawFacesGLSL(DerivedMesh *dm, int (*setMaterial)(int, void *at
 static void cgdm_drawMappedFacesMat(DerivedMesh *dm, void (*setMaterial)(void *userData, int, void *attribs), int (*setFace)(void *userData, int index), void *userData) {
        CCGDerivedMesh *ccgdm = (CCGDerivedMesh*) dm;
        CCGSubSurf *ss = ccgdm->ss;
-       CCGFaceIterator *fi = ccgSubSurf_getFaceIterator(ss);
        GPUVertexAttribs gattribs;
        DMVertexAttribs attribs= {{{NULL}}};
        int gridSize = ccgSubSurf_getGridSize(ss);
@@ -1894,18 +1891,15 @@ static void cgdm_drawMappedFacesMat(DerivedMesh *dm, void (*setMaterial)(void *u
        }
 
 #undef PASSATTRIB
-
-       ccgFaceIterator_free(fi);
 }
 
 
 static void cgdm_drawFacesColored(DerivedMesh *dm, int UNUSED(useTwoSided), unsigned char *col1, unsigned char *col2) {
        CCGDerivedMesh *cgdm = (CCGDerivedMesh*) dm;
        CCGSubSurf *ss = cgdm->ss;
-       CCGFaceIterator *fi = ccgSubSurf_getFaceIterator(ss);
        int gridSize = ccgSubSurf_getGridSize(ss);
        unsigned char *cp1, *cp2;
-       int useTwoSide=1;
+       int useTwoSide=1, i, totface;
 
        ccgdm_pbvh_update(cgdm);
 
@@ -1924,8 +1918,9 @@ static void cgdm_drawFacesColored(DerivedMesh *dm, int UNUSED(useTwoSided), unsi
        }
 
        glBegin(GL_QUADS);
-       for (; !ccgFaceIterator_isStopped(fi); ccgFaceIterator_next(fi)) {
-               CCGFace *f = ccgFaceIterator_getCurrent(fi);
+       totface = ccgSubSurf_getNumFaces(ss);
+       for(i = 0; i < totface; i++) {
+               CCGFace *f = ccgdm->faceMap[i].face;
                int S, x, y, numVerts = ccgSubSurf_getFaceNumVerts(f);
 
                for (S=0; S<numVerts; S++) {
@@ -1964,8 +1959,6 @@ static void cgdm_drawFacesColored(DerivedMesh *dm, int UNUSED(useTwoSided), unsi
                }
        }
        glEnd();
-
-       ccgFaceIterator_free(fi);
 }
 
 static void cgdm_drawFacesTex_common(DerivedMesh *dm,