Grindstone Game Engine v0.2.0
An open source game engine and toolkit.
Loading...
Searching...
No Matches
Dds.hpp
1#pragma once
2
3namespace Grindstone::Formats::DDS {
4 using DWORD = unsigned long;
5
7 DWORD dwSize = 32;
8 DWORD dwFlags;
9 DWORD dwFourCC;
10 DWORD dwRGBBitCount;
11 DWORD dwRBitMask;
12 DWORD dwGBitMask;
13 DWORD dwBBitMask;
14 DWORD dwABitMask;
15 };
16
17 constexpr DWORD DDPF_ALPHAPIXELS = 0x1;
18 constexpr DWORD DDPF_FOURCC = 0x4;
19 constexpr DWORD DDPF_RGB = 0x40;
20
21 constexpr DWORD DDSD_CAPS = 0x1;
22 constexpr DWORD DDSD_HEIGHT = 0x2;
23 constexpr DWORD DDSD_WIDTH = 0x4;
24 constexpr DWORD DDSD_PITCH = 0x8;
25 constexpr DWORD DDSD_PIXELFORMAT = 0x1000;
26 constexpr DWORD DDSD_MIPMAPCOUNT = 0x20000;
27 constexpr DWORD DDSD_LINEARSIZE = 0x80000;
28 constexpr DWORD DDSD_DEPTH = 0x800000;
29 constexpr DWORD DDSD_REQUIRED =
30 DDSD_CAPS |
31 DDSD_HEIGHT |
32 DDSD_WIDTH |
33 DDSD_PIXELFORMAT |
34 DDSD_LINEARSIZE;
35
36 struct DDSHeader {
37 DWORD dwSize = 124;
38 DWORD dwFlags;
39 DWORD dwHeight;
40 DWORD dwWidth;
41 DWORD dwPitchOrLinearSize;
42 DWORD dwDepth;
43 DWORD dwMipMapCount;
44 DWORD dwReserved1[11];
45 DDS_PIXELFORMAT ddspf;
46 DWORD dwCaps;
47 DWORD dwCaps2;
48 DWORD dwCaps3;
49 DWORD dwCaps4;
50 DWORD dwReserved2;
51 };
52
53 enum class DxgiFormat : uint32_t {
54 DXGI_FORMAT_UNKNOWN = 0,
55 DXGI_FORMAT_R32G32B32A32_TYPELESS = 1,
56 DXGI_FORMAT_R32G32B32A32_FLOAT = 2,
57 DXGI_FORMAT_R32G32B32A32_UINT = 3,
58 DXGI_FORMAT_R32G32B32A32_SINT = 4,
59 DXGI_FORMAT_R32G32B32_TYPELESS = 5,
60 DXGI_FORMAT_R32G32B32_FLOAT = 6,
61 DXGI_FORMAT_R32G32B32_UINT = 7,
62 DXGI_FORMAT_R32G32B32_SINT = 8,
63 DXGI_FORMAT_R16G16B16A16_TYPELESS = 9,
64 DXGI_FORMAT_R16G16B16A16_FLOAT = 10,
65 DXGI_FORMAT_R16G16B16A16_UNORM = 11,
66 DXGI_FORMAT_R16G16B16A16_UINT = 12,
67 DXGI_FORMAT_R16G16B16A16_SNORM = 13,
68 DXGI_FORMAT_R16G16B16A16_SINT = 14,
69 DXGI_FORMAT_R32G32_TYPELESS = 15,
70 DXGI_FORMAT_R32G32_FLOAT = 16,
71 DXGI_FORMAT_R32G32_UINT = 17,
72 DXGI_FORMAT_R32G32_SINT = 18,
73 DXGI_FORMAT_R32G8X24_TYPELESS = 19,
74 DXGI_FORMAT_D32_FLOAT_S8X24_UINT = 20,
75 DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS = 21,
76 DXGI_FORMAT_X32_TYPELESS_G8X24_UINT = 22,
77 DXGI_FORMAT_R10G10B10A2_TYPELESS = 23,
78 DXGI_FORMAT_R10G10B10A2_UNORM = 24,
79 DXGI_FORMAT_R10G10B10A2_UINT = 25,
80 DXGI_FORMAT_R11G11B10_FLOAT = 26,
81 DXGI_FORMAT_R8G8B8A8_TYPELESS = 27,
82 DXGI_FORMAT_R8G8B8A8_UNORM = 28,
83 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB = 29,
84 DXGI_FORMAT_R8G8B8A8_UINT = 30,
85 DXGI_FORMAT_R8G8B8A8_SNORM = 31,
86 DXGI_FORMAT_R8G8B8A8_SINT = 32,
87 DXGI_FORMAT_R16G16_TYPELESS = 33,
88 DXGI_FORMAT_R16G16_FLOAT = 34,
89 DXGI_FORMAT_R16G16_UNORM = 35,
90 DXGI_FORMAT_R16G16_UINT = 36,
91 DXGI_FORMAT_R16G16_SNORM = 37,
92 DXGI_FORMAT_R16G16_SINT = 38,
93 DXGI_FORMAT_R32_TYPELESS = 39,
94 DXGI_FORMAT_D32_FLOAT = 40,
95 DXGI_FORMAT_R32_FLOAT = 41,
96 DXGI_FORMAT_R32_UINT = 42,
97 DXGI_FORMAT_R32_SINT = 43,
98 DXGI_FORMAT_R24G8_TYPELESS = 44,
99 DXGI_FORMAT_D24_UNORM_S8_UINT = 45,
100 DXGI_FORMAT_R24_UNORM_X8_TYPELESS = 46,
101 DXGI_FORMAT_X24_TYPELESS_G8_UINT = 47,
102 DXGI_FORMAT_R8G8_TYPELESS = 48,
103 DXGI_FORMAT_R8G8_UNORM = 49,
104 DXGI_FORMAT_R8G8_UINT = 50,
105 DXGI_FORMAT_R8G8_SNORM = 51,
106 DXGI_FORMAT_R8G8_SINT = 52,
107 DXGI_FORMAT_R16_TYPELESS = 53,
108 DXGI_FORMAT_R16_FLOAT = 54,
109 DXGI_FORMAT_D16_UNORM = 55,
110 DXGI_FORMAT_R16_UNORM = 56,
111 DXGI_FORMAT_R16_UINT = 57,
112 DXGI_FORMAT_R16_SNORM = 58,
113 DXGI_FORMAT_R16_SINT = 59,
114 DXGI_FORMAT_R8_TYPELESS = 60,
115 DXGI_FORMAT_R8_UNORM = 61,
116 DXGI_FORMAT_R8_UINT = 62,
117 DXGI_FORMAT_R8_SNORM = 63,
118 DXGI_FORMAT_R8_SINT = 64,
119 DXGI_FORMAT_A8_UNORM = 65,
120 DXGI_FORMAT_R1_UNORM = 66,
121 DXGI_FORMAT_R9G9B9E5_SHAREDEXP = 67,
122 DXGI_FORMAT_R8G8_B8G8_UNORM = 68,
123 DXGI_FORMAT_G8R8_G8B8_UNORM = 69,
124 DXGI_FORMAT_BC1_TYPELESS = 70,
125 DXGI_FORMAT_BC1_UNORM = 71,
126 DXGI_FORMAT_BC1_UNORM_SRGB = 72,
127 DXGI_FORMAT_BC2_TYPELESS = 73,
128 DXGI_FORMAT_BC2_UNORM = 74,
129 DXGI_FORMAT_BC2_UNORM_SRGB = 75,
130 DXGI_FORMAT_BC3_TYPELESS = 76,
131 DXGI_FORMAT_BC3_UNORM = 77,
132 DXGI_FORMAT_BC3_UNORM_SRGB = 78,
133 DXGI_FORMAT_BC4_TYPELESS = 79,
134 DXGI_FORMAT_BC4_UNORM = 80,
135 DXGI_FORMAT_BC4_SNORM = 81,
136 DXGI_FORMAT_BC5_TYPELESS = 82,
137 DXGI_FORMAT_BC5_UNORM = 83,
138 DXGI_FORMAT_BC5_SNORM = 84,
139 DXGI_FORMAT_B5G6R5_UNORM = 85,
140 DXGI_FORMAT_B5G5R5A1_UNORM = 86,
141 DXGI_FORMAT_B8G8R8A8_UNORM = 87,
142 DXGI_FORMAT_B8G8R8X8_UNORM = 88,
143 DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM = 89,
144 DXGI_FORMAT_B8G8R8A8_TYPELESS = 90,
145 DXGI_FORMAT_B8G8R8A8_UNORM_SRGB = 91,
146 DXGI_FORMAT_B8G8R8X8_TYPELESS = 92,
147 DXGI_FORMAT_B8G8R8X8_UNORM_SRGB = 93,
148 DXGI_FORMAT_BC6H_TYPELESS = 94,
149 DXGI_FORMAT_BC6H_UF16 = 95,
150 DXGI_FORMAT_BC6H_SF16 = 96,
151 DXGI_FORMAT_BC7_TYPELESS = 97,
152 DXGI_FORMAT_BC7_UNORM = 98,
153 DXGI_FORMAT_BC7_UNORM_SRGB = 99,
154 DXGI_FORMAT_AYUV = 100,
155 DXGI_FORMAT_Y410 = 101,
156 DXGI_FORMAT_Y416 = 102,
157 DXGI_FORMAT_NV12 = 103,
158 DXGI_FORMAT_P010 = 104,
159 DXGI_FORMAT_P016 = 105,
160 DXGI_FORMAT_420_OPAQUE = 106,
161 DXGI_FORMAT_YUY2 = 107,
162 DXGI_FORMAT_Y210 = 108,
163 DXGI_FORMAT_Y216 = 109,
164 DXGI_FORMAT_NV11 = 110,
165 DXGI_FORMAT_AI44 = 111,
166 DXGI_FORMAT_IA44 = 112,
167 DXGI_FORMAT_P8 = 113,
168 DXGI_FORMAT_A8P8 = 114,
169 DXGI_FORMAT_B4G4R4A4_UNORM = 115,
170 DXGI_FORMAT_P208 = 130,
171 DXGI_FORMAT_V208 = 131,
172 DXGI_FORMAT_V408 = 132,
173 DXGI_FORMAT_SAMPLER_FEEDBACK_MIN_MIP_OPAQUE,
174 DXGI_FORMAT_SAMPLER_FEEDBACK_MIP_REGION_USED_OPAQUE,
175 DXGI_FORMAT_FORCE_UINT = 0xffffffff
176 };
177
178 enum class D3d10ResourceDimension : uint32_t {
179 D3D10_RESOURCE_DIMENSION_UNKNOWN = 0,
180 D3D10_RESOURCE_DIMENSION_BUFFER = 1,
181 D3D10_RESOURCE_DIMENSION_TEXTURE1D = 2,
182 D3D10_RESOURCE_DIMENSION_TEXTURE2D = 3,
183 D3D10_RESOURCE_DIMENSION_TEXTURE3D = 4
184 };
185
187 DxgiFormat dxgiFormat = DxgiFormat::DXGI_FORMAT_UNKNOWN;
188 D3d10ResourceDimension resourceDimension = D3d10ResourceDimension::D3D10_RESOURCE_DIMENSION_TEXTURE2D;
189 uint32_t miscFlag;
190 uint32_t arraySize;
191 uint32_t miscFlags2;
192 };
193
194 constexpr DWORD MakeFourCC(char c0, char c1, char c2, char c3) {
195 return ((DWORD)(char)(c0) | ((DWORD)(char)(c1) << 8) | \
196 ((DWORD)(char)(c2) << 16) | ((DWORD)(char)(c3) << 24));
197 }
198
199 constexpr DWORD MakeFourCCStr(const char* str) {
200 return MakeFourCC(str[0], str[1], str[2], str[3]);
201 }
202
203 constexpr DWORD FOURCC_R16 = 111;
204 constexpr DWORD FOURCC_RG16 = 112;
205 constexpr DWORD FOURCC_RGBA16 = 113;
206 constexpr DWORD FOURCC_R32 = 114;
207 constexpr DWORD FOURCC_RG32 = 115;
208 constexpr DWORD FOURCC_RGBA32 = 116;
209 constexpr DWORD FOURCC_DXT1 = MakeFourCC('D', 'X', 'T', '1');
210 constexpr DWORD FOURCC_DXT3 = MakeFourCC('D', 'X', 'T', '3');
211 constexpr DWORD FOURCC_DXT5 = MakeFourCC('D', 'X', 'T', '5');
212 constexpr DWORD FOURCC_BC4 = MakeFourCC('A', 'T', 'I', '1');
213 constexpr DWORD FOURCC_BC5 = MakeFourCC('A', 'T', 'I', '2');
214 constexpr DWORD FOURCC_DXGI = MakeFourCC('D', 'X', '1', '0');
215 constexpr DWORD FOURCC_RGB16 = MakeFourCC('H', 'D', 'R', 'I'); // This is made up, and not supported, but I decided to use it because I don't want an alpha channel
216
217 constexpr DWORD DXGI_BC6H = 95;
218
219 constexpr DWORD DDSCAPS_COMPLEX = 0x8;
220 constexpr DWORD DDSCAPS_MIPMAP = 0x400000;
221 constexpr DWORD DDSCAPS_TEXTURE = 0x1000;
222
223 constexpr DWORD DDSCAPS2_CUBEMAP = 0x200;
224 constexpr DWORD DDSCAPS2_CUBEMAP_POSITIVEX = 0x400;
225 constexpr DWORD DDSCAPS2_CUBEMAP_NEGATIVEX = 0x800;
226 constexpr DWORD DDSCAPS2_CUBEMAP_POSITIVEY = 0x1000;
227 constexpr DWORD DDSCAPS2_CUBEMAP_NEGATIVEY = 0x2000;
228 constexpr DWORD DDSCAPS2_CUBEMAP_POSITIVEZ = 0x4000;
229 constexpr DWORD DDSCAPS2_CUBEMAP_NEGATIVEZ = 0x8000;
230 constexpr DWORD DDSCAPS2_CUBEMAP_VOLUME = 0x200000;
231
232 constexpr DWORD DDS_CUBEMAP_ALLFACES =
233 DDSCAPS2_CUBEMAP |
234 DDSCAPS2_CUBEMAP_POSITIVEX |
235 DDSCAPS2_CUBEMAP_NEGATIVEX |
236 DDSCAPS2_CUBEMAP_POSITIVEY |
237 DDSCAPS2_CUBEMAP_NEGATIVEY |
238 DDSCAPS2_CUBEMAP_POSITIVEZ |
239 DDSCAPS2_CUBEMAP_NEGATIVEZ;
240}