1 #pragma once
2 
3 #include <cstdint>
4 #include <cstdlib>
5 
6 namespace Draw {
7 
8 enum class DataFormat : uint8_t {
9 	UNDEFINED,
10 
11 	R8_UNORM,
12 	R8G8_UNORM,
13 	R8G8B8_UNORM,
14 
15 	R8G8B8A8_UNORM,
16 	R8G8B8A8_UNORM_SRGB,
17 	B8G8R8A8_UNORM,  // D3D style
18 	B8G8R8A8_UNORM_SRGB,  // D3D style
19 
20 	R8G8B8A8_SNORM,
21 	R8G8B8A8_UINT,
22 	R8G8B8A8_SINT,
23 
24 	R4G4_UNORM_PACK8,
25 	A4R4G4B4_UNORM_PACK16,  // A4 in the UPPER bit
26 	B4G4R4A4_UNORM_PACK16,
27 	R4G4B4A4_UNORM_PACK16,
28 	R5G6B5_UNORM_PACK16,
29 	B5G6R5_UNORM_PACK16,
30 	R5G5B5A1_UNORM_PACK16, // A1 in the LOWER bit
31 	B5G5R5A1_UNORM_PACK16, // A1 in the LOWER bit
32 	A1R5G5B5_UNORM_PACK16, // A1 in the UPPER bit.
33 	A1B5G5R5_UNORM_PACK16, // A1 in the UPPER bit. OpenGL-only.
34 
35 	R16_FLOAT,
36 	R16G16_FLOAT,
37 	R16G16B16A16_FLOAT,
38 
39 	R32_FLOAT,
40 	R32G32_FLOAT,
41 	R32G32B32_FLOAT,
42 	R32G32B32A32_FLOAT,
43 
44 	// Block compression formats.
45 	// These are modern names for DXT and friends, now patent free.
46 	// https://msdn.microsoft.com/en-us/library/bb694531.aspx
47 	BC1_RGBA_UNORM_BLOCK,
48 	BC1_RGBA_SRGB_BLOCK,
49 	BC2_UNORM_BLOCK,  // 4-bit straight alpha + DXT1 color. Usually not worth using
50 	BC2_SRGB_BLOCK,
51 	BC3_UNORM_BLOCK,  // 3-bit alpha with 2 ref values (+ magic) + DXT1 color
52 	BC3_SRGB_BLOCK,
53 	BC4_UNORM_BLOCK,  // 1-channel, same storage as BC3 alpha
54 	BC4_SNORM_BLOCK,
55 	BC5_UNORM_BLOCK,  // 2-channel RG, each has same storage as BC3 alpha
56 	BC5_SNORM_BLOCK,
57 	BC6H_UFLOAT_BLOCK,  // TODO
58 	BC6H_SFLOAT_BLOCK,
59 	BC7_UNORM_BLOCK,    // Highly advanced, very expensive to compress, very good quality.
60 	BC7_SRGB_BLOCK,
61 
62 	ETC1,
63 
64 	S8,
65 	D16,
66 	D24_S8,
67 	D32F,
68 	D32F_S8,
69 };
70 
71 size_t DataFormatSizeInBytes(DataFormat fmt);
72 bool DataFormatIsDepthStencil(DataFormat fmt);
DataFormatIsColor(DataFormat fmt)73 inline bool DataFormatIsColor(DataFormat fmt) {
74 	return !DataFormatIsDepthStencil(fmt);
75 }
76 
77 void ConvertFromRGBA8888(uint8_t *dst, const uint8_t *src, uint32_t dstStride, uint32_t srcStride, uint32_t width, uint32_t height, DataFormat format);
78 void ConvertFromBGRA8888(uint8_t *dst, const uint8_t *src, uint32_t dstStride, uint32_t srcStride, uint32_t width, uint32_t height, DataFormat format);
79 void ConvertToD32F(uint8_t *dst, const uint8_t *src, uint32_t dstStride, uint32_t srcStride, uint32_t width, uint32_t height, DataFormat format);
80 
81 }  // namespace
82