Code cleanup: use typedefs for DerivedMesh drawing callbacks.
authorNicholas Bishop <nicholasbishop@gmail.com>
Wed, 7 Mar 2012 04:41:14 +0000 (04:41 +0000)
committerNicholas Bishop <nicholasbishop@gmail.com>
Wed, 7 Mar 2012 04:41:14 +0000 (04:41 +0000)
There are still fairly bewildering set of callbacks being tossed
around, but it's at least a little less verbose now.

source/blender/blenkernel/BKE_DerivedMesh.h
source/blender/blenkernel/intern/cdderivedmesh.c
source/blender/blenkernel/intern/editderivedmesh.c
source/blender/blenkernel/intern/subsurf_ccg.c
source/blender/blenlib/intern/pbvh.c
source/blender/gpu/GPU_buffers.h
source/blender/gpu/intern/gpu_buffers.c

index 8c03624dbf7edadd63af9279cf5934455087ce9e..3fb245ff0fa5f531fb348fb5c07d36d853725589 100644 (file)
@@ -124,6 +124,14 @@ typedef enum DerivedMeshType {
        DM_TYPE_CCGDM
 } DerivedMeshType;
 
+/* 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 int (*DMSetDrawOptionsShading)(void *userData, int index, int *drawSmooth_r);
+
 typedef struct DerivedMesh DerivedMesh;
 struct DerivedMesh {
        /* Private DerivedMesh data, only for internal DerivedMesh use */
@@ -308,25 +316,21 @@ struct DerivedMesh {
         * Also called for *final* editmode DerivedMeshes
         */
        void (*drawFacesSolid)(DerivedMesh *dm, float (*partial_redraw_planes)[4],
-                                                  int fast, int (*setMaterial)(int, void *attribs));
+                                                  int fast, DMSetMaterial setMaterial);
 
        /* Draw all faces using MTFace 
         *  o Drawing options too complicated to enumerate, look at code.
         */
        void (*drawFacesTex)(DerivedMesh *dm,
-                            int (*setDrawOptions)(struct MTFace *tface,
-                            int has_vcol, int matnr),
-                                               int (*compareDrawOptions)(void *userData,
-                                                        int cur_index,
-                                                        int next_index),
-                                               void *userData);
+                            DMSetDrawOptionsTex setDrawOptions,
+                                                DMCompareDrawOptions compareDrawOptions,
+                                                void *userData);
 
        /* Draw all faces with GLSL materials
         *  o setMaterial is called for every different material nr
         *  o Only if setMaterial returns true
         */
