Replace depth buffer creation with D3D12Texture wrapper
This commit is contained in:
@@ -19,6 +19,7 @@ public:
|
||||
bool InitializeFromExisting(ID3D12Resource* resource);
|
||||
bool InitializeFromData(ID3D12Device* device, ID3D12GraphicsCommandList* commandList,
|
||||
const void* pixelData, uint32_t width, uint32_t height, DXGI_FORMAT format);
|
||||
bool InitializeDepthStencil(ID3D12Device* device, uint32_t width, uint32_t height, DXGI_FORMAT format = DXGI_FORMAT_D24_UNORM_S8_UINT);
|
||||
void Shutdown();
|
||||
|
||||
ID3D12Resource* GetResource() const { return m_resource.Get(); }
|
||||
|
||||
@@ -143,6 +143,40 @@ bool D3D12Texture::InitializeFromData(ID3D12Device* device, ID3D12GraphicsComman
|
||||
return true;
|
||||
}
|
||||
|
||||
bool D3D12Texture::InitializeDepthStencil(ID3D12Device* device, uint32_t width, uint32_t height, DXGI_FORMAT format) {
|
||||
D3D12_RESOURCE_DESC desc = {};
|
||||
desc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;
|
||||
desc.Alignment = 0;
|
||||
desc.Width = width;
|
||||
desc.Height = height;
|
||||
desc.DepthOrArraySize = 1;
|
||||
desc.MipLevels = 1;
|
||||
desc.Format = format;
|
||||
desc.SampleDesc.Count = 1;
|
||||
desc.SampleDesc.Quality = 0;
|
||||
desc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN;
|
||||
desc.Flags = D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL;
|
||||
|
||||
D3D12_HEAP_PROPERTIES heapProperties = {};
|
||||
heapProperties.Type = D3D12_HEAP_TYPE_DEFAULT;
|
||||
|
||||
D3D12_CLEAR_VALUE clearValue = {};
|
||||
clearValue.Format = format;
|
||||
clearValue.DepthStencil.Depth = 1.0f;
|
||||
clearValue.DepthStencil.Stencil = 0;
|
||||
|
||||
HRESULT hResult = device->CreateCommittedResource(
|
||||
&heapProperties,
|
||||
D3D12_HEAP_FLAG_NONE,
|
||||
&desc,
|
||||
D3D12_RESOURCE_STATE_DEPTH_WRITE,
|
||||
&clearValue,
|
||||
IID_PPV_ARGS(&m_resource)
|
||||
);
|
||||
|
||||
return SUCCEEDED(hResult);
|
||||
}
|
||||
|
||||
void D3D12Texture::Shutdown() {
|
||||
m_resource.Reset();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user