Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ImGui to 1.91.1 #970

Merged
merged 7 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/d3d12/D3D12_Functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ bool D3D12::InitializeImGui(size_t aBuffersCounts)

ReloadFonts();

if (!ImGui_ImplDX12_CreateDeviceObjects())
if (!ImGui_ImplDX12_CreateDeviceObjects(m_pCommandQueue.Get()))
{
Log::Error("D3D12::InitializeImGui() - ImGui_ImplDX12_CreateDeviceObjects call failed!");
ImGui_ImplDX12_Shutdown();
Expand Down Expand Up @@ -514,7 +514,7 @@ void D3D12::Update()
// swap staging ImGui buffer with render ImGui buffer
{
std::lock_guard _(m_imguiLock);
ImGui_ImplDX12_NewFrame();
ImGui_ImplDX12_NewFrame(m_pCommandQueue.Get());
if (m_imguiDrawDataBuffers[1].Valid)
{
std::swap(m_imguiDrawDataBuffers[0], m_imguiDrawDataBuffers[1]);
Expand Down
34 changes: 17 additions & 17 deletions src/imgui_impl/dx12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ void ImGui_ImplDX12_RenderDrawData(ImDrawData* draw_data, ID3D12GraphicsCommandL
}
}

static void ImGui_ImplDX12_CreateFontsTexture()
static void ImGui_ImplDX12_CreateFontsTexture(ID3D12CommandQueue* apCommandQueue)
{
// Build texture atlas
ImGuiIO& io = ImGui::GetIO();
Expand Down Expand Up @@ -464,9 +464,9 @@ static void ImGui_ImplDX12_CreateFontsTexture()
queueDesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
queueDesc.NodeMask = 1;

ID3D12CommandQueue* cmdQueue = nullptr;
hr = bd->pd3dDevice->CreateCommandQueue(&queueDesc, IID_PPV_ARGS(&cmdQueue));
IM_ASSERT(SUCCEEDED(hr));
//ID3D12CommandQueue* cmdQueue = nullptr;
//hr = bd->pd3dDevice->CreateCommandQueue(&queueDesc, IID_PPV_ARGS(&cmdQueue));
//IM_ASSERT(SUCCEEDED(hr));

ID3D12CommandAllocator* cmdAlloc = nullptr;
hr = bd->pd3dDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&cmdAlloc));
Expand All @@ -482,16 +482,16 @@ static void ImGui_ImplDX12_CreateFontsTexture()
hr = cmdList->Close();
IM_ASSERT(SUCCEEDED(hr));

cmdQueue->ExecuteCommandLists(1, (ID3D12CommandList* const*)&cmdList);
hr = cmdQueue->Signal(fence, 1);
apCommandQueue->ExecuteCommandLists(1, (ID3D12CommandList* const*)&cmdList);
hr = apCommandQueue->Signal(fence, 1);
IM_ASSERT(SUCCEEDED(hr));

fence->SetEventOnCompletion(1, event);
WaitForSingleObject(event, INFINITE);

cmdList->Release();
cmdAlloc->Release();
cmdQueue->Release();
//cmdQueue->Release();
CloseHandle(event);
fence->Release();
uploadBuffer->Release();
Expand Down Expand Up @@ -522,7 +522,7 @@ static void ImGui_ImplDX12_CreateFontsTexture()
io.Fonts->SetTexID((ImTextureID)bd->hFontSrvGpuDescHandle.ptr);
}

