From c2b8914ed09464178f9c1a87b19f180a0826a0c1 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Tue, 12 Mar 2024 13:41:04 +0100 Subject: [PATCH] Tech ENABLE_GL_CORE_PROFILE set as default --- src/PrusaSlicer.cpp | 32 ++-- src/libslic3r/PrintConfig.cpp | 4 +- src/libslic3r/Technologies.hpp | 3 - src/slic3r/GUI/3DBed.cpp | 8 +- src/slic3r/GUI/3DScene.cpp | 28 ++-- src/slic3r/GUI/GLCanvas3D.cpp | 62 +++++--- src/slic3r/GUI/GLModel.cpp | 88 +++++------ src/slic3r/GUI/GLModel.hpp | 2 - src/slic3r/GUI/GLSelectionRectangle.cpp | 136 ++++++++--------- src/slic3r/GUI/GLShadersManager.cpp | 6 +- src/slic3r/GUI/GLTexture.cpp | 10 -- src/slic3r/GUI/GUI_App.cpp | 8 +- src/slic3r/GUI/GUI_Init.hpp | 4 +- src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp | 37 +++-- .../GUI/Gizmos/GLGizmoMmuSegmentation.cpp | 71 ++++++--- .../GUI/Gizmos/GLGizmoMmuSegmentation.hpp | 2 - src/slic3r/GUI/Gizmos/GLGizmoMove.cpp | 52 ++++--- src/slic3r/GUI/Gizmos/GLGizmoPainterBase.cpp | 144 ++++++++++-------- src/slic3r/GUI/Gizmos/GLGizmoPainterBase.hpp | 2 - src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp | 28 ++-- src/slic3r/GUI/Gizmos/GLGizmoScale.cpp | 124 ++++++++------- src/slic3r/GUI/Gizmos/GLGizmoSimplify.cpp | 14 +- src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp | 8 - src/slic3r/GUI/ImGuiWrapper.cpp | 59 +++---- src/slic3r/GUI/OpenGLManager.cpp | 85 +++-------- src/slic3r/GUI/OpenGLManager.hpp | 18 +-- src/slic3r/GUI/Selection.cpp | 25 +-- src/slic3r/GUI/SendSystemInfoDialog.cpp | 12 +- 28 files changed, 537 insertions(+), 535 deletions(-) diff --git a/src/PrusaSlicer.cpp b/src/PrusaSlicer.cpp index 6eb7f6019e..45e19b3343 100644 --- a/src/PrusaSlicer.cpp +++ b/src/PrusaSlicer.cpp @@ -40,9 +40,9 @@ #include "unix/fhs.hpp" // Generated by CMake from ../platform/unix/fhs.hpp.in #include "libslic3r/libslic3r.h" -#if ENABLE_GL_CORE_PROFILE +#if !SLIC3R_OPENGL_ES #include -#endif // ENABLE_GL_CORE_PROFILE +#endif // !SLIC3R_OPENGL_ES #include "libslic3r/Config.hpp" #include "libslic3r/Geometry.hpp" #include "libslic3r/GCode/PostProcessor.hpp" @@ -191,7 +191,17 @@ int CLI::run(int argc, char **argv) m_actions.erase(it); } #endif // ENABLE_OPENGL_AUTO_AA_SAMPLES -#if ENABLE_GL_CORE_PROFILE +#if SLIC3R_OPENGL_ES + // are we starting as gcodeviewer ? + for (auto it = m_actions.begin(); it != m_actions.end(); ++it) { + if (*it == "gcodeviewer") { + start_gui = true; + start_as_gcodeviewer = true; + m_actions.erase(it); + break; + } + } +#else std::pair opengl_version = { 0, 0 }; bool opengl_debug = false; bool opengl_compatibility_profile = false; @@ -239,17 +249,7 @@ int CLI::run(int argc, char **argv) opengl_debug = true; m_actions.erase(it); } -#else - // are we starting as gcodeviewer ? - for (auto it = m_actions.begin(); it != m_actions.end(); ++it) { - if (*it == "gcodeviewer") { - start_gui = true; - start_as_gcodeviewer = true; - m_actions.erase(it); - break; - } - } -#endif // ENABLE_GL_CORE_PROFILE +#endif // SLIC3R_OPENGL_ES #else // SLIC3R_GUI // If there is no GUI, we shall ignore the parameters. Remove them from the list. #if ENABLE_OPENGL_AUTO_AA_SAMPLES @@ -760,11 +760,11 @@ int CLI::run(int argc, char **argv) #if ENABLE_OPENGL_AUTO_AA_SAMPLES params.opengl_aa = opengl_aa; #endif // ENABLE_OPENGL_AUTO_AA_SAMPLES -#if ENABLE_GL_CORE_PROFILE +#if !SLIC3R_OPENGL_ES params.opengl_version = opengl_version; params.opengl_debug = opengl_debug; params.opengl_compatibiity_profile = opengl_compatibility_profile; -#endif // ENABLE_GL_CORE_PROFILE +#endif // !SLIC3R_OPENGL_ES return Slic3r::GUI::GUI_Run(params); #else // SLIC3R_GUI // No GUI support. Just print out a help. diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index 6d4cbcd9e9..5cd4533c64 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -4923,7 +4923,7 @@ CLIActionsConfigDef::CLIActionsConfigDef() def->set_default_value(new ConfigOptionBool(false)); #endif // ENABLE_OPENGL_AUTO_AA_SAMPLES -#if ENABLE_GL_CORE_PROFILE +#if !SLIC3R_OPENGL_ES def = this->add("opengl-version", coString); def->label = L("OpenGL version"); def->tooltip = L("Select a specific version of OpenGL"); @@ -4941,7 +4941,7 @@ CLIActionsConfigDef::CLIActionsConfigDef() def->tooltip = L("Activate OpenGL debug output on graphic cards which support it (OpenGL 4.3 or higher)"); def->cli = "opengl-debug"; def->set_default_value(new ConfigOptionBool(false)); -#endif // ENABLE_GL_CORE_PROFILE +#endif // !SLIC3R_OPENGL_ES def = this->add("slice", coBool); def->label = L("Slice"); diff --git a/src/libslic3r/Technologies.hpp b/src/libslic3r/Technologies.hpp index 284cb65bae..aeddcf7997 100644 --- a/src/libslic3r/Technologies.hpp +++ b/src/libslic3r/Technologies.hpp @@ -47,9 +47,6 @@ // Enable smoothing of objects normals #define ENABLE_SMOOTH_NORMALS 0 -// Enable OpenGL core profile context (tested against Mesa 20.1.8 on Windows) -#define ENABLE_GL_CORE_PROFILE (1 && !SLIC3R_OPENGL_ES) - // Enable automatic detection of highest number of samples supported for OpenGL antialising #define ENABLE_OPENGL_AUTO_AA_SAMPLES 1 diff --git a/src/slic3r/GUI/3DBed.cpp b/src/slic3r/GUI/3DBed.cpp index 41306c88ad..2f0e10edf0 100644 --- a/src/slic3r/GUI/3DBed.cpp +++ b/src/slic3r/GUI/3DBed.cpp @@ -518,10 +518,10 @@ void Bed3D::render_default(bool bottom, bool picking, bool show_texture, const T if (show_texture) { // draw grid -#if ENABLE_GL_CORE_PROFILE +#if !SLIC3R_OPENGL_ES if (!OpenGLManager::get_gl_info().is_core_profile()) -#endif // ENABLE_GL_CORE_PROFILE glsafe(::glLineWidth(1.5f * m_scale_factor)); +#endif // !SLIC3R_OPENGL_ES m_gridlines.set_color(has_model && !bottom ? DEFAULT_SOLID_GRID_COLOR : DEFAULT_TRANSPARENT_GRID_COLOR); m_gridlines.render(); } @@ -549,10 +549,10 @@ void Bed3D::render_contour(const Transform3d& view_matrix, const Transform3d& pr glsafe(::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); // draw contour -#if ENABLE_GL_CORE_PROFILE +#if !SLIC3R_OPENGL_ES if (!OpenGLManager::get_gl_info().is_core_profile()) -#endif // ENABLE_GL_CORE_PROFILE glsafe(::glLineWidth(1.5f * m_scale_factor)); +#endif // !SLIC3R_OPENGL_ES m_contourlines.render(); glsafe(::glDisable(GL_BLEND)); diff --git a/src/slic3r/GUI/3DScene.cpp b/src/slic3r/GUI/3DScene.cpp index 49d846ed96..b27afd7c3c 100644 --- a/src/slic3r/GUI/3DScene.cpp +++ b/src/slic3r/GUI/3DScene.cpp @@ -147,10 +147,10 @@ void GLVolume::NonManifoldEdges::render() { update(); -#if ENABLE_GL_CORE_PROFILE +#if !SLIC3R_OPENGL_ES if (!GUI::OpenGLManager::get_gl_info().is_core_profile()) -#endif // ENABLE_GL_CORE_PROFILE glsafe(::glLineWidth(2.0f)); +#endif // !SLIC3R_OPENGL_ES GLShaderProgram* shader = GUI::wxGetApp().get_current_shader(); if (shader == nullptr) @@ -159,12 +159,16 @@ void GLVolume::NonManifoldEdges::render() const GUI::Camera& camera = GUI::wxGetApp().plater()->get_camera(); shader->set_uniform("view_model_matrix", camera.get_view_matrix() * m_parent.world_matrix()); shader->set_uniform("projection_matrix", camera.get_projection_matrix()); -#if ENABLE_GL_CORE_PROFILE - const std::array& viewport = camera.get_viewport(); - shader->set_uniform("viewport_size", Vec2d(double(viewport[2]), double(viewport[3]))); - shader->set_uniform("width", 0.5f); - shader->set_uniform("gap_size", 0.0f); -#endif // ENABLE_GL_CORE_PROFILE +#if !SLIC3R_OPENGL_ES + if (GUI::OpenGLManager::get_gl_info().is_core_profile()) { +#endif // !SLIC3R_OPENGL_ES + const std::array& viewport = camera.get_viewport(); + shader->set_uniform("viewport_size", Vec2d(double(viewport[2]), double(viewport[3]))); + shader->set_uniform("width", 0.5f); + shader->set_uniform("gap_size", 0.0f); +#if !SLIC3R_OPENGL_ES + } +#endif // !SLIC3R_OPENGL_ES m_model.set_color(complementary(m_parent.render_color)); m_model.render(); } @@ -749,11 +753,11 @@ void GLVolumeCollection::render(GLVolumeCollection::ERenderType type, bool disab return; GLShaderProgram* sink_shader = GUI::wxGetApp().get_shader("flat"); -#if ENABLE_GL_CORE_PROFILE - GLShaderProgram* edges_shader = GUI::OpenGLManager::get_gl_info().is_core_profile() ? GUI::wxGetApp().get_shader("dashed_thick_lines") : GUI::wxGetApp().get_shader("flat"); +#if SLIC3R_OPENGL_ES + GLShaderProgram* edges_shader = GUI::wxGetApp().get_shader("dashed_lines"); #else - GLShaderProgram* edges_shader = GUI::wxGetApp().get_shader("flat"); -#endif // ENABLE_GL_CORE_PROFILE + GLShaderProgram* edges_shader = GUI::OpenGLManager::get_gl_info().is_core_profile() ? GUI::wxGetApp().get_shader("dashed_thick_lines") : GUI::wxGetApp().get_shader("flat"); +#endif // SLIC3R_OPENGL_ES if (type == ERenderType::Transparent) { glsafe(::glEnable(GL_BLEND)); diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 96666697ee..6d75879ee3 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -465,21 +465,25 @@ void GLCanvas3D::LayersEditing::render_profile(const GLCanvas3D& canvas) m_profile.profile.init_from(std::move(init_data)); } -#if ENABLE_GL_CORE_PROFILE - GLShaderProgram* shader = OpenGLManager::get_gl_info().is_core_profile() ? wxGetApp().get_shader("dashed_thick_lines") : wxGetApp().get_shader("flat"); +#if SLIC3R_OPENGL_ES + GLShaderProgram* shader = wxGetApp().get_shader("dashed_lines"); #else - GLShaderProgram* shader = wxGetApp().get_shader("flat"); -#endif // ENABLE_GL_CORE_PROFILE + GLShaderProgram* 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) { shader->start_using(); shader->set_uniform("view_model_matrix", Transform3d::Identity()); shader->set_uniform("projection_matrix", Transform3d::Identity()); -#if ENABLE_GL_CORE_PROFILE - const std::array& viewport = wxGetApp().plater()->get_camera().get_viewport(); - shader->set_uniform("viewport_size", Vec2d(double(viewport[2]), double(viewport[3]))); - shader->set_uniform("width", 0.25f); - shader->set_uniform("gap_size", 0.0f); -#endif // ENABLE_GL_CORE_PROFILE +#if !SLIC3R_OPENGL_ES + if (OpenGLManager::get_gl_info().is_core_profile()) { +#endif // !SLIC3R_OPENGL_ES + const std::array& viewport = wxGetApp().plater()->get_camera().get_viewport(); + shader->set_uniform("viewport_size", Vec2d(double(viewport[2]), double(viewport[3]))); + shader->set_uniform("width", 0.25f); + shader->set_uniform("gap_size", 0.0f); +#if !SLIC3R_OPENGL_ES + } +#endif // !SLIC3R_OPENGL_ES m_profile.baseline.render(); m_profile.profile.render(); shader->stop_using(); @@ -955,11 +959,16 @@ void GLCanvas3D::SequentialPrintClearance::render() if (!m_evaluating && !m_dragging) m_fill.render(); -#if ENABLE_GL_CORE_PROFILE +#if !SLIC3R_OPENGL_ES if (OpenGLManager::get_gl_info().is_core_profile()) { +#endif // !SLIC3R_OPENGL_ES shader->stop_using(); +#if SLIC3R_OPENGL_ES + shader = wxGetApp().get_shader("dashed_lines"); +#else shader = wxGetApp().get_shader("dashed_thick_lines"); +#endif // SLIC3R_OPENGL_ES if (shader == nullptr) return; @@ -969,10 +978,11 @@ void GLCanvas3D::SequentialPrintClearance::render() shader->set_uniform("viewport_size", Vec2d(double(viewport[2]), double(viewport[3]))); shader->set_uniform("width", 1.0f); shader->set_uniform("gap_size", 0.0f); +#if !SLIC3R_OPENGL_ES } else -#endif // ENABLE_GL_CORE_PROFILE glsafe(::glLineWidth(2.0f)); +#endif // !SLIC3R_OPENGL_ES for (const auto& [id, trafo] : m_instances) { shader->set_uniform("view_model_matrix", camera.get_view_matrix() * trafo); @@ -6172,10 +6182,10 @@ void GLCanvas3D::_render_camera_target() static const float half_length = 5.0f; glsafe(::glDisable(GL_DEPTH_TEST)); -#if ENABLE_GL_CORE_PROFILE +#if !SLIC3R_OPENGL_ES if (!OpenGLManager::get_gl_info().is_core_profile()) -#endif // ENABLE_GL_CORE_PROFILE glsafe(::glLineWidth(2.0f)); +#endif // !SLIC3R_OPENGL_ES const Vec3f& target = wxGetApp().plater()->get_camera().get_target().cast(); m_camera_target.target = target.cast(); @@ -6211,22 +6221,26 @@ void GLCanvas3D::_render_camera_target() } } -#if ENABLE_GL_CORE_PROFILE - GLShaderProgram* shader = OpenGLManager::get_gl_info().is_core_profile() ? wxGetApp().get_shader("dashed_thick_lines") : wxGetApp().get_shader("flat"); +#if SLIC3R_OPENGL_ES + GLShaderProgram* shader = wxGetApp().get_shader("dashed_lines"); #else - GLShaderProgram* shader = wxGetApp().get_shader("flat"); -#endif // ENABLE_GL_CORE_PROFILE + GLShaderProgram* 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) { shader->start_using(); const Camera& camera = wxGetApp().plater()->get_camera(); shader->set_uniform("view_model_matrix", camera.get_view_matrix() * Geometry::translation_transform(m_camera_target.target)); shader->set_uniform("projection_matrix", camera.get_projection_matrix()); -#if ENABLE_GL_CORE_PROFILE - const std::array& viewport = camera.get_viewport(); - shader->set_uniform("viewport_size", Vec2d(double(viewport[2]), double(viewport[3]))); - shader->set_uniform("width", 0.5f); - shader->set_uniform("gap_size", 0.0f); -#endif // ENABLE_GL_CORE_PROFILE +#if !SLIC3R_OPENGL_ES + if (OpenGLManager::get_gl_info().is_core_profile()) { +#endif // !SLIC3R_OPENGL_ES + const std::array& viewport = camera.get_viewport(); + shader->set_uniform("viewport_size", Vec2d(double(viewport[2]), double(viewport[3]))); + shader->set_uniform("width", 0.5f); + shader->set_uniform("gap_size", 0.0f); +#if !SLIC3R_OPENGL_ES + } +#endif // !SLIC3R_OPENGL_ES for (int i = 0; i < 3; ++i) { m_camera_target.axis[i].render(); } diff --git a/src/slic3r/GUI/GLModel.cpp b/src/slic3r/GUI/GLModel.cpp index 606f448cb5..3b714714dc 100644 --- a/src/slic3r/GUI/GLModel.cpp +++ b/src/slic3r/GUI/GLModel.cpp @@ -685,12 +685,16 @@ void GLModel::reset() s_statistics.gpu_memory.vertices.current -= vertices_size_bytes(); #endif // ENABLE_GLMODEL_STATISTICS } -#if ENABLE_GL_CORE_PROFILE - if (m_render_data.vao_id > 0) { - glsafe(::glDeleteVertexArrays(1, &m_render_data.vao_id)); - m_render_data.vao_id = 0; +#if !SLIC3R_OPENGL_ES + if (OpenGLManager::get_gl_info().is_core_profile()) { +#endif // !SLIC3R_OPENGL_ES + if (m_render_data.vao_id > 0) { + glsafe(::glDeleteVertexArrays(1, &m_render_data.vao_id)); + m_render_data.vao_id = 0; + } +#if !SLIC3R_OPENGL_ES } -#endif // ENABLE_GL_CORE_PROFILE +#endif // !SLIC3R_OPENGL_ES m_render_data.vertices_count = 0; m_render_data.indices_count = 0; @@ -760,11 +764,14 @@ void GLModel::render(const std::pair& range) const bool tex_coord = Geometry::has_tex_coord(data.format); const bool extra = Geometry::has_extra(data.format); -#if ENABLE_GL_CORE_PROFILE - if (OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0)) +#if !SLIC3R_OPENGL_ES + if (OpenGLManager::get_gl_info().is_core_profile()) { +#endif // !SLIC3R_OPENGL_ES glsafe(::glBindVertexArray(m_render_data.vao_id)); +#if !SLIC3R_OPENGL_ES + } +#endif // !SLIC3R_OPENGL_ES // the following binding is needed to set the vertex attributes -#endif // ENABLE_GL_CORE_PROFILE glsafe(::glBindBuffer(GL_ARRAY_BUFFER, m_render_data.vbo_id)); int position_id = -1; @@ -803,14 +810,8 @@ void GLModel::render(const std::pair& range) shader->set_uniform("uniform_color", data.color); -#if ENABLE_GL_CORE_PROFILE - if (!OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0)) -#endif // ENABLE_GL_CORE_PROFILE - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_render_data.ibo_id)); + glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_render_data.ibo_id)); glsafe(::glDrawElements(mode, range.second - range.first, index_type, (const void*)(range.first * Geometry::index_stride_bytes(data)))); -#if !ENABLE_GL_CORE_PROFILE - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); -#endif // !ENABLE_GL_CORE_PROFILE if (extra_id != -1) glsafe(::glDisableVertexAttribArray(extra_id)); @@ -822,10 +823,13 @@ void GLModel::render(const std::pair& range) glsafe(::glDisableVertexAttribArray(position_id)); glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); -#if ENABLE_GL_CORE_PROFILE - if (OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0)) +#if !SLIC3R_OPENGL_ES + if (OpenGLManager::get_gl_info().is_core_profile()) { +#endif // !SLIC3R_OPENGL_ES glsafe(::glBindVertexArray(0)); -#endif // ENABLE_GL_CORE_PROFILE +#if !SLIC3R_OPENGL_ES + } +#endif // !SLIC3R_OPENGL_ES #if ENABLE_GLMODEL_STATISTICS ++s_statistics.render_calls; @@ -858,10 +862,13 @@ void GLModel::render_instanced(unsigned int instances_vbo, unsigned int instance return; } -#if ENABLE_GL_CORE_PROFILE - if (OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0)) +#if !SLIC3R_OPENGL_ES + if (OpenGLManager::get_gl_info().is_core_profile()) { +#endif // !SLIC3R_OPENGL_ES glsafe(::glBindVertexArray(m_render_data.vao_id)); -#endif // ENABLE_GL_CORE_PROFILE +#if !SLIC3R_OPENGL_ES + } +#endif // !SLIC3R_OPENGL_ES glsafe(::glBindBuffer(GL_ARRAY_BUFFER, instances_vbo)); const size_t instance_stride = 5 * sizeof(float); @@ -882,9 +889,7 @@ void GLModel::render_instanced(unsigned int instances_vbo, unsigned int instance const bool position = Geometry::has_position(data.format); const bool normal = Geometry::has_normal(data.format); -#if ENABLE_GL_CORE_PROFILE // the following binding is needed to set the vertex attributes -#endif // ENABLE_GL_CORE_PROFILE glsafe(::glBindBuffer(GL_ARRAY_BUFFER, m_render_data.vbo_id)); if (position) { @@ -899,13 +904,7 @@ void GLModel::render_instanced(unsigned int instances_vbo, unsigned int instance shader->set_uniform("uniform_color", data.color); -#if !ENABLE_GL_CORE_PROFILE - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_render_data.ibo_id)); -#endif // !ENABLE_GL_CORE_PROFILE glsafe(::glDrawElementsInstanced(mode, indices_count(), index_type, (const void*)0, instances_count)); -#if !ENABLE_GL_CORE_PROFILE - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); -#endif // !ENABLE_GL_CORE_PROFILE if (normal) glsafe(::glDisableVertexAttribArray(normal_id)); @@ -916,10 +915,13 @@ void GLModel::render_instanced(unsigned int instances_vbo, unsigned int instance glsafe(::glDisableVertexAttribArray(offset_id)); glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); -#if ENABLE_GL_CORE_PROFILE - if (OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0)) +#if !SLIC3R_OPENGL_ES + if (OpenGLManager::get_gl_info().is_core_profile()) { +#endif // !SLIC3R_OPENGL_ES glsafe(::glBindVertexArray(0)); -#endif // ENABLE_GL_CORE_PROFILE +#if !SLIC3R_OPENGL_ES + } +#endif // !SLIC3R_OPENGL_ES #if ENABLE_GLMODEL_STATISTICS ++s_statistics.render_instanced_calls; @@ -939,12 +941,14 @@ bool GLModel::send_to_gpu() return false; } -#if ENABLE_GL_CORE_PROFILE - if (OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0)) { +#if !SLIC3R_OPENGL_ES + if (OpenGLManager::get_gl_info().is_core_profile()) { +#endif // !SLIC3R_OPENGL_ES glsafe(::glGenVertexArrays(1, &m_render_data.vao_id)); glsafe(::glBindVertexArray(m_render_data.vao_id)); +#if !SLIC3R_OPENGL_ES } -#endif // ENABLE_GL_CORE_PROFILE +#endif // !SLIC3R_OPENGL_ES // vertices glsafe(::glGenBuffers(1, &m_render_data.vbo_id)); @@ -985,11 +989,6 @@ bool GLModel::send_to_gpu() glsafe(::glBufferData(GL_ELEMENT_ARRAY_BUFFER, data.indices_size_bytes(), data.indices.data(), GL_STATIC_DRAW)); } -#if ENABLE_GL_CORE_PROFILE - if (!OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0)) -#endif // ENABLE_GL_CORE_PROFILE - glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); - m_render_data.indices_count = indices_count; #if ENABLE_GLMODEL_STATISTICS s_statistics.gpu_memory.indices.current += data.indices_size_bytes(); @@ -997,10 +996,13 @@ bool GLModel::send_to_gpu() #endif // ENABLE_GLMODEL_STATISTICS data.indices = std::vector(); -#if ENABLE_GL_CORE_PROFILE - if (OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0)) +#if !SLIC3R_OPENGL_ES + if (OpenGLManager::get_gl_info().is_core_profile()) { +#endif // !SLIC3R_OPENGL_ES glsafe(::glBindVertexArray(0)); -#endif // ENABLE_GL_CORE_PROFILE +#if !SLIC3R_OPENGL_ES + } +#endif // !SLIC3R_OPENGL_ES return true; } diff --git a/src/slic3r/GUI/GLModel.hpp b/src/slic3r/GUI/GLModel.hpp index dad1128957..13fa5c1048 100644 --- a/src/slic3r/GUI/GLModel.hpp +++ b/src/slic3r/GUI/GLModel.hpp @@ -154,9 +154,7 @@ namespace GUI { struct RenderData { Geometry geometry; -#if ENABLE_GL_CORE_PROFILE unsigned int vao_id{ 0 }; -#endif // ENABLE_GL_CORE_PROFILE unsigned int vbo_id{ 0 }; unsigned int ibo_id{ 0 }; size_t vertices_count{ 0 }; diff --git a/src/slic3r/GUI/GLSelectionRectangle.cpp b/src/slic3r/GUI/GLSelectionRectangle.cpp index a08c090610..3bbbcc6941 100644 --- a/src/slic3r/GUI/GLSelectionRectangle.cpp +++ b/src/slic3r/GUI/GLSelectionRectangle.cpp @@ -76,32 +76,25 @@ namespace GUI { const float top = -2.0f * (get_top() * cnv_inv_height - 0.5f); const float bottom = -2.0f * (get_bottom() * cnv_inv_height - 0.5f); -#if ENABLE_GL_CORE_PROFILE - const bool core_profile = OpenGLManager::get_gl_info().is_core_profile(); - if (!core_profile) -#endif // ENABLE_GL_CORE_PROFILE +#if !SLIC3R_OPENGL_ES + if (!OpenGLManager::get_gl_info().is_core_profile()) glsafe(::glLineWidth(1.5f)); +#endif // !SLIC3R_OPENGL_ES glsafe(::glDisable(GL_DEPTH_TEST)); #if !SLIC3R_OPENGL_ES -#if ENABLE_GL_CORE_PROFILE - if (!core_profile) { -#endif // ENABLE_GL_CORE_PROFILE - glsafe(::glPushAttrib(GL_ENABLE_BIT)); - glsafe(::glLineStipple(4, 0xAAAA)); - glsafe(::glEnable(GL_LINE_STIPPLE)); -#if ENABLE_GL_CORE_PROFILE + if (!OpenGLManager::get_gl_info().is_core_profile()) { + glsafe(::glPushAttrib(GL_ENABLE_BIT)); + glsafe(::glLineStipple(4, 0xAAAA)); + glsafe(::glEnable(GL_LINE_STIPPLE)); } -#endif // ENABLE_GL_CORE_PROFILE #endif // !SLIC3R_OPENGL_ES #if SLIC3R_OPENGL_ES GLShaderProgram* shader = wxGetApp().get_shader("dashed_lines"); -#elif ENABLE_GL_CORE_PROFILE - GLShaderProgram* shader = core_profile ? wxGetApp().get_shader("dashed_thick_lines") : wxGetApp().get_shader("flat"); #else - GLShaderProgram* shader = wxGetApp().get_shader("flat"); + GLShaderProgram* 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) { shader->start_using(); @@ -112,67 +105,76 @@ namespace GUI { m_rectangle.reset(); GLModel::Geometry init_data; -#if ENABLE_GL_CORE_PROFILE || SLIC3R_OPENGL_ES - init_data.format = { GLModel::Geometry::EPrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P4 }; - init_data.reserve_vertices(5); - init_data.reserve_indices(8); -#else - init_data.format = { GLModel::Geometry::EPrimitiveType::LineLoop, GLModel::Geometry::EVertexLayout::P2 }; - init_data.reserve_vertices(4); - init_data.reserve_indices(4); -#endif // ENABLE_GL_CORE_PROFILE || SLIC3R_OPENGL_ES +#if !SLIC3R_OPENGL_ES + if (OpenGLManager::get_gl_info().is_core_profile()) { +#endif // !SLIC3R_OPENGL_ES + init_data.format = { GLModel::Geometry::EPrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P4 }; + init_data.reserve_vertices(5); + init_data.reserve_indices(8); +#if !SLIC3R_OPENGL_ES + } + else { + init_data.format = { GLModel::Geometry::EPrimitiveType::LineLoop, GLModel::Geometry::EVertexLayout::P2 }; + init_data.reserve_vertices(4); + init_data.reserve_indices(4); + } +#endif // !SLIC3R_OPENGL_ES // vertices -#if ENABLE_GL_CORE_PROFILE || SLIC3R_OPENGL_ES - const float width = right - left; - const float height = top - bottom; - float perimeter = 0.0f; +#if !SLIC3R_OPENGL_ES + if (OpenGLManager::get_gl_info().is_core_profile()) { +#endif // !SLIC3R_OPENGL_ES + const float width = right - left; + const float height = top - bottom; + float perimeter = 0.0f; - init_data.add_vertex(Vec4f(left, bottom, 0.0f, perimeter)); - perimeter += width; - init_data.add_vertex(Vec4f(right, bottom, 0.0f, perimeter)); - perimeter += height; - init_data.add_vertex(Vec4f(right, top, 0.0f, perimeter)); - perimeter += width; - init_data.add_vertex(Vec4f(left, top, 0.0f, perimeter)); - perimeter += height; - init_data.add_vertex(Vec4f(left, bottom, 0.0f, perimeter)); + init_data.add_vertex(Vec4f(left, bottom, 0.0f, perimeter)); + perimeter += width; + init_data.add_vertex(Vec4f(right, bottom, 0.0f, perimeter)); + perimeter += height; + init_data.add_vertex(Vec4f(right, top, 0.0f, perimeter)); + perimeter += width; + init_data.add_vertex(Vec4f(left, top, 0.0f, perimeter)); + perimeter += height; + init_data.add_vertex(Vec4f(left, bottom, 0.0f, perimeter)); - // indices - init_data.add_line(0, 1); - init_data.add_line(1, 2); - init_data.add_line(2, 3); - init_data.add_line(3, 4); -#else - init_data.add_vertex(Vec2f(left, bottom)); - init_data.add_vertex(Vec2f(right, bottom)); - init_data.add_vertex(Vec2f(right, top)); - init_data.add_vertex(Vec2f(left, top)); + // indices + init_data.add_line(0, 1); + init_data.add_line(1, 2); + init_data.add_line(2, 3); + init_data.add_line(3, 4); +#if !SLIC3R_OPENGL_ES + } + else { + init_data.add_vertex(Vec2f(left, bottom)); + init_data.add_vertex(Vec2f(right, bottom)); + init_data.add_vertex(Vec2f(right, top)); + init_data.add_vertex(Vec2f(left, top)); - // indices - init_data.add_index(0); - init_data.add_index(1); - init_data.add_index(2); - init_data.add_index(3); -#endif // ENABLE_GL_CORE_PROFILE || SLIC3R_OPENGL_ES + // indices + init_data.add_index(0); + init_data.add_index(1); + init_data.add_index(2); + init_data.add_index(3); + } +#endif // !SLIC3R_OPENGL_ES m_rectangle.init_from(std::move(init_data)); } shader->set_uniform("view_model_matrix", Transform3d::Identity()); shader->set_uniform("projection_matrix", Transform3d::Identity()); -#if SLIC3R_OPENGL_ES - shader->set_uniform("dash_size", 0.01f); - shader->set_uniform("gap_size", 0.0075f); -#elif ENABLE_GL_CORE_PROFILE - if (core_profile) { - const std::array& viewport = wxGetApp().plater()->get_camera().get_viewport(); - shader->set_uniform("viewport_size", Vec2d(double(viewport[2]), double(viewport[3]))); - shader->set_uniform("width", 0.25f); - shader->set_uniform("dash_size", 0.01f); - shader->set_uniform("gap_size", 0.0075f); +#if !SLIC3R_OPENGL_ES + if (OpenGLManager::get_gl_info().is_core_profile()) { +#endif // !SLIC3R_OPENGL_ES + const std::array& viewport = wxGetApp().plater()->get_camera().get_viewport(); + shader->set_uniform("viewport_size", Vec2d(double(viewport[2]), double(viewport[3]))); + shader->set_uniform("width", 0.25f); + shader->set_uniform("dash_size", 0.01f); + shader->set_uniform("gap_size", 0.0075f); +#if !SLIC3R_OPENGL_ES } -#endif // SLIC3R_OPENGL_ES +#endif // !SLIC3R_OPENGL_ES m_rectangle.set_color(ColorRGBA((m_state == EState::Select) ? 0.3f : 1.0f, (m_state == EState::Select) ? 1.0f : 0.3f, 0.3f, 1.0f)); m_rectangle.render(); @@ -180,10 +182,8 @@ namespace GUI { } #if !SLIC3R_OPENGL_ES -#if ENABLE_GL_CORE_PROFILE - if (!core_profile) -#endif // ENABLE_GL_CORE_PROFILE - glsafe(::glPopAttrib()); + if (!OpenGLManager::get_gl_info().is_core_profile()) + glsafe(::glPopAttrib()); #endif // !SLIC3R_OPENGL_ES } diff --git a/src/slic3r/GUI/GLShadersManager.cpp b/src/slic3r/GUI/GLShadersManager.cpp index 68266faca7..a5221f8b0a 100644 --- a/src/slic3r/GUI/GLShadersManager.cpp +++ b/src/slic3r/GUI/GLShadersManager.cpp @@ -7,9 +7,9 @@ #include "GLShadersManager.hpp" #include "3DScene.hpp" #include "GUI_App.hpp" -#if ENABLE_GL_CORE_PROFILE +#if !SLIC3R_OPENGL_ES #include "OpenGLManager.hpp" -#endif // ENABLE_GL_CORE_PROFILE +#endif // !SLIC3R_OPENGL_ES #include #include @@ -60,7 +60,7 @@ std::pair GLShadersManager::init() #if SLIC3R_OPENGL_ES // used to render dashed lines valid &= append_shader("dashed_lines", { prefix + "dashed_lines.vs", prefix + "dashed_lines.fs" }); -#elif ENABLE_GL_CORE_PROFILE +#else if (GUI::OpenGLManager::get_gl_info().is_core_profile()) // used to render thick and/or dashed lines valid &= append_shader("dashed_thick_lines", { prefix + "dashed_thick_lines.vs", prefix + "dashed_thick_lines.fs", prefix + "dashed_thick_lines.gs" }); diff --git a/src/slic3r/GUI/GLTexture.cpp b/src/slic3r/GUI/GLTexture.cpp index 14918012f6..80c210ae4b 100644 --- a/src/slic3r/GUI/GLTexture.cpp +++ b/src/slic3r/GUI/GLTexture.cpp @@ -336,12 +336,6 @@ void GLTexture::render_sub_texture(unsigned int tex_id, float left, float right, { glsafe(::glEnable(GL_BLEND)); glsafe(::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); - -#if !ENABLE_GL_CORE_PROFILE && !SLIC3R_OPENGL_ES - glsafe(::glEnable(GL_TEXTURE_2D)); - glsafe(::glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE)); -#endif // !ENABLE_GL_CORE_PROFILE && !SLIC3R_OPENGL_ES - glsafe(::glBindTexture(GL_TEXTURE_2D, (GLuint)tex_id)); GLModel::Geometry init_data; @@ -372,10 +366,6 @@ void GLTexture::render_sub_texture(unsigned int tex_id, float left, float right, } glsafe(::glBindTexture(GL_TEXTURE_2D, 0)); - -#if !ENABLE_GL_CORE_PROFILE && !SLIC3R_OPENGL_ES - glsafe(::glDisable(GL_TEXTURE_2D)); -#endif // !ENABLE_GL_CORE_PROFILE && !SLIC3R_OPENGL_ES glsafe(::glDisable(GL_BLEND)); } diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 9fb30fbed8..cd23fdc27c 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -887,12 +887,12 @@ std::string GUI_App::get_gl_info(bool for_github) wxGLContext* GUI_App::init_glcontext(wxGLCanvas& canvas) { -#if ENABLE_GL_CORE_PROFILE +#if SLIC3R_OPENGL_ES + return m_opengl_mgr.init_glcontext(canvas); +#else return m_opengl_mgr.init_glcontext(canvas, init_params != nullptr ? init_params->opengl_version : std::make_pair(0, 0), init_params != nullptr ? init_params->opengl_compatibiity_profile : false, init_params != nullptr ? init_params->opengl_debug : false); -#else - return m_opengl_mgr.init_glcontext(canvas); -#endif // ENABLE_GL_CORE_PROFILE +#endif // SLIC3R_OPENGL_ES } bool GUI_App::init_opengl() diff --git a/src/slic3r/GUI/GUI_Init.hpp b/src/slic3r/GUI/GUI_Init.hpp index 2fb0429f05..1090b696f4 100644 --- a/src/slic3r/GUI/GUI_Init.hpp +++ b/src/slic3r/GUI/GUI_Init.hpp @@ -33,11 +33,11 @@ struct GUI_InitParams bool start_downloader; bool delete_after_load; std::string download_url; -#if ENABLE_GL_CORE_PROFILE +#if !SLIC3R_OPENGL_ES std::pair opengl_version; bool opengl_debug; bool opengl_compatibiity_profile; -#endif // ENABLE_GL_CORE_PROFILE +#endif // !SLIC3R_OPENGL_ES #if ENABLE_OPENGL_AUTO_AA_SAMPLES bool opengl_aa; #endif // ENABLE_OPENGL_AUTO_AA_SAMPLES diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp index c5b29d0bd5..120c007e73 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMeasure.cpp @@ -1168,24 +1168,29 @@ void GLGizmoMeasure::render_dimensioning() const Transform3d ss_to_ndc_matrix = TransformHelper::ndc_to_ss_matrix_inverse(viewport); -#if ENABLE_GL_CORE_PROFILE +#if !SLIC3R_OPENGL_ES if (OpenGLManager::get_gl_info().is_core_profile()) { +#endif // !SLIC3R_OPENGL_ES shader->stop_using(); +#if SLIC3R_OPENGL_ES + shader = wxGetApp().get_shader("dashed_lines"); +#else shader = wxGetApp().get_shader("dashed_thick_lines"); +#endif // SLIC3R_OPENGL_ES if (shader == nullptr) return; shader->start_using(); shader->set_uniform("projection_matrix", Transform3d::Identity()); - const std::array& viewport = camera.get_viewport(); shader->set_uniform("viewport_size", Vec2d(double(viewport[2]), double(viewport[3]))); shader->set_uniform("width", 1.0f); shader->set_uniform("gap_size", 0.0f); +#if !SLIC3R_OPENGL_ES } else -#endif // ENABLE_GL_CORE_PROFILE glsafe(::glLineWidth(2.0f)); +#endif // !SLIC3R_OPENGL_ES // stem shader->set_uniform("view_model_matrix", overlap ? @@ -1194,8 +1199,9 @@ void GLGizmoMeasure::render_dimensioning() m_dimensioning.line.set_color(ColorRGBA::WHITE()); m_dimensioning.line.render(); -#if ENABLE_GL_CORE_PROFILE +#if !SLIC3R_OPENGL_ES if (OpenGLManager::get_gl_info().is_core_profile()) { +#endif // !SLIC3R_OPENGL_ES shader->stop_using(); shader = wxGetApp().get_shader("flat"); @@ -1203,10 +1209,11 @@ void GLGizmoMeasure::render_dimensioning() return; shader->start_using(); +#if !SLIC3R_OPENGL_ES } else -#endif // ENABLE_GL_CORE_PROFILE glsafe(::glLineWidth(1.0f)); +#endif // !SLIC3R_OPENGL_ES // arrow 1 shader->set_uniform("view_model_matrix", overlap ? @@ -1462,11 +1469,16 @@ void GLGizmoMeasure::render_dimensioning() } const Camera& camera = wxGetApp().plater()->get_camera(); -#if ENABLE_GL_CORE_PROFILE +#if !SLIC3R_OPENGL_ES if (OpenGLManager::get_gl_info().is_core_profile()) { +#endif // !SLIC3R_OPENGL_ES shader->stop_using(); +#if SLIC3R_OPENGL_ES + shader = wxGetApp().get_shader("dashed_lines"); +#else shader = wxGetApp().get_shader("dashed_thick_lines"); +#endif // SLIC3R_OPENGL_ES if (shader == nullptr) return; @@ -1476,18 +1488,20 @@ void GLGizmoMeasure::render_dimensioning() shader->set_uniform("viewport_size", Vec2d(double(viewport[2]), double(viewport[3]))); shader->set_uniform("width", 1.0f); shader->set_uniform("gap_size", 0.0f); +#if !SLIC3R_OPENGL_ES } else -#endif // ENABLE_GL_CORE_PROFILE - glsafe(::glLineWidth(2.0f)); + glsafe(::glLineWidth(2.0f)); +#endif // !SLIC3R_OPENGL_ES // arc shader->set_uniform("projection_matrix", camera.get_projection_matrix()); shader->set_uniform("view_model_matrix", camera.get_view_matrix() * Geometry::translation_transform(center)); m_dimensioning.arc.render(); -#if ENABLE_GL_CORE_PROFILE +#if !SLIC3R_OPENGL_ES if (OpenGLManager::get_gl_info().is_core_profile()) { +#endif // !SLIC3R_OPENGL_ES shader->stop_using(); shader = wxGetApp().get_shader("flat"); @@ -1495,10 +1509,11 @@ void GLGizmoMeasure::render_dimensioning() return; shader->start_using(); +#if !SLIC3R_OPENGL_ES } else -#endif // ENABLE_GL_CORE_PROFILE - glsafe(::glLineWidth(1.0f)); + glsafe(::glLineWidth(1.0f)); +#endif // !SLIC3R_OPENGL_ES // arrows auto render_arrow = [this, shader, &camera, &normal, ¢er, &e1_unit, draw_radius, step, resolution](unsigned int endpoint_id) { diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.cpp index b6c72c0b44..ce8c925a8a 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.cpp @@ -664,12 +664,16 @@ void GLMmSegmentationGizmo3DScene::release_geometry() { glsafe(::glDeleteBuffers(1, &triangle_indices_VBO_id)); triangle_indices_VBO_id = 0; } -#if ENABLE_GL_CORE_PROFILE - if (this->vertices_VAO_id > 0) { - glsafe(::glDeleteVertexArrays(1, &this->vertices_VAO_id)); - this->vertices_VAO_id = 0; +#if !SLIC3R_OPENGL_ES + if (OpenGLManager::get_gl_info().is_core_profile()) { +#endif // !SLIC3R_OPENGL_ES + if (this->vertices_VAO_id > 0) { + glsafe(::glDeleteVertexArrays(1, &this->vertices_VAO_id)); + this->vertices_VAO_id = 0; + } +#if !SLIC3R_OPENGL_ES } -#endif // ENABLE_GL_CORE_PROFILE +#endif // !SLIC3R_OPENGL_ES this->clear(); } @@ -678,10 +682,13 @@ void GLMmSegmentationGizmo3DScene::render(size_t triangle_indices_idx) const { assert(triangle_indices_idx < this->triangle_indices_VBO_ids.size()); assert(this->triangle_indices_sizes.size() == this->triangle_indices_VBO_ids.size()); -#if ENABLE_GL_CORE_PROFILE - if (OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0)) +#if !SLIC3R_OPENGL_ES + if (OpenGLManager::get_gl_info().is_core_profile()) { +#endif // !SLIC3R_OPENGL_ES assert(this->vertices_VAO_id != 0); -#endif // ENABLE_GL_CORE_PROFILE +#if !SLIC3R_OPENGL_ES + } +#endif // !SLIC3R_OPENGL_ES assert(this->vertices_VBO_id != 0); assert(this->triangle_indices_VBO_ids[triangle_indices_idx] != 0); @@ -689,11 +696,14 @@ void GLMmSegmentationGizmo3DScene::render(size_t triangle_indices_idx) const if (shader == nullptr) return; -#if ENABLE_GL_CORE_PROFILE - if (OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0)) +#if !SLIC3R_OPENGL_ES + if (OpenGLManager::get_gl_info().is_core_profile()) { +#endif // !SLIC3R_OPENGL_ES glsafe(::glBindVertexArray(this->vertices_VAO_id)); +#if !SLIC3R_OPENGL_ES + } +#endif // !SLIC3R_OPENGL_ES // the following binding is needed to set the vertex attributes -#endif // ENABLE_GL_CORE_PROFILE glsafe(::glBindBuffer(GL_ARRAY_BUFFER, this->vertices_VBO_id)); const GLint position_id = shader->get_attrib_location("v_position"); if (position_id != -1) { @@ -713,25 +723,34 @@ void GLMmSegmentationGizmo3DScene::render(size_t triangle_indices_idx) const glsafe(::glDisableVertexAttribArray(position_id)); glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); -#if ENABLE_GL_CORE_PROFILE - if (OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0)) +#if !SLIC3R_OPENGL_ES + if (OpenGLManager::get_gl_info().is_core_profile()) { +#endif // !SLIC3R_OPENGL_ES glsafe(::glBindVertexArray(0)); -#endif // ENABLE_GL_CORE_PROFILE +#if !SLIC3R_OPENGL_ES + } +#endif // !SLIC3R_OPENGL_ES } void GLMmSegmentationGizmo3DScene::finalize_vertices() { -#if ENABLE_GL_CORE_PROFILE +#if !SLIC3R_OPENGL_ES + if (OpenGLManager::get_gl_info().is_core_profile()) { +#endif // !SLIC3R_OPENGL_ES assert(this->vertices_VAO_id == 0); -#endif // ENABLE_GL_CORE_PROFILE +#if !SLIC3R_OPENGL_ES + } +#endif // !SLIC3R_OPENGL_ES assert(this->vertices_VBO_id == 0); if (!this->vertices.empty()) { -#if ENABLE_GL_CORE_PROFILE - if (OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0)) { +#if !SLIC3R_OPENGL_ES + if (OpenGLManager::get_gl_info().is_core_profile()) { +#endif // !SLIC3R_OPENGL_ES glsafe(::glGenVertexArrays(1, &this->vertices_VAO_id)); glsafe(::glBindVertexArray(this->vertices_VAO_id)); +#if !SLIC3R_OPENGL_ES } -#endif // ENABLE_GL_CORE_PROFILE +#endif // !SLIC3R_OPENGL_ES glsafe(::glGenBuffers(1, &this->vertices_VBO_id)); glsafe(::glBindBuffer(GL_ARRAY_BUFFER, this->vertices_VBO_id)); @@ -739,10 +758,13 @@ void GLMmSegmentationGizmo3DScene::finalize_vertices() glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); this->vertices.clear(); -#if ENABLE_GL_CORE_PROFILE - if (OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0)) - glsafe(::glBindVertexArray(0)); -#endif // ENABLE_GL_CORE_PROFILE +#if !SLIC3R_OPENGL_ES + if (OpenGLManager::get_gl_info().is_core_profile()) { +#endif // !SLIC3R_OPENGL_ES + glsafe(::glBindVertexArray(0)); +#if !SLIC3R_OPENGL_ES + } +#endif // !SLIC3R_OPENGL_ES } } @@ -751,7 +773,7 @@ void GLMmSegmentationGizmo3DScene::finalize_triangle_indices() assert(std::all_of(triangle_indices_VBO_ids.cbegin(), triangle_indices_VBO_ids.cend(), [](const auto &ti_VBO_id) { return ti_VBO_id == 0; })); assert(this->triangle_indices.size() == this->triangle_indices_VBO_ids.size()); - for (size_t buffer_idx = 0; buffer_idx < this->triangle_indices.size(); ++buffer_idx) + for (size_t buffer_idx = 0; buffer_idx < this->triangle_indices.size(); ++buffer_idx) { if (!this->triangle_indices[buffer_idx].empty()) { glsafe(::glGenBuffers(1, &this->triangle_indices_VBO_ids[buffer_idx])); glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this->triangle_indices_VBO_ids[buffer_idx])); @@ -759,6 +781,7 @@ void GLMmSegmentationGizmo3DScene::finalize_triangle_indices() glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); this->triangle_indices[buffer_idx].clear(); } + } } } // namespace Slic3r diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.hpp b/src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.hpp index 23e8318c37..40832c816b 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.hpp @@ -61,9 +61,7 @@ public: // IDs of the Vertex Array Objects, into which the geometry has been loaded. // Zero if the VBOs are not sent to GPU yet. -#if ENABLE_GL_CORE_PROFILE unsigned int vertices_VAO_id{ 0 }; -#endif // ENABLE_GL_CORE_PROFILE unsigned int vertices_VBO_id{ 0 }; std::vector triangle_indices_VBO_ids; }; diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMove.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMove.cpp index 402b436701..835cc59342 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMove.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMove.cpp @@ -134,10 +134,10 @@ void GLGizmoMove3D::on_render() m_grabbers[2].center = { 0.0, 0.0, half_box_size.z() + Offset }; m_grabbers[2].color = AXES_COLOR[2]; -#if ENABLE_GL_CORE_PROFILE +#if !SLIC3R_OPENGL_ES if (!OpenGLManager::get_gl_info().is_core_profile()) -#endif // ENABLE_GL_CORE_PROFILE glsafe(::glLineWidth((m_hover_id != -1) ? 2.0f : 1.5f)); +#endif // !SLIC3R_OPENGL_ES auto render_grabber_connection = [this, &zero](unsigned int id) { if (m_grabbers[id].enabled) { @@ -166,22 +166,26 @@ void GLGizmoMove3D::on_render() }; if (m_hover_id == -1) { -#if ENABLE_GL_CORE_PROFILE - GLShaderProgram* shader = OpenGLManager::get_gl_info().is_core_profile() ? wxGetApp().get_shader("dashed_thick_lines") : wxGetApp().get_shader("flat"); +#if SLIC3R_OPENGL_ES + GLShaderProgram* shader = wxGetApp().get_shader("dashed_lines"); #else - GLShaderProgram* shader = wxGetApp().get_shader("flat"); -#endif // ENABLE_GL_CORE_PROFILE + GLShaderProgram* 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) { shader->start_using(); const Camera& camera = wxGetApp().plater()->get_camera(); shader->set_uniform("view_model_matrix", camera.get_view_matrix() * base_matrix); shader->set_uniform("projection_matrix", camera.get_projection_matrix()); -#if ENABLE_GL_CORE_PROFILE - const std::array& viewport = camera.get_viewport(); - shader->set_uniform("viewport_size", Vec2d(double(viewport[2]), double(viewport[3]))); - shader->set_uniform("width", 0.25f); - shader->set_uniform("gap_size", 0.0f); -#endif // ENABLE_GL_CORE_PROFILE +#if !SLIC3R_OPENGL_ES + if (OpenGLManager::get_gl_info().is_core_profile()) { +#endif // !SLIC3R_OPENGL_ES + const std::array& viewport = camera.get_viewport(); + shader->set_uniform("viewport_size", Vec2d(double(viewport[2]), double(viewport[3]))); + shader->set_uniform("width", 0.25f); + shader->set_uniform("gap_size", 0.0f); +#if !SLIC3R_OPENGL_ES + } +#endif // !SLIC3R_OPENGL_ES // draw axes for (unsigned int i = 0; i < 3; ++i) { @@ -196,23 +200,27 @@ void GLGizmoMove3D::on_render() } else { // draw axis -#if ENABLE_GL_CORE_PROFILE - GLShaderProgram* shader = OpenGLManager::get_gl_info().is_core_profile() ? wxGetApp().get_shader("dashed_thick_lines") : wxGetApp().get_shader("flat"); +#if SLIC3R_OPENGL_ES + GLShaderProgram* shader = wxGetApp().get_shader("dashed_lines"); #else - GLShaderProgram* shader = wxGetApp().get_shader("flat"); -#endif // ENABLE_GL_CORE_PROFILE + GLShaderProgram* 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) { shader->start_using(); const Camera& camera = wxGetApp().plater()->get_camera(); shader->set_uniform("view_model_matrix", camera.get_view_matrix()* base_matrix); shader->set_uniform("projection_matrix", camera.get_projection_matrix()); -#if ENABLE_GL_CORE_PROFILE - const std::array& viewport = camera.get_viewport(); - shader->set_uniform("viewport_size", Vec2d(double(viewport[2]), double(viewport[3]))); - shader->set_uniform("width", 0.5f); - shader->set_uniform("gap_size", 0.0f); -#endif // ENABLE_GL_CORE_PROFILE +#if !SLIC3R_OPENGL_ES + if (OpenGLManager::get_gl_info().is_core_profile()) { +#endif /// !SLIC3R_OPENGL_ES + const std::array& viewport = camera.get_viewport(); + shader->set_uniform("viewport_size", Vec2d(double(viewport[2]), double(viewport[3]))); + shader->set_uniform("width", 0.5f); + shader->set_uniform("gap_size", 0.0f); +#if !SLIC3R_OPENGL_ES + } +#endif // !SLIC3R_OPENGL_ES render_grabber_connection(m_hover_id); shader->stop_using(); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoPainterBase.cpp b/src/slic3r/GUI/Gizmos/GLGizmoPainterBase.cpp index 4b1ca58325..29f0b134b6 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoPainterBase.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoPainterBase.cpp @@ -158,103 +158,115 @@ void GLGizmoPainterBase::render_cursor_circle() const float cnv_inv_height = 1.0f / cnv_height; const Vec2d center = m_parent.get_local_mouse_position(); -#if ENABLE_GL_CORE_PROFILE || SLIC3R_OPENGL_ES const float zoom = float(wxGetApp().plater()->get_camera().get_zoom()); const float radius = m_cursor_radius * zoom; -#else - const float radius = m_cursor_radius * float(wxGetApp().plater()->get_camera().get_zoom()); -#endif // ENABLE_GL_CORE_PROFILE || SLIC3R_OPENGL_ES -#if ENABLE_GL_CORE_PROFILE +#if !SLIC3R_OPENGL_ES if (!OpenGLManager::get_gl_info().is_core_profile()) -#endif // ENABLE_GL_CORE_PROFILE glsafe(::glLineWidth(1.5f)); +#endif // !SLIC3R_OPENGL_ES + glsafe(::glDisable(GL_DEPTH_TEST)); -#if !ENABLE_GL_CORE_PROFILE && !SLIC3R_OPENGL_ES - glsafe(::glPushAttrib(GL_ENABLE_BIT)); - glsafe(::glLineStipple(4, 0xAAAA)); - glsafe(::glEnable(GL_LINE_STIPPLE)); -#endif // !ENABLE_GL_CORE_PROFILE && !SLIC3R_OPENGL_ES +#if !SLIC3R_OPENGL_ES + if (!OpenGLManager::get_gl_info().is_core_profile()) { + glsafe(::glPushAttrib(GL_ENABLE_BIT)); + glsafe(::glLineStipple(4, 0xAAAA)); + glsafe(::glEnable(GL_LINE_STIPPLE)); + } +#endif // !SLIC3R_OPENGL_ES -#if ENABLE_GL_CORE_PROFILE || SLIC3R_OPENGL_ES - if (!m_circle.is_initialized() || std::abs(m_old_cursor_radius - radius) > EPSILON) { - m_old_cursor_radius = radius; - m_circle.reset(); -#else if (!m_circle.is_initialized() || !m_old_center.isApprox(center) || std::abs(m_old_cursor_radius - radius) > EPSILON) { m_old_cursor_radius = radius; m_old_center = center; m_circle.reset(); -#endif // ENABLE_GL_CORE_PROFILE || SLIC3R_OPENGL_ES GLModel::Geometry init_data; -#if ENABLE_GL_CORE_PROFILE || SLIC3R_OPENGL_ES - const unsigned int StepsCount = (unsigned int)(2 * (4 + int(252 * (zoom - 1.0f) / (250.0f - 1.0f)))); - const float StepSize = 2.0f * float(PI) / float(StepsCount); - init_data.format = { GLModel::Geometry::EPrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P2 }; -#else - static const unsigned int StepsCount = 32; - static const float StepSize = 2.0f * float(PI) / float(StepsCount); - init_data.format = { GLModel::Geometry::EPrimitiveType::LineLoop, GLModel::Geometry::EVertexLayout::P2 }; -#endif // ENABLE_GL_CORE_PROFILE || SLIC3R_OPENGL_ES + unsigned int steps_count = 0; +#if !SLIC3R_OPENGL_ES + if (OpenGLManager::get_gl_info().is_core_profile()) { +#endif // !SLIC3R_OPENGL_ES + steps_count = (unsigned int)(2 * (4 + int(252 * (zoom - 1.0f) / (250.0f - 1.0f)))); + init_data.format = { GLModel::Geometry::EPrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P2 }; +#if !SLIC3R_OPENGL_ES + } + else { + steps_count = 32; + init_data.format = { GLModel::Geometry::EPrimitiveType::LineLoop, GLModel::Geometry::EVertexLayout::P2 }; + } +#endif // !SLIC3R_OPENGL_ES + const float step_size = 2.0f * float(PI) / float(steps_count); init_data.color = { 0.0f, 1.0f, 0.3f, 1.0f }; - init_data.reserve_vertices(StepsCount); - init_data.reserve_indices(StepsCount); + init_data.reserve_vertices(steps_count); + init_data.reserve_indices(steps_count); // vertices + indices - for (unsigned int i = 0; i < StepsCount; ++i) { -#if ENABLE_GL_CORE_PROFILE || SLIC3R_OPENGL_ES - if (i % 2 != 0) continue; + for (unsigned int i = 0; i < steps_count; ++i) { +#if !SLIC3R_OPENGL_ES + if (OpenGLManager::get_gl_info().is_core_profile()) { +#endif // !SLIC3R_OPENGL_ES + if (i % 2 != 0) continue; - const float angle_i = float(i) * StepSize; - const unsigned int j = (i + 1) % StepsCount; - const float angle_j = float(j) * StepSize; - const Vec2d v_i(::cos(angle_i), ::sin(angle_i)); - const Vec2d v_j(::cos(angle_j), ::sin(angle_j)); - init_data.add_vertex(Vec2f(v_i.x(), v_i.y())); - init_data.add_vertex(Vec2f(v_j.x(), v_j.y())); - const size_t vcount = init_data.vertices_count(); - init_data.add_line(vcount - 2, vcount - 1); -#else - const float angle = float(i) * StepSize; - init_data.add_vertex(Vec2f(2.0f * ((center.x() + ::cos(angle) * radius) * cnv_inv_width - 0.5f), - -2.0f * ((center.y() + ::sin(angle) * radius) * cnv_inv_height - 0.5f))); - init_data.add_index(i); -#endif // ENABLE_GL_CORE_PROFILE || SLIC3R_OPENGL_ES + const float angle_i = float(i) * step_size; + const unsigned int j = (i + 1) % steps_count; + const float angle_j = float(j) * step_size; + const Vec2d v_i(::cos(angle_i), ::sin(angle_i)); + const Vec2d v_j(::cos(angle_j), ::sin(angle_j)); + init_data.add_vertex(Vec2f(v_i.x(), v_i.y())); + init_data.add_vertex(Vec2f(v_j.x(), v_j.y())); + const size_t vcount = init_data.vertices_count(); + init_data.add_line(vcount - 2, vcount - 1); +#if !SLIC3R_OPENGL_ES + } + else { + const float angle = float(i) * step_size; + init_data.add_vertex(Vec2f(2.0f * ((center.x() + ::cos(angle) * radius) * cnv_inv_width - 0.5f), + -2.0f * ((center.y() + ::sin(angle) * radius) * cnv_inv_height - 0.5f))); + init_data.add_index(i); + } +#endif // !SLIC3R_OPENGL_ES } m_circle.init_from(std::move(init_data)); } -#if ENABLE_GL_CORE_PROFILE - GLShaderProgram* shader = OpenGLManager::get_gl_info().is_core_profile() ? wxGetApp().get_shader("dashed_thick_lines") : wxGetApp().get_shader("flat"); +#if SLIC3R_OPENGL_ES + GLShaderProgram* shader = wxGetApp().get_shader("dashed_lines"); #else - GLShaderProgram* shader = GUI::wxGetApp().get_shader("flat"); -#endif // ENABLE_GL_CORE_PROFILE + GLShaderProgram* 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) { shader->start_using(); -#if ENABLE_GL_CORE_PROFILE || SLIC3R_OPENGL_ES - const Transform3d view_model_matrix = Geometry::translation_transform(Vec3d(2.0f * (center.x() * cnv_inv_width - 0.5f), -2.0f * (center.y() * cnv_inv_height - 0.5f), 0.0)) * - Geometry::scale_transform(Vec3d(2.0f * radius * cnv_inv_width, 2.0f * radius * cnv_inv_height, 1.0f)); - shader->set_uniform("view_model_matrix", view_model_matrix); -#else - shader->set_uniform("view_model_matrix", Transform3d::Identity()); -#endif // ENABLE_GL_CORE_PROFILE || SLIC3R_OPENGL_ES +#if !SLIC3R_OPENGL_ES + if (OpenGLManager::get_gl_info().is_core_profile()) { +#endif // !SLIC3R_OPENGL_ES + const Transform3d view_model_matrix = Geometry::translation_transform(Vec3d(2.0f * (center.x() * cnv_inv_width - 0.5f), -2.0f * (center.y() * cnv_inv_height - 0.5f), 0.0)) * + Geometry::scale_transform(Vec3d(2.0f * radius * cnv_inv_width, 2.0f * radius * cnv_inv_height, 1.0f)); + shader->set_uniform("view_model_matrix", view_model_matrix); +#if !SLIC3R_OPENGL_ES + } + else + shader->set_uniform("view_model_matrix", Transform3d::Identity()); +#endif // !SLIC3R_OPENGL_ES shader->set_uniform("projection_matrix", Transform3d::Identity()); -#if ENABLE_GL_CORE_PROFILE - const std::array& viewport = wxGetApp().plater()->get_camera().get_viewport(); - shader->set_uniform("viewport_size", Vec2d(double(viewport[2]), double(viewport[3]))); - shader->set_uniform("width", 0.25f); - shader->set_uniform("gap_size", 0.0f); -#endif // ENABLE_GL_CORE_PROFILE +#if !SLIC3R_OPENGL_ES + if (OpenGLManager::get_gl_info().is_core_profile()) { +#endif // !SLIC3R_OPENGL_ES + const std::array& viewport = wxGetApp().plater()->get_camera().get_viewport(); + shader->set_uniform("viewport_size", Vec2d(double(viewport[2]), double(viewport[3]))); + shader->set_uniform("width", 0.25f); + shader->set_uniform("gap_size", 0.0f); +#if !SLIC3R_OPENGL_ES + } +#endif // !SLIC3R_OPENGL_ES m_circle.render(); shader->stop_using(); } -#if !ENABLE_GL_CORE_PROFILE && !SLIC3R_OPENGL_ES - glsafe(::glPopAttrib()); -#endif // !ENABLE_GL_CORE_PROFILE && !SLIC3R_OPENGL_ES +#if !SLIC3R_OPENGL_ES + if (!OpenGLManager::get_gl_info().is_core_profile()) + glsafe(::glPopAttrib()); +#endif // !SLIC3R_OPENGL_ES glsafe(::glEnable(GL_DEPTH_TEST)); } diff --git a/src/slic3r/GUI/Gizmos/GLGizmoPainterBase.hpp b/src/slic3r/GUI/Gizmos/GLGizmoPainterBase.hpp index 7b65ef91cb..db974205fb 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoPainterBase.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoPainterBase.hpp @@ -154,9 +154,7 @@ protected: float m_highlight_by_angle_threshold_deg = 0.f; GLModel m_circle; -#if !ENABLE_GL_CORE_PROFILE Vec2d m_old_center{ Vec2d::Zero() }; -#endif // !ENABLE_GL_CORE_PROFILE float m_old_cursor_radius{ 0.0f }; static constexpr float SmartFillAngleMin = 0.0f; diff --git a/src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp b/src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp index 72ca3e3cf9..cf220dc206 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp @@ -153,16 +153,16 @@ void GLGizmoRotate::on_render() m_grabbers.front().matrix = local_transform(selection); -#if ENABLE_GL_CORE_PROFILE +#if !SLIC3R_OPENGL_ES if (!OpenGLManager::get_gl_info().is_core_profile()) -#endif // ENABLE_GL_CORE_PROFILE glsafe(::glLineWidth((m_hover_id != -1) ? 2.0f : 1.5f)); +#endif // !SLIC3R_OPENGL_ES -#if ENABLE_GL_CORE_PROFILE - GLShaderProgram* shader = OpenGLManager::get_gl_info().is_core_profile() ? wxGetApp().get_shader("dashed_thick_lines") : wxGetApp().get_shader("flat"); +#if SLIC3R_OPENGL_ES + GLShaderProgram* shader = wxGetApp().get_shader("dashed_lines"); #else - GLShaderProgram* shader = wxGetApp().get_shader("flat"); -#endif // ENABLE_GL_CORE_PROFILE + GLShaderProgram* 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) { shader->start_using(); @@ -170,12 +170,16 @@ void GLGizmoRotate::on_render() const Transform3d view_model_matrix = camera.get_view_matrix() * m_grabbers.front().matrix; shader->set_uniform("view_model_matrix", view_model_matrix); shader->set_uniform("projection_matrix", camera.get_projection_matrix()); -#if ENABLE_GL_CORE_PROFILE - const std::array& viewport = camera.get_viewport(); - shader->set_uniform("viewport_size", Vec2d(double(viewport[2]), double(viewport[3]))); - shader->set_uniform("width", 0.25f); - shader->set_uniform("gap_size", 0.0f); -#endif // ENABLE_GL_CORE_PROFILE +#if !SLIC3R_OPENGL_ES + if (OpenGLManager::get_gl_info().is_core_profile()) { +#endif // !SLIC3R_OPENGL_ES + const std::array& viewport = camera.get_viewport(); + shader->set_uniform("viewport_size", Vec2d(double(viewport[2]), double(viewport[3]))); + shader->set_uniform("width", 0.25f); + shader->set_uniform("gap_size", 0.0f); +#if !SLIC3R_OPENGL_ES + } +#endif // !SLIC3R_OPENGL_ES const bool radius_changed = std::abs(m_old_radius - m_radius) > EPSILON; m_old_radius = m_radius; diff --git a/src/slic3r/GUI/Gizmos/GLGizmoScale.cpp b/src/slic3r/GUI/Gizmos/GLGizmoScale.cpp index 3254cc4219..a414296a57 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoScale.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoScale.cpp @@ -164,31 +164,35 @@ void GLGizmoScale3D::on_render() update_render_data(); -#if ENABLE_GL_CORE_PROFILE +#if !SLIC3R_OPENGL_ES if (!OpenGLManager::get_gl_info().is_core_profile()) -#endif // ENABLE_GL_CORE_PROFILE glsafe(::glLineWidth((m_hover_id != -1) ? 2.0f : 1.5f)); +#endif // !SLIC3R_OPENGL_ES const float grabber_mean_size = (float)((m_bounding_box.size().x() + m_bounding_box.size().y() + m_bounding_box.size().z()) / 3.0); if (m_hover_id == -1) { // draw connections -#if ENABLE_GL_CORE_PROFILE - GLShaderProgram* shader = OpenGLManager::get_gl_info().is_core_profile() ? wxGetApp().get_shader("dashed_thick_lines") : wxGetApp().get_shader("flat"); +#if SLIC3R_OPENGL_ES + GLShaderProgram* shader = wxGetApp().get_shader("dashed_lines"); #else - GLShaderProgram* shader = wxGetApp().get_shader("flat"); -#endif // ENABLE_GL_CORE_PROFILE + GLShaderProgram* 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) { shader->start_using(); const Camera& camera = wxGetApp().plater()->get_camera(); shader->set_uniform("view_model_matrix", camera.get_view_matrix() * m_grabbers_transform); shader->set_uniform("projection_matrix", camera.get_projection_matrix()); -#if ENABLE_GL_CORE_PROFILE - const std::array& viewport = camera.get_viewport(); - shader->set_uniform("viewport_size", Vec2d(double(viewport[2]), double(viewport[3]))); - shader->set_uniform("width", 0.25f); - shader->set_uniform("gap_size", 0.0f); -#endif // ENABLE_GL_CORE_PROFILE +#if !SLIC3R_OPENGL_ES + if (OpenGLManager::get_gl_info().is_core_profile()) { +#endif // !SLIC3R_OPENGL_ES + const std::array& viewport = camera.get_viewport(); + shader->set_uniform("viewport_size", Vec2d(double(viewport[2]), double(viewport[3]))); + shader->set_uniform("width", 0.25f); + shader->set_uniform("gap_size", 0.0f); +#if !SLIC3R_OPENGL_ES + } +#endif // !SLIC3R_OPENGL_ES if (m_grabbers[0].enabled && m_grabbers[1].enabled) render_grabbers_connection(0, 1, m_grabbers[0].color); if (m_grabbers[2].enabled && m_grabbers[3].enabled) @@ -207,22 +211,26 @@ void GLGizmoScale3D::on_render() } else if ((m_hover_id == 0 || m_hover_id == 1) && m_grabbers[0].enabled && m_grabbers[1].enabled) { // draw connections -#if ENABLE_GL_CORE_PROFILE - GLShaderProgram* shader = OpenGLManager::get_gl_info().is_core_profile() ? wxGetApp().get_shader("dashed_thick_lines") : wxGetApp().get_shader("flat"); +#if SLIC3R_OPENGL_ES + GLShaderProgram* shader = wxGetApp().get_shader("dashed_lines"); #else - GLShaderProgram* shader = wxGetApp().get_shader("flat"); -#endif // ENABLE_GL_CORE_PROFILE + GLShaderProgram* 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) { shader->start_using(); const Camera& camera = wxGetApp().plater()->get_camera(); shader->set_uniform("view_model_matrix", camera.get_view_matrix() * m_grabbers_transform); shader->set_uniform("projection_matrix", camera.get_projection_matrix()); -#if ENABLE_GL_CORE_PROFILE - const std::array& viewport = camera.get_viewport(); - shader->set_uniform("viewport_size", Vec2d(double(viewport[2]), double(viewport[3]))); - shader->set_uniform("width", 0.25f); - shader->set_uniform("gap_size", 0.0f); -#endif // ENABLE_GL_CORE_PROFILE +#if !SLIC3R_OPENGL_ES + if (OpenGLManager::get_gl_info().is_core_profile()) { +#endif // !SLIC3R_OPENGL_ES + const std::array& viewport = camera.get_viewport(); + shader->set_uniform("viewport_size", Vec2d(double(viewport[2]), double(viewport[3]))); + shader->set_uniform("width", 0.25f); + shader->set_uniform("gap_size", 0.0f); +#if !SLIC3R_OPENGL_ES + } +#endif // !SLIC3R_OPENGL_ES render_grabbers_connection(0, 1, m_grabbers[0].color); shader->stop_using(); } @@ -238,22 +246,26 @@ void GLGizmoScale3D::on_render() } else if ((m_hover_id == 2 || m_hover_id == 3) && m_grabbers[2].enabled && m_grabbers[3].enabled) { // draw connections -#if ENABLE_GL_CORE_PROFILE - GLShaderProgram* shader = OpenGLManager::get_gl_info().is_core_profile() ? wxGetApp().get_shader("dashed_thick_lines") : wxGetApp().get_shader("flat"); +#if SLIC3R_OPENGL_ES + GLShaderProgram* shader = wxGetApp().get_shader("dashed_lines"); #else - GLShaderProgram* shader = wxGetApp().get_shader("flat"); -#endif // ENABLE_GL_CORE_PROFILE + GLShaderProgram* 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) { shader->start_using(); const Camera& camera = wxGetApp().plater()->get_camera(); shader->set_uniform("view_model_matrix", camera.get_view_matrix() * m_grabbers_transform); shader->set_uniform("projection_matrix", camera.get_projection_matrix()); -#if ENABLE_GL_CORE_PROFILE - const std::array& viewport = camera.get_viewport(); - shader->set_uniform("viewport_size", Vec2d(double(viewport[2]), double(viewport[3]))); - shader->set_uniform("width", 0.25f); - shader->set_uniform("gap_size", 0.0f); -#endif // ENABLE_GL_CORE_PROFILE +#if !SLIC3R_OPENGL_ES + if (OpenGLManager::get_gl_info().is_core_profile()) { +#endif // !SLIC3R_OPENGL_ES + const std::array& viewport = camera.get_viewport(); + shader->set_uniform("viewport_size", Vec2d(double(viewport[2]), double(viewport[3]))); + shader->set_uniform("width", 0.25f); + shader->set_uniform("gap_size", 0.0f); +#if !SLIC3R_OPENGL_ES + } +#endif // !SLIC3R_OPENGL_ES render_grabbers_connection(2, 3, m_grabbers[2].color); shader->stop_using(); } @@ -269,22 +281,26 @@ void GLGizmoScale3D::on_render() } else if ((m_hover_id == 4 || m_hover_id == 5) && m_grabbers[4].enabled && m_grabbers[5].enabled) { // draw connections -#if ENABLE_GL_CORE_PROFILE - GLShaderProgram* shader = OpenGLManager::get_gl_info().is_core_profile() ? wxGetApp().get_shader("dashed_thick_lines") : wxGetApp().get_shader("flat"); +#if SLIC3R_OPENGL_ES + GLShaderProgram* shader = wxGetApp().get_shader("dashed_lines"); #else - GLShaderProgram* shader = wxGetApp().get_shader("flat"); -#endif // ENABLE_GL_CORE_PROFILE + GLShaderProgram* 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) { shader->start_using(); const Camera& camera = wxGetApp().plater()->get_camera(); shader->set_uniform("view_model_matrix", camera.get_view_matrix() * m_grabbers_transform); shader->set_uniform("projection_matrix", camera.get_projection_matrix()); -#if ENABLE_GL_CORE_PROFILE - const std::array& viewport = camera.get_viewport(); - shader->set_uniform("viewport_size", Vec2d(double(viewport[2]), double(viewport[3]))); - shader->set_uniform("width", 0.25f); - shader->set_uniform("gap_size", 0.0f); -#endif // ENABLE_GL_CORE_PROFILE +#if !SLIC3R_OPENGL_ES + if (OpenGLManager::get_gl_info().is_core_profile()) { +#endif // !SLIC3R_OPENGL_ES + const std::array& viewport = camera.get_viewport(); + shader->set_uniform("viewport_size", Vec2d(double(viewport[2]), double(viewport[3]))); + shader->set_uniform("width", 0.25f); + shader->set_uniform("gap_size", 0.0f); +#if !SLIC3R_OPENGL_ES + } +#endif // !SLIC3R_OPENGL_ES render_grabbers_connection(4, 5, m_grabbers[4].color); shader->stop_using(); } @@ -300,22 +316,26 @@ void GLGizmoScale3D::on_render() } else if (m_hover_id >= 6) { // draw connections -#if ENABLE_GL_CORE_PROFILE - GLShaderProgram* shader = OpenGLManager::get_gl_info().is_core_profile() ? wxGetApp().get_shader("dashed_thick_lines") : wxGetApp().get_shader("flat"); +#if SLIC3R_OPENGL_ES + GLShaderProgram* shader = wxGetApp().get_shader("dashed_lines"); #else - GLShaderProgram* shader = wxGetApp().get_shader("flat"); -#endif // ENABLE_GL_CORE_PROFILE + GLShaderProgram* 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) { shader->start_using(); const Camera& camera = wxGetApp().plater()->get_camera(); shader->set_uniform("view_model_matrix", camera.get_view_matrix() * m_grabbers_transform); shader->set_uniform("projection_matrix", camera.get_projection_matrix()); -#if ENABLE_GL_CORE_PROFILE - const std::array& viewport = camera.get_viewport(); - shader->set_uniform("viewport_size", Vec2d(double(viewport[2]), double(viewport[3]))); - shader->set_uniform("width", 0.25f); - shader->set_uniform("gap_size", 0.0f); -#endif // ENABLE_GL_CORE_PROFILE +#if !SLIC3R_OPENGL_ES + if (OpenGLManager::get_gl_info().is_core_profile()) { +#endif // !SLIC3R_OPENGL_ES + const std::array& viewport = camera.get_viewport(); + shader->set_uniform("viewport_size", Vec2d(double(viewport[2]), double(viewport[3]))); + shader->set_uniform("width", 0.25f); + shader->set_uniform("gap_size", 0.0f); +#if !SLIC3R_OPENGL_ES + } +#endif // !SLIC3R_OPENGL_ES render_grabbers_connection(6, 7, m_drag_color); render_grabbers_connection(7, 8, m_drag_color); render_grabbers_connection(8, 9, m_drag_color); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoSimplify.cpp b/src/slic3r/GUI/Gizmos/GLGizmoSimplify.cpp index 09e20d3e3b..2bdd92b75a 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoSimplify.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoSimplify.cpp @@ -737,11 +737,7 @@ void GLGizmoSimplify::on_render() const Transform3d trafo_matrix = selected_volume->world_matrix(); auto* gouraud_shader = wxGetApp().get_shader("gouraud_light"); -#if ENABLE_GL_CORE_PROFILE || SLIC3R_OPENGL_ES bool depth_test_enabled = ::glIsEnabled(GL_DEPTH_TEST); -#else - glsafe(::glPushAttrib(GL_DEPTH_TEST)); -#endif // ENABLE_GL_CORE_PROFILE || SLIC3R_OPENGL_ES glsafe(::glEnable(GL_DEPTH_TEST)); gouraud_shader->start_using(); const Camera& camera = wxGetApp().plater()->get_camera(); @@ -766,11 +762,9 @@ void GLGizmoSimplify::on_render() contour_shader->set_uniform("projection_matrix", camera.get_projection_matrix()); const ColorRGBA color = glmodel.get_color(); glmodel.set_color(ColorRGBA::WHITE()); -#if ENABLE_GL_CORE_PROFILE - if (!OpenGLManager::get_gl_info().is_core_profile()) -#endif // ENABLE_GL_CORE_PROFILE - glsafe(::glLineWidth(1.0f)); #if !SLIC3R_OPENGL_ES + if (!OpenGLManager::get_gl_info().is_core_profile()) + glsafe(::glLineWidth(1.0f)); glsafe(::glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)); #endif // !SLIC3R_OPENGL_ES glmodel.render(); @@ -780,12 +774,8 @@ void GLGizmoSimplify::on_render() glmodel.set_color(color); contour_shader->stop_using(); } -#if ENABLE_GL_CORE_PROFILE || SLIC3R_OPENGL_ES if (depth_test_enabled) glsafe(::glEnable(GL_DEPTH_TEST)); -#else - glsafe(::glPopAttrib()); -#endif // ENABLE_GL_CORE_PROFILE || SLIC3R_OPENGL_ES } } diff --git a/src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp b/src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp index 7092f1c3cf..a115aaf467 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp @@ -225,19 +225,11 @@ void InstancesHider::render_cut() const else clipper->set_limiting_plane(ClippingPlane::ClipsNothing()); -#if ENABLE_GL_CORE_PROFILE || SLIC3R_OPENGL_ES bool depth_test_enabled = ::glIsEnabled(GL_DEPTH_TEST); -#else - glsafe(::glPushAttrib(GL_DEPTH_TEST)); -#endif // ENABLE_GL_CORE_PROFILE || SLIC3R_OPENGL_ES glsafe(::glDisable(GL_DEPTH_TEST)); clipper->render_cut(mv->is_model_part() ? ColorRGBA(0.8f, 0.3f, 0.0f, 1.0f) : color_from_model_volume(*mv)); -#if ENABLE_GL_CORE_PROFILE || SLIC3R_OPENGL_ES if (depth_test_enabled) glsafe(::glEnable(GL_DEPTH_TEST)); -#else - glsafe(::glPopAttrib()); -#endif // ENABLE_GL_CORE_PROFILE || SLIC3R_OPENGL_ES ++clipper_id; } diff --git a/src/slic3r/GUI/ImGuiWrapper.cpp b/src/slic3r/GUI/ImGuiWrapper.cpp index ad5ffcd696..51f48e417d 100644 --- a/src/slic3r/GUI/ImGuiWrapper.cpp +++ b/src/slic3r/GUI/ImGuiWrapper.cpp @@ -1919,14 +1919,15 @@ void ImGuiWrapper::render_draw_data(ImDrawData *draw_data) shader->start_using(); -#if ENABLE_GL_CORE_PROFILE || SLIC3R_OPENGL_ES // Backup GL state GLenum last_active_texture; glsafe(::glGetIntegerv(GL_ACTIVE_TEXTURE, (GLint*)&last_active_texture)); GLuint last_program; glsafe(::glGetIntegerv(GL_CURRENT_PROGRAM, (GLint*)&last_program)); GLuint last_texture; glsafe(::glGetIntegerv(GL_TEXTURE_BINDING_2D, (GLint*)&last_texture)); GLuint last_array_buffer; glsafe(::glGetIntegerv(GL_ARRAY_BUFFER_BINDING, (GLint*)&last_array_buffer)); GLuint last_vertex_array_object = 0; - if (OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0)) +#if !SLIC3R_OPENGL_ES + if (OpenGLManager::get_gl_info().is_core_profile()) +#endif // !SLIC3R_OPENGL_ES glsafe(::glGetIntegerv(GL_VERTEX_ARRAY_BINDING, (GLint*)&last_vertex_array_object)); GLint last_viewport[4]; glsafe(::glGetIntegerv(GL_VIEWPORT, last_viewport)); GLint last_scissor_box[4]; glsafe(::glGetIntegerv(GL_SCISSOR_BOX, last_scissor_box)); @@ -1951,25 +1952,6 @@ void ImGuiWrapper::render_draw_data(ImDrawData *draw_data) glsafe(::glDisable(GL_DEPTH_TEST)); glsafe(::glDisable(GL_STENCIL_TEST)); glsafe(::glEnable(GL_SCISSOR_TEST)); -#else - // We are using the OpenGL fixed pipeline to make the example code simpler to read! - // Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled, vertex/texcoord/color pointers, polygon fill. - GLint last_texture; glsafe(::glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture)); - GLint last_polygon_mode[2]; glsafe(::glGetIntegerv(GL_POLYGON_MODE, last_polygon_mode)); - GLint last_viewport[4]; glsafe(::glGetIntegerv(GL_VIEWPORT, last_viewport)); - GLint last_scissor_box[4]; glsafe(::glGetIntegerv(GL_SCISSOR_BOX, last_scissor_box)); - GLint last_texture_env_mode; glsafe(::glGetTexEnviv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, &last_texture_env_mode)); - glsafe(::glPushAttrib(GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT | GL_TRANSFORM_BIT)); - glsafe(::glEnable(GL_BLEND)); - glsafe(::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); - glsafe(::glDisable(GL_CULL_FACE)); - glsafe(::glDisable(GL_DEPTH_TEST)); - glsafe(::glDisable(GL_STENCIL_TEST)); - glsafe(::glEnable(GL_SCISSOR_TEST)); - glsafe(::glEnable(GL_TEXTURE_2D)); - glsafe(::glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)); - glsafe(::glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE)); -#endif // ENABLE_GL_CORE_PROFILE || SLIC3R_OPENGL_ES // Setup viewport, orthographic projection matrix // Our visible imgui space lies from draw_data->DisplayPos (top left) to draw_data->DisplayPos+data_data->DisplaySize (bottom right). DisplayPos is (0,0) for single viewport apps. @@ -2001,13 +1983,15 @@ void ImGuiWrapper::render_draw_data(ImDrawData *draw_data) const GLsizeiptr vtx_buffer_size = (GLsizeiptr)cmd_list->VtxBuffer.Size * (int)sizeof(ImDrawVert); const GLsizeiptr idx_buffer_size = (GLsizeiptr)cmd_list->IdxBuffer.Size * (int)sizeof(ImDrawIdx); -#if ENABLE_GL_CORE_PROFILE GLuint vao_id = 0; - if (OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0)) { +#if !SLIC3R_OPENGL_ES + if (OpenGLManager::get_gl_info().is_core_profile()) { +#endif // !SLIC3R_OPENGL_ES glsafe(::glGenVertexArrays(1, &vao_id)); glsafe(::glBindVertexArray(vao_id)); +#if !SLIC3R_OPENGL_ES } -#endif // ENABLE_GL_CORE_PROFILE +#endif // !SLIC3R_OPENGL_ES GLuint vbo_id; glsafe(::glGenBuffers(1, &vbo_id)); @@ -2069,17 +2053,22 @@ void ImGuiWrapper::render_draw_data(ImDrawData *draw_data) glsafe(::glDeleteBuffers(1, &ibo_id)); glsafe(::glDeleteBuffers(1, &vbo_id)); -#if ENABLE_GL_CORE_PROFILE - if (vao_id > 0) - glsafe(::glDeleteVertexArrays(1, &vao_id)); -#endif // ENABLE_GL_CORE_PROFILE +#if !SLIC3R_OPENGL_ES + if (OpenGLManager::get_gl_info().is_core_profile()) { +#endif // !SLIC3R_OPENGL_ES + if (vao_id > 0) + glsafe(::glDeleteVertexArrays(1, &vao_id)); +#if !SLIC3R_OPENGL_ES + } +#endif // !SLIC3R_OPENGL_ES } -#if ENABLE_GL_CORE_PROFILE || SLIC3R_OPENGL_ES // Restore modified GL state glsafe(::glBindTexture(GL_TEXTURE_2D, last_texture)); glsafe(::glActiveTexture(last_active_texture)); - if (OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0)) +#if !SLIC3R_OPENGL_ES + if (OpenGLManager::get_gl_info().is_core_profile()) +#endif // !SLIC3R_OPENGL_ES glsafe(::glBindVertexArray(last_vertex_array_object)); glsafe(::glBindBuffer(GL_ARRAY_BUFFER, last_array_buffer)); glsafe(::glBlendEquationSeparate(last_blend_equation_rgb, last_blend_equation_alpha)); @@ -2091,16 +2080,6 @@ void ImGuiWrapper::render_draw_data(ImDrawData *draw_data) if (last_enable_scissor_test) glsafe(::glEnable(GL_SCISSOR_TEST)); else glsafe(::glDisable(GL_SCISSOR_TEST)); glsafe(::glViewport(last_viewport[0], last_viewport[1], (GLsizei)last_viewport[2], (GLsizei)last_viewport[3])); glsafe(::glScissor(last_scissor_box[0], last_scissor_box[1], (GLsizei)last_scissor_box[2], (GLsizei)last_scissor_box[3])); -#else - // Restore modified state - glsafe(::glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, last_texture_env_mode)); - glsafe(::glBindTexture(GL_TEXTURE_2D, (GLuint)last_texture)); - glsafe(::glPopAttrib()); - glsafe(::glPolygonMode(GL_FRONT, (GLenum)last_polygon_mode[0]); - glsafe(::glPolygonMode(GL_BACK, (GLenum)last_polygon_mode[1]))); - glsafe(::glViewport(last_viewport[0], last_viewport[1], (GLsizei)last_viewport[2], (GLsizei)last_viewport[3])); - glsafe(::glScissor(last_scissor_box[0], last_scissor_box[1], (GLsizei)last_scissor_box[2], (GLsizei)last_scissor_box[3])); -#endif // ENABLE_GL_CORE_PROFILE || SLIC3R_OPENGL_ES shader->stop_using(); diff --git a/src/slic3r/GUI/OpenGLManager.cpp b/src/slic3r/GUI/OpenGLManager.cpp index 9964a5766d..c8472b8d9d 100644 --- a/src/slic3r/GUI/OpenGLManager.cpp +++ b/src/slic3r/GUI/OpenGLManager.cpp @@ -6,9 +6,9 @@ #include "OpenGLManager.hpp" #include "GUI.hpp" -#if ENABLE_GL_CORE_PROFILE +#if !SLIC3R_OPENGL_ES #include "GUI_Init.hpp" -#endif // ENABLE_GL_CORE_PROFILE +#endif // !SLIC3R_OPENGL_ES #include "I18N.hpp" #include "3DScene.hpp" #include "format.hpp" @@ -207,9 +207,9 @@ 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 << " (" << m_version_string << ")" << line_end; -#if ENABLE_GL_CORE_PROFILE +#if !SLIC3R_OPENGL_ES out << b_start << "Profile: " << b_end << (is_core_profile() ? "Core" : "Compatibility") << line_end; -#endif // ENABLE_GL_CORE_PROFILE +#endif // !SLIC3R_OPENGL_ES out << b_start << "Vendor: " << b_end << m_vendor << line_end; out << b_start << "Renderer: " << b_end << m_renderer << line_end; out << b_start << "GLSL version: " << b_end << m_glsl_version << line_end; @@ -219,13 +219,13 @@ std::string OpenGLManager::GLInfo::to_string(bool for_github) const #endif // ENABLE_OPENGL_AUTO_AA_SAMPLES { -#if ENABLE_GL_CORE_PROFILE - std::vector extensions_list = get_extensions_list(); -#else +#if SLIC3R_OPENGL_ES const std::string extensions_str = gl_get_string_safe(GL_EXTENSIONS, ""); std::vector extensions_list; boost::split(extensions_list, extensions_str, boost::is_any_of(" "), boost::token_compress_on); -#endif // ENABLE_GL_CORE_PROFILE +#else + std::vector extensions_list = get_extensions_list(); +#endif // SLIC3R_OPENGL_ES if (!extensions_list.empty()) { if (for_github) @@ -246,7 +246,7 @@ std::string OpenGLManager::GLInfo::to_string(bool for_github) const return out.str(); } -#if ENABLE_GL_CORE_PROFILE +#if !SLIC3R_OPENGL_ES std::vector OpenGLManager::GLInfo::get_extensions_list() const { std::vector ret; @@ -269,7 +269,7 @@ std::vector OpenGLManager::GLInfo::get_extensions_list() const return ret; } -#endif // ENABLE_GL_CORE_PROFILE +#endif // !SLIC3R_OPENGL_ES OpenGLManager::GLInfo OpenGLManager::s_gl_info; bool OpenGLManager::s_compressed_textures_supported = false; @@ -299,7 +299,7 @@ OpenGLManager::~OpenGLManager() #endif //__APPLE__ } -#if ENABLE_GL_CORE_PROFILE +#if !SLIC3R_OPENGL_ES #ifdef _WIN32 static void APIENTRY CustomGLDebugOutput(GLenum source, GLenum type, unsigned int id, GLenum severity, GLsizei length, const char* message, const void* userParam) #else @@ -343,26 +343,22 @@ static void CustomGLDebugOutput(GLenum source, GLenum type, unsigned int id, GLe out += "]:\n"; std::cout << out << "(" << id << "): " << message << "\n\n"; } -#endif // ENABLE_GL_CORE_PROFILE +#endif // !SLIC3R_OPENGL_ES bool OpenGLManager::init_gl() { if (!m_gl_initialized) { -#if ENABLE_GL_CORE_PROFILE || SLIC3R_OPENGL_ES glewExperimental = true; -#endif // ENABLE_GL_CORE_PROFILE || SLIC3R_OPENGL_ES GLenum err = glewInit(); if (err != GLEW_OK) { BOOST_LOG_TRIVIAL(error) << "Unable to init glew library: " << glewGetErrorString(err); return false; } -#if ENABLE_GL_CORE_PROFILE do { // glewInit() generates an OpenGL GL_INVALID_ENUM error err = ::glGetError(); } while (err != GL_NO_ERROR); -#endif // ENABLE_GL_CORE_PROFILE m_gl_initialized = true; @@ -379,24 +375,19 @@ bool OpenGLManager::init_gl() s_framebuffers_type = EFramebufferType::Unknown; #if SLIC3R_OPENGL_ES - bool valid_version = s_gl_info.is_version_greater_or_equal_to(2, 0); -#elif ENABLE_GL_CORE_PROFILE - const bool valid_version = s_gl_info.is_version_greater_or_equal_to(3, 2); + bool valid_version = s_gl_info.is_version_greater_or_equal_to(3, 0); #else - bool valid_version = s_gl_info.is_version_greater_or_equal_to(2, 0); + const bool valid_version = s_gl_info.is_version_greater_or_equal_to(3, 2); #endif // SLIC3R_OPENGL_ES if (!valid_version) { // Complain about the OpenGL version. wxString message = format_wxstr( #if SLIC3R_OPENGL_ES - _L("PrusaSlicer requires OpenGL ES 2.0 capable graphics driver to run correctly, \n" - "while OpenGL version %s, render %s, vendor %s was detected."), s_gl_info.get_version_string(), s_gl_info.get_renderer(), s_gl_info.get_vendor()); -#elif ENABLE_GL_CORE_PROFILE - _L("PrusaSlicer requires OpenGL 3.2 capable graphics driver to run correctly,\n" + _L("PrusaSlicer requires OpenGL ES 3.0 capable graphics driver to run correctly, \n" "while OpenGL version %s, render %s, vendor %s was detected."), s_gl_info.get_version_string(), s_gl_info.get_renderer(), s_gl_info.get_vendor()); #else - _L("PrusaSlicer requires OpenGL 2.0 capable graphics driver to run correctly, \n" + _L("PrusaSlicer requires OpenGL 3.2 capable graphics driver to run correctly,\n" "while OpenGL version %s, render %s, vendor %s was detected."), s_gl_info.get_version_string(), s_gl_info.get_renderer(), s_gl_info.get_vendor()); #endif // SLIC3R_OPENGL_ES message += "\n"; @@ -415,7 +406,7 @@ bool OpenGLManager::init_gl() wxString message = format_wxstr(_L("Unable to load the following shaders:\n%s"), error); wxMessageBox(message, wxString("PrusaSlicer - ") + _L("Error loading shaders"), wxOK | wxICON_ERROR); } -#if ENABLE_GL_CORE_PROFILE +#if !SLIC3R_OPENGL_ES if (m_debug_enabled && s_gl_info.is_version_greater_or_equal_to(4, 3) && GLEW_KHR_debug) { ::glEnable(GL_DEBUG_OUTPUT); ::glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); @@ -423,7 +414,7 @@ bool OpenGLManager::init_gl() ::glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, nullptr, GL_TRUE); std::cout << "Enabled OpenGL debug output\n"; } -#endif // ENABLE_GL_CORE_PROFILE +#endif // !SLIC3R_OPENGL_ES } #ifdef _WIN32 @@ -449,19 +440,19 @@ bool OpenGLManager::init_gl() return true; } -#if ENABLE_GL_CORE_PROFILE +#if SLIC3R_OPENGL_ES +wxGLContext* OpenGLManager::init_glcontext(wxGLCanvas& canvas) +#else wxGLContext* OpenGLManager::init_glcontext(wxGLCanvas& canvas, const std::pair& required_opengl_version, bool enable_compatibility_profile, bool enable_debug) -#else -wxGLContext* OpenGLManager::init_glcontext(wxGLCanvas& canvas) -#endif // ENABLE_GL_CORE_PROFILE +#endif // SLIC3R_OPENGL_ES { if (m_context == nullptr) { #if SLIC3R_OPENGL_ES wxGLContextAttrs attrs; attrs.PlatformDefaults().ES2().MajorVersion(2).EndList(); m_context = new wxGLContext(&canvas, nullptr, &attrs); -#elif ENABLE_GL_CORE_PROFILE +#else m_debug_enabled = enable_debug; const int gl_major = required_opengl_version.first; @@ -531,8 +522,6 @@ wxGLContext* OpenGLManager::init_glcontext(wxGLCanvas& canvas) // if no valid context was created use the default one m_context = new wxGLContext(&canvas, nullptr, &attrs); } -#else - m_context = new wxGLContext(&canvas); #endif // SLIC3R_OPENGL_ES #ifdef __APPLE__ @@ -551,7 +540,6 @@ wxGLCanvas* OpenGLManager::create_wxglcanvas(wxWindow& parent, bool enable_auto_ wxGLCanvas* OpenGLManager::create_wxglcanvas(wxWindow& parent) #endif // ENABLE_OPENGL_AUTO_AA_SAMPLES { -#if ENABLE_GL_CORE_PROFILE || SLIC3R_OPENGL_ES wxGLAttributes attribList; #if ENABLE_OPENGL_AUTO_AA_SAMPLES s_multisample = EMultisampleState::Disabled; @@ -574,23 +562,6 @@ wxGLCanvas* OpenGLManager::create_wxglcanvas(wxWindow& parent) // on MAC the method RGBA() has no effect attribList.SetNeedsARB(true); #endif // __APPLE__ -#else - int attribList[] = { - WX_GL_RGBA, - WX_GL_DOUBLEBUFFER, - // RGB channels each should be allocated with 8 bit depth. One should almost certainly get these bit depths by default. - WX_GL_MIN_RED, 8, - WX_GL_MIN_GREEN, 8, - WX_GL_MIN_BLUE, 8, - // Requesting an 8 bit alpha channel. Interestingly, the NVIDIA drivers would most likely work with some alpha plane, but glReadPixels would not return - // the alpha channel on NVIDIA if not requested when the GL context is created. - WX_GL_MIN_ALPHA, 8, - WX_GL_DEPTH_SIZE, 24, - WX_GL_SAMPLE_BUFFERS, GL_TRUE, - WX_GL_SAMPLES, 4, - 0 - }; -#endif // ENABLE_GL_CORE_PROFILE || SLIC3R_OPENGL_ES #if ENABLE_OPENGL_AUTO_AA_SAMPLES if (s_multisample != EMultisampleState::Enabled) @@ -600,7 +571,6 @@ wxGLCanvas* OpenGLManager::create_wxglcanvas(wxWindow& parent) if (!can_multisample()) #endif // ENABLE_OPENGL_AUTO_AA_SAMPLES -#if ENABLE_GL_CORE_PROFILE || SLIC3R_OPENGL_ES { attribList.Reset(); attribList.PlatformDefaults().RGBA().DoubleBuffer().MinRGBA(8, 8, 8, 8).Depth(24).EndList(); @@ -611,19 +581,10 @@ wxGLCanvas* OpenGLManager::create_wxglcanvas(wxWindow& parent) } return new wxGLCanvas(&parent, attribList, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxWANTS_CHARS); -#else - attribList[12] = 0; - - return new wxGLCanvas(&parent, wxID_ANY, attribList, wxDefaultPosition, wxDefaultSize, wxWANTS_CHARS); -#endif // ENABLE_GL_CORE_PROFILE || SLIC3R_OPENGL_ES } #if !ENABLE_OPENGL_AUTO_AA_SAMPLES -#if ENABLE_GL_CORE_PROFILE || SLIC3R_OPENGL_ES void OpenGLManager::detect_multisample(const wxGLAttributes& attribList) -#else -void OpenGLManager::detect_multisample(int* attribList) -#endif // ENABLE_GL_CORE_PROFILE || SLIC3R_OPENGL_ES { int wxVersion = wxMAJOR_VERSION * 10000 + wxMINOR_VERSION * 100 + wxRELEASE_NUMBER; bool enable_multisample = wxVersion >= 30003; diff --git a/src/slic3r/GUI/OpenGLManager.hpp b/src/slic3r/GUI/OpenGLManager.hpp index 72af86e737..5f58038452 100644 --- a/src/slic3r/GUI/OpenGLManager.hpp +++ b/src/slic3r/GUI/OpenGLManager.hpp @@ -10,9 +10,7 @@ class wxWindow; class wxGLCanvas; class wxGLContext; -#if ENABLE_GL_CORE_PROFILE || SLIC3R_OPENGL_ES class wxGLAttributes; -#endif // ENABLE_GL_CORE_PROFILE || SLIC3R_OPENGL_ES namespace Slic3r { namespace GUI { @@ -77,9 +75,9 @@ public: // Otherwise HTML formatted for the system info dialog. std::string to_string(bool for_github) const; -#if ENABLE_GL_CORE_PROFILE +#if !SLIC3R_OPENGL_ES std::vector get_extensions_list() const; -#endif // ENABLE_GL_CORE_PROFILE +#endif // !SLIC3R_OPENGL_ES private: void detect() const; @@ -123,11 +121,11 @@ public: ~OpenGLManager(); bool init_gl(); -#if ENABLE_GL_CORE_PROFILE - wxGLContext* init_glcontext(wxGLCanvas& canvas, const std::pair& required_opengl_version, bool enable_compatibility_profile, bool enable_debug); -#else +#if SLIC3R_OPENGL_ES wxGLContext* init_glcontext(wxGLCanvas& canvas); -#endif // ENABLE_GL_CORE_PROFILE +#else + wxGLContext* init_glcontext(wxGLCanvas& canvas, const std::pair& required_opengl_version, bool enable_compatibility_profile, bool enable_debug); +#endif // SLIC3R_OPENGL_ES GLShaderProgram* get_shader(const std::string& shader_name) { return m_shaders_manager.get_shader(shader_name); } GLShaderProgram* get_current_shader() { return m_shaders_manager.get_current_shader(); } @@ -146,11 +144,7 @@ public: private: #if !ENABLE_OPENGL_AUTO_AA_SAMPLES -#if ENABLE_GL_CORE_PROFILE || SLIC3R_OPENGL_ES static void detect_multisample(const wxGLAttributes& attribList); -#else - static void detect_multisample(int* attribList); -#endif // ENABLE_GL_CORE_PROFILE || SLIC3R_OPENGL_ES #endif // !ENABLE_OPENGL_AUTO_AA_SAMPLES }; diff --git a/src/slic3r/GUI/Selection.cpp b/src/slic3r/GUI/Selection.cpp index 22feabfbc1..e9fdef933a 100644 --- a/src/slic3r/GUI/Selection.cpp +++ b/src/slic3r/GUI/Selection.cpp @@ -2267,15 +2267,14 @@ void Selection::render_bounding_box(const BoundingBoxf3& box, const Transform3d& glsafe(::glEnable(GL_DEPTH_TEST)); -#if ENABLE_GL_CORE_PROFILE +#if SLIC3R_OPENGL_ES + GLShaderProgram* shader = wxGetApp().get_shader("dashed_lines"); +#else if (!OpenGLManager::get_gl_info().is_core_profile()) glsafe(::glLineWidth(2.0f * m_scale_factor)); GLShaderProgram* shader = OpenGLManager::get_gl_info().is_core_profile() ? wxGetApp().get_shader("dashed_thick_lines") : wxGetApp().get_shader("flat"); -#else - glsafe(::glLineWidth(2.0f * m_scale_factor)); - GLShaderProgram* shader = wxGetApp().get_shader("flat"); -#endif // ENABLE_GL_CORE_PROFILE +#endif // SLIC3R_OPENGL_ES if (shader == nullptr) return; @@ -2283,12 +2282,16 @@ void Selection::render_bounding_box(const BoundingBoxf3& box, const Transform3d& const Camera& camera = wxGetApp().plater()->get_camera(); shader->set_uniform("view_model_matrix", camera.get_view_matrix() * trafo); shader->set_uniform("projection_matrix", camera.get_projection_matrix()); -#if ENABLE_GL_CORE_PROFILE - const std::array& viewport = camera.get_viewport(); - shader->set_uniform("viewport_size", Vec2d(double(viewport[2]), double(viewport[3]))); - shader->set_uniform("width", 1.5f); - shader->set_uniform("gap_size", 0.0f); -#endif // ENABLE_GL_CORE_PROFILE +#if !SLIC3R_OPENGL_ES + if (OpenGLManager::get_gl_info().is_core_profile()) { +#endif // !SLIC3R_OPENGL_ES + const std::array& viewport = camera.get_viewport(); + shader->set_uniform("viewport_size", Vec2d(double(viewport[2]), double(viewport[3]))); + shader->set_uniform("width", 1.5f); + shader->set_uniform("gap_size", 0.0f); +#if !SLIC3R_OPENGL_ES + } +#endif // !SLIC3R_OPENGL_ES m_box.set_color(to_rgba(color)); m_box.render(); shader->stop_using(); diff --git a/src/slic3r/GUI/SendSystemInfoDialog.cpp b/src/slic3r/GUI/SendSystemInfoDialog.cpp index 7d11042e9b..0845799833 100644 --- a/src/slic3r/GUI/SendSystemInfoDialog.cpp +++ b/src/slic3r/GUI/SendSystemInfoDialog.cpp @@ -59,10 +59,10 @@ static const std::string SEND_SYSTEM_INFO_DOMAIN = "prusa3d.com"; static const std::string SEND_SYSTEM_INFO_URL = "https://files." + SEND_SYSTEM_INFO_DOMAIN + "/wp-json/v1/ps"; -#if !ENABLE_GL_CORE_PROFILE +#if SLIC3R_OPENGL_ES // Declaration of a free function defined in OpenGLManager.cpp: std::string gl_get_string_safe(GLenum param, const std::string& default_value); -#endif // !ENABLE_GL_CORE_PROFILE +#endif // SLIC3R_OPENGL_ES // A dialog with the information text and buttons send/dont send/ask later. @@ -513,13 +513,13 @@ static std::string generate_system_info_json() opengl_node.put("Vendor", OpenGLManager::get_gl_info().get_vendor()); opengl_node.put("Renderer", OpenGLManager::get_gl_info().get_renderer()); // Generate list of OpenGL extensions: -#if ENABLE_GL_CORE_PROFILE - std::vector extensions_list = OpenGLManager::get_gl_info().get_extensions_list(); -#else +#if SLIC3R_OPENGL_ES std::string extensions_str = gl_get_string_safe(GL_EXTENSIONS, ""); std::vector extensions_list; boost::split(extensions_list, extensions_str, boost::is_any_of(" "), boost::token_compress_off); -#endif // ENABLE_GL_CORE_PROFILE +#else + std::vector extensions_list = OpenGLManager::get_gl_info().get_extensions_list(); +#endif // SLIC3R_OPENGL_ES std::sort(extensions_list.begin(), extensions_list.end()); pt::ptree extensions_node; for (const std::string& s : extensions_list) {