diff --git a/src/slic3r/GUI/3DBed.cpp b/src/slic3r/GUI/3DBed.cpp index e6589e548..98f2d7dc3 100644 --- a/src/slic3r/GUI/3DBed.cpp +++ b/src/slic3r/GUI/3DBed.cpp @@ -522,6 +522,14 @@ 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 + // generate a temporary lower resolution texture to show while no main texture levels have been compressed + if (!m_temp_texture.load_from_svg_file(filename, false, false, false, max_tex_size / 8)) + { + render_custom(); + return; + } + + // starts generating the main texture, compression will run asynchronously 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)) @@ -542,7 +550,14 @@ void Bed3D::render_prusa(const std::string &key, bool bottom) const } #if ENABLE_COMPRESSED_TEXTURES else if (m_texture.unsent_compressed_data_available()) + { + // sends to gpu the already available compressed levels of the main texture m_texture.send_compressed_data_to_gpu(); + + // the temporary texture is not needed anymore, reset it + if (m_temp_texture.get_id() != 0) + m_temp_texture.reset(); + } #endif // ENABLE_COMPRESSED_TEXTURES if (!bottom) @@ -616,7 +631,16 @@ void Bed3D::render_prusa_shader(bool transparent) const GLint position_id = m_shader.get_attrib_location("v_position"); GLint tex_coords_id = m_shader.get_attrib_location("v_tex_coords"); +#if ENABLE_COMPRESSED_TEXTURES + // show the temporary texture while no compressed data is available + GLuint tex_id = (GLuint)m_temp_texture.get_id(); + if (tex_id == 0) + tex_id = (GLuint)m_texture.get_id(); + + glsafe(::glBindTexture(GL_TEXTURE_2D, tex_id)); +#else glsafe(::glBindTexture(GL_TEXTURE_2D, (GLuint)m_texture.get_id())); +#endif // ENABLE_COMPRESSED_TEXTURES glsafe(::glBindBuffer(GL_ARRAY_BUFFER, m_vbo_id)); if (position_id != -1) diff --git a/src/slic3r/GUI/3DBed.hpp b/src/slic3r/GUI/3DBed.hpp index e60cdf94e..054b746e5 100644 --- a/src/slic3r/GUI/3DBed.hpp +++ b/src/slic3r/GUI/3DBed.hpp @@ -91,6 +91,10 @@ private: GeometryBuffer m_gridlines; #if ENABLE_TEXTURES_FROM_SVG mutable GLTexture m_texture; +#if ENABLE_COMPRESSED_TEXTURES + // temporary texture shown until the main texture has still no levels compressed + mutable GLTexture m_temp_texture; +#endif // ENABLE_COMPRESSED_TEXTURES mutable Shader m_shader; mutable unsigned int m_vbo_id; #else diff --git a/src/slic3r/GUI/GLTexture.cpp b/src/slic3r/GUI/GLTexture.cpp index cc6bdc715..469e192b5 100644 --- a/src/slic3r/GUI/GLTexture.cpp +++ b/src/slic3r/GUI/GLTexture.cpp @@ -343,18 +343,6 @@ void GLTexture::reset() #endif // ENABLE_COMPRESSED_TEXTURES } -#if ENABLE_COMPRESSED_TEXTURES -bool GLTexture::unsent_compressed_data_available() const -{ - return m_compressor.unsent_compressed_data_available(); -} - -void GLTexture::send_compressed_data_to_gpu() -{ - m_compressor.send_compressed_data_to_gpu(); -} -#endif // ENABLE_COMPRESSED_TEXTURES - void GLTexture::render_texture(unsigned int tex_id, float left, float right, float bottom, float top) { render_sub_texture(tex_id, left, right, bottom, top, FullTextureUVs); @@ -603,7 +591,7 @@ bool GLTexture::load_from_svg(const std::string& filename, bool use_mipmaps, uns int lod_h = m_height; GLint level = 0; // we do not need to generate all levels down to 1x1 - while ((lod_w > 64) || (lod_h > 64)) + while ((lod_w > 16) || (lod_h > 16)) { ++level; diff --git a/src/slic3r/GUI/GLTexture.hpp b/src/slic3r/GUI/GLTexture.hpp index f5cf13a45..ed2070a44 100644 --- a/src/slic3r/GUI/GLTexture.hpp +++ b/src/slic3r/GUI/GLTexture.hpp @@ -106,8 +106,8 @@ namespace GUI { const std::string& get_source() const { return m_source; } #if ENABLE_COMPRESSED_TEXTURES - bool unsent_compressed_data_available() const; - void send_compressed_data_to_gpu(); + bool unsent_compressed_data_available() const { return m_compressor.unsent_compressed_data_available(); } + void send_compressed_data_to_gpu() { m_compressor.send_compressed_data_to_gpu(); } #endif // ENABLE_COMPRESSED_TEXTURES static void render_texture(unsigned int tex_id, float left, float right, float bottom, float top);