Blender V4.3
extract_mesh_ibo_fdots.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2021 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#include "GPU_index_buffer.hh"
10
11#include "extract_mesh.hh"
12
13namespace blender::draw {
14
16{
17 IndexMask visible(mr.faces_num);
18 if (!mr.hide_poly.is_empty()) {
19 visible = IndexMask::from_bools_inverse(visible, mr.hide_poly, memory);
20 }
21 if (mr.use_subsurf_fdots) {
22 const OffsetIndices faces = mr.faces;
23 const Span<int> corner_verts = mr.corner_verts;
24 const BitSpan facedot_tags = mr.mesh->runtime->subsurf_face_dot_tags;
25 visible = IndexMask::from_predicate(visible, GrainSize(4096), memory, [&](const int i) {
26 const Span<int> face_verts = corner_verts.slice(faces[i]);
27 return std::any_of(face_verts.begin(), face_verts.end(), [&](const int vert) {
28 return facedot_tags[vert];
29 });
30 });
31 }
32 return visible;
33}
34
35static void index_mask_to_ibo(const IndexMask &mask, gpu::IndexBuf &ibo)
36{
37 const int max_index = mask.min_array_size();
38 GPUIndexBufBuilder builder;
39 GPU_indexbuf_init(&builder, GPU_PRIM_POINTS, mask.size(), max_index);
41 mask.to_indices<int>(data.cast<int>());
42 GPU_indexbuf_build_in_place_ex(&builder, 0, max_index, false, &ibo);
43}
44
45static void extract_face_dots_mesh(const MeshRenderData &mr, gpu::IndexBuf &face_dots)
46{
47 IndexMaskMemory memory;
48 const IndexMask visible_faces = calc_face_visibility_mesh(mr, memory);
49 index_mask_to_ibo(visible_faces, face_dots);
50}
51
52static void extract_face_dots_bm(const MeshRenderData &mr, gpu::IndexBuf &face_dots)
53{
54 BMesh &bm = *mr.bm;
55 IndexMaskMemory memory;
56 const IndexMask visible_faces = IndexMask::from_predicate(
57 IndexRange(bm.totface), GrainSize(4096), memory, [&](const int i) {
59 });
60 index_mask_to_ibo(visible_faces, face_dots);
61}
62
64{
65 if (mr.extract_type == MR_EXTRACT_MESH) {
66 extract_face_dots_mesh(mr, face_dots);
67 }
68 else {
69 extract_face_dots_bm(mr, face_dots);
70 }
71}
72
73} // namespace blender::draw
void GPU_indexbuf_build_in_place_ex(GPUIndexBufBuilder *builder, uint index_min, uint index_max, bool uses_restart_indices, blender::gpu::IndexBuf *elem)
blender::MutableSpan< uint32_t > GPU_indexbuf_get_data(GPUIndexBufBuilder *)
void GPU_indexbuf_init(GPUIndexBufBuilder *, GPUPrimType, uint prim_len, uint vertex_len)
@ GPU_PRIM_POINTS
@ BM_ELEM_HIDDEN
#define BM_elem_flag_test_bool(ele, hflag)
ATTR_WARN_UNUSED_RESULT BMesh * bm
BLI_INLINE BMFace * BM_face_at_index(BMesh *bm, const int index)
constexpr Span slice(int64_t start, int64_t size) const
Definition BLI_span.hh:138
constexpr const T * end() const
Definition BLI_span.hh:225
constexpr const T * begin() const
Definition BLI_span.hh:221
constexpr bool is_empty() const
Definition BLI_span.hh:261
static IndexMask from_predicate(const IndexMask &universe, GrainSize grain_size, IndexMaskMemory &memory, Fn &&predicate)
static IndexMask from_bools_inverse(const IndexMask &universe, Span< bool > bools, IndexMaskMemory &memory)
Extraction of Mesh data into VBO to feed to GPU.
void extract_face_dots(const MeshRenderData &mr, gpu::IndexBuf &face_dots)
static void extract_face_dots_mesh(const MeshRenderData &mr, gpu::IndexBuf &face_dots)
static void index_mask_to_ibo(const IndexMask &mask, gpu::IndexBuf &ibo)
static IndexMask calc_face_visibility_mesh(const MeshRenderData &mr, IndexMaskMemory &memory)
static void extract_face_dots_bm(const MeshRenderData &mr, gpu::IndexBuf &face_dots)
int totface
MeshRuntimeHandle * runtime
OffsetIndices< int > faces