Removed GLVolume non-VBO rendering

This commit is contained in:
Enrico Turri 2019-07-01 12:28:16 +02:00
parent d7c418ef84
commit 4269c8b23c
12 changed files with 221 additions and 390 deletions

View file

@ -274,8 +274,8 @@ void Bed3D::Axes::render_axis(double length) const
Bed3D::Bed3D() Bed3D::Bed3D()
: m_type(Custom) : m_type(Custom)
, m_requires_canvas_update(false)
#if ENABLE_TEXTURES_FROM_SVG #if ENABLE_TEXTURES_FROM_SVG
, m_requires_canvas_update(false)
, m_vbo_id(0) , m_vbo_id(0)
#endif // ENABLE_TEXTURES_FROM_SVG #endif // ENABLE_TEXTURES_FROM_SVG
, m_scale_factor(1.0f) , m_scale_factor(1.0f)
@ -330,12 +330,11 @@ Point Bed3D::point_projection(const Point& point) const
} }
#if ENABLE_TEXTURES_FROM_SVG #if ENABLE_TEXTURES_FROM_SVG
void Bed3D::render(GLCanvas3D* canvas, float theta, bool useVBOs, float scale_factor) const void Bed3D::render(GLCanvas3D* canvas, float theta, float scale_factor) const
{ {
m_scale_factor = scale_factor; m_scale_factor = scale_factor;
EType type = useVBOs ? m_type : Custom; switch (m_type)
switch (type)
{ {
case MK2: case MK2:
{ {
@ -361,7 +360,7 @@ void Bed3D::render(GLCanvas3D* canvas, float theta, bool useVBOs, float scale_fa
} }
} }
#else #else
void Bed3D::render(GLCanvas3D* canvas, float theta, bool useVBOs, float scale_factor) const void Bed3D::render(float theta, float scale_factor) const
{ {
m_scale_factor = scale_factor; m_scale_factor = scale_factor;
@ -372,17 +371,17 @@ void Bed3D::render(GLCanvas3D* canvas, float theta, bool useVBOs, float scale_fa
{ {
case MK2: case MK2:
{ {
render_prusa(canvas, "mk2", theta, useVBOs); render_prusa("mk2", theta);
break; break;
} }
case MK3: case MK3:
{ {
render_prusa(canvas, "mk3", theta, useVBOs); render_prusa("mk3", theta);
break; break;
} }
case SL1: case SL1:
{ {
render_prusa(canvas, "sl1", theta, useVBOs); render_prusa("sl1", theta);
break; break;
} }
default: default:
@ -546,7 +545,7 @@ void Bed3D::render_prusa(GLCanvas3D* canvas, const std::string &key, bool bottom
if (!bottom) if (!bottom)
{ {
filename = model_path + "_bed.stl"; filename = model_path + "_bed.stl";
if ((m_model.get_filename() != filename) && m_model.init_from_file(filename, true)) { if ((m_model.get_filename() != filename) && m_model.init_from_file(filename)) {
Vec3d offset = m_bounding_box.center() - Vec3d(0.0, 0.0, 0.5 * m_model.get_bounding_box().size()(2)); Vec3d offset = m_bounding_box.center() - Vec3d(0.0, 0.0, 0.5 * m_model.get_bounding_box().size()(2));
if (key == "mk2") if (key == "mk2")
// hardcoded value to match the stl model // hardcoded value to match the stl model
@ -651,7 +650,7 @@ void Bed3D::render_prusa_shader(bool transparent) const
} }
} }
#else #else
void Bed3D::render_prusa(const std::string &key, float theta, bool useVBOs) const void Bed3D::render_prusa(const std::string& key, float theta) const
{ {
std::string tex_path = resources_dir() + "/icons/bed/" + key; std::string tex_path = resources_dir() + "/icons/bed/" + key;
@ -677,7 +676,7 @@ void Bed3D::render_prusa(const std::string &key, float theta, bool useVBOs) cons
std::string filename = tex_path + "_top.png"; std::string filename = tex_path + "_top.png";
if ((m_top_texture.get_id() == 0) || (m_top_texture.get_source() != filename)) if ((m_top_texture.get_id() == 0) || (m_top_texture.get_source() != filename))
{ {
if (!m_top_texture.load_from_file(filename, true)) if (!m_top_texture.load_from_file(filename, true, true))
{ {
render_custom(); render_custom();
return; return;
@ -694,7 +693,7 @@ void Bed3D::render_prusa(const std::string &key, float theta, bool useVBOs) cons
filename = tex_path + "_bottom.png"; filename = tex_path + "_bottom.png";
if ((m_bottom_texture.get_id() == 0) || (m_bottom_texture.get_source() != filename)) if ((m_bottom_texture.get_id() == 0) || (m_bottom_texture.get_source() != filename))
{ {
if (!m_bottom_texture.load_from_file(filename, true)) if (!m_bottom_texture.load_from_file(filename, true, true))
{ {
render_custom(); render_custom();
return; return;
@ -711,7 +710,7 @@ void Bed3D::render_prusa(const std::string &key, float theta, bool useVBOs) cons
if (theta <= 90.0f) if (theta <= 90.0f)
{ {
filename = model_path + "_bed.stl"; filename = model_path + "_bed.stl";
if ((m_model.get_filename() != filename) && m_model.init_from_file(filename, useVBOs)) { if ((m_model.get_filename() != filename) && m_model.init_from_file(filename)) {
Vec3d offset = m_bounding_box.center() - Vec3d(0.0, 0.0, 0.5 * m_model.get_bounding_box().size()(2)); Vec3d offset = m_bounding_box.center() - Vec3d(0.0, 0.0, 0.5 * m_model.get_bounding_box().size()(2));
if (key == "mk2") if (key == "mk2")
// hardcoded value to match the stl model // hardcoded value to match the stl model

View file

@ -128,7 +128,11 @@ public:
bool contains(const Point& point) const; bool contains(const Point& point) const;
Point point_projection(const Point& point) const; Point point_projection(const Point& point) const;
void render(GLCanvas3D* canvas, float theta, bool useVBOs, float scale_factor) const; #if ENABLE_TEXTURES_FROM_SVG
void render(GLCanvas3D* canvas, float theta, float scale_factor) const;
#else
void render(float theta, float scale_factor) const;
#endif // ENABLE_TEXTURES_FROM_SVG
void render_axes() const; void render_axes() const;
private: private:
@ -140,7 +144,7 @@ private:
void render_prusa(GLCanvas3D* canvas, const std::string& key, bool bottom) const; void render_prusa(GLCanvas3D* canvas, const std::string& key, bool bottom) const;
void render_prusa_shader(bool transparent) const; void render_prusa_shader(bool transparent) const;
#else #else
void render_prusa(const std::string &key, float theta, bool useVBOs) const; void render_prusa(const std::string& key, float theta) const;
#endif // ENABLE_TEXTURES_FROM_SVG #endif // ENABLE_TEXTURES_FROM_SVG
void render_custom() const; void render_custom() const;
#if ENABLE_TEXTURES_FROM_SVG #if ENABLE_TEXTURES_FROM_SVG

View file

@ -55,21 +55,6 @@ void glAssertRecentCallImpl(const char *file_name, unsigned int line, const char
namespace Slic3r { namespace Slic3r {
void GLIndexedVertexArray::load_mesh_flat_shading(const TriangleMesh &mesh)
{
assert(triangle_indices.empty() && vertices_and_normals_interleaved_size == 0);
assert(quad_indices.empty() && triangle_indices_size == 0);
assert(vertices_and_normals_interleaved.size() % 6 == 0 && quad_indices_size == vertices_and_normals_interleaved.size());
this->vertices_and_normals_interleaved.reserve(this->vertices_and_normals_interleaved.size() + 3 * 3 * 2 * mesh.facets_count());
for (int i = 0; i < (int)mesh.stl.stats.number_of_facets; ++i) {
const stl_facet &facet = mesh.stl.facet_start[i];
for (int j = 0; j < 3; ++ j)
this->push_geometry(facet.vertex[j](0), facet.vertex[j](1), facet.vertex[j](2), facet.normal(0), facet.normal(1), facet.normal(2));
}
}
void GLIndexedVertexArray::load_mesh_full_shading(const TriangleMesh &mesh) void GLIndexedVertexArray::load_mesh_full_shading(const TriangleMesh &mesh)
{ {
assert(triangle_indices.empty() && vertices_and_normals_interleaved_size == 0); assert(triangle_indices.empty() && vertices_and_normals_interleaved_size == 0);
@ -89,7 +74,7 @@ void GLIndexedVertexArray::load_mesh_full_shading(const TriangleMesh &mesh)
} }
} }
void GLIndexedVertexArray::finalize_geometry(bool use_VBOs) void GLIndexedVertexArray::finalize_geometry()
{ {
assert(this->vertices_and_normals_interleaved_VBO_id == 0); assert(this->vertices_and_normals_interleaved_VBO_id == 0);
assert(this->triangle_indices_VBO_id == 0); assert(this->triangle_indices_VBO_id == 0);
@ -97,28 +82,28 @@ void GLIndexedVertexArray::finalize_geometry(bool use_VBOs)
this->setup_sizes(); this->setup_sizes();
if (use_VBOs) { if (! empty()) {
if (! empty()) { glsafe(::glGenBuffers(1, &this->vertices_and_normals_interleaved_VBO_id));
glsafe(::glGenBuffers(1, &this->vertices_and_normals_interleaved_VBO_id)); glsafe(::glBindBuffer(GL_ARRAY_BUFFER, this->vertices_and_normals_interleaved_VBO_id));
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, this->vertices_and_normals_interleaved_VBO_id)); glsafe(::glBufferData(GL_ARRAY_BUFFER, this->vertices_and_normals_interleaved.size() * 4, this->vertices_and_normals_interleaved.data(), GL_STATIC_DRAW));
glsafe(::glBufferData(GL_ARRAY_BUFFER, this->vertices_and_normals_interleaved.size() * 4, this->vertices_and_normals_interleaved.data(), GL_STATIC_DRAW)); glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0));
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); this->vertices_and_normals_interleaved.clear();
this->vertices_and_normals_interleaved.clear();
}
if (! this->triangle_indices.empty()) {
glsafe(::glGenBuffers(1, &this->triangle_indices_VBO_id));
glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this->triangle_indices_VBO_id));
glsafe(::glBufferData(GL_ELEMENT_ARRAY_BUFFER, this->triangle_indices.size() * 4, this->triangle_indices.data(), GL_STATIC_DRAW));
this->triangle_indices.clear();
}
if (! this->quad_indices.empty()) {
glsafe(::glGenBuffers(1, &this->quad_indices_VBO_id));
glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this->quad_indices_VBO_id));
glsafe(::glBufferData(GL_ELEMENT_ARRAY_BUFFER, this->quad_indices.size() * 4, this->quad_indices.data(), GL_STATIC_DRAW));
this->quad_indices.clear();
}
glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0));
} }
if (! this->triangle_indices.empty()) {
glsafe(::glGenBuffers(1, &this->triangle_indices_VBO_id));
glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this->triangle_indices_VBO_id));
glsafe(::glBufferData(GL_ELEMENT_ARRAY_BUFFER, this->triangle_indices.size() * 4, this->triangle_indices.data(), GL_STATIC_DRAW));
glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0));
this->triangle_indices.clear();
}
if (! this->quad_indices.empty()) {
glsafe(::glGenBuffers(1, &this->quad_indices_VBO_id));
glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this->quad_indices_VBO_id));
glsafe(::glBufferData(GL_ELEMENT_ARRAY_BUFFER, this->quad_indices.size() * 4, this->quad_indices.data(), GL_STATIC_DRAW));
glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0));
this->quad_indices.clear();
}
this->shrink_to_fit(); this->shrink_to_fit();
} }
@ -423,7 +408,7 @@ void GLVolume::render() const
glFrontFace(GL_CCW); glFrontFace(GL_CCW);
} }
void GLVolume::render_VBOs(int color_id, int detection_id, int worldmatrix_id) const void GLVolume::render(int color_id, int detection_id, int worldmatrix_id) const
{ {
if (!is_active) if (!is_active)
return; return;
@ -431,9 +416,6 @@ void GLVolume::render_VBOs(int color_id, int detection_id, int worldmatrix_id) c
if (!indexed_vertex_array.vertices_and_normals_interleaved_VBO_id) if (!indexed_vertex_array.vertices_and_normals_interleaved_VBO_id)
return; return;
if (this->is_left_handed())
glFrontFace(GL_CW);
GLsizei n_triangles = GLsizei(std::min(indexed_vertex_array.triangle_indices_size, tverts_range.second - tverts_range.first)); GLsizei n_triangles = GLsizei(std::min(indexed_vertex_array.triangle_indices_size, tverts_range.second - tverts_range.first));
GLsizei n_quads = GLsizei(std::min(indexed_vertex_array.quad_indices_size, qverts_range.second - qverts_range.first)); GLsizei n_quads = GLsizei(std::min(indexed_vertex_array.quad_indices_size, qverts_range.second - qverts_range.first));
if (n_triangles + n_quads == 0) if (n_triangles + n_quads == 0)
@ -464,6 +446,9 @@ void GLVolume::render_VBOs(int color_id, int detection_id, int worldmatrix_id) c
return; return;
} }
if (this->is_left_handed())
glFrontFace(GL_CW);
if (color_id >= 0) if (color_id >= 0)
glsafe(::glUniform4fv(color_id, 1, (const GLfloat*)render_color)); glsafe(::glUniform4fv(color_id, 1, (const GLfloat*)render_color));
else else
@ -500,162 +485,114 @@ void GLVolume::render_VBOs(int color_id, int detection_id, int worldmatrix_id) c
glFrontFace(GL_CCW); glFrontFace(GL_CCW);
} }
void GLVolume::render_legacy() const
{
assert(!indexed_vertex_array.vertices_and_normals_interleaved_VBO_id);
if (!is_active)
return;
if (this->is_left_handed())
glFrontFace(GL_CW);
GLsizei n_triangles = GLsizei(std::min(indexed_vertex_array.triangle_indices_size, tverts_range.second - tverts_range.first));
GLsizei n_quads = GLsizei(std::min(indexed_vertex_array.quad_indices_size, qverts_range.second - qverts_range.first));
if (n_triangles + n_quads == 0)
{
glsafe(::glDisableClientState(GL_VERTEX_ARRAY));
glsafe(::glDisableClientState(GL_NORMAL_ARRAY));
glsafe(::glColor4fv(render_color));
render();
glsafe(::glEnableClientState(GL_VERTEX_ARRAY));
glsafe(::glEnableClientState(GL_NORMAL_ARRAY));
return;
}
glsafe(::glColor4fv(render_color));
glsafe(::glVertexPointer(3, GL_FLOAT, 6 * sizeof(float), indexed_vertex_array.vertices_and_normals_interleaved.data() + 3));
glsafe(::glNormalPointer(GL_FLOAT, 6 * sizeof(float), indexed_vertex_array.vertices_and_normals_interleaved.data()));
glsafe(::glPushMatrix());
glsafe(::glMultMatrixd(world_matrix().data()));
if (n_triangles > 0)
glsafe(::glDrawElements(GL_TRIANGLES, n_triangles, GL_UNSIGNED_INT, indexed_vertex_array.triangle_indices.data() + tverts_range.first));
if (n_quads > 0)
glsafe(::glDrawElements(GL_QUADS, n_quads, GL_UNSIGNED_INT, indexed_vertex_array.quad_indices.data() + qverts_range.first));
glsafe(::glPopMatrix());
if (this->is_left_handed())
glFrontFace(GL_CCW);
}
bool GLVolume::is_sla_support() const { return this->composite_id.volume_id == -int(slaposSupportTree); } bool GLVolume::is_sla_support() const { return this->composite_id.volume_id == -int(slaposSupportTree); }
bool GLVolume::is_sla_pad() const { return this->composite_id.volume_id == -int(slaposBasePool); } bool GLVolume::is_sla_pad() const { return this->composite_id.volume_id == -int(slaposBasePool); }
std::vector<int> GLVolumeCollection::load_object( std::vector<int> GLVolumeCollection::load_object(
const ModelObject *model_object, const ModelObject* model_object,
int obj_idx, int obj_idx,
const std::vector<int> &instance_idxs, const std::vector<int>& instance_idxs,
const std::string &color_by, const std::string& color_by)
bool use_VBOs)
{ {
std::vector<int> volumes_idx; std::vector<int> volumes_idx;
for (int volume_idx = 0; volume_idx < int(model_object->volumes.size()); ++ volume_idx) for (int volume_idx = 0; volume_idx < int(model_object->volumes.size()); ++volume_idx)
for (int instance_idx : instance_idxs) for (int instance_idx : instance_idxs)
volumes_idx.emplace_back(this->GLVolumeCollection::load_object_volume(model_object, obj_idx, volume_idx, instance_idx, color_by, use_VBOs)); volumes_idx.emplace_back(this->GLVolumeCollection::load_object_volume(model_object, obj_idx, volume_idx, instance_idx, color_by));
return volumes_idx; return volumes_idx;
} }
int GLVolumeCollection::load_object_volume( int GLVolumeCollection::load_object_volume(
const ModelObject *model_object, const ModelObject* model_object,
int obj_idx, int obj_idx,
int volume_idx, int volume_idx,
int instance_idx, int instance_idx,
const std::string &color_by, const std::string& color_by)
bool use_VBOs)
{ {
const ModelVolume *model_volume = model_object->volumes[volume_idx]; const ModelVolume* model_volume = model_object->volumes[volume_idx];
const int extruder_id = model_volume->extruder_id(); const int extruder_id = model_volume->extruder_id();
const ModelInstance *instance = model_object->instances[instance_idx]; const ModelInstance* instance = model_object->instances[instance_idx];
const TriangleMesh& mesh = model_volume->mesh(); const TriangleMesh& mesh = model_volume->mesh();
float color[4]; float color[4];
memcpy(color, GLVolume::MODEL_COLOR[((color_by == "volume") ? volume_idx : obj_idx) % 4], sizeof(float) * 3); memcpy(color, GLVolume::MODEL_COLOR[((color_by == "volume") ? volume_idx : obj_idx) % 4], sizeof(float) * 3);
/* if (model_volume->is_support_blocker()) { /* if (model_volume->is_support_blocker()) {
color[0] = 1.0f; color[0] = 1.0f;
color[1] = 0.2f; color[1] = 0.2f;
color[2] = 0.2f; color[2] = 0.2f;
} else if (model_volume->is_support_enforcer()) { } else if (model_volume->is_support_enforcer()) {
color[0] = 0.2f; color[0] = 0.2f;
color[1] = 0.2f; color[1] = 0.2f;
color[2] = 1.0f; color[2] = 1.0f;
} }
color[3] = model_volume->is_model_part() ? 1.f : 0.5f; */ color[3] = model_volume->is_model_part() ? 1.f : 0.5f; */
color[3] = model_volume->is_model_part() ? 1.f : 0.5f; color[3] = model_volume->is_model_part() ? 1.f : 0.5f;
this->volumes.emplace_back(new GLVolume(color)); this->volumes.emplace_back(new GLVolume(color));
GLVolume &v = *this->volumes.back(); GLVolume& v = *this->volumes.back();
v.set_color_from_model_volume(model_volume); v.set_color_from_model_volume(model_volume);
v.indexed_vertex_array.load_mesh(mesh, use_VBOs); v.indexed_vertex_array.load_mesh(mesh);
// finalize_geometry() clears the vertex arrays, therefore the bounding box has to be computed before finalize_geometry(). // finalize_geometry() clears the vertex arrays, therefore the bounding box has to be computed before finalize_geometry().
v.bounding_box = v.indexed_vertex_array.bounding_box(); v.bounding_box = v.indexed_vertex_array.bounding_box();
v.indexed_vertex_array.finalize_geometry(use_VBOs); v.indexed_vertex_array.finalize_geometry();
v.composite_id = GLVolume::CompositeID(obj_idx, volume_idx, instance_idx); v.composite_id = GLVolume::CompositeID(obj_idx, volume_idx, instance_idx);
if (model_volume->is_model_part()) if (model_volume->is_model_part())
{ {
// GLVolume will reference a convex hull from model_volume! // GLVolume will reference a convex hull from model_volume!
v.set_convex_hull(model_volume->get_convex_hull_shared_ptr()); v.set_convex_hull(model_volume->get_convex_hull_shared_ptr());
if (extruder_id != -1) if (extruder_id != -1)
v.extruder_id = extruder_id; v.extruder_id = extruder_id;
} }
v.is_modifier = ! model_volume->is_model_part(); v.is_modifier = !model_volume->is_model_part();
v.shader_outside_printer_detection_enabled = model_volume->is_model_part(); v.shader_outside_printer_detection_enabled = model_volume->is_model_part();
v.set_instance_transformation(instance->get_transformation()); v.set_instance_transformation(instance->get_transformation());
v.set_volume_transformation(model_volume->get_transformation()); v.set_volume_transformation(model_volume->get_transformation());
return int(this->volumes.size() - 1); return int(this->volumes.size() - 1);
} }
// Load SLA auxiliary GLVolumes (for support trees or pad). // Load SLA auxiliary GLVolumes (for support trees or pad).
// This function produces volumes for multiple instances in a single shot, // This function produces volumes for multiple instances in a single shot,
// as some object specific mesh conversions may be expensive. // as some object specific mesh conversions may be expensive.
void GLVolumeCollection::load_object_auxiliary( void GLVolumeCollection::load_object_auxiliary(
const SLAPrintObject *print_object, const SLAPrintObject* print_object,
int obj_idx, int obj_idx,
// pairs of <instance_idx, print_instance_idx> // pairs of <instance_idx, print_instance_idx>
const std::vector<std::pair<size_t, size_t>> &instances, const std::vector<std::pair<size_t, size_t>>& instances,
SLAPrintObjectStep milestone, SLAPrintObjectStep milestone,
// Timestamp of the last change of the milestone // Timestamp of the last change of the milestone
size_t timestamp, size_t timestamp)
bool use_VBOs)
{ {
assert(print_object->is_step_done(milestone)); assert(print_object->is_step_done(milestone));
Transform3d mesh_trafo_inv = print_object->trafo().inverse(); Transform3d mesh_trafo_inv = print_object->trafo().inverse();
// Get the support mesh. // Get the support mesh.
TriangleMesh mesh = print_object->get_mesh(milestone); TriangleMesh mesh = print_object->get_mesh(milestone);
mesh.transform(mesh_trafo_inv); mesh.transform(mesh_trafo_inv);
// Convex hull is required for out of print bed detection. // Convex hull is required for out of print bed detection.
TriangleMesh convex_hull = mesh.convex_hull_3d(); TriangleMesh convex_hull = mesh.convex_hull_3d();
for (const std::pair<size_t, size_t> &instance_idx : instances) { for (const std::pair<size_t, size_t>& instance_idx : instances) {
const ModelInstance &model_instance = *print_object->model_object()->instances[instance_idx.first]; const ModelInstance& model_instance = *print_object->model_object()->instances[instance_idx.first];
this->volumes.emplace_back(new GLVolume((milestone == slaposBasePool) ? GLVolume::SLA_PAD_COLOR : GLVolume::SLA_SUPPORT_COLOR)); this->volumes.emplace_back(new GLVolume((milestone == slaposBasePool) ? GLVolume::SLA_PAD_COLOR : GLVolume::SLA_SUPPORT_COLOR));
GLVolume &v = *this->volumes.back(); GLVolume& v = *this->volumes.back();
v.indexed_vertex_array.load_mesh(mesh, use_VBOs); v.indexed_vertex_array.load_mesh(mesh);
// finalize_geometry() clears the vertex arrays, therefore the bounding box has to be computed before finalize_geometry(). // finalize_geometry() clears the vertex arrays, therefore the bounding box has to be computed before finalize_geometry().
v.bounding_box = v.indexed_vertex_array.bounding_box(); v.bounding_box = v.indexed_vertex_array.bounding_box();
v.indexed_vertex_array.finalize_geometry(use_VBOs); v.indexed_vertex_array.finalize_geometry();
v.composite_id = GLVolume::CompositeID(obj_idx, - int(milestone), (int)instance_idx.first); v.composite_id = GLVolume::CompositeID(obj_idx, -int(milestone), (int)instance_idx.first);
v.geometry_id = std::pair<size_t, size_t>(timestamp, model_instance.id().id); v.geometry_id = std::pair<size_t, size_t>(timestamp, model_instance.id().id);
// Create a copy of the convex hull mesh for each instance. Use a move operator on the last instance. // Create a copy of the convex hull mesh for each instance. Use a move operator on the last instance.
if (&instance_idx == &instances.back()) if (&instance_idx == &instances.back())
v.set_convex_hull(std::move(convex_hull)); v.set_convex_hull(std::move(convex_hull));
else else
v.set_convex_hull(convex_hull); v.set_convex_hull(convex_hull);
v.is_modifier = false; v.is_modifier = false;
v.shader_outside_printer_detection_enabled = (milestone == slaposSupportTree); v.shader_outside_printer_detection_enabled = (milestone == slaposSupportTree);
v.set_instance_transformation(model_instance.get_transformation()); v.set_instance_transformation(model_instance.get_transformation());
// Leave the volume transformation at identity. // Leave the volume transformation at identity.
// v.set_volume_transformation(model_volume->get_transformation()); // v.set_volume_transformation(model_volume->get_transformation());
} }
} }
int GLVolumeCollection::load_wipe_tower_preview( int GLVolumeCollection::load_wipe_tower_preview(
int obj_idx, float pos_x, float pos_y, float width, float depth, float height, float rotation_angle, bool use_VBOs, bool size_unknown, float brim_width) int obj_idx, float pos_x, float pos_y, float width, float depth, float height, float rotation_angle, bool size_unknown, float brim_width)
{ {
if (depth < 0.01f) if (depth < 0.01f)
return int(this->volumes.size() - 1); return int(this->volumes.size() - 1);
@ -680,45 +617,45 @@ int GLVolumeCollection::load_wipe_tower_preview(
{ 38.453f, 0, 1 }, { 0, 0, 1 }, { 0, -depth, 1 }, { 100.0f, -depth, 1 }, { 100.0f, 0, 1 }, { 61.547f, 0, 1 }, { 55.7735f, -10.0f, 1 }, { 44.2265f, 10.0f, 1 } }; { 38.453f, 0, 1 }, { 0, 0, 1 }, { 0, -depth, 1 }, { 100.0f, -depth, 1 }, { 100.0f, 0, 1 }, { 61.547f, 0, 1 }, { 55.7735f, -10.0f, 1 }, { 44.2265f, 10.0f, 1 } };
int out_facets_idx[][3] = { { 0, 1, 2 }, { 3, 4, 5 }, { 6, 5, 0 }, { 3, 5, 6 }, { 6, 2, 7 }, { 6, 0, 2 }, { 8, 9, 10 }, { 11, 12, 13 }, { 10, 11, 14 }, { 14, 11, 13 }, { 15, 8, 14 }, int out_facets_idx[][3] = { { 0, 1, 2 }, { 3, 4, 5 }, { 6, 5, 0 }, { 3, 5, 6 }, { 6, 2, 7 }, { 6, 0, 2 }, { 8, 9, 10 }, { 11, 12, 13 }, { 10, 11, 14 }, { 14, 11, 13 }, { 15, 8, 14 },
{8, 10, 14}, {3, 12, 4}, {3, 13, 12}, {6, 13, 3}, {6, 14, 13}, {7, 14, 6}, {7, 15, 14}, {2, 15, 7}, {2, 8, 15}, {1, 8, 2}, {1, 9, 8}, {8, 10, 14}, {3, 12, 4}, {3, 13, 12}, {6, 13, 3}, {6, 14, 13}, {7, 14, 6}, {7, 15, 14}, {2, 15, 7}, {2, 8, 15}, {1, 8, 2}, {1, 9, 8},
{0, 9, 1}, {0, 10, 9}, {5, 10, 0}, {5, 11, 10}, {4, 11, 5}, {4, 12, 11}}; {0, 9, 1}, {0, 10, 9}, {5, 10, 0}, {5, 11, 10}, {4, 11, 5}, {4, 12, 11} };
for (int i=0;i<16;++i) for (int i = 0; i < 16; ++i)
points.push_back(Vec3d(out_points_idx[i][0] / (100.f/min_width), out_points_idx[i][1] + depth, out_points_idx[i][2])); points.push_back(Vec3d(out_points_idx[i][0] / (100.f / min_width), out_points_idx[i][1] + depth, out_points_idx[i][2]));
for (int i=0;i<28;++i) for (int i = 0; i < 28; ++i)
facets.push_back(Vec3crd(out_facets_idx[i][0], out_facets_idx[i][1], out_facets_idx[i][2])); facets.push_back(Vec3crd(out_facets_idx[i][0], out_facets_idx[i][1], out_facets_idx[i][2]));
TriangleMesh tooth_mesh(points, facets); TriangleMesh tooth_mesh(points, facets);
// We have the mesh ready. It has one tooth and width of min_width. We will now append several of these together until we are close to // We have the mesh ready. It has one tooth and width of min_width. We will now append several of these together until we are close to
// the required width of the block. Than we can scale it precisely. // the required width of the block. Than we can scale it precisely.
size_t n = std::max(1, int(width/min_width)); // How many shall be merged? size_t n = std::max(1, int(width / min_width)); // How many shall be merged?
for (size_t i=0;i<n;++i) { for (size_t i = 0; i < n; ++i) {
mesh.merge(tooth_mesh); mesh.merge(tooth_mesh);
tooth_mesh.translate(min_width, 0.f, 0.f); tooth_mesh.translate(min_width, 0.f, 0.f);
} }
mesh.scale(Vec3d(width/(n*min_width), 1.f, height)); // Scaling to proper width mesh.scale(Vec3d(width / (n * min_width), 1.f, height)); // Scaling to proper width
} }
else else
mesh = make_cube(width, depth, height); mesh = make_cube(width, depth, height);
// We'll make another mesh to show the brim (fixed layer height): // We'll make another mesh to show the brim (fixed layer height):
TriangleMesh brim_mesh = make_cube(width+2.f*brim_width, depth+2.f*brim_width, 0.2f); TriangleMesh brim_mesh = make_cube(width + 2.f * brim_width, depth + 2.f * brim_width, 0.2f);
brim_mesh.translate(-brim_width, -brim_width, 0.f); brim_mesh.translate(-brim_width, -brim_width, 0.f);
mesh.merge(brim_mesh); mesh.merge(brim_mesh);
this->volumes.emplace_back(new GLVolume(color)); this->volumes.emplace_back(new GLVolume(color));
GLVolume &v = *this->volumes.back(); GLVolume& v = *this->volumes.back();
v.indexed_vertex_array.load_mesh(mesh, use_VBOs); v.indexed_vertex_array.load_mesh(mesh);
v.set_volume_offset(Vec3d(pos_x, pos_y, 0.0)); v.set_volume_offset(Vec3d(pos_x, pos_y, 0.0));
v.set_volume_rotation(Vec3d(0., 0., (M_PI/180.) * rotation_angle)); v.set_volume_rotation(Vec3d(0., 0., (M_PI / 180.) * rotation_angle));
// finalize_geometry() clears the vertex arrays, therefore the bounding box has to be computed before finalize_geometry(). // finalize_geometry() clears the vertex arrays, therefore the bounding box has to be computed before finalize_geometry().
v.bounding_box = v.indexed_vertex_array.bounding_box(); v.bounding_box = v.indexed_vertex_array.bounding_box();
v.indexed_vertex_array.finalize_geometry(use_VBOs); v.indexed_vertex_array.finalize_geometry();
v.composite_id = GLVolume::CompositeID(obj_idx, 0, 0); v.composite_id = GLVolume::CompositeID(obj_idx, 0, 0);
v.geometry_id.first = 0; v.geometry_id.first = 0;
v.geometry_id.second = wipe_tower_instance_id().id; v.geometry_id.second = wipe_tower_instance_id().id;
v.is_wipe_tower = true; v.is_wipe_tower = true;
v.shader_outside_printer_detection_enabled = ! size_unknown; v.shader_outside_printer_detection_enabled = !size_unknown;
return int(this->volumes.size() - 1); return int(this->volumes.size() - 1);
} }
@ -759,7 +696,7 @@ GLVolumeWithIdAndZList volumes_to_render(const GLVolumePtrs& volumes, GLVolumeCo
return list; return list;
} }
void GLVolumeCollection::render_VBOs(GLVolumeCollection::ERenderType type, bool disable_cullface, const Transform3d& view_matrix, std::function<bool(const GLVolume&)> filter_func) const void GLVolumeCollection::render(GLVolumeCollection::ERenderType type, bool disable_cullface, const Transform3d& view_matrix, std::function<bool(const GLVolume&)> filter_func) const
{ {
glsafe(::glEnable(GL_BLEND)); glsafe(::glEnable(GL_BLEND));
glsafe(::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); glsafe(::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));
@ -797,7 +734,7 @@ void GLVolumeCollection::render_VBOs(GLVolumeCollection::ERenderType type, bool
GLVolumeWithIdAndZList to_render = volumes_to_render(this->volumes, type, view_matrix, filter_func); GLVolumeWithIdAndZList to_render = volumes_to_render(this->volumes, type, view_matrix, filter_func);
for (GLVolumeWithIdAndZ& volume : to_render) { for (GLVolumeWithIdAndZ& volume : to_render) {
volume.first->set_render_color(); volume.first->set_render_color();
volume.first->render_VBOs(color_id, print_box_detection_id, print_box_worldmatrix_id); volume.first->render(color_id, print_box_detection_id, print_box_worldmatrix_id);
} }
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0));
@ -812,34 +749,6 @@ void GLVolumeCollection::render_VBOs(GLVolumeCollection::ERenderType type, bool
glsafe(::glDisable(GL_BLEND)); glsafe(::glDisable(GL_BLEND));
} }
void GLVolumeCollection::render_legacy(ERenderType type, bool disable_cullface, const Transform3d& view_matrix, std::function<bool(const GLVolume&)> filter_func) const
{
glsafe(::glEnable(GL_BLEND));
glsafe(::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));
glsafe(::glCullFace(GL_BACK));
if (disable_cullface)
glsafe(::glDisable(GL_CULL_FACE));
glsafe(::glEnableClientState(GL_VERTEX_ARRAY));
glsafe(::glEnableClientState(GL_NORMAL_ARRAY));
GLVolumeWithIdAndZList to_render = volumes_to_render(this->volumes, type, view_matrix, filter_func);
for (GLVolumeWithIdAndZ& volume : to_render)
{
volume.first->set_render_color();
volume.first->render_legacy();
}
glsafe(::glDisableClientState(GL_VERTEX_ARRAY));
glsafe(::glDisableClientState(GL_NORMAL_ARRAY));
if (disable_cullface)
glsafe(::glEnable(GL_CULL_FACE));
glsafe(::glDisable(GL_BLEND));
}
bool GLVolumeCollection::check_outside_state(const DynamicPrintConfig* config, ModelInstance::EPrintVolumeState* out_state) bool GLVolumeCollection::check_outside_state(const DynamicPrintConfig* config, ModelInstance::EPrintVolumeState* out_state)
{ {
if (config == nullptr) if (config == nullptr)
@ -1623,8 +1532,7 @@ void _3DScene::point3_to_verts(const Vec3crd& point, double width, double height
GUI::GLCanvas3DManager _3DScene::s_canvas_mgr; GUI::GLCanvas3DManager _3DScene::s_canvas_mgr;
GLModel::GLModel() GLModel::GLModel()
: m_useVBOs(false) : m_filename("")
, m_filename("")
{ {
m_volume.shader_outside_printer_detection_enabled = false; m_volume.shader_outside_printer_detection_enabled = false;
} }
@ -1677,14 +1585,6 @@ void GLModel::reset()
} }
void GLModel::render() const void GLModel::render() const
{
if (m_useVBOs)
render_VBOs();
else
render_legacy();
}
void GLModel::render_VBOs() const
{ {
glsafe(::glEnable(GL_BLEND)); glsafe(::glEnable(GL_BLEND));
glsafe(::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); glsafe(::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));
@ -1697,7 +1597,8 @@ void GLModel::render_VBOs() const
glsafe(::glGetIntegerv(GL_CURRENT_PROGRAM, &current_program_id)); glsafe(::glGetIntegerv(GL_CURRENT_PROGRAM, &current_program_id));
GLint color_id = (current_program_id > 0) ? ::glGetUniformLocation(current_program_id, "uniform_color") : -1; GLint color_id = (current_program_id > 0) ? ::glGetUniformLocation(current_program_id, "uniform_color") : -1;
glcheck(); glcheck();
m_volume.render_VBOs(color_id, -1, -1);
m_volume.render(color_id, -1, -1);
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0));
glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0));
@ -1708,26 +1609,7 @@ void GLModel::render_VBOs() const
glsafe(::glDisable(GL_BLEND)); glsafe(::glDisable(GL_BLEND));
} }
void GLModel::render_legacy() const bool GLArrow::on_init()
{
glsafe(::glEnable(GL_LIGHTING));
glsafe(::glEnable(GL_BLEND));
glsafe(::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));
glsafe(::glCullFace(GL_BACK));
glsafe(::glEnableClientState(GL_VERTEX_ARRAY));
glsafe(::glEnableClientState(GL_NORMAL_ARRAY));
m_volume.render_legacy();
glsafe(::glDisableClientState(GL_VERTEX_ARRAY));
glsafe(::glDisableClientState(GL_NORMAL_ARRAY));
glsafe(::glDisable(GL_BLEND));
glsafe(::glDisable(GL_LIGHTING));
}
bool GLArrow::on_init(bool useVBOs)
{ {
Pointf3s vertices; Pointf3s vertices;
std::vector<Vec3crd> triangles; std::vector<Vec3crd> triangles;
@ -1780,9 +1662,8 @@ bool GLArrow::on_init(bool useVBOs)
triangles.emplace_back(6, 0, 7); triangles.emplace_back(6, 0, 7);
triangles.emplace_back(7, 13, 6); triangles.emplace_back(7, 13, 6);
m_useVBOs = useVBOs; m_volume.indexed_vertex_array.load_mesh(TriangleMesh(vertices, triangles));
m_volume.indexed_vertex_array.load_mesh(TriangleMesh(vertices, triangles), useVBOs); m_volume.finalize_geometry();
m_volume.finalize_geometry(m_useVBOs);
return true; return true;
} }
@ -1794,7 +1675,7 @@ GLCurvedArrow::GLCurvedArrow(unsigned int resolution)
m_resolution = 1; m_resolution = 1;
} }
bool GLCurvedArrow::on_init(bool useVBOs) bool GLCurvedArrow::on_init()
{ {
Pointf3s vertices; Pointf3s vertices;
std::vector<Vec3crd> triangles; std::vector<Vec3crd> triangles;
@ -1895,14 +1776,13 @@ bool GLCurvedArrow::on_init(bool useVBOs)
triangles.emplace_back(vertices_per_level, vertices_per_level + 1, 0); triangles.emplace_back(vertices_per_level, vertices_per_level + 1, 0);
triangles.emplace_back(vertices_per_level, 2 * vertices_per_level + 1, vertices_per_level + 1); triangles.emplace_back(vertices_per_level, 2 * vertices_per_level + 1, vertices_per_level + 1);
m_useVBOs = useVBOs; m_volume.indexed_vertex_array.load_mesh(TriangleMesh(vertices, triangles));
m_volume.indexed_vertex_array.load_mesh(TriangleMesh(vertices, triangles), useVBOs);
m_volume.bounding_box = m_volume.indexed_vertex_array.bounding_box(); m_volume.bounding_box = m_volume.indexed_vertex_array.bounding_box();
m_volume.finalize_geometry(m_useVBOs); m_volume.finalize_geometry();
return true; return true;
} }
bool GLBed::on_init_from_file(const std::string& filename, bool useVBOs) bool GLBed::on_init_from_file(const std::string& filename)
{ {
reset(); reset();
@ -1923,7 +1803,6 @@ bool GLBed::on_init_from_file(const std::string& filename, bool useVBOs)
} }
m_filename = filename; m_filename = filename;
m_useVBOs = useVBOs;
ModelObject* model_object = model.objects.front(); ModelObject* model_object = model.objects.front();
model_object->center_around_origin(); model_object->center_around_origin();
@ -1931,13 +1810,13 @@ bool GLBed::on_init_from_file(const std::string& filename, bool useVBOs)
TriangleMesh mesh = model.mesh(); TriangleMesh mesh = model.mesh();
mesh.repair(); mesh.repair();
m_volume.indexed_vertex_array.load_mesh(mesh, useVBOs); m_volume.indexed_vertex_array.load_mesh(mesh);
float color[4] = { 0.235f, 0.235f, 0.235f, 1.0f }; float color[4] = { 0.235f, 0.235f, 0.235f, 1.0f };
set_color(color, 4); set_color(color, 4);
m_volume.bounding_box = m_volume.indexed_vertex_array.bounding_box(); m_volume.bounding_box = m_volume.indexed_vertex_array.bounding_box();
m_volume.finalize_geometry(m_useVBOs); m_volume.finalize_geometry();
return true; return true;
} }