bool ImGui_ImplDX12_CreateDeviceObjects()
bool ImGui_ImplDX12_CreateDeviceObjects(ID3D12CommandQueue* apCommandQueue)
{
ImGui_ImplDX12_Data* bd = ImGui_ImplDX12_GetBackendData();
if (!bd || !bd->pd3dDevice)
Expand Down Expand Up @@ -579,22 +579,22 @@ bool ImGui_ImplDX12_CreateDeviceObjects()

// Load d3d12.dll and D3D12SerializeRootSignature() function address dynamically to facilitate using with D3D12On7.
// See if any version of d3d12.dll is already loaded in the process. If so, give preference to that.
static HINSTANCE d3d12_dll = ::GetModuleHandleA("d3d12.dll");
static HINSTANCE d3d12_dll = ::GetModuleHandle(_T("d3d12.dll"));
if (d3d12_dll == nullptr)
{
// Attempt to load d3d12.dll from local directories. This will only succeed if
// (1) the current OS is Windows 7, and
// (2) there exists a version of d3d12.dll for Windows 7 (D3D12On7) in one of the following directories.
// See https://github.com/ocornut/imgui/pull/3696 for details.
const char* localD3d12Paths[] = {
".\\d3d12.dll", ".\\d3d12on7\\d3d12.dll", ".\\12on7\\d3d12.dll"}; // A. current directory, B. used by some games, C. used in Microsoft D3D12On7 sample
const TCHAR* localD3d12Paths[] = {
_T(".\\d3d12.dll"), _T(".\\d3d12on7\\d3d12.dll"), _T(".\\12on7\\d3d12.dll")}; // A. current directory, B. used by some games, C. used in Microsoft D3D12On7 sample
for (int i = 0; i < IM_ARRAYSIZE(localD3d12Paths); i++)
if ((d3d12_dll = ::LoadLibraryA(localD3d12Paths[i])) != nullptr)
if ((d3d12_dll = ::LoadLibrary(localD3d12Paths[i])) != nullptr)
break;

// If failed, we are on Windows >= 10.
if (d3d12_dll == nullptr)
d3d12_dll = ::LoadLibraryA("d3d12.dll");
d3d12_dll = ::LoadLibrary(_T("d3d12.dll"));

if (d3d12_dll == nullptr)
return false;
Expand Down Expand Up @@ -747,7 +747,7 @@ bool ImGui_ImplDX12_CreateDeviceObjects()
if (result_pipeline_state != S_OK)
return false;

ImGui_ImplDX12_CreateFontsTexture();
ImGui_ImplDX12_CreateFontsTexture(apCommandQueue);

return true;
}
Expand Down Expand Up @@ -831,13 +831,13 @@ void ImGui_ImplDX12_Shutdown()
IM_DELETE(bd);
}

void ImGui_ImplDX12_NewFrame()
void ImGui_ImplDX12_NewFrame(ID3D12CommandQueue* apCommandQueue)
{
ImGui_ImplDX12_Data* bd = ImGui_ImplDX12_GetBackendData();
IM_ASSERT(bd != nullptr && "Context or backend not initialized! Did you call ImGui_ImplDX12_Init()?");

if (!bd->pPipelineState)
ImGui_ImplDX12_CreateDeviceObjects();
if (!bd->pPipelineState || !ImGui::GetIO().Fonts->IsBuilt())
ImGui_ImplDX12_CreateDeviceObjects(apCommandQueue);
}

//--------------------------------------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions src/imgui_impl/dx12.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ struct D3D12_GPU_DESCRIPTOR_HANDLE;
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_NewFrame(ID3D12CommandQueue* apCommandQueue);
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();
IMGUI_IMPL_API bool ImGui_ImplDX12_CreateDeviceObjects(ID3D12CommandQueue* apCommandQueue);

#endif // #ifndef IMGUI_DISABLE
35 changes: 22 additions & 13 deletions src/imgui_impl/win32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@

#include <stdafx.h>

// CET Headers
#include "CET.h"
#include "Utils.h"

#include "imgui.h"
#ifndef IMGUI_DISABLE
#include "win32.h"
Expand Down Expand Up @@ -175,6 +179,11 @@ static bool ImGui_ImplWin32_InitEx(void* hwnd, bool platform_has_own_dc)
io.BackendFlags |= ImGuiBackendFlags_PlatformHasViewports; // We can create multi-viewports on the Platform side (optional)
io.BackendFlags |= ImGuiBackendFlags_HasMouseHoveredViewport; // We can call io.AddMouseViewportEvent() with correct data (optional)

