diff options
author | Nicholas Bishop <nicholasbishop@gmail.com> | 2012-03-08 10:47:05 +0400 |
---|---|---|
committer | Nicholas Bishop <nicholasbishop@gmail.com> | 2012-03-08 10:47:05 +0400 |
commit | 640b0adb9844f506ed68f99f8761a1f4daa288b0 (patch) | |
tree | 957737baac66b88d79f1f24b6d7a262dcbfc4b7e | |
parent | ee84084f990da866c15a7b24e7c5945050c4a720 (diff) |
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.
-rw-r--r-- | source/blender/blenkernel/BKE_DerivedMesh.h | 15 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/cdderivedmesh.c | 48 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/editderivedmesh.c | 53 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/subsurf_ccg.c | 33 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/drawmesh.c | 75 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/drawobject.c | 109 |
6 files changed, 190 insertions, 143 deletions
diff --git a/source/blender/blenkernel/BKE_DerivedMesh.h b/source/blender/blenkernel/BKE_DerivedMesh.h index 6b49235a0b7..199b2d751a8 100644 --- a/source/blender/blenkernel/BKE_DerivedMesh.h +++ b/source/blender/blenkernel/BKE_DerivedMesh.h @@ -124,12 +124,23 @@ typedef enum DerivedMeshType { 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, diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c index e6d37718cba..7ba9e6b9686 100644 --- a/source/blender/blenkernel/intern/cdderivedmesh.c +++ b/source/blender/blenkernel/intern/cdderivedmesh.c @@ -623,26 +623,26 @@ static void cdDM_drawFacesTex_common(DerivedMesh *dm, 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 @@ static void cdDM_drawFacesTex_common(DerivedMesh *dm, /* 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 @@ static void cdDM_drawFacesTex_common(DerivedMesh *dm, 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 @@ static void cdDM_drawMappedFaces(DerivedMesh *dm, 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 @@ static void cdDM_drawMappedFaces(DerivedMesh *dm, 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 @@ static void cdDM_drawMappedFaces(DerivedMesh *dm, 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 @@ static void cdDM_drawMappedFaces(DerivedMesh *dm, 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 @@ static void cdDM_drawMappedFacesGLSL(DerivedMesh *dm, /* continue */ } - else if(!setDrawOptions(userData, orig)) + else if(setDrawOptions(userData, orig) == DM_DRAW_OPTION_SKIP) continue; } @@ -1403,7 +1405,7 @@ static void cdDM_drawMappedEdges(DerivedMesh *dm, DMSetDrawOptions setDrawOption 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); } diff --git a/source/blender/blenkernel/intern/editderivedmesh.c b/source/blender/blenkernel/intern/editderivedmesh.c index 943f499ed1b..6912eb8dbe8 100644 --- a/source/blender/blenkernel/intern/editderivedmesh.c +++ b/source/blender/blenkernel/intern/editderivedmesh.c @@ -414,7 +414,7 @@ static void emDM_drawMappedEdges( 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 @@ static void emDM_drawMappedEdges( 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 @@ static void emDM_drawMappedEdgesInterp( 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 @@ static void emDM_drawMappedEdgesInterp( 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 @@ static void emDM_drawMappedFaces( 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 @@ static void emDM_drawMappedFaces( 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 @@ static void emDM_drawMappedFaces( } } - flush= (draw==2); + flush= (draw_option == DM_DRAW_OPTION_STIPPLE); if (!skip_normals && !flush && (i != lasttri)) flush|= efa->mat_nr != looptris[i + 1][0]->f->mat_nr; /* TODO, make this neater */ @@ -690,10 +693,12 @@ static void emDM_drawMappedFaces( 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 */ @@ -739,7 +744,7 @@ static void emDM_drawMappedFaces( } } - flush= (draw==2); + flush= (draw_option == DM_DRAW_OPTION_STIPPLE); if (!skip_normals && !flush && (i != lasttri)) { flush|= efa->mat_nr != looptris[i + 1][0]->f->mat_nr; /* TODO, make this neater */ } @@ -815,7 +820,7 @@ static void emDM_drawFacesTex_common( MTFace mtf = {{{0}}}; /*unsigned char *cp= NULL;*/ /*UNUSED*/ int drawSmooth= BM_elem_flag_test(ls[0]->f, BM_ELEM_SMOOTH); - int flag; + DMDrawOption draw_option; efa = ls[0]->f; @@ -824,13 +829,13 @@ static void emDM_drawFacesTex_common( } if (drawParams) - flag= drawParams(&mtf, has_vcol, efa->mat_nr); + draw_option= drawParams(&mtf, has_vcol, efa->mat_nr); else if (drawParamsMapped) - flag= drawParamsMapped(userData, BM_elem_index_get(efa)); + draw_option= drawParamsMapped(userData, BM_elem_index_get(efa)); else - flag= 1; + draw_option= DM_DRAW_OPTION_NORMAL; - if (flag != 0) { /* flag 0 == the face is hidden or invisible */ + if (draw_option != DM_DRAW_OPTION_SKIP) { if (!drawSmooth) { glNormal3fv(bmdm->polyNos[BM_elem_index_get(efa)]); @@ -886,7 +891,7 @@ static void emDM_drawFacesTex_common( MTFace mtf = {{{0}}}; /*unsigned char *cp= NULL;*/ /*UNUSED*/ int drawSmooth= BM_elem_flag_test(ls[0]->f, BM_ELEM_SMOOTH); - int flag; + DMDrawOption draw_option; efa = ls[0]->f; @@ -895,13 +900,13 @@ static void emDM_drawFacesTex_common( } if (drawParams) - flag= drawParams(&mtf, has_vcol, efa->mat_nr); + draw_option= drawParams(&mtf, has_vcol, efa->mat_nr); else if (drawParamsMapped) - flag= drawParamsMapped(userData, BM_elem_index_get(efa)); + draw_option= drawParamsMapped(userData, BM_elem_index_get(efa)); else - flag= 1; + draw_option= DM_DRAW_OPTION_NORMAL; - if (flag != 0) { /* flag 0 == the face is hidden or invisible */ + if (draw_option != DM_DRAW_OPTION_SKIP) { glBegin(GL_TRIANGLES); if (!drawSmooth) { @@ -1032,7 +1037,7 @@ static void emDM_drawMappedFacesGLSL( efa = ltri[0]->f; drawSmooth= BM_elem_flag_test(efa, BM_ELEM_SMOOTH); - if (setDrawOptions && !setDrawOptions(userData, BM_elem_index_get(efa))) + if (setDrawOptions && (setDrawOptions(userData, BM_elem_index_get(efa)) == DM_DRAW_OPTION_SKIP)) continue; new_matnr = efa->mat_nr + 1; diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c index 5ca2e876e28..0aee583fcf0 100644 --- a/source/blender/blenkernel/intern/subsurf_ccg.c +++ b/source/blender/blenkernel/intern/subsurf_ccg.c @@ -1689,7 +1689,8 @@ static void ccgDM_drawMappedFacesGLSL(DerivedMesh *dm, DM_vertex_attributes_from_gpu(dm, &gattribs, &attribs); } - if(!doDraw || (setDrawOptions && (origIndex != ORIGINDEX_NONE) && !setDrawOptions(userData, origIndex))) { + if(!doDraw || (setDrawOptions && (origIndex != ORIGINDEX_NONE) && + (setDrawOptions(userData, origIndex) == DM_DRAW_OPTION_SKIP))) { a += gridFaces*gridFaces*numVerts; continue; } @@ -1926,7 +1927,8 @@ static void ccgDM_drawFacesTex_common(DerivedMesh *dm, MCol *mcol = dm->getTessFaceDataArray(dm, CD_WEIGHT_MCOL); MTFace *tf = DM_get_tessface_data_layer(dm, CD_MTFACE); DMFlagMat *faceFlags = ccgdm->faceFlags; - int i, totface, flag, gridSize = ccgSubSurf_getGridSize(ss); + DMDrawOption draw_option; + int i, totface, gridSize = ccgSubSurf_getGridSize(ss); int gridFaces = gridSize - 1; (void) compareDrawOptions; @@ -1958,14 +1960,14 @@ static void ccgDM_drawFacesTex_common(DerivedMesh *dm, } if(drawParams) - flag = drawParams(tf, (mcol != NULL), mat_nr); + draw_option = drawParams(tf, (mcol != NULL), mat_nr); else if (index != ORIGINDEX_NONE) - flag= (drawParamsMapped)? drawParamsMapped(userData, index): 1; + draw_option= (drawParamsMapped)? drawParamsMapped(userData, index): DM_DRAW_OPTION_NORMAL; else - flag= GPU_enable_material(mat_nr, NULL) ? 1:0; + draw_option= GPU_enable_material(mat_nr, NULL) ? DM_DRAW_OPTION_NORMAL : DM_DRAW_OPTION_SKIP; - if (flag == 0) { /* flag 0 == the face is hidden or invisible */ + if (draw_option == DM_DRAW_OPTION_SKIP) { if(tf) tf += gridFaces*gridFaces*numVerts; if(mcol) mcol += gridFaces*gridFaces*numVerts*4; continue; @@ -1973,7 +1975,8 @@ static void ccgDM_drawFacesTex_common(DerivedMesh *dm, /* flag 1 == use vertex colors */ if(mcol) { - if(flag==1) cp= (unsigned char*)mcol; + if(draw_option != DM_DRAW_OPTION_NO_MCOL) + cp= (unsigned char*)mcol; mcol += gridFaces*gridFaces*numVerts*4; } @@ -2153,15 +2156,15 @@ static void ccgDM_drawMappedFaces(DerivedMesh *dm, } { - int draw= 1; + DMDrawOption draw_option= DM_DRAW_OPTION_NORMAL; if(index == ORIGINDEX_NONE) - draw= setMaterial(faceFlags ? faceFlags[origIndex].mat_nr + 1: 1, NULL); /* XXX, no faceFlags no material */ + draw_option= setMaterial(faceFlags ? faceFlags[origIndex].mat_nr + 1: 1, NULL); /* XXX, no faceFlags no material */ else if (setDrawOptions) - draw= setDrawOptions(userData, index); + draw_option= setDrawOptions(userData, index); - if (draw) { - if (draw==2) { + if (draw_option != DM_DRAW_OPTION_SKIP) { + if (draw_option == DM_DRAW_OPTION_STIPPLE) { glEnable(GL_POLYGON_STIPPLE); glPolygonStipple(stipple_quarttone); } @@ -2232,7 +2235,7 @@ static void ccgDM_drawMappedFaces(DerivedMesh *dm, glEnd(); } } - if (draw==2) + if (draw_option == DM_DRAW_OPTION_STIPPLE) glDisable(GL_POLYGON_STIPPLE); } } @@ -2256,7 +2259,7 @@ static void ccgDM_drawMappedEdges(DerivedMesh *dm, int index = ccgDM_getEdgeMapIndex(ss, e); glBegin(GL_LINE_STRIP); - if (index!=-1 && (!setDrawOptions || setDrawOptions(userData, index))) { + if (index!=-1 && (!setDrawOptions || (setDrawOptions(userData, index) != DM_DRAW_OPTION_SKIP))) { if (useAging && !(G.f&G_BACKBUFSEL)) { int ageCol = 255-ccgSubSurf_getEdgeAge(ss, e)*4; glColor3ub(0, ageCol>0?ageCol:0, 0); @@ -2291,7 +2294,7 @@ static void ccgDM_drawMappedEdgesInterp(DerivedMesh *dm, int index = ccgDM_getEdgeMapIndex(ss, e); glBegin(GL_LINE_STRIP); - if (index!=-1 && (!setDrawOptions || setDrawOptions(userData, index))) { + if (index!=-1 && (!setDrawOptions || (setDrawOptions(userData, index) != DM_DRAW_OPTION_SKIP))) { for (i=0; i<edgeSize; i++) { setDrawInterpOptions(userData, index, (float) i/(edgeSize-1)); diff --git a/source/blender/editors/space_view3d/drawmesh.c b/source/blender/editors/space_view3d/drawmesh.c index fabd3f92573..32f2d1bab9f 100644 --- a/source/blender/editors/space_view3d/drawmesh.c +++ b/source/blender/editors/space_view3d/drawmesh.c @@ -139,7 +139,7 @@ static EdgeHash *get_tface_mesh_marked_edge_info(Mesh *me) } -static int draw_mesh_face_select__setHiddenOpts(void *userData, int index) +static DMDrawOption draw_mesh_face_select__setHiddenOpts(void *userData, int index) { drawMeshFaceSelect_userData *data = userData; Mesh *me= data->me; @@ -147,34 +147,36 @@ static int draw_mesh_face_select__setHiddenOpts(void *userData, int index) uintptr_t flags = (intptr_t) BLI_edgehash_lookup(data->eh, med->v1, med->v2); if (me->drawflag & ME_DRAWEDGES) { - if (me->drawflag & ME_HIDDENEDGES) - return 1; + if ((me->drawflag & ME_HIDDENEDGES) || (flags & eEdge_Visible)) + return DM_DRAW_OPTION_NORMAL; else - return (flags & eEdge_Visible); + return DM_DRAW_OPTION_SKIP; } + else if(flags & eEdge_Select) + return DM_DRAW_OPTION_NORMAL; else - return (flags & eEdge_Select); + return DM_DRAW_OPTION_SKIP; } -static int draw_mesh_face_select__setSelectOpts(void *userData, int index) +static DMDrawOption draw_mesh_face_select__setSelectOpts(void *userData, int index) { drawMeshFaceSelect_userData *data = userData; MEdge *med = &data->me->medge[index]; uintptr_t flags = (intptr_t) BLI_edgehash_lookup(data->eh, med->v1, med->v2); - return flags & eEdge_Select; + return (flags & eEdge_Select) ? DM_DRAW_OPTION_NORMAL : DM_DRAW_OPTION_SKIP; } /* draws unselected */ -static int draw_mesh_face_select__drawFaceOptsInv(void *userData, int index) +static DMDrawOption draw_mesh_face_select__drawFaceOptsInv(void *userData, int index) { Mesh *me = (Mesh*)userData; MPoly *mface = &me->mpoly[index]; if (!(mface->flag&ME_HIDE) && !(mface->flag&ME_FACE_SEL)) - return 2; /* Don't set color */ + return DM_DRAW_OPTION_NO_MCOL; /* Don't set color */ else - return 0; + return DM_DRAW_OPTION_SKIP; } static void draw_mesh_face_select(RegionView3D *rv3d, Mesh *me, DerivedMesh *dm) @@ -388,22 +390,23 @@ static void draw_textured_end(void) glPopMatrix(); } -static int draw_tface__set_draw_legacy(MTFace *tface, int has_mcol, int matnr) +static DMDrawOption draw_tface__set_draw_legacy(MTFace *tface, int has_mcol, int matnr) { Material *ma= give_current_material(Gtexdraw.ob, matnr+1); int validtexture=0; - if (ma && (ma->game.flag & GEMAT_INVISIBLE)) return 0; + if (ma && (ma->game.flag & GEMAT_INVISIBLE)) + return DM_DRAW_OPTION_SKIP; validtexture = set_draw_settings_cached(0, tface, ma, Gtexdraw); if (tface && validtexture) { glColor3ub(0xFF, 0x00, 0xFF); - return 2; /* Don't set color */ + return DM_DRAW_OPTION_NO_MCOL; /* Don't set color */ } else if (ma && ma->shade_flag&MA_OBCOLOR) { glColor3ubv(Gtexdraw.obcol); - return 2; /* Don't set color */ + return DM_DRAW_OPTION_NO_MCOL; /* Don't set color */ } else if (!has_mcol) { if (tface) glColor3f(1.0, 1.0, 1.0); @@ -417,36 +420,39 @@ static int draw_tface__set_draw_legacy(MTFace *tface, int has_mcol, int matnr) } else glColor3f(1.0, 1.0, 1.0); } - return 2; /* Don't set color */ + return DM_DRAW_OPTION_NO_MCOL; /* Don't set color */ } else { - return 1; /* Set color from mcol */ + return DM_DRAW_OPTION_NORMAL; /* Set color from mcol */ } } -static int draw_mcol__set_draw_legacy(MTFace *UNUSED(tface), int has_mcol, int UNUSED(matnr)) +static DMDrawOption draw_mcol__set_draw_legacy(MTFace *UNUSED(tface), int has_mcol, int UNUSED(matnr)) { - if (has_mcol) return 1; - else return 2; + if (has_mcol) + return DM_DRAW_OPTION_NORMAL; + else + return DM_DRAW_OPTION_NO_MCOL; } -static int draw_tface__set_draw(MTFace *tface, int has_mcol, int matnr) +static DMDrawOption draw_tface__set_draw(MTFace *tface, int has_mcol, int matnr) { Material *ma= give_current_material(Gtexdraw.ob, matnr+1); if (ma && (ma->game.flag & GEMAT_INVISIBLE)) return 0; if (tface && set_draw_settings_cached(0, tface, ma, Gtexdraw)) { - return 2; /* Don't set color */ + return DM_DRAW_OPTION_NO_MCOL; /* Don't set color */ } else if (tface && tface->mode&TF_OBCOL) { - return 2; /* Don't set color */ + return DM_DRAW_OPTION_NO_MCOL; /* Don't set color */ } else if (!has_mcol) { - return 1; /* Don't set color */ + /* XXX: this return value looks wrong (and doesn't match comment) */ + return DM_DRAW_OPTION_NORMAL; /* Don't set color */ } else { - return 1; /* Set color from mcol */ + return DM_DRAW_OPTION_NORMAL; /* Set color from mcol */ } } static void add_tface_color_layer(DerivedMesh *dm) @@ -528,7 +534,7 @@ static void add_tface_color_layer(DerivedMesh *dm) CustomData_add_layer( &dm->faceData, CD_TEXTURE_MCOL, CD_ASSIGN, finalCol, dm->numTessFaceData ); } -static int draw_tface_mapped__set_draw(void *userData, int index) +static DMDrawOption draw_tface_mapped__set_draw(void *userData, int index) { Mesh *me = (Mesh *)userData; @@ -538,7 +544,7 @@ static int draw_tface_mapped__set_draw(void *userData, int index) BLI_assert(index >= 0 && index < me->totpoly); if (mpoly->flag & ME_HIDE) { - return 0; + return DM_DRAW_OPTION_SKIP; } else { MTexPoly *tpoly = (me->mtpoly) ? &me->mtpoly[index] : NULL; @@ -553,14 +559,14 @@ static int draw_tface_mapped__set_draw(void *userData, int index) } } -static int draw_em_tf_mapped__set_draw(void *userData, int index) +static DMDrawOption draw_em_tf_mapped__set_draw(void *userData, int index) { drawEMTFMapped_userData *data = userData; BMEditMesh *em = data->em; BMFace *efa= EDBM_get_face_for_index(em, index); if (efa==NULL || BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) { - return 0; + return DM_DRAW_OPTION_SKIP; } else { MTFace mtf= {{{0}}}; @@ -576,27 +582,28 @@ static int draw_em_tf_mapped__set_draw(void *userData, int index) } } -static int wpaint__setSolidDrawOptions_material(void *userData, int index) +static DMDrawOption wpaint__setSolidDrawOptions_material(void *userData, int index) { Mesh *me = (Mesh*)userData; if (me->mat && me->mpoly) { Material *ma= me->mat[me->mpoly[index].mat_nr]; if (ma && (ma->game.flag & GEMAT_INVISIBLE)) { - return 0; + return DM_DRAW_OPTION_SKIP; } } - return 1; + return DM_DRAW_OPTION_NORMAL; } /* when face select is on, use face hidden flag */ -static int wpaint__setSolidDrawOptions_facemask(void *userData, int index) +static DMDrawOption wpaint__setSolidDrawOptions_facemask(void *userData, int index) { Mesh *me = (Mesh*)userData; MPoly *mp = &me->mpoly[index]; - if (mp->flag & ME_HIDE) return 0; - return 1; + if (mp->flag & ME_HIDE) + return DM_DRAW_OPTION_SKIP; + return DM_DRAW_OPTION_NORMAL; } static void draw_mesh_text(Scene *scene, Object *ob, int glsl) diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c index aad6530f049..9dd9636a271 100644 --- a/source/blender/editors/space_view3d/drawobject.c +++ b/source/blender/editors/space_view3d/drawobject.c @@ -2375,7 +2375,7 @@ static void draw_dm_verts(BMEditMesh *em, DerivedMesh *dm, int sel, BMVert *eve_ } /* Draw edges with color set based on selection */ -static int draw_dm_edges_sel__setDrawOptions(void *userData, int index) +static DMDrawOption draw_dm_edges_sel__setDrawOptions(void *userData, int index) { BMEdge *eed; //unsigned char **cols = userData, *col; @@ -2396,14 +2396,15 @@ static int draw_dm_edges_sel__setDrawOptions(void *userData, int index) col = data->baseCol; } /* no alpha, this is used so a transparent color can disable drawing unselected edges in editmode */ - if (col[3]==0) return 0; + if (col[3]==0) + return DM_DRAW_OPTION_SKIP; glColor4ubv(col); } - return 1; + return DM_DRAW_OPTION_NORMAL; } else { - return 0; + return DM_DRAW_OPTION_SKIP; } } static void draw_dm_edges_sel(BMEditMesh *em, DerivedMesh *dm, unsigned char *baseCol, @@ -2420,19 +2421,26 @@ static void draw_dm_edges_sel(BMEditMesh *em, DerivedMesh *dm, unsigned char *ba } /* Draw edges */ -static int draw_dm_edges__setDrawOptions(void *userData, int index) +static DMDrawOption draw_dm_edges__setDrawOptions(void *userData, int index) { - return !BM_elem_flag_test(EDBM_get_edge_for_index(userData, index), BM_ELEM_HIDDEN); + if (BM_elem_flag_test(EDBM_get_edge_for_index(userData, index), BM_ELEM_HIDDEN)) + return DM_DRAW_OPTION_SKIP; + else + return DM_DRAW_OPTION_NORMAL; } + static void draw_dm_edges(BMEditMesh *em, DerivedMesh *dm) { dm->drawMappedEdges(dm, draw_dm_edges__setDrawOptions, em); } /* Draw edges with color interpolated based on selection */ -static int draw_dm_edges_sel_interp__setDrawOptions(void *userData, int index) +static DMDrawOption draw_dm_edges_sel_interp__setDrawOptions(void *userData, int index) { - return !BM_elem_flag_test(EDBM_get_edge_for_index(((void**)userData)[0], index), BM_ELEM_HIDDEN); + if (BM_elem_flag_test(EDBM_get_edge_for_index(((void**)userData)[0], index), BM_ELEM_HIDDEN)) + return DM_DRAW_OPTION_SKIP; + else + return DM_DRAW_OPTION_NORMAL; } static void draw_dm_edges_sel_interp__setDrawInterpOptions(void *userData, int index, float t) { @@ -2455,11 +2463,14 @@ static void draw_dm_edges_sel_interp(BMEditMesh *em, DerivedMesh *dm, unsigned c } /* Draw only seam edges */ -static int draw_dm_edges_seams__setDrawOptions(void *userData, int index) +static DMDrawOption draw_dm_edges_seams__setDrawOptions(void *userData, int index) { BMEdge *eed = EDBM_get_edge_for_index(userData, index); - return !BM_elem_flag_test(eed, BM_ELEM_HIDDEN) && BM_elem_flag_test(eed, BM_ELEM_SEAM); + if (!BM_elem_flag_test(eed, BM_ELEM_HIDDEN) && BM_elem_flag_test(eed, BM_ELEM_SEAM)) + return DM_DRAW_OPTION_NORMAL; + else + return DM_DRAW_OPTION_SKIP; } static void draw_dm_edges_seams(BMEditMesh *em, DerivedMesh *dm) @@ -2468,12 +2479,16 @@ static void draw_dm_edges_seams(BMEditMesh *em, DerivedMesh *dm) } /* Draw only sharp edges */ -static int draw_dm_edges_sharp__setDrawOptions(void *userData, int index) +static DMDrawOption draw_dm_edges_sharp__setDrawOptions(void *userData, int index) { BMEdge *eed = EDBM_get_edge_for_index(userData, index); - return !BM_elem_flag_test(eed, BM_ELEM_HIDDEN) && !BM_elem_flag_test(eed, BM_ELEM_SMOOTH); + if (!BM_elem_flag_test(eed, BM_ELEM_HIDDEN) && !BM_elem_flag_test(eed, BM_ELEM_SMOOTH)) + return DM_DRAW_OPTION_NORMAL; + else + return DM_DRAW_OPTION_SKIP; } + static void draw_dm_edges_sharp(BMEditMesh *em, DerivedMesh *dm) { dm->drawMappedEdges(dm, draw_dm_edges_sharp__setDrawOptions, em); @@ -2482,28 +2497,29 @@ static void draw_dm_edges_sharp(BMEditMesh *em, DerivedMesh *dm) /* Draw faces with color set based on selection * return 2 for the active face so it renders with stipple enabled */ -static int draw_dm_faces_sel__setDrawOptions(void *userData, int index) +static DMDrawOption draw_dm_faces_sel__setDrawOptions(void *userData, int index) { drawDMFacesSel_userData * data = userData; BMFace *efa = EDBM_get_face_for_index(data->em, index); unsigned char *col; if (!efa) - return 0; + return DM_DRAW_OPTION_SKIP; if (!BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) { if (efa == data->efa_act) { glColor4ubv(data->cols[2]); - return 2; /* stipple */ + return DM_DRAW_OPTION_STIPPLE; } else { col = data->cols[BM_elem_flag_test(efa, BM_ELEM_SELECT)?1:0]; - if (col[3]==0) return 0; + if (col[3]==0) + return DM_DRAW_OPTION_SKIP; glColor4ubv(col); - return 1; + return DM_DRAW_OPTION_NORMAL; } } - return 0; + return DM_DRAW_OPTION_SKIP; } static int draw_dm_faces_sel__compareDrawOptions(void *userData, int index, int next_index) @@ -2552,21 +2568,21 @@ static void draw_dm_faces_sel(BMEditMesh *em, DerivedMesh *dm, unsigned char *ba dm->drawMappedFaces(dm, draw_dm_faces_sel__setDrawOptions, GPU_enable_material, draw_dm_faces_sel__compareDrawOptions, &data, 0); } -static int draw_dm_creases__setDrawOptions(void *userData, int index) +static DMDrawOption draw_dm_creases__setDrawOptions(void *userData, int index) { BMEditMesh *em = userData; BMEdge *eed = EDBM_get_edge_for_index(userData, index); float *crease = eed ? (float *)CustomData_bmesh_get(&em->bm->edata, eed->head.data, CD_CREASE) : NULL; if (!crease) - return 0; + return DM_DRAW_OPTION_SKIP; if (!BM_elem_flag_test(eed, BM_ELEM_HIDDEN) && *crease!=0.0f) { UI_ThemeColorBlend(TH_WIRE, TH_EDGE_CREASE, *crease); - return 1; + return DM_DRAW_OPTION_NORMAL; } else { - return 0; + return DM_DRAW_OPTION_SKIP; } } static void draw_dm_creases(BMEditMesh *em, DerivedMesh *dm) @@ -2576,21 +2592,21 @@ static void draw_dm_creases(BMEditMesh *em, DerivedMesh *dm) glLineWidth(1.0); } -static int draw_dm_bweights__setDrawOptions(void *userData, int index) +static DMDrawOption draw_dm_bweights__setDrawOptions(void *userData, int index) { BMEditMesh *em = userData; BMEdge *eed = EDBM_get_edge_for_index(userData, index); float *bweight = (float *)CustomData_bmesh_get(&em->bm->edata, eed->head.data, CD_BWEIGHT); if (!bweight) - return 0; + return DM_DRAW_OPTION_SKIP; if (!BM_elem_flag_test(eed, BM_ELEM_HIDDEN) && *bweight!=0.0f) { UI_ThemeColorBlend(TH_WIRE, TH_EDGE_SELECT, *bweight); - return 1; + return DM_DRAW_OPTION_NORMAL; } else { - return 0; + return DM_DRAW_OPTION_SKIP; } } static void draw_dm_bweights__mapFunc(void *userData, int index, float *co, float *UNUSED(no_f), short *UNUSED(no_s)) @@ -2965,23 +2981,26 @@ static void draw_em_indices(BMEditMesh *em) } } -static int draw_em_fancy__setFaceOpts(void *userData, int index) +static DMDrawOption draw_em_fancy__setFaceOpts(void *userData, int index) { BMFace *efa = EDBM_get_face_for_index(userData, index); if (efa && !BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) { GPU_enable_material(efa->mat_nr+1, NULL); - return 1; + return DM_DRAW_OPTION_NORMAL; } else - return 0; + return DM_DRAW_OPTION_SKIP; } -static int draw_em_fancy__setGLSLFaceOpts(void *userData, int index) +static DMDrawOption draw_em_fancy__setGLSLFaceOpts(void *userData, int index) { BMFace *efa = EDBM_get_face_for_index(userData, index); - return !BM_elem_flag_test(efa, BM_ELEM_HIDDEN); + if (BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) + return DM_DRAW_OPTION_SKIP; + else + return DM_DRAW_OPTION_NORMAL; } static void draw_em_fancy(Scene *scene, View3D *v3d, RegionView3D *rv3d, @@ -7125,7 +7144,7 @@ static void bbs_mesh_verts(BMEditMesh *em, DerivedMesh *dm, int offset) glPointSize(1.0); } -static int bbs_mesh_wire__setDrawOptions(void *userData, int index) +static DMDrawOption bbs_mesh_wire__setDrawOptions(void *userData, int index) { void **ptrs = userData; int offset = (intptr_t) ptrs[0]; @@ -7133,10 +7152,10 @@ static int bbs_mesh_wire__setDrawOptions(void *userData, int index) if (!BM_elem_flag_test(eed, BM_ELEM_HIDDEN)) { WM_set_framebuffer_index_color(offset+index); - return 1; + return DM_DRAW_OPTION_NORMAL; } else { - return 0; + return DM_DRAW_OPTION_SKIP; } } static void bbs_mesh_wire(BMEditMesh *em, DerivedMesh *dm, int offset) @@ -7145,7 +7164,7 @@ static void bbs_mesh_wire(BMEditMesh *em, DerivedMesh *dm, int offset) dm->drawMappedEdges(dm, bbs_mesh_wire__setDrawOptions, ptrs); } -static int bbs_mesh_solid__setSolidDrawOptions(void *userData, int index) +static DMDrawOption bbs_mesh_solid__setSolidDrawOptions(void *userData, int index) { BMFace *efa = EDBM_get_face_for_index(((void**)userData)[0], index); @@ -7153,10 +7172,10 @@ static int bbs_mesh_solid__setSolidDrawOptions(void *userData, int index) if (((void**)userData)[1]) { WM_set_framebuffer_index_color(index+1); } - return 1; + return DM_DRAW_OPTION_NORMAL; } else { - return 0; + return DM_DRAW_OPTION_SKIP; } } @@ -7196,35 +7215,35 @@ static void bbs_mesh_solid_EM(BMEditMesh *em, Scene *scene, View3D *v3d, } } -static int bbs_mesh_solid__setDrawOpts(void *UNUSED(userData), int index) +static DMDrawOption bbs_mesh_solid__setDrawOpts(void *UNUSED(userData), int index) { WM_set_framebuffer_index_color(index+1); - return 1; + return DM_DRAW_OPTION_NORMAL; } -static int bbs_mesh_solid_hide__setDrawOpts(void *userData, int index) +static DMDrawOption bbs_mesh_solid_hide__setDrawOpts(void *userData, int index) { Mesh *me = userData; if (!(me->mpoly[index].flag&ME_HIDE)) { WM_set_framebuffer_index_color(index+1); - return 1; + return DM_DRAW_OPTION_NORMAL; } else { - return 0; + return DM_DRAW_OPTION_SKIP; } } // must have called WM_set_framebuffer_index_color beforehand -static int bbs_mesh_solid_hide2__setDrawOpts(void *userData, int index) +static DMDrawOption bbs_mesh_solid_hide2__setDrawOpts(void *userData, int index) { Mesh *me = userData; if (!(me->mpoly[index].flag & ME_HIDE)) { - return 1; + return DM_DRAW_OPTION_NORMAL; } else { - return 0; + return DM_DRAW_OPTION_SKIP; } } static void bbs_mesh_solid(Scene *scene, Object *ob) |