Skip to content

Commit 90868ae

Browse files
committed
Update DDS structs
1 parent cb1dcca commit 90868ae

6 files changed

+310
-253
lines changed

DDSTextureLoader/DDSTextureLoader11.cpp

+80-71
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include <algorithm>
2020
#include <cassert>
21+
#include <cstdint>
2122
#include <memory>
2223
#include <new>
2324

@@ -53,82 +54,90 @@ using namespace DirectX;
5354
//
5455
// See DDS.h in the 'Texconv' sample and the 'DirectXTex' library
5556
//--------------------------------------------------------------------------------------
56-
#pragma pack(push,1)
57+
namespace
58+
{
59+
#pragma pack(push,1)
5760

58-
constexpr uint32_t DDS_MAGIC = 0x20534444; // "DDS "
61+
constexpr uint32_t DDS_MAGIC = 0x20534444; // "DDS "
5962

60-
struct DDS_PIXELFORMAT
61-
{
62-
uint32_t size;
63-
uint32_t flags;
64-
uint32_t fourCC;
65-
uint32_t RGBBitCount;
66-
uint32_t RBitMask;
67-
uint32_t GBitMask;
68-
uint32_t BBitMask;
69-
uint32_t ABitMask;
70-
};
71-
72-
#define DDS_FOURCC 0x00000004 // DDPF_FOURCC
73-
#define DDS_RGB 0x00000040 // DDPF_RGB
74-
#define DDS_LUMINANCE 0x00020000 // DDPF_LUMINANCE
75-
#define DDS_ALPHA 0x00000002 // DDPF_ALPHA
76-
#define DDS_BUMPDUDV 0x00080000 // DDPF_BUMPDUDV
77-
78-
#define DDS_HEADER_FLAGS_VOLUME 0x00800000 // DDSD_DEPTH
79-
80-
#define DDS_HEIGHT 0x00000002 // DDSD_HEIGHT
81-
82-
#define DDS_CUBEMAP_POSITIVEX 0x00000600 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_POSITIVEX
83-
#define DDS_CUBEMAP_NEGATIVEX 0x00000a00 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_NEGATIVEX
84-
#define DDS_CUBEMAP_POSITIVEY 0x00001200 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_POSITIVEY
85-
#define DDS_CUBEMAP_NEGATIVEY 0x00002200 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_NEGATIVEY
86-
#define DDS_CUBEMAP_POSITIVEZ 0x00004200 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_POSITIVEZ
87-
#define DDS_CUBEMAP_NEGATIVEZ 0x00008200 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_NEGATIVEZ
88-
89-
#define DDS_CUBEMAP_ALLFACES ( DDS_CUBEMAP_POSITIVEX | DDS_CUBEMAP_NEGATIVEX |\
90-
DDS_CUBEMAP_POSITIVEY | DDS_CUBEMAP_NEGATIVEY |\
91-
DDS_CUBEMAP_POSITIVEZ | DDS_CUBEMAP_NEGATIVEZ )
92-
93-
#define DDS_CUBEMAP 0x00000200 // DDSCAPS2_CUBEMAP
94-
95-
enum DDS_MISC_FLAGS2
96-
{
97-
DDS_MISC_FLAGS2_ALPHA_MODE_MASK = 0x7L,
98-
};
63+
struct DDS_PIXELFORMAT
64+
{
65+
uint32_t size;
66+
uint32_t flags;
67+
uint32_t fourCC;
68+
uint32_t RGBBitCount;
69+
uint32_t RBitMask;
70+
uint32_t GBitMask;
71+
uint32_t BBitMask;
72+
uint32_t ABitMask;
73+
};
74+
75+
#define DDS_FOURCC 0x00000004 // DDPF_FOURCC
76+
#define DDS_RGB 0x00000040 // DDPF_RGB
77+
#define DDS_LUMINANCE 0x00020000 // DDPF_LUMINANCE
78+
#define DDS_ALPHA 0x00000002 // DDPF_ALPHA
79+
#define DDS_BUMPDUDV 0x00080000 // DDPF_BUMPDUDV
80+
81+
#define DDS_HEADER_FLAGS_VOLUME 0x00800000 // DDSD_DEPTH
82+
83+
#define DDS_HEIGHT 0x00000002 // DDSD_HEIGHT
84+
85+
#define DDS_CUBEMAP_POSITIVEX 0x00000600 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_POSITIVEX
86+
#define DDS_CUBEMAP_NEGATIVEX 0x00000a00 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_NEGATIVEX
87+
#define DDS_CUBEMAP_POSITIVEY 0x00001200 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_POSITIVEY
88+
#define DDS_CUBEMAP_NEGATIVEY 0x00002200 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_NEGATIVEY
89+
#define DDS_CUBEMAP_POSITIVEZ 0x00004200 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_POSITIVEZ
90+
#define DDS_CUBEMAP_NEGATIVEZ 0x00008200 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_NEGATIVEZ
91+
92+
#define DDS_CUBEMAP_ALLFACES ( DDS_CUBEMAP_POSITIVEX | DDS_CUBEMAP_NEGATIVEX |\
93+
DDS_CUBEMAP_POSITIVEY | DDS_CUBEMAP_NEGATIVEY |\
94+
DDS_CUBEMAP_POSITIVEZ | DDS_CUBEMAP_NEGATIVEZ )
95+
96+
#define DDS_CUBEMAP 0x00000200 // DDSCAPS2_CUBEMAP
97+
98+
enum DDS_MISC_FLAGS2
99+
{
100+
DDS_MISC_FLAGS2_ALPHA_MODE_MASK = 0x7L,
101+
};
99102

