Blender V5.0
extract_mesh_vbo_orco.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 "extract_mesh.hh"
10
11namespace blender::draw {
12
14{
15 const Span<float3> orco_data(
16 static_cast<const float3 *>(CustomData_get_layer(&mr.mesh->vert_data, CD_ORCO)),
17 mr.corners_num);
18
19 /* FIXME(fclem): We use the last component as a way to differentiate from generic vertex
20 * attributes. This is a substantial waste of video-ram and should be done another way.
21 * Unfortunately, at the time of writing, I did not found any other "non disruptive"
22 * alternative. */
24 "orco", gpu::VertAttrType::SFLOAT_32_32_32_32);
25
28 MutableSpan vbo_data = vbo->data<float4>();
29
30 const int64_t bytes = orco_data.size_in_bytes() + vbo_data.size_in_bytes();
33 const BMesh &bm = *mr.bm;
34 threading::parallel_for(IndexRange(bm.totface), 2048, [&](const IndexRange range) {
35 for (const int face_index : range) {
36 const BMFace &face = *BM_face_at_index(&const_cast<BMesh &>(bm), face_index);
37 const BMLoop *loop = BM_FACE_FIRST_LOOP(&face);
38 for ([[maybe_unused]] const int i : IndexRange(face.len)) {
39 const int index = BM_elem_index_get(loop);
40 vbo_data[index] = float4(orco_data[BM_elem_index_get(loop->v)], 0.0f);
41 loop = loop->next;
42 }
43 }
44 });
45 }
46 else {
47 const Span<int> corner_verts = mr.corner_verts;
48 threading::parallel_for(corner_verts.index_range(), 4096, [&](const IndexRange range) {
49 for (const int corner : range) {
50 vbo_data[corner] = float4(orco_data[corner_verts[corner]], 0.0f);
51 }
52 });
53 }
54 });
55 return vbo;
56}
57
58} // namespace blender::draw
const void * CustomData_get_layer(const CustomData *data, eCustomDataType type)
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
long long int int64_t
constexpr T * data() const
Definition BLI_span.hh:539
constexpr int64_t size_in_bytes() const
Definition BLI_span.hh:501
constexpr int64_t size_in_bytes() const
Definition BLI_span.hh:268
constexpr IndexRange index_range() const
Definition BLI_span.hh:401
Extraction of Mesh data into VBO to feed to GPU.
format
gpu::VertBufPtr extract_orco(const MeshRenderData &mr)
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
void memory_bandwidth_bound_task(const int64_t approximate_bytes_touched, const Function &function)
Definition BLI_task.hh:265
VecBase< float, 4 > float4
VecBase< float, 3 > float3
CustomData vert_data