71 return std::visit([](
const auto& vec) -> std::optional<TextureAccess> {
72 using T =
typename std::decay_t<
decltype(vec)>::value_type;
76 "as_texture_access: empty variant");
82 if constexpr (std::is_same_v<T, std::complex<double>>) {
84 "as_texture_access: complex<double> (RG64F) is not a sampled "
85 "image format in Vulkan. Use complex<float> for RG32F.");
89 if constexpr (std::is_same_v<T, glm::mat4>) {
91 "as_texture_access: mat4 layout is ambiguous for texel upload. "
92 "Unpack each column to a vec4 and use vector<glm::vec4>.");
98 if constexpr (std::is_same_v<T, uint8_t>) {
101 .byte_count = vec.size() *
sizeof(T),
106 if constexpr (std::is_same_v<T, uint16_t>) {
109 .byte_count = vec.size() *
sizeof(T),
114 if constexpr (std::is_same_v<T, uint32_t>) {
117 .byte_count = vec.size() *
sizeof(T),
122 if constexpr (std::is_same_v<T, float>) {
125 .byte_count = vec.size() *
sizeof(T),
130 if constexpr (std::is_same_v<T, glm::vec2>
131 || std::is_same_v<T, std::complex<float>>) {
134 .byte_count = vec.size() *
sizeof(T),
139 if constexpr (std::is_same_v<T, glm::vec4>) {
142 .byte_count = vec.size() *
sizeof(T),
149 if constexpr (std::is_same_v<T, double>) {
151 "as_texture_access: double narrowed to float for texel upload. "
152 "Precision beyond float range is lost.");
157 for (
size_t i = 0; i < vec.size(); ++i) {
158 dst[i] =
static_cast<float>(vec[i]);
167 if constexpr (std::is_same_v<T, glm::vec3>) {
169 "as_texture_access: vec3 promoted to vec4 (W=0). "
170 "RGB32F is not a universally-supported sampled image format in Vulkan.");
175 for (
size_t i = 0; i < vec.size(); ++i) {
176 dst[i] = glm::vec4(vec[i], 0.0F);
185 "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.
size_t bytes_per_texel() const noexcept
Bytes per texel for this format.
uint32_t channel_count() const noexcept
Number of channels (components per texel).
Memory-compatible view of a DataVariant for texel upload.