-       void (*drawFacesGLSL)(DerivedMesh *dm,
-               int (*setMaterial)(int, void *attribs));
+       void (*drawFacesGLSL)(DerivedMesh *dm, DMSetMaterial setMaterial);
 
        /* Draw mapped faces (no color, or texture)
         *  o Only if !setDrawOptions or
@@ -342,23 +346,17 @@ struct DerivedMesh {
         * smooth shaded.
         */
        void (*drawMappedFaces)(DerivedMesh *dm,
-                                                       int (*setDrawOptions)(void *userData, int index,
-                                                                                                 int *drawSmooth_r),
-                                                       int (*setMaterial)(int, void *attribs),
-                                                       int (*compareDrawOptions)(void *userData,
-                                                                                 int cur_index,
-                                                                                 int next_index),
+                                                       DMSetDrawOptionsShading setDrawOptions,
+                                                       DMSetMaterial setMaterial,
+                                                       DMCompareDrawOptions compareDrawOptions,
                                                        void *userData, int useColors);
 
        /* Draw mapped faces using MTFace 
         *  o Drawing options too complicated to enumerate, look at code.
         */
        void (*drawMappedFacesTex)(DerivedMesh *dm,
-                                                          int (*setDrawOptions)(void *userData,
-                                                                                                        int index),
-                                                          int (*compareDrawOptions)(void *userData,
-                                                                                    int cur_index,
-                                                                                    int next_index),
+                                                          DMSetDrawOptions setDrawOptions,
+                                                          DMCompareDrawOptions compareDrawOptions,
                                                           void *userData);
 
        /* Draw mapped faces with GLSL materials
@@ -367,8 +365,8 @@ struct DerivedMesh {
         *  o Only if setMaterial and setDrawOptions return true
         */
        void (*drawMappedFacesGLSL)(DerivedMesh *dm,
-               int (*setMaterial)(int, void *attribs),
-               int (*setDrawOptions)(void *userData, int index),
+               DMSetMaterial setMaterial,
+               DMSetDrawOptions setDrawOptions,
                void *userData);
 
        /* Draw mapped edges as lines
@@ -376,7 +374,7 @@ struct DerivedMesh {
         *    returns true
         */
        void (*drawMappedEdges)(DerivedMesh *dm,
-                                                       int (*setDrawOptions)(void *userData, int index),
+                                                       DMSetDrawOptions setDrawOptions,
                                                        void *userData);
 
        /* Draw mapped edges as lines with interpolation values
@@ -387,11 +385,8 @@ struct DerivedMesh {
         * NOTE: This routine is optional!
         */
        void (*drawMappedEdgesInterp)(DerivedMesh *dm, 
-                                                                 int (*setDrawOptions)(void *userData,
-                                                                                                               int index), 
-                                                                 void (*setDrawInterpOptions)(void *userData,
-                                                                                                                          int index,
-                                                                                                                          float t),
+                                                                 DMSetDrawOptions setDrawOptions,
+                                                                 DMSetDrawInterpOptions setDrawInterpOptions,
                                                                  void *userData);
 
        /* Draw all faces with materials
index 25f7841420493456190ff76c35ef689ac5458a07..6b3b11fe0b965be1e2922062a41c8a066361daba 100644 (file)
@@ -505,7 +505,7 @@ static void cdDM_drawLooseEdges(DerivedMesh *dm)
 
 static void cdDM_drawFacesSolid(DerivedMesh *dm,
                                float (*partial_redraw_planes)[4],
-                               int UNUSED(fast), int (*setMaterial)(int, void *attribs))
+                               int UNUSED(fast), DMSetMaterial setMaterial)
 {
        CDDerivedMesh *cddm = (CDDerivedMesh*) dm;
        MVert *mvert = cddm->mvert;
@@ -600,9 +600,9 @@ static void cdDM_drawFacesSolid(DerivedMesh *dm,
 }
 
 static void cdDM_drawFacesTex_common(DerivedMesh *dm,
-                          int (*drawParams)(MTFace *tface, int has_mcol, int matnr),
-                          int (*drawParamsMapped)(void *userData, int index),
-                          int (*compareDrawOptions)(void *userData, int cur_index, int next_index),
+                          DMSetDrawOptionsTex drawParams,
+                          DMSetDrawOptions drawParamsMapped,
+                          DMCompareDrawOptions compareDrawOptions,
                           void *userData) 
 {
        CDDerivedMesh *cddm = (CDDerivedMesh*) dm;
@@ -788,17 +788,17 @@ static void cdDM_drawFacesTex_common(DerivedMesh *dm,
 }
 
 static void cdDM_drawFacesTex(DerivedMesh *dm,
-                          int (*setDrawOptions)(MTFace *tface, int has_mcol, int matnr),
-                          int (*compareDrawOptions)(void *userData, int cur_index, int next_index),
+                          DMSetDrawOptionsTex setDrawOptions,
+                          DMCompareDrawOptions compareDrawOptions,
                           void *userData)
 {
        cdDM_drawFacesTex_common(dm, setDrawOptions, NULL, compareDrawOptions, userData);
 }
 
 static void cdDM_drawMappedFaces(DerivedMesh *dm,
-                       int (*setDrawOptions)(void *userData, int index, int *drawSmooth_r),
-                       int (*setMaterial)(int, void *attribs),
-                       int (*compareDrawOptions)(void *userData, int cur_index, int next_index),
+                       DMSetDrawOptionsShading setDrawOptions,
+                       DMSetMaterial setMaterial,
+                       DMCompareDrawOptions compareDrawOptions,
                        void *userData, int useColors)
 {
        CDDerivedMesh *cddm = (CDDerivedMesh*) dm;
@@ -961,8 +961,8 @@ static void cdDM_drawMappedFaces(DerivedMesh *dm,
 }
 
 static void cdDM_drawMappedFacesTex(DerivedMesh *dm,
-                          int (*setDrawOptions)(void *userData, int index),
-                          int (*compareDrawOptions)(void *userData, int cur_index, int next_index),
+                          DMSetDrawOptions setDrawOptions,
+                          DMCompareDrawOptions compareDrawOptions,
                           void *userData)
 {
        cdDM_drawFacesTex_common(dm, NULL, setDrawOptions, compareDrawOptions, userData);
@@ -1013,8 +1013,8 @@ static void cddm_draw_attrib_vertex(DMVertexAttribs *attribs, MVert *mvert, int
 }
 
 static void cdDM_drawMappedFacesGLSL(DerivedMesh *dm,
-                          int (*setMaterial)(int, void *attribs),
-                          int (*setDrawOptions)(void *userData, int index),
+                          DMSetMaterial setMaterial,
+                          DMSetDrawOptions setDrawOptions,
                           void *userData)
 {
        CDDerivedMesh *cddm = (CDDerivedMesh*) dm;
@@ -1302,7 +1302,7 @@ static void cdDM_drawMappedFacesGLSL(DerivedMesh *dm,
        glShadeModel(GL_FLAT);
 }
 
-static void cdDM_drawFacesGLSL(DerivedMesh *dm,int (*setMaterial)(int, void *attribs))
+static void cdDM_drawFacesGLSL(DerivedMesh *dm, DMSetMaterial setMaterial)
 {
        dm->drawMappedFacesGLSL(dm, setMaterial, NULL, NULL);
 }
@@ -1386,7 +1386,7 @@ static void cdDM_drawMappedFacesMat(DerivedMesh *dm,
        glShadeModel(GL_FLAT);
 }
 
-static void cdDM_drawMappedEdges(DerivedMesh *dm, int (*setDrawOptions)(void *userData, int index), void *userData)
+static void cdDM_drawMappedEdges(DerivedMesh *dm, DMSetDrawOptions setDrawOptions, void *userData)
 {
        CDDerivedMesh *cddm = (CDDerivedMesh*) dm;
        MVert *vert = cddm->mvert;
index 717f6d5e9fa7ab70868a24466770159c07a58034..ae52322a0c56fddbd9180595f0ce12ef31be1b15 100644 (file)
@@ -399,7 +399,7 @@ static void emDM_foreachMappedEdge(
 
 static void emDM_drawMappedEdges(
                DerivedMesh *dm,
-               int (*setDrawOptions)(void *userData, int index),
+               DMSetDrawOptions setDrawOptions,
                void *userData)
 {
        EditDerivedBMesh *bmdm= (EditDerivedBMesh*) dm;
@@ -443,8 +443,8 @@ static void emDM_drawEdges(
 
 static void emDM_drawMappedEdgesInterp(
                DerivedMesh *dm,
-               int (*setDrawOptions)(void *userData, int index),
-               void (*setDrawInterpOptions)(void *userData, int index, float t),
+               DMSetDrawOptions setDrawOptions,
+               DMSetDrawInterpOptions setDrawInterpOptions,
                void *userData)
 {
        EditDerivedBMesh *bmdm= (EditDerivedBMesh*) dm;
@@ -579,9 +579,9 @@ static void emDM_foreachMappedFaceCenter(
 
 static void emDM_drawMappedFaces(
                DerivedMesh *dm,
-               int (*setDrawOptions)(void *userData, int index, int *drawSmooth_r),
-               int (*setMaterial)(int, void *attribs),
-               int (*compareDrawOptions)(void *userData, int cur_index, int next_index),
+               DMSetDrawOptionsShading setDrawOptions,
+               DMSetMaterial setMaterial,
+               DMCompareDrawOptions compareDrawOptions,
                void *userData, int UNUSED(useColors))
 {
        EditDerivedBMesh *bmdm= (EditDerivedBMesh*) dm;
@@ -777,9 +777,9 @@ static void bmdm_get_tri_tex(BMesh *bm, BMLoop **ls, MLoopUV *luv[3], MLoopCol *
 
 static void emDM_drawFacesTex_common(
                DerivedMesh *dm,
-               int (*drawParams)(MTFace *tface, int has_vcol, int matnr),
-               int (*drawParamsMapped)(void *userData, int index),
-               int (*compareDrawOptions)(void *userData, int cur_index, int next_index),
+               DMSetDrawOptionsTex drawParams,
+               DMSetDrawOptions drawParamsMapped,
+               DMCompareDrawOptions compareDrawOptions,
                void *userData)
 {
        EditDerivedBMesh *bmdm= (EditDerivedBMesh*) dm;
@@ -960,8 +960,8 @@ static void emDM_drawFacesTex_common(
 
 static void emDM_drawFacesTex(
                DerivedMesh *dm,
-               int (*setDrawOptions)(MTFace *tface, int has_vcol, int matnr),
-               int (*compareDrawOptions)(void *userData, int cur_index, int next_index),
+               DMSetDrawOptionsTex setDrawOptions,
+               DMCompareDrawOptions compareDrawOptions,
                void *userData)
 {
        emDM_drawFacesTex_common(dm, setDrawOptions, NULL, compareDrawOptions, userData);
@@ -969,8 +969,8 @@ static void emDM_drawFacesTex(
 
 static void emDM_drawMappedFacesTex(
                DerivedMesh *dm,
-               int (*setDrawOptions)(void *userData, int index),
-               int (*compareDrawOptions)(void *userData, int cur_index, int next_index),
+               DMSetDrawOptions setDrawOptions,
+               DMCompareDrawOptions compareDrawOptions,
                void *userData)
 {
        emDM_drawFacesTex_common(dm, NULL, setDrawOptions, compareDrawOptions, userData);
@@ -978,8 +978,8 @@ static void emDM_drawMappedFacesTex(
 
 static void emDM_drawMappedFacesGLSL(
                DerivedMesh *dm,
-               int (*setMaterial)(int, void *attribs),
-               int (*setDrawOptions)(void *userData, int index),
+               DMSetMaterial setMaterial,
+               DMSetDrawOptions setDrawOptions,
                void *userData)
 {
        EditDerivedBMesh *bmdm= (EditDerivedBMesh*) dm;
index d60793d193fb914ee9acd859697ca98cdff46b76..8edd6362d50666cc727959a63142f48e9285233c 100644 (file)
@@ -1534,7 +1534,7 @@ static void ccgDM_glNormalFast(float *a, float *b, float *c, float *d)
 }
 
        /* Only used by non-editmesh types */
