2#include "../foray_basics.hpp"
3#include "../foray_vulkan.hpp"
11 template <
typename COMPONENT_T, COMPONENT_T ALPHA_FALLBACK_,
bool IS_FLOAT_,
bool IS_SIGNED_>
22 inline static constexpr bool IS_FLOAT = IS_FLOAT_;
24 inline static constexpr bool IS_SIGNED = IS_SIGNED_;
45 template <VkFormat FORMAT>
60 template <
typename COMPONENT_TRAITS_, u
int32_t COMPONENT_COUNT_>
63 template <
typename COMPONENT_TRAITS_>
67 using COMPONENT_TRAITS = COMPONENT_TRAITS_;
68 using COMPONENT =
typename COMPONENT_TRAITS_::COMPONENT;
69 inline static const uint32_t COMPONENT_COUNT = 4;
70 inline static constexpr uint32_t COMPONENT_STRIDE = 4;
71 inline static constexpr uint32_t BYTESTRIDE = COMPONENT_TRAITS::SIZE * COMPONENT_STRIDE;
74 inline static void WriteColor(
void* out, COMPONENT r, COMPONENT g, COMPONENT b, COMPONENT a)
76 COMPONENT* data =
reinterpret_cast<COMPONENT*
>(out);
84 inline static void WriteGrayscale(
void* out, COMPONENT y, COMPONENT a)
86 COMPONENT* data =
reinterpret_cast<COMPONENT*
>(out);
94 template <
typename COMPONENT_TRAITS_>
95 class ImageFormatTraitsBase<COMPONENT_TRAITS_, 3>
98 using COMPONENT_TRAITS = COMPONENT_TRAITS_;
99 using COMPONENT =
typename COMPONENT_TRAITS_::COMPONENT;
100 inline static constexpr uint32_t COMPONENT_COUNT = 3;
101 inline static constexpr uint32_t COMPONENT_STRIDE = 3;
102 inline static constexpr uint32_t BYTESTRIDE = COMPONENT_TRAITS::SIZE * COMPONENT_STRIDE;
105 inline static void WriteColor(
void* out, COMPONENT r, COMPONENT g, COMPONENT b, COMPONENT a)
107 COMPONENT* data =
reinterpret_cast<COMPONENT*
>(out);
114 inline static void WriteGrayscale(
void* out, COMPONENT y, COMPONENT a)
116 COMPONENT* data =
reinterpret_cast<COMPONENT*
>(out);
123 template <
typename COMPONENT_TRAITS_>
124 class ImageFormatTraitsBase<COMPONENT_TRAITS_, 2>
127 using COMPONENT_TRAITS = COMPONENT_TRAITS_;
128 using COMPONENT =
typename COMPONENT_TRAITS_::COMPONENT;
129 inline static constexpr uint32_t COMPONENT_COUNT = 2;
130 inline static constexpr uint32_t COMPONENT_STRIDE = 2;
131 inline static constexpr uint32_t BYTESTRIDE = COMPONENT_TRAITS::SIZE * COMPONENT_STRIDE;
134 inline static void WriteColor(
void* out, COMPONENT r, COMPONENT g, COMPONENT b, COMPONENT a)
136 COMPONENT* data =
reinterpret_cast<COMPONENT*
>(out);
142 inline static void WriteGrayscale(
void* out, COMPONENT y, COMPONENT a)
144 COMPONENT* data =
reinterpret_cast<COMPONENT*
>(out);
150 template <
typename COMPONENT_TRAITS_>
151 class ImageFormatTraitsBase<COMPONENT_TRAITS_, 1>
154 using COMPONENT_TRAITS = COMPONENT_TRAITS_;
155 using COMPONENT =
typename COMPONENT_TRAITS_::COMPONENT;
156 inline static constexpr uint32_t COMPONENT_COUNT = 1;
157 inline static constexpr uint32_t COMPONENT_STRIDE = 1;
158 inline static constexpr uint32_t BYTESTRIDE = COMPONENT_TRAITS::SIZE * COMPONENT_STRIDE;
161 inline static void WriteColor(
void* out, COMPONENT r, COMPONENT g, COMPONENT b, COMPONENT a)
163 COMPONENT* data =
reinterpret_cast<COMPONENT*
>(out);
168 inline static void WriteGrayscale(
void* out, COMPONENT y, COMPONENT a)
170 COMPONENT* data =
reinterpret_cast<COMPONENT*
>(out);
176#pragma region float half
178 class ImageFormatTraits<VkFormat::VK_FORMAT_R16G16B16A16_SFLOAT> :
public ImageFormatTraitsBase<ComponentTraits_Fp16, 4>
182 class ImageFormatTraits<VkFormat::VK_FORMAT_R16G16B16_SFLOAT> :
public ImageFormatTraitsBase<ComponentTraits_Fp16, 3>
186 class ImageFormatTraits<VkFormat::VK_FORMAT_R16G16_SFLOAT> :
public ImageFormatTraitsBase<ComponentTraits_Fp16, 2>
190 class ImageFormatTraits<VkFormat::VK_FORMAT_R16_SFLOAT> :
public ImageFormatTraitsBase<ComponentTraits_Fp16, 1>
194#pragma region float full
196 class ImageFormatTraits<VkFormat::VK_FORMAT_R32G32B32A32_SFLOAT> :
public ImageFormatTraitsBase<ComponentTraits_Fp32, 4>
200 class ImageFormatTraits<VkFormat::VK_FORMAT_R32G32B32_SFLOAT> :
public ImageFormatTraitsBase<ComponentTraits_Fp32, 3>
204 class ImageFormatTraits<VkFormat::VK_FORMAT_R32G32_SFLOAT> :
public ImageFormatTraitsBase<ComponentTraits_Fp32, 2>
208 class ImageFormatTraits<VkFormat::VK_FORMAT_R32_SFLOAT> :
public ImageFormatTraitsBase<ComponentTraits_Fp32, 1>
212#pragma region float double
214 class ImageFormatTraits<VkFormat::VK_FORMAT_R64G64B64A64_SFLOAT> :
public ImageFormatTraitsBase<ComponentTraits_Fp64, 4>
218 class ImageFormatTraits<VkFormat::VK_FORMAT_R64G64B64_SFLOAT> :
public ImageFormatTraitsBase<ComponentTraits_Fp64, 3>
222 class ImageFormatTraits<VkFormat::VK_FORMAT_R64G64_SFLOAT> :
public ImageFormatTraitsBase<ComponentTraits_Fp64, 2>
226 class ImageFormatTraits<VkFormat::VK_FORMAT_R64_SFLOAT> :
public ImageFormatTraitsBase<ComponentTraits_Fp64, 1>
230#pragma region integer 32 unsigned
232 class ImageFormatTraits<VkFormat::VK_FORMAT_R32G32B32A32_UINT> :
public ImageFormatTraitsBase<ComponentTraits_UInt32, 4>
236 class ImageFormatTraits<VkFormat::VK_FORMAT_R32G32B32_UINT> :
public ImageFormatTraitsBase<ComponentTraits_UInt32, 3>
240 class ImageFormatTraits<VkFormat::VK_FORMAT_R32G32_UINT> :
public ImageFormatTraitsBase<ComponentTraits_UInt32, 2>
244 class ImageFormatTraits<VkFormat::VK_FORMAT_R32_UINT> :
public ImageFormatTraitsBase<ComponentTraits_UInt32, 1>
248#pragma region integer 8 unsigned
250 class ImageFormatTraits<VkFormat::VK_FORMAT_R8G8B8A8_UINT> :
public ImageFormatTraitsBase<ComponentTraits_UInt8, 4>
254 class ImageFormatTraits<VkFormat::VK_FORMAT_R8G8B8_UINT> :
public ImageFormatTraitsBase<ComponentTraits_UInt8, 3>
258 class ImageFormatTraits<VkFormat::VK_FORMAT_R8G8_UINT> :
public ImageFormatTraitsBase<ComponentTraits_UInt8, 2>
262 class ImageFormatTraits<VkFormat::VK_FORMAT_R8_UINT> :
public ImageFormatTraitsBase<ComponentTraits_UInt8, 1>
266 class ImageFormatTraits<VkFormat::VK_FORMAT_R8G8B8A8_UNORM> :
public ImageFormatTraitsBase<ComponentTraits_UInt8, 4>
270 class ImageFormatTraits<VkFormat::VK_FORMAT_R8G8B8_UNORM> :
public ImageFormatTraitsBase<ComponentTraits_UInt8, 3>
274 class ImageFormatTraits<VkFormat::VK_FORMAT_R8G8_UNORM> :
public ImageFormatTraitsBase<ComponentTraits_UInt8, 2>
278 class ImageFormatTraits<VkFormat::VK_FORMAT_R8_UNORM> :
public ImageFormatTraitsBase<ComponentTraits_UInt8, 1>
282#pragma region integer packed 10 + 10 + 10 + 2 unsigned
285 class ImageFormatTraits<VkFormat::VK_FORMAT_A2R10G10B10_UINT_PACK32>
295 inline static void WriteColor(
void* out, COMPONENT r, COMPONENT g, COMPONENT b, COMPONENT a)
297 COMPONENT* data =
reinterpret_cast<COMPONENT*
>(out);
298 data[0] = ((a & 0b11) << 30) | ((r & 0b1111111111) << 20) | ((g & 0b1111111111) << 10) | (b & 0b1111111111);
302 inline static void WriteGrayscale(
void* out, COMPONENT y, COMPONENT a)
304 COMPONENT* data =
reinterpret_cast<COMPONENT*
>(out);
305 y = y & 0b1111111111;
306 data[0] = ((a & 0b11) << 30) | (y << 20) | (y << 20) | y;
Describes the traits of a component type.
Definition foray_imageformattraits.hpp:13
static constexpr bool IS_FLOAT
True if the internal representation is a floating point value.
Definition foray_imageformattraits.hpp:22
static constexpr COMPONENT ALPHA_FALLBACK
Full opacity alpha fallback value.
Definition foray_imageformattraits.hpp:20
static constexpr bool IS_SIGNED
True if the internal representation supports negative values.
Definition foray_imageformattraits.hpp:24
COMPONENT_T COMPONENT
Component type.
Definition foray_imageformattraits.hpp:16
static constexpr uint32_t SIZE
Size (bytes) of the component.
Definition foray_imageformattraits.hpp:18
Definition foray_dualbuffer.hpp:5
ComponentTraits< std::nullptr_t, nullptr, false, false > ComponentTraits_None
Definition foray_imageformattraits.hpp:27
ComponentTraits< uint32_t, 0b11, false, false > ComponentTraits_PackedAlpha2Color30
32 bit unsigned integer packed component type (2 bits alpha, 30 bits color, 1 component per texel,...
Definition foray_imageformattraits.hpp:42