depth buffer
This commit is contained in:
1 parent
db9aca2128
commit
62e097c9fa
2 files changed
+67
No files matched your search
@@ -268,6 +268,37 @@ R_Handle r_window_equip(WM_Window handle)
|
|||||||
Vector2i resolution = { (int32)(client_rect.x1 - client_rect.x0), (int32)(client_rect.y1 - client_rect.y0) };
|
Vector2i resolution = { (int32)(client_rect.x1 - client_rect.x0), (int32)(client_rect.y1 - client_rect.y0) };
|
||||||
window->last_resolution = resolution;
|
window->last_resolution = resolution;
|
||||||
|
|
||||||
|
// create depth buffer
|
||||||
|
D3D12_DESCRIPTOR_HEAP_DESC dsv_heap_desc = { 0 };
|
||||||
|
dsv_heap_desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_DSV;
|
||||||
|
dsv_heap_desc.NumDescriptors = 1;
|
||||||
|
dsv_heap_desc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE;
|
||||||
|
ID3D12Device4_CreateDescriptorHeap(r_d3d12_state->device, &dsv_heap_desc, &IID_ID3D12DescriptorHeap,
|
||||||
|
(void**)&window->dsv_heap);
|
||||||
|
ID3D12DescriptorHeap_GetCPUDescriptorHandleForHeapStart(window->dsv_heap, &window->dsv_handle);
|
||||||
|
|
||||||
|
D3D12_HEAP_PROPERTIES depth_prop = { 0 };
|
||||||
|
depth_prop.Type = D3D12_HEAP_TYPE_DEFAULT;
|
||||||
|
D3D12_RESOURCE_DESC depth_desc = { 0 };
|
||||||
|
depth_desc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;
|
||||||
|
depth_desc.Format = DXGI_FORMAT_D32_FLOAT;
|
||||||
|
depth_desc.Width = resolution.x;
|
||||||
|
depth_desc.Height = resolution.y;
|
||||||
|
depth_desc.DepthOrArraySize = 1;
|
||||||
|
depth_desc.MipLevels = 1;
|
||||||
|
depth_desc.SampleDesc.Count = 1;
|
||||||
|
depth_desc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN;
|
||||||
|
depth_desc.Flags = D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL;
|
||||||
|
|
||||||
|
D3D12_CLEAR_VALUE depth_clear_val = { 0 };
|
||||||
|
depth_clear_val.Format = DXGI_FORMAT_D32_FLOAT;
|
||||||
|
depth_clear_val.DepthStencil.Depth = 1.0f;
|
||||||
|
|
||||||
|
ID3D12Device4_CreateCommittedResource(r_d3d12_state->device, &depth_prop, D3D12_HEAP_FLAG_NONE, &depth_desc,
|
||||||
|
D3D12_RESOURCE_STATE_DEPTH_WRITE, &depth_clear_val, &IID_ID3D12Resource,
|
||||||
|
(void**)&window->depth_buffer);
|
||||||
|
ID3D12Device4_CreateDepthStencilView(r_d3d12_state->device, window->depth_buffer, 0, window->dsv_handle);
|
||||||
|
|
||||||
result = r_d3d12_handle_from_window(window);
|
result = r_d3d12_handle_from_window(window);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
@@ -282,6 +313,8 @@ void r_window_unequip(WM_Window handle, R_Handle handle_equip)
|
|||||||
R_D3D12_Window* window = r_d3d12_window_from_handle(handle_equip);
|
R_D3D12_Window* window = r_d3d12_window_from_handle(handle_equip);
|
||||||
if (window != 0 && window != &r_d3d12_nil_window)
|
if (window != 0 && window != &r_d3d12_nil_window)
|
||||||
{
|
{
|
||||||
|
ID3D12Resource_Release(window->depth_buffer);
|
||||||
|
ID3D12DescriptorHeap_Release(window->dsv_heap);
|
||||||
for EachIndex(i, 2)
|
for EachIndex(i, 2)
|
||||||
{
|
{
|
||||||
ID3D12Resource_Release(window->framebuffer[i]);
|
ID3D12Resource_Release(window->framebuffer[i]);
|
||||||
@@ -356,6 +389,31 @@ void r_window_begin_frame(WM_Window window, R_Handle window_equip)
|
|||||||
IDXGISwapChain3_GetBuffer(r_window->swapchain, i, &IID_ID3D12Resource, (void**)&r_window->framebuffer[i]);
|
IDXGISwapChain3_GetBuffer(r_window->swapchain, i, &IID_ID3D12Resource, (void**)&r_window->framebuffer[i]);
|
||||||
ID3D12Device4_CreateRenderTargetView(r_d3d12_state->device, r_window->framebuffer[i], 0, r_window->rtv_handles[i]);
|
ID3D12Device4_CreateRenderTargetView(r_d3d12_state->device, r_window->framebuffer[i], 0, r_window->rtv_handles[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// recreate depth buffer
|
||||||
|
ID3D12Resource_Release(r_window->depth_buffer);
|
||||||
|
D3D12_HEAP_PROPERTIES depth_prop = { 0 };
|
||||||
|
depth_prop.Type = D3D12_HEAP_TYPE_DEFAULT;
|
||||||
|
D3D12_RESOURCE_DESC depth_desc = { 0 };
|
||||||
|
depth_desc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;
|
||||||
|
depth_desc.Format = DXGI_FORMAT_D32_FLOAT;
|
||||||
|
depth_desc.Width = resolution.x;
|
||||||
|
depth_desc.Height = resolution.y;
|
||||||
|
depth_desc.DepthOrArraySize = 1;
|
||||||
|
depth_desc.MipLevels = 1;
|
||||||
|
depth_desc.SampleDesc.Count = 1;
|
||||||
|
depth_desc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN;
|
||||||
|
depth_desc.Flags = D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL;
|
||||||
|
|
||||||
|
D3D12_CLEAR_VALUE depth_clear_val = { 0 };
|
||||||
|
depth_clear_val.Format = DXGI_FORMAT_D32_FLOAT;
|
||||||
|
depth_clear_val.DepthStencil.Depth = 1.0f;
|
||||||
|
|
||||||
|
ID3D12Device4_CreateCommittedResource(r_d3d12_state->device, &depth_prop, D3D12_HEAP_FLAG_NONE, &depth_desc,
|
||||||
|
D3D12_RESOURCE_STATE_DEPTH_WRITE, &depth_clear_val,
|
||||||
|
&IID_ID3D12Resource, (void**)&r_window->depth_buffer);
|
||||||
|
ID3D12Resource_SetName(r_window->depth_buffer, L"Window_DepthBuffer");
|
||||||
|
ID3D12Device4_CreateDepthStencilView(r_d3d12_state->device, r_window->depth_buffer, 0, r_window->dsv_handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open the command list for that window that frame
|
// Open the command list for that window that frame
|
||||||
@@ -380,6 +438,10 @@ void r_window_begin_frame(WM_Window window, R_Handle window_equip)
|
|||||||
float32 background[4] = { 0.1f, 0.2f, 0.8f, 1.0f };
|
float32 background[4] = { 0.1f, 0.2f, 0.8f, 1.0f };
|
||||||
ID3D12GraphicsCommandList_ClearRenderTargetView(cmd_list, r_window->rtv_handles[r_window->framebuffer_idx],
|
ID3D12GraphicsCommandList_ClearRenderTargetView(cmd_list, r_window->rtv_handles[r_window->framebuffer_idx],
|
||||||
background, 0, 0);
|
background, 0, 0);
|
||||||
|
|
||||||
|
ID3D12GraphicsCommandList_ClearDepthStencilView(cmd_list, r_window->dsv_handle, D3D12_CLEAR_FLAG_DEPTH, 1.0f, 0, 0, 0);
|
||||||
|
ID3D12GraphicsCommandList_OMSetRenderTargets(cmd_list, 1, &r_window->rtv_handles[r_window->framebuffer_idx],
|
||||||
|
FALSE, &r_window->dsv_handle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,11 @@ struct R_D3D12_Window
|
|||||||
ID3D12DescriptorHeap* rtv_heap;
|
ID3D12DescriptorHeap* rtv_heap;
|
||||||
uint8 framebuffer_idx;
|
uint8 framebuffer_idx;
|
||||||
|
|
||||||
|
// depth buffer
|
||||||
|
ID3D12Resource* depth_buffer;
|
||||||
|
ID3D12DescriptorHeap* dsv_heap;
|
||||||
|
D3D12_CPU_DESCRIPTOR_HANDLE dsv_handle;
|
||||||
|
|
||||||
// last state
|
// last state
|
||||||
Vector2i last_resolution;
|
Vector2i last_resolution;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in new issue
Block a user