From 0f5e125992945a38eb8477cc3d03829d828907a1 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Fri, 3 May 2024 19:27:12 +0200 Subject: [PATCH] impr: Added back multisampling with proper detection logic --- .../source/ui/imgui_imhex_extensions.cpp | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/lib/libimhex/source/ui/imgui_imhex_extensions.cpp b/lib/libimhex/source/ui/imgui_imhex_extensions.cpp index 337951e94..3d60b929f 100644 --- a/lib/libimhex/source/ui/imgui_imhex_extensions.cpp +++ b/lib/libimhex/source/ui/imgui_imhex_extensions.cpp @@ -21,6 +21,7 @@ #include #include +#include namespace ImGuiExt { @@ -29,6 +30,20 @@ namespace ImGuiExt { namespace { + bool isOpenGLExtensionSupported(const char *name) { + GLint extensionCount = 0; + glGetIntegerv(GL_NUM_EXTENSIONS, &extensionCount); + + for (GLint i = 0; i < extensionCount; i++) { + std::string_view extension = reinterpret_cast(glGetStringi(GL_EXTENSIONS, i)); + if (extension == name) { + return true; + } + } + + return false; + } + constexpr auto getGLFilter(Texture::Filter filter) { switch (filter) { using enum Texture::Filter; @@ -68,7 +83,13 @@ namespace ImGuiExt { if (filter == Texture::Filter::Nearest) return texture; - #if 0 + if (!isOpenGLExtensionSupported("GL_ARB_texture_multisample")) { + hex::log::error("Platform does not support texture multisample! Bailing out!"); + return texture; + } + + #if defined(GL_TEXTURE_2D_MULTISAMPLE) + constexpr static auto SampleCount = 8; // Generate renderbuffer @@ -83,18 +104,20 @@ namespace ImGuiExt { glBindFramebuffer(GL_FRAMEBUFFER, framebuffer); // Attach texture to color attachment 0 - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, texture, 0); // Attach renderbuffer to depth-stencil attachment glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, renderbuffer); // Check framebuffer status if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) { - return 0; + hex::log::error("Platform claim to support texture multisample but the API is failing! Bailing out!"); + return texture; } // Unbind framebuffer glBindFramebuffer(GL_FRAMEBUFFER, 0); + #endif return texture;