diff --git a/source/blender/blenkernel/BKE_DerivedMesh.h b/source/blender/blenkernel/BKE_DerivedMesh.h index 6e17b056685..2c3ffc296ba 100644 --- a/source/blender/blenkernel/BKE_DerivedMesh.h +++ b/source/blender/blenkernel/BKE_DerivedMesh.h @@ -257,7 +257,7 @@ struct DerivedMesh { */ void (*drawFacesTex)(DerivedMesh *dm, int (*setDrawOptions)(struct MTFace *tface, - struct MCol *mcol, int matnr)); + int has_mcol, int matnr)); /* Draw all faces with GLSL materials * o setMaterial is called for every different material nr diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index fddd2809c47..5e462238f31 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -799,7 +799,7 @@ static void emDM_drawMappedFaces(DerivedMesh *dm, int (*setDrawOptions)(void *us } static void emDM_drawFacesTex_common(DerivedMesh *dm, - int (*drawParams)(MTFace *tface, MCol *mcol, int matnr), + int (*drawParams)(MTFace *tface, int has_mcol, int matnr), int (*drawParamsMapped)(void *userData, int index), void *userData) { @@ -827,7 +827,7 @@ static void emDM_drawFacesTex_common(DerivedMesh *dm, int flag; if(drawParams) - flag= drawParams(tf, mcol, efa->mat_nr); + flag= drawParams(tf, (mcol != NULL), efa->mat_nr); else if(drawParamsMapped) flag= drawParamsMapped(userData, i); else @@ -900,7 +900,7 @@ static void emDM_drawFacesTex_common(DerivedMesh *dm, int flag; if(drawParams) - flag= drawParams(tf, mcol, efa->mat_nr); + flag= drawParams(tf, (mcol != NULL), efa->mat_nr); else if(drawParamsMapped) flag= drawParamsMapped(userData, i); else @@ -966,7 +966,7 @@ static void emDM_drawFacesTex_common(DerivedMesh *dm, } } -static void emDM_drawFacesTex(DerivedMesh *dm, int (*setDrawOptions)(MTFace *tface, MCol *mcol, int matnr)) +static void emDM_drawFacesTex(DerivedMesh *dm, int (*setDrawOptions)(MTFace *tface, int has_mcol, int matnr)) { emDM_drawFacesTex_common(dm, setDrawOptions, NULL, NULL); } diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c index afa310b0b80..707bf95f9c3 100644 --- a/source/blender/blenkernel/intern/cdderivedmesh.c +++ b/source/blender/blenkernel/intern/cdderivedmesh.c @@ -647,7 +647,7 @@ static void cdDM_drawFacesColored(DerivedMesh *dm, int useTwoSided, unsigned cha } static void cdDM_drawFacesTex_common(DerivedMesh *dm, - int (*drawParams)(MTFace *tface, MCol *mcol, int matnr), + int (*drawParams)(MTFace *tface, int has_mcol, int matnr), int (*drawParamsMapped)(void *userData, int index), void *userData) { @@ -673,7 +673,7 @@ static void cdDM_drawFacesTex_common(DerivedMesh *dm, unsigned char *cp = NULL; if(drawParams) { - flag = drawParams(tf? &tf[i]: NULL, mcol? &mcol[i*4]: NULL, mf->mat_nr); + flag = drawParams(tf? &tf[i]: NULL, (mcol != NULL), mf->mat_nr); } else { if(index) { @@ -792,7 +792,7 @@ static void cdDM_drawFacesTex_common(DerivedMesh *dm, int flag = 1; if(drawParams) { - flag = drawParams(tf? &tf[actualFace]: NULL, mcol? &mcol[actualFace*4]: NULL, mf[actualFace].mat_nr); + flag = drawParams(tf? &tf[actualFace]: NULL, (mcol != NULL), mf[actualFace].mat_nr); } else { if(index) { @@ -835,7 +835,7 @@ static void cdDM_drawFacesTex_common(DerivedMesh *dm, } } -static void cdDM_drawFacesTex(DerivedMesh *dm, int (*setDrawOptions)(MTFace *tface, MCol *mcol, int matnr)) +static void cdDM_drawFacesTex(DerivedMesh *dm, int (*setDrawOptions)(MTFace *tface, int has_mcol, int matnr)) { cdDM_drawFacesTex_common(dm, setDrawOptions, NULL, NULL); } diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c index 36263746228..3d3806f7c02 100644 --- a/source/blender/blenkernel/intern/subsurf_ccg.c +++ b/source/blender/blenkernel/intern/subsurf_ccg.c @@ -1583,7 +1583,7 @@ static void ccgDM_drawFacesColored(DerivedMesh *dm, int UNUSED(useTwoSided), uns } static void ccgDM_drawFacesTex_common(DerivedMesh *dm, - int (*drawParams)(MTFace *tface, MCol *mcol, int matnr), + int (*drawParams)(MTFace *tface, int has_mcol, int matnr), int (*drawParamsMapped)(void *userData, int index), void *userData) { @@ -1619,7 +1619,7 @@ static void ccgDM_drawFacesTex_common(DerivedMesh *dm, } if(drawParams) - flag = drawParams(tf, mcol, mat_nr); + flag = drawParams(tf, (mcol != NULL), mat_nr); else if (index != ORIGINDEX_NONE) flag= (drawParamsMapped)? drawParamsMapped(userData, index): 1; else @@ -1722,7 +1722,7 @@ static void ccgDM_drawFacesTex_common(DerivedMesh *dm, } } -static void ccgDM_drawFacesTex(DerivedMesh *dm, int (*setDrawOptions)(MTFace *tface, MCol *mcol, int matnr)) +static void ccgDM_drawFacesTex(DerivedMesh *dm, int (*setDrawOptions)(MTFace *tface, int has_mcol, int matnr)) { ccgDM_drawFacesTex_common(dm, setDrawOptions, NULL, NULL); } diff --git a/source/blender/editors/space_view3d/drawmesh.c b/source/blender/editors/space_view3d/drawmesh.c index b6e76885719..bf4bd7f1d93 100644 --- a/source/blender/editors/space_view3d/drawmesh.c +++ b/source/blender/editors/space_view3d/drawmesh.c @@ -362,7 +362,7 @@ static void draw_textured_end(void) glPopMatrix(); } -static int draw_tface__set_draw_legacy(MTFace *tface, MCol *mcol, int matnr) +static int draw_tface__set_draw_legacy(MTFace *tface, int has_mcol, int matnr) { Material *ma= give_current_material(Gtexdraw.ob, matnr+1); int validtexture=0; @@ -377,7 +377,7 @@ static int draw_tface__set_draw_legacy(MTFace *tface, MCol *mcol, int matnr) } else if (ma && ma->shade_flag&MA_OBCOLOR) { glColor3ubv(Gtexdraw.obcol); return 2; /* Don't set color */ - } else if (!mcol) { + } else if (!has_mcol) { if (tface) glColor3f(1.0, 1.0, 1.0); else { if(ma) { @@ -394,7 +394,7 @@ static int draw_tface__set_draw_legacy(MTFace *tface, MCol *mcol, int matnr) return 1; /* Set color from mcol */ } } -static int draw_tface__set_draw(MTFace *tface, MCol *mcol, int matnr) +static int draw_tface__set_draw(MTFace *tface, int has_mcol, int matnr) { Material *ma= give_current_material(Gtexdraw.ob, matnr+1); @@ -404,7 +404,7 @@ static int draw_tface__set_draw(MTFace *tface, MCol *mcol, int matnr) return 2; /* Don't set color */ } else if (tface && tface->mode&TF_OBCOL) { return 2; /* Don't set color */ - } else if (!mcol) { + } else if (!has_mcol) { return 1; /* Don't set color */ } else { return 1; /* Set color from mcol */ @@ -491,28 +491,26 @@ static int draw_tface_mapped__set_draw(void *userData, int index) Mesh *me = (Mesh*)userData; MTFace *tface = (me->mtface)? &me->mtface[index]: NULL; MFace *mface = &me->mface[index]; - MCol *mcol = (me->mcol)? &me->mcol[index]: NULL; const int matnr = mface->mat_nr; if (mface->flag & ME_HIDE) return 0; - return draw_tface__set_draw(tface, mcol, matnr); + return draw_tface__set_draw(tface, (me->mcol != NULL), matnr); } static int draw_em_tf_mapped__set_draw(void *userData, int index) { - EditMesh *em = userData; + struct {EditMesh *em; short has_mcol; short has_mtface;} *data = userData; + EditMesh *em = data->em; EditFace *efa= EM_get_face_for_index(index); MTFace *tface; - MCol *mcol; int matnr; if (efa->h) return 0; - tface = CustomData_em_get(&em->fdata, efa->data, CD_MTFACE); - mcol = CustomData_em_get(&em->fdata, efa->data, CD_MCOL); + tface = data->has_mtface ? CustomData_em_get(&em->fdata, efa->data, CD_MTFACE) : NULL; matnr = efa->mat_nr; - return draw_tface__set_draw_legacy(tface, mcol, matnr); + return draw_tface__set_draw_legacy(tface, data->has_mcol, matnr); } static int wpaint__setSolidDrawOptions(void *userData, int index, int *drawSmooth_r) @@ -632,7 +630,13 @@ void draw_mesh_textured(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *o glColor4f(1.0f,1.0f,1.0f,1.0f); if(ob->mode & OB_MODE_EDIT) { - dm->drawMappedFacesTex(dm, draw_em_tf_mapped__set_draw, me->edit_mesh); + struct {EditMesh *em; short has_mcol; short has_mtface;} data; + + data.em= me->edit_mesh; + data.has_mcol= CustomData_has_layer(&me->edit_mesh->fdata, CD_MCOL); + data.has_mtface= CustomData_has_layer(&me->edit_mesh->fdata, CD_MTFACE); + + dm->drawMappedFacesTex(dm, draw_em_tf_mapped__set_draw, &data); } else if(faceselect) { if(ob->mode & OB_MODE_WEIGHT_PAINT)