View file

@ -115,9 +115,8 @@ public:
unsigned int triangle_indices_VBO_id; unsigned int triangle_indices_VBO_id;
unsigned int quad_indices_VBO_id; unsigned int quad_indices_VBO_id;
void load_mesh_flat_shading(const TriangleMesh &mesh);
void load_mesh_full_shading(const TriangleMesh &mesh); void load_mesh_full_shading(const TriangleMesh &mesh);
void load_mesh(const TriangleMesh &mesh, bool use_VBOs) { use_VBOs ? this->load_mesh_full_shading(mesh) : this->load_mesh_flat_shading(mesh); } void load_mesh(const TriangleMesh& mesh) { this->load_mesh_full_shading(mesh); }
inline bool has_VBOs() const { return vertices_and_normals_interleaved_VBO_id != 0; } inline bool has_VBOs() const { return vertices_and_normals_interleaved_VBO_id != 0; }
@ -166,7 +165,7 @@ public:
// Finalize the initialization of the geometry & indices, // Finalize the initialization of the geometry & indices,
// upload the geometry and indices to OpenGL VBO objects // upload the geometry and indices to OpenGL VBO objects
// and shrink the allocated data, possibly relasing it if it has been loaded into the VBOs. // and shrink the allocated data, possibly relasing it if it has been loaded into the VBOs.
void finalize_geometry(bool use_VBOs); void finalize_geometry();
// Release the geometry data, release OpenGL VBOs. // Release the geometry data, release OpenGL VBOs.
void release_geometry(); void release_geometry();
// Render either using an immediate mode, or the VBOs. // Render either using an immediate mode, or the VBOs.
@ -415,10 +414,9 @@ public:
void set_range(coordf_t low, coordf_t high); void set_range(coordf_t low, coordf_t high);
void render() const; void render() const;
void render_VBOs(int color_id, int detection_id, int worldmatrix_id) const; void render(int color_id, int detection_id, int worldmatrix_id) const;
void render_legacy() const;
void finalize_geometry(bool use_VBOs) { this->indexed_vertex_array.finalize_geometry(use_VBOs); } void finalize_geometry() { this->indexed_vertex_array.finalize_geometry(); }
void release_geometry() { this->indexed_vertex_array.release_geometry(); } void release_geometry() { this->indexed_vertex_array.release_geometry(); }
void set_bounding_boxes_as_dirty() { m_transformed_bounding_box_dirty = true; m_transformed_convex_hull_bounding_box_dirty = true; } void set_bounding_boxes_as_dirty() { m_transformed_bounding_box_dirty = true; m_transformed_convex_hull_bounding_box_dirty = true; }
@ -459,42 +457,38 @@ public:
~GLVolumeCollection() { clear(); }; ~GLVolumeCollection() { clear(); };
std::vector<int> load_object( std::vector<int> load_object(
const ModelObject *model_object, const ModelObject* model_object,
int obj_idx, int obj_idx,
const std::vector<int> &instance_idxs, const std::vector<int>& instance_idxs,
const std::string &color_by, const std::string& color_by);
bool use_VBOs);
int load_object_volume( int load_object_volume(
const ModelObject *model_object, const ModelObject* model_object,
int obj_idx, int obj_idx,
int volume_idx, int volume_idx,
int instance_idx, int instance_idx,
const std::string &color_by, const std::string& color_by);
bool use_VBOs);
// Load SLA auxiliary GLVolumes (for support trees or pad). // Load SLA auxiliary GLVolumes (for support trees or pad).
void load_object_auxiliary( void load_object_auxiliary(
const SLAPrintObject *print_object, const SLAPrintObject* print_object,
int obj_idx, int obj_idx,
// pairs of <instance_idx, print_instance_idx> // pairs of <instance_idx, print_instance_idx>
const std::vector<std::pair<size_t, size_t>> &instances, const std::vector<std::pair<size_t, size_t>>& instances,
SLAPrintObjectStep milestone, SLAPrintObjectStep milestone,
// Timestamp of the last change of the milestone // Timestamp of the last change of the milestone
size_t timestamp, size_t timestamp);
bool use_VBOs);
int load_wipe_tower_preview( int load_wipe_tower_preview(
int obj_idx, float pos_x, float pos_y, float width, float depth, float height, float rotation_angle, bool use_VBOs, bool size_unknown, float brim_width); int obj_idx, float pos_x, float pos_y, float width, float depth, float height, float rotation_angle, bool size_unknown, float brim_width);
// Render the volumes by OpenGL. // Render the volumes by OpenGL.
void render_VBOs(ERenderType type, bool disable_cullface, const Transform3d& view_matrix, std::function<bool(const GLVolume&)> filter_func = std::function<bool(const GLVolume&)>()) const; void render(ERenderType type, bool disable_cullface, const Transform3d& view_matrix, std::function<bool(const GLVolume&)> filter_func = std::function<bool(const GLVolume&)>()) const;
void render_legacy(ERenderType type, bool disable_cullface, const Transform3d& view_matrix, std::function<bool(const GLVolume&)> filter_func = std::function<bool(const GLVolume&)>()) const;
// Finalize the initialization of the geometry & indices, // Finalize the initialization of the geometry & indices,
// upload the geometry and indices to OpenGL VBO objects // upload the geometry and indices to OpenGL VBO objects
// and shrink the allocated data, possibly relasing it if it has been loaded into the VBOs. // and shrink the allocated data, possibly relasing it if it has been loaded into the VBOs.
void finalize_geometry(bool use_VBOs) { for (auto *v : volumes) v->finalize_geometry(use_VBOs); } void finalize_geometry() { for (auto* v : volumes) v->finalize_geometry(); }
// Release the geometry data assigned to the volumes. // Release the geometry data assigned to the volumes.
// If OpenGL VBOs were allocated, an OpenGL context has to be active to release them. // If OpenGL VBOs were allocated, an OpenGL context has to be active to release them.
void release_geometry() { for (auto *v : volumes) v->release_geometry(); } void release_geometry() { for (auto *v : volumes) v->release_geometry(); }
@ -533,15 +527,14 @@ class GLModel
{ {
protected: protected:
GLVolume m_volume; GLVolume m_volume;
bool m_useVBOs;
std::string m_filename; std::string m_filename;
public: public:
GLModel(); GLModel();
virtual ~GLModel(); virtual ~GLModel();
bool init(bool useVBOs) { return on_init(useVBOs); } bool init() { return on_init(); }
bool init_from_file(const std::string& filename, bool useVBOs) { return on_init_from_file(filename, useVBOs); } bool init_from_file(const std::string& filename) { return on_init_from_file(filename); }
void center_around(const Vec3d& center) { m_volume.set_volume_offset(center - m_volume.bounding_box.center()); } void center_around(const Vec3d& center) { m_volume.set_volume_offset(center - m_volume.bounding_box.center()); }
void set_color(const float* color, unsigned int size); void set_color(const float* color, unsigned int size);
@ -562,18 +555,14 @@ public:
void render() const; void render() const;
protected: protected:
virtual bool on_init(bool useVBOs) { return false; } virtual bool on_init() { return false; }
virtual bool on_init_from_file(const std::string& filename, bool useVBOs) { return false; } virtual bool on_init_from_file(const std::string& filename) { return false; }
private:
void render_VBOs() const;
void render_legacy() const;
}; };
class GLArrow : public GLModel class GLArrow : public GLModel
{ {
protected: protected:
virtual bool on_init(bool useVBOs); virtual bool on_init();
}; };
class GLCurvedArrow : public GLModel class GLCurvedArrow : public GLModel
@ -584,13 +573,13 @@ public:
explicit GLCurvedArrow(unsigned int resolution); explicit GLCurvedArrow(unsigned int resolution);
protected: protected:
virtual bool on_init(bool useVBOs); virtual bool on_init();
}; };
class GLBed : public GLModel class GLBed : public GLModel
{ {
protected: protected:
virtual bool on_init_from_file(const std::string& filename, bool useVBOs); virtual bool on_init_from_file(const std::string& filename);
}; };
class _3DScene class _3DScene

