Blender V4.3
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
9#include "GPU_index_buffer.hh"
10
11#include "extract_mesh.hh"
12
13#include "draw_subdivision.hh"
14
15namespace blender::draw {
16
18{
19 static GPUVertFormat format = {0};
20 if (format.attr_len == 0) {
22 }
23 return format;
24}
25
27{
28 static GPUVertFormat format = {0};
29 if (format.attr_len == 0) {
31 }
32 return format;
33}
34
36{
37 const Span<float3> positions = mr.vert_positions;
38 const OffsetIndices faces = mr.faces;
39 const Span<int> corner_verts = mr.corner_verts;
40 if (mr.use_subsurf_fdots) {
41 const BitSpan facedot_tags = mr.mesh->runtime->subsurf_face_dot_tags;
42 threading::parallel_for(faces.index_range(), 4096, [&](const IndexRange range) {
43 for (const int face : range) {
44 const Span<int> face_verts = corner_verts.slice(faces[face]);
45 const int *vert = std::find_if(face_verts.begin(), face_verts.end(), [&](const int vert) {
46 return facedot_tags[vert].test();
47 });
48 if (vert == face_verts.end()) {
49 vbo_data[face] = float3(0);
50 }
51 else {
52 vbo_data[face] = positions[*vert];
53 }
54 }
55 });
56 }
57 else {
58 threading::parallel_for(faces.index_range(), 4096, [&](const IndexRange range) {
59 for (const int face : range) {
60 vbo_data[face] = bke::mesh::face_center_calc(positions, corner_verts.slice(faces[face]));
61 }
62 });
63 }
64}
65
67{
68 const BMesh &bm = *mr.bm;
69 threading::parallel_for(IndexRange(bm.totface), 2048, [&](const IndexRange range) {
70 for (const int face_index : range) {
71 const BMFace &face = *BM_face_at_index(&const_cast<BMesh &>(bm), face_index);
72 if (mr.bm_vert_coords.is_empty()) {
73 BM_face_calc_center_median(&face, vbo_data[face_index]);
74 }
75 else {
76 BM_face_calc_center_median_vcos(&bm, &face, vbo_data[face_index], mr.bm_vert_coords);
77 }
78 }
79 });
80}
81
95
97 gpu::VertBuf &fdots_pos,
98 gpu::VertBuf *fdots_nor,
99 gpu::IndexBuf &fdots)
100{
101 /* We "extract" positions, normals, and indices at once. */
102 /* The normals may not be requested. */
103 if (fdots_nor) {
105 *fdots_nor, get_fdots_nor_format_subdiv(), subdiv_cache.num_coarse_faces);
106 }
108 fdots_pos, get_fdots_pos_format(), subdiv_cache.num_coarse_faces);
110 draw_subdiv_build_fdots_buffers(subdiv_cache, &fdots_pos, fdots_nor, &fdots);
111}
112
113} // namespace blender::draw
void GPU_indexbuf_init_build_on_device(blender::gpu::IndexBuf *elem, uint index_len)
void GPU_vertbuf_init_build_on_device(blender::gpu::VertBuf &verts, const GPUVertFormat &format, uint v_len)
#define GPU_vertbuf_init_with_format(verts, format)
void GPU_vertbuf_data_alloc(blender::gpu::VertBuf &verts, uint v_len)
@ GPU_FETCH_FLOAT
uint GPU_vertformat_attr_add(GPUVertFormat *, const char *name, GPUVertCompType, uint comp_len, GPUVertFetchMode)
@ GPU_COMP_F32
ATTR_WARN_UNUSED_RESULT BMesh * bm
MutableSpan< T > data()
Extraction of Mesh data into VBO to feed to GPU.
format
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)
void extract_face_dots_position(const MeshRenderData &mr, gpu::VertBuf &vbo)
static void extract_face_dot_positions_bm(const MeshRenderData &mr, MutableSpan< float3 > vbo_data)
static void extract_face_dot_positions_mesh(const MeshRenderData &mr, MutableSpan< float3 > vbo_data)
void extract_face_dots_subdiv(const DRWSubdivCache &subdiv_cache, gpu::VertBuf &fdots_pos, gpu::VertBuf *fdots_nor, gpu::IndexBuf &fdots)
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:95
int totface
MeshRuntimeHandle * runtime
OffsetIndices< int > faces