Tech ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL - Replace GLIndexedVertexArray with GLModel: MeshClipper::m_vertex_array
This commit is contained in:
parent
443a42c6d8
commit
be6922795d
4 changed files with 81 additions and 1 deletions
|
@ -213,15 +213,21 @@ void InstancesHider::render_cut() const
|
||||||
clipper->set_limiting_plane(ClippingPlane::ClipsNothing());
|
clipper->set_limiting_plane(ClippingPlane::ClipsNothing());
|
||||||
|
|
||||||
glsafe(::glPushMatrix());
|
glsafe(::glPushMatrix());
|
||||||
|
#if !ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL
|
||||||
if (mv->is_model_part())
|
if (mv->is_model_part())
|
||||||
glsafe(::glColor3f(0.8f, 0.3f, 0.0f));
|
glsafe(::glColor3f(0.8f, 0.3f, 0.0f));
|
||||||
else {
|
else {
|
||||||
const ColorRGBA color = color_from_model_volume(*mv);
|
const ColorRGBA color = color_from_model_volume(*mv);
|
||||||
glsafe(::glColor4fv(color.data()));
|
glsafe(::glColor4fv(color.data()));
|
||||||
}
|
}
|
||||||
|
#endif // !ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL
|
||||||
glsafe(::glPushAttrib(GL_DEPTH_TEST));
|
glsafe(::glPushAttrib(GL_DEPTH_TEST));
|
||||||
glsafe(::glDisable(GL_DEPTH_TEST));
|
glsafe(::glDisable(GL_DEPTH_TEST));
|
||||||
|
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL
|
||||||
|
clipper->render_cut(mv->is_model_part() ? ColorRGBA(0.8f, 0.3f, 0.0f, 1.0f) : color_from_model_volume(*mv));
|
||||||
|
#else
|
||||||
clipper->render_cut();
|
clipper->render_cut();
|
||||||
|
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL
|
||||||
glsafe(::glPopAttrib());
|
glsafe(::glPopAttrib());
|
||||||
glsafe(::glPopMatrix());
|
glsafe(::glPopMatrix());
|
||||||
|
|
||||||
|
@ -417,8 +423,12 @@ void ObjectClipper::render_cut() const
|
||||||
clipper->set_transformation(trafo);
|
clipper->set_transformation(trafo);
|
||||||
clipper->set_limiting_plane(ClippingPlane(Vec3d::UnitZ(), -SINKING_Z_THRESHOLD));
|
clipper->set_limiting_plane(ClippingPlane(Vec3d::UnitZ(), -SINKING_Z_THRESHOLD));
|
||||||
glsafe(::glPushMatrix());
|
glsafe(::glPushMatrix());
|
||||||
|
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL
|
||||||
|
clipper->render_cut({ 1.0f, 0.37f, 0.0f, 1.0f });
|
||||||
|
#else
|
||||||
glsafe(::glColor3f(1.0f, 0.37f, 0.0f));
|
glsafe(::glColor3f(1.0f, 0.37f, 0.0f));
|
||||||
clipper->render_cut();
|
clipper->render_cut();
|
||||||
|
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL
|
||||||
glsafe(::glPopMatrix());
|
glsafe(::glPopMatrix());
|
||||||
|
|
||||||
++clipper_id;
|
++clipper_id;
|
||||||
|
@ -530,8 +540,12 @@ void SupportsClipper::render_cut() const
|
||||||
m_clipper->set_transformation(supports_trafo);
|
m_clipper->set_transformation(supports_trafo);
|
||||||
|
|
||||||
glsafe(::glPushMatrix());
|
glsafe(::glPushMatrix());
|
||||||
|
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL
|
||||||
|
m_clipper->render_cut({ 1.0f, 0.f, 0.37f, 1.0f });
|
||||||
|
#else
|
||||||
glsafe(::glColor3f(1.0f, 0.f, 0.37f));
|
glsafe(::glColor3f(1.0f, 0.f, 0.37f));
|
||||||
m_clipper->render_cut();
|
m_clipper->render_cut();
|
||||||
|
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL
|
||||||
glsafe(::glPopMatrix());
|
glsafe(::glPopMatrix());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,9 @@
|
||||||
#include "libslic3r/ClipperUtils.hpp"
|
#include "libslic3r/ClipperUtils.hpp"
|
||||||
#include "libslic3r/Model.hpp"
|
#include "libslic3r/Model.hpp"
|
||||||
|
|
||||||
|
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL
|
||||||
|
#include "slic3r/GUI/GUI_App.hpp"
|
||||||
|
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL
|
||||||
#include "slic3r/GUI/Camera.hpp"
|
#include "slic3r/GUI/Camera.hpp"
|
||||||
|
|
||||||
#include <GL/glew.h>
|
#include <GL/glew.h>
|
||||||
|
@ -66,13 +69,34 @@ void MeshClipper::set_transformation(const Geometry::Transformation& trafo)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL
|
||||||
|
void MeshClipper::render_cut(const ColorRGBA& color)
|
||||||
|
#else
|
||||||
void MeshClipper::render_cut()
|
void MeshClipper::render_cut()
|
||||||
|
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL
|
||||||
{
|
{
|
||||||
if (! m_triangles_valid)
|
if (! m_triangles_valid)
|
||||||
recalculate_triangles();
|
recalculate_triangles();
|
||||||
|
|
||||||
|
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL
|
||||||
|
GLShaderProgram* curr_shader = wxGetApp().get_current_shader();
|
||||||
|
if (curr_shader != nullptr)
|
||||||
|
curr_shader->stop_using();
|
||||||
|
|
||||||
|
GLShaderProgram* shader = wxGetApp().get_shader("flat");
|
||||||
|
if (shader != nullptr) {
|
||||||
|
shader->start_using();
|
||||||
|
m_model.set_color(color);
|
||||||
|
m_model.render();
|
||||||
|
shader->stop_using();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (curr_shader != nullptr)
|
||||||
|
curr_shader->start_using();
|
||||||
|
#else
|
||||||
if (m_vertex_array.has_VBOs())
|
if (m_vertex_array.has_VBOs())
|
||||||
m_vertex_array.render();
|
m_vertex_array.render();
|
||||||
|
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -161,6 +185,30 @@ void MeshClipper::recalculate_triangles()
|
||||||
|
|
||||||
tr.pretranslate(0.001 * m_plane.get_normal().normalized()); // to avoid z-fighting
|
tr.pretranslate(0.001 * m_plane.get_normal().normalized()); // to avoid z-fighting
|
||||||
|
|
||||||
|
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL
|
||||||
|
m_model.reset();
|
||||||
|
|
||||||
|
GLModel::Geometry init_data;
|
||||||
|
const GLModel::Geometry::EIndexType index_type = (m_triangles2d.size() < 65536) ? GLModel::Geometry::EIndexType::USHORT : GLModel::Geometry::EIndexType::UINT;
|
||||||
|
init_data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3, index_type };
|
||||||
|
init_data.reserve_vertices(m_triangles2d.size());
|
||||||
|
init_data.reserve_indices(m_triangles2d.size());
|
||||||
|
|
||||||
|
// vertices + indices
|
||||||
|
for (auto it = m_triangles2d.cbegin(); it != m_triangles2d.cend(); it = it + 3) {
|
||||||
|
init_data.add_vertex((Vec3f)(tr * Vec3d((*(it + 0)).x(), (*(it + 0)).y(), height_mesh)).cast<float>(), (Vec3f)up.cast<float>());
|
||||||
|
init_data.add_vertex((Vec3f)(tr * Vec3d((*(it + 1)).x(), (*(it + 1)).y(), height_mesh)).cast<float>(), (Vec3f)up.cast<float>());
|
||||||
|
init_data.add_vertex((Vec3f)(tr * Vec3d((*(it + 2)).x(), (*(it + 2)).y(), height_mesh)).cast<float>(), (Vec3f)up.cast<float>());
|
||||||
|
const size_t idx = it - m_triangles2d.cbegin();
|
||||||
|
if (index_type == GLModel::Geometry::EIndexType::USHORT)
|
||||||
|
init_data.add_ushort_triangle((unsigned short)idx, (unsigned short)idx + 1, (unsigned short)idx + 2);
|
||||||
|
else
|
||||||
|
init_data.add_uint_triangle((unsigned int)idx, (unsigned int)idx + 1, (unsigned int)idx + 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!init_data.is_empty())
|
||||||
|
m_model.init_from(std::move(init_data));
|
||||||
|
#else
|
||||||
m_vertex_array.release_geometry();
|
m_vertex_array.release_geometry();
|
||||||
for (auto it=m_triangles2d.cbegin(); it != m_triangles2d.cend(); it=it+3) {
|
for (auto it=m_triangles2d.cbegin(); it != m_triangles2d.cend(); it=it+3) {
|
||||||
m_vertex_array.push_geometry(tr * Vec3d((*(it+0))(0), (*(it+0))(1), height_mesh), up);
|
m_vertex_array.push_geometry(tr * Vec3d((*(it+0))(0), (*(it+0))(1), height_mesh), up);
|
||||||
|
@ -170,6 +218,7 @@ void MeshClipper::recalculate_triangles()
|
||||||
m_vertex_array.push_triangle(idx, idx+1, idx+2);
|
m_vertex_array.push_triangle(idx, idx+1, idx+2);
|
||||||
}
|
}
|
||||||
m_vertex_array.finalize_geometry(true);
|
m_vertex_array.finalize_geometry(true);
|
||||||
|
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL
|
||||||
|
|
||||||
m_triangles_valid = true;
|
m_triangles_valid = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,11 @@
|
||||||
#include "libslic3r/SLA/IndexedMesh.hpp"
|
#include "libslic3r/SLA/IndexedMesh.hpp"
|
||||||
#include "admesh/stl.h"
|
#include "admesh/stl.h"
|
||||||
|
|
||||||
|
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL
|
||||||
|
#include "slic3r/GUI/GLModel.hpp"
|
||||||
|
#else
|
||||||
#include "slic3r/GUI/3DScene.hpp"
|
#include "slic3r/GUI/3DScene.hpp"
|
||||||
|
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL
|
||||||
|
|
||||||
#include <cfloat>
|
#include <cfloat>
|
||||||
|
|
||||||
|
@ -69,7 +73,8 @@ public:
|
||||||
|
|
||||||
|
|
||||||
// MeshClipper class cuts a mesh and is able to return a triangulated cut.
|
// MeshClipper class cuts a mesh and is able to return a triangulated cut.
|
||||||
class MeshClipper {
|
class MeshClipper
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
// Inform MeshClipper about which plane we want to use to cut the mesh
|
// Inform MeshClipper about which plane we want to use to cut the mesh
|
||||||
// This is supposed to be in world coordinates.
|
// This is supposed to be in world coordinates.
|
||||||
|
@ -92,7 +97,11 @@ public:
|
||||||
|
|
||||||
// Render the triangulated cut. Transformation matrices should
|
// Render the triangulated cut. Transformation matrices should
|
||||||
// be set in world coords.
|
// be set in world coords.
|
||||||
|
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL
|
||||||
|
void render_cut(const ColorRGBA& color);
|
||||||
|
#else
|
||||||
void render_cut();
|
void render_cut();
|
||||||
|
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void recalculate_triangles();
|
void recalculate_triangles();
|
||||||
|
@ -103,7 +112,11 @@ private:
|
||||||
ClippingPlane m_plane;
|
ClippingPlane m_plane;
|
||||||
ClippingPlane m_limiting_plane = ClippingPlane::ClipsNothing();
|
ClippingPlane m_limiting_plane = ClippingPlane::ClipsNothing();
|
||||||
std::vector<Vec2f> m_triangles2d;
|
std::vector<Vec2f> m_triangles2d;
|
||||||
|
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL
|
||||||
|
GLModel m_model;
|
||||||
|
#else
|
||||||
GLIndexedVertexArray m_vertex_array;
|
GLIndexedVertexArray m_vertex_array;
|
||||||
|
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL
|
||||||
bool m_triangles_valid = false;
|
bool m_triangles_valid = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,10 @@
|
||||||
#include <libslic3r/ObjectID.hpp>
|
#include <libslic3r/ObjectID.hpp>
|
||||||
#include <libslic3r/Utils.hpp>
|
#include <libslic3r/Utils.hpp>
|
||||||
|
|
||||||
|
#if ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL
|
||||||
|
#include "slic3r/GUI/3DScene.hpp"
|
||||||
|
#endif // ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL
|
||||||
|
|
||||||
#include <boost/foreach.hpp>
|
#include <boost/foreach.hpp>
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
|
|
Loading…
Reference in a new issue