From b2b279fbb1188eee512f4a9e2435a5d1a1da5701 Mon Sep 17 00:00:00 2001 From: walbourn_cp Date: Fri, 30 Nov 2012 13:10:48 -0800 Subject: [PATCH] DirectXTex: added Ex versions of CreateTexture and CreateShaderResource for advanced / expert scenarios --- DirectXTex/DirectXTex.h | 8 ++++++ DirectXTex/DirectXTexD3D11.cpp | 50 +++++++++++++++++++++++++--------- 2 files changed, 45 insertions(+), 13 deletions(-) diff --git a/DirectXTex/DirectXTex.h b/DirectXTex/DirectXTex.h index 0de8b03..454664e 100644 --- a/DirectXTex/DirectXTex.h +++ b/DirectXTex/DirectXTex.h @@ -459,6 +459,14 @@ namespace DirectX HRESULT CreateShaderResourceView( _In_ ID3D11Device* pDevice, _In_count_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata, _Deref_out_ ID3D11ShaderResourceView** ppSRV ); + HRESULT CreateTextureEx( _In_ ID3D11Device* pDevice, _In_count_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata, + _In_ D3D11_USAGE usage, _In_ unsigned int bindFlags, _In_ unsigned int cpuAccessFlags, _In_ unsigned int miscFlags, + _Deref_out_ ID3D11Resource** ppResource ); + + HRESULT CreateShaderResourceViewEx( _In_ ID3D11Device* pDevice, _In_count_(nimages) const Image* srcImages, _In_ size_t nimages, _In_ const TexMetadata& metadata, + _In_ D3D11_USAGE usage, _In_ unsigned int bindFlags, _In_ unsigned int cpuAccessFlags, _In_ unsigned int miscFlags, + _Deref_out_ ID3D11ShaderResourceView** ppSRV ); + HRESULT CaptureTexture( _In_ ID3D11Device* pDevice, _In_ ID3D11DeviceContext* pContext, _In_ ID3D11Resource* pSource, _Out_ ScratchImage& result ); #include "DirectXTex.inl" diff --git a/DirectXTex/DirectXTexD3D11.cpp b/DirectXTex/DirectXTexD3D11.cpp index 95d659e..e9959a5 100644 --- a/DirectXTex/DirectXTexD3D11.cpp +++ b/DirectXTex/DirectXTexD3D11.cpp @@ -338,6 +338,15 @@ bool IsSupportedTexture( ID3D11Device* pDevice, const TexMetadata& metadata ) //------------------------------------------------------------------------------------- HRESULT CreateTexture( ID3D11Device* pDevice, const Image* srcImages, size_t nimages, const TexMetadata& metadata, ID3D11Resource** ppResource ) +{ + return CreateTextureEx( pDevice, srcImages, nimages, metadata, + D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, 0, 0, + ppResource ); +} + +HRESULT CreateTextureEx( ID3D11Device* pDevice, const Image* srcImages, size_t nimages, const TexMetadata& metadata, + D3D11_USAGE usage, unsigned int bindFlags, unsigned int cpuAccessFlags, unsigned int miscFlags, + ID3D11Resource** ppResource ) { if ( !pDevice || !srcImages || !nimages || !ppResource ) return E_INVALIDARG; @@ -465,10 +474,10 @@ HRESULT CreateTexture( ID3D11Device* pDevice, const Image* srcImages, size_t nim desc.MipLevels = static_cast( metadata.mipLevels ); desc.ArraySize = static_cast( metadata.arraySize ); desc.Format = metadata.format; - desc.Usage = D3D11_USAGE_DEFAULT; - desc.BindFlags = D3D11_BIND_SHADER_RESOURCE; - desc.CPUAccessFlags = 0; - desc.MiscFlags = 0; + desc.Usage = usage; + desc.BindFlags = bindFlags; + desc.CPUAccessFlags = cpuAccessFlags; + desc.MiscFlags = miscFlags & ~D3D11_RESOURCE_MISC_TEXTURECUBE; hr = pDevice->CreateTexture1D( &desc, initData.get(), reinterpret_cast(ppResource) ); } @@ -484,10 +493,13 @@ HRESULT CreateTexture( ID3D11Device* pDevice, const Image* srcImages, size_t nim desc.Format = metadata.format; desc.SampleDesc.Count = 1; desc.SampleDesc.Quality = 0; - desc.Usage = D3D11_USAGE_DEFAULT; - desc.BindFlags = D3D11_BIND_SHADER_RESOURCE; - desc.CPUAccessFlags = 0; - desc.MiscFlags = (metadata.miscFlags & TEX_MISC_TEXTURECUBE) ? D3D11_RESOURCE_MISC_TEXTURECUBE : 0; + desc.Usage = usage; + desc.BindFlags = bindFlags; + desc.CPUAccessFlags = cpuAccessFlags; + if (metadata.miscFlags & TEX_MISC_TEXTURECUBE) + desc.MiscFlags = miscFlags | D3D11_RESOURCE_MISC_TEXTURECUBE; + else + desc.MiscFlags = miscFlags & ~D3D11_RESOURCE_MISC_TEXTURECUBE; hr = pDevice->CreateTexture2D( &desc, initData.get(), reinterpret_cast(ppResource) ); } @@ -501,10 +513,10 @@ HRESULT CreateTexture( ID3D11Device* pDevice, const Image* srcImages, size_t nim desc.Depth = static_cast( metadata.depth ); desc.MipLevels = static_cast( metadata.mipLevels ); desc.Format = metadata.format; - desc.Usage = D3D11_USAGE_DEFAULT; - desc.BindFlags = D3D11_BIND_SHADER_RESOURCE; - desc.CPUAccessFlags = 0; - desc.MiscFlags = 0; + desc.Usage = usage; + desc.BindFlags = bindFlags; + desc.CPUAccessFlags = cpuAccessFlags; + desc.MiscFlags = miscFlags & ~D3D11_RESOURCE_MISC_TEXTURECUBE; hr = pDevice->CreateTexture3D( &desc, initData.get(), reinterpret_cast(ppResource) ); } @@ -520,12 +532,24 @@ HRESULT CreateTexture( ID3D11Device* pDevice, const Image* srcImages, size_t nim //------------------------------------------------------------------------------------- HRESULT CreateShaderResourceView( ID3D11Device* pDevice, const Image* srcImages, size_t nimages, const TexMetadata& metadata, ID3D11ShaderResourceView** ppSRV ) +{ + return CreateShaderResourceViewEx( pDevice, srcImages, nimages, metadata, + D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, 0, 0, + ppSRV ); +} + + +HRESULT CreateShaderResourceViewEx( ID3D11Device* pDevice, const Image* srcImages, size_t nimages, const TexMetadata& metadata, + D3D11_USAGE usage, unsigned int bindFlags, unsigned int cpuAccessFlags, unsigned int miscFlags, + ID3D11ShaderResourceView** ppSRV ) { if ( !ppSRV ) return E_INVALIDARG; ScopedObject resource; - HRESULT hr = CreateTexture( pDevice, srcImages, nimages, metadata, &resource ); + HRESULT hr = CreateTextureEx( pDevice, srcImages, nimages, metadata, + usage, bindFlags, cpuAccessFlags, miscFlags, + &resource ); if ( FAILED(hr) ) return hr;