some speedup for drawing mesh in texture mode.
authorCampbell Barton <ideasman42@gmail.com>
Fri, 23 Sep 2011 18:29:45 +0000 (18:29 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Fri, 23 Sep 2011 18:29:45 +0000 (18:29 +0000)
- 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/blenkernel/BKE_DerivedMesh.h
source/blender/blenkernel/intern/DerivedMesh.c
source/blender/blenkernel/intern/cdderivedmesh.c
source/blender/blenkernel/intern/subsurf_ccg.c
source/blender/editors/space_view3d/drawmesh.c

index 6e17b056685e9d5cc789040f90f0204862b4a64b..2c3ffc296ba8512d1900c4e0b9c87ec197738add 100644 (file)
@@ -257,7 +257,7 @@ struct DerivedMesh {
         */
        void (*drawFacesTex)(DerivedMesh *dm,
                                                 int (*setDrawOptions)(struct MTFace *tface,
         */
        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
 
        /* Draw all faces with GLSL materials
         *  o setMaterial is called for every different material nr
index fddd2809c47735d06a0fd94798b115f38d32b394..5e462238f31851150261de692824bfdb8b4d0741 100644 (file)
@@ -799,7 +799,7 @@ static void emDM_drawMappedFaces(DerivedMesh *dm, int (*setDrawOptions)(void *us
 }
 
 static void emDM_drawFacesTex_common(DerivedMesh *dm,
 }
 
 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) 
 {
                           int (*drawParamsMapped)(void *userData, int index),
                           void *userData) 
 {
@@ -827,7 +827,7 @@ static void emDM_drawFacesTex_common(DerivedMesh *dm,
                        int flag;
 
                        if(drawParams)
                        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
                        else if(drawParamsMapped)
                                flag= drawParamsMapped(userData, i);
                        else
@@ -900,7 +900,7 @@ static void emDM_drawFacesTex_common(DerivedMesh *dm,
                        int flag;
 
                        if(drawParams)
                        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
                        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);
 }
 {
        emDM_drawFacesTex_common(dm, setDrawOptions, NULL, NULL);
 }
index afa310b0b801dd3212a3c2cdebc2aa5e550c02d9..707bf95f9c3d494b721282ec4b2297fc349fc0d6 100644 (file)
@@ -647,7 +647,7 @@ static void cdDM_drawFacesColored(DerivedMesh *dm, int useTwoSided, unsigned cha
 }
 
 static void cdDM_drawFacesTex_common(DerivedMesh *dm,
 }
 
 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) 
 {
                           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) {
                        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) {
                        }
                        else {
                                if(index) {
@@ -792,7 +792,7 @@ static void cdDM_drawFacesTex_common(DerivedMesh *dm,
                                int flag = 1;
 
                                if(drawParams) {
                                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) {
                                }
                                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);
 }
 {
        cdDM_drawFacesTex_common(dm, setDrawOptions, NULL, NULL);
 }
index 3626374622838b4965d047adce8ce3e51fe692fb..3d3806f7c022acabd86b0f7d01dbeedaae4dee65 100644 (file)
@@ -1583,7 +1583,7 @@ static void ccgDM_drawFacesColored(DerivedMesh *dm, int UNUSED(useTwoSided), uns
 }
 
 static void ccgDM_drawFacesTex_common(DerivedMesh *dm,
 }
 
 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) 
 {
        int (*drawParamsMapped)(void *userData, int index),
        void *userData) 
 {
@@ -1619,7 +1619,7 @@ static void ccgDM_drawFacesTex_common(DerivedMesh *dm,
                }
 
                if(drawParams)
                }
 
                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
                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);
 }
 {
        ccgDM_drawFacesTex_common(dm, setDrawOptions, NULL, NULL);
 }
index b6e76885719b0a95475159189044b205d1a3d8f5..bf4bd7f1d93fe5dccc4b3128e54565feed22cf24 100644 (file)
@@ -362,7 +362,7 @@ static void draw_textured_end(void)
        glPopMatrix();
 }
 
        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;
 {
        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 (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) {
                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 */
        }
 }
                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);
 
 {
        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 */
                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 */
                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];
        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;
        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)
 {
 }
 
 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;
        EditFace *efa= EM_get_face_for_index(index);
        MTFace *tface;
-       MCol *mcol;
        int matnr;
 
        if (efa->h)
                return 0;
 
        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;
 
        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)
 }
 
 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) {
        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)
        }
        else if(faceselect) {
                if(ob->mode & OB_MODE_WEIGHT_PAINT)