From 999bae0f53eb1c4ca319cd3a318b5bc869c6dce3 Mon Sep 17 00:00:00 2001 From: "jun.zhang" Date: Wed, 22 Jan 2025 19:07:52 +0800 Subject: [PATCH] FIX: black edge issue jira: STUDIO-9954 Change-Id: Ib503039383763074947992606ac9a8f7b8409ec8 (cherry picked from commit 3870dbb980a36535f22ec8a0849546c0b1ee7b4c) --- resources/shaders/110/printbed.fs | 14 ++++++----- src/slic3r/GUI/GLModel.cpp | 1 - src/slic3r/GUI/GLTexture.cpp | 40 +++++++++++++++++++++++++++++++ src/slic3r/GUI/GLTexture.hpp | 13 ++++++++++ src/slic3r/GUI/PartPlate.cpp | 7 +++--- 5 files changed, 65 insertions(+), 10 deletions(-) diff --git a/resources/shaders/110/printbed.fs b/resources/shaders/110/printbed.fs index 833dff08f..b9a284291 100644 --- a/resources/shaders/110/printbed.fs +++ b/resources/shaders/110/printbed.fs @@ -9,26 +9,28 @@ uniform bool svg_source; varying vec2 tex_coord; -vec4 svg_color() +vec4 svg_color(vec2 uv) { // takes foreground from texture - vec4 fore_color = texture2D(texture, tex_coord); + vec4 fore_color = texture2D(texture, uv); // calculates radial gradient - vec3 back_color = vec3(mix(back_color_light, back_color_dark, smoothstep(0.0, 0.5, length(abs(tex_coord.xy) - vec2(0.5))))); + vec3 back_color = vec3(mix(back_color_light, back_color_dark, smoothstep(0.0, 0.5, length(abs(uv) - vec2(0.5))))); // blends foreground with background return vec4(mix(back_color, fore_color.rgb, fore_color.a), transparent_background ? fore_color.a : 1.0); } -vec4 non_svg_color() +vec4 non_svg_color(vec2 uv) { // takes foreground from texture - vec4 color = texture2D(texture, tex_coord); + vec4 color = texture2D(texture, uv); return vec4(color.rgb, transparent_background ? color.a * 0.25 : color.a); } void main() { - gl_FragColor = svg_source ? svg_color() : non_svg_color(); + // flip uv + vec2 uv = vec2(tex_coord.x, 1.0 - tex_coord.y); + gl_FragColor = svg_source ? svg_color(uv) : non_svg_color(uv); } \ No newline at end of file diff --git a/src/slic3r/GUI/GLModel.cpp b/src/slic3r/GUI/GLModel.cpp index 61e068741..7fea2bf9b 100644 --- a/src/slic3r/GUI/GLModel.cpp +++ b/src/slic3r/GUI/GLModel.cpp @@ -660,7 +660,6 @@ bool GLModel::init_model_from_poly(const std::vector &triangles, float z, return false; Vec2f inv_size = size.cwiseInverse(); - inv_size.y() *= -1.0f; // vertices + indices unsigned int vertices_counter = 0; diff --git a/src/slic3r/GUI/GLTexture.cpp b/src/slic3r/GUI/GLTexture.cpp index e144f78e2..7336b3ba2 100644 --- a/src/slic3r/GUI/GLTexture.cpp +++ b/src/slic3r/GUI/GLTexture.cpp @@ -30,6 +30,21 @@ #include #include #include "FontUtils.hpp" +namespace { + GLenum get_gl_texture_wrap_mode(Slic3r::GUI::GLTexture::ESamplerWrapMode mode) { + switch (mode) { + case Slic3r::GUI::GLTexture::ESamplerWrapMode::Repeat: + return GL_REPEAT; + case Slic3r::GUI::GLTexture::ESamplerWrapMode::MirrorRepeat: + return GL_MIRRORED_REPEAT; + case Slic3r::GUI::GLTexture::ESamplerWrapMode::Border: + return GL_CLAMP_TO_BORDER; + case Slic3r::GUI::GLTexture::ESamplerWrapMode::Clamp: + default: + return GL_CLAMP_TO_EDGE; + } + } +} namespace Slic3r { namespace GUI { @@ -658,6 +673,31 @@ bool GLTexture::generate_texture_from_text(const std::string& text_str, wxFont& return true; } +void GLTexture::set_wrap_mode_u(ESamplerWrapMode mode) +{ + m_wrap_mode_u = mode; +} + +void GLTexture::set_wrap_mode_v(ESamplerWrapMode mode) +{ + m_wrap_mode_v = mode; +} + +void GLTexture::bind(uint8_t stage) +{ + glActiveTexture(GL_TEXTURE0 + stage); + glBindTexture(GL_TEXTURE_2D, m_id); + + // set sampler state + glsafe(::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, get_gl_texture_wrap_mode(m_wrap_mode_u))); + glsafe(::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, get_gl_texture_wrap_mode(m_wrap_mode_v))); +} + +void GLTexture::unbind() +{ + glBindTexture(GL_TEXTURE_2D, 0); +} + 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); diff --git a/src/slic3r/GUI/GLTexture.hpp b/src/slic3r/GUI/GLTexture.hpp index cc446ab06..6acf57557 100644 --- a/src/slic3r/GUI/GLTexture.hpp +++ b/src/slic3r/GUI/GLTexture.hpp @@ -64,6 +64,13 @@ namespace GUI { SingleThreaded, MultiThreaded }; + enum ESamplerWrapMode : uint8_t + { + Repeat, + MirrorRepeat, + Clamp, + Border + }; struct UV { @@ -87,6 +94,8 @@ namespace GUI { int m_height; std::string m_source; Compressor m_compressor; + ESamplerWrapMode m_wrap_mode_u{ ESamplerWrapMode::Clamp }; + ESamplerWrapMode m_wrap_mode_v{ ESamplerWrapMode::Clamp }; public: GLTexture(); @@ -124,6 +133,10 @@ namespace GUI { 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(); } bool all_compressed_data_sent_to_gpu() const { return m_compressor.all_compressed_data_sent_to_gpu(); } + void set_wrap_mode_u(ESamplerWrapMode mode); + void set_wrap_mode_v(ESamplerWrapMode mode); + void bind(uint8_t stage = 0); + void unbind(); static void render_texture(unsigned int tex_id, float left, float right, float bottom, float top); static void render_sub_texture(unsigned int tex_id, float left, float right, float bottom, float top, const Quad_UVs& uvs); diff --git a/src/slic3r/GUI/PartPlate.cpp b/src/slic3r/GUI/PartPlate.cpp index bfe60c93b..0e33a9243 100644 --- a/src/slic3r/GUI/PartPlate.cpp +++ b/src/slic3r/GUI/PartPlate.cpp @@ -517,10 +517,11 @@ void PartPlate::render_logo_texture(GLTexture &logo_texture, GLModel &logo_buffe glsafe(::glFrontFace(GL_CW)); // show the temporary texture while no compressed data is available - GLuint tex_id = (GLuint)logo_texture.get_id(); - glsafe(::glBindTexture(GL_TEXTURE_2D, tex_id)); + logo_texture.set_wrap_mode_u(GLTexture::ESamplerWrapMode::Clamp); + logo_texture.set_wrap_mode_v(GLTexture::ESamplerWrapMode::Clamp); + logo_texture.bind(0); logo_buffer.render_geometry(); - glsafe(::glBindTexture(GL_TEXTURE_2D, 0)); + logo_texture.unbind(); if (bottom) glsafe(::glFrontFace(GL_CCW));