From 09ad6d704060a6a2a9a08771e796bc9bec09479f Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Wed, 30 Mar 2022 14:46:08 +0200 Subject: [PATCH] Tech ENABLE_GL_CORE_PROFILE - Fixed detection of OpenGL extensions and support for newer Mesa drivers --- src/libslic3r/Technologies.hpp | 2 +- src/slic3r/GUI/GLCanvas3D.cpp | 10 +++++++-- src/slic3r/GUI/OpenGLManager.cpp | 36 +++++++++++++++++++++++++++++--- src/slic3r/GUI/OpenGLManager.hpp | 5 +++++ 4 files changed, 47 insertions(+), 6 deletions(-) diff --git a/src/libslic3r/Technologies.hpp b/src/libslic3r/Technologies.hpp index ab595817fd..c33abaddec 100644 --- a/src/libslic3r/Technologies.hpp +++ b/src/libslic3r/Technologies.hpp @@ -55,7 +55,7 @@ #define ENABLE_WIPETOWER_OBJECTID_1000_REMOVAL (1 && ENABLE_2_5_0_ALPHA1) // Enable removal of legacy OpenGL calls #define ENABLE_LEGACY_OPENGL_REMOVAL (1 && ENABLE_2_5_0_ALPHA1) -// Enable OpenGL core profile context +// Enable OpenGL core profile context (tested against Mesa 20.1.8 on Windows) #define ENABLE_GL_CORE_PROFILE (1 && ENABLE_LEGACY_OPENGL_REMOVAL) // Shows an imgui dialog with GLModel statistics data #define ENABLE_GLMODEL_STATISTICS (0 && ENABLE_LEGACY_OPENGL_REMOVAL) diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 35745ab525..34611bfcc8 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -123,8 +123,14 @@ void GLCanvas3D::LayersEditing::init() { glsafe(::glGenTextures(1, (GLuint*)&m_z_texture_id)); glsafe(::glBindTexture(GL_TEXTURE_2D, m_z_texture_id)); - glsafe(::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP)); - glsafe(::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP)); +#if ENABLE_GL_CORE_PROFILE + if (!OpenGLManager::get_gl_info().is_core_profile() || !OpenGLManager::get_gl_info().is_mesa()) { +#endif // ENABLE_GL_CORE_PROFILE + glsafe(::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP)); + glsafe(::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP)); +#if ENABLE_GL_CORE_PROFILE + } +#endif // ENABLE_GL_CORE_PROFILE glsafe(::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); glsafe(::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST)); glsafe(::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1)); diff --git a/src/slic3r/GUI/OpenGLManager.cpp b/src/slic3r/GUI/OpenGLManager.cpp index 9dfa32789a..b1bd9dd32f 100644 --- a/src/slic3r/GUI/OpenGLManager.cpp +++ b/src/slic3r/GUI/OpenGLManager.cpp @@ -30,6 +30,7 @@ namespace GUI { std::string gl_get_string_safe(GLenum param, const std::string& default_value) { const char* value = (const char*)::glGetString(param); + glcheck(); return std::string((value != nullptr) ? value : default_value); } @@ -65,6 +66,18 @@ const std::string& OpenGLManager::GLInfo::get_renderer() const return m_renderer; } +#if ENABLE_GL_CORE_PROFILE +bool OpenGLManager::GLInfo::is_core_profile() const +{ + return !GLEW_ARB_compatibility; +} + +bool OpenGLManager::GLInfo::is_mesa() const +{ + return boost::icontains(m_version, "mesa"); +} +#endif // ENABLE_OPENGL_ES + int OpenGLManager::GLInfo::get_max_tex_size() const { if (!m_detected) @@ -176,7 +189,7 @@ std::string OpenGLManager::GLInfo::to_string(bool for_github) const out << h2_start << "OpenGL installation" << h2_end << line_end; out << b_start << "GL version: " << b_end << m_version << line_end; #if ENABLE_GL_CORE_PROFILE - out << b_start << "Profile: " << b_end << (GLEW_ARB_compatibility ? "Compatibility" : "Core") << line_end; + out << b_start << "Profile: " << b_end << (is_core_profile() ? "Core" : "Compatibility") << line_end; #endif // ENABLE_GL_CORE_PROFILE out << b_start << "Vendor: " << b_end << m_vendor << line_end; out << b_start << "Renderer: " << b_end << m_renderer << line_end; @@ -184,8 +197,25 @@ std::string OpenGLManager::GLInfo::to_string(bool for_github) const { std::vector extensions_list; - std::string extensions_str = gl_get_string_safe(GL_EXTENSIONS, ""); - boost::split(extensions_list, extensions_str, boost::is_any_of(" "), boost::token_compress_on); +#if ENABLE_GL_CORE_PROFILE + std::string extensions_str; + if (is_core_profile()) { + GLint n = 0; + glsafe(::glGetIntegerv(GL_NUM_EXTENSIONS, &n)); + for (GLint i = 0; i < n; ++i) { + const char* extension = (const char*)::glGetStringi(GL_EXTENSIONS, i); + glcheck(); + if (extension != nullptr) + extensions_list.emplace_back(extension); + } + } + else { + extensions_str = gl_get_string_safe(GL_EXTENSIONS, ""); + boost::split(extensions_list, extensions_str, boost::is_any_of(" "), boost::token_compress_on); + } +#else + const std::string extensions_str = gl_get_string_safe(GL_EXTENSIONS, ""); +#endif // ENABLE_GL_CORE_PROFILE if (!extensions_list.empty()) { if (for_github) diff --git a/src/slic3r/GUI/OpenGLManager.hpp b/src/slic3r/GUI/OpenGLManager.hpp index 298e003f23..892a1ac3f1 100644 --- a/src/slic3r/GUI/OpenGLManager.hpp +++ b/src/slic3r/GUI/OpenGLManager.hpp @@ -43,6 +43,11 @@ public: const std::string& get_vendor() const; const std::string& get_renderer() const; +#if ENABLE_GL_CORE_PROFILE + bool is_core_profile() const; + bool is_mesa() const; +#endif // ENABLE_OPENGL_ES + int get_max_tex_size() const; float get_max_anisotropy() const;