зеркало из https://github.com/microsoft/DirectXTK.git
DirectXTK: Added DirectXHelpers.h header with new MapGuard helper and public version fo SetDebugName template
This commit is contained in:
Родитель
f7c80a7c6b
Коммит
c5557333ec
|
@ -21,6 +21,7 @@
|
|||
<ItemGroup>
|
||||
<ClInclude Include="Inc\CommonStates.h" />
|
||||
<ClInclude Include="Inc\DDSTextureLoader.h" />
|
||||
<ClInclude Include="Inc\DirectXHelpers.h" />
|
||||
<ClInclude Include="Inc\Effects.h" />
|
||||
<ClInclude Include="Inc\GeometricPrimitive.h" />
|
||||
<ClInclude Include="Inc\Model.h" />
|
||||
|
|
|
@ -81,6 +81,9 @@
|
|||
<ClInclude Include="Inc\SimpleMath.inl">
|
||||
<Filter>Inc</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Inc\DirectXHelpers.h">
|
||||
<Filter>Inc</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Src\CommonStates.cpp">
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
<ItemGroup>
|
||||
<ClInclude Include="Inc\CommonStates.h" />
|
||||
<ClInclude Include="Inc\DDSTextureLoader.h" />
|
||||
<ClInclude Include="Inc\DirectXHelpers.h" />
|
||||
<ClInclude Include="Inc\Effects.h" />
|
||||
<ClInclude Include="Inc\GeometricPrimitive.h" />
|
||||
<ClInclude Include="Inc\Model.h" />
|
||||
|
|
|
@ -81,6 +81,9 @@
|
|||
<ClInclude Include="Inc\SimpleMath.inl">
|
||||
<Filter>Inc</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Inc\DirectXHelpers.h">
|
||||
<Filter>Inc</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Src\CommonStates.cpp">
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
<ItemGroup>
|
||||
<ClInclude Include="Inc\CommonStates.h" />
|
||||
<ClInclude Include="Inc\DDSTextureLoader.h" />
|
||||
<ClInclude Include="Inc\DirectXHelpers.h" />
|
||||
<ClInclude Include="Inc\Effects.h" />
|
||||
<ClInclude Include="Inc\GeometricPrimitive.h" />
|
||||
<ClInclude Include="Inc\Model.h" />
|
||||
|
|
|
@ -81,6 +81,9 @@
|
|||
<ClInclude Include="Inc\SimpleMath.inl">
|
||||
<Filter>Inc</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Inc\DirectXHelpers.h">
|
||||
<Filter>Inc</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Src\CommonStates.cpp">
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
<ClInclude Include="Inc\Audio.h" />
|
||||
<ClInclude Include="Inc\CommonStates.h" />
|
||||
<ClInclude Include="Inc\DDSTextureLoader.h" />
|
||||
<ClInclude Include="Inc\DirectXHelpers.h" />
|
||||
<ClInclude Include="Inc\Effects.h" />
|
||||
<ClInclude Include="Inc\GeometricPrimitive.h" />
|
||||
<ClInclude Include="Inc\Model.h" />
|
||||
|
|
|
@ -96,6 +96,9 @@
|
|||
<ClInclude Include="Audio\SoundCommon.h">
|
||||
<Filter>Audio</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Inc\DirectXHelpers.h">
|
||||
<Filter>Inc</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Src\CommonStates.cpp">
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
<ClInclude Include="Inc\Audio.h" />
|
||||
<ClInclude Include="Inc\CommonStates.h" />
|
||||
<ClInclude Include="Inc\DDSTextureLoader.h" />
|
||||
<ClInclude Include="Inc\DirectXHelpers.h" />
|
||||
<ClInclude Include="Inc\Effects.h" />
|
||||
<ClInclude Include="Inc\GeometricPrimitive.h" />
|
||||
<ClInclude Include="Inc\Model.h" />
|
||||
|
|
|
@ -96,6 +96,9 @@
|
|||
<ClInclude Include="Audio\SoundCommon.h">
|
||||
<Filter>Audio</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Inc\DirectXHelpers.h">
|
||||
<Filter>Inc</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Src\CommonStates.cpp">
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
<ClInclude Include="Inc\Audio.h" />
|
||||
<ClInclude Include="Inc\CommonStates.h" />
|
||||
<ClInclude Include="Inc\DDSTextureLoader.h" />
|
||||
<ClInclude Include="Inc\DirectXHelpers.h" />
|
||||
<ClInclude Include="Inc\Effects.h" />
|
||||
<ClInclude Include="Inc\GeometricPrimitive.h" />
|
||||
<ClInclude Include="Inc\Model.h" />
|
||||
|
|
|
@ -93,6 +93,9 @@
|
|||
<ClInclude Include="Audio\SoundCommon.h">
|
||||
<Filter>Audio</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Inc\DirectXHelpers.h">
|
||||
<Filter>Inc</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Src\CommonStates.cpp">
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
<ClInclude Include="Inc\Audio.h" />
|
||||
<ClInclude Include="Inc\CommonStates.h" />
|
||||
<ClInclude Include="Inc\DDSTextureLoader.h" />
|
||||
<ClInclude Include="Inc\DirectXHelpers.h" />
|
||||
<ClInclude Include="Inc\Effects.h" />
|
||||
<ClInclude Include="Inc\GeometricPrimitive.h" />
|
||||
<ClInclude Include="Inc\Model.h" />
|
||||
|
|
|
@ -95,6 +95,9 @@
|
|||
<ClInclude Include="Audio\SoundCommon.h">
|
||||
<Filter>Audio</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Inc\DirectXHelpers.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Src\AlphaTestEffect.cpp">
|
||||
|
|
|
@ -116,6 +116,7 @@
|
|||
<ClInclude Include="Inc\Audio.h" />
|
||||
<ClInclude Include="Inc\CommonStates.h" />
|
||||
<ClInclude Include="Inc\DDSTextureLoader.h" />
|
||||
<ClInclude Include="Inc\DirectXHelpers.h" />
|
||||
<ClInclude Include="Inc\Effects.h" />
|
||||
<ClInclude Include="Inc\GeometricPrimitive.h" />
|
||||
<ClInclude Include="Inc\Model.h" />
|
||||
|
|
|
@ -196,6 +196,9 @@
|
|||
<ClInclude Include="Audio\SoundCommon.h">
|
||||
<Filter>Audio</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Inc\DirectXHelpers.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Src\TeapotData.inc">
|
||||
|
|
|
@ -0,0 +1,120 @@
|
|||
//--------------------------------------------------------------------------------------
|
||||
// File: DirectXHelpers.h
|
||||
//
|
||||
// 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=248929
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
#pragma once
|
||||
|
||||
#if defined(_XBOX_ONE) && defined(_TITLE) && MONOLITHIC
|
||||
#include <d3d11_x.h>
|
||||
#define NO_D3D11_DEBUG_NAME
|
||||
#else
|
||||
#include <d3d11_1.h>
|
||||
#endif
|
||||
|
||||
#if !defined(NO_D3D11_DEBUG_NAME) && ( defined(_DEBUG) || defined(PROFILE) )
|
||||
#pragma comment(lib,"dxguid.lib")
|
||||
#endif
|
||||
|
||||
#include <exception>
|
||||
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4005)
|
||||
#include <stdint.h>
|
||||
#pragma warning(pop)
|
||||
|
||||
//
|
||||
// The core Direct3D headers provide the following helper C++ classes
|
||||
// CD3D11_RECT
|
||||
// CD3D11_BOX
|
||||
// CD3D11_DEPTH_STENCIL_DESC
|
||||
// CD3D11_BLEND_DESC, CD3D11_BLEND_DESC1
|
||||
// CD3D11_RASTERIZER_DESC, CD3D11_RASTERIZER_DESC1
|
||||
// CD3D11_BUFFER_DESC
|
||||
// CD3D11_TEXTURE1D_DESC
|
||||
// CD3D11_TEXTURE2D_DESC
|
||||
// CD3D11_TEXTURE3D_DESC
|
||||
// CD3D11_SHADER_RESOURCE_VIEW_DESC
|
||||
// CD3D11_RENDER_TARGET_VIEW_DESC
|
||||
// CD3D11_VIEWPORT
|
||||
// CD3D11_DEPTH_STENCIL_VIEW_DESC
|
||||
// CD3D11_UNORDERED_ACCESS_VIEW_DESC
|
||||
// CD3D11_SAMPLER_DESC
|
||||
// CD3D11_QUERY_DESC
|
||||
// CD3D11_COUNTER_DESC
|
||||
//
|
||||
|
||||
|
||||
namespace DirectX
|
||||
{
|
||||
// simliar to std::lock_guard for exception-safe Direct3D 11 resource locking
|
||||
class MapGuard : public D3D11_MAPPED_SUBRESOURCE
|
||||
{
|
||||
public:
|
||||
MapGuard( _In_ ID3D11DeviceContext* context,
|
||||
_In_ ID3D11Resource *resource,
|
||||
_In_ UINT subresource,
|
||||
_In_ D3D11_MAP mapType,
|
||||
_In_ UINT mapFlags )
|
||||
: mContext(context), mResource(resource), mSubresource(subresource)
|
||||
{
|
||||
HRESULT hr = mContext->Map( resource, subresource, mapType, mapFlags, this );
|
||||
if (FAILED(hr))
|
||||
{
|
||||
throw std::exception();
|
||||
}
|
||||
}
|
||||
|
||||
~MapGuard()
|
||||
{
|
||||
mContext->Unmap( mResource, mSubresource );
|
||||
}
|
||||
|
||||
uint8_t* get() const
|
||||
{
|
||||
return reinterpret_cast<uint8_t*>( pData );
|
||||
}
|
||||
uint8_t* get(size_t slice) const
|
||||
{
|
||||
return reinterpret_cast<uint8_t*>( pData ) + ( slice * DepthPitch );
|
||||
}
|
||||
|
||||
uint8_t* scanline(size_t row) const
|
||||
{
|
||||
return reinterpret_cast<uint8_t*>( pData ) + ( row * RowPitch );
|
||||
}
|
||||
uint8_t* scanline(size_t slice, size_t row) const
|
||||
{
|
||||
return reinterpret_cast<uint8_t*>( pData ) + ( slice * DepthPitch ) + ( row * RowPitch );
|
||||
}
|
||||
|
||||
private:
|
||||
ID3D11DeviceContext* mContext;
|
||||
ID3D11Resource* mResource;
|
||||
UINT mSubresource;
|
||||
|
||||
MapGuard(MapGuard const&);
|
||||
MapGuard& operator= (MapGuard const&);
|
||||
};
|
||||
|
||||
|
||||
// Helper sets a D3D resource name string (used by PIX and debug layer leak reporting).
|
||||
template<UINT TNameLength>
|
||||
inline void SetDebugObjectName(_In_ ID3D11DeviceChild* resource, _In_z_ const char (&name)[TNameLength])
|
||||
{
|
||||
#if !defined(NO_D3D11_DEBUG_NAME) && ( defined(_DEBUG) || defined(PROFILE) )
|
||||
resource->SetPrivateData(WKPDID_D3DDebugObjectName, TNameLength - 1, name);
|
||||
#else
|
||||
UNREFERENCED_PARAMETER(resource);
|
||||
UNREFERENCED_PARAMETER(name);
|
||||
#endif
|
||||
}
|
||||
}
|
|
@ -14,6 +14,7 @@
|
|||
#include "pch.h"
|
||||
#include "CommonStates.h"
|
||||
#include "DemandCreate.h"
|
||||
#include "DirectXHelpers.h"
|
||||
#include "SharedResourcePool.h"
|
||||
|
||||
using namespace DirectX;
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "DirectXHelpers.h"
|
||||
#include "PlatformHelpers.h"
|
||||
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "DDSTextureLoader.h"
|
||||
|
||||
#include "dds.h"
|
||||
#include "DirectXHelpers.h"
|
||||
#include "PlatformHelpers.h"
|
||||
|
||||
using namespace DirectX;
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include "GeometricPrimitive.h"
|
||||
#include "Effects.h"
|
||||
#include "CommonStates.h"
|
||||
#include "DirectXHelpers.h"
|
||||
#include "VertexTypes.h"
|
||||
#include "SharedResourcePool.h"
|
||||
#include "Bezier.h"
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include "Model.h"
|
||||
|
||||
#include "CommonStates.h"
|
||||
#include "DirectXHelpers.h"
|
||||
#include "Effects.h"
|
||||
#include "PlatformHelpers.h"
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include "Effects.h"
|
||||
#include "VertexTypes.h"
|
||||
|
||||
#include "DirectXHelpers.h"
|
||||
#include "PlatformHelpers.h"
|
||||
#include "BinaryReader.h"
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include "Effects.h"
|
||||
#include "VertexTypes.h"
|
||||
|
||||
#include "DirectXHelpers.h"
|
||||
#include "PlatformHelpers.h"
|
||||
#include "BinaryReader.h"
|
||||
|
||||
|
|
|
@ -17,9 +17,6 @@
|
|||
|
||||
#include <exception>
|
||||
|
||||
#if defined(_DEBUG) || defined(PROFILE)
|
||||
#pragma comment(lib,"dxguid.lib")
|
||||
#endif
|
||||
|
||||
namespace DirectX
|
||||
{
|
||||
|
@ -33,19 +30,6 @@ namespace DirectX
|
|||
}
|
||||
|
||||
|
||||
// Helper sets a D3D resource name string (used by PIX and debug layer leak reporting).
|
||||
template<UINT TNameLength>
|
||||
inline void SetDebugObjectName(_In_ ID3D11DeviceChild* resource, _In_z_ const char (&name)[TNameLength])
|
||||
{
|
||||
#if !defined(NO_D3D11_DEBUG_NAME) && ( defined(_DEBUG) || defined(PROFILE) )
|
||||
resource->SetPrivateData(WKPDID_D3DDebugObjectName, TNameLength - 1, name);
|
||||
#else
|
||||
UNREFERENCED_PARAMETER(resource);
|
||||
UNREFERENCED_PARAMETER(name);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
// Helper for output debug tracing
|
||||
inline void DebugTrace( _In_z_ _Printf_format_string_ const char* format, ... )
|
||||
{
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
|
||||
#include "pch.h"
|
||||
#include "PrimitiveBatch.h"
|
||||
#include "DirectXHelpers.h"
|
||||
#include "PlatformHelpers.h"
|
||||
|
||||
using namespace DirectX;
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include <vector>
|
||||
|
||||
#include "SpriteFont.h"
|
||||
#include "DirectXHelpers.h"
|
||||
#include "BinaryReader.h"
|
||||
|
||||
using namespace DirectX;
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
|
||||
#include "WICTextureLoader.h"
|
||||
|
||||
#include "DirectXHelpers.h"
|
||||
#include "PlatformHelpers.h"
|
||||
|
||||
using Microsoft::WRL::ComPtr;
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include "XboxDDSTextureLoader.h"
|
||||
|
||||
#include "dds.h"
|
||||
#include "DirectXHelpers.h"
|
||||
#include "PlatformHelpers.h"
|
||||
|
||||
#include <xdk.h>
|
||||
|
|
Загрузка…
Ссылка в новой задаче