100-
struct DDS_HEADER
101-
{
102-
uint32_t size;
103-
uint32_t flags;
104-
uint32_t height;
105-
uint32_t width;
106-
uint32_t pitchOrLinearSize;
107-
uint32_t depth; // only if DDS_HEADER_FLAGS_VOLUME is set in flags
108-
uint32_t mipMapCount;
109-
uint32_t reserved1[11];
110-
DDS_PIXELFORMAT ddspf;
111-
uint32_t caps;
112-
uint32_t caps2;
113-
uint32_t caps3;
114-
uint32_t caps4;
115-
uint32_t reserved2;
116-
};
117-
118-
struct DDS_HEADER_DXT10
119-
{
120-
DXGI_FORMAT dxgiFormat;
121-
uint32_t resourceDimension;
122-
uint32_t miscFlag; // see D3D11_RESOURCE_MISC_FLAG
123-
uint32_t arraySize;
124-
uint32_t miscFlags2;
125-
};
103+
struct DDS_HEADER
104+
{
105+
uint32_t size;
106+
uint32_t flags;
107+
uint32_t height;
108+
uint32_t width;
109+
uint32_t pitchOrLinearSize;
110+
uint32_t depth; // only if DDS_HEADER_FLAGS_VOLUME is set in flags
111+
uint32_t mipMapCount;
112+
uint32_t reserved1[11];
113+
DDS_PIXELFORMAT ddspf;
114+
uint32_t caps;
115+
uint32_t caps2;
116+
uint32_t caps3;
117+
uint32_t caps4;
118+
uint32_t reserved2;
119+
};
120+
121+
struct DDS_HEADER_DXT10
122+
{
123+
DXGI_FORMAT dxgiFormat;
124+
uint32_t resourceDimension;
125+
uint32_t miscFlag; // see D3D11_RESOURCE_MISC_FLAG
126+
uint32_t arraySize;
127+
uint32_t miscFlags2;
128+
};
126129

127-
#pragma pack(pop)
130+
#pragma pack(pop)
128131

