Update DirectX12 example

omar 2024-11-20 23:05:22 +01:00
parent ec38f9b540
commit cee2e70842

@ -164,12 +164,21 @@ io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Cont
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // IF using Docking Branch
// Setup Platform/Renderer backends
ImGui_ImplWin32_Init(YOUR_HWND);
ImGui_ImplDX12_Init(YOUR_D3D_DEVICE, NUM_FRAME_IN_FLIGHT, YOUR_RENDER_TARGET_DXGI_FORMAT,
YOUR_SRV_DESC_HEAP,
// You'll need to designate a descriptor from your descriptor heap for Dear ImGui to use internally for its font texture's SRV
YOUR_CPU_DESCRIPTOR_HANDLE_FOR_FONT_SRV,
YOUR_GPU_DESCRIPTOR_HANDLE_FOR_FONT_SRV);
ImGui_ImplDX12_InitInfo init_info = {};
init_info.Device = YOUR_D3D_DEVICE;
init_info.CommandQueue = YOUR_COMMAND_QUEUE;
init_info.NumFramesInFlight = NUM_FRAMES_IN_FLIGHT;
init_info.RTVFormat = DXGI_FORMAT_R8G8B8A8_UNORM; // Or your render target format.
// Allocating SRV descriptors (for textures) is up to the application, so we provide callbacks.
// The example_win32_directx12/main.cpp application include a simple free-list based allocator.
init_info.SrvDescriptorHeap = YOUR_SRV_DESC_HEAP;
init_info.SrvDescriptorAllocFn = [](ImGui_ImplDX12_InitInfo*, D3D12_CPU_DESCRIPTOR_HANDLE* out_cpu_handle, D3D12_GPU_DESCRIPTOR_HANDLE* out_gpu_handle) { return YOUR_ALLOCATOR_FUNCTION_FOR_SRV_DESCRIPTORS(...); };
init_info.SrvDescriptorFreeFn = [](ImGui_ImplDX12_InitInfo*, D3D12_CPU_DESCRIPTOR_HANDLE cpu_handle, D3D12_GPU_DESCRIPTOR_HANDLE gpu_handle) { return YOUR_FREE_FUNCTION_FOR_SRV_DESCRIPTORS(...); };
// (before 1.91.6 the DirectX12 backend required a single SRV descriptor passed)
// (there is a legacy version of ImGui_ImplDX12_Init() that supports those, but a future version of Dear ImGuii will requires more descriptors to be allocated)
```
Add to start of main loop:
```cpp