Skip to content

Commit

Permalink
Update ImGui to 1.91.1
Browse files Browse the repository at this point in the history
  • Loading branch information
dragonzkiller committed Oct 25, 2024
1 parent ae1cd01 commit 13e6fab
Show file tree
Hide file tree
Showing 11 changed files with 1,930 additions and 493 deletions.
3 changes: 2 additions & 1 deletion src/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ bool IsLuaCData(const sol::object& acpObject)

float GetAlignedItemWidth(const int64_t acItemsCount)
{
return (ImGui::GetWindowContentRegionWidth() - static_cast<float>(acItemsCount - 1) * ImGui::GetStyle().ItemSpacing.x) / static_cast<float>(acItemsCount);
return (ImGui::GetWindowContentRegionMax().x - ImGui::GetWindowContentRegionMin().x - static_cast<float>(acItemsCount - 1) * ImGui::GetStyle().ItemSpacing.x) /
static_cast<float>(acItemsCount);
}

float GetCenteredOffsetForText(const char* acpText)
Expand Down
2 changes: 2 additions & 0 deletions src/d3d12/D3D12.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include "common/D3D12Downlevel.h"
#include "window/Window.h"

extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);

using TPresentD3D12Downlevel = HRESULT(ID3D12CommandQueueDownlevel*, ID3D12GraphicsCommandList*, ID3D12Resource*, HWND, D3D12_DOWNLEVEL_PRESENT_FLAGS);
using TCreateCommittedResource =
HRESULT(ID3D12Device*, const D3D12_HEAP_PROPERTIES*, D3D12_HEAP_FLAGS, const D3D12_RESOURCE_DESC*, D3D12_RESOURCE_STATES, const D3D12_CLEAR_VALUE*, const IID*, void**);
Expand Down
14 changes: 6 additions & 8 deletions src/d3d12/D3D12_Functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ bool D3D12::ResetState(const bool acClearDownlevelBackbuffers, const bool acDest
{
for (auto i = 0; i < drawData.CmdListsCount; ++i)
IM_DELETE(drawData.CmdLists[i]);
delete[] drawData.CmdLists;
drawData.CmdLists = nullptr;
drawData.Clear();
}

Expand Down Expand Up @@ -466,7 +464,7 @@ bool D3D12::InitializeImGui(size_t aBuffersCounts)

ReloadFonts();

if (!ImGui_ImplDX12_CreateDeviceObjects(m_pCommandQueue.Get()))
if (!ImGui_ImplDX12_CreateDeviceObjects())
{
Log::Error("D3D12::InitializeImGui() - ImGui_ImplDX12_CreateDeviceObjects call failed!");
ImGui_ImplDX12_Shutdown();
Expand All @@ -484,7 +482,7 @@ void D3D12::PrepareUpdate()

std::lock_guard _(m_imguiLock);

ImGui_ImplWin32_NewFrame(m_outSize);
ImGui_ImplWin32_NewFrame();
ImGui::NewFrame();

CET::Get().GetOverlay().Update();
Expand All @@ -497,13 +495,13 @@ void D3D12::PrepareUpdate()

for (auto i = 0; i < drawData.CmdListsCount; ++i)
IM_DELETE(drawData.CmdLists[i]);
delete[] drawData.CmdLists;
drawData.CmdLists = nullptr;
drawData.Clear();

drawData = *ImGui::GetDrawData();

auto** copiedDrawLists = new ImDrawList*[drawData.CmdListsCount];
ImVector<ImDrawList*> copiedDrawLists;
copiedDrawLists.resize(drawData.CmdListsCount);

for (auto i = 0; i < drawData.CmdListsCount; ++i)
copiedDrawLists[i] = drawData.CmdLists[i]->CloneOutput();
drawData.CmdLists = copiedDrawLists;
Expand All @@ -516,7 +514,7 @@ void D3D12::Update()
// swap staging ImGui buffer with render ImGui buffer
{
std::lock_guard _(m_imguiLock);
ImGui_ImplDX12_NewFrame(m_pCommandQueue.Get());
ImGui_ImplDX12_NewFrame();
if (m_imguiDrawDataBuffers[1].Valid)
{
std::swap(m_imguiDrawDataBuffers[0], m_imguiDrawDataBuffers[1]);
Expand Down
803 changes: 598 additions & 205 deletions src/imgui_impl/dx12.cpp

Large diffs are not rendered by default.

45 changes: 26 additions & 19 deletions src/imgui_impl/dx12.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,46 @@
// This needs to be used along with a Platform Backend (e.g. Win32)

// Implemented features:
// [X] Renderer: User texture binding. Use 'D3D12_GPU_DESCRIPTOR_HANDLE' as ImTextureID. Read the FAQ about
// ImTextureID! [X] Renderer: Support for large meshes (64k+ vertices) with 16-bit indices.
// [X] Renderer: User texture binding. Use 'D3D12_GPU_DESCRIPTOR_HANDLE' as ImTextureID. Read the FAQ about ImTextureID!
// [X] Renderer: Large meshes support (64k+ vertices) with 16-bit indices.
// [X] Renderer: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'.

// Important: to compile on 32-bit systems, this backend requires code to be compiled with '#define ImTextureID ImU64'.
// This is because we need ImTextureID to carry a 64-bit value and by default ImTextureID is defined as void*.
// This define is set in the example .vcxproj file and need to be replicated in your app or by adding it to your
// imconfig.h file.
// See imgui_impl_dx12.cpp file for details.

// You can copy and use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
// If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp.
// Read online: https://github.com/ocornut/imgui/tree/master/docs
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
// Learn about Dear ImGui:
// - FAQ https://dearimgui.com/faq
// - Getting Started https://dearimgui.com/getting-started
// - Documentation https://dearimgui.com/docs (same as your local docs/ folder).
// - Introduction, links and more at the top of imgui.cpp

#pragma once
#include "imgui.h" // IMGUI_IMPL_API
#include "imgui.h" // IMGUI_IMPL_API
#ifndef IMGUI_DISABLE
#include <dxgiformat.h> // DXGI_FORMAT

struct ID3D12Device;
struct ID3D12DescriptorHeap;
struct ID3D12GraphicsCommandList;
struct D3D12_CPU_DESCRIPTOR_HANDLE;
struct D3D12_GPU_DESCRIPTOR_HANDLE;

// Follow "Getting Started" link and check examples/ folder to learn about using backends!

// cmd_list is the command list that the implementation will use to render imgui draw lists.
// Before calling the render function, caller must prepare cmd_list by resetting it and setting the appropriate
// render target and descriptor heap that contains font_srv_cpu_desc_handle/font_srv_gpu_desc_handle.
// 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.
IMGUI_IMPL_API bool ImGui_ImplDX12_Init(
ID3D12Device* apDevice, int aNumFramesInFlight, DXGI_FORMAT aRTVFormat, ID3D12DescriptorHeap* apSRVHeapDesc, D3D12_CPU_DESCRIPTOR_HANDLE aFontSRVDescCPU,
D3D12_GPU_DESCRIPTOR_HANDLE aFontSRVDescGPU);
IMGUI_IMPL_API void ImGui_ImplDX12_Shutdown();
IMGUI_IMPL_API void ImGui_ImplDX12_NewFrame(ID3D12CommandQueue* apCommandQueue);
IMGUI_IMPL_API void ImGui_ImplDX12_RenderDrawData(ImDrawData* apDrawData, ID3D12GraphicsCommandList* apCommandLists);
// 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.
IMGUI_IMPL_API bool ImGui_ImplDX12_Init(ID3D12Device* device, int num_frames_in_flight, DXGI_FORMAT rtv_format, ID3D12DescriptorHeap* cbv_srv_heap,
D3D12_CPU_DESCRIPTOR_HANDLE font_srv_cpu_desc_handle, D3D12_GPU_DESCRIPTOR_HANDLE font_srv_gpu_desc_handle);
IMGUI_IMPL_API void ImGui_ImplDX12_Shutdown();
IMGUI_IMPL_API void ImGui_ImplDX12_NewFrame();
IMGUI_IMPL_API void ImGui_ImplDX12_RenderDrawData(ImDrawData* draw_data, ID3D12GraphicsCommandList* graphics_command_list);

// Use if you want to reset your rendering device without losing Dear ImGui state.
IMGUI_IMPL_API void ImGui_ImplDX12_InvalidateDeviceObjects();
IMGUI_IMPL_API bool ImGui_ImplDX12_CreateDeviceObjects(ID3D12CommandQueue* apCommandQueue);
IMGUI_IMPL_API void ImGui_ImplDX12_InvalidateDeviceObjects();
IMGUI_IMPL_API bool ImGui_ImplDX12_CreateDeviceObjects();

#endif // #ifndef IMGUI_DISABLE
Loading

0 comments on commit 13e6fab

Please sign in to comment.