Blender V5.0
extract_mesh_vbo_fdots_pos.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
8
9#include "GPU_index_buffer.hh"
10
11#include "extract_mesh.hh"
12
13#include "draw_subdivision.hh"
14
15namespace blender::draw {
16
18{
20 "pos", gpu::VertAttrType::SFLOAT_32_32_32);
21 return format;
22}
23
25{
27 "norAndFlag", gpu::VertAttrType::SFLOAT_32_32_32_32);
28 return format;
29}
30
32{
33 const Span<float3> positions = mr.vert_positions;
34 const OffsetIndices faces = mr.faces;
35 const Span<int> corner_verts = mr.corner_verts;
36 if (mr.use_subsurf_fdots) {
37 const BitSpan facedot_tags = mr.mesh->runtime->subsurf_face_dot_tags;
38 threading::parallel_for(faces.index_range(), 4096, [&](const IndexRange range) {
39 for (const int face : range) {
40 const Span<int> face_verts = corner_verts.slice(faces[face]);
41 const int *vert = std::find_if(face_verts.begin(), face_verts.end(), [&](const int vert) {
42 return facedot_tags[vert].test();
43 });
44 if (vert == face_verts.end()) {
45 vbo_data[face] = float3(0);
46 }
47 else {
48 vbo_data[face] = positions[*vert];
49 }
50 }
51 });
52 }
53 else {
54 threading::parallel_for(faces.index_range(), 4096, [&](const IndexRange range) {
55 for (const int face : range) {
56 vbo_data[face] = bke::mesh::face_center_calc(positions, corner_verts.slice(faces[face]));
57 }
58 });
59 }
60}
61
63{
64 const BMesh &bm = *mr.bm;
65 threading::parallel_for(IndexRange(bm.totface), 2048, [&](const IndexRange range) {
66 for (const int face_index : range) {
67 const BMFace &face = *BM_face_at_index(&const_cast<BMesh &>(bm), face_index);
68 if (mr.bm_vert_coords.is_empty()) {
69 BM_face_calc_center_median(&face, vbo_data[face_index]);
70 }
71 else {
72 BM_face_calc_center_median_vcos(&bm, &face, vbo_data[face_index], mr.bm_vert_coords);
73 }
74 }
75 });
76}
77
91
93 gpu::VertBufPtr &fdots_pos,
94 gpu::VertBufPtr *fdots_nor,
95 gpu::IndexBufPtr &fdots)
96{
97 /* We "extract" positions, normals, and indices at once. */
98 /* The normals may not be requested. */
99 if (fdots_nor) {
101 subdiv_cache.num_coarse_faces));
102 }
103 fdots_pos = gpu::VertBufPtr(
107 subdiv_cache, fdots_pos.get(), fdots_nor ? fdots_nor->get() : nullptr, fdots.get());
108}
109
110} // namespace blender::draw
blender::gpu::IndexBuf * GPU_indexbuf_build_on_device(uint index_len)
blender::gpu::VertBuf * GPU_vertbuf_create_on_device(const GPUVertFormat &format, uint v_len)
static blender::gpu::VertBuf * GPU_vertbuf_create_with_format(const GPUVertFormat &format)
void GPU_vertbuf_data_alloc(blender::gpu::VertBuf &verts, uint v_len)
GPUVertFormat GPU_vertformat_from_attribute(blender::StringRef name, blender::gpu::VertAttrType type)
BMesh * bm
constexpr T * data() const
Definition BLI_span.hh:539
Extraction of Mesh data into VBO to feed to GPU.
format
static char faces[256]
static const GPUVertFormat & get_fdots_pos_format()
static const GPUVertFormat & get_fdots_nor_format_subdiv()
void draw_subdiv_build_fdots_buffers(const DRWSubdivCache &cache, gpu::VertBuf *fdots_pos, gpu::VertBuf *fdots_nor, gpu::IndexBuf *fdots_indices)
static void extract_face_dot_positions_bm(const MeshRenderData &mr, MutableSpan< float3 > vbo_data)
void extract_face_dots_subdiv(const DRWSubdivCache &subdiv_cache, gpu::VertBufPtr &fdots_pos, gpu::VertBufPtr *fdots_nor, gpu::IndexBufPtr &fdots)
static void extract_face_dot_positions_mesh(const MeshRenderData &mr, MutableSpan< float3 > vbo_data)
gpu::VertBufPtr extract_face_dots_position(const MeshRenderData &mr)
std::unique_ptr< IndexBuf, IndexBufDeleter > IndexBufPtr
std::unique_ptr< gpu::VertBuf, gpu::VertBufDeleter > VertBufPtr
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
Definition BLI_task.hh:93
VecBase< float, 3 > float3
MeshRuntimeHandle * runtime
OffsetIndices< int > faces