mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-11 16:57:53 -06:00
Tech ENABLE_GLINDEXEDVERTEXARRAY_REMOVAL - Replace GLIndexedVertexArray with GLModel - GLGizmoFlatten::PlaneData::vbo
(cherry picked from commit prusa3d/PrusaSlicer@ffa3a1d8fc)
This commit is contained in:
parent
f9de4ec399
commit
6eed22015a
4 changed files with 61 additions and 28 deletions
|
@ -17,6 +17,16 @@
|
||||||
namespace Slic3r {
|
namespace Slic3r {
|
||||||
namespace GUI {
|
namespace GUI {
|
||||||
|
|
||||||
|
void GLModel::Geometry::reserve_vertices(size_t vertices_count)
|
||||||
|
{
|
||||||
|
vertices.reserve(vertices_count * vertex_stride_floats(format));
|
||||||
|
}
|
||||||
|
|
||||||
|
void GLModel::Geometry::reserve_indices(size_t indices_count)
|
||||||
|
{
|
||||||
|
indices.reserve(indices_count * index_stride_bytes(format));
|
||||||
|
}
|
||||||
|
|
||||||
void GLModel::Geometry::add_vertex(const Vec2f& position)
|
void GLModel::Geometry::add_vertex(const Vec2f& position)
|
||||||
{
|
{
|
||||||
assert(format.vertex_layout == EVertexLayout::P2);
|
assert(format.vertex_layout == EVertexLayout::P2);
|
||||||
|
@ -403,8 +413,8 @@ void GLModel::init_from(const indexed_triangle_set& its)
|
||||||
|
|
||||||
Geometry& data = m_render_data.geometry;
|
Geometry& data = m_render_data.geometry;
|
||||||
data.format = { Geometry::EPrimitiveType::Triangles, Geometry::EVertexLayout::P3N3, Geometry::EIndexType::UINT };
|
data.format = { Geometry::EPrimitiveType::Triangles, Geometry::EVertexLayout::P3N3, Geometry::EIndexType::UINT };
|
||||||
data.vertices.reserve(3 * its.indices.size() * Geometry::vertex_stride_floats(data.format));
|
data.reserve_vertices(3 * its.indices.size());
|
||||||
data.indices.reserve(3 * its.indices.size() * Geometry::index_stride_bytes(data.format));
|
data.reserve_indices(3 * its.indices.size());
|
||||||
|
|
||||||
// vertices + indices
|
// vertices + indices
|
||||||
unsigned int vertices_counter = 0;
|
unsigned int vertices_counter = 0;
|
||||||
|
@ -446,8 +456,8 @@ void GLModel::init_from(const Polygons& polygons, float z)
|
||||||
segments_count += polygon.points.size();
|
segments_count += polygon.points.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
data.vertices.reserve(2 * segments_count * Geometry::vertex_stride_floats(data.format));
|
data.reserve_vertices(2 * segments_count);
|
||||||
data.indices.reserve(2 * segments_count * Geometry::index_stride_bytes(data.format));
|
data.reserve_indices(2 * segments_count);
|
||||||
|
|
||||||
// vertices + indices
|
// vertices + indices
|
||||||
unsigned int vertices_counter = 0;
|
unsigned int vertices_counter = 0;
|
||||||
|
@ -713,8 +723,8 @@ GLModel::Geometry stilized_arrow(unsigned short resolution, float tip_radius, fl
|
||||||
|
|
||||||
GLModel::Geometry data;
|
GLModel::Geometry data;
|
||||||
data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3, GLModel::Geometry::EIndexType::USHORT };
|
data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3, GLModel::Geometry::EIndexType::USHORT };
|
||||||
data.vertices.reserve((6 * resolution + 2) * GLModel::Geometry::vertex_stride_floats(data.format));
|
data.reserve_vertices(6 * resolution + 2);
|
||||||
data.indices.reserve((6 * resolution * 3) * GLModel::Geometry::index_stride_bytes(data.format));
|
data.reserve_indices(6 * resolution * 3);
|
||||||
|
|
||||||
const float angle_step = 2.0f * float(PI) / float(resolution);
|
const float angle_step = 2.0f * float(PI) / float(resolution);
|
||||||
std::vector<float> cosines(resolution);
|
std::vector<float> cosines(resolution);
|
||||||
|
@ -787,6 +797,7 @@ GLModel::Geometry stilized_arrow(unsigned short resolution, float tip_radius, fl
|
||||||
const unsigned short v3 = (i < resolution - 1) ? i + 5 * resolution + 3 : 5 * resolution + 2;
|
const unsigned short v3 = (i < resolution - 1) ? i + 5 * resolution + 3 : 5 * resolution + 2;
|
||||||
append_triangle(data, 5 * resolution + 1, v3, i + 5 * resolution + 2);
|
append_triangle(data, 5 * resolution + 1, v3, i + 5 * resolution + 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -797,8 +808,8 @@ GLModel::Geometry circular_arrow(unsigned short resolution, float radius, float
|
||||||
|
|
||||||
GLModel::Geometry data;
|
GLModel::Geometry data;
|
||||||
data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3, GLModel::Geometry::EIndexType::USHORT };
|
data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3, GLModel::Geometry::EIndexType::USHORT };
|
||||||
data.vertices.reserve((8 * (resolution + 1) + 30) * GLModel::Geometry::vertex_stride_floats(data.format));
|
data.reserve_vertices(8 * (resolution + 1) + 30);
|
||||||
data.indices.reserve(((8 * resolution + 16) * 3) * GLModel::Geometry::index_stride_bytes(data.format));
|
data.reserve_indices((8 * resolution + 16) * 3);
|
||||||
|
|
||||||
const float half_thickness = 0.5f * thickness;
|
const float half_thickness = 0.5f * thickness;
|
||||||
const float half_stem_width = 0.5f * stem_width;
|
const float half_stem_width = 0.5f * stem_width;
|
||||||
|
@ -951,6 +962,7 @@ GLModel::Geometry circular_arrow(unsigned short resolution, float radius, float
|
||||||
append_triangle(data, ii, ii + 1, ii + resolution + 2);
|
append_triangle(data, ii, ii + 1, ii + resolution + 2);
|
||||||
append_triangle(data, ii, ii + resolution + 2, ii + resolution + 1);
|
append_triangle(data, ii, ii + resolution + 2, ii + resolution + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -958,8 +970,8 @@ GLModel::Geometry straight_arrow(float tip_width, float tip_height, float stem_w
|
||||||
{
|
{
|
||||||
GLModel::Geometry data;
|
GLModel::Geometry data;
|
||||||
data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3, GLModel::Geometry::EIndexType::USHORT };
|
data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3, GLModel::Geometry::EIndexType::USHORT };
|
||||||
data.vertices.reserve(42 * GLModel::Geometry::vertex_stride_floats(data.format));
|
data.reserve_vertices(42);
|
||||||
data.indices.reserve((24 * 3) * GLModel::Geometry::index_stride_bytes(data.format));
|
data.reserve_indices(72);
|
||||||
|
|
||||||
const float half_thickness = 0.5f * thickness;
|
const float half_thickness = 0.5f * thickness;
|
||||||
const float half_stem_width = 0.5f * stem_width;
|
const float half_stem_width = 0.5f * stem_width;
|
||||||
|
@ -1044,6 +1056,7 @@ GLModel::Geometry straight_arrow(float tip_width, float tip_height, float stem_w
|
||||||
append_triangle(data, 14 + ii, 15 + ii, 17 + ii);
|
append_triangle(data, 14 + ii, 15 + ii, 17 + ii);
|
||||||
append_triangle(data, 14 + ii, 17 + ii, 16 + ii);
|
append_triangle(data, 14 + ii, 17 + ii, 16 + ii);
|
||||||
}
|
}
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1054,8 +1067,8 @@ GLModel::Geometry diamond(unsigned short resolution)
|
||||||
|
|
||||||
GLModel::Geometry data;
|
GLModel::Geometry data;
|
||||||
data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3, GLModel::Geometry::EIndexType::USHORT };
|
data.format = { GLModel::Geometry::EPrimitiveType::Triangles, GLModel::Geometry::EVertexLayout::P3N3, GLModel::Geometry::EIndexType::USHORT };
|
||||||
data.vertices.reserve((resolution + 2) * GLModel::Geometry::vertex_stride_floats(data.format));
|
data.reserve_vertices(resolution + 2);
|
||||||
data.indices.reserve(((2 * (resolution + 1)) * 3) * GLModel::Geometry::index_stride_bytes(data.format));
|
data.reserve_indices((2 * (resolution + 1)) * 3);
|
||||||
|
|
||||||
const float step = 2.0f * float(PI) / float(resolution);
|
const float step = 2.0f * float(PI) / float(resolution);
|
||||||
|
|
||||||
|
@ -1082,6 +1095,7 @@ GLModel::Geometry diamond(unsigned short resolution)
|
||||||
append_triangle(data, i + 0, resolution + 1, i + 1);
|
append_triangle(data, i + 0, resolution + 1, i + 1);
|
||||||
}
|
}
|
||||||
append_triangle(data, resolution - 1, resolution + 1, 0);
|
append_triangle(data, resolution - 1, resolution + 1, 0);
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,6 +60,9 @@ namespace GUI {
|
||||||
std::vector<unsigned char> indices;
|
std::vector<unsigned char> indices;
|
||||||
ColorRGBA color{ ColorRGBA::BLACK() };
|
ColorRGBA color{ ColorRGBA::BLACK() };
|
||||||
|
|
||||||
|
void reserve_vertices(size_t vertices_count);
|
||||||
|
void reserve_indices(size_t indices_count);
|
||||||
|
|
||||||
void add_vertex(const Vec2f& position);
|
void add_vertex(const Vec2f& position);
|
||||||
void add_vertex(const Vec2f& position, const Vec2f& tex_coord);
|
void add_vertex(const Vec2f& position, const Vec2f& tex_coord);
|
||||||
void add_vertex(const Vec3f& position);
|
void add_vertex(const Vec3f& position);
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
// Include GLGizmoBase.hpp before I18N.hpp as it includes some libigl code, which overrides our localization "L" macro.
|
// Include GLGizmoBase.hpp before I18N.hpp as it includes some libigl code, which overrides our localization "L" macro.
|
||||||
#include "GLGizmoFlatten.hpp"
|
#include "GLGizmoFlatten.hpp"
|
||||||
#include "slic3r/GUI/GLCanvas3D.hpp"
|
#include "slic3r/GUI/GLCanvas3D.hpp"
|
||||||
|
#include "slic3r/GUI/GUI_App.hpp"
|
||||||
#include "slic3r/GUI/Gizmos/GLGizmosCommon.hpp"
|
#include "slic3r/GUI/Gizmos/GLGizmosCommon.hpp"
|
||||||
|
|
||||||
#include "libslic3r/Geometry/ConvexHull.hpp"
|
#include "libslic3r/Geometry/ConvexHull.hpp"
|
||||||
|
@ -62,6 +63,11 @@ void GLGizmoFlatten::on_render()
|
||||||
{
|
{
|
||||||
const Selection& selection = m_parent.get_selection();
|
const Selection& selection = m_parent.get_selection();
|
||||||
|
|
||||||
|
GLShaderProgram* shader = wxGetApp().get_shader("flat");
|
||||||
|
if (shader == nullptr)
|
||||||
|
return;
|
||||||
|
|
||||||
|
shader->start_using();
|
||||||
glsafe(::glClear(GL_DEPTH_BUFFER_BIT));
|
glsafe(::glClear(GL_DEPTH_BUFFER_BIT));
|
||||||
|
|
||||||
glsafe(::glEnable(GL_DEPTH_TEST));
|
glsafe(::glEnable(GL_DEPTH_TEST));
|
||||||
|
@ -75,12 +81,7 @@ void GLGizmoFlatten::on_render()
|
||||||
if (this->is_plane_update_necessary())
|
if (this->is_plane_update_necessary())
|
||||||
update_planes();
|
update_planes();
|
||||||
for (int i = 0; i < (int)m_planes.size(); ++i) {
|
for (int i = 0; i < (int)m_planes.size(); ++i) {
|
||||||
if (i == m_hover_id)
|
m_planes[i].vbo.set_color(i == m_hover_id ? GLGizmoBase::FLATTEN_HOVER_COLOR : GLGizmoBase::FLATTEN_COLOR);
|
||||||
glsafe(::glColor4fv(GLGizmoBase::FLATTEN_HOVER_COLOR.data()));
|
|
||||||
else
|
|
||||||
glsafe(::glColor4fv(GLGizmoBase::FLATTEN_COLOR.data()));
|
|
||||||
|
|
||||||
if (m_planes[i].vbo.has_VBOs())
|
|
||||||
m_planes[i].vbo.render();
|
m_planes[i].vbo.render();
|
||||||
}
|
}
|
||||||
glsafe(::glPopMatrix());
|
glsafe(::glPopMatrix());
|
||||||
|
@ -88,11 +89,17 @@ void GLGizmoFlatten::on_render()
|
||||||
|
|
||||||
glsafe(::glEnable(GL_CULL_FACE));
|
glsafe(::glEnable(GL_CULL_FACE));
|
||||||
glsafe(::glDisable(GL_BLEND));
|
glsafe(::glDisable(GL_BLEND));
|
||||||
|
shader->stop_using();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLGizmoFlatten::on_render_for_picking()
|
void GLGizmoFlatten::on_render_for_picking()
|
||||||
{
|
{
|
||||||
const Selection& selection = m_parent.get_selection();
|
const Selection& selection = m_parent.get_selection();
|
||||||
|
GLShaderProgram* shader = wxGetApp().get_shader("flat");
|
||||||
|
if (shader == nullptr)
|
||||||
|
return;
|
||||||
|
|
||||||
|
shader->start_using();
|
||||||
|
|
||||||
glsafe(::glDisable(GL_DEPTH_TEST));
|
glsafe(::glDisable(GL_DEPTH_TEST));
|
||||||
glsafe(::glDisable(GL_BLEND));
|
glsafe(::glDisable(GL_BLEND));
|
||||||
|
@ -105,13 +112,14 @@ void GLGizmoFlatten::on_render_for_picking()
|
||||||
if (this->is_plane_update_necessary())
|
if (this->is_plane_update_necessary())
|
||||||
update_planes();
|
update_planes();
|
||||||
for (int i = 0; i < (int)m_planes.size(); ++i) {
|
for (int i = 0; i < (int)m_planes.size(); ++i) {
|
||||||
glsafe(::glColor4fv(picking_color_component(i).data()));
|
m_planes[i].vbo.set_color(picking_color_component(i));
|
||||||
m_planes[i].vbo.render();
|
m_planes[i].vbo.render();
|
||||||
}
|
}
|
||||||
glsafe(::glPopMatrix());
|
glsafe(::glPopMatrix());
|
||||||
}
|
}
|
||||||
|
|
||||||
glsafe(::glEnable(GL_CULL_FACE));
|
glsafe(::glEnable(GL_CULL_FACE));
|
||||||
|
shader->stop_using();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLGizmoFlatten::set_flattening_data(const ModelObject* model_object)
|
void GLGizmoFlatten::set_flattening_data(const ModelObject* model_object)
|
||||||
|
@ -328,12 +336,20 @@ void GLGizmoFlatten::update_planes()
|
||||||
// And finally create respective VBOs. The polygon is convex with
|
// And finally create respective VBOs. The polygon is convex with
|
||||||
// the vertices in order, so triangulation is trivial.
|
// the vertices in order, so triangulation is trivial.
|
||||||
for (auto& plane : m_planes) {
|
for (auto& plane : m_planes) {
|
||||||
plane.vbo.reserve(plane.vertices.size());
|
GLModel::Geometry init_data;
|
||||||
for (const auto& vert : plane.vertices)
|
const GLModel::Geometry::EIndexType index_type = (plane.vertices.size() < 65536) ? GLModel::Geometry::EIndexType::USHORT : GLModel::Geometry::EIndexType::UINT;
|
||||||
plane.vbo.push_geometry(vert, plane.normal);
|
init_data.format = { GLModel::Geometry::EPrimitiveType::TriangleFan, GLModel::Geometry::EVertexLayout::P3N3, index_type };
|
||||||
for (size_t i=1; i<plane.vertices.size()-1; ++i)
|
init_data.reserve_vertices(plane.vertices.size());
|
||||||
plane.vbo.push_triangle(0, i, i+1); // triangle fan
|
init_data.reserve_indices(plane.vertices.size());
|
||||||
plane.vbo.finalize_geometry(true);
|
// vertices + indices
|
||||||
|
for (size_t i = 0; i < plane.vertices.size(); ++i) {
|
||||||
|
init_data.add_vertex((Vec3f)plane.vertices[i].cast<float>(), (Vec3f)plane.normal.cast<float>());
|
||||||
|
if (index_type == GLModel::Geometry::EIndexType::USHORT)
|
||||||
|
init_data.add_ushort_index(i);
|
||||||
|
else
|
||||||
|
init_data.add_uint_index(i);
|
||||||
|
}
|
||||||
|
plane.vbo.init_from(std::move(init_data));
|
||||||
// FIXME: vertices should really be local, they need not
|
// FIXME: vertices should really be local, they need not
|
||||||
// persist now when we use VBOs
|
// persist now when we use VBOs
|
||||||
plane.vertices.clear();
|
plane.vertices.clear();
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
#define slic3r_GLGizmoFlatten_hpp_
|
#define slic3r_GLGizmoFlatten_hpp_
|
||||||
|
|
||||||
#include "GLGizmoBase.hpp"
|
#include "GLGizmoBase.hpp"
|
||||||
#include "slic3r/GUI/3DScene.hpp"
|
#include "slic3r/GUI/GLModel.hpp"
|
||||||
|
|
||||||
|
|
||||||
namespace Slic3r {
|
namespace Slic3r {
|
||||||
|
@ -22,7 +22,7 @@ private:
|
||||||
|
|
||||||
struct PlaneData {
|
struct PlaneData {
|
||||||
std::vector<Vec3d> vertices; // should be in fact local in update_planes()
|
std::vector<Vec3d> vertices; // should be in fact local in update_planes()
|
||||||
GLIndexedVertexArray vbo;
|
GLModel vbo;
|
||||||
Vec3d normal;
|
Vec3d normal;
|
||||||
float area;
|
float area;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue