2016-08-22 18:26:36 +00:00
|
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
// File: DDSTextureLoader12.h
|
|
|
|
//
|
2016-09-23 05:34:50 +00:00
|
|
|
// Functions for loading a DDS texture and creating a Direct3D runtime resource for it
|
2016-08-22 18:26:36 +00:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
2021-02-27 06:59:42 +00:00
|
|
|
// Copyright (c) Microsoft Corporation.
|
2018-02-24 06:24:46 +00:00
|
|
|
// Licensed under the MIT License.
|
2016-08-22 18:26:36 +00:00
|
|
|
//
|
|
|
|
// http://go.microsoft.com/fwlink/?LinkId=248926
|
|
|
|
// http://go.microsoft.com/fwlink/?LinkID=615561
|
|
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2021-01-08 21:31:20 +00:00
|
|
|
#if defined(WIN32) || defined(_WIN32)
|
2016-08-22 18:26:36 +00:00
|
|
|
#include <d3d12.h>
|
2021-01-08 10:20:55 +00:00
|
|
|
#else
|
|
|
|
#include <wsl/winadapter.h>
|
|
|
|
#include <wsl/wrladapter.h>
|
|
|
|
#include <directx/d3d12.h>
|
|
|
|
#endif
|
2016-08-22 18:26:36 +00:00
|
|
|
|
2020-12-31 21:53:09 +00:00
|
|
|
#include <cstddef>
|
2020-03-10 08:05:10 +00:00
|
|
|
#include <cstdint>
|
2016-08-22 18:26:36 +00:00
|
|
|
#include <memory>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DirectX
|
|
|
|
{
|
2019-12-11 20:04:52 +00:00
|
|
|
#ifndef DDS_ALPHA_MODE_DEFINED
|
|
|
|
#define DDS_ALPHA_MODE_DEFINED
|
2020-05-21 07:40:33 +00:00
|
|
|
enum DDS_ALPHA_MODE : uint32_t
|
2016-08-22 18:26:36 +00:00
|
|
|
{
|
|
|
|
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,
|
|
|
|
};
|
2021-06-03 00:13:29 +00:00
|
|
|
|
2019-12-11 20:04:52 +00:00
|
|
|
#endif
|
2016-08-22 18:26:36 +00:00
|
|
|
|
2021-06-03 00:13:29 +00:00
|
|
|
#ifndef DDS_LOADER_FLAGS_DEFINED
|
|
|
|
#define DDS_LOADER_FLAGS_DEFINED
|
|
|
|
|
|
|
|
enum DDS_LOADER_FLAGS : uint32_t
|
2016-09-23 05:34:50 +00:00
|
|
|
{
|
2020-06-02 02:00:09 +00:00
|
|
|
DDS_LOADER_DEFAULT = 0,
|
|
|
|
DDS_LOADER_FORCE_SRGB = 0x1,
|
|
|
|
DDS_LOADER_MIP_RESERVE = 0x8,
|
2016-09-23 05:34:50 +00:00
|
|
|
};
|
|
|
|
|
2021-06-03 00:13:29 +00:00
|
|
|
#ifdef __clang__
|
|
|
|
#pragma clang diagnostic push
|
|
|
|
#pragma clang diagnostic ignored "-Wdeprecated-dynamic-exception-spec"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
DEFINE_ENUM_FLAG_OPERATORS(DDS_LOADER_FLAGS);
|
|
|
|
|
|
|
|
#ifdef __clang__
|
|
|
|
#pragma clang diagnostic pop
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2016-08-22 18:26:36 +00:00
|
|
|
// 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,
|
2016-09-23 05:34:50 +00:00
|
|
|
D3D12_RESOURCE_FLAGS resFlags,
|
2021-06-03 00:13:29 +00:00
|
|
|
DDS_LOADER_FLAGS loadFlags,
|
2016-08-22 18:26:36 +00:00
|
|
|
_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,
|
2016-09-23 05:34:50 +00:00
|
|
|
D3D12_RESOURCE_FLAGS resFlags,
|
2021-06-03 00:13:29 +00:00
|
|
|
DDS_LOADER_FLAGS loadFlags,
|
2016-08-22 18:26:36 +00:00
|
|
|
_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);
|
|
|
|
}
|