Blender V4.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
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> {
41 static constexpr GPUVertCompType gpu_component_type = GPU_COMP_I32;
42 static constexpr int gpu_component_len = COMPONENT_LEN_SCALAR;
43 static constexpr GPUVertFetchMode gpu_fetch_mode = GPU_FETCH_INT_TO_FLOAT;
44 static VBOType convert(const bool &value)
45 {
46 return VBOType(value);
47 }
48};
49template<> struct AttributeConverter<int8_t> {
51 static constexpr GPUVertCompType gpu_component_type = GPU_COMP_I32;
52 static constexpr int gpu_component_len = COMPONENT_LEN_SCALAR;
53 static constexpr GPUVertFetchMode gpu_fetch_mode = GPU_FETCH_INT_TO_FLOAT;
54 static VBOType convert(const int8_t &value)
55 {
57 }
58};
59template<> struct AttributeConverter<int> {
61 static constexpr GPUVertCompType gpu_component_type = GPU_COMP_I32;
62 static constexpr int gpu_component_len = COMPONENT_LEN_SCALAR;
63 static constexpr GPUVertFetchMode gpu_fetch_mode = GPU_FETCH_INT_TO_FLOAT;
64 static VBOType convert(const int &value)
65 {
66 return int3(value);
67 }
68};
69template<> struct AttributeConverter<int2> {
70 using VBOType = int2;
71 static constexpr GPUVertCompType gpu_component_type = GPU_COMP_I32;
72 static constexpr int gpu_component_len = 2;
73 static constexpr GPUVertFetchMode gpu_fetch_mode = GPU_FETCH_INT_TO_FLOAT;
74 static VBOType convert(const int2 &value)
75 {
76 return int2(value.x, value.y);
77 }
78};
79template<> struct AttributeConverter<float> {
81 static constexpr GPUVertCompType gpu_component_type = GPU_COMP_F32;
82 static constexpr int gpu_component_len = COMPONENT_LEN_SCALAR;
83 static constexpr GPUVertFetchMode gpu_fetch_mode = GPU_FETCH_FLOAT;
84 static VBOType convert(const float &value)
85 {
86 return VBOType(value);
87 }
88};
89template<> struct AttributeConverter<float2> {
90 using VBOType = float2;
91 static constexpr GPUVertCompType gpu_component_type = GPU_COMP_F32;
92 static constexpr int gpu_component_len = 2;
93 static constexpr GPUVertFetchMode gpu_fetch_mode = GPU_FETCH_FLOAT;
94 static VBOType convert(const float2 &value)
95 {
96 return value;
97 }
98};
99template<> struct AttributeConverter<float3> {
101 static constexpr GPUVertCompType gpu_component_type = GPU_COMP_F32;
102 static constexpr int gpu_component_len = 3;
103 static constexpr GPUVertFetchMode gpu_fetch_mode = GPU_FETCH_FLOAT;
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. */
112 static constexpr GPUVertCompType gpu_component_type = GPU_COMP_U16;
113 static constexpr int gpu_component_len = 4;
114 static constexpr GPUVertFetchMode gpu_fetch_mode = GPU_FETCH_INT_TO_FLOAT_UNIT;
122};
125 static constexpr GPUVertCompType gpu_component_type = GPU_COMP_F32;
126 static constexpr int gpu_component_len = 4;
127 static constexpr GPUVertFetchMode gpu_fetch_mode = GPU_FETCH_FLOAT;
128 static VBOType convert(const ColorGeometry4f &value)
129 {
130 return value;
131 }
132};
133template<> struct AttributeConverter<math::Quaternion> {
135 static constexpr GPUVertCompType gpu_component_type = GPU_COMP_F32;
136 static constexpr int gpu_component_len = 4;
137 static constexpr GPUVertFetchMode gpu_fetch_mode = GPU_FETCH_FLOAT;
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
@ GPU_FETCH_INT_TO_FLOAT
GPUVertCompType
@ GPU_COMP_U16
@ GPU_COMP_F32
@ GPU_COMP_I32
constexpr int COMPONENT_LEN_SCALAR
draw_view in_light_buf[] float
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
#define unit_float_to_ushort_clamp(val)
float BLI_color_from_srgb_table[256]
GPUVertFormat init_format_for_attribute(const eCustomDataType data_type, const StringRefNull vbo_name)
void vertbuf_data_extract_direct(const GSpan attribute, gpu::VertBuf &vbo)
VecBase< float, 4 > float4
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
VecBase< int32_t, 3 > int3
ColorSceneLinear4f< eAlpha::Premultiplied > ColorGeometry4f
Definition BLI_color.hh:337
blender::VecBase< uint16_t, 4 > ushort4
VecBase< float, 3 > float3
signed char int8_t
Definition stdint.h:75
static VBOType convert(const ColorGeometry4b &value)
static VBOType convert(const ColorGeometry4f &value)
static VBOType convert(const bool &value)
static VBOType convert(const float2 &value)
static VBOType convert(const float3 &value)
static VBOType convert(const float &value)
static VBOType convert(const int2 &value)
static VBOType convert(const int8_t &value)
static VBOType convert(const int &value)
static VBOType convert(const math::Quaternion &value)