18
18
19
19
// DirectX
20
20
#include < d3d12.h>
21
+ #include < dxgi1_4.h>
21
22
#include < d3dcompiler.h>
22
23
23
24
// DirectX data
@@ -48,6 +49,10 @@ struct VERTEX_CONSTANT_BUFFER
48
49
float mvp[4 ][4 ];
49
50
};
50
51
52
+ // Forward Declarations
53
+ static void ImGui_ImplDX12_InitPlatformInterface ();
54
+ static void ImGui_ImplDX12_ShutdownPlatformInterface ();
55
+
51
56
// Render function
52
57
// (this used to be set in io.RenderDrawListsFn and called by ImGui::Render(), but you can now call this directly from your main loop)
53
58
void ImGui_ImplDX12_RenderDrawData (ImDrawData* draw_data)
@@ -587,7 +592,7 @@ bool ImGui_ImplDX12_Init(ID3D12Device* device, int num_frames_in_flight, DXGI_FO
587
592
g_RTVFormat = rtv_format;
588
593
g_hFontSrvCpuDescHandle = font_srv_cpu_desc_handle;
589
594
g_hFontSrvGpuDescHandle = font_srv_gpu_desc_handle;
590
- g_pFrameResources = new FrameResources [num_frames_in_flight];
595
+ g_pFrameResources = new FrameResources[num_frames_in_flight];
591
596
g_numFramesInFlight = num_frames_in_flight;
592
597
g_frameIndex = UINT_MAX;
593
598
@@ -599,11 +604,16 @@ bool ImGui_ImplDX12_Init(ID3D12Device* device, int num_frames_in_flight, DXGI_FO
599
604
g_pFrameResources[i].IndexBufferSize = 10000 ;
600
605
}
601
606
607
+ ImGuiIO& io = ImGui::GetIO ();
608
+ if (io.ConfigFlags & ImGuiConfigFlags_MultiViewports)
609
+ ImGui_ImplDX12_InitPlatformInterface ();
610
+
602
611
return true ;
603
612
}
604
613
605
614
void ImGui_ImplDX12_Shutdown ()
606
615
{
616
+ ImGui_ImplDX12_ShutdownPlatformInterface ();
607
617
ImGui_ImplDX12_InvalidateDeviceObjects ();
608
618
delete[] g_pFrameResources;
609
619
g_pd3dDevice = NULL ;
@@ -622,3 +632,135 @@ void ImGui_ImplDX12_NewFrame(ID3D12GraphicsCommandList* command_list)
622
632
623
633
g_pd3dCommandList = command_list;
624
634
}
635
+
636
+ // --------------------------------------------------------------------------------------------------------
637
+ // Platform Windows
638
+ // --------------------------------------------------------------------------------------------------------
639
+
640
+ #include " imgui_internal.h" // ImGuiViewport
641
+
642
+ struct ImGuiPlatformDataDx12
643
+ {
644
+ IDXGISwapChain3* SwapChain;
645
+
646
+ ImGuiPlatformDataDx12 () { SwapChain = NULL ; }
647
+ ~ImGuiPlatformDataDx12 () { IM_ASSERT (SwapChain == NULL ); }
648
+ };
649
+
650
+ static void ImGui_ImplDX12_CreateViewport (ImGuiViewport* viewport)
651
+ {
652
+ ImGuiPlatformDataDx12* data = IM_NEW (ImGuiPlatformDataDx12)();
653
+ viewport->RendererUserData = data;
654
+ IM_ASSERT (0 );
655
+
656
+ /*
657
+ // FIXME-PLATFORM
658
+ HWND hwnd = (HWND)viewport->PlatformHandle;
659
+ IM_ASSERT(hwnd != 0);
660
+
661
+ // Create swap chain
662
+ DXGI_SWAP_CHAIN_DESC sd;
663
+ ZeroMemory(&sd, sizeof(sd));
664
+ sd.BufferDesc.Width = (UINT)viewport->Size.x;
665
+ sd.BufferDesc.Height = (UINT)viewport->Size.y;
666
+ sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
667
+ sd.SampleDesc.Count = 1;
668
+ sd.SampleDesc.Quality = 0;
669
+ sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
670
+ sd.BufferCount = 1;
671
+ sd.OutputWindow = hwnd;
672
+ sd.Windowed = TRUE;
673
+ sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
674
+ sd.Flags = 0;
675
+
676
+ IM_ASSERT(data->SwapChain == NULL && data->RTView == NULL);
677
+ g_pFactory->CreateSwapChain(g_pd3dDevice, &sd, &data->SwapChain);
678
+
679
+ // Create the render target
680
+ if (data->SwapChain)
681
+ {
682
+ ID3D11Texture2D* pBackBuffer;
683
+ data->SwapChain->GetBuffer(0, IID_PPV_ARGS(&pBackBuffer));
684
+ g_pd3dDevice->CreateRenderTargetView(pBackBuffer, NULL, &data->RTView);
685
+ pBackBuffer->Release();
686
+ }
687
+ */
688
+ }
689
+
690
+ static void ImGui_ImplDX12_DestroyViewport (ImGuiViewport* viewport)
691
+ {
692
+ if (ImGuiPlatformDataDx12* data = (ImGuiPlatformDataDx12*)viewport->RendererUserData )
693
+ {
694
+ IM_ASSERT (0 );
695
+ /*
696
+ if (data->SwapChain)
697
+ data->SwapChain->Release();
698
+ data->SwapChain = NULL;
699
+ if (data->RTView)
700
+ data->RTView->Release();
701
+ data->RTView = NULL;
702
+ IM_DELETE(data);
703
+ */
704
+ }
705
+ viewport->RendererUserData = NULL ;
706
+ }
707
+
708
+ static void ImGui_ImplDX12_ResizeViewport (ImGuiViewport* viewport, int w, int h)
709
+ {
710
+ ImGuiPlatformDataDx12* data = (ImGuiPlatformDataDx12*)viewport->RendererUserData ;
711
+ IM_ASSERT (0 );
712
+ /*
713
+ if (data->RTView)
714
+ {
715
+ data->RTView->Release();
716
+ data->RTView = NULL;
717
+ }
718
+ if (data->SwapChain)
719
+ {
720
+ ID3D11Texture2D* pBackBuffer = NULL;
721
+ data->SwapChain->ResizeBuffers(0, w, h, DXGI_FORMAT_UNKNOWN, 0);
722
+ data->SwapChain->GetBuffer(0, IID_PPV_ARGS(&pBackBuffer));
723
+ g_pd3dDevice->CreateRenderTargetView(pBackBuffer, NULL, &data->RTView);
724
+ pBackBuffer->Release();
725
+ }
726
+ */
727
+ }
728
+
729
+ static void ImGui_ImplDX12_RenderViewport (ImGuiViewport* viewport)
730
+ {
731
+ ImGuiPlatformDataDx12* data = (ImGuiPlatformDataDx12*)viewport->RendererUserData ;
732
+ IM_ASSERT (0 );
733
+ /*
734
+ ImVec4 clear_color = ImGui::GetStyle().Colors[ImGuiCol_WindowBg]; // FIXME-PLATFORM
735
+ clear_color.w = 1.0f;
736
+ g_pd3dDeviceContext->OMSetRenderTargets(1, &data->RTView, NULL);
737
+ g_pd3dDeviceContext->ClearRenderTargetView(data->RTView, (float*)&clear_color);
738
+ */
739
+ ImGui_ImplDX12_RenderDrawData (&viewport->DrawData );
740
+ }
741
+
742
+ static void ImGui_ImplDX12_SwapBuffers (ImGuiViewport* viewport)
743
+ {
744
+ ImGuiPlatformDataDx12* data = (ImGuiPlatformDataDx12*)viewport->RendererUserData ;
745
+ IM_ASSERT (0 );
746
+ /*
747
+ data->SwapChain->Present(0, 0); // Present without vsync
748
+ */
749
+ }
750
+
751
+ void ImGui_ImplDX12_InitPlatformInterface ()
752
+ {
753
+ ImGuiIO& io = ImGui::GetIO ();
754
+ io.RendererInterface .CreateViewport = ImGui_ImplDX12_CreateViewport;
755
+ io.RendererInterface .DestroyViewport = ImGui_ImplDX12_DestroyViewport;
756
+ io.RendererInterface .ResizeViewport = ImGui_ImplDX12_ResizeViewport;
757
+ io.RendererInterface .RenderViewport = ImGui_ImplDX12_RenderViewport;
758
+ io.RendererInterface .SwapBuffers = ImGui_ImplDX12_SwapBuffers;
759
+ }
760
+
761
+ void ImGui_ImplDX12_ShutdownPlatformInterface ()
762
+ {
763
+ ImGuiIO& io = ImGui::GetIO ();
764
+ memset (&io.RendererInterface , 0 , sizeof (io.RendererInterface ));
765
+ }
766
+
0 commit comments