41 return std::visit([](
const auto& vec) -> std::optional<TextureAccess> {
42 using T =
typename std::decay_t<
decltype(vec)>::value_type;
46 "as_texture_access: empty variant");
52 if constexpr (std::is_same_v<T, std::complex<double>>) {
54 "as_texture_access: complex<double> (RG64F) is not a sampled "
55 "image format in Vulkan. Use complex<float> for RG32F.");
59 if constexpr (std::is_same_v<T, glm::mat4>) {
61 "as_texture_access: mat4 layout is ambiguous for texel upload. "
62 "Unpack each column to a vec4 and use vector<glm::vec4>.");
68 if constexpr (std::is_same_v<T, uint8_t>) {
71 .byte_count = vec.size() *
sizeof(T),
76 if constexpr (std::is_same_v<T, uint16_t>) {
79 .byte_count = vec.size() *
sizeof(T),
84 if constexpr (std::is_same_v<T, uint32_t>) {
87 .byte_count = vec.size() *
sizeof(T),
92 if constexpr (std::is_same_v<T, float>) {
95 .byte_count = vec.size() *
sizeof(T),
100 if constexpr (std::is_same_v<T, glm::vec2>
101 || std::is_same_v<T, std::complex<float>>) {
104 .byte_count = vec.size() *
sizeof(T),
109 if constexpr (std::is_same_v<T, glm::vec4>) {
112 .byte_count = vec.size() *
sizeof(T),
119 if constexpr (std::is_same_v<T, double>) {
121 "as_texture_access: double narrowed to float for texel upload. "
122 "Precision beyond float range is lost.");
127 for (
size_t i = 0; i < vec.size(); ++i) {
128 dst[i] =
static_cast<float>(vec[i]);
137 if constexpr (std::is_same_v<T, glm::vec3>) {
139 "as_texture_access: vec3 promoted to vec4 (W=0). "
140 "RGB32F is not a universally-supported sampled image format in Vulkan.");
145 for (
size_t i = 0; i < vec.size(); ++i) {
146 dst[i] = glm::vec4(vec[i], 0.0F);
155 "as_texture_access: unhandled variant type {}",
std::variant< std::vector< double >, std::vector< float >, std::vector< uint8_t >, std::vector< uint16_t >, std::vector< uint32_t >, std::vector< std::complex< float > >, std::vector< std::complex< double > >, std::vector< glm::vec2 >, std::vector< glm::vec3 >, std::vector< glm::vec4 >, std::vector< glm::mat4 > > DataVariant
Multi-type data storage for different precision needs.
std::vector< std::byte > conversion_buffer
Promotion buffer.
uint32_t channel_count() const noexcept
Number of channels (components per texel).
Memory-compatible view of a DataVariant for texel upload.