|
3 | 3 |
|
4 | 4 | // Implemented features:
|
5 | 5 | // [X] Renderer: User texture binding. Use 'D3D12_GPU_DESCRIPTOR_HANDLE' as ImTextureID. Read the FAQ about ImTextureID!
|
6 |
| -// [X] Renderer: Large meshes support (64k+ vertices) with 16-bit indices. |
| 6 | +// [X] Renderer: Large meshes support (64k+ vertices) even with 16-bit indices (ImGuiBackendFlags_RendererHasVtxOffset). |
| 7 | +// [X] Renderer: Expose selected render state for draw callbacks to use. Access in '(ImGui_ImplXXXX_RenderState*)GetPlatformIO().Renderer_RenderState'. |
7 | 8 | // [X] Renderer: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'.
|
8 | 9 |
|
9 |
| -// Important: to compile on 32-bit systems, this backend requires code to be compiled with '#define ImTextureID ImU64'. |
10 |
| -// See imgui_impl_dx12.cpp file for details. |
| 10 | +// The aim of imgui_impl_dx12.h/.cpp is to be usable in your engine without any modification. |
| 11 | +// IF YOU FEEL YOU NEED TO MAKE ANY CHANGE TO THIS CODE, please share them and your feedback at https://github.com/ocornut/imgui/ |
11 | 12 |
|
12 | 13 | // You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
13 | 14 | // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
|
|
21 | 22 | #include "imgui.h" // IMGUI_IMPL_API
|
22 | 23 | #ifndef IMGUI_DISABLE
|
23 | 24 | #include <dxgiformat.h> // DXGI_FORMAT
|
24 |
| - |
25 |
| -struct ID3D12Device; |
26 |
| -struct ID3D12DescriptorHeap; |
27 |
| -struct ID3D12GraphicsCommandList; |
28 |
| -struct D3D12_CPU_DESCRIPTOR_HANDLE; |
29 |
| -struct D3D12_GPU_DESCRIPTOR_HANDLE; |
| 25 | +#include <d3d12.h> // D3D12_CPU_DESCRIPTOR_HANDLE |
30 | 26 |
|
31 | 27 | // FIX(zig-gamedev)
|
32 | 28 | extern "C" {
|
33 | 29 |
|
34 |
| -// cmd_list is the command list that the implementation will use to render imgui draw lists. |
35 |
| -// Before calling the render function, caller must prepare cmd_list by resetting it and setting the appropriate |
36 |
| -// render target and descriptor heap that contains font_srv_cpu_desc_handle/font_srv_gpu_desc_handle. |
37 |
| -// font_srv_cpu_desc_handle and font_srv_gpu_desc_handle are handles to a single SRV descriptor to use for the internal font texture. |
38 |
| -IMGUI_IMPL_API bool ImGui_ImplDX12_Init(ID3D12Device* device, int num_frames_in_flight, DXGI_FORMAT rtv_format, ID3D12DescriptorHeap* cbv_srv_heap, |
39 |
| - D3D12_CPU_DESCRIPTOR_HANDLE font_srv_cpu_desc_handle, D3D12_GPU_DESCRIPTOR_HANDLE font_srv_gpu_desc_handle); |
| 30 | +// Initialization data, for ImGui_ImplDX12_Init() |
| 31 | +struct ImGui_ImplDX12_InitInfo |
| 32 | +{ |
| 33 | + ID3D12Device* Device; |
| 34 | + ID3D12CommandQueue* CommandQueue; |
| 35 | + int NumFramesInFlight; |
| 36 | + DXGI_FORMAT RTVFormat; // RenderTarget format. |
| 37 | + DXGI_FORMAT DSVFormat; // DepthStencilView format. |
| 38 | + void* UserData; |
| 39 | + |
| 40 | + // Allocating SRV descriptors for textures is up to the application, so we provide callbacks. |
| 41 | + // (current version of the backend will only allocate one descriptor, future versions will need to allocate more) |
| 42 | + ID3D12DescriptorHeap* SrvDescriptorHeap; |
| 43 | + void (*SrvDescriptorAllocFn)(ImGui_ImplDX12_InitInfo* info, D3D12_CPU_DESCRIPTOR_HANDLE* out_cpu_desc_handle, D3D12_GPU_DESCRIPTOR_HANDLE* out_gpu_desc_handle); |
| 44 | + void (*SrvDescriptorFreeFn)(ImGui_ImplDX12_InitInfo* info, D3D12_CPU_DESCRIPTOR_HANDLE cpu_desc_handle, D3D12_GPU_DESCRIPTOR_HANDLE gpu_desc_handle); |
| 45 | +#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS |
| 46 | + D3D12_CPU_DESCRIPTOR_HANDLE LegacySingleSrvCpuDescriptor; // To facilitate transition from single descriptor to allocator callback, you may use those. |
| 47 | + D3D12_GPU_DESCRIPTOR_HANDLE LegacySingleSrvGpuDescriptor; |
| 48 | +#endif |
| 49 | + |
| 50 | + ImGui_ImplDX12_InitInfo() { memset((void*)this, 0, sizeof(*this)); } |
| 51 | +}; |
| 52 | + |
| 53 | +// Follow "Getting Started" link and check examples/ folder to learn about using backends! |
| 54 | +IMGUI_IMPL_API bool ImGui_ImplDX12_Init(ImGui_ImplDX12_InitInfo* info); |
| 55 | + |
| 56 | + |
40 | 57 | IMGUI_IMPL_API void ImGui_ImplDX12_Shutdown();
|
41 | 58 | IMGUI_IMPL_API void ImGui_ImplDX12_NewFrame();
|
42 | 59 | IMGUI_IMPL_API void ImGui_ImplDX12_RenderDrawData(ImDrawData* draw_data, ID3D12GraphicsCommandList* graphics_command_list);
|
43 | 60 |
|
| 61 | +// FIX(zig-gamedev) |
| 62 | +#if 0 |
| 63 | +// Legacy initialization API Obsoleted in 1.91.5 |
| 64 | +// font_srv_cpu_desc_handle and font_srv_gpu_desc_handle are handles to a single SRV descriptor to use for the internal font texture, they must be in 'srv_descriptor_heap' |
| 65 | +IMGUI_IMPL_API bool ImGui_ImplDX12_Init(ID3D12Device* device, int num_frames_in_flight, DXGI_FORMAT rtv_format, ID3D12DescriptorHeap* srv_descriptor_heap, D3D12_CPU_DESCRIPTOR_HANDLE font_srv_cpu_desc_handle, D3D12_GPU_DESCRIPTOR_HANDLE font_srv_gpu_desc_handle); |
| 66 | +#endif |
| 67 | + |
44 | 68 | // Use if you want to reset your rendering device without losing Dear ImGui state.
|
45 |
| -IMGUI_IMPL_API void ImGui_ImplDX12_InvalidateDeviceObjects(); |
46 | 69 | IMGUI_IMPL_API bool ImGui_ImplDX12_CreateDeviceObjects();
|
| 70 | +IMGUI_IMPL_API void ImGui_ImplDX12_InvalidateDeviceObjects(); |
47 | 71 |
|
48 | 72 | }
|
49 | 73 |
|
| 74 | +// [BETA] Selected render state data shared with callbacks. |
| 75 | +// This is temporarily stored in GetPlatformIO().Renderer_RenderState during the ImGui_ImplDX12_RenderDrawData() call. |
| 76 | +// (Please open an issue if you feel you need access to more data) |
| 77 | +struct ImGui_ImplDX12_RenderState |
| 78 | +{ |
| 79 | + ID3D12Device* Device; |
| 80 | + ID3D12GraphicsCommandList* CommandList; |
| 81 | +}; |
| 82 | + |
50 | 83 | #endif // #ifndef IMGUI_DISABLE
|
0 commit comments