Added DDSTextureLoader for DX12

This commit is contained in:
Chuck Walbourn 2016-07-07 17:51:28 -07:00
parent 0f75b5d268
commit 5278803345
4 changed files with 2997 additions and 1439 deletions

File diff suppressed because it is too large Load Diff

View File

@ -36,98 +36,98 @@ namespace DirectX
}; };
// Standard version // Standard version
HRESULT CreateDDSTextureFromMemory( _In_ ID3D11Device* d3dDevice, HRESULT CreateDDSTextureFromMemory(
_In_reads_bytes_(ddsDataSize) const uint8_t* ddsData, _In_ ID3D11Device* d3dDevice,
_In_ size_t ddsDataSize, _In_reads_bytes_(ddsDataSize) const uint8_t* ddsData,
_Outptr_opt_ ID3D11Resource** texture, _In_ size_t ddsDataSize,
_Outptr_opt_ ID3D11ShaderResourceView** textureView, _Outptr_opt_ ID3D11Resource** texture,
_In_ size_t maxsize = 0, _Outptr_opt_ ID3D11ShaderResourceView** textureView,
_Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr _In_ size_t maxsize = 0,
); _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr);
HRESULT CreateDDSTextureFromFile( _In_ ID3D11Device* d3dDevice, HRESULT CreateDDSTextureFromFile(
_In_z_ const wchar_t* szFileName, _In_ ID3D11Device* d3dDevice,
_Outptr_opt_ ID3D11Resource** texture, _In_z_ const wchar_t* szFileName,
_Outptr_opt_ ID3D11ShaderResourceView** textureView, _Outptr_opt_ ID3D11Resource** texture,
_In_ size_t maxsize = 0, _Outptr_opt_ ID3D11ShaderResourceView** textureView,
_Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr _In_ size_t maxsize = 0,
); _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr);
// Standard version with optional auto-gen mipmap support // Standard version with optional auto-gen mipmap support
HRESULT CreateDDSTextureFromMemory( _In_ ID3D11Device* d3dDevice, HRESULT CreateDDSTextureFromMemory(
_In_opt_ ID3D11DeviceContext* d3dContext, _In_ ID3D11Device* d3dDevice,
_In_reads_bytes_(ddsDataSize) const uint8_t* ddsData, _In_opt_ ID3D11DeviceContext* d3dContext,
_In_ size_t ddsDataSize, _In_reads_bytes_(ddsDataSize) const uint8_t* ddsData,
_Outptr_opt_ ID3D11Resource** texture, _In_ size_t ddsDataSize,
_Outptr_opt_ ID3D11ShaderResourceView** textureView, _Outptr_opt_ ID3D11Resource** texture,
_In_ size_t maxsize = 0, _Outptr_opt_ ID3D11ShaderResourceView** textureView,
_Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr _In_ size_t maxsize = 0,
); _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr);
HRESULT CreateDDSTextureFromFile( _In_ ID3D11Device* d3dDevice, HRESULT CreateDDSTextureFromFile(
_In_opt_ ID3D11DeviceContext* d3dContext, _In_ ID3D11Device* d3dDevice,
_In_z_ const wchar_t* szFileName, _In_opt_ ID3D11DeviceContext* d3dContext,
_Outptr_opt_ ID3D11Resource** texture, _In_z_ const wchar_t* szFileName,
_Outptr_opt_ ID3D11ShaderResourceView** textureView, _Outptr_opt_ ID3D11Resource** texture,
_In_ size_t maxsize = 0, _Outptr_opt_ ID3D11ShaderResourceView** textureView,
_Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr _In_ size_t maxsize = 0,
); _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr);
// Extended version // Extended version
HRESULT CreateDDSTextureFromMemoryEx( _In_ ID3D11Device* d3dDevice, HRESULT CreateDDSTextureFromMemoryEx(
_In_reads_bytes_(ddsDataSize) const uint8_t* ddsData, _In_ ID3D11Device* d3dDevice,
_In_ size_t ddsDataSize, _In_reads_bytes_(ddsDataSize) const uint8_t* ddsData,
_In_ size_t maxsize, _In_ size_t ddsDataSize,
_In_ D3D11_USAGE usage, _In_ size_t maxsize,
_In_ unsigned int bindFlags, _In_ D3D11_USAGE usage,
_In_ unsigned int cpuAccessFlags, _In_ unsigned int bindFlags,
_In_ unsigned int miscFlags, _In_ unsigned int cpuAccessFlags,
_In_ bool forceSRGB, _In_ unsigned int miscFlags,
_Outptr_opt_ ID3D11Resource** texture, _In_ bool forceSRGB,
_Outptr_opt_ ID3D11ShaderResourceView** textureView, _Outptr_opt_ ID3D11Resource** texture,
_Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr _Outptr_opt_ ID3D11ShaderResourceView** textureView,
); _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr);
HRESULT CreateDDSTextureFromFileEx( _In_ ID3D11Device* d3dDevice, HRESULT CreateDDSTextureFromFileEx(
_In_z_ const wchar_t* szFileName, _In_ ID3D11Device* d3dDevice,
_In_ size_t maxsize, _In_z_ const wchar_t* szFileName,
_In_ D3D11_USAGE usage, _In_ size_t maxsize,
_In_ unsigned int bindFlags, _In_ D3D11_USAGE usage,
_In_ unsigned int cpuAccessFlags, _In_ unsigned int bindFlags,
_In_ unsigned int miscFlags, _In_ unsigned int cpuAccessFlags,
_In_ bool forceSRGB, _In_ unsigned int miscFlags,
_Outptr_opt_ ID3D11Resource** texture, _In_ bool forceSRGB,
_Outptr_opt_ ID3D11ShaderResourceView** textureView, _Outptr_opt_ ID3D11Resource** texture,
_Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr _Outptr_opt_ ID3D11ShaderResourceView** textureView,
); _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr);
// Extended version with optional auto-gen mipmap support // Extended version with optional auto-gen mipmap support
HRESULT CreateDDSTextureFromMemoryEx( _In_ ID3D11Device* d3dDevice, HRESULT CreateDDSTextureFromMemoryEx(
_In_opt_ ID3D11DeviceContext* d3dContext, _In_ ID3D11Device* d3dDevice,
_In_reads_bytes_(ddsDataSize) const uint8_t* ddsData, _In_opt_ ID3D11DeviceContext* d3dContext,
_In_ size_t ddsDataSize, _In_reads_bytes_(ddsDataSize) const uint8_t* ddsData,
_In_ size_t maxsize, _In_ size_t ddsDataSize,
_In_ D3D11_USAGE usage, _In_ size_t maxsize,
_In_ unsigned int bindFlags, _In_ D3D11_USAGE usage,
_In_ unsigned int cpuAccessFlags, _In_ unsigned int bindFlags,
_In_ unsigned int miscFlags, _In_ unsigned int cpuAccessFlags,
_In_ bool forceSRGB, _In_ unsigned int miscFlags,
_Outptr_opt_ ID3D11Resource** texture, _In_ bool forceSRGB,
_Outptr_opt_ ID3D11ShaderResourceView** textureView, _Outptr_opt_ ID3D11Resource** texture,
_Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr _Outptr_opt_ ID3D11ShaderResourceView** textureView,
); _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr);
HRESULT CreateDDSTextureFromFileEx( _In_ ID3D11Device* d3dDevice, HRESULT CreateDDSTextureFromFileEx(
_In_opt_ ID3D11DeviceContext* d3dContext, _In_ ID3D11Device* d3dDevice,
_In_z_ const wchar_t* szFileName, _In_opt_ ID3D11DeviceContext* d3dContext,
_In_ size_t maxsize, _In_z_ const wchar_t* szFileName,
_In_ D3D11_USAGE usage, _In_ size_t maxsize,
_In_ unsigned int bindFlags, _In_ D3D11_USAGE usage,
_In_ unsigned int cpuAccessFlags, _In_ unsigned int bindFlags,
_In_ unsigned int miscFlags, _In_ unsigned int cpuAccessFlags,
_In_ bool forceSRGB, _In_ unsigned int miscFlags,
_Outptr_opt_ ID3D11Resource** texture, _In_ bool forceSRGB,
_Outptr_opt_ ID3D11ShaderResourceView** textureView, _Outptr_opt_ ID3D11Resource** texture,
_Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr _Outptr_opt_ ID3D11ShaderResourceView** textureView,
); _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr);
} }

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,88 @@
//--------------------------------------------------------------------------------------
// File: DDSTextureLoader12.h
//
// Functions for loading a DDS texture and creating a Direct3D 12 runtime resource for it
//
// Note these functions are useful as a light-weight runtime loader for DDS files. For
// a full-featured DDS file reader, writer, and texture processing pipeline see
// the 'Texconv' sample and the 'DirectXTex' library.
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// http://go.microsoft.com/fwlink/?LinkId=248926
// http://go.microsoft.com/fwlink/?LinkID=615561
//--------------------------------------------------------------------------------------
#pragma once
#include <d3d12.h>
#include <memory>
#include <vector>
#include <stdint.h>
namespace DirectX
{
enum DDS_ALPHA_MODE
{
DDS_ALPHA_MODE_UNKNOWN = 0,
DDS_ALPHA_MODE_STRAIGHT = 1,
DDS_ALPHA_MODE_PREMULTIPLIED = 2,
DDS_ALPHA_MODE_OPAQUE = 3,
DDS_ALPHA_MODE_CUSTOM = 4,
};
// Standard version
HRESULT __cdecl LoadDDSTextureFromMemory(
_In_ ID3D12Device* d3dDevice,
_In_reads_bytes_(ddsDataSize) const uint8_t* ddsData,
size_t ddsDataSize,
_Outptr_ ID3D12Resource** texture,
std::vector<D3D12_SUBRESOURCE_DATA>& subresources,
size_t maxsize = 0,
_Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr,
_Out_opt_ bool* isCubeMap = nullptr);
HRESULT __cdecl LoadDDSTextureFromFile(
_In_ ID3D12Device* d3dDevice,
_In_z_ const wchar_t* szFileName,
_Outptr_ ID3D12Resource** texture,
std::unique_ptr<uint8_t[]>& ddsData,
std::vector<D3D12_SUBRESOURCE_DATA>& subresources,
size_t maxsize = 0,
_Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr,
_Out_opt_ bool* isCubeMap = nullptr);
// Extended version
HRESULT __cdecl LoadDDSTextureFromMemoryEx(
_In_ ID3D12Device* d3dDevice,
_In_reads_bytes_(ddsDataSize) const uint8_t* ddsData,
size_t ddsDataSize,
size_t maxsize,
D3D12_RESOURCE_FLAGS flags,
bool forceSRGB,
bool reserveFullMipChain,
_Outptr_ ID3D12Resource** texture,
std::vector<D3D12_SUBRESOURCE_DATA>& subresources,
_Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr,
_Out_opt_ bool* isCubeMap = nullptr);
HRESULT __cdecl LoadDDSTextureFromFileEx(
_In_ ID3D12Device* d3dDevice,
_In_z_ const wchar_t* szFileName,
size_t maxsize,
D3D12_RESOURCE_FLAGS flags,
bool forceSRGB,
bool reserveFullMipChain,
_Outptr_ ID3D12Resource** texture,
std::unique_ptr<uint8_t[]>& ddsData,
std::vector<D3D12_SUBRESOURCE_DATA>& subresources,
_Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr,
_Out_opt_ bool* isCubeMap = nullptr);
}