View file

@ -1211,7 +1211,6 @@ GLCanvas3D::GLCanvas3D(wxGLCanvas* canvas, Bed3D& bed, Camera& camera, GLToolbar
, m_model(nullptr) , m_model(nullptr)
, m_dirty(true) , m_dirty(true)
, m_initialized(false) , m_initialized(false)
, m_use_VBOs(false)
, m_apply_zoom_to_volumes_filter(false) , m_apply_zoom_to_volumes_filter(false)
, m_legend_texture_enabled(false) , m_legend_texture_enabled(false)
, m_picking_enabled(false) , m_picking_enabled(false)
@ -1252,7 +1251,7 @@ void GLCanvas3D::post_event(wxEvent &&event)
wxPostEvent(m_canvas, event); wxPostEvent(m_canvas, event);
} }
bool GLCanvas3D::init(bool useVBOs) bool GLCanvas3D::init()
{ {
if (m_initialized) if (m_initialized)
return true; return true;
@ -1303,30 +1302,30 @@ bool GLCanvas3D::init(bool useVBOs)
if (m_multisample_allowed) if (m_multisample_allowed)
glsafe(::glEnable(GL_MULTISAMPLE)); glsafe(::glEnable(GL_MULTISAMPLE));
if (useVBOs && !m_shader.init("gouraud.vs", "gouraud.fs")) if (!m_shader.init("gouraud.vs", "gouraud.fs"))
{
std::cout << "Unable to initialize gouraud shader: please, check that the files gouraud.vs and gouraud.fs are available" << std::endl;
return false; return false;
}
if (m_toolbar.is_enabled() && useVBOs && !m_layers_editing.init("variable_layer_height.vs", "variable_layer_height.fs")) if (m_toolbar.is_enabled() && !m_layers_editing.init("variable_layer_height.vs", "variable_layer_height.fs"))
{
std::cout << "Unable to initialize variable_layer_height shader: please, check that the files variable_layer_height.vs and variable_layer_height.fs are available" << std::endl;
return false; return false;
}
m_use_VBOs = useVBOs;
// on linux the gl context is not valid until the canvas is not shown on screen // on linux the gl context is not valid until the canvas is not shown on screen
// we defer the geometry finalization of volumes until the first call to render() // we defer the geometry finalization of volumes until the first call to render()
if (!m_volumes.empty()) if (!m_volumes.empty())
m_volumes.finalize_geometry(m_use_VBOs); m_volumes.finalize_geometry();
if (m_gizmos.is_enabled()) { if (m_gizmos.is_enabled() && !m_gizmos.init(*this))
if (! m_gizmos.init(*this)) { std::cout << "Unable to initialize gizmos: please, check that all the required textures are available" << std::endl;
std::cout << "Unable to initialize gizmos: please, check that all the required textures are available" << std::endl;
return false;
}
}
if (!_init_toolbar()) if (!_init_toolbar())
return false; return false;
if (m_selection.is_enabled() && !m_selection.init(m_use_VBOs)) if (m_selection.is_enabled() && !m_selection.init())
return false; return false;
post_event(SimpleEvent(EVT_GLCANVAS_INIT)); post_event(SimpleEvent(EVT_GLCANVAS_INIT));
@ -1778,7 +1777,7 @@ std::vector<int> GLCanvas3D::load_object(const ModelObject& model_object, int ob
instance_idxs.push_back(i); instance_idxs.push_back(i);
} }
} }
return m_volumes.load_object(&model_object, obj_idx, instance_idxs, m_color_by, m_use_VBOs && m_initialized); return m_volumes.load_object(&model_object, obj_idx, instance_idxs, m_color_by);
} }
std::vector<int> GLCanvas3D::load_object(const Model& model, int obj_idx) std::vector<int> GLCanvas3D::load_object(const Model& model, int obj_idx)
@ -1966,8 +1965,8 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re
assert(it != model_volume_state.end() && it->geometry_id == key.geometry_id); assert(it != model_volume_state.end() && it->geometry_id == key.geometry_id);
if (it->new_geometry()) { if (it->new_geometry()) {
// New volume. // New volume.
m_volumes.load_object_volume(&model_object, obj_idx, volume_idx, instance_idx, m_color_by, m_use_VBOs && m_initialized); m_volumes.load_object_volume(&model_object, obj_idx, volume_idx, instance_idx, m_color_by);
m_volumes.volumes.back()->geometry_id = key.geometry_id; m_volumes.volumes.back()->geometry_id = key.geometry_id;
update_object_list = true; update_object_list = true;
} else { } else {
// Recycling an old GLVolume. // Recycling an old GLVolume.
@ -2031,7 +2030,7 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re
for (size_t istep = 0; istep < sla_steps.size(); ++istep) for (size_t istep = 0; istep < sla_steps.size(); ++istep)
if (!instances[istep].empty()) if (!instances[istep].empty())
m_volumes.load_object_auxiliary(print_object, object_idx, instances[istep], sla_steps[istep], state.step[istep].timestamp, m_use_VBOs && m_initialized); m_volumes.load_object_auxiliary(print_object, object_idx, instances[istep], sla_steps[istep], state.step[istep].timestamp);
} }
// Shift-up all volumes of the object so that it has the right elevation with respect to the print bed // Shift-up all volumes of the object so that it has the right elevation with respect to the print bed
@ -2068,9 +2067,9 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re
float brim_spacing = print->config().nozzle_diameter.values[0] * 1.25f - first_layer_height * (1. - M_PI_4); float brim_spacing = print->config().nozzle_diameter.values[0] * 1.25f - first_layer_height * (1. - M_PI_4);
if (!print->is_step_done(psWipeTower)) if (!print->is_step_done(psWipeTower))
depth = (900.f/w) * (float)(extruders_count - 1) ; depth = (900.f/w) * (float)(extruders_count - 1);
int volume_idx_wipe_tower_new = m_volumes.load_wipe_tower_preview( int volume_idx_wipe_tower_new = m_volumes.load_wipe_tower_preview(
1000, x, y, w, depth, (float)height, a, m_use_VBOs && m_initialized, !print->is_step_done(psWipeTower), 1000, x, y, w, depth, (float)height, a, !print->is_step_done(psWipeTower),
brim_spacing * 4.5f); brim_spacing * 4.5f);
if (volume_idx_wipe_tower_old != -1) if (volume_idx_wipe_tower_old != -1)
map_glvolume_old_to_new[volume_idx_wipe_tower_old] = volume_idx_wipe_tower_new; map_glvolume_old_to_new[volume_idx_wipe_tower_old] = volume_idx_wipe_tower_new;
@ -3821,7 +3820,11 @@ void GLCanvas3D::_render_bed(float theta) const
#if ENABLE_RETINA_GL #if ENABLE_RETINA_GL
scale_factor = m_retina_helper->get_scale_factor(); scale_factor = m_retina_helper->get_scale_factor();
#endif // ENABLE_RETINA_GL #endif // ENABLE_RETINA_GL
m_bed.render(const_cast<GLCanvas3D*>(this), theta, m_use_VBOs, scale_factor); #if ENABLE_TEXTURES_FROM_SVG
m_bed.render(const_cast<GLCanvas3D*>(this), theta, scale_factor);
#else
m_bed.render(theta, scale_factor);
#endif // ENABLE_TEXTURES_FROM_SVG
} }
void GLCanvas3D::_render_axes() const void GLCanvas3D::_render_axes() const
@ -3829,8 +3832,6 @@ void GLCanvas3D::_render_axes() const
m_bed.render_axes(); m_bed.render_axes();
} }
void GLCanvas3D::_render_objects() const void GLCanvas3D::_render_objects() const
{ {
if (m_volumes.empty()) if (m_volumes.empty())
@ -3841,75 +3842,44 @@ void GLCanvas3D::_render_objects() const
m_camera_clipping_plane = m_gizmos.get_sla_clipping_plane(); m_camera_clipping_plane = m_gizmos.get_sla_clipping_plane();
if (m_use_VBOs) if (m_picking_enabled)
{ {
if (m_picking_enabled) // Update the layer editing selection to the first object selected, update the current object maximum Z.
const_cast<LayersEditing&>(m_layers_editing).select_object(*m_model, this->is_layers_editing_enabled() ? m_selection.get_object_idx() : -1);
if (m_config != nullptr)
{ {
// Update the layer editing selection to the first object selected, update the current object maximum Z. const BoundingBoxf3& bed_bb = m_bed.get_bounding_box(false);
const_cast<LayersEditing&>(m_layers_editing).select_object(*m_model, this->is_layers_editing_enabled() ? m_selection.get_object_idx() : -1); m_volumes.set_print_box((float)bed_bb.min(0), (float)bed_bb.min(1), 0.0f, (float)bed_bb.max(0), (float)bed_bb.max(1), (float)m_config->opt_float("max_print_height"));
m_volumes.check_outside_state(m_config, nullptr);
if (m_config != nullptr)
{
const BoundingBoxf3& bed_bb = m_bed.get_bounding_box(false);
m_volumes.set_print_box((float)bed_bb.min(0), (float)bed_bb.min(1), 0.0f, (float)bed_bb.max(0), (float)bed_bb.max(1), (float)m_config->opt_float("max_print_height"));
m_volumes.check_outside_state(m_config, nullptr);
}
} }
if (m_use_clipping_planes)
m_volumes.set_z_range(-m_clipping_planes[0].get_data()[3], m_clipping_planes[1].get_data()[3]);
else
m_volumes.set_z_range(-FLT_MAX, FLT_MAX);
m_volumes.set_clipping_plane(m_camera_clipping_plane.get_data());
m_shader.start_using();
if (m_picking_enabled && !m_gizmos.is_dragging() && m_layers_editing.is_enabled() && (m_layers_editing.last_object_id != -1) && (m_layers_editing.object_max_z() > 0.0f)) {
int object_id = m_layers_editing.last_object_id;
m_volumes.render_VBOs(GLVolumeCollection::Opaque, false, m_camera.get_view_matrix(), [object_id](const GLVolume &volume) {
// Which volume to paint without the layer height profile shader?
return volume.is_active && (volume.is_modifier || volume.composite_id.object_id != object_id);
});
// Let LayersEditing handle rendering of the active object using the layer height profile shader.
m_layers_editing.render_volumes(*this, this->m_volumes);
} else {
// do not cull backfaces to show broken geometry, if any
m_volumes.render_VBOs(GLVolumeCollection::Opaque, m_picking_enabled, m_camera.get_view_matrix(), [this](const GLVolume& volume) {
return (m_render_sla_auxiliaries || volume.composite_id.volume_id >= 0);
});
}
m_volumes.render_VBOs(GLVolumeCollection::Transparent, false, m_camera.get_view_matrix());
m_shader.stop_using();
} }
if (m_use_clipping_planes)
m_volumes.set_z_range(-m_clipping_planes[0].get_data()[3], m_clipping_planes[1].get_data()[3]);
else else
{ m_volumes.set_z_range(-FLT_MAX, FLT_MAX);
::glClipPlane(GL_CLIP_PLANE0, (GLdouble*)m_camera_clipping_plane.get_data());
::glEnable(GL_CLIP_PLANE0);
if (m_use_clipping_planes) m_volumes.set_clipping_plane(m_camera_clipping_plane.get_data());
{
glsafe(::glClipPlane(GL_CLIP_PLANE1, (GLdouble*)m_clipping_planes[0].get_data()));
glsafe(::glEnable(GL_CLIP_PLANE1));
glsafe(::glClipPlane(GL_CLIP_PLANE2, (GLdouble*)m_clipping_planes[1].get_data()));
glsafe(::glEnable(GL_CLIP_PLANE2));
}
m_shader.start_using();
if (m_picking_enabled && !m_gizmos.is_dragging() && m_layers_editing.is_enabled() && (m_layers_editing.last_object_id != -1) && (m_layers_editing.object_max_z() > 0.0f)) {
int object_id = m_layers_editing.last_object_id;
m_volumes.render(GLVolumeCollection::Opaque, false, m_camera.get_view_matrix(), [object_id](const GLVolume& volume) {
// Which volume to paint without the layer height profile shader?
return volume.is_active && (volume.is_modifier || volume.composite_id.object_id != object_id);
});
// Let LayersEditing handle rendering of the active object using the layer height profile shader.
m_layers_editing.render_volumes(*this, this->m_volumes);
} else {
// do not cull backfaces to show broken geometry, if any // do not cull backfaces to show broken geometry, if any
m_volumes.render_legacy(GLVolumeCollection::Opaque, m_picking_enabled, m_camera.get_view_matrix(), [this](const GLVolume& volume) { m_volumes.render(GLVolumeCollection::Opaque, m_picking_enabled, m_camera.get_view_matrix(), [this](const GLVolume& volume) {
return (m_render_sla_auxiliaries || volume.composite_id.volume_id >= 0); return (m_render_sla_auxiliaries || volume.composite_id.volume_id >= 0);
}); });
m_volumes.render_legacy(GLVolumeCollection::Transparent, false, m_camera.get_view_matrix());
::glDisable(GL_CLIP_PLANE0);
if (m_use_clipping_planes)
{
glsafe(::glDisable(GL_CLIP_PLANE1));
glsafe(::glDisable(GL_CLIP_PLANE2));
}
} }
m_volumes.render(GLVolumeCollection::Transparent, false, m_camera.get_view_matrix());
m_shader.stop_using();
m_camera_clipping_plane = ClippingPlane::ClipsNothing(); m_camera_clipping_plane = ClippingPlane::ClipsNothing();
glsafe(::glDisable(GL_LIGHTING)); glsafe(::glDisable(GL_LIGHTING));
} }
@ -4025,6 +3995,7 @@ void GLCanvas3D::_render_current_gizmo() const
void GLCanvas3D::_render_gizmos_overlay() const void GLCanvas3D::_render_gizmos_overlay() const
{ {
#if ENABLE_SVG_ICONS
#if ENABLE_RETINA_GL #if ENABLE_RETINA_GL
// m_gizmos.set_overlay_scale(m_retina_helper->get_scale_factor()); // m_gizmos.set_overlay_scale(m_retina_helper->get_scale_factor());
const float scale = m_retina_helper->get_scale_factor()*wxGetApp().toolbar_icon_scale(); const float scale = m_retina_helper->get_scale_factor()*wxGetApp().toolbar_icon_scale();
@ -4035,6 +4006,7 @@ void GLCanvas3D::_render_gizmos_overlay() const
const float size = int(GLGizmosManager::Default_Icons_Size*wxGetApp().toolbar_icon_scale()); const float size = int(GLGizmosManager::Default_Icons_Size*wxGetApp().toolbar_icon_scale());
m_gizmos.set_overlay_icon_size(size); //! #ys_FIXME_experiment m_gizmos.set_overlay_icon_size(size); //! #ys_FIXME_experiment
#endif /* __WXMSW__ */ #endif /* __WXMSW__ */
#endif // ENABLE_SVG_ICONS
m_gizmos.render_overlay(*this, m_selection); m_gizmos.render_overlay(*this, m_selection);
} }
@ -4288,13 +4260,9 @@ void GLCanvas3D::_render_sla_slices() const
void GLCanvas3D::_render_selection_sidebar_hints() const void GLCanvas3D::_render_selection_sidebar_hints() const
{ {
if (m_use_VBOs) m_shader.start_using();
m_shader.start_using();
m_selection.render_sidebar_hints(m_sidebar_field); m_selection.render_sidebar_hints(m_sidebar_field);
m_shader.stop_using();
if (m_use_VBOs)
m_shader.stop_using();
} }
@ -4507,7 +4475,7 @@ void GLCanvas3D::_load_print_toolpaths()
_3DScene::extrusionentity_to_verts(print->skirt(), print_zs[i], Point(0, 0), volume); _3DScene::extrusionentity_to_verts(print->skirt(), print_zs[i], Point(0, 0), volume);
} }
volume.bounding_box = volume.indexed_vertex_array.bounding_box(); volume.bounding_box = volume.indexed_vertex_array.bounding_box();
volume.indexed_vertex_array.finalize_geometry(m_use_VBOs && m_initialized); volume.indexed_vertex_array.finalize_geometry();
} }
void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, const std::vector<std::string>& str_tool_colors, const std::vector<double>& color_print_values) void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, const std::vector<std::string>& str_tool_colors, const std::vector<double>& color_print_values)
@ -4694,7 +4662,7 @@ void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, c
[](const GLVolume *volume) { return volume->empty(); }), [](const GLVolume *volume) { return volume->empty(); }),
m_volumes.volumes.end()); m_volumes.volumes.end());
for (size_t i = volumes_cnt_initial; i < m_volumes.volumes.size(); ++i) for (size_t i = volumes_cnt_initial; i < m_volumes.volumes.size(); ++i)
m_volumes.volumes[i]->indexed_vertex_array.finalize_geometry(m_use_VBOs && m_initialized); m_volumes.volumes[i]->indexed_vertex_array.finalize_geometry();
BOOST_LOG_TRIVIAL(debug) << "Loading print object toolpaths in parallel - end"; BOOST_LOG_TRIVIAL(debug) << "Loading print object toolpaths in parallel - end";
} }
@ -4865,7 +4833,7 @@ void GLCanvas3D::_load_wipe_tower_toolpaths(const std::vector<std::string>& str_
[](const GLVolume *volume) { return volume->empty(); }), [](const GLVolume *volume) { return volume->empty(); }),
m_volumes.volumes.end()); m_volumes.volumes.end());
for (size_t i = volumes_cnt_initial; i < m_volumes.volumes.size(); ++i) for (size_t i = volumes_cnt_initial; i < m_volumes.volumes.size(); ++i)
m_volumes.volumes[i]->indexed_vertex_array.finalize_geometry(m_use_VBOs && m_initialized); m_volumes.volumes[i]->indexed_vertex_array.finalize_geometry();
BOOST_LOG_TRIVIAL(debug) << "Loading wipe tower toolpaths in parallel - end"; BOOST_LOG_TRIVIAL(debug) << "Loading wipe tower toolpaths in parallel - end";
} }
@ -5050,7 +5018,7 @@ void GLCanvas3D::_load_gcode_extrusion_paths(const GCodePreviewData& preview_dat
{ {
GLVolume* volume = m_volumes.volumes[i]; GLVolume* volume = m_volumes.volumes[i];
volume->bounding_box = volume->indexed_vertex_array.bounding_box(); volume->bounding_box = volume->indexed_vertex_array.bounding_box();
volume->indexed_vertex_array.finalize_geometry(m_use_VBOs && m_initialized); volume->indexed_vertex_array.finalize_geometry();
} }
} }
} }
@ -5105,7 +5073,7 @@ void GLCanvas3D::_load_gcode_travel_paths(const GCodePreviewData& preview_data,
{ {
GLVolume* volume = m_volumes.volumes[i]; GLVolume* volume = m_volumes.volumes[i];
volume->bounding_box = volume->indexed_vertex_array.bounding_box(); volume->bounding_box = volume->indexed_vertex_array.bounding_box();
volume->indexed_vertex_array.finalize_geometry(m_use_VBOs && m_initialized); volume->indexed_vertex_array.finalize_geometry();
} }
} }
} }
@ -5339,7 +5307,7 @@ void GLCanvas3D::_load_gcode_retractions(const GCodePreviewData& preview_data)
// finalize volumes and sends geometry to gpu // finalize volumes and sends geometry to gpu
volume->bounding_box = volume->indexed_vertex_array.bounding_box(); volume->bounding_box = volume->indexed_vertex_array.bounding_box();
volume->indexed_vertex_array.finalize_geometry(m_use_VBOs && m_initialized); volume->indexed_vertex_array.finalize_geometry();
} }
} }
@ -5370,7 +5338,7 @@ void GLCanvas3D::_load_gcode_unretractions(const GCodePreviewData& preview_data)
// finalize volumes and sends geometry to gpu // finalize volumes and sends geometry to gpu
volume->bounding_box = volume->indexed_vertex_array.bounding_box(); volume->bounding_box = volume->indexed_vertex_array.bounding_box();
volume->indexed_vertex_array.finalize_geometry(m_use_VBOs && m_initialized); volume->indexed_vertex_array.finalize_geometry();
} }
} }
@ -5396,7 +5364,7 @@ void GLCanvas3D::_load_fff_shells()
instance_ids[i] = i; instance_ids[i] = i;
} }
m_volumes.load_object(model_obj, object_id, instance_ids, "object", m_use_VBOs && m_initialized); m_volumes.load_object(model_obj, object_id, instance_ids, "object");
++object_id; ++object_id;
} }
@ -5416,9 +5384,9 @@ void GLCanvas3D::_load_fff_shells()
float brim_spacing = print->config().nozzle_diameter.values[0] * 1.25f - first_layer_height * (1. - M_PI_4); float brim_spacing = print->config().nozzle_diameter.values[0] * 1.25f - first_layer_height * (1. - M_PI_4);
if (!print->is_step_done(psWipeTower)) if (!print->is_step_done(psWipeTower))
depth = (900.f/config.wipe_tower_width) * (float)(extruders_count - 1) ; depth = (900.f/config.wipe_tower_width) * (float)(extruders_count - 1);
m_volumes.load_wipe_tower_preview(1000, config.wipe_tower_x, config.wipe_tower_y, config.wipe_tower_width, depth, max_z, config.wipe_tower_rotation_angle, m_volumes.load_wipe_tower_preview(1000, config.wipe_tower_x, config.wipe_tower_y, config.wipe_tower_width, depth, max_z, config.wipe_tower_rotation_angle,
m_use_VBOs && m_initialized, !print->is_step_done(psWipeTower), brim_spacing * 4.5f); !print->is_step_done(psWipeTower), brim_spacing * 4.5f);
} }
} }
} }
@ -5436,8 +5404,8 @@ void GLCanvas3D::_load_sla_shells()
const TriangleMesh &mesh, const float color[4], bool outside_printer_detection_enabled) { const TriangleMesh &mesh, const float color[4], bool outside_printer_detection_enabled) {
m_volumes.volumes.emplace_back(new GLVolume(color)); m_volumes.volumes.emplace_back(new GLVolume(color));
GLVolume& v = *m_volumes.volumes.back(); GLVolume& v = *m_volumes.volumes.back();
v.indexed_vertex_array.load_mesh(mesh, m_use_VBOs); v.indexed_vertex_array.load_mesh(mesh);
v.shader_outside_printer_detection_enabled = outside_printer_detection_enabled; v.shader_outside_printer_detection_enabled = outside_printer_detection_enabled;
v.composite_id.volume_id = volume_id; v.composite_id.volume_id = volume_id;
v.set_instance_offset(unscale(instance.shift(0), instance.shift(1), 0)); v.set_instance_offset(unscale(instance.shift(0), instance.shift(1), 0));
v.set_instance_rotation(Vec3d(0.0, 0.0, (double)instance.rotation)); v.set_instance_rotation(Vec3d(0.0, 0.0, (double)instance.rotation));
@ -5464,7 +5432,7 @@ void GLCanvas3D::_load_sla_shells()
GLVolume& v = *m_volumes.volumes[i]; GLVolume& v = *m_volumes.volumes[i];
// finalize volumes and sends geometry to gpu // finalize volumes and sends geometry to gpu
v.bounding_box = v.indexed_vertex_array.bounding_box(); v.bounding_box = v.indexed_vertex_array.bounding_box();
v.indexed_vertex_array.finalize_geometry(m_use_VBOs); v.indexed_vertex_array.finalize_geometry();
// apply shift z // apply shift z
v.set_sla_shift_z(shift_z); v.set_sla_shift_z(shift_z);
} }
@ -5640,7 +5608,7 @@ bool GLCanvas3D::_is_any_volume_outside() const
void GLCanvas3D::_resize_toolbars() const void GLCanvas3D::_resize_toolbars() const
{ {
Size cnv_size = get_canvas_size(); Size cnv_size = get_canvas_size();
float zoom = get_camera_zoom(); float zoom = (float)m_camera.get_zoom();
float inv_zoom = (zoom != 0.0f) ? 1.0f / zoom : 0.0f; float inv_zoom = (zoom != 0.0f) ? 1.0f / zoom : 0.0f;
#if ENABLE_RETINA_GL #if ENABLE_RETINA_GL
@ -5690,19 +5658,16 @@ void GLCanvas3D::_resize_toolbars() const
} }
} }
if (m_view_toolbar != nullptr)
{
#if ENABLE_RETINA_GL #if ENABLE_RETINA_GL
m_view_toolbar.set_icons_scale(m_retina_helper->get_scale_factor()); m_view_toolbar.set_icons_scale(m_retina_helper->get_scale_factor());
#else #else
m_view_toolbar.set_icons_scale(m_canvas->GetContentScaleFactor()); m_view_toolbar.set_icons_scale(m_canvas->GetContentScaleFactor());
#endif /* __WXMSW__ */ #endif /* __WXMSW__ */
// places the toolbar on the bottom-left corner of the 3d scene // places the toolbar on the bottom-left corner of the 3d scene
float top = (-0.5f * (float)cnv_size.get_height() + m_view_toolbar.get_height()) * inv_zoom; float top = (-0.5f * (float)cnv_size.get_height() + m_view_toolbar.get_height()) * inv_zoom;
float left = -0.5f * (float)cnv_size.get_width() * inv_zoom; float left = -0.5f * (float)cnv_size.get_width() * inv_zoom;
m_view_toolbar.set_position(top, left); m_view_toolbar.set_position(top, left);
}
} }
#endif // !ENABLE_SVG_ICONS #endif // !ENABLE_SVG_ICONS

