Blender V4.3
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
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 static GPUVertFormat format = {0};
20 if (format.attr_len == 0) {
21 /* FIXME(fclem): We use the last component as a way to differentiate from generic vertex
22 * attributes. This is a substantial waste of video-ram and should be done another way.
23 * Unfortunately, at the time of writing, I did not found any other "non disruptive"
24 * alternative. */
26 }
29 MutableSpan vbo_data = vbo.data<float4>();
30
31 const int64_t bytes = orco_data.size_in_bytes() + vbo_data.size_in_bytes();
34 const BMesh &bm = *mr.bm;
35 threading::parallel_for(IndexRange(bm.totface), 2048, [&](const IndexRange range) {
36 for (const int face_index : range) {
37 const BMFace &face = *BM_face_at_index(&const_cast<BMesh &>(bm), face_index);
38 const BMLoop *loop = BM_FACE_FIRST_LOOP(&face);
39 for ([[maybe_unused]] const int i : IndexRange(face.len)) {
40 const int index = BM_elem_index_get(loop);
41 vbo_data[index] = float4(orco_data[BM_elem_index_get(loop->v)], 0.0f);
42 loop = loop->next;
43 }
44 }
45 });
46 }
47 else {
48 const Span<int> corner_verts = mr.corner_verts;
49 threading::parallel_for(corner_verts.index_range(), 4096, [&](const IndexRange range) {
50 for (const int corner : range) {
51 vbo_data[corner] = float4(orco_data[corner_verts[corner]], 0.0f);
52 }
53 });
54 }
55 });
56}
57
58} // namespace blender::draw
const void * CustomData_get_layer(const CustomData *data, eCustomDataType type)
#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
constexpr int64_t size_in_bytes() const
Definition BLI_span.hh:502
constexpr int64_t size_in_bytes() const
Definition BLI_span.hh:269
constexpr IndexRange index_range() const
Definition BLI_span.hh:402
MutableSpan< T > data()
Extraction of Mesh data into VBO to feed to GPU.
format
void extract_orco(const MeshRenderData &mr, gpu::VertBuf &vbo)
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
void memory_bandwidth_bound_task(const int64_t approximate_bytes_touched, const Function &function)
Definition BLI_task.hh:243
__int64 int64_t
Definition stdint.h:89
CustomData vert_data