Well it's something ig
This commit is contained in:
@@ -13,17 +13,18 @@ DepthBuffer::~DepthBuffer()
|
||||
|
||||
bool DepthBuffer::Initialize()
|
||||
{
|
||||
// Create a depth buffer
|
||||
// Create a depth buffer with a typeless format
|
||||
D3D11_TEXTURE2D_DESC desc = {};
|
||||
desc.Width = m_width;
|
||||
desc.Height = m_height;
|
||||
desc.MipLevels = 1;
|
||||
desc.ArraySize = 1;
|
||||
desc.Format = DXGI_FORMAT_D32_FLOAT;
|
||||
desc.Format = DXGI_FORMAT_R32_TYPELESS; // Typeless format
|
||||
desc.SampleDesc.Count = 1;
|
||||
desc.Usage = D3D11_USAGE_DEFAULT;
|
||||
desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
|
||||
desc.BindFlags = D3D11_BIND_DEPTH_STENCIL | D3D11_BIND_SHADER_RESOURCE; // Add shader resource binding
|
||||
desc.CPUAccessFlags = 0;
|
||||
desc.MiscFlags = 0;
|
||||
|
||||
HRESULT hr = m_device->CreateTexture2D(&desc, nullptr, &m_depthBuffer);
|
||||
if (FAILED(hr))
|
||||
@@ -33,8 +34,9 @@ bool DepthBuffer::Initialize()
|
||||
|
||||
// Create DepthStencilView
|
||||
D3D11_DEPTH_STENCIL_VIEW_DESC dsvDesc = {};
|
||||
dsvDesc.Format = DXGI_FORMAT_D32_FLOAT;
|
||||
dsvDesc.Format = DXGI_FORMAT_D32_FLOAT; // Depth format
|
||||
dsvDesc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
|
||||
dsvDesc.Texture2D.MipSlice = 0;
|
||||
hr = m_device->CreateDepthStencilView(m_depthBuffer, &dsvDesc, &m_depthStencilView);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
@@ -42,4 +44,14 @@ bool DepthBuffer::Initialize()
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
ID3D11Texture2D* DepthBuffer::GetDepthBuffer()
|
||||
{
|
||||
return m_depthBuffer;
|
||||
}
|
||||
|
||||
ID3D11DepthStencilView* DepthBuffer::GetDepthStencilView()
|
||||
{
|
||||
return m_depthStencilView;
|
||||
}
|
||||
|
||||
@@ -13,6 +13,10 @@ public:
|
||||
ID3D11Texture2D* GetDepthBuffer() const { return m_depthBuffer; }
|
||||
ID3D11DepthStencilView* GetDepthStencilView() const { return m_depthStencilView; }
|
||||
|
||||
ID3D11DepthStencilView *GetDepthStencilView();
|
||||
|
||||
ID3D11Texture2D *GetDepthBuffer();
|
||||
|
||||
private:
|
||||
ID3D11Device* m_device;
|
||||
UINT m_width;
|
||||
@@ -20,6 +24,7 @@ private:
|
||||
|
||||
ID3D11Texture2D* m_depthBuffer;
|
||||
ID3D11DepthStencilView* m_depthStencilView;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -20,16 +20,22 @@ bool ShadowMapBuffer::Initialize() {
|
||||
|
||||
// Create ShaderResourceView for the depth buffer
|
||||
D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc = {};
|
||||
srvDesc.Format = DXGI_FORMAT_R32_FLOAT;
|
||||
srvDesc.Format = DXGI_FORMAT_R32_FLOAT; // Shader-readable format
|
||||
srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
|
||||
srvDesc.Texture2D.MipLevels = 1;
|
||||
srvDesc.Texture2D.MostDetailedMip = 0;
|
||||
|
||||
HRESULT hr = m_device->CreateShaderResourceView(m_depthBuffer.GetDepthBuffer(), &srvDesc, &m_shaderResourceView);
|
||||
if (FAILED(hr)) {
|
||||
if (FAILED(hr))
|
||||
{
|
||||
OutputDebugStringA("Failed to create ShaderResourceView for ShadowMapBuffer.\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void ShadowMapBuffer::SetRenderTarget(ID3D11DeviceContext *deviceContext) {
|
||||
deviceContext->OMSetRenderTargets(0, nullptr, m_depthBuffer.GetDepthStencilView());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user