From a189b71a28d3eddc6b85948ab1063be0a032cde4 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 23 Sep 2011 18:29:45 +0000 Subject: some speedup for drawing mesh in texture mode. - only pass if the mesh has vertex colors to drawParams() rather then the mcol its self, this saves a lookup on the color. - drawing textures in editmode with no vertex colors would still lookup vertex colors on each face, instead cache this info for all faces. --- source/blender/editors/space_view3d/drawmesh.c | 28 +++++++++++++++----------- 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'source/blender/editors/space_view3d/drawmesh.c') 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) -- cgit v1.2.3