-static void ccgDM_drawFacesSolid(DerivedMesh *dm, float (*partial_redraw_planes)[4], int fast, int (*setMaterial)(int, void *attribs))
+static void ccgDM_drawFacesSolid(DerivedMesh *dm, float (*partial_redraw_planes)[4], int fast, DMSetMaterial setMaterial)
 {
        CCGDerivedMesh *ccgdm = (CCGDerivedMesh*) dm;
        CCGSubSurf *ss = ccgdm->ss;
@@ -1624,8 +1624,8 @@ static void ccgDM_drawFacesSolid(DerivedMesh *dm, float (*partial_redraw_planes)
 
        /* Only used by non-editmesh types */
 static void ccgDM_drawMappedFacesGLSL(DerivedMesh *dm,
-                       int (*setMaterial)(int, void *attribs),
-                       int (*setDrawOptions)(void *userData, int index),
+                       DMSetMaterial setMaterial,
+                       DMSetDrawOptions setDrawOptions,
                        void *userData)
 {
        CCGDerivedMesh *ccgdm = (CCGDerivedMesh*) dm;
@@ -1764,7 +1764,7 @@ static void ccgDM_drawMappedFacesGLSL(DerivedMesh *dm,
 #undef PASSATTRIB
 }
 
-static void ccgDM_drawFacesGLSL(DerivedMesh *dm, int (*setMaterial)(int, void *attribs))
+static void ccgDM_drawFacesGLSL(DerivedMesh *dm, DMSetMaterial setMaterial)
 {
        dm->drawMappedFacesGLSL(dm, setMaterial, NULL, NULL);
 }
@@ -1916,9 +1916,9 @@ static void ccgDM_drawMappedFacesMat(DerivedMesh *dm, void (*setMaterial)(void *
 }
 
 static void ccgDM_drawFacesTex_common(DerivedMesh *dm,
-       int (*drawParams)(MTFace *tface, int has_mcol, int matnr),
-       int (*drawParamsMapped)(void *userData, int index),
-       int (*compareDrawOptions)(void *userData, int cur_index, int next_index),
+       DMSetDrawOptionsTex drawParams,
+       DMSetDrawOptions drawParamsMapped,
+       DMCompareDrawOptions compareDrawOptions,
        void *userData) 
 {
        CCGDerivedMesh *ccgdm = (CCGDerivedMesh*) dm;
@@ -2062,16 +2062,16 @@ static void ccgDM_drawFacesTex_common(DerivedMesh *dm,
 }
 
 static void ccgDM_drawFacesTex(DerivedMesh *dm,
-                          int (*setDrawOptions)(MTFace *tface, int has_vcol, int matnr),
-                          int (*compareDrawOptions)(void *userData, int cur_index, int next_index),
+                          DMSetDrawOptionsTex setDrawOptions,
+                          DMCompareDrawOptions compareDrawOptions,
                           void *userData)
 {
        ccgDM_drawFacesTex_common(dm, setDrawOptions, NULL, compareDrawOptions, userData);
 }
 
 static void ccgDM_drawMappedFacesTex(DerivedMesh *dm,
-    int (*setDrawOptions)(void *userData, int index),
-    int (*compareDrawOptions)(void *userData, int cur_index, int next_index),
+    DMSetDrawOptions setDrawOptions,
+    DMCompareDrawOptions compareDrawOptions,
     void *userData)
 {
        ccgDM_drawFacesTex_common(dm, NULL, setDrawOptions, compareDrawOptions, userData);
@@ -2111,9 +2111,9 @@ static void ccgDM_drawUVEdges(DerivedMesh *dm)
 }
 
 static void ccgDM_drawMappedFaces(DerivedMesh *dm,
-                       int (*setDrawOptions)(void *userData, int index, int *drawSmooth_r),
-                       int (*setMaterial)(int, void *attribs),
-                       int (*compareDrawOptions)(void *userData, int cur_index, int next_index),
+                       DMSetDrawOptionsShading setDrawOptions,
+                       DMSetMaterial setMaterial,
+                       DMCompareDrawOptions compareDrawOptions,
                        void *userData, int useColors)
 {
        CCGDerivedMesh *ccgdm = (CCGDerivedMesh*) dm;
@@ -2237,7 +2237,9 @@ static void ccgDM_drawMappedFaces(DerivedMesh *dm,
        }
 }
 
-static void ccgDM_drawMappedEdges(DerivedMesh *dm, int (*setDrawOptions)(void *userData, int index), void *userData)
+static void ccgDM_drawMappedEdges(DerivedMesh *dm,
+                                                                 DMSetDrawOptions setDrawOptions,
+                                                                 void *userData)
 {
        CCGDerivedMesh *ccgdm = (CCGDerivedMesh*) dm;
        CCGSubSurf *ss = ccgdm->ss;
@@ -2269,7 +2271,10 @@ static void ccgDM_drawMappedEdges(DerivedMesh *dm, int (*setDrawOptions)(void *u
        ccgEdgeIterator_free(ei);
 }
 
-static void ccgDM_drawMappedEdgesInterp(DerivedMesh *dm, int (*setDrawOptions)(void *userData, int index), void (*setDrawInterpOptions)(void *userData, int index, float t), void *userData)
+static void ccgDM_drawMappedEdgesInterp(DerivedMesh *dm,
+                                                                               DMSetDrawOptions setDrawOptions,
+                                                                               DMSetDrawInterpOptions setDrawInterpOptions,
+                                                                               void *userData)
 {
        CCGDerivedMesh *ccgdm = (CCGDerivedMesh*) dm;
        CCGSubSurf *ss = ccgdm->ss;
index 861219159e121d35c9bdbf91b17f91dd1db9e5d9..d0dc51d1a8a01d8ed1f6cc5a5e8bd4093f72e38c 100644 (file)
@@ -1560,7 +1560,7 @@ int BLI_pbvh_node_planes_contain_AABB(PBVHNode *node, void *data)
 }
 
 void BLI_pbvh_draw(PBVH *bvh, float (*planes)[4], float (*face_nors)[3],
-                                  int (*setMaterial)(int, void *attribs))
+                                  DMSetMaterial setMaterial)
 {
        PBVHNode **nodes;
        int totnode;
index 2e260ab8a2edac406d2b59631d42a06098b3c2c0..9aa9b6fe857eed216d7cbf774a2aceafd7409796 100644 (file)
@@ -170,7 +170,7 @@ void GPU_update_grid_buffers(GPU_Buffers *buffers, struct DMGridData **grids,
                                                         const struct DMFlagMat *grid_flag_mats,
                                                         int *grid_indices, int totgrid, int gridsize);
 
-void GPU_draw_buffers(GPU_Buffers *buffers, int (*setMaterial)(int, void *attribs));
+void GPU_draw_buffers(GPU_Buffers *buffers, DMSetMaterial setMaterial);
 
 void GPU_free_buffers(GPU_Buffers *buffers);
 
index cd9314504978bd41ff128e9cf64b63e92b664317..57d3344895c15301583b7307c8af249565c074b4 100644 (file)
@@ -1613,7 +1613,7 @@ static void gpu_draw_buffers_legacy_grids(GPU_Buffers *buffers, int smooth)
        }
 }
 
-void GPU_draw_buffers(GPU_Buffers *buffers, int (*setMaterial)(int, void *attribs))
+void GPU_draw_buffers(GPU_Buffers *buffers, DMSetMaterial setMaterial)
 {
        int smooth = 0;