From d925c8216dc97c007bf5b88d14bc0e34dbe5040c Mon Sep 17 00:00:00 2001 From: WerWolv Date: Sat, 9 Aug 2025 19:13:45 +0200 Subject: [PATCH] impr: Allow ImHex to be used without subpixel rendering on Windows if only OpenGL 3 is available --- lib/libimhex/include/hex/api/imhex_api.hpp | 7 ++++ .../include/hex/helpers/semantic_version.hpp | 1 + lib/libimhex/source/api/imhex_api.cpp | 9 +++++ .../source/helpers/semantic_version.cpp | 4 ++ main/gui/source/init/splash_window.cpp | 7 ++++ main/gui/source/window/win_window.cpp | 9 ++++- plugins/fonts/include/font_settings.hpp | 39 +++++++++++++------ 7 files changed, 62 insertions(+), 14 deletions(-) diff --git a/lib/libimhex/include/hex/api/imhex_api.hpp b/lib/libimhex/include/hex/api/imhex_api.hpp index 04ce4f4b9..17f80f815 100644 --- a/lib/libimhex/include/hex/api/imhex_api.hpp +++ b/lib/libimhex/include/hex/api/imhex_api.hpp @@ -443,6 +443,7 @@ EXPORT_MODULE namespace hex { void setGPUVendor(const std::string &vendor); void setGLRenderer(const std::string &renderer); + void setGLVersion(SemanticVersion version); void addInitArgument(const std::string &key, const std::string &value = { }); @@ -594,6 +595,12 @@ EXPORT_MODULE namespace hex { */ const std::string& getGLRenderer(); + /** + * @brief Gets the current OpenGL version + * @return The current OpenGL version + */ + const SemanticVersion& getGLVersion(); + /** * @brief Checks if ImHex is being run in a "Corporate Environment" * This function simply checks for common telltale signs such as if the machine is joined a diff --git a/lib/libimhex/include/hex/helpers/semantic_version.hpp b/lib/libimhex/include/hex/helpers/semantic_version.hpp index 7e7365c72..67f94daf3 100644 --- a/lib/libimhex/include/hex/helpers/semantic_version.hpp +++ b/lib/libimhex/include/hex/helpers/semantic_version.hpp @@ -11,6 +11,7 @@ EXPORT_MODULE namespace hex { class SemanticVersion { public: SemanticVersion() = default; + SemanticVersion(u32 major, u32 minor, u32 patch); SemanticVersion(std::string version); SemanticVersion(std::string_view version); SemanticVersion(const char *version); diff --git a/lib/libimhex/source/api/imhex_api.cpp b/lib/libimhex/source/api/imhex_api.cpp index 332a09375..efbd4abd9 100644 --- a/lib/libimhex/source/api/imhex_api.cpp +++ b/lib/libimhex/source/api/imhex_api.cpp @@ -560,6 +560,11 @@ namespace hex { s_glRenderer = renderer; } + static SemanticVersion s_openGLVersion; + void setGLVersion(SemanticVersion version) { + s_openGLVersion = version; + } + static AutoReset> s_initArguments; void addInitArgument(const std::string &key, const std::string &value) { static std::mutex initArgumentsMutex; @@ -755,6 +760,10 @@ namespace hex { return impl::s_glRenderer; } + const SemanticVersion& getGLVersion() { + return impl::s_openGLVersion; + } + bool isCorporateEnvironment() { #if defined(OS_WINDOWS) { diff --git a/lib/libimhex/source/helpers/semantic_version.cpp b/lib/libimhex/source/helpers/semantic_version.cpp index ca284aa8c..bf798cd9f 100644 --- a/lib/libimhex/source/helpers/semantic_version.cpp +++ b/lib/libimhex/source/helpers/semantic_version.cpp @@ -4,6 +4,10 @@ namespace hex { + SemanticVersion::SemanticVersion(u32 major, u32 minor, u32 patch) : SemanticVersion(fmt::format("{}.{}.{}", major, minor, patch)) { + + } + SemanticVersion::SemanticVersion(const char *version) : SemanticVersion(std::string(version)) { } diff --git a/main/gui/source/init/splash_window.cpp b/main/gui/source/init/splash_window.cpp index 27aecb4bf..21c2addf3 100644 --- a/main/gui/source/init/splash_window.cpp +++ b/main/gui/source/init/splash_window.cpp @@ -71,6 +71,13 @@ namespace hex::init { ImHexApi::System::impl::setGPUVendor(glVendor); ImHexApi::System::impl::setGLRenderer(glRenderer); + + { + int glVersionMajor = 0, glVersionMinor = 0; + glGetIntegerv(GL_MAJOR_VERSION, &glVersionMajor); + glGetIntegerv(GL_MINOR_VERSION, &glVersionMinor); + ImHexApi::System::impl::setGLVersion(SemanticVersion(glVersionMajor, glVersionMinor, 0)); + } } } diff --git a/main/gui/source/window/win_window.cpp b/main/gui/source/window/win_window.cpp index 6ea2daccd..9825f25b9 100644 --- a/main/gui/source/window/win_window.cpp +++ b/main/gui/source/window/win_window.cpp @@ -397,8 +397,13 @@ namespace hex { } void Window::configureGLFW() { - glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); - glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1); + if (ImHexApi::System::getGLVersion() >= SemanticVersion(4,1,0)) { + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1); + } else { + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); + } glfwWindowHint(GLFW_DECORATED, ImHexApi::System::isBorderlessWindowModeEnabled() ? GL_FALSE : GL_TRUE); // Windows versions before Windows 10 have issues with transparent framebuffers diff --git a/plugins/fonts/include/font_settings.hpp b/plugins/fonts/include/font_settings.hpp index f73c289c6..e6fcd7d7c 100644 --- a/plugins/fonts/include/font_settings.hpp +++ b/plugins/fonts/include/font_settings.hpp @@ -13,18 +13,33 @@ namespace hex::fonts { class AntialiasPicker : public ContentRegistry::Settings::Widgets::DropDown { public: - AntialiasPicker() : DropDown( - // Only allow subpixel rendering on Windows and Linux - #if defined(OS_WINDOWS) || defined(OS_LINUX) - std::vector({"hex.fonts.setting.font.antialias_none", "hex.fonts.setting.font.antialias_grayscale", "hex.fonts.setting.font.antialias_subpixel"}), - std::vector({"none", "grayscale" , "subpixel"}), - nlohmann::json("subpixel") - #else - std::vector({"hex.fonts.setting.font.antialias_none", "hex.fonts.setting.font.antialias_grayscale"}), - std::vector({"none", "grayscale"}), - nlohmann::json("grayscale") - #endif - ){} + + AntialiasPicker() : DropDown(create()) { } + + private: + static bool isSubpixelRenderingSupported() { + #if defined(OS_WINDOWS) || defined(OS_LINUX) + return ImHexApi::System::getGLVersion() >= SemanticVersion(4,1,0); + #else + return false; + #endif + } + + static DropDown create() { + if (isSubpixelRenderingSupported()) { + return DropDown( + std::vector{ "hex.fonts.setting.font.antialias_none", "hex.fonts.setting.font.antialias_grayscale", "hex.fonts.setting.font.antialias_subpixel" }, + { "none", "grayscale" , "subpixel" }, + "subpixel" + ); + } else { + return DropDown( + std::vector{ "hex.fonts.setting.font.antialias_none", "hex.fonts.setting.font.antialias_grayscale" }, + { "none", "grayscale" }, + "grayscale" + ); + } + } }; class FontFilePicker : public ContentRegistry::Settings::Widgets::FilePicker {