Blender V5.0
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.h"
14#include "BLI_string_ref.hh"
15
16#include "GPU_vertex_format.hh"
17
19
20namespace blender::gpu {
21class VertBuf;
22}
23
24namespace blender::bke {
25enum class AttrType : int16_t;
26}
27
33constexpr int COMPONENT_LEN_SCALAR = 3;
34
35namespace blender::draw {
36
40template<typename T> struct AttributeConverter {
41 using VBOType = void;
42};
43
44template<> struct AttributeConverter<bool> {
49 static VBOType convert(const bool &value)
50 {
51 return VBOType(value);
52 }
53};
54template<> struct AttributeConverter<int8_t> {
59 static VBOType convert(const int8_t &value)
60 {
62 }
63};
74template<> struct AttributeConverter<int2> {
75 using VBOType = float2;
77 static constexpr int gpu_component_len = 2;
79 static VBOType convert(const int2 &value)
80 {
81 return float2(value.x, value.y);
82 }
83};
84template<> struct AttributeConverter<float> {
89 static VBOType convert(const float &value)
90 {
91 return VBOType(value);
92 }
93};
94template<> struct AttributeConverter<float2> {
95 using VBOType = float2;
97 static constexpr int gpu_component_len = 2;
99 static VBOType convert(const float2 &value)
100 {
101 return value;
102 }
103};
104template<> struct AttributeConverter<float3> {
107 static constexpr int gpu_component_len = 3;
109 static VBOType convert(const float3 &value)
110 {
111 return value;
112 }
113};
115 /* 16 bits are required to store the color in linear space without precision loss. */
118 static constexpr int gpu_component_len = 4;
120 static VBOType convert(const ColorGeometry4b &value)
121 {
126 return {unit_float_to_ushort_clamp(rgb[0]),
129 ushort(value.a * 257)};
130 }
131};
135 static constexpr int gpu_component_len = 4;
137 static VBOType convert(const ColorGeometry4f &value)
138 {
139 return value;
140 }
141};
142template<> struct AttributeConverter<math::Quaternion> {
145 static constexpr int gpu_component_len = 4;
147 static VBOType convert(const math::Quaternion &value)
148 {
149 return float4(value.w, value.x, value.y, value.z);
150 }
151};
152
154
156
157} // namespace blender::draw
unsigned short ushort
GPUVertFetchMode
@ GPU_FETCH_FLOAT
@ GPU_FETCH_INT_TO_FLOAT_UNIT
GPUVertCompType
@ GPU_COMP_U16
@ GPU_COMP_F32
BLI_INLINE void IMB_colormanagement_rec709_to_scene_linear(float scene_linear[3], const float rec709[3])
constexpr int COMPONENT_LEN_SCALAR
ChannelStorageType r
ChannelStorageType g
ChannelStorageType b
ChannelStorageType a
nullptr float
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 bke::AttrType 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
blender::VecBase< uint16_t, 4 > ushort4
VecBase< float, 3 > float3
ColorSceneLinearByteEncoded4b< eAlpha::Premultiplied > ColorGeometry4b
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)