View file

@ -452,7 +452,6 @@ private:
// Screen is only refreshed from the OnIdle handler if it is dirty. // Screen is only refreshed from the OnIdle handler if it is dirty.
bool m_dirty; bool m_dirty;
bool m_initialized; bool m_initialized;
bool m_use_VBOs;
bool m_apply_zoom_to_volumes_filter; bool m_apply_zoom_to_volumes_filter;
mutable std::vector<int> m_hover_volume_idxs; mutable std::vector<int> m_hover_volume_idxs;
bool m_warning_texture_enabled; bool m_warning_texture_enabled;
@ -494,7 +493,7 @@ public:
wxGLCanvas* get_wxglcanvas() { return m_canvas; } wxGLCanvas* get_wxglcanvas() { return m_canvas; }
const wxGLCanvas* get_wxglcanvas() const { return m_canvas; } const wxGLCanvas* get_wxglcanvas() const { return m_canvas; }
bool init(bool useVBOs); bool init();
void post_event(wxEvent &&event); void post_event(wxEvent &&event);
void set_as_dirty(); void set_as_dirty();

View file

@ -192,7 +192,6 @@ GLCanvas3DManager::GLInfo GLCanvas3DManager::s_gl_info;
GLCanvas3DManager::GLCanvas3DManager() GLCanvas3DManager::GLCanvas3DManager()
: m_context(nullptr) : m_context(nullptr)
, m_gl_initialized(false) , m_gl_initialized(false)
, m_use_VBOs(false)
{ {
} }
@ -266,8 +265,6 @@ void GLCanvas3DManager::init_gl()
if (!m_gl_initialized) if (!m_gl_initialized)
{ {
glewInit(); glewInit();
const AppConfig* config = GUI::get_app_config();
m_use_VBOs = s_gl_info.is_version_greater_or_equal_to(2, 0);
m_gl_initialized = true; m_gl_initialized = true;
if (GLEW_EXT_texture_compression_s3tc) if (GLEW_EXT_texture_compression_s3tc)
s_compressed_textures_supported = true; s_compressed_textures_supported = true;
@ -323,7 +320,7 @@ bool GLCanvas3DManager::init(GLCanvas3D& canvas)
if (!m_gl_initialized) if (!m_gl_initialized)
init_gl(); init_gl();
return canvas.init(m_use_VBOs); return canvas.init();
} }
void GLCanvas3DManager::detect_multisample(int* attribList) void GLCanvas3DManager::detect_multisample(int* attribList)

