[Bf-blender-cvs] [41d31e100d9] master: Cleanup: remove MeshBatchCache from MeshRenderData

Campbell Barton noreply at git.blender.org
Fri Aug 21 09:20:49 CEST 2020


Commit: 41d31e100d9d76aa8f20bd9fe8429122828dc7a9
Author: Campbell Barton
Date:   Fri Aug 21 17:19:25 2020 +1000
Branches: master
https://developer.blender.org/rB41d31e100d9d76aa8f20bd9fe8429122828dc7a9

Cleanup: remove MeshBatchCache from MeshRenderData

Was noted as a hack, this can be passed as an argument instead.

===================================================================

M	source/blender/draw/intern/draw_cache_extract_mesh.c

===================================================================

diff --git a/source/blender/draw/intern/draw_cache_extract_mesh.c b/source/blender/draw/intern/draw_cache_extract_mesh.c
index 934b47d583e..fe48ce00b86 100644
--- a/source/blender/draw/intern/draw_cache_extract_mesh.c
+++ b/source/blender/draw/intern/draw_cache_extract_mesh.c
@@ -99,8 +99,6 @@ typedef struct MeshRenderData {
   float obmat[4][4];
 
   const ToolSettings *toolsettings;
-  /* HACK not supposed to be there but it's needed. */
-  struct MeshBatchCache *cache;
   /** Edit Mesh */
   BMEditMesh *edit_bmesh;
   BMesh *bm;
@@ -751,8 +749,13 @@ typedef void(ExtractLVertMeshFn)(const MeshRenderData *mr,
 /** \name Mesh Elements Extract Struct
  * \{ */
 
-typedef void *(ExtractInitFn)(const MeshRenderData *mr, void *buffer);
-typedef void(ExtractFinishFn)(const MeshRenderData *mr, void *buffer, void *data);
+typedef void *(ExtractInitFn)(const MeshRenderData *mr,
+                              struct MeshBatchCache *cache,
+                              void *buffer);
+typedef void(ExtractFinishFn)(const MeshRenderData *mr,
+                              struct MeshBatchCache *cache,
+                              void *buffer,
+                              void *data);
 
 typedef struct MeshExtract {
   /** Executed on main thread and return user data for iteration functions. */
@@ -796,7 +799,9 @@ typedef struct MeshExtract_Tri_Data {
   int *tri_mat_end;
 } MeshExtract_Tri_Data;
 
-static void *extract_tris_init(const MeshRenderData *mr, void *UNUSED(ibo))
+static void *extract_tris_init(const MeshRenderData *mr,
+                               struct MeshBatchCache *UNUSED(cache),
+                               void *UNUSED(ibo))
 {
   MeshExtract_Tri_Data *data = MEM_callocN(sizeof(*data), __func__);
 
@@ -882,14 +887,17 @@ static void extract_tris_iter_looptri_mesh(const MeshRenderData *mr,
   EXTRACT_TRIS_LOOPTRI_FOREACH_MESH_END;
 }
 
-static void extract_tris_finish(const MeshRenderData *mr, void *ibo, void *_data)
+static void extract_tris_finish(const MeshRenderData *mr,
+                                struct MeshBatchCache *cache,
+                                void *ibo,
+                                void *_data)
 {
   MeshExtract_Tri_Data *data = _data;
   GPU_indexbuf_build_in_place(&data->elb, ibo);
   /* HACK: Create ibo sub-ranges and assign them to each #GPUBatch. */
   /* The `surface_per_mat` tests are there when object shading type is set to Wire or Bounds. In
    * these cases there isn't a surface per material. */
-  if (mr->use_final_mesh && mr->cache->surface_per_mat && mr->cache->surface_per_mat[0]) {
+  if (mr->use_final_mesh && cache->surface_per_mat && cache->surface_per_mat[0]) {
     for (int i = 0; i < mr->mat_len; i++) {
       /* Multiply by 3 because these are triangle indices. */
       const int mat_start = data->tri_mat_start[i];
@@ -898,7 +906,7 @@ static void extract_tris_finish(const MeshRenderData *mr, void *ibo, void *_data
       const int len = (mat_end - mat_start) * 3;
       GPUIndexBuf *sub_ibo = GPU_indexbuf_create_subrange(ibo, start, len);
       /* WARNING: We modify the #GPUBatch here! */
-      GPU_batch_elembuf_set(mr->cache->surface_per_mat[i], sub_ibo, true);
+      GPU_batch_elembuf_set(cache->surface_per_mat[i], sub_ibo, true);
     }
   }
   MEM_freeN(data->tri_mat_start);
@@ -921,7 +929,9 @@ static const MeshExtract extract_tris = {
 /** \name Extract Edges Indices
  * \{ */
 
-static void *extract_lines_init(const MeshRenderData *mr, void *UNUSED(buf))
+static void *extract_lines_init(const MeshRenderData *mr,
+                                struct MeshBatchCache *UNUSED(cache),
+                                void *UNUSED(buf))
 {
   GPUIndexBufBuilder *elb = MEM_mallocN(sizeof(*elb), __func__);
   /* Put loose edges at the end. */
@@ -1039,7 +1049,10 @@ static void extract_lines_iter_ledge_mesh(const MeshRenderData *mr,
   EXTRACT_LEDGE_FOREACH_MESH_END;
 }
 
-static void extract_lines_finish(const MeshRenderData *UNUSED(mr), void *ibo, void *elb)
+static void extract_lines_finish(const MeshRenderData *UNUSED(mr),
+                                 struct MeshBatchCache *UNUSED(cache),
+                                 void *ibo,
+                                 void *elb)
 {
   GPU_indexbuf_build_in_place(elb, ibo);
   MEM_freeN(elb);
@@ -1061,21 +1074,24 @@ static const MeshExtract extract_lines = {
 /** \name Extract Loose Edges Sub Buffer
  * \{ */
 
-static void extract_lines_loose_subbuffer(const MeshRenderData *mr)
+static void extract_lines_loose_subbuffer(const MeshRenderData *mr, struct MeshBatchCache *cache)
 {
-  BLI_assert(mr->cache->final.ibo.lines);
+  BLI_assert(cache->final.ibo.lines);
   /* Multiply by 2 because these are edges indices. */
   const int start = mr->edge_len * 2;
   const int len = mr->edge_loose_len * 2;
   GPU_indexbuf_create_subrange_in_place(
-      mr->cache->final.ibo.lines_loose, mr->cache->final.ibo.lines, start, len);
-  mr->cache->no_loose_wire = (len == 0);
+      cache->final.ibo.lines_loose, cache->final.ibo.lines, start, len);
+  cache->no_loose_wire = (len == 0);
 }
 
-static void extract_lines_with_lines_loose_finish(const MeshRenderData *mr, void *ibo, void *elb)
+static void extract_lines_with_lines_loose_finish(const MeshRenderData *mr,
+                                                  struct MeshBatchCache *cache,
+                                                  void *ibo,
+                                                  void *elb)
 {
   GPU_indexbuf_build_in_place(elb, ibo);
-  extract_lines_loose_subbuffer(mr);
+  extract_lines_loose_subbuffer(mr, cache);
   MEM_freeN(elb);
 }
 
@@ -1096,7 +1112,9 @@ static const MeshExtract extract_lines_with_lines_loose = {
 /** \name Extract Point Indices
  * \{ */
 
-static void *extract_points_init(const MeshRenderData *mr, void *UNUSED(buf))
+static void *extract_points_init(const MeshRenderData *mr,
+                                 struct MeshBatchCache *UNUSED(cache),
+                                 void *UNUSED(buf))
 {
   GPUIndexBufBuilder *elb = MEM_mallocN(sizeof(*elb), __func__);
   GPU_indexbuf_init(elb, GPU_PRIM_POINTS, mr->vert_len, mr->loop_len + mr->loop_loose_len);
@@ -1200,7 +1218,10 @@ static void extract_points_iter_lvert_mesh(const MeshRenderData *mr,
   EXTRACT_LVERT_FOREACH_MESH_END;
 }
 
-static void extract_points_finish(const MeshRenderData *UNUSED(mr), void *ibo, void *elb)
+static void extract_points_finish(const MeshRenderData *UNUSED(mr),
+                                  struct MeshBatchCache *UNUSED(cache),
+                                  void *ibo,
+                                  void *elb)
 {
   GPU_indexbuf_build_in_place(elb, ibo);
   MEM_freeN(elb);
@@ -1225,7 +1246,9 @@ static const MeshExtract extract_points = {
 /** \name Extract Facedots Indices
  * \{ */
 
-static void *extract_fdots_init(const MeshRenderData *mr, void *UNUSED(buf))
+static void *extract_fdots_init(const MeshRenderData *mr,
+                                struct MeshBatchCache *UNUSED(cache),
+                                void *UNUSED(buf))
 {
   GPUIndexBufBuilder *elb = MEM_mallocN(sizeof(*elb), __func__);
   GPU_indexbuf_init(elb, GPU_PRIM_POINTS, mr->poly_len, mr->poly_len);
@@ -1280,7 +1303,10 @@ static void extract_fdots_iter_poly_mesh(const MeshRenderData *mr,
   }
 }
 
-static void extract_fdots_finish(const MeshRenderData *UNUSED(mr), void *ibo, void *elb)
+static void extract_fdots_finish(const MeshRenderData *UNUSED(mr),
+                                 struct MeshBatchCache *UNUSED(cache),
+                                 void *ibo,
+                                 void *elb)
 {
   GPU_indexbuf_build_in_place(elb, ibo);
   MEM_freeN(elb);
@@ -1307,7 +1333,9 @@ typedef struct MeshExtract_LinePaintMask_Data {
   BLI_bitmap select_map[0];
 } MeshExtract_LinePaintMask_Data;
 
-static void *extract_lines_paint_mask_init(const MeshRenderData *mr, void *UNUSED(buf))
+static void *extract_lines_paint_mask_init(const MeshRenderData *mr,
+                                           struct MeshBatchCache *UNUSED(cache),
+                                           void *UNUSED(buf))
 {
   size_t bitmap_size = BLI_BITMAP_SIZE(mr->edge_len);
   MeshExtract_LinePaintMask_Data *data = MEM_callocN(sizeof(*data) + bitmap_size, __func__);
@@ -1354,6 +1382,7 @@ static void extract_lines_paint_mask_iter_poly_mesh(const MeshRenderData *mr,
   EXTRACT_POLY_AND_LOOP_FOREACH_MESH_END;
 }
 static void extract_lines_paint_mask_finish(const MeshRenderData *UNUSED(mr),
+                                            struct MeshBatchCache *UNUSED(cache),
                                             void *ibo,
                                             void *_data)
 {
@@ -1387,7 +1416,9 @@ typedef struct MeshExtract_LineAdjacency_Data {
   uint vert_to_loop[0];
 } MeshExtract_LineAdjacency_Data;
 
-static void *extract_lines_adjacency_init(const MeshRenderData *mr, void *UNUSED(buf))
+static void *extract_lines_adjacency_init(const MeshRenderData *mr,
+                                          struct MeshBatchCache *UNUSED(cache),
+                                          void *UNUSED(buf))
 {
   /* Similar to poly_to_tri_count().
    * There is always (loop + triangle - 1) edges inside a polygon.
@@ -1483,7 +1514,10 @@ static void extract_lines_adjacency_iter_looptri_mesh(const MeshRenderData *mr,
   EXTRACT_TRIS_LOOPTRI_FOREACH_MESH_END;
 }
 
-static void extract_lines_adjacency_finish(const MeshRenderData *mr, void *ibo, void *_data)
+static void extract_lines_adjacency_finish(const MeshRenderData *UNUSED(mr),
+                                           struct MeshBatchCache *cache,
+                                           void *ibo,
+                                           void *_data)
 {
   MeshExtract_LineAdjacency_Data *data = _data;
   /* Create edges for remaining non manifold edges. */
@@ -1506,7 +1540,7 @@ static void extract_lines_adjacency_finish(const MeshRenderData *mr, void *ibo,
   BLI_edgehashIterator_free(ehi);
   BLI_edgehash_free(data->eh, NULL);
 
-  mr->cache->is_manifold = data->is_manifold;
+  cache->is_manifold = data->is_manifold;
 
   GPU_indexbuf_build_in_place(&data->elb, ibo);
   MEM_freeN(data);
@@ -1534,7 +1568,9 @@ typedef 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list