-
Notifications
You must be signed in to change notification settings - Fork 411
/
WICTextureLoader.h
206 lines (184 loc) · 6.95 KB
/
WICTextureLoader.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
//--------------------------------------------------------------------------------------
// File: WICTextureLoader.h
//
// Function for loading a WIC image and creating a Direct3D runtime texture for it
// (auto-generating mipmaps if possible)
//
// Note: Assumes application has already called CoInitializeEx
//
// Note these functions are useful for images created as simple 2D textures. For
// more complex resources, DDSTextureLoader is an excellent light-weight runtime loader.
// For a full-featured DDS file reader, writer, and texture processing pipeline see
// the 'Texconv' sample and the 'DirectXTex' library.
//
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
//
// http://go.microsoft.com/fwlink/?LinkID=615561
//--------------------------------------------------------------------------------------
#pragma once
#ifdef _GAMING_XBOX_SCARLETT
#include <d3d12_xs.h>
#elif (defined(_XBOX_ONE) && defined(_TITLE)) || defined(_GAMING_XBOX)
#include <d3d12_x.h>
#elif defined(USING_DIRECTX_HEADERS)
#include <directx/d3d12.h>
#include <dxguids/dxguids.h>
#else
#include <d3d12.h>
#endif
#include <cstddef>
#include <cstdint>
#include <memory>
#ifdef _MSC_VER
#pragma comment(lib,"uuid.lib")
#endif
namespace DirectX
{
inline namespace DX12
{
enum WIC_LOADER_FLAGS : uint32_t
{
WIC_LOADER_DEFAULT = 0,
WIC_LOADER_FORCE_SRGB = 0x1,
WIC_LOADER_IGNORE_SRGB = 0x2,
WIC_LOADER_SRGB_DEFAULT = 0x4,
WIC_LOADER_MIP_AUTOGEN = 0x8,
WIC_LOADER_MIP_RESERVE = 0x10,
WIC_LOADER_FIT_POW2 = 0x20,
WIC_LOADER_MAKE_SQUARE = 0x40,
WIC_LOADER_FORCE_RGBA32 = 0x80,
};
}
class ResourceUploadBatch;
// Standard version
HRESULT __cdecl LoadWICTextureFromMemory(
_In_ ID3D12Device* device,
_In_reads_bytes_(wicDataSize) const uint8_t* wicData,
size_t wicDataSize,
_Outptr_ ID3D12Resource** texture,
std::unique_ptr<uint8_t[]>& decodedData,
D3D12_SUBRESOURCE_DATA& subresource,
size_t maxsize = 0) noexcept;
HRESULT __cdecl LoadWICTextureFromFile(
_In_ ID3D12Device* device,
_In_z_ const wchar_t* szFileName,
_Outptr_ ID3D12Resource** texture,
std::unique_ptr<uint8_t[]>& decodedData,
D3D12_SUBRESOURCE_DATA& subresource,
size_t maxsize = 0) noexcept;
// Standard version with resource upload
HRESULT __cdecl CreateWICTextureFromMemory(
_In_ ID3D12Device* device,
ResourceUploadBatch& resourceUpload,
_In_reads_bytes_(wicDataSize) const uint8_t* wicData,
size_t wicDataSize,
_Outptr_ ID3D12Resource** texture,
bool generateMips = false,
size_t maxsize = 0);
HRESULT __cdecl CreateWICTextureFromFile(
_In_ ID3D12Device* device,
ResourceUploadBatch& resourceUpload,
_In_z_ const wchar_t* szFileName,
_Outptr_ ID3D12Resource** texture,
bool generateMips = false,
size_t maxsize = 0);
// Extended version
HRESULT __cdecl LoadWICTextureFromMemoryEx(
_In_ ID3D12Device* device,
_In_reads_bytes_(wicDataSize) const uint8_t* wicData,
size_t wicDataSize,
size_t maxsize,
D3D12_RESOURCE_FLAGS resFlags,
WIC_LOADER_FLAGS loadFlags,
_Outptr_ ID3D12Resource** texture,
std::unique_ptr<uint8_t[]>& decodedData,
D3D12_SUBRESOURCE_DATA& subresource) noexcept;
HRESULT __cdecl LoadWICTextureFromFileEx(
_In_ ID3D12Device* device,
_In_z_ const wchar_t* szFileName,
size_t maxsize,
D3D12_RESOURCE_FLAGS resFlags,
WIC_LOADER_FLAGS loadFlags,
_Outptr_ ID3D12Resource** texture,
std::unique_ptr<uint8_t[]>& decodedData,
D3D12_SUBRESOURCE_DATA& subresource) noexcept;
// Extended version with resource upload
HRESULT __cdecl CreateWICTextureFromMemoryEx(
_In_ ID3D12Device* device,
ResourceUploadBatch& resourceUpload,
_In_reads_bytes_(wicDataSize) const uint8_t* wicData,
size_t wicDataSize,
size_t maxsize,
D3D12_RESOURCE_FLAGS resFlags,
WIC_LOADER_FLAGS loadFlags,
_Outptr_ ID3D12Resource** texture);
HRESULT __cdecl CreateWICTextureFromFileEx(
_In_ ID3D12Device* device,
ResourceUploadBatch& resourceUpload,
_In_z_ const wchar_t* szFileName,
size_t maxsize,
D3D12_RESOURCE_FLAGS resFlags,
WIC_LOADER_FLAGS loadFlags,
_Outptr_ ID3D12Resource** texture);
#ifdef __cpp_lib_byte
inline HRESULT __cdecl LoadWICTextureFromMemory(
_In_ ID3D12Device* device,
_In_reads_bytes_(wicDataSize) const std::byte* wicData,
size_t wicDataSize,
_Outptr_ ID3D12Resource** texture,
std::unique_ptr<uint8_t[]>& decodedData,
D3D12_SUBRESOURCE_DATA& subresource,
size_t maxsize = 0) noexcept
{
return LoadWICTextureFromMemory(device, reinterpret_cast<const uint8_t*>(wicData), wicDataSize, texture, decodedData, subresource, maxsize);
}
inline HRESULT __cdecl CreateWICTextureFromMemory(
_In_ ID3D12Device* device,
ResourceUploadBatch& resourceUpload,
_In_reads_bytes_(wicDataSize) const std::byte* wicData,
size_t wicDataSize,
_Outptr_ ID3D12Resource** texture,
bool generateMips = false,
size_t maxsize = 0)
{
return CreateWICTextureFromMemory(device, resourceUpload, reinterpret_cast<const uint8_t*>(wicData), wicDataSize, texture, generateMips, maxsize);
}
inline HRESULT __cdecl LoadWICTextureFromMemoryEx(
_In_ ID3D12Device* device,
_In_reads_bytes_(wicDataSize) const std::byte* wicData,
size_t wicDataSize,
size_t maxsize,
D3D12_RESOURCE_FLAGS resFlags,
WIC_LOADER_FLAGS loadFlags,
_Outptr_ ID3D12Resource** texture,
std::unique_ptr<uint8_t[]>& decodedData,
D3D12_SUBRESOURCE_DATA& subresource) noexcept
{
return LoadWICTextureFromMemoryEx(device, reinterpret_cast<const uint8_t*>(wicData), wicDataSize, maxsize, resFlags, loadFlags, texture, decodedData, subresource);
}
inline HRESULT __cdecl CreateWICTextureFromMemoryEx(
_In_ ID3D12Device* device,
ResourceUploadBatch& resourceUpload,
_In_reads_bytes_(wicDataSize) const std::byte* wicData,
size_t wicDataSize,
size_t maxsize,
D3D12_RESOURCE_FLAGS resFlags,
WIC_LOADER_FLAGS loadFlags,
_Outptr_ ID3D12Resource** texture)
{
return CreateWICTextureFromMemoryEx(device, resourceUpload, reinterpret_cast<const uint8_t*>(wicData), wicDataSize, maxsize, resFlags, loadFlags, texture);
}
#endif // __cpp_lib_byte
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-dynamic-exception-spec"
#endif
inline namespace DX12
{
DEFINE_ENUM_FLAG_OPERATORS(WIC_LOADER_FLAGS)
}
#ifdef __clang__
#pragma clang diagnostic pop
#endif
}