From 93aba977e8a9dcec124a93e83a9878a61e16e2b8 Mon Sep 17 00:00:00 2001 From: Chuck Walbourn Date: Tue, 14 Feb 2017 15:51:26 -0800 Subject: [PATCH] XboxDDSTextureLoader updates --- Inc/XboxDDSTextureLoader.h | 120 ++++++++++++++++++----------------- Src/XboxDDSTextureLoader.cpp | 12 +++- 2 files changed, 72 insertions(+), 60 deletions(-) diff --git a/Inc/XboxDDSTextureLoader.h b/Inc/XboxDDSTextureLoader.h index d42255d..e1e0481 100644 --- a/Inc/XboxDDSTextureLoader.h +++ b/Inc/XboxDDSTextureLoader.h @@ -1,60 +1,62 @@ -//-------------------------------------------------------------------------------------- -// File: XboxDDSTextureLoader.h -// -// Functions for loading a DDS texture using the XBOX extended header and creating a -// Direct3D11.X runtime resource for it via the CreatePlacement APIs -// -// Note these functions will not load standard DDS files. Use the DDSTextureLoader -// module in the DirectXTex package or as part of the DirectXTK library to load -// these files which use standard Direct3D resource creation APIs. -// -// 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=248929 -//-------------------------------------------------------------------------------------- - -#pragma once - -#if !defined(_XBOX_ONE) || !defined(_TITLE) -#error This module only supports Xbox One exclusive apps -#endif - -#include - -#include - -namespace Xbox -{ - 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, - }; - - HRESULT __cdecl CreateDDSTextureFromMemory( - _In_ ID3D11DeviceX* d3dDevice, - _In_reads_bytes_(ddsDataSize) const uint8_t* ddsData, - _In_ size_t ddsDataSize, - _Outptr_opt_ ID3D11Resource** texture, - _Outptr_opt_ ID3D11ShaderResourceView** textureView, - _Outptr_ void** grfxMemory, - _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr, - _In_ bool forceSRGB = false); - - HRESULT __cdecl CreateDDSTextureFromFile( _In_ ID3D11DeviceX* d3dDevice, - _In_z_ const wchar_t* szFileName, - _Outptr_opt_ ID3D11Resource** texture, - _Outptr_opt_ ID3D11ShaderResourceView** textureView, - _Outptr_ void** grfxMemory, - _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr, - _In_ bool forceSRGB = false); +//-------------------------------------------------------------------------------------- +// File: XboxDDSTextureLoader.h +// +// Functions for loading a DDS texture using the XBOX extended header and creating a +// Direct3D11.X runtime resource for it via the CreatePlacement APIs +// +// Note these functions will not load standard DDS files. Use the DDSTextureLoader +// module in the DirectXTex package or as part of the DirectXTK library to load +// these files which use standard Direct3D resource creation APIs. +// +// 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=248929 +//-------------------------------------------------------------------------------------- + +#pragma once + +#if !defined(_XBOX_ONE) || !defined(_TITLE) +#error This module only supports Xbox One exclusive apps +#endif + +#include + +#include + +namespace Xbox +{ + 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, + }; + + HRESULT __cdecl CreateDDSTextureFromMemory( + _In_ ID3D11DeviceX* d3dDevice, + _In_reads_bytes_(ddsDataSize) const uint8_t* ddsData, + _In_ size_t ddsDataSize, + _Outptr_opt_ ID3D11Resource** texture, + _Outptr_opt_ ID3D11ShaderResourceView** textureView, + _Outptr_ void** grfxMemory, + _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr, + _In_ bool forceSRGB = false); + + HRESULT __cdecl CreateDDSTextureFromFile( _In_ ID3D11DeviceX* d3dDevice, + _In_z_ const wchar_t* szFileName, + _Outptr_opt_ ID3D11Resource** texture, + _Outptr_opt_ ID3D11ShaderResourceView** textureView, + _Outptr_ void** grfxMemory, + _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr, + _In_ bool forceSRGB = false); + + void FreeDDSTextureMemory( _In_opt_ void* grfxMemory ); } \ No newline at end of file diff --git a/Src/XboxDDSTextureLoader.cpp b/Src/XboxDDSTextureLoader.cpp index b35d9fe..c75ee17 100644 --- a/Src/XboxDDSTextureLoader.cpp +++ b/Src/XboxDDSTextureLoader.cpp @@ -575,7 +575,7 @@ namespace texture, textureView); if (FAILED(hr)) { - D3DFreeGraphicsMemory(*grfxMemory); + (void)D3DFreeGraphicsMemory(*grfxMemory); *grfxMemory = nullptr; } @@ -772,3 +772,13 @@ HRESULT Xbox::CreateDDSTextureFromFile( ID3D11DeviceX* d3dDevice, return hr; } + +//-------------------------------------------------------------------------------------- +_Use_decl_annotations_ +void Xbox::FreeDDSTextureMemory(void* grfxMemory) +{ + if (grfxMemory) + { + (void)D3DFreeGraphicsMemory(grfxMemory); + } +}