diff --git a/resources/shaders/110/flat.fs b/resources/shaders/110/flat.fs new file mode 100644 index 000000000..ab656998d --- /dev/null +++ b/resources/shaders/110/flat.fs @@ -0,0 +1,8 @@ +#version 110 + +uniform vec4 uniform_color; + +void main() +{ + gl_FragColor = uniform_color; +} diff --git a/resources/shaders/110/flat.vs b/resources/shaders/110/flat.vs new file mode 100644 index 000000000..d9063f0c7 --- /dev/null +++ b/resources/shaders/110/flat.vs @@ -0,0 +1,11 @@ +#version 110 + +uniform mat4 view_model_matrix; +uniform mat4 projection_matrix; + +attribute vec3 v_position; + +void main() +{ + gl_Position = projection_matrix * view_model_matrix * vec4(v_position, 1.0); +} diff --git a/resources/shaders/printbed.fs b/resources/shaders/110/printbed.fs similarity index 73% rename from resources/shaders/printbed.fs rename to resources/shaders/110/printbed.fs index d1316ca2f..833dff08f 100644 --- a/resources/shaders/printbed.fs +++ b/resources/shaders/110/printbed.fs @@ -1,21 +1,21 @@ #version 110 -const vec3 back_color_dark = vec3(0.235, 0.235, 0.235); +const vec3 back_color_dark = vec3(0.235, 0.235, 0.235); const vec3 back_color_light = vec3(0.365, 0.365, 0.365); uniform sampler2D texture; uniform bool transparent_background; uniform bool svg_source; -varying vec2 tex_coords; +varying vec2 tex_coord; vec4 svg_color() { // takes foreground from texture - vec4 fore_color = texture2D(texture, tex_coords); + vec4 fore_color = texture2D(texture, tex_coord); // calculates radial gradient - vec3 back_color = vec3(mix(back_color_light, back_color_dark, smoothstep(0.0, 0.5, length(abs(tex_coords.xy) - vec2(0.5))))); + vec3 back_color = vec3(mix(back_color_light, back_color_dark, smoothstep(0.0, 0.5, length(abs(tex_coord.xy) - 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); @@ -24,7 +24,7 @@ vec4 svg_color() vec4 non_svg_color() { // takes foreground from texture - vec4 color = texture2D(texture, tex_coords); + vec4 color = texture2D(texture, tex_coord); return vec4(color.rgb, transparent_background ? color.a * 0.25 : color.a); } diff --git a/resources/shaders/110/printbed.vs b/resources/shaders/110/printbed.vs new file mode 100644 index 000000000..dc4868b04 --- /dev/null +++ b/resources/shaders/110/printbed.vs @@ -0,0 +1,15 @@ +#version 110 + +uniform mat4 view_model_matrix; +uniform mat4 projection_matrix; + +attribute vec3 v_position; +attribute vec2 v_tex_coord; + +varying vec2 tex_coord; + +void main() +{ + tex_coord = v_tex_coord; + gl_Position = projection_matrix * view_model_matrix * vec4(v_position, 1.0); +} diff --git a/resources/shaders/printbed.vs b/resources/shaders/printbed.vs deleted file mode 100644 index 7633017f1..000000000 --- a/resources/shaders/printbed.vs +++ /dev/null @@ -1,14 +0,0 @@ -#version 110 - -attribute vec3 v_position; -attribute vec2 v_tex_coords; - -varying vec2 tex_coords; - -void main() -{ - gl_Position = gl_ModelViewProjectionMatrix * vec4(v_position.x, v_position.y, v_position.z, 1.0); - // the following line leads to crash on some Intel graphics card - //gl_Position = gl_ModelViewProjectionMatrix * vec4(v_position, 1.0); - tex_coords = v_tex_coords; -} diff --git a/src/slic3r/GUI/3DBed.cpp b/src/slic3r/GUI/3DBed.cpp index b590af3ee..db283c508 100644 --- a/src/slic3r/GUI/3DBed.cpp +++ b/src/slic3r/GUI/3DBed.cpp @@ -320,8 +320,14 @@ void Bed3D::on_change_color_mode(bool is_dark) m_is_dark = is_dark; } -void Bed3D::render(GLCanvas3D& canvas, bool bottom, float scale_factor, bool show_axes) +BoundingBoxf3 Bed3D::get_cur_bed_model_box() { + BoundingBoxf3 model_bb = m_model.get_bounding_box(); + model_bb.translate(m_model_offset); + return model_bb; +} + +void Bed3D::render(GLCanvas3D &canvas, bool bottom, float scale_factor, bool show_axes) { render_internal(canvas, bottom, scale_factor, show_axes); } @@ -558,7 +564,7 @@ void Bed3D::render_system(GLCanvas3D& canvas, bool bottom) const unsigned int stride = m_triangles.get_vertex_data_size(); GLint position_id = shader->get_attrib_location("v_position"); - GLint tex_coords_id = shader->get_attrib_location("v_tex_coords"); + GLint tex_coords_id = shader->get_attrib_location("v_tex_coord"); // show the temporary texture while no compressed data is available GLuint tex_id = (GLuint)temp_texture->get_id(); diff --git a/src/slic3r/GUI/3DBed.hpp b/src/slic3r/GUI/3DBed.hpp index cd2dc301c..b0d5ce763 100644 --- a/src/slic3r/GUI/3DBed.hpp +++ b/src/slic3r/GUI/3DBed.hpp @@ -133,6 +133,7 @@ public: // Bounding box around the print bed, axes and model, for rendering. const BoundingBoxf3& extended_bounding_box() const { return m_extended_bounding_box; } + BoundingBoxf3 get_cur_bed_model_box(); const std::string & get_model_filename() { return m_model_filename; } const GLModel & get_model() { return m_model; } // Check against an expanded 2d bounding box. diff --git a/src/slic3r/GUI/3DScene.hpp b/src/slic3r/GUI/3DScene.hpp index 2be906094..293615ace 100644 --- a/src/slic3r/GUI/3DScene.hpp +++ b/src/slic3r/GUI/3DScene.hpp @@ -10,7 +10,7 @@ // BBS #include "libslic3r/ObjectID.hpp" -#include "GLModel.hpp" +#include "MeshUtils.hpp" #include "GLShader.hpp" #include diff --git a/src/slic3r/GUI/GLModel.cpp b/src/slic3r/GUI/GLModel.cpp index 82ea7127c..1c0574ead 100644 --- a/src/slic3r/GUI/GLModel.cpp +++ b/src/slic3r/GUI/GLModel.cpp @@ -474,6 +474,7 @@ void GLModel::init_from(Geometry &&data, bool generate_mesh) m_render_data.clear(); m_render_data.push_back(RenderData()); m_render_data.back().indices_count = data.indices.size(); + m_render_data.back().vertices_count = data.vertices.size(); m_render_data.back().type = data.format.type; m_render_data.back().color = data.color.get_data(); if (generate_mesh) { @@ -623,14 +624,92 @@ bool GLModel::init_from_file(const std::string& filename) return true; } +bool GLModel::init_model_from_poly(const std::vector &triangles, float z, bool generate_mesh) +{ + if (triangles.empty() || triangles.size() % 3 != 0) + return false; + + GLModel::Geometry init_data; + init_data.format = {GLModel::PrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3T2}; + init_data.reserve_vertices(triangles.size()); + init_data.reserve_indices(triangles.size() / 3); + + Vec2f min = triangles.front(); + Vec2f max = min; + for (const Vec2f &v : triangles) { + min = min.cwiseMin(v).eval(); + max = max.cwiseMax(v).eval(); + } + + const Vec2f size = max - min; + if (size.x() <= 0.0f || size.y() <= 0.0f) + return false; + + Vec2f inv_size = size.cwiseInverse(); + inv_size.y() *= -1.0f; + + // vertices + indices + unsigned int vertices_counter = 0; + for (const Vec2f &v : triangles) { + const Vec3f p = {v.x(), v.y(), z}; + init_data.add_vertex(p, (Vec2f) (v - min).cwiseProduct(inv_size).eval()); + ++vertices_counter; + if (vertices_counter % 3 == 0) + init_data.add_triangle(vertices_counter - 3, vertices_counter - 2, vertices_counter - 1); + } + init_from(std::move(init_data), generate_mesh); + return true; +} + +bool GLModel::init_model_from_lines(const Lines &lines, float z, bool generate_mesh) +{ + GLModel::Geometry init_data; + init_data.format = {GLModel::PrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P3}; + init_data.reserve_vertices(2 * lines.size()); + init_data.reserve_indices(2 * lines.size()); + + for (const auto &l : lines) { + init_data.add_vertex(Vec3f(unscale(l.a.x()), unscale(l.a.y()), z)); + init_data.add_vertex(Vec3f(unscale(l.b.x()), unscale(l.b.y()), z)); + const unsigned int vertices_counter = (unsigned int) init_data.vertices_count(); + init_data.add_line(vertices_counter - 2, vertices_counter - 1); + } + init_from(std::move(init_data), generate_mesh); + return true; +} + +bool GLModel::init_model_from_lines(const Lines3 &lines, bool generate_mesh) +{ + GLModel::Geometry init_data; + init_data.format = {GLModel::PrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P3}; + init_data.reserve_vertices(2 * lines.size()); + init_data.reserve_indices(2 * lines.size()); + + for (const auto &l : lines) { + init_data.add_vertex(Vec3f(unscale(l.a.x()), unscale(l.a.y()), unscale(l.a.z()))); + init_data.add_vertex(Vec3f(unscale(l.b.x()), unscale(l.b.y()), unscale(l.b.z()))); + const unsigned int vertices_counter = (unsigned int) init_data.vertices_count(); + init_data.add_line(vertices_counter - 2, vertices_counter - 1); + } + init_from(std::move(init_data), generate_mesh); + + return true; +} + void GLModel::set_color(int entity_id, const std::array& color) { for (size_t i = 0; i < m_render_data.size(); ++i) { - if (entity_id == -1 || static_cast(i) == entity_id) + if (entity_id == -1 || static_cast(i) == entity_id) { m_render_data[i].color = color; + m_render_data[i].geometry.color = color; + } } } +void GLModel::set_color(const ColorRGBA &color) { + set_color(-1,color.get_data()); +} + void GLModel::reset() { for (RenderData& data : m_render_data) { @@ -646,6 +725,50 @@ void GLModel::reset() m_filename = std::string(); } +static GLenum get_primitive_mode(const GLModel::Geometry::Format &format) +{ + switch (format.type) { + case GLModel::PrimitiveType::Points: { + return GL_POINTS; + } + default: + case GLModel::PrimitiveType::Triangles: { + return GL_TRIANGLES; + } + case GLModel::PrimitiveType::TriangleStrip: { + return GL_TRIANGLE_STRIP; + } + case GLModel::PrimitiveType::TriangleFan: { + return GL_TRIANGLE_FAN; + } + case GLModel::PrimitiveType::Lines: { + return GL_LINES; + } + case GLModel::PrimitiveType::LineStrip: { + return GL_LINE_STRIP; + } + case GLModel::PrimitiveType::LineLoop: { + return GL_LINE_LOOP; + } + } +} + +static GLenum get_index_type(const GLModel::Geometry &data) +{ + switch (data.index_type) { + default: + case GLModel::Geometry::EIndexType::UINT: { + return GL_UNSIGNED_INT; + } + case GLModel::Geometry::EIndexType::USHORT: { + return GL_UNSIGNED_SHORT; + } + case GLModel::Geometry::EIndexType::UBYTE: { + return GL_UNSIGNED_BYTE; + } + } +} + void GLModel::render() const { GLShaderProgram* shader = wxGetApp().get_current_shader(); @@ -654,7 +777,7 @@ void GLModel::render() const // sends data to gpu if not done yet if (data.vbo_id == 0 || data.ibo_id == 0) { auto origin_data = const_cast(&data); - if (data.geometry.vertices_count() > 0 && data.geometry.indices_count() > 0 + if (data.geometry.vertices_count() > 0 && data.geometry.indices_count() > 0 && !send_to_gpu(*origin_data, data.geometry.vertices, data.geometry.indices)) continue; } @@ -701,6 +824,79 @@ void GLModel::render() const } } +void GLModel::render_geometry() { + render_geometry(0,std::make_pair(0, indices_count())); +} + +void GLModel::render_geometry(int i,const std::pair &range) +{ + if (range.second == range.first) return; + + GLShaderProgram *shader = wxGetApp().get_current_shader(); + if (shader == nullptr) return; + + auto &render_data = m_render_data[i]; + // sends data to gpu if not done yet + if (render_data.vbo_id == 0 || render_data.ibo_id == 0) { + if (render_data.geometry.vertices_count() > 0 && render_data.geometry.indices_count() > 0 && + !send_to_gpu(render_data, render_data.geometry.vertices, render_data.geometry.indices)) + return; + } + const Geometry &data = render_data.geometry; + + + const GLenum mode = get_primitive_mode(data.format); + const GLenum index_type = get_index_type(data); + + const size_t vertex_stride_bytes = Geometry::vertex_stride_bytes(data.format); + const bool position = Geometry::has_position(data.format); + const bool normal = Geometry::has_normal(data.format); + const bool tex_coord = Geometry::has_tex_coord(data.format); + + glsafe(::glBindBuffer(GL_ARRAY_BUFFER, render_data.vbo_id)); + + int position_id = -1; + int normal_id = -1; + int tex_coord_id = -1; + + if (position) { + position_id = shader->get_attrib_location("v_position"); + if (position_id != -1) { + glsafe(::glVertexAttribPointer(position_id, Geometry::position_stride_floats(data.format), GL_FLOAT, GL_FALSE, vertex_stride_bytes, + (const void *) Geometry::position_offset_bytes(data.format))); + glsafe(::glEnableVertexAttribArray(position_id)); + } + } + if (normal) { + normal_id = shader->get_attrib_location("v_normal"); + if (normal_id != -1) { + glsafe(::glVertexAttribPointer(normal_id, Geometry::normal_stride_floats(data.format), GL_FLOAT, GL_FALSE, vertex_stride_bytes, + (const void *) Geometry::normal_offset_bytes(data.format))); + glsafe(::glEnableVertexAttribArray(normal_id)); + } + } + if (tex_coord) { + tex_coord_id = shader->get_attrib_location("v_tex_coord"); + if (tex_coord_id != -1) { + glsafe(::glVertexAttribPointer(tex_coord_id, Geometry::tex_coord_stride_floats(data.format), GL_FLOAT, GL_FALSE, vertex_stride_bytes, + (const void *) Geometry::tex_coord_offset_bytes(data.format))); + glsafe(::glEnableVertexAttribArray(tex_coord_id)); + } + } + + shader->set_uniform("uniform_color", data.color.get_data()); + + glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, render_data.ibo_id)); + glsafe(::glDrawElements(mode, range.second - range.first, index_type, (const void *) (range.first * Geometry::index_stride_bytes(data)))); + glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); + + if (tex_coord_id != -1) glsafe(::glDisableVertexAttribArray(tex_coord_id)); + if (normal_id != -1) glsafe(::glDisableVertexAttribArray(normal_id)); + if (position_id != -1) glsafe(::glDisableVertexAttribArray(position_id)); + + glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); +} + void GLModel::render_instanced(unsigned int instances_vbo, unsigned int instances_count) const { if (instances_vbo == 0) @@ -801,6 +997,7 @@ bool GLModel::send_to_gpu(RenderData& data, const std::vector& vertices, glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, data.ibo_id)); glsafe(::glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(unsigned int), indices.data(), GL_STATIC_DRAW)); glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); + return true; } diff --git a/src/slic3r/GUI/GLModel.hpp b/src/slic3r/GUI/GLModel.hpp index 1a341b296..ec375877f 100644 --- a/src/slic3r/GUI/GLModel.hpp +++ b/src/slic3r/GUI/GLModel.hpp @@ -22,7 +22,10 @@ namespace GUI { public: enum class PrimitiveType : unsigned char { + Points, Triangles, + TriangleStrip, + TriangleFan, Lines, LineStrip, LineLoop @@ -130,6 +133,7 @@ namespace GUI { PrimitiveType type; unsigned int vbo_id{0}; unsigned int ibo_id{0}; + size_t vertices_count{0}; size_t indices_count{0}; std::array color{1.0f, 1.0f, 1.0f, 1.0f}; }; @@ -165,6 +169,12 @@ namespace GUI { GLModel() = default; virtual ~GLModel(); + size_t vertices_count(int i = 0) const { + return m_render_data[i].vertices_count > 0 ? m_render_data[i].vertices_count : m_render_data[i].geometry.vertices_count(); + } + size_t indices_count(int i = 0) const { + return m_render_data[i].indices_count > 0 ? m_render_data[i].indices_count : m_render_data[i].geometry.indices_count(); } + TriangleMesh *mesh{nullptr}; void init_from(Geometry &&data, bool generate_mesh = false); @@ -173,12 +183,17 @@ namespace GUI { void init_from(const indexed_triangle_set& its); void init_from(const Polygons& polygons, float z); bool init_from_file(const std::string& filename); - + bool init_model_from_poly(const std::vector &triangles, float z, bool generate_mesh = false); + bool init_model_from_lines(const Lines &lines, float z, bool generate_mesh = false); + bool init_model_from_lines(const Lines3 &lines, bool generate_mesh = false); // if entity_id == -1 set the color of all entities void set_color(int entity_id, const std::array& color); + void set_color(const ColorRGBA &color); void reset(); void render() const; + void render_geometry(); + void render_geometry(int i,const std::pair &range); void render_instanced(unsigned int instances_vbo, unsigned int instances_count) const; bool is_initialized() const { return !m_render_data.empty(); } diff --git a/src/slic3r/GUI/GLShadersManager.cpp b/src/slic3r/GUI/GLShadersManager.cpp index 0d06d3733..ddf081f24 100644 --- a/src/slic3r/GUI/GLShadersManager.cpp +++ b/src/slic3r/GUI/GLShadersManager.cpp @@ -41,7 +41,7 @@ std::pair GLShadersManager::init() valid &= append_shader("cali", { "cali.vs", "cali.fs"}); valid &= append_shader("flat", {"flat.vs", "flat.fs"}); // used to render printbed - valid &= append_shader("printbed", { "printbed.vs", "printbed.fs" }); + valid &= append_shader("printbed", {"110/printbed.vs", "110/printbed.fs"}); // used to render options in gcode preview if (GUI::wxGetApp().is_gl_version_greater_or_equal_to(3, 3)) valid &= append_shader("gouraud_light_instanced", { "gouraud_light_instanced.vs", "gouraud_light_instanced.fs" }); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoBase.hpp b/src/slic3r/GUI/Gizmos/GLGizmoBase.hpp index e67b1312e..d412eb9f4 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoBase.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoBase.hpp @@ -5,8 +5,7 @@ #include "libslic3r/Color.hpp" #include "slic3r/GUI/I18N.hpp" -#include "slic3r/GUI/GLModel.hpp" -#include "slic3r/GUI/MeshUtils.hpp" +#include "slic3r/GUI/3DScene.hpp" #include diff --git a/src/slic3r/GUI/Gizmos/GLGizmosCommon.hpp b/src/slic3r/GUI/Gizmos/GLGizmosCommon.hpp index 1eabff381..e2030a6a2 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmosCommon.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmosCommon.hpp @@ -4,14 +4,11 @@ #include #include +#include "libslic3r/Model.hpp" #include "slic3r/GUI/MeshUtils.hpp" #include "libslic3r/SLA/Hollowing.hpp" namespace Slic3r { - -class ModelObject; - - namespace GUI { class GLCanvas3D; diff --git a/src/slic3r/GUI/MeshUtils.hpp b/src/slic3r/GUI/MeshUtils.hpp index 236abd067..80b5e1743 100644 --- a/src/slic3r/GUI/MeshUtils.hpp +++ b/src/slic3r/GUI/MeshUtils.hpp @@ -7,7 +7,7 @@ #include "libslic3r/SLA/IndexedMesh.hpp" #include "admesh/stl.h" -#include "slic3r/GUI/3DScene.hpp" +#include "slic3r/GUI/GLModel.hpp" #include diff --git a/src/slic3r/GUI/PartPlate.cpp b/src/slic3r/GUI/PartPlate.cpp index 510885fec..1398071bd 100644 --- a/src/slic3r/GUI/PartPlate.cpp +++ b/src/slic3r/GUI/PartPlate.cpp @@ -346,14 +346,20 @@ void PartPlate::calc_bounding_boxes() const { } } -void PartPlate::calc_triangles(const ExPolygon& poly) { - if (!m_triangles.set_from_triangles(triangulate_expolygon_2f(poly, NORMALS_UP), GROUND_Z)) +void PartPlate::calc_triangles(const ExPolygon& poly) +{ + auto triangles =triangulate_expolygon_2f(poly, NORMALS_UP); + m_triangles.reset(); + if (!m_triangles.init_model_from_poly(triangles, GROUND_Z)) BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ":Unable to create plate triangles\n"; } void PartPlate::calc_exclude_triangles(const ExPolygon& poly) { - if (!m_exclude_triangles.set_from_triangles(triangulate_expolygon_2f(poly, NORMALS_UP), GROUND_Z)) - BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ":Unable to create exclude triangles\n"; + if (poly.empty()) { return; } + auto triangles = triangulate_expolygon_2f(poly, NORMALS_UP); + m_exclude_triangles.reset(); + if (!m_exclude_triangles.init_model_from_poly(triangles, GROUND_Z)) + BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ":Unable to create plate triangles\n"; } void PartPlate::calc_gridlines(const ExPolygon& poly, const BoundingBox& pp_bbox) { @@ -392,10 +398,11 @@ void PartPlate::calc_gridlines(const ExPolygon& poly, const BoundingBox& pp_bbox Lines contour_lines = to_lines(poly); std::copy(contour_lines.begin(), contour_lines.end(), std::back_inserter(gridlines)); - if (!m_gridlines.set_from_lines(gridlines, GROUND_Z)) + m_gridlines.reset(); + if (!m_gridlines.init_model_from_lines(gridlines, GROUND_Z)) BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << "Unable to create bed grid lines\n"; - - if (!m_gridlines_bolder.set_from_lines(gridlines_bolder, GROUND_Z)) + m_gridlines_bolder.reset(); + if (!m_gridlines_bolder.init_model_from_lines(gridlines_bolder, GROUND_Z)) BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << "Unable to create bed grid lines\n"; } @@ -430,18 +437,18 @@ void PartPlate::calc_height_limit() { } //std::copy(bottom_lines.begin(), bottom_lines.end(), std::back_inserter(bottom_h_lines)); std::copy(top_lines.begin(), top_lines.end(), std::back_inserter(top_h_lines)); - - if (!m_height_limit_common.set_from_3d_Lines(common_lines)) + m_height_limit_common.reset(); + if (!m_height_limit_common.init_model_from_lines(common_lines)) BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << "Unable to create height limit bottom lines\n"; - - if (!m_height_limit_bottom.set_from_3d_Lines(bottom_h_lines)) + m_height_limit_bottom.reset(); + if (!m_height_limit_bottom.init_model_from_lines(bottom_h_lines)) BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << "Unable to create height limit bottom lines\n"; - - if (!m_height_limit_top.set_from_3d_Lines(top_h_lines)) + m_height_limit_top.reset(); + if (!m_height_limit_top.init_model_from_lines(top_h_lines)) BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << "Unable to create height limit top lines\n"; } -void PartPlate::calc_vertex_for_number(int index, bool one_number, GeometryBuffer &buffer) +void PartPlate::calc_vertex_for_number(int index, bool one_number, GLModel &gl_model) { ExPolygon poly; #if 0 //in the up area @@ -462,11 +469,12 @@ void PartPlate::calc_vertex_for_number(int index, bool one_number, GeometryBuffe poly.contour.append({ scale_(p(0) + PARTPLATE_ICON_GAP_LEFT + offset_x), scale_(p(1) + PARTPLATE_ICON_SIZE - PARTPLATE_TEXT_OFFSET_Y) }); #endif auto triangles = triangulate_expolygon_2f(poly, NORMALS_UP); - if (!buffer.set_from_triangles(triangles, GROUND_Z)) - BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << "Unable to generate geometry buffers for icons\n"; + gl_model.reset(); + if (!gl_model.init_model_from_poly(triangles, GROUND_Z)) + BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ":Unable to create plate triangles\n"; } -void PartPlate::calc_vertex_for_plate_name(GLTexture &texture, GeometryBuffer &buffer) +void PartPlate::calc_vertex_for_plate_name(GLTexture &texture, GLModel &gl_model) { if (texture.get_width() > 0 && texture.get_height()) { wxCoord w, h; @@ -483,12 +491,15 @@ void PartPlate::calc_vertex_for_plate_name(GLTexture &texture, GeometryBuffer &b poly.contour.append({scale_(p(0) + PARTPLATE_ICON_GAP_LEFT + offset_x), scale_(p(1) )}); auto triangles = triangulate_expolygon_2f(poly, NORMALS_UP); - if (!buffer.set_from_triangles(triangles, GROUND_Z)) BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << "Unable to generate geometry buffers for icons\n"; + gl_model.reset(); + if (!gl_model.init_model_from_poly(triangles, GROUND_Z)) + BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << "Unable to generate geometry buffers for icons\n"; } } -void PartPlate::calc_vertex_for_plate_name_edit_icon(GLTexture *texture, int index, GeometryBuffer &buffer) { +void PartPlate::calc_vertex_for_plate_name_edit_icon(GLTexture *texture, int index, GLModel &gl_model) +{ auto bed_ext = get_extents(m_shape); auto factor = bed_ext.size()(1) / 200.0; wxCoord w, h; @@ -498,6 +509,7 @@ void PartPlate::calc_vertex_for_plate_name_edit_icon(GLTexture *texture, int ind float offset_x = 1; h = PARTPLATE_EDIT_PLATE_NAME_ICON_SIZE; p += Vec2d(0, PARTPLATE_PLATENAME_OFFSET_Y + h); + std::vector triangles; if (texture && texture->get_width() > 0 && texture->get_height()) { w = int(factor * (texture->get_original_width() * 16) / texture->get_height()) + 1; @@ -506,9 +518,7 @@ void PartPlate::calc_vertex_for_plate_name_edit_icon(GLTexture *texture, int ind poly.contour.append({scale_(p(0) + PARTPLATE_ICON_GAP_LEFT + w + PARTPLATE_EDIT_PLATE_NAME_ICON_SIZE), scale_(p(1))}); poly.contour.append({scale_(p(0) + PARTPLATE_ICON_GAP_LEFT + w), scale_(p(1) )}); - auto triangles = triangulate_expolygon_2f(poly, NORMALS_UP); - if (!buffer.set_from_triangles(triangles, GROUND_Z)) - BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << "Unable to generate geometry buffers for icons\n"; + triangles = triangulate_expolygon_2f(poly, NORMALS_UP); } else { poly.contour.append({scale_(p(0) + PARTPLATE_ICON_GAP_LEFT + offset_x ), scale_(p(1) - h )}); @@ -516,13 +526,14 @@ void PartPlate::calc_vertex_for_plate_name_edit_icon(GLTexture *texture, int ind poly.contour.append({scale_(p(0) + PARTPLATE_ICON_GAP_LEFT + offset_x + PARTPLATE_EDIT_PLATE_NAME_ICON_SIZE), scale_(p(1))}); poly.contour.append({scale_(p(0) + PARTPLATE_ICON_GAP_LEFT + offset_x), scale_(p(1) )}); - auto triangles = triangulate_expolygon_2f(poly, NORMALS_UP); - if (!buffer.set_from_triangles(triangles, GROUND_Z)) - BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << "Unable to generate geometry buffers for icons\n"; + triangles = triangulate_expolygon_2f(poly, NORMALS_UP); } + gl_model.reset(); + if (!gl_model.init_model_from_poly(triangles, GROUND_Z)) + BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << "Unable to generate geometry buffers for icons\n"; } -void PartPlate::calc_vertex_for_icons(int index, GeometryBuffer &buffer) +void PartPlate::calc_vertex_for_icons(int index, GLModel &gl_model) { ExPolygon poly; Vec2d& p = m_shape[2]; @@ -533,7 +544,8 @@ void PartPlate::calc_vertex_for_icons(int index, GeometryBuffer &buffer) poly.contour.append({ scale_(p(0) + PARTPLATE_ICON_GAP_LEFT), scale_(p(1) - index * (PARTPLATE_ICON_SIZE + PARTPLATE_ICON_GAP_Y)- PARTPLATE_ICON_GAP_TOP) }); auto triangles = triangulate_expolygon_2f(poly, NORMALS_UP); - if (!buffer.set_from_triangles(triangles, GROUND_Z)) + gl_model.reset(); + if (!gl_model.init_model_from_poly(triangles, GROUND_Z)) BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << "Unable to generate geometry buffers for icons\n"; } @@ -552,33 +564,30 @@ void PartPlate::calc_vertex_for_icons_background(int icon_count, GeometryBuffer BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << "Unable to generate geometry buffers for icons\n"; } -void PartPlate::render_background(bool force_default_color) const { - unsigned int triangles_vcount = m_triangles.get_vertices_count(); - +void PartPlate::render_background(bool force_default_color) { //return directly for current plate if (m_selected && !force_default_color) return; // draw background glsafe(::glDepthMask(GL_FALSE)); - + ColorRGBA color; if (!force_default_color) { if (m_selected) { - glsafe(::glColor4fv(PartPlate::SELECT_COLOR.data())); + color = PartPlate::SELECT_COLOR; } else { - glsafe(m_partplate_list->m_is_dark ? ::glColor4fv(PartPlate::UNSELECT_DARK_COLOR.data()) : ::glColor4fv(PartPlate::UNSELECT_COLOR.data())); + color = m_partplate_list->m_is_dark ? PartPlate::UNSELECT_DARK_COLOR : PartPlate::UNSELECT_COLOR; } } else { - glsafe(::glColor4fv(PartPlate::DEFAULT_COLOR.data())); + color = PartPlate::DEFAULT_COLOR; } - glsafe(::glNormal3d(0.0f, 0.0f, 1.0f)); - glsafe(::glVertexPointer(3, GL_FLOAT, m_triangles.get_vertex_data_size(), (GLvoid*)m_triangles.get_vertices_data())); - glsafe(::glDrawArrays(GL_TRIANGLES, 0, (GLsizei)triangles_vcount)); - glsafe(::glDepthMask(GL_TRUE)); + m_triangles.set_color(color); + m_triangles.render_geometry(); + glsafe(::glDepthMask(GL_TRUE)); } -void PartPlate::render_logo_texture(GLTexture &logo_texture, const GeometryBuffer& logo_buffer, bool bottom, unsigned int vbo_id) const +void PartPlate::render_logo_texture(GLTexture &logo_texture, GLModel &logo_buffer, bool bottom) { //check valid if (logo_texture.unsent_compressed_data_available()) { @@ -586,57 +595,18 @@ void PartPlate::render_logo_texture(GLTexture &logo_texture, const GeometryBuffe logo_texture.send_compressed_data_to_gpu(); } - if (logo_buffer.get_vertices_count() > 0) { - GLShaderProgram* shader = wxGetApp().get_shader("printbed"); - if (shader != nullptr) { - shader->start_using(); - shader->set_uniform("transparent_background", 0); - shader->set_uniform("svg_source", 0); - - //glsafe(::glEnable(GL_DEPTH_TEST)); - glsafe(::glDepthMask(GL_FALSE)); + if (logo_buffer.is_initialized()) { if (bottom) glsafe(::glFrontFace(GL_CW)); - unsigned int stride = logo_buffer.get_vertex_data_size(); - - GLint position_id = shader->get_attrib_location("v_position"); - GLint tex_coords_id = shader->get_attrib_location("v_tex_coords"); - if (position_id != -1) { - glsafe(::glEnableVertexAttribArray(position_id)); - } - if (tex_coords_id != -1) { - glsafe(::glEnableVertexAttribArray(tex_coords_id)); - } - // 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)); - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, vbo_id)); - - if (position_id != -1) - glsafe(::glVertexAttribPointer(position_id, 3, GL_FLOAT, GL_FALSE, stride, (GLvoid*)(intptr_t)logo_buffer.get_position_offset())); - if (tex_coords_id != -1) - glsafe(::glVertexAttribPointer(tex_coords_id, 2, GL_FLOAT, GL_FALSE, stride, (GLvoid*)(intptr_t)logo_buffer.get_tex_coords_offset())); - glsafe(::glDrawArrays(GL_TRIANGLES, 0, (GLsizei)logo_buffer.get_vertices_count())); - - if (tex_coords_id != -1) - glsafe(::glDisableVertexAttribArray(tex_coords_id)); - - if (position_id != -1) - glsafe(::glDisableVertexAttribArray(position_id)); - - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); + logo_buffer.render_geometry(); glsafe(::glBindTexture(GL_TEXTURE_2D, 0)); if (bottom) glsafe(::glFrontFace(GL_CCW)); - - glsafe(::glDepthMask(GL_TRUE)); - - shader->stop_using(); - } } } @@ -650,17 +620,6 @@ void PartPlate::render_logo(bool bottom, bool render_cali) m_partplate_list->m_logo_texture.reset(); if (boost::algorithm::iends_with(m_partplate_list->m_logo_texture_filename, ".svg")) { - /*// use higher resolution images if graphic card and opengl version allow - GLint max_tex_size = OpenGLManager::get_gl_info().get_max_tex_size(); - if (temp_texture->get_id() == 0 || temp_texture->get_source() != m_texture_filename) { - // generate a temporary lower resolution texture to show while no main texture levels have been compressed - if (!temp_texture->load_from_svg_file(m_texture_filename, false, false, false, max_tex_size / 8)) { - render_default(bottom, false); - return; - } - canvas.request_extra_frame(); - }*/ - // starts generating the main texture, compression will run asynchronously GLint max_tex_size = OpenGLManager::get_gl_info().get_max_tex_size(); GLint logo_tex_size = (max_tex_size < 2048) ? max_tex_size : 2048; @@ -699,23 +658,15 @@ void PartPlate::render_logo(bool bottom, bool render_cali) // canvas.request_extra_frame(); } - if (m_vbo_id == 0) { - unsigned int *vbo_id_ptr = const_cast(&m_vbo_id); - glsafe(::glGenBuffers(1, vbo_id_ptr)); - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, *vbo_id_ptr)); - glsafe(::glBufferData(GL_ARRAY_BUFFER, (GLsizeiptr) m_logo_triangles.get_vertices_data_size(), (const GLvoid *) m_logo_triangles.get_vertices_data(), - GL_STATIC_DRAW)); - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); - } if (m_partplate_list && m_partplate_list->m_bed3d && !m_partplate_list->m_bed3d->get_model_filename().empty()) { auto cur_bed = m_partplate_list->m_bed3d; - auto cur_box = cur_bed->get_model().get_bounding_box().transformed(Geometry::translation_transform(m_origin)); + auto cur_box = cur_bed->get_cur_bed_model_box(); if ((m_cur_bed_boundingbox.center() - cur_box.center()).norm() > 1.0f) { set_logo_box_by_bed(cur_box); } } - if (m_vbo_id != 0 && m_logo_triangles.get_vertices_count() > 0) { - render_logo_texture(m_partplate_list->m_logo_texture, m_logo_triangles, bottom, m_vbo_id); + if (m_logo_triangles.is_initialized()) { + render_logo_texture(m_partplate_list->m_logo_texture, m_logo_triangles, bottom); } if (!m_partplate_list->render_bedtype_logo) { return; @@ -736,7 +687,7 @@ void PartPlate::render_logo(bool bottom, bool render_cali) // render bed textures for (auto &part : m_partplate_list->bed_texture_info[bed_type_idx].parts) { if (part.texture) { - if (part.buffer && part.buffer->get_vertices_count() > 0 + if (part.buffer && part.buffer->is_initialized() //&& part.vbo_id != 0 ) { if (part.offset.x() != m_origin.x() || part.offset.y() != m_origin.y()) { @@ -745,8 +696,7 @@ void PartPlate::render_logo(bool bottom, bool render_cali) } render_logo_texture(*(part.texture), *(part.buffer), - bottom, - part.vbo_id); + bottom); } } } @@ -755,322 +705,169 @@ void PartPlate::render_logo(bool bottom, bool render_cali) if (render_cali) { for (auto& part : m_partplate_list->cali_texture_info.parts) { if (part.texture) { - if (part.buffer && part.buffer->get_vertices_count() > 0) { + if (part.buffer && part.buffer->is_initialized()) { if (part.offset.x() != m_origin.x() || part.offset.y() != m_origin.y()) { part.offset = Vec2d(m_origin.x(), m_origin.y()); part.update_buffer(); } render_logo_texture(*(part.texture), *(part.buffer), - bottom, - part.vbo_id); + bottom); } } } } } -void PartPlate::render_exclude_area(bool force_default_color) const { - if (force_default_color) //for thumbnail case +void PartPlate::render_exclude_area(bool force_default_color) +{ + if (force_default_color || !m_exclude_triangles.is_initialized()) // for thumbnail case return; - unsigned int triangles_vcount = m_exclude_triangles.get_vertices_count(); - std::array select_color{ 0.765f, 0.7686f, 0.7686f, 1.0f }; - std::array unselect_color{ 0.9f, 0.9f, 0.9f, 1.0f }; - std::array default_color{ 0.9f, 0.9f, 0.9f, 1.0f }; + ColorRGBA select_color{0.765f, 0.7686f, 0.7686f, 1.0f}; + ColorRGBA unselect_color{0.9f, 0.9f, 0.9f, 1.0f}; + //std::array default_color{ 0.9f, 0.9f, 0.9f, 1.0f }; // draw exclude area glsafe(::glDepthMask(GL_FALSE)); - - if (m_selected) { - glsafe(::glColor4fv(select_color.data())); - } - else { - glsafe(::glColor4fv(unselect_color.data())); - } - - glsafe(::glNormal3d(0.0f, 0.0f, 1.0f)); - glsafe(::glVertexPointer(3, GL_FLOAT, m_exclude_triangles.get_vertex_data_size(), (GLvoid*)m_exclude_triangles.get_vertices_data())); - glsafe(::glDrawArrays(GL_TRIANGLES, 0, (GLsizei)triangles_vcount)); + m_exclude_triangles.set_color(m_selected ? select_color : unselect_color); + m_exclude_triangles.render_geometry(); glsafe(::glDepthMask(GL_TRUE)); } - -/*void PartPlate::render_background_for_picking(const float* render_color) const -{ - unsigned int triangles_vcount = m_triangles.get_vertices_count(); - - glsafe(::glDepthMask(GL_FALSE)); - glsafe(::glColor4fv(render_color)); - glsafe(::glNormal3d(0.0f, 0.0f, 1.0f)); - glsafe(::glVertexPointer(3, GL_FLOAT, m_triangles.get_vertex_data_size(), (GLvoid*)m_triangles.get_vertices_data())); - glsafe(::glDrawArrays(GL_TRIANGLES, 0, (GLsizei)triangles_vcount)); - glsafe(::glDepthMask(GL_TRUE)); -}*/ - -void PartPlate::render_grid(bool bottom) const { +void PartPlate::render_grid(bool bottom) { //glsafe(::glEnable(GL_MULTISAMPLE)); // draw grid glsafe(::glLineWidth(1.0f * m_scale_factor)); + ColorRGBA color; if (bottom) - glsafe(::glColor4fv(LINE_BOTTOM_COLOR.data())); + color = LINE_BOTTOM_COLOR; else { if (m_selected) - glsafe(m_partplate_list->m_is_dark ? ::glColor4fv(LINE_TOP_SEL_DARK_COLOR.data()) : ::glColor4fv(LINE_TOP_SEL_COLOR.data())); + color = m_partplate_list->m_is_dark ? LINE_TOP_SEL_DARK_COLOR : LINE_TOP_SEL_COLOR; else - glsafe(m_partplate_list->m_is_dark ? ::glColor4fv(LINE_TOP_DARK_COLOR.data()) : ::glColor4fv(LINE_TOP_COLOR.data())); + color = m_partplate_list->m_is_dark ? LINE_TOP_DARK_COLOR : LINE_TOP_COLOR; } - glsafe(::glVertexPointer(3, GL_FLOAT, m_gridlines.get_vertex_data_size(), (GLvoid*)m_gridlines.get_vertices_data())); - glsafe(::glDrawArrays(GL_LINES, 0, (GLsizei)m_gridlines.get_vertices_count())); + m_gridlines.set_color(color); + m_gridlines.render_geometry(); - glsafe(::glLineWidth(2.0f * m_scale_factor)); - glsafe(::glVertexPointer(3, GL_FLOAT, m_gridlines_bolder.get_vertex_data_size(), (GLvoid*)m_gridlines_bolder.get_vertices_data())); - glsafe(::glDrawArrays(GL_LINES, 0, (GLsizei)m_gridlines_bolder.get_vertices_count())); + glsafe(::glLineWidth(2.0f * m_scale_factor)); + m_gridlines_bolder.set_color(color); + m_gridlines_bolder.render_geometry(); } -void PartPlate::render_height_limit(PartPlate::HeightLimitMode mode) const +void PartPlate::render_height_limit(PartPlate::HeightLimitMode mode) { if (m_print && m_print->config().print_sequence == PrintSequence::ByObject && mode != HEIGHT_LIMIT_NONE) { // draw lower limit glsafe(::glLineWidth(3.0f * m_scale_factor)); - glsafe(::glColor4fv(HEIGHT_LIMIT_BOTTOM_COLOR.data())); - glsafe(::glVertexPointer(3, GL_FLOAT, m_height_limit_common.get_vertex_data_size(), (GLvoid*)m_height_limit_common.get_vertices_data())); - glsafe(::glDrawArrays(GL_LINES, 0, (GLsizei)m_height_limit_common.get_vertices_count())); + m_height_limit_common.set_color(HEIGHT_LIMIT_BOTTOM_COLOR); + m_height_limit_common.render_geometry(); if ((mode == HEIGHT_LIMIT_BOTTOM) || (mode == HEIGHT_LIMIT_BOTH)) { - glsafe(::glLineWidth(3.0f * m_scale_factor)); - glsafe(::glColor4fv(HEIGHT_LIMIT_BOTTOM_COLOR.data())); - glsafe(::glVertexPointer(3, GL_FLOAT, m_height_limit_bottom.get_vertex_data_size(), (GLvoid*)m_height_limit_bottom.get_vertices_data())); - glsafe(::glDrawArrays(GL_LINES, 0, (GLsizei)m_height_limit_bottom.get_vertices_count())); - } - + glsafe(::glLineWidth(3.0f * m_scale_factor)); + m_height_limit_bottom.set_color(HEIGHT_LIMIT_BOTTOM_COLOR); + m_height_limit_bottom.render_geometry(); + } // draw upper limit if ((mode == HEIGHT_LIMIT_TOP) || (mode == HEIGHT_LIMIT_BOTH)){ glsafe(::glLineWidth(3.0f * m_scale_factor)); - glsafe(::glColor4fv(HEIGHT_LIMIT_TOP_COLOR.data())); - glsafe(::glVertexPointer(3, GL_FLOAT, m_height_limit_top.get_vertex_data_size(), (GLvoid*)m_height_limit_top.get_vertices_data())); - glsafe(::glDrawArrays(GL_LINES, 0, (GLsizei)m_height_limit_top.get_vertices_count())); + m_height_limit_top.set_color(HEIGHT_LIMIT_TOP_COLOR); + m_height_limit_top.render_geometry(); } } } -void PartPlate::render_icon_texture(int position_id, int tex_coords_id, const GeometryBuffer &buffer, GLTexture &texture, unsigned int &vbo_id) const +void PartPlate::render_icon_texture(GLModel &icon, GLTexture &texture) { - if (vbo_id == 0) { - glsafe(::glGenBuffers(1, &vbo_id)); - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, vbo_id)); - glsafe(::glBufferData(GL_ARRAY_BUFFER, (GLsizeiptr)buffer.get_vertices_data_size(), (const GLvoid*)buffer.get_vertices_data(), GL_STATIC_DRAW)); - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); - } - - unsigned int stride = buffer.get_vertex_data_size(); - GLuint tex_id = (GLuint)texture.get_id(); - glsafe(::glBindTexture(GL_TEXTURE_2D, tex_id)); - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, vbo_id)); - if (position_id != -1) - glsafe(::glVertexAttribPointer(position_id, 3, GL_FLOAT, GL_FALSE, stride, (GLvoid*)(intptr_t)buffer.get_position_offset())); - if (tex_coords_id != -1) - glsafe(::glVertexAttribPointer(tex_coords_id, 2, GL_FLOAT, GL_FALSE, stride, (GLvoid*)(intptr_t)buffer.get_tex_coords_offset())); - glsafe(::glDrawArrays(GL_TRIANGLES, 0, (GLsizei)buffer.get_vertices_count())); - - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); - glsafe(::glBindTexture(GL_TEXTURE_2D, 0)); -} - -void PartPlate::render_plate_name_texture(int position_id, int tex_coords_id) -{ - if (m_name_change) { - m_name_change = false; - if (m_plate_name_vbo_id > 0) { - glsafe(::glDeleteBuffers(1, &m_plate_name_vbo_id)); - m_plate_name_vbo_id = 0; - } - if (m_plate_name_edit_vbo_id > 0) { - glsafe(::glDeleteBuffers(1, &m_plate_name_edit_vbo_id)); - m_plate_name_edit_vbo_id = 0; - } - } - if (m_plate_name_vbo_id==0) { - if (generate_plate_name_texture()) { - calc_vertex_for_plate_name(m_name_texture, m_plate_name_icon); - if (m_plate_name_edit_vbo_id > 0) { //for redo - glsafe(::glDeleteBuffers(1, &m_plate_name_edit_vbo_id)); - m_plate_name_edit_vbo_id = 0; - } - calc_vertex_for_plate_name_edit_icon(&m_name_texture, 0, m_plate_name_edit_icon); - } - else { - if (m_plate_name_edit_vbo_id==0) { - calc_vertex_for_plate_name_edit_icon(nullptr, 0, m_plate_name_edit_icon); - } - return; - } - } - - if (m_plate_name_vbo_id == 0 && m_plate_name_icon.get_vertices_data_size() > 0) { - glsafe(::glGenBuffers(1, &m_plate_name_vbo_id)); - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, m_plate_name_vbo_id)); - glsafe(::glBufferData(GL_ARRAY_BUFFER, (GLsizeiptr) m_plate_name_icon.get_vertices_data_size(), (const GLvoid *) m_plate_name_icon.get_vertices_data(), GL_STATIC_DRAW)); - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); - } - - unsigned int stride = m_plate_name_icon.get_vertex_data_size(); - GLuint tex_id = (GLuint) m_name_texture.get_id(); + GLuint tex_id = (GLuint) texture.get_id(); glsafe(::glBindTexture(GL_TEXTURE_2D, tex_id)); - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, m_plate_name_vbo_id)); - if (position_id != -1) glsafe(::glVertexAttribPointer(position_id, 3, GL_FLOAT, GL_FALSE, stride, (GLvoid *) (intptr_t) m_plate_name_icon.get_position_offset())); - if (tex_coords_id != -1) glsafe(::glVertexAttribPointer(tex_coords_id, 2, GL_FLOAT, GL_FALSE, stride, (GLvoid *) (intptr_t) m_plate_name_icon.get_tex_coords_offset())); - glsafe(::glDrawArrays(GL_TRIANGLES, 0, (GLsizei) m_plate_name_icon.get_vertices_count())); + icon.render_geometry(); + glsafe(::glBindTexture(GL_TEXTURE_2D, 0)); +} - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); +void PartPlate::render_plate_name_texture() +{ + if (m_name_change) { + m_name_change = false; + generate_plate_name_texture(); + } + if (m_name_texture.get_id() == 0) + generate_plate_name_texture(); + if (!m_plate_name_icon.is_initialized()) { + return; + } + GLuint tex_id = (GLuint) m_name_texture.get_id(); + glsafe(::glBindTexture(GL_TEXTURE_2D, tex_id)); + m_plate_name_icon.render_geometry(); glsafe(::glBindTexture(GL_TEXTURE_2D, 0)); } void PartPlate::render_icons(bool bottom, bool only_body, int hover_id) { - GLShaderProgram* shader = wxGetApp().get_shader("printbed"); - if (shader != nullptr) { - shader->start_using(); - shader->set_uniform("transparent_background", bottom); - //shader->set_uniform("svg_source", boost::algorithm::iends_with(m_partplate_list->m_del_texture.get_source(), ".svg")); - shader->set_uniform("svg_source", 0); + if (!only_body) { + if (hover_id == 1) + render_icon_texture(m_del_icon, m_partplate_list->m_del_hovered_texture); + else + render_icon_texture(m_del_icon, m_partplate_list->m_del_texture); - //if (bottom) - // glsafe(::glFrontFace(GL_CW)); - glsafe(::glDepthMask(GL_FALSE)); + if (hover_id == 2) + render_icon_texture(m_orient_icon, m_partplate_list->m_orient_hovered_texture); + else + render_icon_texture(m_orient_icon, m_partplate_list->m_orient_texture); - GLint position_id = shader->get_attrib_location("v_position"); - GLint tex_coords_id = shader->get_attrib_location("v_tex_coords"); - if (position_id != -1) { - glsafe(::glEnableVertexAttribArray(position_id)); + if (hover_id == 3) + render_icon_texture(m_arrange_icon, m_partplate_list->m_arrange_hovered_texture); + else + render_icon_texture(m_arrange_icon, m_partplate_list->m_arrange_texture); + + if (hover_id == 4) { + if (this->is_locked()) + render_icon_texture(m_lock_icon, m_partplate_list->m_locked_hovered_texture); + else + render_icon_texture(m_lock_icon, m_partplate_list->m_lockopen_hovered_texture); + } else { + if (this->is_locked()) + render_icon_texture(m_lock_icon, m_partplate_list->m_locked_texture); + else + render_icon_texture(m_lock_icon, m_partplate_list->m_lockopen_texture); } - if (tex_coords_id != -1) { - glsafe(::glEnableVertexAttribArray(tex_coords_id)); - } - render_plate_name_texture(position_id, tex_coords_id); - if (!only_body) { - if (hover_id == 1) - render_icon_texture(position_id, tex_coords_id, m_del_icon, m_partplate_list->m_del_hovered_texture, m_del_vbo_id); - else - render_icon_texture(position_id, tex_coords_id, m_del_icon, m_partplate_list->m_del_texture, m_del_vbo_id); - if (hover_id == 2) - render_icon_texture(position_id, tex_coords_id, m_orient_icon, m_partplate_list->m_orient_hovered_texture, m_orient_vbo_id); - else - render_icon_texture(position_id, tex_coords_id, m_orient_icon, m_partplate_list->m_orient_texture, m_orient_vbo_id); + if (hover_id == PLATE_NAME_ID) + render_icon_texture(m_plate_name_edit_icon, m_partplate_list->m_plate_name_edit_hovered_texture); + else + render_icon_texture(m_plate_name_edit_icon, m_partplate_list->m_plate_name_edit_texture); - if (hover_id == 3) - render_icon_texture(position_id, tex_coords_id, m_arrange_icon, m_partplate_list->m_arrange_hovered_texture, m_arrange_vbo_id); - else - render_icon_texture(position_id, tex_coords_id, m_arrange_icon, m_partplate_list->m_arrange_texture, m_arrange_vbo_id); - - if (hover_id == 4) { - if (this->is_locked()) - render_icon_texture(position_id, tex_coords_id, m_lock_icon, m_partplate_list->m_locked_hovered_texture, m_lock_vbo_id); + if (m_partplate_list->render_plate_settings) { + bool has_plate_settings = get_bed_type() != BedType::btDefault || get_print_seq() != PrintSequence::ByDefault || !get_first_layer_print_sequence().empty() || + !get_other_layers_print_sequence().empty() || has_spiral_mode_config(); + if (hover_id == 5) { + if (!has_plate_settings) + render_icon_texture(m_plate_settings_icon, m_partplate_list->m_plate_settings_hovered_texture); else - render_icon_texture(position_id, tex_coords_id, m_lock_icon, m_partplate_list->m_lockopen_hovered_texture, m_lock_vbo_id); + render_icon_texture(m_plate_settings_icon, m_partplate_list->m_plate_settings_changed_hovered_texture); } else { - if (this->is_locked()) - render_icon_texture(position_id, tex_coords_id, m_lock_icon, m_partplate_list->m_locked_texture, m_lock_vbo_id); + if (!has_plate_settings) + render_icon_texture(m_plate_settings_icon, m_partplate_list->m_plate_settings_texture); else - render_icon_texture(position_id, tex_coords_id, m_lock_icon, m_partplate_list->m_lockopen_texture, m_lock_vbo_id); - } - - if (hover_id == 6) - render_icon_texture(position_id, tex_coords_id, m_plate_name_edit_icon, m_partplate_list->m_plate_name_edit_hovered_texture, m_plate_name_edit_vbo_id); - else - render_icon_texture(position_id, tex_coords_id, m_plate_name_edit_icon, m_partplate_list->m_plate_name_edit_texture, m_plate_name_edit_vbo_id); - - if (m_partplate_list->render_plate_settings) { - bool has_plate_settings = get_bed_type() != BedType::btDefault || get_print_seq() != PrintSequence::ByDefault || !get_first_layer_print_sequence().empty() || !get_other_layers_print_sequence().empty() || has_spiral_mode_config(); - if (hover_id == 5) { - if (!has_plate_settings) - render_icon_texture(position_id, tex_coords_id, m_plate_settings_icon, m_partplate_list->m_plate_settings_hovered_texture, m_plate_settings_vbo_id); - else - render_icon_texture(position_id, tex_coords_id, m_plate_settings_icon, m_partplate_list->m_plate_settings_changed_hovered_texture, - m_plate_settings_vbo_id); - } else { - if (!has_plate_settings) - render_icon_texture(position_id, tex_coords_id, m_plate_settings_icon, m_partplate_list->m_plate_settings_texture, m_plate_settings_vbo_id); - else - render_icon_texture(position_id, tex_coords_id, m_plate_settings_icon, m_partplate_list->m_plate_settings_changed_texture, m_plate_settings_vbo_id); - } - } - - if (m_plate_index >= 0 && m_plate_index < MAX_PLATE_COUNT) { - render_icon_texture(position_id, tex_coords_id, m_plate_idx_icon, m_partplate_list->m_idx_textures[m_plate_index], m_plate_idx_vbo_id); + render_icon_texture(m_plate_settings_icon, m_partplate_list->m_plate_settings_changed_texture); } } - if (tex_coords_id != -1) - glsafe(::glDisableVertexAttribArray(tex_coords_id)); - if (position_id != -1) - glsafe(::glDisableVertexAttribArray(position_id)); - - //if (bottom) - // glsafe(::glFrontFace(GL_CCW)); - - glsafe(::glDepthMask(GL_TRUE)); - shader->stop_using(); + if (m_plate_index >= 0 && m_plate_index < MAX_PLATE_COUNT) { render_icon_texture(m_plate_idx_icon, m_partplate_list->m_idx_textures[m_plate_index]); } } + render_plate_name_texture(); } -void PartPlate::render_only_numbers(bool bottom) const +void PartPlate::render_only_numbers(bool bottom) { - GLShaderProgram* shader = wxGetApp().get_shader("printbed"); - if (shader != nullptr) { - shader->start_using(); - shader->set_uniform("transparent_background", bottom); - //shader->set_uniform("svg_source", boost::algorithm::iends_with(m_partplate_list->m_del_texture.get_source(), ".svg")); - shader->set_uniform("svg_source", 0); - - //if (bottom) - // glsafe(::glFrontFace(GL_CW)); - glsafe(::glDepthMask(GL_FALSE)); - - GLint position_id = shader->get_attrib_location("v_position"); - GLint tex_coords_id = shader->get_attrib_location("v_tex_coords"); - if (position_id != -1) { - glsafe(::glEnableVertexAttribArray(position_id)); - } - if (tex_coords_id != -1) { - glsafe(::glEnableVertexAttribArray(tex_coords_id)); - } - - if (m_plate_index >=0 && m_plate_index < MAX_PLATE_COUNT) { - render_icon_texture(position_id, tex_coords_id, m_plate_idx_icon, m_partplate_list->m_idx_textures[m_plate_index], m_plate_idx_vbo_id); - } - - if (tex_coords_id != -1) - glsafe(::glDisableVertexAttribArray(tex_coords_id)); - - if (position_id != -1) - glsafe(::glDisableVertexAttribArray(position_id)); - - //if (bottom) - // glsafe(::glFrontFace(GL_CCW)); - - glsafe(::glDepthMask(GL_TRUE)); - shader->stop_using(); + if (m_plate_index >=0 && m_plate_index < MAX_PLATE_COUNT) { + render_icon_texture(m_plate_idx_icon, m_partplate_list->m_idx_textures[m_plate_index]); } } -void PartPlate::render_rectangle_for_picking(const GeometryBuffer &buffer, const float* render_color) const -{ - unsigned int triangles_vcount = buffer.get_vertices_count(); - - //glsafe(::glDepthMask(GL_FALSE)); - glsafe(::glEnableClientState(GL_VERTEX_ARRAY)); - glsafe(::glColor4fv(render_color)); - glsafe(::glNormal3d(0.0f, 0.0f, 1.0f)); - glsafe(::glVertexPointer(3, GL_FLOAT, buffer.get_vertex_data_size(), (GLvoid*)buffer.get_vertices_data())); - glsafe(::glDrawArrays(GL_TRIANGLES, 0, (GLsizei)triangles_vcount)); - glsafe(::glDisableClientState(GL_VERTEX_ARRAY)); - //glsafe(::glDepthMask(GL_TRUE)); -} - void PartPlate::render_label(GLCanvas3D& canvas) const { std::string label = (boost::format("Plate %1%") % (m_plate_index + 1)).str(); const Camera& camera = wxGetApp().plater()->get_camera(); @@ -1287,62 +1084,25 @@ void PartPlate::render_right_arrow(const float* render_color, bool use_lighting) #endif } -void PartPlate::on_render_for_picking() const { +void PartPlate::on_render_for_picking() { //glsafe(::glDisable(GL_DEPTH_TEST)); - int hover_id = 0; - std::array color = picking_color_component(hover_id); - m_grabber_color[0] = color[0]; - m_grabber_color[1] = color[1]; - m_grabber_color[2] = color[2]; - m_grabber_color[3] = color[3]; - //render_grabber(m_grabber_color, false); - render_rectangle_for_picking(m_triangles, m_grabber_color); - hover_id = 1; - color = picking_color_component(hover_id); - m_grabber_color[0] = color[0]; - m_grabber_color[1] = color[1]; - m_grabber_color[2] = color[2]; - m_grabber_color[3] = color[3]; - //render_left_arrow(m_grabber_color, false); - render_rectangle_for_picking(m_del_icon, m_grabber_color); - hover_id = 2; - color = picking_color_component(hover_id); - m_grabber_color[0] = color[0]; - m_grabber_color[1] = color[1]; - m_grabber_color[2] = color[2]; - m_grabber_color[3] = color[3]; - render_rectangle_for_picking(m_orient_icon, m_grabber_color); - hover_id = 3; - color = picking_color_component(hover_id); - m_grabber_color[0] = color[0]; - m_grabber_color[1] = color[1]; - m_grabber_color[2] = color[2]; - m_grabber_color[3] = color[3]; - render_rectangle_for_picking(m_arrange_icon, m_grabber_color); - hover_id = 4; - color = picking_color_component(hover_id); - m_grabber_color[0] = color[0]; - m_grabber_color[1] = color[1]; - m_grabber_color[2] = color[2]; - m_grabber_color[3] = color[3]; - //render_right_arrow(m_grabber_color, false); - render_rectangle_for_picking(m_lock_icon, m_grabber_color); - hover_id = 5; - color = picking_color_component(hover_id); - m_grabber_color[0] = color[0]; - m_grabber_color[1] = color[1]; - m_grabber_color[2] = color[2]; - m_grabber_color[3] = color[3]; - if (m_partplate_list->render_plate_settings) - render_rectangle_for_picking(m_plate_settings_icon, m_grabber_color); - hover_id = 6; - color = picking_color_component(hover_id); - m_grabber_color[0] = color[0]; - m_grabber_color[1] = color[1]; - m_grabber_color[2] = color[2]; - m_grabber_color[3] = color[3]; - // render_left_arrow(m_grabber_color, false); - render_rectangle_for_picking(m_plate_name_edit_icon, m_grabber_color); + const Camera &camera = wxGetApp().plater()->get_camera(); + auto view_mat = camera.get_view_matrix(); + auto proj_mat = camera.get_projection_matrix(); + + GLShaderProgram *shader = wxGetApp().get_shader("flat"); + shader->start_using(); + shader->set_uniform("view_model_matrix", view_mat); + shader->set_uniform("projection_matrix", proj_mat); + std::vector gl_models = {&m_triangles, &m_del_icon, &m_orient_icon, &m_arrange_icon, &m_lock_icon, &m_plate_settings_icon, + &m_plate_name_edit_icon}; + for (size_t i = 0; i < gl_models.size(); i++) { + int hover_id = i; + std::array color = picking_color_component(hover_id); + gl_models[i]->set_color(-1, color); + gl_models[i]->render_geometry(); + } + shader->stop_using(); } std::array PartPlate::picking_color_component(int idx) const @@ -1902,6 +1662,8 @@ bool PartPlate::generate_plate_name_texture() BOOST_LOG_TRIVIAL(error) << "PartPlate::generate_plate_name_texture(): generate_from_text_string() failed"; return false; } + calc_vertex_for_plate_name(m_name_texture, m_plate_name_icon); + calc_vertex_for_plate_name_edit_icon(&m_name_texture, 0, m_plate_name_edit_icon); return true; } @@ -2549,7 +2311,9 @@ void PartPlate::set_logo_box_by_bed(const BoundingBoxf3& box) m_cur_bed_boundingbox = box; ExPolygon logo_poly; generate_logo_polygon(logo_poly, box); - if (!m_logo_triangles.set_from_triangles(triangulate_expolygon_2f(logo_poly, NORMALS_UP), GROUND_Z + 0.02f)) { + auto triangles = triangulate_expolygon_2f(logo_poly, NORMALS_UP); + m_logo_triangles.reset(); + if (!m_logo_triangles.init_model_from_poly(triangles, GROUND_Z + 0.01f)) { BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ":error :Unable to create logo triangles in set_logo_box_by_bed\n"; return; } @@ -2722,14 +2486,16 @@ bool PartPlate::set_shape(const Pointfs& shape, const Pointfs& exclude_areas, Ve ExPolygon logo_poly; generate_logo_polygon(logo_poly); - if (!m_logo_triangles.set_from_triangles(triangulate_expolygon_2f(logo_poly, NORMALS_UP), GROUND_Z+0.02f)) + auto triangles = triangulate_expolygon_2f(logo_poly, NORMALS_UP); + m_logo_triangles.reset(); + if (!m_logo_triangles.init_model_from_poly(triangles, GROUND_Z + 0.01f)) BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ":Unable to create logo triangles\n"; else { ; } if (m_partplate_list && m_partplate_list->m_bed3d && !m_partplate_list->m_bed3d->get_model_filename().empty()) { auto cur_bed = m_partplate_list->m_bed3d; - set_logo_box_by_bed(cur_bed->get_model().get_bounding_box().transformed(Geometry::translation_transform(m_origin))); + set_logo_box_by_bed(cur_bed->get_cur_bed_model_box()); } ExPolygon poly; @@ -2811,35 +2577,53 @@ bool PartPlate::intersects(const BoundingBoxf3& bb) const void PartPlate::render(bool bottom, bool only_body, bool force_background_color, HeightLimitMode mode, int hover_id, bool render_cali) { - glsafe(::glEnable(GL_DEPTH_TEST)); - glsafe(::glEnable(GL_BLEND)); - glsafe(::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); - glsafe(::glEnableClientState(GL_VERTEX_ARRAY)); + glsafe(::glEnable(GL_DEPTH_TEST)); + glsafe(::glEnable(GL_BLEND)); + glsafe(::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); + glsafe(::glDepthMask(GL_FALSE)); + const Camera &camera = wxGetApp().plater()->get_camera(); + auto view_mat = camera.get_view_matrix(); + auto proj_mat = camera.get_projection_matrix(); + { + GLShaderProgram *shader = wxGetApp().get_shader("flat"); + shader->start_using(); + shader->set_uniform("view_model_matrix", view_mat); + shader->set_uniform("projection_matrix", proj_mat); - if (!bottom) { - // draw background - render_background(force_background_color); + if (!bottom) { + // draw background + render_background(force_background_color); + render_exclude_area(force_background_color); + } + render_grid(bottom); + render_height_limit(mode); - render_exclude_area(force_background_color); - } - - 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); - else - render_logo(bottom); - } - - render_height_limit(mode); - - render_icons(bottom, only_body, hover_id); - if (!force_background_color){ - render_only_numbers(bottom); - } - glsafe(::glDisableClientState(GL_VERTEX_ARRAY)); - glsafe(::glDisable(GL_BLEND)); + shader->stop_using(); + } + { + GLShaderProgram *shader = wxGetApp().get_shader("printbed"); + shader->start_using(); + shader->set_uniform("view_model_matrix", view_mat); + shader->set_uniform("projection_matrix", proj_mat); + shader->set_uniform("svg_source", 0); + shader->set_uniform("transparent_background", 0); + if (!bottom && m_selected && !force_background_color) {//bed all icon + if (m_partplate_list) + render_logo(bottom, m_partplate_list->render_cali_logo && render_cali); + else + render_logo(bottom); + } + { + shader->set_uniform("transparent_background", bottom); + render_icons(bottom, only_body, hover_id); + if (!force_background_color) { + render_only_numbers(bottom); + } + } + shader->stop_using(); + } + glsafe(::glDepthMask(GL_TRUE)); + glsafe(::glDisable(GL_BLEND)); //if (with_label) { // render_label(canvas); @@ -5555,17 +5339,9 @@ void PartPlateList::BedTextureInfo::TexturePart::update_buffer() } } - if (!buffer) - buffer = new GeometryBuffer(); - - if (buffer->set_from_triangles(triangulate_expolygon_2f(poly, NORMALS_UP), GROUND_Z + 0.02f)) { - release_vbo(); - unsigned int* vbo_id_ptr = const_cast(&vbo_id); - glsafe(::glGenBuffers(1, vbo_id_ptr)); - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, *vbo_id_ptr)); - glsafe(::glBufferData(GL_ARRAY_BUFFER, (GLsizeiptr)buffer->get_vertices_data_size(), (const GLvoid*)buffer->get_vertices_data(), GL_STATIC_DRAW)); - glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); - } else { + if (!buffer) buffer = new GLModel(); + buffer->reset(); + if (!buffer->init_model_from_poly(triangulate_expolygon_2f(poly, NORMALS_UP), GROUND_Z + 0.02f)) { BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ":Unable to create buffer triangles\n"; } } diff --git a/src/slic3r/GUI/PartPlate.hpp b/src/slic3r/GUI/PartPlate.hpp index 3f22fdbf0..32c792973 100644 --- a/src/slic3r/GUI/PartPlate.hpp +++ b/src/slic3r/GUI/PartPlate.hpp @@ -128,32 +128,34 @@ private: Slic3r::Geometry::Transformation position; std::vector positions; unsigned int m_vbo_id{ 0 }; - GeometryBuffer m_triangles; - GeometryBuffer m_exclude_triangles; - GeometryBuffer m_logo_triangles; - GeometryBuffer m_gridlines; - GeometryBuffer m_gridlines_bolder; - GeometryBuffer m_height_limit_common; - GeometryBuffer m_height_limit_bottom; - GeometryBuffer m_height_limit_top; - GeometryBuffer m_del_icon; - GeometryBuffer m_plate_name_edit_icon; + GLModel m_triangles; + GLModel m_exclude_triangles; + GLModel m_logo_triangles; + GLModel m_gridlines; + GLModel m_gridlines_bolder; + GLModel m_height_limit_common; + GLModel m_height_limit_bottom; + GLModel m_height_limit_top; + GLModel m_del_icon; + GLModel m_plate_name_edit_icon; //GeometryBuffer m_del_and_background_icon; mutable unsigned int m_del_vbo_id{ 0 }; - GeometryBuffer m_arrange_icon; + GLModel m_arrange_icon; mutable unsigned int m_arrange_vbo_id{ 0 }; - GeometryBuffer m_orient_icon; + GLModel m_orient_icon; mutable unsigned int m_orient_vbo_id{ 0 }; - GeometryBuffer m_lock_icon; + GLModel m_lock_icon; mutable unsigned int m_lock_vbo_id{ 0 }; - GeometryBuffer m_plate_settings_icon; + GLModel m_plate_settings_icon; mutable unsigned int m_plate_settings_vbo_id{ 0 }; - GeometryBuffer m_plate_idx_icon; + GLModel m_plate_filament_map_icon; + mutable unsigned int m_plate_filament_map_vbo_id{0}; + GLModel m_plate_idx_icon; + mutable unsigned int m_plate_idx_vbo_id{ 0 }; mutable unsigned int m_plate_name_edit_vbo_id{0}; GLTexture m_texture; - mutable float m_grabber_color[4]; float m_scale_factor{ 1.0f }; GLUquadricObject* m_quadric; int m_hover_id; @@ -166,7 +168,7 @@ private: // part plate name std::string m_name; // utf8 string bool m_name_change = false; - GeometryBuffer m_plate_name_icon; + GLModel m_plate_name_icon; mutable unsigned int m_plate_name_vbo_id{0}; GLTexture m_name_texture; @@ -181,37 +183,42 @@ private: void calc_exclude_triangles(const ExPolygon& poly); void calc_gridlines(const ExPolygon& poly, const BoundingBox& pp_bbox); void calc_height_limit(); - void calc_vertex_for_number(int index, bool one_number, GeometryBuffer &buffer); - void calc_vertex_for_plate_name(GLTexture& texture, GeometryBuffer &buffer); - void calc_vertex_for_plate_name_edit_icon(GLTexture *texture, int index, GeometryBuffer &buffer); - void calc_vertex_for_icons(int index, GeometryBuffer &buffer); + + void calc_vertex_for_number(int index, bool one_number, GLModel &gl_model); + void calc_vertex_for_plate_name(GLTexture &texture, GLModel &buffer); + void calc_vertex_for_plate_name_edit_icon(GLTexture *texture, int index, GLModel &buffer); + void calc_vertex_for_icons(int index, GLModel &gl_model); void calc_vertex_for_icons_background(int icon_count, GeometryBuffer &buffer); - void render_background(bool force_default_color = false) const; + + void render_background(bool force_default_color = false); void render_logo(bool bottom, bool render_cali = true); - void render_logo_texture(GLTexture& logo_texture, const GeometryBuffer& logo_buffer, bool bottom, unsigned int vbo_id) const; - void render_exclude_area(bool force_default_color) const; + void render_logo_texture(GLTexture &logo_texture, GLModel &logo_buffer, bool bottom); + void render_exclude_area(bool force_default_color); //void render_background_for_picking(const float* render_color) const; - void render_grid(bool bottom) const; - void render_height_limit(PartPlate::HeightLimitMode mode = HEIGHT_LIMIT_BOTH) const; + + void render_grid(bool bottom); + void render_height_limit(PartPlate::HeightLimitMode mode = HEIGHT_LIMIT_BOTH); void render_label(GLCanvas3D& canvas) const; void render_grabber(const float* render_color, bool use_lighting) const; void render_face(float x_size, float y_size) const; void render_arrows(const float* render_color, bool use_lighting) const; void render_left_arrow(const float* render_color, bool use_lighting) const; void render_right_arrow(const float* render_color, bool use_lighting) const; - void render_icon_texture(int position_id, int tex_coords_id, const GeometryBuffer &buffer, GLTexture &texture, unsigned int &vbo_id) const; - void render_plate_name_texture(int position_id, int tex_coords_id); + + void render_icon_texture(GLModel &buffer, GLTexture &texture); + void render_plate_name_texture(); void render_icons(bool bottom, bool only_body = false, int hover_id = -1); - void render_only_numbers(bool bottom) const; - void render_rectangle_for_picking(const GeometryBuffer &buffer, const float* render_color) const; - void on_render_for_picking() const; + + void render_only_numbers(bool bottom); + void on_render_for_picking(); std::array picking_color_component(int idx) const; void release_opengl_resource(); public: static const unsigned int PLATE_BASE_ID = 255 * 255 * 253; - static const unsigned int PLATE_NAME_HOVER_ID = 6; + //static const unsigned int PLATE_FILAMENT_MAP_ID = 6;//todo static const unsigned int GRABBER_COUNT = 7; + static const unsigned int PLATE_NAME_ID = GRABBER_COUNT-1; static std::array SELECT_COLOR; static std::array UNSELECT_COLOR; @@ -375,7 +382,7 @@ public: bool intersects(const BoundingBoxf3& bb) const; void render(bool bottom, bool only_body = false, bool force_background_color = false, HeightLimitMode mode = HEIGHT_LIMIT_NONE, int hover_id = -1, bool render_cali = false); - void render_for_picking() const { on_render_for_picking(); } + void render_for_picking() { on_render_for_picking(); } void set_selected(); void set_unselected(); void set_hover_id(int id) { m_hover_id = id; } @@ -619,7 +626,7 @@ public: std::string filename; GLTexture* texture { nullptr }; Vec2d offset; - GeometryBuffer* buffer { nullptr }; + GLModel* buffer{nullptr}; TexturePart(float xx, float yy, float ww, float hh, std::string file){ x = xx; y = yy; w = ww; h = hh; diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index d37f9c6b4..34b1a94d8 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -13388,7 +13388,7 @@ int Plater::select_plate_by_hover_id(int hover_id, bool right_click, bool isModi int action, plate_index; plate_index = hover_id / PartPlate::GRABBER_COUNT; - action = isModidyPlateName ? PartPlate::PLATE_NAME_HOVER_ID : hover_id % PartPlate::GRABBER_COUNT; + action = isModidyPlateName ? PartPlate::PLATE_NAME_ID : hover_id % PartPlate::GRABBER_COUNT; BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": enter, hover_id %1%, plate_index %2%, action %3%")%hover_id % plate_index %action; if (action == 0)