From 54f11cc76e751f5ce760f9ddd3b3633882406cf3 Mon Sep 17 00:00:00 2001 From: briaguya <70942617+briaguya-ai@users.noreply.github.com> Date: Fri, 10 Jan 2025 05:10:47 -0500 Subject: [PATCH] switch back to `void*` by using a patch to modify `imconfig.h` --- cmake/dependencies/common.cmake | 6 +- .../patches/imgui-fixes-and-config.patch | 59 +++++++++++++++++++ .../patches/sdl-gamepad-fix.patch | 17 ------ src/controller/controldeck/ControlDeck.cpp | 3 - .../ControllerDisconnectedWindow.h | 3 - .../deviceindex/ControllerReorderingWindow.h | 3 - src/debug/Console.h | 3 - src/graphic/Fast3D/gfx_direct3d11.cpp | 4 +- src/graphic/Fast3D/gfx_direct3d11.h | 5 +- src/graphic/Fast3D/gfx_metal.cpp | 4 +- src/graphic/Fast3D/gfx_metal.h | 2 +- src/window/gui/ConsoleWindow.h | 3 - src/window/gui/GameOverlay.h | 3 - src/window/gui/Gui.cpp | 8 +-- src/window/gui/Gui.h | 5 +- src/window/gui/GuiWindow.h | 3 - src/window/gui/InputEditorWindow.h | 3 - src/window/gui/StatsWindow.cpp | 3 - src/window/gui/resource/GuiTexture.h | 2 +- 19 files changed, 74 insertions(+), 65 deletions(-) create mode 100644 cmake/dependencies/patches/imgui-fixes-and-config.patch delete mode 100644 cmake/dependencies/patches/sdl-gamepad-fix.patch diff --git a/cmake/dependencies/common.cmake b/cmake/dependencies/common.cmake index 7ba64a7b0..21ebd54d7 100644 --- a/cmake/dependencies/common.cmake +++ b/cmake/dependencies/common.cmake @@ -9,15 +9,15 @@ if (CMAKE_GENERATOR MATCHES "Visual Studio") endif() #=================== ImGui =================== -set(sdl_gamepad_patch_file ${CMAKE_CURRENT_SOURCE_DIR}/cmake/dependencies/patches/sdl-gamepad-fix.patch) +set(imgui_fixes_and_config_patch_file ${CMAKE_CURRENT_SOURCE_DIR}/cmake/dependencies/patches/imgui-fixes-and-config.patch) # Applies the patch or checks if it has already been applied successfully previously. Will error otherwise. -set(sdl_apply_patch_if_needed git apply ${sdl_gamepad_patch_file} ${git_hide_output} || git apply --reverse --check ${sdl_gamepad_patch_file}) +set(imgui_apply_patch_if_needed git apply ${imgui_fixes_and_config_patch_file} ${git_hide_output} || git apply --reverse --check ${imgui_fixes_and_config_patch_file}) FetchContent_Declare( ImGui GIT_REPOSITORY https://github.com/ocornut/imgui.git GIT_TAG v1.91.6-docking - PATCH_COMMAND ${sdl_apply_patch_if_needed} + PATCH_COMMAND ${imgui_apply_patch_if_needed} ) FetchContent_MakeAvailable(ImGui) list(APPEND ADDITIONAL_LIB_INCLUDES ${imgui_SOURCE_DIR} ${imgui_SOURCE_DIR}/backends) diff --git a/cmake/dependencies/patches/imgui-fixes-and-config.patch b/cmake/dependencies/patches/imgui-fixes-and-config.patch new file mode 100644 index 000000000..baba0add2 --- /dev/null +++ b/cmake/dependencies/patches/imgui-fixes-and-config.patch @@ -0,0 +1,59 @@ +From 7cd9b89560b66b992db9fd0e620c2d28ad9a9645 Mon Sep 17 00:00:00 2001 +From: briaguya <70942617+briaguya-ai@users.noreply.github.com> +Date: Fri, 10 Jan 2025 04:48:50 -0500 +Subject: [PATCH 1/2] sdl gamepad fix + +--- + backends/imgui_impl_sdl2.cpp | 3 --- + 1 file changed, 3 deletions(-) + +diff --git a/backends/imgui_impl_sdl2.cpp b/backends/imgui_impl_sdl2.cpp +index 23f12796..a7fef045 100644 +--- a/backends/imgui_impl_sdl2.cpp ++++ b/backends/imgui_impl_sdl2.cpp +@@ -816,9 +816,6 @@ static void ImGui_ImplSDL2_UpdateGamepads() + bd->WantUpdateGamepadsList = false; + } + +- // FIXME: Technically feeding gamepad shouldn't depend on this now that they are regular inputs. +- if ((io.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) == 0) +- return; + io.BackendFlags &= ~ImGuiBackendFlags_HasGamepad; + if (bd->Gamepads.Size == 0) + return; +-- +2.47.1 + + +From 635226a311071e80c22e0c58c9cb5c9d950d2e17 Mon Sep 17 00:00:00 2001 +From: briaguya <70942617+briaguya-ai@users.noreply.github.com> +Date: Fri, 10 Jan 2025 04:52:36 -0500 +Subject: [PATCH 2/2] add config stuff + +--- + imconfig.h | 5 ++++- + 1 file changed, 4 insertions(+), 1 deletion(-) + +diff --git a/imconfig.h b/imconfig.h +index 8f8bc3b9..cc578e3f 100644 +--- a/imconfig.h ++++ b/imconfig.h +@@ -111,7 +111,7 @@ + operator MyVec4() const { return MyVec4(x,y,z,w); } + */ + //---- ...Or use Dear ImGui's own very basic math operators. +-//#define IMGUI_DEFINE_MATH_OPERATORS ++#define IMGUI_DEFINE_MATH_OPERATORS + + //---- Use 32-bit vertex indices (default is 16-bit) is one way to allow large meshes with more than 64K vertices. + // Your renderer backend will need to support it (most example renderer backends support both 16/32-bit indices). +@@ -140,3 +140,6 @@ namespace ImGui + void MyFunction(const char* name, MyMatrix44* mtx); + } + */ ++ ++// handle https://github.com/ocornut/imgui/issues/1641 the old way ++#define ImTextureID void* +-- +2.47.1 + diff --git a/cmake/dependencies/patches/sdl-gamepad-fix.patch b/cmake/dependencies/patches/sdl-gamepad-fix.patch deleted file mode 100644 index b56e4972a..000000000 --- a/cmake/dependencies/patches/sdl-gamepad-fix.patch +++ /dev/null @@ -1,17 +0,0 @@ - backends/imgui_impl_sdl2.cpp | 3 --- - 1 file changed, 3 deletions(-) - -diff --git a/backends/imgui_impl_sdl2.cpp b/backends/imgui_impl_sdl2.cpp -index 569b01d1..c2f84dca 100644 ---- a/backends/imgui_impl_sdl2.cpp -+++ b/backends/imgui_impl_sdl2.cpp -@@ -770,9 +770,6 @@ static void ImGui_ImplSDL2_UpdateGamepads() - bd->WantUpdateGamepadsList = false; - } - -- // FIXME: Technically feeding gamepad shouldn't depend on this now that they are regular inputs. -- if ((io.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) == 0) -- return; - io.BackendFlags &= ~ImGuiBackendFlags_HasGamepad; - if (bd->Gamepads.Size == 0) - return; diff --git a/src/controller/controldeck/ControlDeck.cpp b/src/controller/controldeck/ControlDeck.cpp index 4b7416433..6a679bf05 100644 --- a/src/controller/controldeck/ControlDeck.cpp +++ b/src/controller/controldeck/ControlDeck.cpp @@ -4,9 +4,6 @@ #include "controller/controldevice/controller/Controller.h" #include "utils/StringHelper.h" #include "public/bridge/consolevariablebridge.h" -#ifndef IMGUI_DEFINE_MATH_OPERATORS -#define IMGUI_DEFINE_MATH_OPERATORS -#endif #include #include "controller/deviceindex/ShipDeviceIndexMappingManager.h" #include "controller/controldevice/controller/mapping/mouse/WheelHandler.h" diff --git a/src/controller/deviceindex/ControllerDisconnectedWindow.h b/src/controller/deviceindex/ControllerDisconnectedWindow.h index 29de503e3..2c2bee341 100644 --- a/src/controller/deviceindex/ControllerDisconnectedWindow.h +++ b/src/controller/deviceindex/ControllerDisconnectedWindow.h @@ -2,9 +2,6 @@ #include "stdint.h" #include "window/gui/GuiWindow.h" -#ifndef IMGUI_DEFINE_MATH_OPERATORS -#define IMGUI_DEFINE_MATH_OPERATORS -#endif #include #include #include diff --git a/src/controller/deviceindex/ControllerReorderingWindow.h b/src/controller/deviceindex/ControllerReorderingWindow.h index f172cda3b..c62a48568 100644 --- a/src/controller/deviceindex/ControllerReorderingWindow.h +++ b/src/controller/deviceindex/ControllerReorderingWindow.h @@ -2,9 +2,6 @@ #include "stdint.h" #include "window/gui/GuiWindow.h" -#ifndef IMGUI_DEFINE_MATH_OPERATORS -#define IMGUI_DEFINE_MATH_OPERATORS -#endif #include #include #include diff --git a/src/debug/Console.h b/src/debug/Console.h index 22f762e17..8bb52947b 100644 --- a/src/debug/Console.h +++ b/src/debug/Console.h @@ -6,9 +6,6 @@ #include #include #include -#ifndef IMGUI_DEFINE_MATH_OPERATORS -#define IMGUI_DEFINE_MATH_OPERATORS -#endif #include namespace Ship { diff --git a/src/graphic/Fast3D/gfx_direct3d11.cpp b/src/graphic/Fast3D/gfx_direct3d11.cpp index d486fc2e5..4f987fe06 100644 --- a/src/graphic/Fast3D/gfx_direct3d11.cpp +++ b/src/graphic/Fast3D/gfx_direct3d11.cpp @@ -1229,8 +1229,8 @@ gfx_d3d11_get_pixel_depth(int fb_id, const std::set>& co } // namespace -ImTextureID gfx_d3d11_get_texture_by_id(unsigned long long id) { - return (unsigned long long)d3d.textures[id].resource_view.Get(); +ImTextureID gfx_d3d11_get_texture_by_id(int id) { + return d3d.textures[id].resource_view.Get(); } void gfx_d3d11_enable_srgb_mode() { diff --git a/src/graphic/Fast3D/gfx_direct3d11.h b/src/graphic/Fast3D/gfx_direct3d11.h index 68022bc1d..e3771ef1f 100644 --- a/src/graphic/Fast3D/gfx_direct3d11.h +++ b/src/graphic/Fast3D/gfx_direct3d11.h @@ -4,13 +4,10 @@ #define GFX_DIRECT3D11_H #include "gfx_rendering_api.h" -#ifndef IMGUI_DEFINE_MATH_OPERATORS -#define IMGUI_DEFINE_MATH_OPERATORS -#endif #include extern struct GfxRenderingAPI gfx_direct3d11_api; -ImTextureID gfx_d3d11_get_texture_by_id(unsigned long long id); +ImTextureID gfx_d3d11_get_texture_by_id(int id); #endif diff --git a/src/graphic/Fast3D/gfx_metal.cpp b/src/graphic/Fast3D/gfx_metal.cpp index d52d92365..d8c972a70 100644 --- a/src/graphic/Fast3D/gfx_metal.cpp +++ b/src/graphic/Fast3D/gfx_metal.cpp @@ -1295,8 +1295,8 @@ FilteringMode gfx_metal_get_texture_filter() { return mctx.current_filter_mode; } -ImTextureID gfx_metal_get_texture_by_id(unsigned long long fb_id) { - return (unsigned long long)mctx.textures[fb_id].texture; +ImTextureID gfx_metal_get_texture_by_id(int fb_id) { + return (void*)mctx.textures[fb_id].texture; } void gfx_metal_enable_srgb_mode() { diff --git a/src/graphic/Fast3D/gfx_metal.h b/src/graphic/Fast3D/gfx_metal.h index e3ff0f48c..c014b234e 100644 --- a/src/graphic/Fast3D/gfx_metal.h +++ b/src/graphic/Fast3D/gfx_metal.h @@ -15,7 +15,7 @@ extern struct GfxRenderingAPI gfx_metal_api; -ImTextureID gfx_metal_get_texture_by_id(unsigned long long id); +ImTextureID gfx_metal_get_texture_by_id(int id); bool Metal_IsSupported(); diff --git a/src/window/gui/ConsoleWindow.h b/src/window/gui/ConsoleWindow.h index 0bf38b999..f9ab21065 100644 --- a/src/window/gui/ConsoleWindow.h +++ b/src/window/gui/ConsoleWindow.h @@ -7,9 +7,6 @@ #include "window/gui/GuiWindow.h" #include "debug/Console.h" -#ifndef IMGUI_DEFINE_MATH_OPERATORS -#define IMGUI_DEFINE_MATH_OPERATORS -#endif #include #include diff --git a/src/window/gui/GameOverlay.h b/src/window/gui/GameOverlay.h index 34f28927d..1f1155b26 100644 --- a/src/window/gui/GameOverlay.h +++ b/src/window/gui/GameOverlay.h @@ -4,9 +4,6 @@ #include #include "debug/Console.h" -#ifndef IMGUI_DEFINE_MATH_OPERATORS -#define IMGUI_DEFINE_MATH_OPERATORS -#endif #include #include #include "resource/ResourceManager.h" diff --git a/src/window/gui/Gui.cpp b/src/window/gui/Gui.cpp index 0b70f9c07..281dadad6 100644 --- a/src/window/gui/Gui.cpp +++ b/src/window/gui/Gui.cpp @@ -654,7 +654,7 @@ void Gui::DrawGame() { } if (gfxFramebuffer) { ImGui::SetCursorPos(pos); - ImGui::Image(gfxFramebuffer, size); + ImGui::Image(reinterpret_cast(gfxFramebuffer), size); } ImGui::End(); @@ -722,7 +722,7 @@ void Gui::SetupRendererFrame() { } } -ImTextureID Gui::GetTextureById(unsigned long long id) { +ImTextureID Gui::GetTextureById(int32_t id) { #ifdef ENABLE_DX11 if (Context::GetInstance()->GetWindow()->GetWindowBackend() == WindowBackend::FAST3D_DXGI_DX11) { return gfx_d3d11_get_texture_by_id(id); @@ -734,7 +734,7 @@ ImTextureID Gui::GetTextureById(unsigned long long id) { } #endif - return id; + return reinterpret_cast(id); } bool Gui::HasTextureByName(const std::string& name) { @@ -743,7 +743,7 @@ bool Gui::HasTextureByName(const std::string& name) { ImTextureID Gui::GetTextureByName(const std::string& name) { if (!Gui::HasTextureByName(name)) { - return 0; + return nullptr; } return GetTextureById(mGuiTextures[name].RendererTextureId); } diff --git a/src/window/gui/Gui.h b/src/window/gui/Gui.h index 1b1c2da29..0675c804c 100644 --- a/src/window/gui/Gui.h +++ b/src/window/gui/Gui.h @@ -1,9 +1,6 @@ #pragma once #ifdef __cplusplus -#ifndef IMGUI_DEFINE_MATH_OPERATORS -#define IMGUI_DEFINE_MATH_OPERATORS -#endif #include #include @@ -119,7 +116,7 @@ class Gui { void ImGuiBackendInit(); void ImGuiRenderDrawData(ImDrawData* data); - ImTextureID GetTextureById(unsigned long long id); + ImTextureID GetTextureById(int32_t id); void ApplyResolutionChanges(); int16_t GetIntegerScaleFactor(); void CheckSaveCvars(); diff --git a/src/window/gui/GuiWindow.h b/src/window/gui/GuiWindow.h index 60ed293da..a1bac96c6 100644 --- a/src/window/gui/GuiWindow.h +++ b/src/window/gui/GuiWindow.h @@ -1,9 +1,6 @@ #pragma once #include -#ifndef IMGUI_DEFINE_MATH_OPERATORS -#define IMGUI_DEFINE_MATH_OPERATORS -#endif #include #include #include "window/gui/GuiElement.h" diff --git a/src/window/gui/InputEditorWindow.h b/src/window/gui/InputEditorWindow.h index 29f515232..2f408c7d2 100644 --- a/src/window/gui/InputEditorWindow.h +++ b/src/window/gui/InputEditorWindow.h @@ -2,9 +2,6 @@ #include "stdint.h" #include "window/gui/GuiWindow.h" -#ifndef IMGUI_DEFINE_MATH_OPERATORS -#define IMGUI_DEFINE_MATH_OPERATORS -#endif #include #include #include diff --git a/src/window/gui/StatsWindow.cpp b/src/window/gui/StatsWindow.cpp index 0723ce224..7b169d13c 100644 --- a/src/window/gui/StatsWindow.cpp +++ b/src/window/gui/StatsWindow.cpp @@ -1,7 +1,4 @@ #include "StatsWindow.h" -#ifndef IMGUI_DEFINE_MATH_OPERATORS -#define IMGUI_DEFINE_MATH_OPERATORS -#endif #include #include "public/bridge/consolevariablebridge.h" #include "spdlog/spdlog.h" diff --git a/src/window/gui/resource/GuiTexture.h b/src/window/gui/resource/GuiTexture.h index 05532fb75..a5145a62e 100644 --- a/src/window/gui/resource/GuiTexture.h +++ b/src/window/gui/resource/GuiTexture.h @@ -7,7 +7,7 @@ namespace Ship { #define RESOURCE_TYPE_GUI_TEXTURE 0x47544558 // GTEX struct GuiTextureMetadata { - unsigned long long RendererTextureId; + uint32_t RendererTextureId; int32_t Width; int32_t Height; };