// CET specific
// Enable Keyboard Nav and setup INI path
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
io.IniFilename = UTF16ToUTF8(GetAbsolutePath(L"layout.ini", CET::Get().GetPaths().CETRoot(), true).native()).c_str();

bd->hWnd = (HWND)hwnd;
bd->WantUpdateMonitors = true;
bd->TicksPerSecond = perf_frequency;
Expand All @@ -191,15 +200,15 @@ static bool ImGui_ImplWin32_InitEx(void* hwnd, bool platform_has_own_dc)
// Dynamically load XInput library
#ifndef IMGUI_IMPL_WIN32_DISABLE_GAMEPAD
bd->WantUpdateHasGamepad = true;
const char* xinput_dll_names[] = {
"xinput1_4.dll", // Windows 8+
"xinput1_3.dll", // DirectX SDK
"xinput9_1_0.dll", // Windows Vista, Windows 7
"xinput1_2.dll", // DirectX SDK
"xinput1_1.dll" // DirectX SDK
const TCHAR* xinput_dll_names[] = {
_T("xinput1_4.dll"), // Windows 8+
_T("xinput1_3.dll"), // DirectX SDK
_T("xinput9_1_0.dll"), // Windows Vista, Windows 7
_T("xinput1_2.dll"), // DirectX SDK
_T("xinput1_1.dll") // DirectX SDK
};
for (int n = 0; n < IM_ARRAYSIZE(xinput_dll_names); n++)
if (HMODULE dll = ::LoadLibraryA(xinput_dll_names[n]))
if (HMODULE dll = ::LoadLibrary(xinput_dll_names[n]))
{
bd->XInputDLL = dll;
bd->XInputGetCapabilities = (PFN_XInputGetCapabilities)::GetProcAddress(dll, "XInputGetCapabilities");
Expand Down Expand Up @@ -903,7 +912,7 @@ static BOOL _IsWindowsVersionOrGreater(WORD major, WORD minor, WORD)
typedef LONG(WINAPI * PFN_RtlVerifyVersionInfo)(OSVERSIONINFOEXW*, ULONG, ULONGLONG);
static PFN_RtlVerifyVersionInfo RtlVerifyVersionInfoFn = nullptr;
if (RtlVerifyVersionInfoFn == nullptr)
if (HMODULE ntdllModule = ::GetModuleHandleA("ntdll.dll"))
if (HMODULE ntdllModule = ::GetModuleHandle(_T("ntdll.dll")))
RtlVerifyVersionInfoFn = (PFN_RtlVerifyVersionInfo)GetProcAddress(ntdllModule, "RtlVerifyVersionInfo");
if (RtlVerifyVersionInfoFn == nullptr)
return FALSE;
Expand Down Expand Up @@ -958,7 +967,7 @@ void ImGui_ImplWin32_EnableDpiAwareness()

if (_IsWindows10OrGreater())
{
static HINSTANCE user32_dll = ::LoadLibraryA("user32.dll"); // Reference counted per-process
static HINSTANCE user32_dll = ::LoadLibrary(_T("user32.dll")); // Reference counted per-process
if (PFN_SetThreadDpiAwarenessContext SetThreadDpiAwarenessContextFn = (PFN_SetThreadDpiAwarenessContext)::GetProcAddress(user32_dll, "SetThreadDpiAwarenessContext"))
{
SetThreadDpiAwarenessContextFn(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
Expand All @@ -967,7 +976,7 @@ void ImGui_ImplWin32_EnableDpiAwareness()
}
if (_IsWindows8Point1OrGreater())
{
static HINSTANCE shcore_dll = ::LoadLibraryA("shcore.dll"); // Reference counted per-process
static HINSTANCE shcore_dll = ::LoadLibrary(_T("shcore.dll")); // Reference counted per-process
if (PFN_SetProcessDpiAwareness SetProcessDpiAwarenessFn = (PFN_SetProcessDpiAwareness)::GetProcAddress(shcore_dll, "SetProcessDpiAwareness"))
{
SetProcessDpiAwarenessFn(PROCESS_PER_MONITOR_DPI_AWARE);
Expand All @@ -988,7 +997,7 @@ float ImGui_ImplWin32_GetDpiScaleForMonitor(void* monitor)
UINT xdpi = 96, ydpi = 96;
if (_IsWindows8Point1OrGreater())
{
static HINSTANCE shcore_dll = ::LoadLibraryA("shcore.dll"); // Reference counted per-process
static HINSTANCE shcore_dll = ::LoadLibrary(_T("shcore.dll")); // Reference counted per-process
static PFN_GetDpiForMonitor GetDpiForMonitorFn = nullptr;
if (GetDpiForMonitorFn == nullptr && shcore_dll != nullptr)
GetDpiForMonitorFn = (PFN_GetDpiForMonitor)::GetProcAddress(shcore_dll, "GetDpiForMonitor");
Expand Down Expand Up @@ -1124,7 +1133,7 @@ static void ImGui_ImplWin32_CreateWindow(ImGuiViewport* viewport)
viewport->PlatformHandle = viewport->PlatformHandleRaw = vd->Hwnd;

// Secondary viewports store their imgui context
::SetPropA(vd->Hwnd, "IMGUI_CONTEXT", ImGui::GetCurrentContext());
::SetProp(vd->Hwnd, _T("IMGUI_CONTEXT"), ImGui::GetCurrentContext());
}

static void ImGui_ImplWin32_DestroyWindow(ImGuiViewport* viewport)
Expand Down Expand Up @@ -1328,7 +1337,7 @@ static void ImGui_ImplWin32_OnChangedViewport(ImGuiViewport* viewport)
static LRESULT CALLBACK ImGui_ImplWin32_WndProcHandler_PlatformWindow(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
// Allow secondary viewport WndProc to be called regardless of current context
ImGuiContext* hwnd_ctx = (ImGuiContext*)::GetPropA(hWnd, "IMGUI_CONTEXT");
ImGuiContext* hwnd_ctx = (ImGuiContext*)::GetProp(hWnd, _T("IMGUI_CONTEXT"));
ImGuiContext* prev_ctx = ImGui::GetCurrentContext();
if (hwnd_ctx != prev_ctx && hwnd_ctx != NULL)
ImGui::SetCurrentContext(hwnd_ctx);
Expand Down
2 changes: 1 addition & 1 deletion xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ target("RED4ext.SDK")
on_install(function() end)

target("cyber_engine_tweaks")
add_defines("WIN32_LEAN_AND_MEAN", "NOMINMAX", "WINVER=0x0601", "SOL_ALL_SAFETIES_ON", "SOL_LUAJIT=1", "SOL_EXCEPTIONS_SAFE_PROPAGATION", "SPDLOG_WCHAR_TO_UTF8_SUPPORT", "SPDLOG_WCHAR_FILENAMES", "SPDLOG_WCHAR_SUPPORT", "IMGUI_USER_CONFIG=\""..imguiUserConfig.."\"") -- WINVER=0x0601 == Windows 7xmake
add_defines("WIN32_LEAN_AND_MEAN", "NOMINMAX", "WINVER=0x0601", "SOL_ALL_SAFETIES_ON", "SOL_LUAJIT=1", "SOL_EXCEPTIONS_SAFE_PROPAGATION", "SPDLOG_WCHAR_TO_UTF8_SUPPORT", "SPDLOG_WCHAR_FILENAMES", "SPDLOG_WCHAR_SUPPORT", "IMGUI_USER_CONFIG=\""..imguiUserConfig.."\", IMGUI_IMPL_WIN32_DISABLE_GAMEPAD") -- WINVER=0x0601 == Windows 7xmake
WSSDude marked this conversation as resolved.
Show resolved Hide resolved
set_pcxxheader("src/stdafx.h")
set_kind("shared")
set_filename("cyber_engine_tweaks.asi")
Expand Down
Loading