impr: Allow ImHex to be used without subpixel rendering on Windows if only OpenGL 3 is available

This commit is contained in:
WerWolv
2025-08-09 19:13:45 +02:00
parent e6f46747b6
commit d925c8216d
7 changed files with 62 additions and 14 deletions

View File

@@ -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

View File

@@ -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);

View File

@@ -560,6 +560,11 @@ namespace hex {
s_glRenderer = renderer;
}
static SemanticVersion s_openGLVersion;
void setGLVersion(SemanticVersion version) {
s_openGLVersion = version;
}
static AutoReset<std::map<std::string, std::string>> 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)
{

View File

@@ -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)) {
}

View File

@@ -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));
}
}
}

View File

@@ -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

View File

@@ -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<UnlocalizedString>({"hex.fonts.setting.font.antialias_none", "hex.fonts.setting.font.antialias_grayscale", "hex.fonts.setting.font.antialias_subpixel"}),
std::vector<nlohmann::json>({"none", "grayscale" , "subpixel"}),
nlohmann::json("subpixel")
#else
std::vector<UnlocalizedString>({"hex.fonts.setting.font.antialias_none", "hex.fonts.setting.font.antialias_grayscale"}),
std::vector<nlohmann::json>({"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<UnlocalizedString>{ "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<UnlocalizedString>{ "hex.fonts.setting.font.antialias_none", "hex.fonts.setting.font.antialias_grayscale" },
{ "none", "grayscale" },
"grayscale"
);
}
}
};
class FontFilePicker : public ContentRegistry::Settings::Widgets::FilePicker {