Blender V5.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
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. */
23 static const GPUVertFormat format = GPU_vertformat_from_attribute(
24 "orco", gpu::VertAttrType::SFLOAT_32_32_32_32);
25
26 gpu::VertBufPtr vert_vbo = gpu::VertBufPtr(GPU_vertbuf_create_with_format(format));
27 GPU_vertbuf_data_alloc(*vert_vbo, mr.verts_num);
28 MutableSpan vbo_data = vert_vbo->data<float4>();
29 const int64_t bytes = orco_data.size_in_bytes() + vbo_data.size_in_bytes();
31 threading::parallel_for(IndexRange(mr.verts_num), 2048, [&](const IndexRange range) {
32 for (const int vert : range) {
33 vbo_data[vert] = float4(orco_data[vert], 0.0f);
34 }
35 });
36 });
37
39 gather_vert_to_corner_gpu(mr, cache, *vert_vbo, *vbo);
40 return vbo;
41}
42
43} // namespace blender::draw
constexpr IndexRange()=default
constexpr T * data() const
Definition BLI_span.hh:545
constexpr int64_t size_in_bytes() const
Definition BLI_span.hh:507
constexpr int64_t size_in_bytes() const
Definition BLI_span.hh:272
Extraction of Mesh data into VBO to feed to GPU.
gpu::VertBufPtr extract_orco(const MeshRenderData &mr, MeshBufferCache &cache)
void gather_vert_to_corner_gpu(const MeshRenderData &mr, MeshBufferCache &cache, gpu::VertBuf &src, gpu::VertBuf &dst)
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:69
void memory_bandwidth_bound_task(const int64_t approximate_bytes_touched, const Function &function)
Definition BLI_task.hh:251
__int64 int64_t
Definition BKE_text.h:90
gpu::VertBuf * GPU_vertbuf_create_on_device(const GPUVertFormat &format, uint v_len)
GPUVertFormat GPU_vertformat_from_attribute(StringRef name, gpu::VertAttrType type)
VecBase< float, 4 > float4
const void * CustomData_get_layer(const CustomData *data, eCustomDataType type)
void GPU_vertbuf_data_alloc(gpu::VertBuf &verts, uint v_len)
VecBase< float, 3 > float3
CustomData vert_data