Blender V4.3
attribute_convert.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2005 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#include "BLI_array_utils.hh"
10
11#include "BKE_attribute_math.hh"
12
13#include "GPU_vertex_buffer.hh"
14
15#include "attribute_convert.hh"
16
17namespace blender::draw {
18
20 const StringRefNull vbo_name)
21{
23 bke::attribute_math::convert_to_static_type(data_type, [&](auto dummy) {
24 using T = decltype(dummy);
25 using Converter = AttributeConverter<T>;
26 if constexpr (!std::is_void_v<typename Converter::VBOType>) {
28 vbo_name.c_str(),
29 Converter::gpu_component_type,
30 Converter::gpu_component_len,
31 Converter::gpu_fetch_mode);
32 }
33 });
34 return format;
35}
36
38{
39 bke::attribute_math::convert_to_static_type(attribute.type(), [&](auto dummy) {
40 using T = decltype(dummy);
41 using Converter = AttributeConverter<T>;
42 using VBOType = typename Converter::VBOType;
43 if constexpr (!std::is_void_v<VBOType>) {
44 const Span<T> src = attribute.typed<T>();
45 MutableSpan<VBOType> data = vbo.data<VBOType>();
46 if constexpr (std::is_same_v<T, VBOType>) {
47 array_utils::copy(src, data);
48 }
49 else {
50 threading::parallel_for(src.index_range(), 8192, [&](const IndexRange range) {
51 for (const int i : range) {
52 data[i] = Converter::convert(src[i]);
53 }
54 });
55 }
56 }
57 });
58}
59
60} // namespace blender::draw
uint GPU_vertformat_attr_add(GPUVertFormat *, const char *name, GPUVertCompType, uint comp_len, GPUVertFetchMode)
constexpr const char * c_str() const
format
void convert_to_static_type(const CPPType &cpp_type, const Func &func)
GPUVertFormat init_format_for_attribute(const eCustomDataType data_type, const StringRefNull vbo_name)
void vertbuf_data_extract_direct(const GSpan attribute, gpu::VertBuf &vbo)