View file

@ -75,7 +75,6 @@ private:
wxGLContext* m_context; wxGLContext* m_context;
static GLInfo s_gl_info; static GLInfo s_gl_info;
bool m_gl_initialized; bool m_gl_initialized;
bool m_use_VBOs;
static EMultisampleState s_multisample; static EMultisampleState s_multisample;
static bool s_compressed_textures_supported; static bool s_compressed_textures_supported;

View file

@ -188,7 +188,7 @@ bool GLToolbar::init(const ItemsIconsTexture::Metadata& icons_texture, const Bac
return true; return true;
std::string path = resources_dir() + "/icons/"; std::string path = resources_dir() + "/icons/";
bool res = !icons_texture.filename.empty() && m_icons_texture.texture.load_from_file(path + icons_texture.filename, false); bool res = !icons_texture.filename.empty() && m_icons_texture.texture.load_from_file(path + icons_texture.filename, false, true);
if (res) if (res)
m_icons_texture.metadata = icons_texture; m_icons_texture.metadata = icons_texture;
#endif // ENABLE_SVG_ICONS #endif // ENABLE_SVG_ICONS

View file

@ -49,7 +49,7 @@ bool GLGizmosManager::init(GLCanvas3D& parent)
if (!m_icons_texture.metadata.filename.empty()) if (!m_icons_texture.metadata.filename.empty())
{ {
if (!m_icons_texture.texture.load_from_file(resources_dir() + "/icons/" + m_icons_texture.metadata.filename, false)) if (!m_icons_texture.texture.load_from_file(resources_dir() + "/icons/" + m_icons_texture.metadata.filename, false, true))
{ {
reset(); reset();
return false; return false;
@ -1072,7 +1072,7 @@ void GLGizmosManager::do_render_overlay(const GLCanvas3D& canvas, const Selectio
#if ENABLE_SVG_ICONS #if ENABLE_SVG_ICONS
it->second->render_input_window(width, 0.5f * cnv_h - top_y * zoom, toolbar_top, selection); it->second->render_input_window(width, 0.5f * cnv_h - top_y * zoom, toolbar_top, selection);
#else #else
it->second->render_input_window(2.0f * m_overlay_border + icon_size * zoom, 0.5f * cnv_h - top_y * zoom, toolbar_top, selection); it->second->render_input_window(2.0f * m_overlay_border + scaled_icons_size * zoom, 0.5f * cnv_h - top_y * zoom, toolbar_top, selection);
#endif // ENABLE_SVG_ICONS #endif // ENABLE_SVG_ICONS
} }
#if ENABLE_SVG_ICONS #if ENABLE_SVG_ICONS

View file

@ -99,14 +99,14 @@ void Selection::set_volumes(GLVolumePtrs* volumes)
update_valid(); update_valid();
} }
bool Selection::init(bool useVBOs) bool Selection::init()
{ {
if (!m_arrow.init(useVBOs)) if (!m_arrow.init())
return false; return false;
m_arrow.set_scale(5.0 * Vec3d::Ones()); m_arrow.set_scale(5.0 * Vec3d::Ones());
if (!m_curved_arrow.init(useVBOs)) if (!m_curved_arrow.init())
return false; return false;
m_curved_arrow.set_scale(5.0 * Vec3d::Ones()); m_curved_arrow.set_scale(5.0 * Vec3d::Ones());

View file

@ -212,7 +212,7 @@ public:
#endif // ENABLE_RENDER_SELECTION_CENTER #endif // ENABLE_RENDER_SELECTION_CENTER
void set_volumes(GLVolumePtrs* volumes); void set_volumes(GLVolumePtrs* volumes);
bool init(bool useVBOs); bool init();
bool is_enabled() const { return m_enabled; } bool is_enabled() const { return m_enabled; }
void set_enabled(bool enable) { m_enabled = enable; } void set_enabled(bool enable) { m_enabled = enable; }