Revision: 44731
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=44731
Author:   nicholasbishop
Date:     2012-03-08 06:47:05 +0000 (Thu, 08 Mar 2012)
Log Message:
-----------
Code cleanup: use named values for options in DerivedMesh drawing.

The DMSetDrawOptions[Tex] callbacks return 0 (skip), 1 (draw), or 2
(either stipple or skip mcols.) In the CDDM, EDDM, and CCGDM draw
functions, as well as the callbacks in drawmesh/drawobject, replace
these numbers with values from an enum, DMDrawOptions.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_DerivedMesh.h
    trunk/blender/source/blender/blenkernel/intern/cdderivedmesh.c
    trunk/blender/source/blender/blenkernel/intern/editderivedmesh.c
    trunk/blender/source/blender/blenkernel/intern/subsurf_ccg.c
    trunk/blender/source/blender/editors/space_view3d/drawmesh.c
    trunk/blender/source/blender/editors/space_view3d/drawobject.c

Modified: trunk/blender/source/blender/blenkernel/BKE_DerivedMesh.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_DerivedMesh.h   2012-03-08 
05:36:05 UTC (rev 44730)
+++ trunk/blender/source/blender/blenkernel/BKE_DerivedMesh.h   2012-03-08 
06:47:05 UTC (rev 44731)
@@ -124,12 +124,23 @@
        DM_TYPE_CCGDM
 } DerivedMeshType;
 
+typedef enum DMDrawOption {
+       /* the element is hidden or otherwise non-drawable */
+       DM_DRAW_OPTION_SKIP = 0,
+       /* normal drawing */
+       DM_DRAW_OPTION_NORMAL = 1,
+       /* draw, but don't set the color from mcol */
+       DM_DRAW_OPTION_NO_MCOL = 2,
+       /* used in drawMappedFaces, use GL stipple for the face */
+       DM_DRAW_OPTION_STIPPLE = 3,
+} DMDrawOption;
+
 /* Drawing callback types */
 typedef int (*DMSetMaterial)(int mat_nr, void *attribs);
 typedef int (*DMCompareDrawOptions)(void *userData, int cur_index, int 
next_index);
 typedef void (*DMSetDrawInterpOptions)(void *userData, int index, float t);
