diff --git a/Src/d3dx12.h b/Src/d3dx12.h index 6538b82b..cda6e036 100644 --- a/Src/d3dx12.h +++ b/Src/d3dx12.h @@ -53,6 +53,71 @@ struct CD3DX12_RECT : public D3D12_RECT operator const D3D12_RECT&() const { return *this; } }; +//------------------------------------------------------------------------------------------------ +struct CD3DX12_VIEWPORT : public D3D12_VIEWPORT +{ + CD3DX12_VIEWPORT() + {} + explicit CD3DX12_VIEWPORT( const D3D12_VIEWPORT& o ) : + D3D12_VIEWPORT( o ) + {} + explicit CD3DX12_VIEWPORT( + FLOAT topLeftX, + FLOAT topLeftY, + FLOAT width, + FLOAT height, + FLOAT minDepth = D3D12_MIN_DEPTH, + FLOAT maxDepth = D3D12_MAX_DEPTH ) + { + TopLeftX = topLeftX; + TopLeftY = topLeftY; + Width = width; + Height = height; + MinDepth = minDepth; + MaxDepth = maxDepth; + } + explicit CD3DX12_VIEWPORT( + _In_ ID3D12Resource* pResource, + UINT mipSlice = 0, + FLOAT topLeftX = 0.0f, + FLOAT topLeftY = 0.0f, + FLOAT minDepth = D3D12_MIN_DEPTH, + FLOAT maxDepth = D3D12_MAX_DEPTH ) + { + D3D12_RESOURCE_DESC Desc = pResource->GetDesc(); + const UINT64 SubresourceWidth = Desc.Width >> mipSlice; + const UINT64 SubresourceHeight = Desc.Height >> mipSlice; + switch (Desc.Dimension) + { + case D3D12_RESOURCE_DIMENSION_BUFFER: + TopLeftX = topLeftX; + TopLeftY = 0.0f; + Width = Desc.Width - topLeftX; + Height = 1.0f; + break; + case D3D12_RESOURCE_DIMENSION_TEXTURE1D: + TopLeftX = topLeftX; + TopLeftY = 0.0f; + Width = (SubresourceWidth ? SubresourceWidth : 1.0f) - topLeftX; + Height = 1.0f; + break; + case D3D12_RESOURCE_DIMENSION_TEXTURE2D: + case D3D12_RESOURCE_DIMENSION_TEXTURE3D: + TopLeftX = topLeftX; + TopLeftY = topLeftY; + Width = (SubresourceWidth ? SubresourceWidth : 1.0f) - topLeftX; + Height = (SubresourceHeight ? SubresourceHeight: 1.0f) - topLeftY; + break; + default: break; + } + + MinDepth = minDepth; + MaxDepth = maxDepth; + } + ~CD3DX12_VIEWPORT() {} + operator const D3D12_VIEWPORT&() const { return *this; } +}; + //------------------------------------------------------------------------------------------------ struct CD3DX12_BOX : public D3D12_BOX { @@ -453,13 +518,13 @@ struct CD3DX12_SHADER_BYTECODE : public D3D12_SHADER_BYTECODE D3D12_SHADER_BYTECODE(o) {} CD3DX12_SHADER_BYTECODE( - ID3DBlob* pShaderBlob ) + _In_ ID3DBlob* pShaderBlob ) { pShaderBytecode = pShaderBlob->GetBufferPointer(); BytecodeLength = pShaderBlob->GetBufferSize(); } CD3DX12_SHADER_BYTECODE( - void* _pShaderBytecode, + const void* _pShaderBytecode, SIZE_T bytecodeLength ) { pShaderBytecode = _pShaderBytecode; @@ -1938,6 +2003,7 @@ inline HRESULT D3DX12SerializeVersionedRootSignature( return E_INVALIDARG; } + #endif // defined( __cplusplus ) #endif //__D3DX12_H__