[Bf-blender-cvs] [cac9828ae38] master: Cleanup: Separate compile unit lines_paint_mask.

Jeroen Bakker noreply at git.blender.org
Tue Jun 8 13:14:41 CEST 2021


Commit: cac9828ae382017fb0d09b48c5187ffcd9bb3126
Author: Jeroen Bakker
Date:   Tue Jun 8 11:21:38 2021 +0200
Branches: master
https://developer.blender.org/rBcac9828ae382017fb0d09b48c5187ffcd9bb3126

Cleanup: Separate compile unit lines_paint_mask.

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

M	source/blender/draw/CMakeLists.txt
M	source/blender/draw/intern/draw_cache_extract_mesh_extractors.c
A	source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_lines_paint_mask.cc

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

diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt
index 1768a53db98..8ae6b3505d1 100644
--- a/source/blender/draw/CMakeLists.txt
+++ b/source/blender/draw/CMakeLists.txt
@@ -55,6 +55,7 @@ set(SRC
   intern/draw_cache_extract_mesh_render_data.c
   intern/draw_cache_extract_mesh.cc
   intern/mesh_extractors/extract_mesh_ibo_fdots.cc
+  intern/mesh_extractors/extract_mesh_ibo_lines_paint_mask.cc
   intern/mesh_extractors/extract_mesh_ibo_lines.cc
   intern/mesh_extractors/extract_mesh_ibo_points.cc
   intern/mesh_extractors/extract_mesh_ibo_tris.cc
diff --git a/source/blender/draw/intern/draw_cache_extract_mesh_extractors.c b/source/blender/draw/intern/draw_cache_extract_mesh_extractors.c
index 0b46d0b6c7d..3ce2ed0fe2c 100644
--- a/source/blender/draw/intern/draw_cache_extract_mesh_extractors.c
+++ b/source/blender/draw/intern/draw_cache_extract_mesh_extractors.c
@@ -105,89 +105,6 @@ const MeshExtract *mesh_extract_override_get(const MeshExtract *extractor,
 
 /** \} */
 
-/* ---------------------------------------------------------------------- */
-/** \name Extract Paint Mask Line Indices
- * \{ */
-
-typedef struct MeshExtract_LinePaintMask_Data {
-  GPUIndexBufBuilder elb;
-  /** One bit per edge set if face is selected. */
-  BLI_bitmap select_map[0];
-} MeshExtract_LinePaintMask_Data;
-
-static void *extract_lines_paint_mask_init(const MeshRenderData *mr,
-                                           struct MeshBatchCache *UNUSED(cache),
-                                           void *UNUSED(ibo))
-{
-  size_t bitmap_size = BLI_BITMAP_SIZE(mr->edge_len);
-  MeshExtract_LinePaintMask_Data *data = MEM_callocN(sizeof(*data) + bitmap_size, __func__);
-  GPU_indexbuf_init(&data->elb, GPU_PRIM_LINES, mr->edge_len, mr->loop_len);
-  return data;
-}
-
-static void extract_lines_paint_mask_iter_poly_mesh(const MeshRenderData *mr,
-                                                    const MPoly *mp,
-                                                    const int UNUSED(mp_index),
-                                                    void *_data)
-{
-  MeshExtract_LinePaintMask_Data *data = _data;
-  const MLoop *mloop = mr->mloop;
-  const int ml_index_end = mp->loopstart + mp->totloop;
-  for (int ml_index = mp->loopstart; ml_index < ml_index_end; ml_index += 1) {
-    const MLoop *ml = &mloop[ml_index];
-
-    const int e_index = ml->e;
-    const MEdge *me = &mr->medge[e_index];
-    if (!((mr->use_hide && (me->flag & ME_HIDE)) ||
-          ((mr->extract_type == MR_EXTRACT_MAPPED) && (mr->e_origindex) &&
-           (mr->e_origindex[e_index] == ORIGINDEX_NONE)))) {
-
-      const int ml_index_last = mp->totloop + mp->loopstart - 1;
-      const int ml_index_other = (ml_index == ml_index_last) ? mp->loopstart : (ml_index + 1);
-      if (mp->flag & ME_FACE_SEL) {
-        if (BLI_BITMAP_TEST_AND_SET_ATOMIC(data->select_map, e_index)) {
-          /* Hide edge as it has more than 2 selected loop. */
-          GPU_indexbuf_set_line_restart(&data->elb, e_index);
-        }
-        else {
-          /* First selected loop. Set edge visible, overwriting any unselected loop. */
-          GPU_indexbuf_set_line_verts(&data->elb, e_index, ml_index, ml_index_other);
-        }
-      }
-      else {
-        /* Set these unselected loop only if this edge has no other selected loop. */
-        if (!BLI_BITMAP_TEST(data->select_map, e_index)) {
-          GPU_indexbuf_set_line_verts(&data->elb, e_index, ml_index, ml_index_other);
-        }
-      }
-    }
-    else {
-      GPU_indexbuf_set_line_restart(&data->elb, e_index);
-    }
-  }
-}
-
-static void extract_lines_paint_mask_finish(const MeshRenderData *UNUSED(mr),
-                                            struct MeshBatchCache *UNUSED(cache),
-                                            void *buf,
-                                            void *_data)
-{
-  GPUIndexBuf *ibo = buf;
-  MeshExtract_LinePaintMask_Data *data = _data;
-  GPU_indexbuf_build_in_place(&data->elb, ibo);
-  MEM_freeN(data);
-}
-
-const MeshExtract extract_lines_paint_mask = {
-    .init = extract_lines_paint_mask_init,
-    .iter_poly_mesh = extract_lines_paint_mask_iter_poly_mesh,
-    .finish = extract_lines_paint_mask_finish,
-    .data_type = 0,
-    .use_threading = false,
-    .mesh_buffer_offset = offsetof(MeshBufferCache, ibo.lines_paint_mask)};
-
-/** \} */
-
 /* ---------------------------------------------------------------------- */
 /** \name Extract Line Adjacency Indices
  * \{ */
diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_lines_paint_mask.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_lines_paint_mask.cc
new file mode 100644
index 00000000000..95d355e0437
--- /dev/null
+++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_ibo_lines_paint_mask.cc
@@ -0,0 +1,127 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2021 by Blender Foundation.
+ * All rights reserved.
+ */
+
+/** \file
+ * \ingroup draw
+ */
+
+#include "draw_cache_extract_mesh_private.h"
+
+#include "BLI_bitmap.h"
+#include "BLI_vector.hh"
+#include "atomic_ops.h"
+
+#include "MEM_guardedalloc.h"
+
+namespace blender::draw {
+/* ---------------------------------------------------------------------- */
+/** \name Extract Paint Mask Line Indices
+ * \{ */
+
+typedef struct MeshExtract_LinePaintMask_Data {
+  GPUIndexBufBuilder elb;
+  /** One bit per edge set if face is selected. */
+  BLI_bitmap select_map[0];
+} MeshExtract_LinePaintMask_Data;
+
+static void *extract_lines_paint_mask_init(const MeshRenderData *mr,
+                                           struct MeshBatchCache *UNUSED(cache),
+                                           void *UNUSED(ibo))
+{
+  size_t bitmap_size = BLI_BITMAP_SIZE(mr->edge_len);
+  MeshExtract_LinePaintMask_Data *data = static_cast<MeshExtract_LinePaintMask_Data *>(
+      MEM_callocN(sizeof(*data) + bitmap_size, __func__));
+  GPU_indexbuf_init(&data->elb, GPU_PRIM_LINES, mr->edge_len, mr->loop_len);
+  return data;
+}
+
+static void extract_lines_paint_mask_iter_poly_mesh(const MeshRenderData *mr,
+                                                    const MPoly *mp,
+                                                    const int UNUSED(mp_index),
+                                                    void *_data)
+{
+  MeshExtract_LinePaintMask_Data *data = static_cast<MeshExtract_LinePaintMask_Data *>(_data);
+  const MLoop *mloop = mr->mloop;
+  const int ml_index_end = mp->loopstart + mp->totloop;
+  for (int ml_index = mp->loopstart; ml_index < ml_index_end; ml_index += 1) {
+    const MLoop *ml = &mloop[ml_index];
+
+    const int e_index = ml->e;
+    const MEdge *me = &mr->medge[e_index];
+    if (!((mr->use_hide && (me->flag & ME_HIDE)) ||
+          ((mr->extract_type == MR_EXTRACT_MAPPED) && (mr->e_origindex) &&
+           (mr->e_origindex[e_index] == ORIGINDEX_NONE)))) {
+
+      const int ml_index_last = mp->totloop + mp->loopstart - 1;
+      const int ml_index_other = (ml_index == ml_index_last) ? mp->loopstart : (ml_index + 1);
+      if (mp->flag & ME_FACE_SEL) {
+        if (BLI_BITMAP_TEST_AND_SET_ATOMIC(data->select_map, e_index)) {
+          /* Hide edge as it has more than 2 selected loop. */
+          GPU_indexbuf_set_line_restart(&data->elb, e_index);
+        }
+        else {
+          /* First selected loop. Set edge visible, overwriting any unselected loop. */
+          GPU_indexbuf_set_line_verts(&data->elb, e_index, ml_index, ml_index_other);
+        }
+      }
+      else {
+        /* Set these unselected loop only if this edge has no other selected loop. */
+        if (!BLI_BITMAP_TEST(data->select_map, e_index)) {
+          GPU_indexbuf_set_line_verts(&data->elb, e_index, ml_index, ml_index_other);
+        }
+      }
+    }
+    else {
+      GPU_indexbuf_set_line_restart(&data->elb, e_index);
+    }
+  }
+}
+
+static void extract_lines_paint_mask_finish(const MeshRenderData *UNUSED(mr),
+                                            struct MeshBatchCache *UNUSED(cache),
+                                            void *buf,
+                                            void *_data)
+{
+  MeshExtract_LinePaintMask_Data *data = static_cast<MeshExtract_LinePaintMask_Data *>(_data);
+  GPUIndexBuf *ibo = static_cast<GPUIndexBuf *>(buf);
+  GPU_indexbuf_build_in_place(&data->elb, ibo);
+  MEM_freeN(data);
+}
+
+/** \} */
+
+constexpr MeshExtract create_extractor_lines_paint_mask()
+{
+  MeshExtract extractor = {0};
+  extractor.init = extract_lines_paint_mask_init;
+  extractor.iter_poly_mesh = extract_lines_paint_mask_iter_poly_mesh;
+  extractor.finish = extract_lines_paint_mask_finish;
+  extractor.data_type = MR_DATA_NONE;
+  extractor.use_threading = false;
+  extractor.mesh_buffer_offset = offsetof(MeshBufferCache, ibo.lines_paint_mask);
+  return extractor;
+}
+
+}  // namespace blender::draw
+
+extern "C" {
+const MeshExtract extract_lines_paint_mask = blender::draw::create_extractor_lines_paint_mask();
+}
+
+/** \} */



More information about the Bf-blender-cvs mailing list