Blender V5.3
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_types.hh"
10#include "BLI_generic_span.hh"
11#include "BLI_math_color_c.hh"
14#include "BLI_string_ref.hh"
15
16#include "GPU_vertex_format.hh"
17
19
20namespace blender {
21
22namespace gpu {
23class VertBuf;
24}
25
26namespace bke {
27enum class AttrType : int16_t;
28}
29
35constexpr int COMPONENT_LEN_SCALAR = 3;
36
37namespace draw {
38
42template<typename T> struct AttributeConverter {
43 using VBOType = void;
44};
45
46template<> struct AttributeConverter<bool> {
51 static VBOType convert(const bool &value)
52 {
53 return VBOType(value);
54 }
55};
76template<> struct AttributeConverter<int2> {
77 using VBOType = float2;
79 static constexpr int gpu_component_len = 2;
81 static VBOType convert(const int2 &value)
82 {
83 return float2(value.x, value.y);
84 }
85};
86template<> struct AttributeConverter<float> {
91 static VBOType convert(const float &value)
92 {
93 return VBOType(value);
94 }
95};
96template<> struct AttributeConverter<float2> {
97 using VBOType = float2;
99 static constexpr int gpu_component_len = 2;
101 static VBOType convert(const float2 &value)
102 {
103 return value;
104 }
105};
106template<> struct AttributeConverter<float3> {
109 static constexpr int gpu_component_len = 3;
111 static VBOType convert(const float3 &value)
112 {
113 return value;
114 }
115};
117 /* 16 bits are required to store the color in linear space without precision loss. */
120 static constexpr int gpu_component_len = 4;
122 static VBOType convert(const ColorGeometry4b &value)
123 {
124 float3 rgb = {BLI_color_from_srgb_table[value.r],
128 return {unit_float_to_ushort_clamp(rgb[0]),
131 ushort(value.a * 257)};
132 }
133};
137 static constexpr int gpu_component_len = 4;
139 static VBOType convert(const ColorGeometry4f &value)
140 {
141 return value;
142 }
143};
144template<> struct AttributeConverter<math::Quaternion> {
147 static constexpr int gpu_component_len = 4;
149 static VBOType convert(const math::Quaternion &value)
150 {
151 return float4(value.w, value.x, value.y, value.z);
152 }
153};
154template<> struct AttributeConverter<float4> {
157 static constexpr int gpu_component_len = 4;
159 static VBOType convert(const float4 &value)
160 {
161 return value;
162 }
163};
164
166
168
169} // namespace draw
170} // namespace blender
ChannelStorageType r
ChannelStorageType g
ChannelStorageType b
ChannelStorageType a
#define attribute(slot)
void vertbuf_data_extract_direct(const GSpan attribute, gpu::VertBuf &vbo)
GPUVertFormat init_format_for_attribute(const bke::AttrType data_type, const StringRef vbo_name)
QuaternionBase< float > Quaternion
BMesh Iterators.
constexpr int COMPONENT_LEN_SCALAR
unsigned short ushort
Definition BKE_text.h:56
@ GPU_FETCH_INT_TO_FLOAT_UNIT
VecBase< float, 4 > float4
float BLI_color_from_srgb_table[256]
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
BLI_INLINE void IMB_colormanagement_rec709_to_scene_linear(float scene_linear[3], const float rec709[3])
MINLINE unsigned short unit_float_to_ushort_clamp(float val)
ColorSceneLinear4f< eAlpha::Premultiplied > ColorGeometry4f
VecBase< float, 3 > float3
VecBase< uint16_t, 4 > ushort4
signed char int8_t
Definition BKE_text.h:76
ColorSceneLinearByteEncoded4b< eAlpha::Premultiplied > ColorGeometry4b
signed short int16_t
Definition BKE_text.h:77
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
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
static VBOType convert(const float4 &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)