BRE12
DDSTextureLoader.h
1 //--------------------------------------------------------------------------------------
2 // File: DDSTextureLoader.h
3 //
4 // Functions for loading a DDS texture and creating a Direct3D 11 runtime resource for it
5 //
6 // Note these functions are useful as a light-weight runtime loader for DDS files. For
7 // a full-featured DDS file reader, writer, and texture processing pipeline see
8 // the 'Texconv' sample and the 'DirectXTex' library.
9 //
10 // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
11 // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
12 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
13 // PARTICULAR PURPOSE.
14 //
15 // Copyright (c) Microsoft Corporation. All rights reserved.
16 //
17 // http://go.microsoft.com/fwlink/?LinkId=248926
18 // http://go.microsoft.com/fwlink/?LinkId=248929
19 //--------------------------------------------------------------------------------------
20 
21 #pragma once
22 
23 #include <wrl.h>
24 #include <d3d11_1.h>
25 #include <DXUtils/d3dx12.h>
26 
27 #include <cstdint>
28 
29 #if defined(_MSC_VER) && (_MSC_VER<1610) && !defined(_In_reads_)
30 #define _In_reads_(exp)
31 #define _Out_writes_(exp)
32 #define _In_reads_bytes_(exp)
33 #define _In_reads_opt_(exp)
34 #define _Outptr_opt_
35 #endif
36 
37 #ifndef _Use_decl_annotations_
38 #define _Use_decl_annotations_
39 #endif
40 
41 namespace DirectX {
42 enum class DDS_ALPHA_MODE : std::uint8_t {
43  DDS_ALPHA_MODE_UNKNOWN = 0,
44  DDS_ALPHA_MODE_STRAIGHT = 1,
45  DDS_ALPHA_MODE_PREMULTIPLIED = 2,
46  DDS_ALPHA_MODE_OPAQUE = 3,
47  DDS_ALPHA_MODE_CUSTOM = 4,
48 };
49 
50 // Standard version
51 HRESULT CreateDDSTextureFromMemory(_In_ ID3D11Device* d3dDevice,
52  _In_reads_bytes_(ddsDataSize) const uint8_t* ddsData,
53  _In_ std::size_t ddsDataSize,
54  _Outptr_opt_ ID3D11Resource** texture,
55  _Outptr_opt_ ID3D11ShaderResourceView** textureView,
56  _In_ std::size_t maxsize = 0,
57  _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr
58 ) noexcept;
59 
60 HRESULT CreateDDSTextureFromMemory12(_In_ ID3D12Device* device,
61  _In_ ID3D12GraphicsCommandList* cmdList,
62  _In_reads_bytes_(ddsDataSize) const uint8_t* ddsData,
63  _In_ std::size_t ddsDataSize,
64  _Out_ Microsoft::WRL::ComPtr<ID3D12Resource>& texture,
65  _Out_ Microsoft::WRL::ComPtr<ID3D12Resource>& textureUploadHeap,
66  _In_ std::size_t maxsize = 0,
67  _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr
68 ) noexcept;
69 
70 HRESULT CreateDDSTextureFromFile(_In_ ID3D11Device* d3dDevice,
71  _In_z_ const wchar_t* szFileName,
72  _Outptr_opt_ ID3D11Resource** texture,
73  _Outptr_opt_ ID3D11ShaderResourceView** textureView,
74  _In_ std::size_t maxsize = 0,
75  _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr
76 ) noexcept;
77 
78 HRESULT CreateDDSTextureFromFile12(_In_ ID3D12Device* device,
79  _In_ ID3D12GraphicsCommandList* cmdList,
80  _In_z_ const wchar_t* szFileName,
81  _Out_ Microsoft::WRL::ComPtr<ID3D12Resource>& texture,
82  _Out_ Microsoft::WRL::ComPtr<ID3D12Resource>& textureUploadHeap,
83  _In_ std::size_t maxsize = 0,
84  _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr
85 ) noexcept;
86 
87 // Standard version with optional auto-gen mipmap support
88 HRESULT CreateDDSTextureFromMemory(_In_ ID3D11Device* d3dDevice,
89  _In_opt_ ID3D11DeviceContext* d3dContext,
90  _In_reads_bytes_(ddsDataSize) const uint8_t* ddsData,
91  _In_ std::size_t ddsDataSize,
92  _Outptr_opt_ ID3D11Resource** texture,
93  _Outptr_opt_ ID3D11ShaderResourceView** textureView,
94  _In_ std::size_t maxsize = 0,
95  _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr
96 ) noexcept;
97 
98 HRESULT CreateDDSTextureFromFile(_In_ ID3D11Device* d3dDevice,
99  _In_opt_ ID3D11DeviceContext* d3dContext,
100  _In_z_ const wchar_t* szFileName,
101  _Outptr_opt_ ID3D11Resource** texture,
102  _Outptr_opt_ ID3D11ShaderResourceView** textureView,
103  _In_ std::size_t maxsize = 0,
104  _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr
105 ) noexcept;
106 
107 // Extended version
108 HRESULT CreateDDSTextureFromMemoryEx(_In_ ID3D11Device* d3dDevice,
109  _In_reads_bytes_(ddsDataSize) const uint8_t* ddsData,
110  _In_ std::size_t ddsDataSize,
111  _In_ std::size_t maxsize,
112  _In_ D3D11_USAGE usage,
113  _In_ unsigned int bindFlags,
114  _In_ unsigned int cpuAccessFlags,
115  _In_ unsigned int miscFlags,
116  _In_ bool forceSRGB,
117  _Outptr_opt_ ID3D11Resource** texture,
118  _Outptr_opt_ ID3D11ShaderResourceView** textureView,
119  _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr
120 ) noexcept;
121 
122 HRESULT CreateDDSTextureFromFileEx(_In_ ID3D11Device* d3dDevice,
123  _In_z_ const wchar_t* szFileName,
124  _In_ std::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_ bool forceSRGB,
130  _Outptr_opt_ ID3D11Resource** texture,
131  _Outptr_opt_ ID3D11ShaderResourceView** textureView,
132  _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr
133 ) noexcept;
134 
135 // Extended version with optional auto-gen mipmap support
136 HRESULT CreateDDSTextureFromMemoryEx(_In_ ID3D11Device* d3dDevice,
137  _In_opt_ ID3D11DeviceContext* d3dContext,
138  _In_reads_bytes_(ddsDataSize) const uint8_t* ddsData,
139  _In_ std::size_t ddsDataSize,
140  _In_ std::size_t maxsize,
141  _In_ D3D11_USAGE usage,
142  _In_ unsigned int bindFlags,
143  _In_ unsigned int cpuAccessFlags,
144  _In_ unsigned int miscFlags,
145  _In_ bool forceSRGB,
146  _Outptr_opt_ ID3D11Resource** texture,
147  _Outptr_opt_ ID3D11ShaderResourceView** textureView,
148  _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr
149 ) noexcept;
150 
151 HRESULT CreateDDSTextureFromFileEx(_In_ ID3D11Device* d3dDevice,
152  _In_opt_ ID3D11DeviceContext* d3dContext,
153  _In_z_ const wchar_t* szFileName,
154  _In_ std::size_t maxsize,
155  _In_ D3D11_USAGE usage,
156  _In_ unsigned int bindFlags,
157  _In_ unsigned int cpuAccessFlags,
158  _In_ unsigned int miscFlags,
159  _In_ bool forceSRGB,
160  _Outptr_opt_ ID3D11Resource** texture,
161  _Outptr_opt_ ID3D11ShaderResourceView** textureView,
162  _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr
163 ) noexcept;
164 }
Definition: DDSTextureLoader.h:41
Definition: _tbb_windef.h:37