Rise
The Vieneo Province
Loading...
Searching...
No Matches
WICTextureLoader.h
Go to the documentation of this file.
1//--------------------------------------------------------------------------------------
2// File: WICTextureLoader.h
3//
4// Function for loading a WIC image and creating a Direct3D runtime texture for it
5// (auto-generating mipmaps if possible)
6//
7// Note: Assumes application has already called CoInitializeEx
8//
9// Warning: CreateWICTexture* functions are not thread-safe if given a d3dContext instance for
10// auto-gen mipmap support.
11//
12// Note these functions are useful for images created as simple 2D textures. For
13// more complex resources, DDSTextureLoader is an excellent light-weight runtime loader.
14// For a full-featured DDS file reader, writer, and texture processing pipeline see
15// the 'Texconv' sample and the 'DirectXTex' library.
16//
17// Copyright (c) Microsoft Corporation.
18// Licensed under the MIT License.
19//
20// http://go.microsoft.com/fwlink/?LinkId=248926
21// https://go.microsoft.com/fwlink/?LinkId=248929
22//--------------------------------------------------------------------------------------
23
24#pragma once
25
26#if defined(_XBOX_ONE) && defined(_TITLE)
27#include <d3d11_x.h>
28#else
29#include <d3d11_1.h>
30#endif
31
32#include <cstddef>
33#include <cstdint>
34
35#ifdef _MSC_VER
36#pragma comment(lib, "uuid.lib")
37#endif
38
39#ifndef DIRECTX_TOOLKIT_API
40#ifdef DIRECTX_TOOLKIT_EXPORT
41#ifdef __GNUC__
42#define DIRECTX_TOOLKIT_API __attribute__((dllexport))
43#else
44#define DIRECTX_TOOLKIT_API __declspec(dllexport)
45#endif
46#elif defined(DIRECTX_TOOLKIT_IMPORT)
47#ifdef __GNUC__
48#define DIRECTX_TOOLKIT_API __attribute__((dllimport))
49#else
50#define DIRECTX_TOOLKIT_API __declspec(dllimport)
51#endif
52#else
53#define DIRECTX_TOOLKIT_API
54#endif
55#endif
56
57namespace DirectX
58{
59 inline namespace DX11
60 {
71 }
72
73 // Standard version
75 HRESULT __cdecl CreateWICTextureFromMemory(_In_ ID3D11Device* d3dDevice,
76 _In_reads_bytes_(wicDataSize) const uint8_t* wicData,
77 _In_ size_t wicDataSize,
78 _Outptr_opt_ ID3D11Resource** texture,
79 _Outptr_opt_ ID3D11ShaderResourceView** textureView,
80 _In_ size_t maxsize = 0) noexcept;
81
83 HRESULT __cdecl CreateWICTextureFromFile(_In_ ID3D11Device* d3dDevice,
84 _In_z_ const wchar_t* szFileName,
85 _Outptr_opt_ ID3D11Resource** texture,
86 _Outptr_opt_ ID3D11ShaderResourceView** textureView,
87 _In_ size_t maxsize = 0) noexcept;
88
89 // Standard version with optional auto-gen mipmap support
92#if defined(_XBOX_ONE) && defined(_TITLE)
93 _In_ ID3D11DeviceX* d3dDevice,
94 _In_opt_ ID3D11DeviceContextX* d3dContext,
95#else
96 _In_ ID3D11Device* d3dDevice,
97 _In_opt_ ID3D11DeviceContext* d3dContext,
98#endif
99 _In_reads_bytes_(wicDataSize) const uint8_t* wicData,
100 _In_ size_t wicDataSize,
101 _Outptr_opt_ ID3D11Resource** texture,
102 _Outptr_opt_ ID3D11ShaderResourceView** textureView,
103 _In_ size_t maxsize = 0) noexcept;
104
107#if defined(_XBOX_ONE) && defined(_TITLE)
108 _In_ ID3D11DeviceX* d3dDevice,
109 _In_opt_ ID3D11DeviceContextX* d3dContext,
110#else
111 _In_ ID3D11Device* d3dDevice,
112 _In_opt_ ID3D11DeviceContext* d3dContext,
113#endif
114 _In_z_ const wchar_t* szFileName,
115 _Outptr_opt_ ID3D11Resource** texture,
116 _Outptr_opt_ ID3D11ShaderResourceView** textureView,
117 _In_ size_t maxsize = 0) noexcept;
118
119 // Extended version
121 HRESULT __cdecl CreateWICTextureFromMemoryEx(_In_ ID3D11Device* d3dDevice,
122 _In_reads_bytes_(wicDataSize) const uint8_t* wicData,
123 _In_ size_t wicDataSize,
124 _In_ size_t maxsize,
125 _In_ D3D11_USAGE usage,
126 _In_ unsigned int bindFlags,
127 _In_ unsigned int cpuAccessFlags,
128 _In_ unsigned int miscFlags,
129 _In_ WIC_LOADER_FLAGS loadFlags,
130 _Outptr_opt_ ID3D11Resource** texture,
131 _Outptr_opt_ ID3D11ShaderResourceView** textureView) noexcept;
132
134 HRESULT __cdecl CreateWICTextureFromFileEx(_In_ ID3D11Device* d3dDevice,
135 _In_z_ const wchar_t* szFileName,
136 _In_ size_t maxsize,
137 _In_ D3D11_USAGE usage,
138 _In_ unsigned int bindFlags,
139 _In_ unsigned int cpuAccessFlags,
140 _In_ unsigned int miscFlags,
141 _In_ WIC_LOADER_FLAGS loadFlags,
142 _Outptr_opt_ ID3D11Resource** texture,
143 _Outptr_opt_ ID3D11ShaderResourceView** textureView) noexcept;
144
145 // Extended version with optional auto-gen mipmap support
148#if defined(_XBOX_ONE) && defined(_TITLE)
149 _In_ ID3D11DeviceX* d3dDevice,
150 _In_opt_ ID3D11DeviceContextX* d3dContext,
151#else
152 _In_ ID3D11Device* d3dDevice,
153 _In_opt_ ID3D11DeviceContext* d3dContext,
154#endif
155 _In_reads_bytes_(wicDataSize) const uint8_t* wicData,
156 _In_ size_t wicDataSize,
157 _In_ size_t maxsize,
158 _In_ D3D11_USAGE usage,
159 _In_ unsigned int bindFlags,
160 _In_ unsigned int cpuAccessFlags,
161 _In_ unsigned int miscFlags,
162 _In_ WIC_LOADER_FLAGS loadFlags,
163 _Outptr_opt_ ID3D11Resource** texture,
164 _Outptr_opt_ ID3D11ShaderResourceView** textureView) noexcept;
165
168#if defined(_XBOX_ONE) && defined(_TITLE)
169 _In_ ID3D11DeviceX* d3dDevice,
170 _In_opt_ ID3D11DeviceContextX* d3dContext,
171#else
172 _In_ ID3D11Device* d3dDevice,
173 _In_opt_ ID3D11DeviceContext* d3dContext,
174#endif
175 _In_z_ const wchar_t* szFileName,
176 _In_ size_t maxsize,
177 _In_ D3D11_USAGE usage,
178 _In_ unsigned int bindFlags,
179 _In_ unsigned int cpuAccessFlags,
180 _In_ unsigned int miscFlags,
181 _In_ WIC_LOADER_FLAGS loadFlags,
182 _Outptr_opt_ ID3D11Resource** texture,
183 _Outptr_opt_ ID3D11ShaderResourceView** textureView) noexcept;
184
185#ifdef __cpp_lib_byte
187 inline HRESULT __cdecl CreateWICTextureFromMemory(_In_ ID3D11Device* d3dDevice,
188 _In_reads_bytes_(wicDataSize) const std::byte* wicData,
189 _In_ size_t wicDataSize,
190 _Outptr_opt_ ID3D11Resource** texture,
191 _Outptr_opt_ ID3D11ShaderResourceView** textureView,
192 _In_ size_t maxsize = 0) noexcept
193 {
194 return CreateWICTextureFromMemory(d3dDevice, reinterpret_cast<const uint8_t*>(wicData), wicDataSize, texture, textureView, maxsize);
195 }
196
199#if defined(_XBOX_ONE) && defined(_TITLE)
200 _In_ ID3D11DeviceX* d3dDevice,
201 _In_opt_ ID3D11DeviceContextX* d3dContext,
202#else
203 _In_ ID3D11Device* d3dDevice,
204 _In_opt_ ID3D11DeviceContext* d3dContext,
205#endif
206 _In_reads_bytes_(wicDataSize) const std::byte* wicData,
207 _In_ size_t wicDataSize,
208 _Outptr_opt_ ID3D11Resource** texture,
209 _Outptr_opt_ ID3D11ShaderResourceView** textureView,
210 _In_ size_t maxsize = 0) noexcept
211 {
212 return CreateWICTextureFromMemory(d3dDevice,
213 d3dContext,
214 reinterpret_cast<const uint8_t*>(wicData),
215 wicDataSize,
216 texture,
217 textureView,
218 maxsize);
219 }
220
222 inline HRESULT __cdecl CreateWICTextureFromMemoryEx(_In_ ID3D11Device* d3dDevice,
223 _In_reads_bytes_(wicDataSize) const std::byte* wicData,
224 _In_ size_t wicDataSize,
225 _In_ size_t maxsize,
226 _In_ D3D11_USAGE usage,
227 _In_ unsigned int bindFlags,
228 _In_ unsigned int cpuAccessFlags,
229 _In_ unsigned int miscFlags,
230 _In_ WIC_LOADER_FLAGS loadFlags,
231 _Outptr_opt_ ID3D11Resource** texture,
232 _Outptr_opt_ ID3D11ShaderResourceView** textureView) noexcept
233 {
234 return CreateWICTextureFromMemoryEx(d3dDevice,
235 reinterpret_cast<const uint8_t*>(wicData),
236 wicDataSize,
237 maxsize,
238 usage,
239 bindFlags,
240 cpuAccessFlags,
241 miscFlags,
242 loadFlags,
243 texture,
244 textureView);
245 }
246
249#if defined(_XBOX_ONE) && defined(_TITLE)
250 _In_ ID3D11DeviceX* d3dDevice,
251 _In_opt_ ID3D11DeviceContextX* d3dContext,
252#else
253 _In_ ID3D11Device* d3dDevice,
254 _In_opt_ ID3D11DeviceContext* d3dContext,
255#endif
256 _In_reads_bytes_(wicDataSize) const std::byte* wicData,
257 _In_ size_t wicDataSize,
258 _In_ size_t maxsize,
259 _In_ D3D11_USAGE usage,
260 _In_ unsigned int bindFlags,
261 _In_ unsigned int cpuAccessFlags,
262 _In_ unsigned int miscFlags,
263 _In_ WIC_LOADER_FLAGS loadFlags,
264 _Outptr_opt_ ID3D11Resource** texture,
265 _Outptr_opt_ ID3D11ShaderResourceView** textureView) noexcept
266 {
267 return CreateWICTextureFromMemoryEx(d3dDevice,
268 d3dContext,
269 reinterpret_cast<const uint8_t*>(wicData),
270 wicDataSize,
271 maxsize,
272 usage,
273 bindFlags,
274 cpuAccessFlags,
275 miscFlags,
276 loadFlags,
277 texture,
278 textureView);
279 }
280#endif // __cpp_lib_byte
281
282#ifdef __clang__
283#pragma clang diagnostic push
284#pragma clang diagnostic ignored "-Wdeprecated-dynamic-exception-spec"
285#endif
286
287 inline namespace DX11
288 {
289 DEFINE_ENUM_FLAG_OPERATORS(WIC_LOADER_FLAGS)
290 }
291
292#ifdef __clang__
293#pragma clang diagnostic pop
294#endif
295} // namespace DirectX
HRESULT(WINAPI *CUniBuffer::_ScriptApplyDigitSubstitution)(const SCRIPT_DIGITSUBSTITUTE *
#define DIRECTX_TOOLKIT_API
Definition DDS.h:24
DIRECTX_TOOLKIT_API HRESULT __cdecl CreateWICTextureFromMemory(_In_ ID3D11Device *d3dDevice, _In_reads_bytes_(wicDataSize) const uint8_t *wicData, _In_ size_t wicDataSize, _Outptr_opt_ ID3D11Resource **texture, _Outptr_opt_ ID3D11ShaderResourceView **textureView, _In_ size_t maxsize=0) noexcept
DIRECTX_TOOLKIT_API HRESULT __cdecl CreateWICTextureFromFile(_In_ ID3D11Device *d3dDevice, _In_z_ const wchar_t *szFileName, _Outptr_opt_ ID3D11Resource **texture, _Outptr_opt_ ID3D11ShaderResourceView **textureView, _In_ size_t maxsize=0) noexcept
DIRECTX_TOOLKIT_API HRESULT __cdecl CreateWICTextureFromMemoryEx(_In_ ID3D11Device *d3dDevice, _In_reads_bytes_(wicDataSize) const uint8_t *wicData, _In_ size_t wicDataSize, _In_ size_t maxsize, _In_ D3D11_USAGE usage, _In_ unsigned int bindFlags, _In_ unsigned int cpuAccessFlags, _In_ unsigned int miscFlags, _In_ WIC_LOADER_FLAGS loadFlags, _Outptr_opt_ ID3D11Resource **texture, _Outptr_opt_ ID3D11ShaderResourceView **textureView) noexcept
DIRECTX_TOOLKIT_API HRESULT __cdecl CreateWICTextureFromFileEx(_In_ ID3D11Device *d3dDevice, _In_z_ const wchar_t *szFileName, _In_ size_t maxsize, _In_ D3D11_USAGE usage, _In_ unsigned int bindFlags, _In_ unsigned int cpuAccessFlags, _In_ unsigned int miscFlags, _In_ WIC_LOADER_FLAGS loadFlags, _Outptr_opt_ ID3D11Resource **texture, _Outptr_opt_ ID3D11ShaderResourceView **textureView) noexcept
#define __cdecl