From cad887553a5bdfed549aea75ee04cc9be5c473b6 Mon Sep 17 00:00:00 2001 From: Andrew Sun Date: Wed, 24 Sep 2025 22:18:40 -0400 Subject: [PATCH] Fix bed grid thin/thick lines in OpenGL Core Profile --- src/slic3r/GUI/PartPlate.cpp | 61 +++++++++++++++++++++++++++++++++--- 1 file changed, 56 insertions(+), 5 deletions(-) diff --git a/src/slic3r/GUI/PartPlate.cpp b/src/slic3r/GUI/PartPlate.cpp index d67c8f7f13..4d0bd1e94b 100644 --- a/src/slic3r/GUI/PartPlate.cpp +++ b/src/slic3r/GUI/PartPlate.cpp @@ -875,7 +875,30 @@ void PartPlate::render_exclude_area(bool force_default_color) { void PartPlate::render_grid(bool bottom) { //glsafe(::glEnable(GL_MULTISAMPLE)); // draw grid - glsafe(::glLineWidth(1.0f * m_scale_factor)); + + // ORCA: OpenGL Core Profile support + // FIXME: ideally, we'd use the same shader for both the thin and thick lines, but for some reason setting the uniforms has no effect + GLShaderProgram* shader = wxGetApp().get_shader("flat"); + if (shader == nullptr) { + return; + } + + shader->start_using(); + glsafe(::glEnable(GL_BLEND)); + glsafe(::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); + + const Camera& camera = wxGetApp().plater()->get_camera(); + const std::array& viewport = camera.get_viewport(); + const Transform3d& view_matrix = camera.get_view_matrix(); + const Transform3d& projection_matrix = camera.get_projection_matrix(); + + shader->set_uniform("view_model_matrix", view_matrix); + shader->set_uniform("projection_matrix", projection_matrix); + +#if !SLIC3R_OPENGL_ES + if (!OpenGLManager::get_gl_info().is_core_profile()) + glsafe(::glLineWidth(1.0f * m_scale_factor)); +#endif // !SLIC3R_OPENGL_ES ColorRGBA color; if (bottom) @@ -889,9 +912,37 @@ void PartPlate::render_grid(bool bottom) { m_gridlines.set_color(color); m_gridlines.render(); - glsafe(::glLineWidth(2.0f * m_scale_factor)); + shader->stop_using(); + + // ORCA: OpenGL Core Profile support +#if SLIC3R_OPENGL_ES + shader = wxGetApp().get_shader("dashed_lines"); +#else + shader = OpenGLManager::get_gl_info().is_core_profile() ? wxGetApp().get_shader("dashed_thick_lines") : wxGetApp().get_shader("flat"); +#endif // SLIC3R_OPENGL_ES + if (shader == nullptr) { + return; + } + shader->start_using(); + + shader->set_uniform("view_model_matrix", view_matrix); + shader->set_uniform("projection_matrix", projection_matrix); + +#if !SLIC3R_OPENGL_ES + if (OpenGLManager::get_gl_info().is_core_profile()) { +#endif // !SLIC3R_OPENGL_ES + shader->set_uniform("viewport_size", Vec2d(double(viewport[2]), double(viewport[3]))); + shader->set_uniform("width", 0.25f); +#if !SLIC3R_OPENGL_ES + } else { + glsafe(::glLineWidth(2.0f * m_scale_factor)); + } +#endif // !SLIC3R_OPENGL_ES + m_gridlines_bolder.set_color(color); m_gridlines_bolder.render(); + + shader->stop_using(); } void PartPlate::render_height_limit(PartPlate::HeightLimitMode mode) @@ -2757,9 +2808,6 @@ void PartPlate::render(const Transform3d& view_matrix, const Transform3d& projec render_exclude_area(force_background_color); } - if (show_grid) - render_grid(bottom); - render_height_limit(mode); glsafe(::glDisable(GL_BLEND)); @@ -2771,6 +2819,9 @@ void PartPlate::render(const Transform3d& view_matrix, const Transform3d& projec shader->stop_using(); } + if (show_grid) + render_grid(bottom); + if (!bottom && m_selected && !force_background_color) { if (m_partplate_list) render_logo(bottom, m_partplate_list->render_cali_logo && render_cali);