Tech ENABLE_GLBEGIN_GLEND_REMOVAL - Removed Slic3r::GUI::GeometryBuffer from 3DBed.hpp and replaced with GLModel

(cherry picked from commit prusa3d/PrusaSlicer@6b041429f6)
This commit is contained in:
enricoturri1966 2023-10-21 23:35:34 +08:00 committed by Noisyfox
parent 499b9d1be8
commit f9de4ec399
8 changed files with 354 additions and 442 deletions

View file

@ -151,7 +151,6 @@ PartPlate::~PartPlate()
clear();
//if (m_quadric != nullptr)
// ::gluDeleteQuadric(m_quadric);
release_opengl_resource();
//boost::nowide::remove(m_tmp_gcode_path.c_str());
}
@ -170,7 +169,6 @@ void PartPlate::init()
m_print_index = -1;
m_print = nullptr;
m_plate_name_vbo_id = 0;
}
BedType PartPlate::get_bed_type(bool load_from_project) const
@ -333,17 +331,71 @@ 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)
{
m_triangles.reset();
if (!init_model_from_poly(m_triangles, poly, 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))
void PartPlate::calc_exclude_triangles(const ExPolygon &poly)
{
m_exclude_triangles.reset();
if (!init_model_from_poly(m_exclude_triangles, poly, GROUND_Z))
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ":Unable to create exclude triangles\n";
}
static bool init_model_from_lines(GLModel &model, const Lines &lines, float z)
{
const GLModel::Geometry::EIndexType index_type = (lines.size() < 65536 / 2) ? GLModel::Geometry::EIndexType::USHORT : GLModel::Geometry::EIndexType::UINT;
GLModel::Geometry init_data;
init_data.format = { GLModel::Geometry::EPrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P3, index_type };
for (const auto &l : lines) {
init_data.add_vertex(Vec3f(unscale<float>(l.a.x()), unscale<float>(l.a.y()), z));
init_data.add_vertex(Vec3f(unscale<float>(l.b.x()), unscale<float>(l.b.y()), z));
const unsigned int vertices_counter = (unsigned int)init_data.vertices_count();
if (index_type == GLModel::Geometry::EIndexType::USHORT)
init_data.add_ushort_line((unsigned short)vertices_counter - 2, (unsigned short)vertices_counter - 1);
else
init_data.add_uint_line(vertices_counter - 2, vertices_counter - 1);
}
model.init_from(std::move(init_data));
return true;
}
static bool init_model_from_lines(GLModel &model, const Lines3 &lines)
{
const GLModel::Geometry::EIndexType index_type = (lines.size() < 65536 / 2) ? GLModel::Geometry::EIndexType::USHORT :
GLModel::Geometry::EIndexType::UINT;
GLModel::Geometry init_data;
init_data.format = {GLModel::Geometry::EPrimitiveType::Lines, GLModel::Geometry::EVertexLayout::P3, index_type};
for (const auto &l : lines) {
init_data.add_vertex(Vec3f(unscale<float>(l.a.x()), unscale<float>(l.a.y()), unscale<float>(l.a.z())));
init_data.add_vertex(Vec3f(unscale<float>(l.b.x()), unscale<float>(l.b.y()), unscale<float>(l.b.z())));
const unsigned int vertices_counter = (unsigned int) init_data.vertices_count();
if (index_type == GLModel::Geometry::EIndexType::USHORT)
init_data.add_ushort_line((unsigned short) vertices_counter - 2, (unsigned short) vertices_counter - 1);
else
init_data.add_uint_line(vertices_counter - 2, vertices_counter - 1);
}
model.init_from(std::move(init_data));
return true;
}
void PartPlate::calc_gridlines(const ExPolygon& poly, const BoundingBox& pp_bbox) {
m_gridlines.reset();
m_gridlines_bolder.reset();
Polylines axes_lines, axes_lines_bolder;
int count = 0;
for (coord_t x = pp_bbox.min(0); x <= pp_bbox.max(0); x += scale_(10.0)) {
@ -379,14 +431,18 @@ 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_GRIDLINE))
if (!init_model_from_lines(m_gridlines, gridlines, GROUND_Z_GRIDLINE))
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << "Unable to create bed grid lines\n";
if (!m_gridlines_bolder.set_from_lines(gridlines_bolder, GROUND_Z_GRIDLINE))
if (!init_model_from_lines(m_gridlines_bolder, gridlines_bolder, GROUND_Z_GRIDLINE))
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << "Unable to create bed grid lines\n";
}
void PartPlate::calc_height_limit() {
m_height_limit_common.reset();
m_height_limit_bottom.reset();
m_height_limit_top.reset();
Lines3 bottom_h_lines, top_lines, top_h_lines, common_lines;
int shape_count = m_shape.size();
float first_z = 0.02f;
@ -418,18 +474,20 @@ 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))
if (!init_model_from_lines(m_height_limit_common, 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))
if (!init_model_from_lines(m_height_limit_bottom, 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))
if (!init_model_from_lines(m_height_limit_top, 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 &buffer)
{
buffer.reset();
ExPolygon poly;
#if 0 //in the up area
Vec2d& p = m_shape[2];
@ -449,13 +507,14 @@ void PartPlate::calc_vertex_for_number(int index, bool one_number, GeometryBuffe
poly.contour.append({ scale_(p(0) + PARTPLATE_ICON_GAP_LEFT + PARTPLATE_ICON_SIZE - offset_x), scale_(p(1) + PARTPLATE_ICON_SIZE - PARTPLATE_TEXT_OFFSET_Y)});
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))
if (!init_model_from_poly(buffer, poly, 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 &buffer)
{
buffer.reset();
ExPolygon poly;
auto bed_ext = get_extents(m_shape);
Vec2d p = bed_ext[2];
@ -468,13 +527,14 @@ void PartPlate::calc_vertex_for_icons(int index, GeometryBuffer &buffer)
poly.contour.append({ scale_(p(0) + PARTPLATE_ICON_GAP_LEFT + PARTPLATE_ICON_SIZE), scale_(p(1) - index * (PARTPLATE_ICON_SIZE + PARTPLATE_ICON_GAP_Y)- PARTPLATE_ICON_GAP_TOP)});
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))
if (!init_model_from_poly(buffer, poly, GROUND_Z))
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << "Unable to generate geometry buffers for icons\n";
}
void PartPlate::calc_vertex_for_icons_background(int icon_count, GeometryBuffer &buffer)
void PartPlate::calc_vertex_for_icons_background(int icon_count, GLModel &buffer)
{
buffer.reset();
ExPolygon poly;
auto bed_ext = get_extents(m_shape);
Vec2d p = bed_ext[2];
@ -484,38 +544,36 @@ void PartPlate::calc_vertex_for_icons_background(int icon_count, GeometryBuffer
poly.contour.append({ scale_(p(0) + PARTPLATE_ICON_GAP_LEFT + PARTPLATE_ICON_SIZE), scale_(p(1) - PARTPLATE_ICON_GAP_TOP)});
poly.contour.append({ scale_(p(0) + PARTPLATE_ICON_GAP_LEFT), scale_(p(1) - PARTPLATE_ICON_GAP_TOP) });
auto triangles = triangulate_expolygon_2f(poly, NORMALS_UP);
if (!buffer.set_from_triangles(triangles, GROUND_Z))
if (!init_model_from_poly(buffer, poly, GROUND_Z))
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));
m_triangles.set_color(color);
m_triangles.render();
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()) {
@ -523,7 +581,7 @@ void PartPlate::render_logo_texture(GLTexture &logo_texture, const GeometryBuffe
logo_texture.send_compressed_data_to_gpu();
}
if (logo_buffer.get_vertices_count() > 0) {
if (logo_buffer.is_initialized()) {
GLShaderProgram* shader = wxGetApp().get_shader("printbed");
if (shader != nullptr) {
shader->start_using();
@ -532,44 +590,25 @@ void PartPlate::render_logo_texture(GLTexture &logo_texture, const GeometryBuffe
//glsafe(::glEnable(GL_DEPTH_TEST));
glsafe(::glDepthMask(GL_FALSE));
glsafe(::glEnable(GL_BLEND));
glsafe(::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));
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();
glsafe(::glBindTexture(GL_TEXTURE_2D, 0));
if (bottom)
glsafe(::glFrontFace(GL_CCW));
glsafe(::glDisable(GL_BLEND));
glsafe(::glDepthMask(GL_TRUE));
shader->stop_using();
@ -577,7 +616,7 @@ void PartPlate::render_logo_texture(GLTexture &logo_texture, const GeometryBuffe
}
}
void PartPlate::render_logo(bool bottom, bool render_cali) const
void PartPlate::render_logo(bool bottom, bool render_cali)
{
if (!m_partplate_list->render_bedtype_logo) {
// render third-party printer texture logo
@ -643,15 +682,8 @@ void PartPlate::render_logo(bool bottom, bool render_cali) const
//canvas.request_extra_frame();
}
if (m_vbo_id == 0) {
unsigned int* vbo_id_ptr = const_cast<unsigned int*>(&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_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);
return;
}
@ -669,7 +701,7 @@ void PartPlate::render_logo(bool bottom, bool render_cali) const
// 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()) {
@ -678,8 +710,7 @@ void PartPlate::render_logo(bool bottom, bool render_cali) const
}
render_logo_texture(*(part.texture),
*(part.buffer),
bottom,
part.vbo_id);
bottom);
}
}
}
@ -688,29 +719,27 @@ void PartPlate::render_logo(bool bottom, bool render_cali) const
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 {
void PartPlate::render_exclude_area(bool force_default_color) {
if (force_default_color) //for thumbnail case
return;
unsigned int triangles_vcount = m_exclude_triangles.get_vertices_count();
ColorRGBA select_color{ 0.765f, 0.7686f, 0.7686f, 1.0f };
ColorRGBA unselect_color{ 0.9f, 0.9f, 0.9f, 1.0f };
ColorRGBA default_color{ 0.9f, 0.9f, 0.9f, 1.0f };
//ColorRGBA default_color{ 0.9f, 0.9f, 0.9f, 1.0f };
// draw exclude area
glsafe(::glDepthMask(GL_FALSE));
@ -722,9 +751,8 @@ void PartPlate::render_exclude_area(bool force_default_color) const {
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();
glsafe(::glDepthMask(GL_TRUE));
}
@ -741,99 +769,68 @@ void PartPlate::render_exclude_area(bool force_default_color) const {
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();
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()));
m_gridlines_bolder.set_color(color);
m_gridlines_bolder.render();
}
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();
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()));
m_height_limit_bottom.set_color(HEIGHT_LIMIT_BOTTOM_COLOR);
m_height_limit_bottom.render();
}
// 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()));
glsafe(::glLineWidth(3.0f * m_scale_factor));
m_height_limit_top.set_color(HEIGHT_LIMIT_TOP_COLOR);
m_height_limit_top.render();
}
}
}
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 &buffer, 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));
buffer.render();
glsafe(::glBindTexture(GL_TEXTURE_2D, 0));
}
void PartPlate::render_plate_name_texture(int position_id, int tex_coords_id)
void PartPlate::render_plate_name_texture()
{
if (m_name_texture.get_id() == 0)
generate_plate_name_texture();
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();
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()));
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0));
m_plate_name_icon.render();
glsafe(::glBindTexture(GL_TEXTURE_2D, 0));
}
@ -865,92 +862,72 @@ void PartPlate::render_icons(bool bottom, bool only_name, int hover_id)
// 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));
}
glsafe(::glEnable(GL_BLEND));
glsafe(::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));
if (!only_name) {
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);
render_icon_texture(m_del_icon, m_partplate_list->m_del_hovered_texture);
show_tooltip(_u8L("Remove current plate (if not last one)"));
}
else
render_icon_texture(position_id, tex_coords_id, m_del_icon, m_partplate_list->m_del_texture,
m_del_vbo_id);
render_icon_texture(m_del_icon, m_partplate_list->m_del_texture);
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);
render_icon_texture(m_orient_icon, m_partplate_list->m_orient_hovered_texture);
show_tooltip(_u8L("Auto orient objects on current plate"));
}
else
render_icon_texture(position_id, tex_coords_id, m_orient_icon, m_partplate_list->m_orient_texture,
m_orient_vbo_id);
render_icon_texture(m_orient_icon, m_partplate_list->m_orient_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);
render_icon_texture(m_arrange_icon, m_partplate_list->m_arrange_hovered_texture);
show_tooltip(_u8L("Arrange objects on current plate"));
}
else
render_icon_texture(position_id, tex_coords_id, m_arrange_icon, m_partplate_list->m_arrange_texture,
m_arrange_vbo_id);
render_icon_texture(m_arrange_icon, m_partplate_list->m_arrange_texture);
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);
render_icon_texture(m_lock_icon,
m_partplate_list->m_locked_hovered_texture);
show_tooltip(_u8L("Unlock current plate"));
}
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_lock_icon,
m_partplate_list->m_lockopen_hovered_texture);
show_tooltip(_u8L("Lock current plate"));
}
} 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);
render_icon_texture(m_lock_icon, m_partplate_list->m_locked_texture);
else
render_icon_texture(position_id, tex_coords_id, m_lock_icon, m_partplate_list->m_lockopen_texture,
m_lock_vbo_id);
render_icon_texture(m_lock_icon, m_partplate_list->m_lockopen_texture);
}
if (m_partplate_list->render_plate_settings) {
if (hover_id == 5) {
if (get_bed_type() == BedType::btDefault && get_print_seq() == PrintSequence::ByDefault && get_first_layer_print_sequence().empty())
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);
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_plate_settings_icon,
m_partplate_list->m_plate_settings_changed_hovered_texture,
m_plate_settings_vbo_id);
render_icon_texture(m_plate_settings_icon, m_partplate_list->m_plate_settings_changed_hovered_texture);
show_tooltip(_u8L("Customize current plate"));
} else {
if (get_bed_type() == BedType::btDefault && get_print_seq() == PrintSequence::ByDefault && get_first_layer_print_sequence().empty())
render_icon_texture(position_id, tex_coords_id, m_plate_settings_icon, m_partplate_list->m_plate_settings_texture, m_plate_settings_vbo_id);
render_icon_texture(m_plate_settings_icon, m_partplate_list->m_plate_settings_texture);
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);
render_icon_texture(m_plate_settings_icon, m_partplate_list->m_plate_settings_changed_texture);
}
}
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_idx_icon, m_partplate_list->m_idx_textures[m_plate_index]);
}
}
render_plate_name_texture(position_id, tex_coords_id);
if (tex_coords_id != -1)
glsafe(::glDisableVertexAttribArray(tex_coords_id));
render_plate_name_texture();
if (position_id != -1)
glsafe(::glDisableVertexAttribArray(position_id));
glsafe(::glDisable(GL_BLEND));
//if (bottom)
// glsafe(::glFrontFace(GL_CCW));
@ -960,7 +937,7 @@ void PartPlate::render_icons(bool bottom, bool only_name, int hover_id)
}
}
void PartPlate::render_only_numbers(bool bottom) const
void PartPlate::render_only_numbers(bool bottom)
{
GLShaderProgram* shader = wxGetApp().get_shader("printbed");
if (shader != nullptr) {
@ -973,24 +950,14 @@ void PartPlate::render_only_numbers(bool bottom) const
// 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));
}
glsafe(::glEnable(GL_BLEND));
glsafe(::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));
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_idx_icon, m_partplate_list->m_idx_textures[m_plate_index]);
}
if (tex_coords_id != -1)
glsafe(::glDisableVertexAttribArray(tex_coords_id));
if (position_id != -1)
glsafe(::glDisableVertexAttribArray(position_id));
glsafe(::glDisable(GL_BLEND));
//if (bottom)
// glsafe(::glFrontFace(GL_CCW));
@ -1000,20 +967,24 @@ void PartPlate::render_only_numbers(bool bottom) const
}
}
void PartPlate::render_rectangle_for_picking(const GeometryBuffer &buffer, const ColorRGBA render_color) const
void PartPlate::render_rectangle_for_picking(GLModel &buffer, const ColorRGBA render_color)
{
unsigned int triangles_vcount = buffer.get_vertices_count();
glsafe(::glDisable(GL_DEPTH_TEST));
//glsafe(::glDepthMask(GL_FALSE));
glsafe(::glEnableClientState(GL_VERTEX_ARRAY));
glsafe(::glColor4fv(render_color.data()));
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));
GLShaderProgram *shader = wxGetApp().get_shader("flat");
if (shader != nullptr) {
shader->start_using();
//glsafe(::glDepthMask(GL_FALSE));
buffer.set_color(render_color);
buffer.render();
//glsafe(::glDepthMask(GL_TRUE));
shader->stop_using();
}
}
/*
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();
@ -1229,8 +1200,9 @@ void PartPlate::render_right_arrow(const ColorRGBA render_color, bool use_lighti
glsafe(::glDisable(GL_LIGHTING));
#endif
}
*/
void PartPlate::on_render_for_picking() const {
void PartPlate::on_render_for_picking() {
//glsafe(::glDisable(GL_DEPTH_TEST));
int hover_id = 0;
ColorRGBA color = picking_color_component(hover_id);
@ -1274,42 +1246,6 @@ ColorRGBA PartPlate::picking_color_component(int idx) const
};
}
void PartPlate::release_opengl_resource()
{
if (m_vbo_id > 0) {
glsafe(::glDeleteBuffers(1, &m_vbo_id));
m_vbo_id = 0;
}
if (m_del_vbo_id > 0) {
glsafe(::glDeleteBuffers(1, &m_del_vbo_id));
m_del_vbo_id = 0;
}
if (m_orient_vbo_id > 0) {
glsafe(::glDeleteBuffers(1, &m_orient_vbo_id));
m_orient_vbo_id = 0;
}
if (m_arrange_vbo_id > 0) {
glsafe(::glDeleteBuffers(1, &m_arrange_vbo_id));
m_arrange_vbo_id = 0;
}
if (m_lock_vbo_id > 0) {
glsafe(::glDeleteBuffers(1, &m_lock_vbo_id));
m_lock_vbo_id = 0;
}
if (m_plate_settings_vbo_id > 0) {
glsafe(::glDeleteBuffers(1, &m_plate_settings_vbo_id));
m_plate_settings_vbo_id = 0;
}
if (m_plate_idx_vbo_id > 0) {
glsafe(::glDeleteBuffers(1, &m_plate_idx_vbo_id));
m_plate_idx_vbo_id = 0;
}
if (m_plate_name_vbo_id > 0) {
glsafe(::glDeleteBuffers(1, &m_plate_name_vbo_id));
m_plate_name_vbo_id = 0;
}
}
std::vector<int> PartPlate::get_extruders(bool conside_custom_gcode) const
{
std::vector<int> plate_extruders;
@ -1746,6 +1682,8 @@ Vec3d PartPlate::get_center_origin()
void PartPlate::generate_plate_name_texture()
{
m_plate_name_icon.reset();
// generate m_name_texture texture from m_name with generate_from_text_string
m_name_texture.reset();
auto text = m_name.empty()? _L("Untitled") : from_u8(m_name);
@ -1768,14 +1706,8 @@ void PartPlate::generate_plate_name_texture()
poly.contour.append({ scale_(p(0) + PARTPLATE_ICON_GAP_LEFT + w - offset_x), scale_(p(1) - PARTPLATE_TEXT_OFFSET_Y)});
poly.contour.append({ scale_(p(0) + PARTPLATE_ICON_GAP_LEFT + offset_x), scale_(p(1) - PARTPLATE_TEXT_OFFSET_Y) });
auto triangles = triangulate_expolygon_2f(poly, NORMALS_UP);
if (!m_plate_name_icon.set_from_triangles(triangles, GROUND_Z))
if (!init_model_from_poly(m_plate_name_icon, poly, GROUND_Z))
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << "Unable to generate geometry buffers for icons\n";
if (m_plate_name_vbo_id > 0) {
glsafe(::glDeleteBuffers(1, &m_plate_name_vbo_id));
m_plate_name_vbo_id = 0;
}
}
void PartPlate::set_plate_name(const std::string& name)
{
@ -2481,11 +2413,9 @@ 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))
m_logo_triangles.reset();
if (!init_model_from_poly(m_logo_triangles, logo_poly, GROUND_Z + 0.02f))
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ":Unable to create logo triangles\n";
else {
;
}
ExPolygon poly;
/*for (const Vec2d& p : m_shape) {
@ -2519,8 +2449,6 @@ bool PartPlate::set_shape(const Pointfs& shape, const Pointfs& exclude_areas, Ve
calc_height_limit();
release_opengl_resource();
return true;
}
@ -2567,40 +2495,45 @@ 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));
GLShaderProgram *shader = wxGetApp().get_shader("flat");
if (shader != nullptr) {
shader->start_using();
glsafe(::glEnable(GL_DEPTH_TEST));
glsafe(::glEnable(GL_BLEND));
glsafe(::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));
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_exclude_area(force_background_color);
}
render_grid(bottom);
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_height_limit(mode);
glsafe(::glDisable(GL_BLEND));
render_icons(bottom, only_body, hover_id);
if (!force_background_color){
render_only_numbers(bottom);
}
glsafe(::glDisableClientState(GL_VERTEX_ARRAY));
glsafe(::glDisable(GL_BLEND));
// if (with_label) {
// render_label(canvas);
// }
//if (with_label) {
// render_label(canvas);
//}
glsafe(::glDisable(GL_DEPTH_TEST));
glsafe(::glDisable(GL_DEPTH_TEST));
shader->stop_using();
}
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_icons(bottom, only_body, hover_id);
if (!force_background_color) {
render_only_numbers(bottom);
}
}
void PartPlate::set_selected() {
@ -3162,10 +3095,6 @@ void PartPlateList::release_icon_textures()
part.texture->reset();
delete part.texture;
}
if (part.vbo_id != 0) {
glsafe(::glDeleteBuffers(1, &part.vbo_id));
part.vbo_id = 0;
}
if (part.buffer) {
delete part.buffer;
}
@ -5078,19 +5007,11 @@ void PartPlateList::BedTextureInfo::TexturePart::update_buffer()
}
if (!buffer)
buffer = new GeometryBuffer();
buffer = new GLModel();
if (buffer->set_from_triangles(triangulate_expolygon_2f(poly, NORMALS_UP), GROUND_Z + 0.02f)) {
if (vbo_id != 0) {
glsafe(::glDeleteBuffers(1, &vbo_id));
vbo_id = 0;
}
unsigned int* vbo_id_ptr = const_cast<unsigned int*>(&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 {
buffer->reset();
if (!init_model_from_poly(*buffer, poly, GROUND_Z + 0.02f)) {
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ":Unable to create buffer triangles\n";
}
}