129-
//--------------------------------------------------------------------------------------
130-
namespace
131-
{
132+
static_assert(sizeof(DDS_PIXELFORMAT) == 32, "DDS pixel format size mismatch");
133+
static_assert(sizeof(DDS_HEADER) == 124, "DDS Header size mismatch");
134+
static_assert(sizeof(DDS_HEADER_DXT10) == 20, "DDS DX10 Extended Header size mismatch");
135+
136+
constexpr size_t DDS_MIN_HEADER_SIZE = sizeof(uint32_t) + sizeof(DDS_HEADER);
137+
constexpr size_t DDS_DX10_HEADER_SIZE = sizeof(uint32_t) + sizeof(DDS_HEADER) + sizeof(DDS_HEADER_DXT10);
138+
static_assert(DDS_DX10_HEADER_SIZE > DDS_MIN_HEADER_SIZE, "DDS DX10 Header should be larger than standard header");
139+
140+
//--------------------------------------------------------------------------------------
132141
struct handle_closer { void operator()(HANDLE h) noexcept { if (h) CloseHandle(h); } };
133142

134143
using ScopedHandle = std::unique_ptr<void, handle_closer>;

DDSTextureLoader/DDSTextureLoader12.cpp

+80-71
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include <algorithm>
2020
#include <cassert>
21+
#include <cstdint>
2122
#include <memory>
2223
#include <new>
2324

@@ -81,82 +82,90 @@ using namespace DirectX;
8182
//
8283
// See DDS.h in the 'Texconv' sample and the 'DirectXTex' library
8384
//--------------------------------------------------------------------------------------
84-
#pragma pack(push,1)
85+
namespace
86+
{
87+
#pragma pack(push,1)
8588

86-
constexpr uint32_t DDS_MAGIC = 0x20534444; // "DDS "
89+
constexpr uint32_t DDS_MAGIC = 0x20534444; // "DDS "
8790

88-
struct DDS_PIXELFORMAT
89-
{
90-
uint32_t size;
91-
uint32_t flags;
92-
uint32_t fourCC;
93-
uint32_t RGBBitCount;
94-
uint32_t RBitMask;
95-
uint32_t GBitMask;
96-
uint32_t BBitMask;
97-
uint32_t ABitMask;
98-
};
99-
100-
#define DDS_FOURCC 0x00000004 // DDPF_FOURCC
101-
#define DDS_RGB 0x00000040 // DDPF_RGB
102-
#define DDS_LUMINANCE 0x00020000 // DDPF_LUMINANCE
103-
#define DDS_ALPHA 0x00000002 // DDPF_ALPHA
104-
#define DDS_BUMPDUDV 0x00080000 // DDPF_BUMPDUDV
105-
106-
#define DDS_HEADER_FLAGS_VOLUME 0x00800000 // DDSD_DEPTH
107-
108-
#define DDS_HEIGHT 0x00000002 // DDSD_HEIGHT
109-
110-
#define DDS_CUBEMAP_POSITIVEX 0x00000600 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_POSITIVEX
111-
#define DDS_CUBEMAP_NEGATIVEX 0x00000a00 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_NEGATIVEX
112-
#define DDS_CUBEMAP_POSITIVEY 0x00001200 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_POSITIVEY
113-
#define DDS_CUBEMAP_NEGATIVEY 0x00002200 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_NEGATIVEY
114-
#define DDS_CUBEMAP_POSITIVEZ 0x00004200 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_POSITIVEZ
115-
#define DDS_CUBEMAP_NEGATIVEZ 0x00008200 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_NEGATIVEZ
116-
117-
#define DDS_CUBEMAP_ALLFACES ( DDS_CUBEMAP_POSITIVEX | DDS_CUBEMAP_NEGATIVEX |\
118-
DDS_CUBEMAP_POSITIVEY | DDS_CUBEMAP_NEGATIVEY |\
119-
DDS_CUBEMAP_POSITIVEZ | DDS_CUBEMAP_NEGATIVEZ )
120-
121-
#define DDS_CUBEMAP 0x00000200 // DDSCAPS2_CUBEMAP
122-
123-
enum DDS_MISC_FLAGS2
124-
{
125-
DDS_MISC_FLAGS2_ALPHA_MODE_MASK = 0x7L,
126-
};
91+
struct DDS_PIXELFORMAT
92+
{
93+
uint32_t size;
94+
uint32_t flags;
95+
uint32_t fourCC;
96+
uint32_t RGBBitCount;
97+
uint32_t RBitMask;
98+
uint32_t GBitMask;
99+
uint32_t BBitMask;
100+
uint32_t ABitMask;
101+
};
102+
103+
#define DDS_FOURCC 0x00000004 // DDPF_FOURCC
104+
#define DDS_RGB 0x00000040 // DDPF_RGB
105+
#define DDS_LUMINANCE 0x00020000 // DDPF_LUMINANCE
106+
#define DDS_ALPHA 0x00000002 // DDPF_ALPHA
107+
#define DDS_BUMPDUDV 0x00080000 // DDPF_BUMPDUDV
108+
109+
#define DDS_HEADER_FLAGS_VOLUME 0x00800000 // DDSD_DEPTH
110+
111+
#define DDS_HEIGHT 0x00000002 // DDSD_HEIGHT
112+
113+
#define DDS_CUBEMAP_POSITIVEX 0x00000600 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_POSITIVEX
114+
#define DDS_CUBEMAP_NEGATIVEX 0x00000a00 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_NEGATIVEX
115+
#define DDS_CUBEMAP_POSITIVEY 0x00001200 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_POSITIVEY
116+
#define DDS_CUBEMAP_NEGATIVEY 0x00002200 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_NEGATIVEY
117+
#define DDS_CUBEMAP_POSITIVEZ 0x00004200 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_POSITIVEZ
118+
#define DDS_CUBEMAP_NEGATIVEZ 0x00008200 // DDSCAPS2_CUBEMAP | DDSCAPS2_CUBEMAP_NEGATIVEZ
119+
120+
#define DDS_CUBEMAP_ALLFACES ( DDS_CUBEMAP_POSITIVEX | DDS_CUBEMAP_NEGATIVEX |\
121+
DDS_CUBEMAP_POSITIVEY | DDS_CUBEMAP_NEGATIVEY |\
122+
DDS_CUBEMAP_POSITIVEZ | DDS_CUBEMAP_NEGATIVEZ )
123+
124+
#define DDS_CUBEMAP 0x00000200 // DDSCAPS2_CUBEMAP
125+
126+
enum DDS_MISC_FLAGS2
127+
{
128+
DDS_MISC_FLAGS2_ALPHA_MODE_MASK = 0x7L,
129+
};
127130

