Blender V4.5
attribute_convert.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2005 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "BLI_color.hh"
10#include "BLI_generic_span.hh"
13#include "BLI_string_ref.hh"
14
15#include "DNA_customdata_types.h" /* #eCustomDataType. */
16
17#include "GPU_vertex_format.hh"
18
19namespace blender::gpu {
20class VertBuf;
21}
22
28constexpr int COMPONENT_LEN_SCALAR = 3;
29
30namespace blender::draw {
31
35template<typename T> struct AttributeConverter {
36 using VBOType = void;
37};
38
39template<> struct AttributeConverter<bool> {
44 static VBOType convert(const bool &value)
45 {
46 return VBOType(value);
47 }
48};
49template<> struct AttributeConverter<int8_t> {
54 static VBOType convert(const int8_t &value)
55 {
57 }
58};
69template<> struct AttributeConverter<int2> {
70 using VBOType = float2;
72 static constexpr int gpu_component_len = 2;
74 static VBOType convert(const int2 &value)
75 {
76 return float2(value.x, value.y);
77 }
78};
79template<> struct AttributeConverter<float> {
84 static VBOType convert(const float &value)
85 {
86 return VBOType(value);
87 }
88};
89template<> struct AttributeConverter<float2> {
90 using VBOType = float2;
92 static constexpr int gpu_component_len = 2;
94 static VBOType convert(const float2 &value)
95 {
96 return value;
97 }
98};
99template<> struct AttributeConverter<float3> {
102 static constexpr int gpu_component_len = 3;
104 static VBOType convert(const float3 &value)
105 {
106 return value;
107 }
108};
110 /* 16 bits are required to store the color in linear space without precision loss. */
113 static constexpr int gpu_component_len = 4;
122};
126 static constexpr int gpu_component_len = 4;
128 static VBOType convert(const ColorGeometry4f &value)
129 {
130 return value;
131 }
132};
133template<> struct AttributeConverter<math::Quaternion> {
136 static constexpr int gpu_component_len = 4;
138 static VBOType convert(const math::Quaternion &value)
139 {
140 return float4(value.w, value.x, value.y, value.z);
141 }
142};
143
145
147
148} // namespace blender::draw
unsigned short ushort
GPUVertFetchMode
@ GPU_FETCH_FLOAT
@ GPU_FETCH_INT_TO_FLOAT_UNIT
GPUVertCompType
@ GPU_COMP_U16
@ GPU_COMP_F32
constexpr int COMPONENT_LEN_SCALAR
ChannelStorageType r
Definition BLI_color.hh:93
ChannelStorageType g
Definition BLI_color.hh:93
ChannelStorageType b
Definition BLI_color.hh:93
ChannelStorageType a
Definition BLI_color.hh:93
MINLINE unsigned short unit_float_to_ushort_clamp(float val)
float BLI_color_from_srgb_table[256]
void vertbuf_data_extract_direct(const GSpan attribute, gpu::VertBuf &vbo)
GPUVertFormat init_format_for_attribute(const eCustomDataType data_type, const StringRef vbo_name)
QuaternionBase< float > Quaternion
VecBase< float, 4 > float4
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
ColorSceneLinear4f< eAlpha::Premultiplied > ColorGeometry4f
Definition BLI_color.hh:342
blender::VecBase< uint16_t, 4 > ushort4
VecBase< float, 3 > float3
ColorSceneLinearByteEncoded4b< eAlpha::Premultiplied > ColorGeometry4b
Definition BLI_color.hh:343
static VBOType convert(const ColorGeometry4b &value)
static VBOType convert(const ColorGeometry4f &value)
VecBase< float, COMPONENT_LEN_SCALAR > VBOType
static constexpr GPUVertCompType gpu_component_type
static constexpr GPUVertFetchMode gpu_fetch_mode
static VBOType convert(const bool &value)
static VBOType convert(const float2 &value)
static constexpr GPUVertCompType gpu_component_type
static constexpr GPUVertFetchMode gpu_fetch_mode
static VBOType convert(const float3 &value)
static constexpr GPUVertFetchMode gpu_fetch_mode
static constexpr GPUVertCompType gpu_component_type
VecBase< float, COMPONENT_LEN_SCALAR > VBOType
static constexpr GPUVertFetchMode gpu_fetch_mode
static constexpr GPUVertCompType gpu_component_type
static VBOType convert(const float &value)
static constexpr GPUVertCompType gpu_component_type
static VBOType convert(const int2 &value)
static constexpr GPUVertFetchMode gpu_fetch_mode
VecBase< float, COMPONENT_LEN_SCALAR > VBOType
static VBOType convert(const int8_t &value)
static constexpr GPUVertFetchMode gpu_fetch_mode
static constexpr GPUVertCompType gpu_component_type
static constexpr GPUVertCompType gpu_component_type
VecBase< float, COMPONENT_LEN_SCALAR > VBOType
static VBOType convert(const int &value)
static constexpr GPUVertFetchMode gpu_fetch_mode
static VBOType convert(const math::Quaternion &value)