From f6b6dace9e79c75f8f494f71eb50228062d3e59c Mon Sep 17 00:00:00 2001
From: Jefferson Montgomery <jdm3@users.noreply.github.com>
Date: Sun, 24 Sep 2017 14:43:37 -0700
Subject: [PATCH] Pass command list in using ImGui_ImplDX12_NewFrame() instead
 of ImGui_ImplDX12_Init()

---
 examples/directx12_example/imgui_impl_dx12.cpp | 7 ++++---
 examples/directx12_example/imgui_impl_dx12.h   | 4 ++--
 examples/directx12_example/main.cpp            | 4 ++--
 3 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/examples/directx12_example/imgui_impl_dx12.cpp b/examples/directx12_example/imgui_impl_dx12.cpp
index b2d62840..8f81b007 100644
--- a/examples/directx12_example/imgui_impl_dx12.cpp
+++ b/examples/directx12_example/imgui_impl_dx12.cpp
@@ -629,13 +629,12 @@ void    ImGui_ImplDX12_InvalidateDeviceObjects()
 }
 
 bool    ImGui_ImplDX12_Init(void* hwnd, int num_frames_in_flight,
-                            ID3D12Device* device, ID3D12GraphicsCommandList* command_list,
+                            ID3D12Device* device,
                             D3D12_CPU_DESCRIPTOR_HANDLE font_srv_cpu_desc_handle,
                             D3D12_GPU_DESCRIPTOR_HANDLE font_srv_gpu_desc_handle)
 {
     g_hWnd = (HWND)hwnd;
     g_pd3dDevice = device;
-    g_pd3dCommandList = command_list;
     g_hFontSrvCpuDescHandle = font_srv_cpu_desc_handle;
     g_hFontSrvGpuDescHandle = font_srv_gpu_desc_handle;
     g_pFrameResources = new FrameResources [num_frames_in_flight];
@@ -697,11 +696,13 @@ void ImGui_ImplDX12_Shutdown()
     g_frameIndex = UINT_MAX;
 }
 
-void ImGui_ImplDX12_NewFrame()
+void ImGui_ImplDX12_NewFrame(ID3D12GraphicsCommandList* command_list)
 {
     if (!g_pPipelineState)
         ImGui_ImplDX12_CreateDeviceObjects();
 
+    g_pd3dCommandList = command_list;
+
     ImGuiIO& io = ImGui::GetIO();
 
     // Setup display size (every frame to accommodate for window resizing)
diff --git a/examples/directx12_example/imgui_impl_dx12.h b/examples/directx12_example/imgui_impl_dx12.h
index 78cef4ab..7bc828eb 100644
--- a/examples/directx12_example/imgui_impl_dx12.h
+++ b/examples/directx12_example/imgui_impl_dx12.h
@@ -21,11 +21,11 @@ struct D3D12_GPU_DESCRIPTOR_HANDLE;
 // fontSrvCpuDescHandle and fontSrvGpuDescHandle are handles to a single SRV
 // descriptor to use for the internal font texture.
 IMGUI_API bool        ImGui_ImplDX12_Init(void* hwnd, int numFramesInFlight,
-                                          ID3D12Device* device, ID3D12GraphicsCommandList* cmdList,
+                                          ID3D12Device* device,
                                           D3D12_CPU_DESCRIPTOR_HANDLE fontSrvCpuDescHandle,
                                           D3D12_GPU_DESCRIPTOR_HANDLE fontSrvGpuDescHandle);
 IMGUI_API void        ImGui_ImplDX12_Shutdown();
-IMGUI_API void        ImGui_ImplDX12_NewFrame();
+IMGUI_API void        ImGui_ImplDX12_NewFrame(ID3D12GraphicsCommandList* cmdList);
 
 // Use if you want to reset your rendering device without losing ImGui state.
 IMGUI_API void        ImGui_ImplDX12_InvalidateDeviceObjects();
diff --git a/examples/directx12_example/main.cpp b/examples/directx12_example/main.cpp
index 1fc6f37b..4bca2a29 100644
--- a/examples/directx12_example/main.cpp
+++ b/examples/directx12_example/main.cpp
@@ -300,7 +300,7 @@ int main(int, char**)
     UpdateWindow(hwnd);
 
     // Setup ImGui binding
-    ImGui_ImplDX12_Init(hwnd, NUM_FRAMES_IN_FLIGHT, g_pd3dDevice, g_pd3dCommandList,
+    ImGui_ImplDX12_Init(hwnd, NUM_FRAMES_IN_FLIGHT, g_pd3dDevice,
         g_pd3dSrvDescHeap->GetCPUDescriptorHandleForHeapStart(),
         g_pd3dSrvDescHeap->GetGPUDescriptorHandleForHeapStart());
 
@@ -329,7 +329,7 @@ int main(int, char**)
             DispatchMessage(&msg);
             continue;
         }
-        ImGui_ImplDX12_NewFrame();
+        ImGui_ImplDX12_NewFrame(g_pd3dCommandList);
 
         // 1. Show a simple window
         // Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets appears in a window automatically called "Debug"