From 8012499206ba2a4fa1b667ce47e4254b5f378aca Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Tue, 28 May 2019 15:21:34 +0200 Subject: [PATCH] Application of anisotropy to textures moved into GLTexture methods --- src/slic3r/GUI/3DBed.cpp | 8 +++++++- src/slic3r/GUI/GLTexture.cpp | 13 ++++++++++--- src/slic3r/GUI/GLTexture.hpp | 4 ++-- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/slic3r/GUI/3DBed.cpp b/src/slic3r/GUI/3DBed.cpp index 4c4e600e8..91275f4e6 100644 --- a/src/slic3r/GUI/3DBed.cpp +++ b/src/slic3r/GUI/3DBed.cpp @@ -494,16 +494,20 @@ void Bed3D::render_prusa(const std::string &key, bool bottom) const std::string model_path = resources_dir() + "/models/" + key; #if ENABLE_TEXTURES_MAXSIZE_DEPENDENT_ON_OPENGL_VERSION +#if !ENABLE_COMPRESSED_TEXTURES // use anisotropic filter if graphic card allows GLfloat max_anisotropy = GLCanvas3DManager::get_gl_info().get_max_anisotropy(); +#endif // !ENABLE_COMPRESSED_TEXTURES // use higher resolution images if graphic card and opengl version allow GLint max_tex_size = GLCanvas3DManager::get_gl_info().get_max_tex_size(); #else +#if !ENABLE_COMPRESSED_TEXTURES // use anisotropic filter if graphic card allows GLfloat max_anisotropy = 0.0f; if (glewIsSupported("GL_EXT_texture_filter_anisotropic")) glsafe(::glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &max_anisotropy)); +#endif // !ENABLE_COMPRESSED_TEXTURES // use higher resolution images if graphic card allows GLint max_tex_size; @@ -518,7 +522,7 @@ void Bed3D::render_prusa(const std::string &key, bool bottom) const if ((m_texture.get_id() == 0) || (m_texture.get_source() != filename)) { #if ENABLE_COMPRESSED_TEXTURES - if (!m_texture.load_from_svg_file(filename, true, true, max_tex_size)) + if (!m_texture.load_from_svg_file(filename, true, true, true, max_tex_size)) #else if (!m_texture.load_from_svg_file(filename, true, max_tex_size)) #endif // ENABLE_COMPRESSED_TEXTURES @@ -527,12 +531,14 @@ void Bed3D::render_prusa(const std::string &key, bool bottom) const return; } +#if !ENABLE_COMPRESSED_TEXTURES if (max_anisotropy > 0.0f) { glsafe(::glBindTexture(GL_TEXTURE_2D, m_texture.get_id())); glsafe(::glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, max_anisotropy)); glsafe(::glBindTexture(GL_TEXTURE_2D, 0)); } +#endif // !ENABLE_COMPRESSED_TEXTURES } if (!bottom) diff --git a/src/slic3r/GUI/GLTexture.cpp b/src/slic3r/GUI/GLTexture.cpp index bdd7ee624..9c1e1f22e 100644 --- a/src/slic3r/GUI/GLTexture.cpp +++ b/src/slic3r/GUI/GLTexture.cpp @@ -58,7 +58,7 @@ bool GLTexture::load_from_file(const std::string& filename, bool use_mipmaps) } #if ENABLE_COMPRESSED_TEXTURES -bool GLTexture::load_from_svg_file(const std::string& filename, bool use_mipmaps, bool compress, unsigned int max_size_px) +bool GLTexture::load_from_svg_file(const std::string& filename, bool use_mipmaps, bool compress, bool apply_anisotropy, unsigned int max_size_px) #else bool GLTexture::load_from_svg_file(const std::string& filename, bool use_mipmaps, unsigned int max_size_px) #endif // ENABLE_COMPRESSED_TEXTURES @@ -70,7 +70,7 @@ bool GLTexture::load_from_svg_file(const std::string& filename, bool use_mipmaps if (boost::algorithm::iends_with(filename, ".svg")) #if ENABLE_COMPRESSED_TEXTURES - return load_from_svg(filename, use_mipmaps, compress, max_size_px); + return load_from_svg(filename, use_mipmaps, compress, apply_anisotropy, max_size_px); #else return load_from_svg(filename, use_mipmaps, max_size_px); #endif // ENABLE_COMPRESSED_TEXTURES @@ -411,7 +411,7 @@ bool GLTexture::load_from_png(const std::string& filename, bool use_mipmaps) } #if ENABLE_COMPRESSED_TEXTURES -bool GLTexture::load_from_svg(const std::string& filename, bool use_mipmaps, bool compress, unsigned int max_size_px) +bool GLTexture::load_from_svg(const std::string& filename, bool use_mipmaps, bool compress, bool apply_anisotropy, unsigned int max_size_px) #else bool GLTexture::load_from_svg(const std::string& filename, bool use_mipmaps, unsigned int max_size_px) #endif // ENABLE_COMPRESSED_TEXTURES @@ -455,6 +455,13 @@ bool GLTexture::load_from_svg(const std::string& filename, bool use_mipmaps, uns glsafe(::glGenTextures(1, &m_id)); glsafe(::glBindTexture(GL_TEXTURE_2D, m_id)); #if ENABLE_COMPRESSED_TEXTURES + if (apply_anisotropy) + { + GLfloat max_anisotropy = GLCanvas3DManager::get_gl_info().get_max_anisotropy(); + if (max_anisotropy > 1.0f) + glsafe(::glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, max_anisotropy)); + } + if (compress && GLEW_EXT_texture_compression_s3tc) glsafe(::glTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, (GLsizei)m_width, (GLsizei)m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, (const void*)data.data())); else diff --git a/src/slic3r/GUI/GLTexture.hpp b/src/slic3r/GUI/GLTexture.hpp index b474f7b05..032d19121 100644 --- a/src/slic3r/GUI/GLTexture.hpp +++ b/src/slic3r/GUI/GLTexture.hpp @@ -40,7 +40,7 @@ namespace GUI { #if ENABLE_COMPRESSED_TEXTURES bool load_from_file(const std::string& filename, bool use_mipmaps, bool compress); - bool load_from_svg_file(const std::string& filename, bool use_mipmaps, bool compress, unsigned int max_size_px); + bool load_from_svg_file(const std::string& filename, bool use_mipmaps, bool compress, bool apply_anisotropy, unsigned int max_size_px); #else bool load_from_file(const std::string& filename, bool use_mipmaps); bool load_from_svg_file(const std::string& filename, bool use_mipmaps, unsigned int max_size_px); @@ -79,7 +79,7 @@ namespace GUI { private: #if ENABLE_COMPRESSED_TEXTURES bool load_from_png(const std::string& filename, bool use_mipmaps, bool compress); - bool load_from_svg(const std::string& filename, bool use_mipmaps, bool compress, unsigned int max_size_px); + bool load_from_svg(const std::string& filename, bool use_mipmaps, bool compress, bool apply_anisotropy, unsigned int max_size_px); #else bool load_from_png(const std::string& filename, bool use_mipmaps); bool load_from_svg(const std::string& filename, bool use_mipmaps, unsigned int max_size_px);