0.7.0
dx.hpp
1 
29 #pragma once
30 
31 #include "format.hpp"
32 #include <array>
33 
34 namespace gli
35 {
36  class dx
37  {
38  public:
39  #define GLI_MAKEFOURCC(ch0, ch1, ch2, ch3) \
40  (std::uint32_t)( \
41  (((std::uint32_t)(std::uint8_t)(ch3) << 24) & 0xFF000000) | \
42  (((std::uint32_t)(std::uint8_t)(ch2) << 16) & 0x00FF0000) | \
43  (((std::uint32_t)(std::uint8_t)(ch1) << 8) & 0x0000FF00) | \
44  ((std::uint32_t)(std::uint8_t)(ch0) & 0x000000FF) )
45 
46  enum D3DFORMAT
47  {
48  D3DFMT_UNKNOWN = 0,
49 
50  D3DFMT_R8G8B8 = 20,
51  D3DFMT_A8R8G8B8 = 21,
52  D3DFMT_X8R8G8B8 = 22,
53  D3DFMT_R5G6B5 = 23,
54  D3DFMT_X1R5G5B5 = 24,
55  D3DFMT_A1R5G5B5 = 25,
56  D3DFMT_A4R4G4B4 = 26,
57  D3DFMT_R3G3B2 = 27,
58  D3DFMT_A8 = 28,
59  D3DFMT_A8R3G3B2 = 29,
60  D3DFMT_X4R4G4B4 = 30,
61  D3DFMT_A2B10G10R10 = 31,
62  D3DFMT_A8B8G8R8 = 32,
63  D3DFMT_X8B8G8R8 = 33,
64  D3DFMT_G16R16 = 34,
65  D3DFMT_A2R10G10B10 = 35,
66  D3DFMT_A16B16G16R16 = 36,
67 
68  D3DFMT_A8P8 = 40,
69  D3DFMT_P8 = 41,
70 
71  D3DFMT_L8 = 50,
72  D3DFMT_A8L8 = 51,
73  D3DFMT_A4L4 = 52,
74 
75  D3DFMT_V8U8 = 60,
76  D3DFMT_L6V5U5 = 61,
77  D3DFMT_X8L8V8U8 = 62,
78  D3DFMT_Q8W8V8U8 = 63,
79  D3DFMT_V16U16 = 64,
80  D3DFMT_A2W10V10U10 = 67,
81 
82  D3DFMT_UYVY = GLI_MAKEFOURCC('U', 'Y', 'V', 'Y'),
83  D3DFMT_R8G8_B8G8 = GLI_MAKEFOURCC('R', 'G', 'B', 'G'),
84  D3DFMT_YUY2 = GLI_MAKEFOURCC('Y', 'U', 'Y', '2'),
85  D3DFMT_G8R8_G8B8 = GLI_MAKEFOURCC('G', 'R', 'G', 'B'),
86  D3DFMT_DXT1 = GLI_MAKEFOURCC('D', 'X', 'T', '1'),
87  D3DFMT_DXT2 = GLI_MAKEFOURCC('D', 'X', 'T', '2'),
88  D3DFMT_DXT3 = GLI_MAKEFOURCC('D', 'X', 'T', '3'),
89  D3DFMT_DXT4 = GLI_MAKEFOURCC('D', 'X', 'T', '4'),
90  D3DFMT_DXT5 = GLI_MAKEFOURCC('D', 'X', 'T', '5'),
91 
92  D3DFMT_ATI1 = GLI_MAKEFOURCC('A', 'T', 'I', '1'),
93  D3DFMT_AT1N = GLI_MAKEFOURCC('A', 'T', '1', 'N'),
94  D3DFMT_ATI2 = GLI_MAKEFOURCC('A', 'T', 'I', '2'),
95  D3DFMT_AT2N = GLI_MAKEFOURCC('A', 'T', '2', 'N'),
96 
97  D3DFMT_ETC = GLI_MAKEFOURCC('E', 'T', 'C', ' '),
98  D3DFMT_ETC1 = GLI_MAKEFOURCC('E', 'T', 'C', '1'),
99  D3DFMT_ATC = GLI_MAKEFOURCC('A', 'T', 'C', ' '),
100  D3DFMT_ATCA = GLI_MAKEFOURCC('A', 'T', 'C', 'A'),
101  D3DFMT_ATCI = GLI_MAKEFOURCC('A', 'T', 'C', 'I'),
102 
103  D3DFMT_POWERVR_2BPP = GLI_MAKEFOURCC('P', 'T', 'C', '2'),
104  D3DFMT_POWERVR_4BPP = GLI_MAKEFOURCC('P', 'T', 'C', '4'),
105 
106  D3DFMT_D16_LOCKABLE = 70,
107  D3DFMT_D32 = 71,
108  D3DFMT_D15S1 = 73,
109  D3DFMT_D24S8 = 75,
110  D3DFMT_D24X8 = 77,
111  D3DFMT_D24X4S4 = 79,
112  D3DFMT_D16 = 80,
113 
114  D3DFMT_D32F_LOCKABLE = 82,
115  D3DFMT_D24FS8 = 83,
116 
117  D3DFMT_L16 = 81,
118 
119  D3DFMT_VERTEXDATA =100,
120  D3DFMT_INDEX16 =101,
121  D3DFMT_INDEX32 =102,
122 
123  D3DFMT_Q16W16V16U16 =110,
124 
125  D3DFMT_MULTI2_ARGB8 = GLI_MAKEFOURCC('M','E','T','1'),
126 
127  D3DFMT_R16F = 111,
128  D3DFMT_G16R16F = 112,
129  D3DFMT_A16B16G16R16F = 113,
130 
131  D3DFMT_R32F = 114,
132  D3DFMT_G32R32F = 115,
133  D3DFMT_A32B32G32R32F = 116,
134 
135  D3DFMT_CxV8U8 = 117,
136 
137  D3DFMT_DX10 = GLI_MAKEFOURCC('D', 'X', '1', '0'),
138 
139  D3DFMT_FORCE_DWORD = 0x7fffffff
140  };
141 
142  enum dxgiFormat
143  {
144  DXGI_FORMAT_UNKNOWN = 0,
145  DXGI_FORMAT_R32G32B32A32_TYPELESS = 1,
146  DXGI_FORMAT_R32G32B32A32_FLOAT = 2,
147  DXGI_FORMAT_R32G32B32A32_UINT = 3,
148  DXGI_FORMAT_R32G32B32A32_SINT = 4,
149  DXGI_FORMAT_R32G32B32_TYPELESS = 5,
150  DXGI_FORMAT_R32G32B32_FLOAT = 6,
151  DXGI_FORMAT_R32G32B32_UINT = 7,
152  DXGI_FORMAT_R32G32B32_SINT = 8,
153  DXGI_FORMAT_R16G16B16A16_TYPELESS = 9,
154  DXGI_FORMAT_R16G16B16A16_FLOAT = 10,
155  DXGI_FORMAT_R16G16B16A16_UNORM = 11,
156  DXGI_FORMAT_R16G16B16A16_UINT = 12,
157  DXGI_FORMAT_R16G16B16A16_SNORM = 13,
158  DXGI_FORMAT_R16G16B16A16_SINT = 14,
159  DXGI_FORMAT_R32G32_TYPELESS = 15,
160  DXGI_FORMAT_R32G32_FLOAT = 16,
161  DXGI_FORMAT_R32G32_UINT = 17,
162  DXGI_FORMAT_R32G32_SINT = 18,
163  DXGI_FORMAT_R32G8X24_TYPELESS = 19,
164  DXGI_FORMAT_D32_FLOAT_S8X24_UINT = 20,
165  DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS = 21,
166  DXGI_FORMAT_X32_TYPELESS_G8X24_UINT = 22,
167  DXGI_FORMAT_R10G10B10A2_TYPELESS = 23,
168  DXGI_FORMAT_R10G10B10A2_UNORM = 24,
169  DXGI_FORMAT_R10G10B10A2_UINT = 25,
170  DXGI_FORMAT_R11G11B10_FLOAT = 26,
171  DXGI_FORMAT_R8G8B8A8_TYPELESS = 27,
172  DXGI_FORMAT_R8G8B8A8_UNORM = 28,
173  DXGI_FORMAT_R8G8B8A8_UNORM_SRGB = 29,
174  DXGI_FORMAT_R8G8B8A8_UINT = 30,
175  DXGI_FORMAT_R8G8B8A8_SNORM = 31,
176  DXGI_FORMAT_R8G8B8A8_SINT = 32,
177  DXGI_FORMAT_R16G16_TYPELESS = 33,
178  DXGI_FORMAT_R16G16_FLOAT = 34,
179  DXGI_FORMAT_R16G16_UNORM = 35,
180  DXGI_FORMAT_R16G16_UINT = 36,
181  DXGI_FORMAT_R16G16_SNORM = 37,
182  DXGI_FORMAT_R16G16_SINT = 38,
183  DXGI_FORMAT_R32_TYPELESS = 39,
184  DXGI_FORMAT_D32_FLOAT = 40,
185  DXGI_FORMAT_R32_FLOAT = 41,
186  DXGI_FORMAT_R32_UINT = 42,
187  DXGI_FORMAT_R32_SINT = 43,
188  DXGI_FORMAT_R24G8_TYPELESS = 44,
189  DXGI_FORMAT_D24_UNORM_S8_UINT = 45,
190  DXGI_FORMAT_R24_UNORM_X8_TYPELESS = 46,
191  DXGI_FORMAT_X24_TYPELESS_G8_UINT = 47,
192  DXGI_FORMAT_R8G8_TYPELESS = 48,
193  DXGI_FORMAT_R8G8_UNORM = 49,
194  DXGI_FORMAT_R8G8_UINT = 50,
195  DXGI_FORMAT_R8G8_SNORM = 51,
196  DXGI_FORMAT_R8G8_SINT = 52,
197  DXGI_FORMAT_R16_TYPELESS = 53,
198  DXGI_FORMAT_R16_FLOAT = 54,
199  DXGI_FORMAT_D16_UNORM = 55,
200  DXGI_FORMAT_R16_UNORM = 56,
201  DXGI_FORMAT_R16_UINT = 57,
202  DXGI_FORMAT_R16_SNORM = 58,
203  DXGI_FORMAT_R16_SINT = 59,
204  DXGI_FORMAT_R8_TYPELESS = 60,
205  DXGI_FORMAT_R8_UNORM = 61,
206  DXGI_FORMAT_R8_UINT = 62,
207  DXGI_FORMAT_R8_SNORM = 63,
208  DXGI_FORMAT_R8_SINT = 64,
209  DXGI_FORMAT_A8_UNORM = 65,
210  DXGI_FORMAT_R1_UNORM = 66,
211  DXGI_FORMAT_R9G9B9E5_SHAREDEXP = 67,
212  DXGI_FORMAT_R8G8_B8G8_UNORM = 68,
213  DXGI_FORMAT_G8R8_G8B8_UNORM = 69,
214  DXGI_FORMAT_BC1_TYPELESS = 70,
215  DXGI_FORMAT_BC1_UNORM = 71,
216  DXGI_FORMAT_BC1_UNORM_SRGB = 72,
217  DXGI_FORMAT_BC2_TYPELESS = 73,
218  DXGI_FORMAT_BC2_UNORM = 74,
219  DXGI_FORMAT_BC2_UNORM_SRGB = 75,
220  DXGI_FORMAT_BC3_TYPELESS = 76,
221  DXGI_FORMAT_BC3_UNORM = 77,
222  DXGI_FORMAT_BC3_UNORM_SRGB = 78,
223  DXGI_FORMAT_BC4_TYPELESS = 79,
224  DXGI_FORMAT_BC4_UNORM = 80,
225  DXGI_FORMAT_BC4_SNORM = 81,
226  DXGI_FORMAT_BC5_TYPELESS = 82,
227  DXGI_FORMAT_BC5_UNORM = 83,
228  DXGI_FORMAT_BC5_SNORM = 84,
229  DXGI_FORMAT_B5G6R5_UNORM = 85,
230  DXGI_FORMAT_B5G5R5A1_UNORM = 86,
231  DXGI_FORMAT_B8G8R8A8_UNORM = 87,
232  DXGI_FORMAT_B8G8R8X8_UNORM = 88,
233  DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM = 89,
234  DXGI_FORMAT_B8G8R8A8_TYPELESS = 90,
235  DXGI_FORMAT_B8G8R8A8_UNORM_SRGB = 91,
236  DXGI_FORMAT_B8G8R8X8_TYPELESS = 92,
237  DXGI_FORMAT_B8G8R8X8_UNORM_SRGB = 93,
238  DXGI_FORMAT_BC6H_TYPELESS = 94,
239  DXGI_FORMAT_BC6H_UF16 = 95,
240  DXGI_FORMAT_BC6H_SF16 = 96,
241  DXGI_FORMAT_BC7_TYPELESS = 97,
242  DXGI_FORMAT_BC7_UNORM = 98,
243  DXGI_FORMAT_BC7_UNORM_SRGB = 99,
244  DXGI_FORMAT_AYUV = 100,
245  DXGI_FORMAT_Y410 = 101,
246  DXGI_FORMAT_Y416 = 102,
247  DXGI_FORMAT_NV12 = 103,
248  DXGI_FORMAT_P010 = 104,
249  DXGI_FORMAT_P016 = 105,
250  DXGI_FORMAT_420_OPAQUE = 106,
251  DXGI_FORMAT_YUY2 = 107,
252  DXGI_FORMAT_Y210 = 108,
253  DXGI_FORMAT_Y216 = 109,
254  DXGI_FORMAT_NV11 = 110,
255  DXGI_FORMAT_AI44 = 111,
256  DXGI_FORMAT_IA44 = 112,
257  DXGI_FORMAT_P8 = 113,
258  DXGI_FORMAT_A8P8 = 114,
259  DXGI_FORMAT_B4G4R4A4_UNORM = 115,
260 
261  DXGI_FORMAT_P208 = 130,
262  DXGI_FORMAT_V208 = 131,
263  DXGI_FORMAT_V408 = 132,
264  DXGI_FORMAT_ASTC_4X4_TYPELESS = 133,
265  DXGI_FORMAT_ASTC_4X4_UNORM = 134,
266  DXGI_FORMAT_ASTC_4X4_UNORM_SRGB = 135,
267  DXGI_FORMAT_ASTC_5X4_TYPELESS = 137,
268  DXGI_FORMAT_ASTC_5X4_UNORM = 138,
269  DXGI_FORMAT_ASTC_5X4_UNORM_SRGB = 139,
270  DXGI_FORMAT_ASTC_5X5_TYPELESS = 141,
271  DXGI_FORMAT_ASTC_5X5_UNORM = 142,
272  DXGI_FORMAT_ASTC_5X5_UNORM_SRGB = 143,
273  DXGI_FORMAT_ASTC_6X5_TYPELESS = 145,
274  DXGI_FORMAT_ASTC_6X5_UNORM = 146,
275  DXGI_FORMAT_ASTC_6X5_UNORM_SRGB = 147,
276  DXGI_FORMAT_ASTC_6X6_TYPELESS = 149,
277  DXGI_FORMAT_ASTC_6X6_UNORM = 150,
278  DXGI_FORMAT_ASTC_6X6_UNORM_SRGB = 151,
279  DXGI_FORMAT_ASTC_8X5_TYPELESS = 153,
280  DXGI_FORMAT_ASTC_8X5_UNORM = 154,
281  DXGI_FORMAT_ASTC_8X5_UNORM_SRGB = 155,
282  DXGI_FORMAT_ASTC_8X6_TYPELESS = 157,
283  DXGI_FORMAT_ASTC_8X6_UNORM = 158,
284  DXGI_FORMAT_ASTC_8X6_UNORM_SRGB = 159,
285  DXGI_FORMAT_ASTC_8X8_TYPELESS = 161,
286  DXGI_FORMAT_ASTC_8X8_UNORM = 162,
287  DXGI_FORMAT_ASTC_8X8_UNORM_SRGB = 163,
288  DXGI_FORMAT_ASTC_10X5_TYPELESS = 165,
289  DXGI_FORMAT_ASTC_10X5_UNORM = 166,
290  DXGI_FORMAT_ASTC_10X5_UNORM_SRGB = 167,
291  DXGI_FORMAT_ASTC_10X6_TYPELESS = 169,
292  DXGI_FORMAT_ASTC_10X6_UNORM = 170,
293  DXGI_FORMAT_ASTC_10X6_UNORM_SRGB = 171,
294  DXGI_FORMAT_ASTC_10X8_TYPELESS = 173,
295  DXGI_FORMAT_ASTC_10X8_UNORM = 174,
296  DXGI_FORMAT_ASTC_10X8_UNORM_SRGB = 175,
297  DXGI_FORMAT_ASTC_10X10_TYPELESS = 177,
298  DXGI_FORMAT_ASTC_10X10_UNORM = 178,
299  DXGI_FORMAT_ASTC_10X10_UNORM_SRGB = 179,
300  DXGI_FORMAT_ASTC_12X10_TYPELESS = 181,
301  DXGI_FORMAT_ASTC_12X10_UNORM = 182,
302  DXGI_FORMAT_ASTC_12X10_UNORM_SRGB = 183,
303  DXGI_FORMAT_ASTC_12X12_TYPELESS = 185,
304  DXGI_FORMAT_ASTC_12X12_UNORM = 186,
305  DXGI_FORMAT_ASTC_12X12_UNORM_SRGB = 187, DXGI_FORMAT_LAST = DXGI_FORMAT_ASTC_12X12_UNORM_SRGB,
306  DXGI_FORMAT_FORCE_UINT = 0xffffffffUL
307  };
308 
309  enum DDPF
310  {
311  DDPF_ALPHAPIXELS = 0x1,
312  DDPF_ALPHA = 0x2,
313  DDPF_FOURCC = 0x4,
314  DDPF_RGB = 0x40,
315  DDPF_YUV = 0x200,
316  DDPF_LUMINANCE = 0x20000,
317  DDPF_LUMINANCE_ALPHA = DDPF_LUMINANCE | DDPF_ALPHA,
318  DDPF_FOURCC_ALPHAPIXELS = DDPF_FOURCC | DDPF_ALPHAPIXELS,
319  DDPF_RGBAPIXELS = DDPF_RGB | DDPF_ALPHAPIXELS,
320  DDPF_RGBA = DDPF_RGB | DDPF_ALPHA,
321  DDPF_LUMINANCE_ALPHAPIXELS = DDPF_LUMINANCE | DDPF_ALPHAPIXELS,
322 
323  };
324 
325  struct format
326  {
327  DDPF DDPixelFormat;
328  D3DFORMAT D3DFormat;
329  dxgiFormat DXGIFormat;
330  glm::u32vec4 Mask;
331  };
332 
333  public:
334  dx();
335 
336  format const & translate(gli::format const & Format) const;
337  gli::format find(D3DFORMAT FourCC);
338  gli::format find(dxgiFormat Format);
339 
340  private:
341  std::array<format, FORMAT_COUNT> Translation;
342  };
343 }//namespace gli
344 
345 #include "./core/dx.inl"
OpenGL Image (gli.g-truc.net)