-typedef int (*DMSetDrawOptions)(void *userData, int index);
-typedef int (*DMSetDrawOptionsTex)(struct MTFace *tface, int has_vcol, int 
matnr);
+typedef DMDrawOption (*DMSetDrawOptions)(void *userData, int index);
+typedef DMDrawOption (*DMSetDrawOptionsTex)(struct MTFace *tface, int 
has_vcol, int matnr);
 
 typedef enum DMDrawFlag {
        DM_DRAW_USE_COLORS = 1,

Modified: trunk/blender/source/blender/blenkernel/intern/cdderivedmesh.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/cdderivedmesh.c      
2012-03-08 05:36:05 UTC (rev 44730)
+++ trunk/blender/source/blender/blenkernel/intern/cdderivedmesh.c      
2012-03-08 06:47:05 UTC (rev 44731)
@@ -623,26 +623,26 @@
                DEBUG_VBO( "Using legacy code. cdDM_drawFacesTex_common\n" );
                for(i = 0; i < dm->numTessFaceData; i++, mf++) {
                        MVert *mvert;
-                       int flag;
+                       DMDrawOption draw_option;
                        unsigned char *cp = NULL;
 
                        if(drawParams) {
-                               flag = drawParams(tf? &tf[i]: NULL, (mcol != 
NULL), mf->mat_nr);
+                               draw_option = drawParams(tf? &tf[i]: NULL, 
(mcol != NULL), mf->mat_nr);
                        }
                        else {
                                if(index) {
                                        orig = *index++;
                                        if(orig == ORIGINDEX_NONE)              
{ if(nors) nors += 3; continue; }
-                                       if(drawParamsMapped) flag = 
drawParamsMapped(userData, orig);
+                                       if(drawParamsMapped) draw_option = 
drawParamsMapped(userData, orig);
                                        else    { if(nors) nors += 3; continue; 
}
                                }
                                else
-                                       if(drawParamsMapped) flag = 
drawParamsMapped(userData, i);
+                                       if(drawParamsMapped) draw_option = 
drawParamsMapped(userData, i);
                                        else    { if(nors) nors += 3; continue; 
}
                        }
                        
-                       if(flag != 0) {
-                               if (flag==1 && mcol)
+                       if(draw_option != DM_DRAW_OPTION_SKIP) {
+                               if (draw_option != DM_DRAW_OPTION_NO_MCOL && 
mcol)
                                        cp= (unsigned char*) &mcol[i*4];
 
                                if(!(mf->flag&ME_SMOOTH)) {
@@ -734,29 +734,29 @@
                        /* lastFlag = 0; */ /* UNUSED */
                        for(i = 0; i < tottri; i++) {
                                int actualFace = next_actualFace;
-                               int flag = 1;
+                               DMDrawOption draw_option = 
DM_DRAW_OPTION_NORMAL;
                                int flush = 0;
 
                                if(i != tottri-1)
                                        next_actualFace= 
dm->drawObject->triangle_to_mface[i+1];
 
                                if(drawParams) {
-                                       flag = drawParams(tf? &tf[actualFace]: 
NULL, (mcol != NULL), mf[actualFace].mat_nr);
+                                       draw_option = drawParams(tf? 
&tf[actualFace]: NULL, (mcol != NULL), mf[actualFace].mat_nr);
                                }
                                else {
                                        if(index) {
                                                orig = index[actualFace];
                                                if(orig == ORIGINDEX_NONE) 
continue;
                                                if(drawParamsMapped)
-                                                       flag = 
drawParamsMapped(userData, orig);
+                                                       draw_option = 
drawParamsMapped(userData, orig);
                                        }
                                        else
                                                if(drawParamsMapped)
-                                                       flag = 
drawParamsMapped(userData, actualFace);
+                                                       draw_option = 
drawParamsMapped(userData, actualFace);
                                }
 
                                /* flush buffer if current triangle isn't 
drawable or it's last triangle */
-                               flush= !flag || i == tottri - 1;
+                               flush= (draw_option == DM_DRAW_OPTION_SKIP) || 
(i == tottri - 1);
 
                                if(!flush && compareDrawOptions) {
                                        /* also compare draw options and flush 
buffer if they're different
@@ -766,7 +766,8 @@
 
                                if(flush) {
                                        int first= startFace*3;
-                                       int count= (i-startFace+(flag ? 1 : 
0))*3; /* Add one to the length if we're drawing at the end of the array */
+                                       /* Add one to the length if we're 
drawing at the end of the array */
+                                       int count= (i-startFace+(draw_option != 
DM_DRAW_OPTION_SKIP ? 1 : 0))*3;
 
                                        if(count) {
                                                if (col)
@@ -823,16 +824,16 @@
                DEBUG_VBO( "Using legacy code. cdDM_drawMappedFaces\n" );
                for(i = 0; i < dm->numTessFaceData; i++, mf++) {
                        int drawSmooth = (flag & DM_DRAW_ALWAYS_SMOOTH) ? 1 : 
(mf->flag & ME_SMOOTH);
-                       int draw= 1;
+                       DMDrawOption draw_option= DM_DRAW_OPTION_NORMAL;
 
                        orig= (index==NULL) ? i : *index++;
                        
                        if(orig == ORIGINDEX_NONE)
-                               draw= setMaterial(mf->mat_nr + 1, NULL);
+                               draw_option= setMaterial(mf->mat_nr + 1, NULL);
                        else if (setDrawOptions != NULL)
-                               draw= setDrawOptions(userData, orig);
+                               draw_option= setDrawOptions(userData, orig);
 
-                       if(draw) {
+                       if(draw_option != DM_DRAW_OPTION_SKIP) {
                                unsigned char *cp = NULL;
 
                                if(useColors && mc)
@@ -916,7 +917,7 @@
                                        int actualFace = next_actualFace;
                                        MFace *mface= mf + actualFace;
                                        /*int drawSmooth= (flag & 
DM_DRAW_ALWAYS_SMOOTH) ? 1 : (mface->flag & ME_SMOOTH);*/ /* UNUSED */
-                                       int draw = 1;
+                                       DMDrawOption draw_option = 
DM_DRAW_OPTION_NORMAL;
                                        int flush = 0;
 
                                        if(i != tottri-1)
@@ -925,16 +926,16 @@
                                        orig= (index==NULL) ? actualFace : 
index[actualFace];
 
                                        if(orig == ORIGINDEX_NONE)
-                                               draw= setMaterial(mface->mat_nr 
+ 1, NULL);
+                                               draw_option= 
setMaterial(mface->mat_nr + 1, NULL);
                                        else if (setDrawOptions != NULL)
-                                               draw= setDrawOptions(userData, 
orig);
+                                               draw_option= 
setDrawOptions(userData, orig);
        
                                        /* 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 */
 
                                        /* flush buffer if current triangle 
isn't drawable or it's last triangle... */
-                                       flush= !draw || i == tottri - 1;
+                                       flush= (draw_option == 
DM_DRAW_OPTION_SKIP) || (i == tottri - 1);
 
                                        /* ... or when material setting is 
dissferent  */
                                        flush|= mf[actualFace].mat_nr != 
mf[next_actualFace].mat_nr;
@@ -945,7 +946,8 @@
 
                                        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 */
+                                               /* Add one to the length if 
we're drawing at the end of the array */
+                                               int count= 
(i-prevstart+(draw_option != DM_DRAW_OPTION_SKIP ? 1 : 0))*3;
 
                                                if(count)
                                                        
glDrawArrays(GL_TRIANGLES, first, count);
@@ -1067,7 +1069,7 @@
                                        
                                        /* continue */
                                }
-                               else if(!setDrawOptions(userData, orig))
+                               else if(setDrawOptions(userData, orig) == 
DM_DRAW_OPTION_SKIP)
                                        continue;
                        }
 
@@ -1403,7 +1405,7 @@
                else
                        orig = i;
 
-               if(!setDrawOptions || setDrawOptions(userData, orig)) {
+               if(!setDrawOptions || (setDrawOptions(userData, orig) != 
DM_DRAW_OPTION_SKIP)) {
                        glVertex3fv(vert[edge->v1].co);
                        glVertex3fv(vert[edge->v2].co);
                }

Modified: trunk/blender/source/blender/blenkernel/intern/editderivedmesh.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/editderivedmesh.c    
2012-03-08 05:36:05 UTC (rev 44730)
+++ trunk/blender/source/blender/blenkernel/intern/editderivedmesh.c    
2012-03-08 06:47:05 UTC (rev 44731)
@@ -414,7 +414,7 @@
                glBegin(GL_LINES);
                eed = BM_iter_new(&iter, bmdm->tc->bm, BM_EDGES_OF_MESH, NULL);
                for (i=0; eed; i++,eed=BM_iter_step(&iter)) {
-                       if (!setDrawOptions || setDrawOptions(userData, i)) {
+                       if (!setDrawOptions || (setDrawOptions(userData, i) != 
DM_DRAW_OPTION_SKIP)) {
                                
glVertex3fv(bmdm->vertexCos[BM_elem_index_get(eed->v1)]);
                                
glVertex3fv(bmdm->vertexCos[BM_elem_index_get(eed->v2)]);
                        }
@@ -425,7 +425,7 @@
                glBegin(GL_LINES);
                eed = BM_iter_new(&iter, bmdm->tc->bm, BM_EDGES_OF_MESH, NULL);
                for (i=0; eed; i++,eed=BM_iter_step(&iter)) {
-                       if (!setDrawOptions || setDrawOptions(userData, i)) {
+                       if (!setDrawOptions || (setDrawOptions(userData, i) != 
DM_DRAW_OPTION_SKIP)) {
                                glVertex3fv(eed->v1->co);
                                glVertex3fv(eed->v2->co);
                        }
@@ -459,7 +459,7 @@
                glBegin(GL_LINES);
                eed = BM_iter_new(&iter, bmdm->tc->bm, BM_EDGES_OF_MESH, NULL);
                for (i=0; eed; i++,eed=BM_iter_step(&iter)) {
-                       if (!setDrawOptions || setDrawOptions(userData, i)) {
+                       if (!setDrawOptions || (setDrawOptions(userData, i) != 
DM_DRAW_OPTION_SKIP)) {
                                setDrawInterpOptions(userData, i, 0.0);
                                
glVertex3fv(bmdm->vertexCos[BM_elem_index_get(eed->v1)]);
                                setDrawInterpOptions(userData, i, 1.0);
@@ -472,7 +472,7 @@
                glBegin(GL_LINES);
                eed = BM_iter_new(&iter, bmdm->tc->bm, BM_EDGES_OF_MESH, NULL);
                for (i=0; eed; i++,eed=BM_iter_step(&iter)) {
-                       if (!setDrawOptions || setDrawOptions(userData, i)) {
+                       if (!setDrawOptions || (setDrawOptions(userData, i) != 
DM_DRAW_OPTION_SKIP)) {
                                setDrawInterpOptions(userData, i, 0.0);
                                glVertex3fv(eed->v1->co);
                                setDrawInterpOptions(userData, i, 1.0);
@@ -590,7 +590,8 @@
        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;
+       DMDrawOption draw_option;
+       int i, 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 */
@@ -618,10 +619,12 @@
                        efa = l[0]->f;
                        drawSmooth= (flag & DM_DRAW_ALWAYS_SMOOTH) ? 1 : 
BM_elem_flag_test(efa, BM_ELEM_SMOOTH);
 
-                       draw = setDrawOptions==NULL ? 1 : 
setDrawOptions(userData, BM_elem_index_get(efa));
-                       if (draw) {
+                       draw_option = (!setDrawOptions ?
+                                                  DM_DRAW_OPTION_NORMAL :
+                                                  setDrawOptions(userData, 
BM_elem_index_get(efa)));
+                       if (draw_option != DM_DRAW_OPTION_SKIP) {
                                const GLenum poly_type= GL_TRIANGLES; /* BMESH 
NOTE, this is odd but keep it for now to match trunk */
-                               if (draw==2) { /* enabled with stipple */
+                               if (draw_option == DM_DRAW_OPTION_STIPPLE) { /* 
enabled with stipple */
 
                                        if (poly_prev != GL_ZERO) glEnd();
                                        poly_prev= GL_ZERO; /* force glBegin */
@@ -667,7 +670,7 @@
                                        }
                                }
 
-                               flush= (draw==2);

@@ Diff output truncated at 10240 characters. @@
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to