fix: Texture multisampling being used on OpenGL < 3.2

#1653
This commit is contained in:
WerWolv
2024-05-08 22:09:47 +02:00
parent d7ddf991a9
commit 89f360d1a7
2 changed files with 39 additions and 11 deletions

View File

@@ -31,17 +31,29 @@ namespace ImGuiExt {
namespace {
bool isOpenGLExtensionSupported(const char *name) {
GLint extensionCount = 0;
glGetIntegerv(GL_NUM_EXTENSIONS, &extensionCount);
static std::set<std::string> extensions;
for (GLint i = 0; i < extensionCount; i++) {
std::string_view extension = reinterpret_cast<const char*>(glGetStringi(GL_EXTENSIONS, i));
if (extension == name) {
return true;
if (extensions.empty()) {
GLint extensionCount = 0;
glGetIntegerv(GL_NUM_EXTENSIONS, &extensionCount);
for (GLint i = 0; i < extensionCount; i++) {
std::string extension = reinterpret_cast<const char*>(glGetStringi(GL_EXTENSIONS, i));
extensions.emplace(std::move(extension));
}
}
return false;
return extensions.contains(name);
}
bool isOpenGLVersionAtLeast(u8 major, u8 minor) {
static GLint actualMajor = 0, actualMinor = 0;
if (actualMajor == 0 || actualMinor == 0) {
glGetIntegerv(GL_MAJOR_VERSION, &actualMajor);
glGetIntegerv(GL_MINOR_VERSION, &actualMinor);
}
return actualMajor > major || (actualMajor == major && actualMinor >= minor);
}
constexpr auto getGLFilter(Texture::Filter filter) {
@@ -80,8 +92,13 @@ namespace ImGuiExt {
// Create a regular texture from the RGBA8 array
GLuint texture = createTextureFromRGBA8Array(buffer, width, height, filter);
if (filter == Texture::Filter::Nearest)
if (filter == Texture::Filter::Nearest) {
return texture;
}
if (!isOpenGLVersionAtLeast(3,2)) {
return texture;
}
if (!isOpenGLExtensionSupported("GL_ARB_texture_multisample")) {
return texture;