Skip to content

Commit 0f5e125

Browse files
committed
impr: Added back multisampling with proper detection logic
1 parent 5785755 commit 0f5e125

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

lib/libimhex/source/ui/imgui_imhex_extensions.cpp

+26-3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#include <hex/api/task_manager.hpp>
2323
#include <hex/api/theme_manager.hpp>
24+
#include <hex/helpers/logger.hpp>
2425

2526

2627
namespace ImGuiExt {
@@ -29,6 +30,20 @@ namespace ImGuiExt {
2930

3031
namespace {
3132

33+
bool isOpenGLExtensionSupported(const char *name) {
34+
GLint extensionCount = 0;
35+
glGetIntegerv(GL_NUM_EXTENSIONS, &extensionCount);
36+
37+
for (GLint i = 0; i < extensionCount; i++) {
38+
std::string_view extension = reinterpret_cast<const char*>(glGetStringi(GL_EXTENSIONS, i));
39+
if (extension == name) {
40+
return true;
41+
}
42+
}
43+
44+
return false;
45+
}
46+
3247
constexpr auto getGLFilter(Texture::Filter filter) {
3348
switch (filter) {
3449
using enum Texture::Filter;
@@ -68,7 +83,13 @@ namespace ImGuiExt {
6883
if (filter == Texture::Filter::Nearest)
6984
return texture;
7085

71-
#if 0
86+
if (!isOpenGLExtensionSupported("GL_ARB_texture_multisample")) {
87+
hex::log::error("Platform does not support texture multisample! Bailing out!");
88+
return texture;
89+
}
90+
91+
#if defined(GL_TEXTURE_2D_MULTISAMPLE)
92+
7293
constexpr static auto SampleCount = 8;
7394

7495
// Generate renderbuffer
@@ -83,18 +104,20 @@ namespace ImGuiExt {
83104
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
84105

85106
// Attach texture to color attachment 0
86-
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
107+
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, texture, 0);
87108

88109
// Attach renderbuffer to depth-stencil attachment
89110
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, renderbuffer);
90111

91112
// Check framebuffer status
92113
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
93-
return 0;
114+
hex::log::error("Platform claim to support texture multisample but the API is failing! Bailing out!");
115+
return texture;
94116
}
95117

96118
// Unbind framebuffer
97119
glBindFramebuffer(GL_FRAMEBUFFER, 0);
120+
98121
#endif
99122

100123
return texture;

0 commit comments

Comments
 (0)