128-
struct DDS_HEADER
129-
{
130-
uint32_t size;
131-
uint32_t flags;
132-
uint32_t height;
133-
uint32_t width;
134-
uint32_t pitchOrLinearSize;
135-
uint32_t depth; // only if DDS_HEADER_FLAGS_VOLUME is set in flags
136-
uint32_t mipMapCount;
137-
uint32_t reserved1[11];
138-
DDS_PIXELFORMAT ddspf;
139-
uint32_t caps;
140-
uint32_t caps2;
141-
uint32_t caps3;
142-
uint32_t caps4;
143-
uint32_t reserved2;
144-
};
145-
146-
struct DDS_HEADER_DXT10
147-
{
148-
DXGI_FORMAT dxgiFormat;
149-
uint32_t resourceDimension;
150-
uint32_t miscFlag; // see D3D11_RESOURCE_MISC_FLAG
151-
uint32_t arraySize;
152-
uint32_t miscFlags2;
153-
};
131+
struct DDS_HEADER
132+
{
133+
uint32_t size;
134+
uint32_t flags;
135+
uint32_t height;
136+
uint32_t width;
137+
uint32_t pitchOrLinearSize;
138+
uint32_t depth; // only if DDS_HEADER_FLAGS_VOLUME is set in flags
139+
uint32_t mipMapCount;
140+
uint32_t reserved1[11];
141+
DDS_PIXELFORMAT ddspf;
142+
uint32_t caps;
143+
uint32_t caps2;
144+
uint32_t caps3;
145+
uint32_t caps4;
146+
uint32_t reserved2;
147+
};
148+
149+
struct DDS_HEADER_DXT10
150+
{
151+
DXGI_FORMAT dxgiFormat;
152+
uint32_t resourceDimension;
153+
uint32_t miscFlag; // see D3D11_RESOURCE_MISC_FLAG
154+
uint32_t arraySize;
155+
uint32_t miscFlags2;
156+
};
154157

155-
#pragma pack(pop)
158+
#pragma pack(pop)
156159

157-
//--------------------------------------------------------------------------------------
158-
namespace
159-
{
160+
static_assert(sizeof(DDS_PIXELFORMAT) == 32, "DDS pixel format size mismatch");
161+
static_assert(sizeof(DDS_HEADER) == 124, "DDS Header size mismatch");
162+
static_assert(sizeof(DDS_HEADER_DXT10) == 20, "DDS DX10 Extended Header size mismatch");
163+
164+
constexpr size_t DDS_MIN_HEADER_SIZE = sizeof(uint32_t) + sizeof(DDS_HEADER);
165+
constexpr size_t DDS_DX10_HEADER_SIZE = sizeof(uint32_t) + sizeof(DDS_HEADER) + sizeof(DDS_HEADER_DXT10);
166+
static_assert(DDS_DX10_HEADER_SIZE > DDS_MIN_HEADER_SIZE, "DDS DX10 Header should be larger than standard header");
167+
168+
//--------------------------------------------------------------------------------------
160169
#ifdef _WIN32
161170
struct handle_closer { void operator()(HANDLE h) noexcept { if (h) CloseHandle(h); } };
162171

0 commit comments

Comments
 (0)