OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::GUI::GLModel Class Reference

#include </home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/GLModel.hpp>

Collaboration diagram for Slic3r::GUI::GLModel:

Classes

struct  Geometry
struct  RenderData

Public Member Functions

 GLModel ()=default
virtual ~GLModel ()
size_t vertices_count () const
size_t indices_count () const
size_t vertices_size_floats () const
size_t vertices_size_bytes () const
size_t indices_size_bytes () const
const Geometry & get_geometry () const
void init_from (Geometry &&data)
void init_from (const TriangleMesh &mesh)
void init_from (const indexed_triangle_set &its)
void init_from (const Polygons &polygons, float z)
bool init_from_file (const std::string &filename)
void set_color (const ColorRGBA &color)
const ColorRGBA & get_color () const
void reset ()
void render (GLShaderProgram *shader=nullptr)
void render (const std::pair< size_t, size_t > &range, GLShaderProgram *shader=nullptr)
void render_instanced (unsigned int instances_vbo, unsigned int instances_count)
bool is_initialized () const
bool is_empty () const
const BoundingBoxf3 & get_bounding_box () const
const std::string & get_filename () const
bool is_render_disabled () const
void enable_render ()
void disable_render ()
size_t cpu_memory_used () const
size_t gpu_memory_used () const

Private Member Functions

bool send_to_gpu ()

Private Attributes

RenderData m_render_data
bool m_render_disabled { false }
BoundingBoxf3 m_bounding_box
std::string m_filename

Detailed Description


Class Documentation

◆ Slic3r::GUI::GLModel::RenderData

struct Slic3r::GUI::GLModel::RenderData
Collaboration diagram for Slic3r::GUI::GLModel::RenderData:
Class Members
Geometry geometry
unsigned int ibo_id { 0 }
size_t indices_count { 0 }
unsigned int vao_id { 0 }
unsigned int vbo_id { 0 }
size_t vertices_count { 0 }

Constructor & Destructor Documentation

◆ GLModel()

Slic3r::GUI::GLModel::GLModel ( )
default

◆ ~GLModel()

virtual Slic3r::GUI::GLModel::~GLModel ( )
inlinevirtual
159{ reset(); }
void reset()
Definition GLModel.cpp:547

References reset().

Here is the call graph for this function:

Member Function Documentation

◆ cpu_memory_used()

size_t Slic3r::GUI::GLModel::cpu_memory_used ( ) const
inline
197 {
198 size_t ret = 0;
199 if (!m_render_data.geometry.vertices.empty())
200 ret += vertices_size_bytes();
201 if (!m_render_data.geometry.indices.empty())
202 ret += indices_size_bytes();
203 return ret;
204 }
size_t indices_size_bytes() const
Definition GLModel.hpp:169
size_t vertices_size_bytes() const
Definition GLModel.hpp:167
RenderData m_render_data
Definition GLModel.hpp:144

References indices_size_bytes(), m_render_data, and vertices_size_bytes().

Referenced by Slic3r::GLVolume::cpu_memory_used().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ disable_render()

void Slic3r::GUI::GLModel::disable_render ( )
inline
195{ m_render_disabled = true; }
bool m_render_disabled
Definition GLModel.hpp:153

References m_render_disabled.

◆ enable_render()

void Slic3r::GUI::GLModel::enable_render ( )
inline
194{ m_render_disabled = false; }

References m_render_disabled.

◆ get_bounding_box()

const BoundingBoxf3 & Slic3r::GUI::GLModel::get_bounding_box ( ) const
inline
190{ return m_bounding_box; }
BoundingBoxf3 m_bounding_box
Definition GLModel.hpp:154

References m_bounding_box.

Referenced by Slic3r::GUI::GLCanvas3D::_shadow_casters_signature(), Slic3r::GLVolume::bounding_box(), and Slic3r::GUI::contains().

Here is the caller graph for this function:

◆ get_color()

const ColorRGBA & Slic3r::GUI::GLModel::get_color ( ) const
inline
180{ return m_render_data.geometry.color; }

References m_render_data.

◆ get_filename()

const std::string & Slic3r::GUI::GLModel::get_filename ( ) const
inline
191{ return m_filename; }
std::string m_filename
Definition GLModel.hpp:155

References m_filename.

◆ get_geometry()

const Geometry & Slic3r::GUI::GLModel::get_geometry ( ) const
inline
171{ return m_render_data.geometry; }

References m_render_data.

Referenced by Slic3r::GUI::contains(), and Slic3r::GUI::init_raycaster_from_model().

Here is the caller graph for this function:

◆ gpu_memory_used()

size_t Slic3r::GUI::GLModel::gpu_memory_used ( ) const
inline
205 {
206 size_t ret = 0;
207 if (m_render_data.geometry.vertices.empty())
208 ret += vertices_size_bytes();
209 if (m_render_data.geometry.indices.empty())
210 ret += indices_size_bytes();
211 return ret;
212 }

References indices_size_bytes(), m_render_data, and vertices_size_bytes().

Referenced by Slic3r::GLVolume::gpu_memory_used().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ indices_count()

size_t Slic3r::GUI::GLModel::indices_count ( ) const
inline
163 { return m_render_data.indices_count > 0 ?
164 m_render_data.indices_count : m_render_data.geometry.indices_count(); }

References m_render_data.

Referenced by Slic3r::GUI::GLCanvas3D::_shadow_casters_signature(), Slic3r::GUI::GLModel::Geometry::extract_index(), Slic3r::GUI::GLModel::Geometry::get_as_indexed_triangle_set(), indices_size_bytes(), is_initialized(), render(), render_instanced(), send_to_gpu(), and Slic3r::GUI::GLModel::Geometry::set_index().

Here is the caller graph for this function:

◆ indices_size_bytes()

size_t Slic3r::GUI::GLModel::indices_size_bytes ( ) const
inline
size_t indices_count() const
Definition GLModel.hpp:163
static size_t index_stride_bytes(const Geometry &data)
Definition GLModel.cpp:340

References Slic3r::GUI::GLModel::Geometry::index_stride_bytes(), indices_count(), and m_render_data.

Referenced by cpu_memory_used(), and gpu_memory_used().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ init_from() [1/4]

void Slic3r::GUI::GLModel::init_from ( const indexed_triangle_set & its)
429{
430 if (is_initialized()) {
431 // call reset() if you want to reuse this model
432 assert(false);
433 return;
434 }
435
436 if (its.vertices.empty() || its.indices.empty()){
437 assert(false);
438 return;
439 }
440
441 Geometry& data = m_render_data.geometry;
443 data.reserve_vertices(3 * its.indices.size());
444 data.reserve_indices(3 * its.indices.size());
445
446 // CLI thumbnail generation can initialize models without a wx application.
447 const bool smooth_normals_enabled = wxApp::GetInstance() != nullptr && wxGetApp().app_config != nullptr &&
448 wxGetApp().app_config->get_bool(SETTING_OPENGL_PHONG_SMOOTH_NORMALS);
449
450 if (smooth_normals_enabled) {
451 const std::vector<Vec3f> corner_normals = its_smooth_corner_normals(its, 5.0);
452
453 unsigned int vertices_counter = 0;
454 for (uint32_t i = 0; i < its.indices.size(); ++i) {
455 const stl_triangle_vertex_indices face = its.indices[i];
456 for (size_t j = 0; j < 3; ++j)
457 data.add_vertex(its.vertices[face[j]], corner_normals[3 * i + j]);
458 data.add_triangle(vertices_counter, vertices_counter + 1, vertices_counter + 2);
459 vertices_counter += 3;
460 }
461 } else {
462 //Original flat (per-face) normals
463 unsigned int vertices_counter = 0;
464 for (uint32_t i = 0; i < its.indices.size(); ++i) {
465 const stl_triangle_vertex_indices face = its.indices[i];
466 const stl_vertex vertex[3] = {its.vertices[face[0]], its.vertices[face[1]], its.vertices[face[2]]};
467 const stl_vertex n = face_normal_normalized(vertex);
468 for (size_t j = 0; j < 3; ++j)
469 data.add_vertex(vertex[j], n);
470 data.add_triangle(vertices_counter, vertices_counter + 1, vertices_counter + 2);
471 vertices_counter += 3;
472 }
473 }
474
475 // update bounding box
476 for (size_t i = 0; i < vertices_count(); ++i) {
477 m_bounding_box.merge(data.extract_position_3(i).cast<double>());
478 }
479}
#define SETTING_OPENGL_PHONG_SMOOTH_NORMALS
Definition AppConfig.hpp:48
bool is_initialized() const
Definition GLModel.hpp:187
size_t vertices_count() const
Definition GLModel.hpp:161
Vec3f face_normal_normalized(const stl_vertex vertex[3])
Definition TriangleMesh.hpp:350
std::vector< Vec3f > its_smooth_corner_normals(const indexed_triangle_set &its, double threshold_degrees)
Definition TriangleMesh.cpp:1634
Definition GLModel.hpp:28

References Slic3r::GUI::GLModel::Geometry::add_triangle(), Slic3r::GUI::GLModel::Geometry::add_vertex(), Slic3r::GUI::GLModel::Geometry::extract_position_3(), Slic3r::face_normal_normalized(), Slic3r::GUI::GLModel::Geometry::format, is_initialized(), Slic3r::its_smooth_corner_normals(), m_bounding_box, m_render_data, Slic3r::GUI::GLModel::Geometry::P3N3, Slic3r::GUI::GLModel::Geometry::reserve_indices(), Slic3r::GUI::GLModel::Geometry::reserve_vertices(), SETTING_OPENGL_PHONG_SMOOTH_NORMALS, Slic3r::GUI::GLModel::Geometry::Triangles, and vertices_count().

Here is the call graph for this function:

◆ init_from() [2/4]

void Slic3r::GUI::GLModel::init_from ( const Polygons & polygons,
float z )
482{
483 if (is_initialized()) {
484 // call reset() if you want to reuse this model
485 assert(false);
486 return;
487 }
488
489 if (polygons.empty()) {
490 assert(false);
491 return;
492 }
493
494 Geometry& data = m_render_data.geometry;
496
497 size_t segments_count = 0;
498 for (const Polygon& polygon : polygons) {
499 segments_count += polygon.points.size();
500 }
501
502 data.reserve_vertices(2 * segments_count);
503 data.reserve_indices(2 * segments_count);
504
505 // vertices + indices
506 unsigned int vertices_counter = 0;
507 for (const Polygon& poly : polygons) {
508 for (size_t i = 0; i < poly.points.size(); ++i) {
509 const Point& p0 = poly.points[i];
510 const Point& p1 = (i == poly.points.size() - 1) ? poly.points.front() : poly.points[i + 1];
511 data.add_vertex(Vec3f(unscale<float>(p0.x()), unscale<float>(p0.y()), z));
512 data.add_vertex(Vec3f(unscale<float>(p1.x()), unscale<float>(p1.y()), z));
513 vertices_counter += 2;
514 data.add_line(vertices_counter - 2, vertices_counter - 1);
515 }
516 }
517
518 // update bounding box
519 for (size_t i = 0; i < vertices_count(); ++i) {
520 m_bounding_box.merge(data.extract_position_3(i).cast<double>());
521 }
522}
void poly(std::vector< std::pair< Vec2d, Vec2d > > &out, std::initializer_list< Vec2d > p)
Definition DesignSketchTool.cpp:7751
Kernel::Point_3 Point
Definition MeshRepair.cpp:81
Eigen::Matrix< float, 3, 1, Eigen::DontAlign > Vec3f
Definition Point.hpp:65
T unscale(Q v)
Definition libslic3r.h:138

References Slic3r::GUI::GLModel::Geometry::add_line(), Slic3r::GUI::GLModel::Geometry::add_vertex(), Slic3r::GUI::GLModel::Geometry::extract_position_3(), Slic3r::GUI::GLModel::Geometry::format, is_initialized(), Slic3r::GUI::GLModel::Geometry::Lines, m_bounding_box, m_render_data, Slic3r::GUI::GLModel::Geometry::P3, Slic3r::GUI::GLModel::Geometry::reserve_indices(), Slic3r::GUI::GLModel::Geometry::reserve_vertices(), Slic3r::unscale(), and vertices_count().

Here is the call graph for this function:

◆ init_from() [3/4]

void Slic3r::GUI::GLModel::init_from ( const TriangleMesh & mesh)
424{
425 init_from(mesh.its);
426}
void init_from(Geometry &&data)
Definition GLModel.cpp:396

References init_from(), and Slic3r::TriangleMesh::its.

Here is the call graph for this function:

◆ init_from() [4/4]

void Slic3r::GUI::GLModel::init_from ( Geometry && data)
397{
398 if (is_initialized()) {
399 // call reset() if you want to reuse this model
400 assert(false);
401 return;
402 }
403
404 if (data.vertices.empty() || data.indices.empty()) {
405 assert(false);
406 return;
407 }
408
409 m_render_data.geometry = std::move(data);
410
411 // update bounding box
412 for (size_t i = 0; i < vertices_count(); ++i) {
413 const size_t position_stride = Geometry::position_stride_floats(data.format);
414 if (position_stride == 3)
415 m_bounding_box.merge(m_render_data.geometry.extract_position_3(i).cast<double>());
416 else if (position_stride == 2) {
417 const Vec2f position = m_render_data.geometry.extract_position_2(i);
418 m_bounding_box.merge(Vec3f(position.x(), position.y(), 0.0f).cast<double>());
419 }
420 }
421}
Eigen::Matrix< float, 2, 1, Eigen::DontAlign > Vec2f
Definition Point.hpp:64
static size_t position_stride_floats(const Format &format)
Definition GLModel.cpp:268

References is_initialized(), m_bounding_box, m_render_data, Slic3r::GUI::GLModel::Geometry::position_stride_floats(), and vertices_count().

Referenced by Slic3r::GUI::GLCanvas3D::_load_sla_shells(), Slic3r::GUI::GLCanvas3D::_render_sla_slices(), Slic3r::GUI::DesignSketchTool::draw_fill(), Slic3r::GUI::DesignSketchTool::draw_fill_holed(), Slic3r::GUI::DesignSketchTool::draw_quad_strip(), Slic3r::GUI::DesignSketchTool::draw_strokes(), Slic3r::GUI::DesignSketchTool::draw_vertices(), Slic3r::GUI::GLGizmoMeasure::init_circle_glmodel(), Slic3r::GUI::init_exclusion_volume_prism_model(), init_from(), Slic3r::GUI::init_from_angle_arc(), Slic3r::GUI::init_from_circle(), init_from_file(), Slic3r::GUI::init_from_scale(), Slic3r::GUI::init_from_snap_radii(), Slic3r::GUI::init_model_from_expolygons(), Slic3r::GUI::init_model_from_lines(), Slic3r::GUI::init_model_from_lines(), Slic3r::GUI::init_model_from_poly(), Slic3r::GUI::init_model_from_polygons(), Slic3r::GUI::GLGizmoMeasure::init_plane_glmodel(), Slic3r::GLVolumeCollection::load_object_auxiliary(), Slic3r::GLVolumeCollection::load_object_volume(), Slic3r::GLVolumeCollection::load_real_wipe_tower_preview(), Slic3r::GLVolumeCollection::load_wipe_tower_preview(), Slic3r::GUI::MeshClipper::recalculate_triangles(), Slic3r::GUI::GLCanvas3D::reload_scene(), Slic3r::GUI::DesignSketchTool::render_base_pick(), Slic3r::GUI::GLGizmoBase::render_cross_mark(), Slic3r::GUI::DesignSketchTool::render_datum_gizmo(), Slic3r::GUI::DesignSketchTool::render_datum_planes(), Slic3r::GUI::DesignSketchTool::render_helix_gizmo(), Slic3r::GUI::DesignSketchTool::render_hole_gizmo(), Slic3r::GUI::DesignSketchTool::render_reference_axes(), Slic3r::GUI::DesignSketchTool::render_rib_gizmo(), Slic3r::GUI::render_ribbons(), Slic3r::GUI::GLTexture::render_sub_texture(), and Slic3r::GUI::DesignSketchTool::render_view_helpers().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ init_from_file()

bool Slic3r::GUI::GLModel::init_from_file ( const std::string & filename)
525{
526 if (!boost::filesystem::exists(filename))
527 return false;
528
529 if (!boost::algorithm::iends_with(filename, ".stl"))
530 return false;
531
532 Model model;
533 try {
534 model = Model::read_from_file(filename);
535 }
536 catch (std::exception&) {
537 return false;
538 }
539
540 init_from(model.mesh());
541
542 m_filename = filename;
543
544 return true;
545}
static Model read_from_file(const std::string &input_file, DynamicPrintConfig *config=nullptr, ConfigSubstitutionContext *config_substitutions=nullptr, LoadStrategy options=LoadStrategy::AddDefaultInstances, PlateDataPtrs *plate_data=nullptr, std::vector< Preset * > *project_presets=nullptr, bool *is_xxx=nullptr, Semver *file_version=nullptr, Import3mfProgressFn proFn=nullptr, ImportstlProgressFn stlFn=nullptr, BBLProject *project=nullptr, int plate_id=0)
Definition Model.cpp:318

References init_from(), m_filename, Slic3r::Model::mesh(), and Slic3r::Model::read_from_file().

Here is the call graph for this function:

◆ is_empty()

bool Slic3r::GUI::GLModel::is_empty ( ) const
inline
188{ return m_render_data.geometry.is_empty(); }

References m_render_data.

Referenced by Slic3r::GLVolume::empty().

Here is the caller graph for this function:

◆ is_initialized()

bool Slic3r::GUI::GLModel::is_initialized ( ) const
inline
187{ return vertices_count() > 0 && indices_count() > 0; }

References indices_count(), and vertices_count().

Referenced by Slic3r::GUI::GLCanvas3D::_render_sla_slices(), Slic3r::GUI::GLGizmoMeasure::init_circle_glmodel(), init_from(), init_from(), init_from(), Slic3r::GUI::GLGizmoMeasure::init_plane_glmodel(), Slic3r::GUI::UVEditorCanvas::render(), Slic3r::GUI::PartPlate::render_logo_texture(), Slic3r::GUI::GLGizmoTextureDisplacement::render_paint_overlay(), and Slic3r::GLVolume::simple_render().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_render_disabled()

bool Slic3r::GUI::GLModel::is_render_disabled ( ) const
inline
193{ return m_render_disabled; }

References m_render_disabled.

◆ render() [1/2]

void Slic3r::GUI::GLModel::render ( const std::pair< size_t, size_t > & range,
GLShaderProgram * shader = nullptr )
609{
611 return;
612
613 if (range.second == range.first)
614 return;
615
616 if (shader == nullptr && wxApp::GetInstance() != nullptr)
617 shader = wxGetApp().get_current_shader();
618
619 if (shader == nullptr)
620 return;
621
622 // sends data to gpu if not done yet
623 if (m_render_data.vbo_id == 0 || m_render_data.ibo_id == 0) {
624 if (m_render_data.geometry.vertices_count() > 0 && m_render_data.geometry.indices_count() > 0 && !send_to_gpu())
625 return;
626 }
627
628 const Geometry& data = m_render_data.geometry;
629
630 const GLenum mode = get_primitive_mode(data.format);
631 const GLenum index_type = get_index_type(data);
632
633 const size_t vertex_stride_bytes = Geometry::vertex_stride_bytes(data.format);
634 const bool position = Geometry::has_position(data.format);
635 const bool normal = Geometry::has_normal(data.format);
636 const bool tex_coord = Geometry::has_tex_coord(data.format);
637
638#if !SLIC3R_OPENGL_ES
639 if (OpenGLManager::get_gl_info().is_core_profile()) {
640#endif // !SLIC3R_OPENGL_ES
642#if !SLIC3R_OPENGL_ES
643 }
644#endif // !SLIC3R_OPENGL_ES
645 // the following binding is needed to set the vertex attributes
647
648 int position_id = -1;
649 int normal_id = -1;
650 int tex_coord_id = -1;
651
652 if (position) {
653 position_id = shader->get_attrib_location("v_position");
654 if (position_id != -1) {
655 glsafe(::glVertexAttribPointer(position_id, Geometry::position_stride_floats(data.format), GL_FLOAT, GL_FALSE, vertex_stride_bytes, (const void*)Geometry::position_offset_bytes(data.format)));
657 }
658 }
659 if (normal) {
660 normal_id = shader->get_attrib_location("v_normal");
661 if (normal_id != -1) {
662 glsafe(::glVertexAttribPointer(normal_id, Geometry::normal_stride_floats(data.format), GL_FLOAT, GL_FALSE, vertex_stride_bytes, (const void*)Geometry::normal_offset_bytes(data.format)));
664 }
665 }
666 if (tex_coord) {
667 tex_coord_id = shader->get_attrib_location("v_tex_coord");
668 if (tex_coord_id != -1) {
669 glsafe(::glVertexAttribPointer(tex_coord_id, Geometry::tex_coord_stride_floats(data.format), GL_FLOAT, GL_FALSE, vertex_stride_bytes, (const void*)Geometry::tex_coord_offset_bytes(data.format)));
670 glsafe(::glEnableVertexAttribArray(tex_coord_id));
671 }
672 }
673
674 shader->set_uniform("uniform_color", data.color);
675
677 glsafe(::glDrawElements(mode, range.second - range.first, index_type, (const void*)(range.first * Geometry::index_stride_bytes(data))));
679
680 if (tex_coord_id != -1)
682 if (normal_id != -1)
684 if (position_id != -1)
686
688#if !SLIC3R_OPENGL_ES
689 if (OpenGLManager::get_gl_info().is_core_profile()) {
690#endif // !SLIC3R_OPENGL_ES
692#if !SLIC3R_OPENGL_ES
693 }
694#endif // !SLIC3R_OPENGL_ES
695}
#define glsafe(cmd)
Definition OpenGLUtils.hpp:25
bool send_to_gpu()
Definition GLModel.cpp:786
static const GLInfo & get_gl_info()
Definition OpenGLManager.hpp:106
#define glDisableVertexAttribArray
Definition gl.h:3613
#define glBindBuffer
Definition gl.h:3267
#define glBindVertexArray
Definition gl.h:3307
#define GL_FLOAT
Definition gl.h:660
#define glEnableVertexAttribArray
Definition gl.h:3673
#define GL_ARRAY_BUFFER
Definition gl.h:238
unsigned int GLenum
Definition gl.h:2054
#define glDrawElements
Definition gl.h:3633
#define glVertexAttribPointer
Definition gl.h:5315
#define GL_FALSE
Definition gl.h:648
#define GL_ELEMENT_ARRAY_BUFFER
Definition gl.h:636
static GLenum get_index_type(const GLModel::Geometry &data)
Definition GLModel.cpp:592
static GLenum get_primitive_mode(const GLModel::Geometry::Format &format)
Definition GLModel.cpp:577
auto range(Cont &&cont)
Definition libslic3r.h:405
Point normal(Point pt, double scale)
Definition TreeSupport.cpp:112
static bool has_normal(const Format &format)
Definition GLModel.cpp:366
static size_t vertex_stride_bytes(const Format &format)
Definition GLModel.hpp:110
static size_t normal_stride_floats(const Format &format)
Definition GLModel.cpp:298
static size_t tex_coord_stride_floats(const Format &format)
Definition GLModel.cpp:318
static bool has_position(const Format &format)
Definition GLModel.cpp:351
static size_t normal_offset_bytes(const Format &format)
Definition GLModel.hpp:120
static size_t tex_coord_offset_bytes(const Format &format)
Definition GLModel.hpp:125
static size_t position_offset_bytes(const Format &format)
Definition GLModel.hpp:115
static bool has_tex_coord(const Format &format)
Definition GLModel.cpp:381

References Slic3r::GUI::GLModel::Geometry::color, Slic3r::GUI::GLModel::Geometry::format, Slic3r::GLShaderProgram::get_attrib_location(), Slic3r::GUI::OpenGLManager::get_gl_info(), Slic3r::GUI::get_index_type(), Slic3r::GUI::get_primitive_mode(), GL_ARRAY_BUFFER, GL_ELEMENT_ARRAY_BUFFER, GL_FALSE, GL_FLOAT, glBindBuffer, glBindVertexArray, glDisableVertexAttribArray, glDrawElements, glEnableVertexAttribArray, glsafe, glVertexAttribPointer, Slic3r::GUI::GLModel::Geometry::has_normal(), Slic3r::GUI::GLModel::Geometry::has_position(), Slic3r::GUI::GLModel::Geometry::has_tex_coord(), Slic3r::GUI::GLModel::Geometry::index_stride_bytes(), m_render_data, m_render_disabled, Slic3r::normal(), Slic3r::GUI::GLModel::Geometry::normal_offset_bytes(), Slic3r::GUI::GLModel::Geometry::normal_stride_floats(), Slic3r::GUI::GLModel::Geometry::position_offset_bytes(), Slic3r::GUI::GLModel::Geometry::position_stride_floats(), Slic3r::range(), send_to_gpu(), Slic3r::GLShaderProgram::set_uniform(), Slic3r::GUI::GLModel::Geometry::tex_coord_offset_bytes(), Slic3r::GUI::GLModel::Geometry::tex_coord_stride_floats(), and Slic3r::GUI::GLModel::Geometry::vertex_stride_bytes().

Here is the call graph for this function:

◆ render() [2/2]

void Slic3r::GUI::GLModel::render ( GLShaderProgram * shader = nullptr)
604{
605 render(std::make_pair<size_t, size_t>(0, indices_count()), shader);
606}
void render(GLShaderProgram *shader=nullptr)
Definition GLModel.cpp:603

References indices_count(), and render().

Referenced by Slic3r::GUI::GLCanvas3D::_render_shadows(), Slic3r::GUI::GLCanvas3D::_render_sla_slices(), Slic3r::GUI::DesignSketchTool::draw_fill(), Slic3r::GUI::DesignSketchTool::draw_fill_holed(), Slic3r::GUI::DesignSketchTool::draw_quad_strip(), Slic3r::GUI::DesignSketchTool::draw_strokes(), Slic3r::GUI::DesignSketchTool::draw_vertices(), render(), Slic3r::GUI::SceneCache::render(), Slic3r::GUI::UVEditorCanvas::render(), Slic3r::GUI::DesignSketchTool::render_base_pick(), Slic3r::GUI::MeshClipper::render_contour(), Slic3r::GUI::GLGizmoBase::render_cross_mark(), Slic3r::GUI::MeshClipper::render_cut(), Slic3r::GUI::DesignSketchTool::render_datum_gizmo(), Slic3r::GUI::DesignSketchTool::render_datum_planes(), Slic3r::GUI::DesignSketchTool::render_helix_gizmo(), Slic3r::GUI::DesignSketchTool::render_hole_gizmo(), Slic3r::GUI::PartPlate::render_icon_texture(), Slic3r::GUI::GLGizmoCut3D::render_line(), Slic3r::GUI::PartPlate::render_logo_texture(), Slic3r::GUI::GLGizmoCut3D::render_model(), Slic3r::GUI::GLGizmoTextureDisplacement::render_paint_overlay(), Slic3r::GUI::DesignSketchTool::render_reference_axes(), Slic3r::GUI::DesignSketchTool::render_rib_gizmo(), Slic3r::GUI::render_ribbons(), Slic3r::GUI::GLTexture::render_sub_texture(), Slic3r::GUI::DesignSketchTool::render_view_helpers(), and Slic3r::GLVolume::simple_render().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ render_instanced()

void Slic3r::GUI::GLModel::render_instanced ( unsigned int instances_vbo,
unsigned int instances_count )
698{
699 if (instances_vbo == 0 || instances_count == 0)
700 return;
701
702 GLShaderProgram* shader = wxGetApp().get_current_shader();
703 if (shader == nullptr || !boost::algorithm::iends_with(shader->get_name(), "_instanced"))
704 return;
705
706 // vertex attributes
707 const GLint position_id = shader->get_attrib_location("v_position");
708 const GLint normal_id = shader->get_attrib_location("v_normal");
709 if (position_id == -1 || normal_id == -1)
710 return;
711
712 // instance attributes
713 const GLint offset_id = shader->get_attrib_location("i_offset");
714 const GLint scales_id = shader->get_attrib_location("i_scales");
715 if (offset_id == -1 || scales_id == -1)
716 return;
717
718 if (m_render_data.vbo_id == 0 || m_render_data.ibo_id == 0) {
719 if (!send_to_gpu())
720 return;
721 }
722
723#if !SLIC3R_OPENGL_ES
724 if (OpenGLManager::get_gl_info().is_core_profile()) {
725#endif // !SLIC3R_OPENGL_ES
727#if !SLIC3R_OPENGL_ES
728 }
729#endif // !SLIC3R_OPENGL_ES
730
731 glsafe(::glBindBuffer(GL_ARRAY_BUFFER, instances_vbo));
732 const size_t instance_stride = 5 * sizeof(float);
733 glsafe(::glVertexAttribPointer(offset_id, 3, GL_FLOAT, GL_FALSE, instance_stride, (const void*)0));
735 glsafe(::glVertexAttribDivisor(offset_id, 1));
736
737 glsafe(::glVertexAttribPointer(scales_id, 2, GL_FLOAT, GL_FALSE, instance_stride, (const void*)(3 * sizeof(float))));
739 glsafe(::glVertexAttribDivisor(scales_id, 1));
740
741 const Geometry& data = m_render_data.geometry;
742
743 const GLenum mode = get_primitive_mode(data.format);
744 const GLenum index_type = get_index_type(data);
745
746 const size_t vertex_stride_bytes = Geometry::vertex_stride_bytes(data.format);
747 const bool position = Geometry::has_position(data.format);
748 const bool normal = Geometry::has_normal(data.format);
749
751
752 if (position) {
753 glsafe(::glVertexAttribPointer(position_id, Geometry::position_stride_floats(data.format), GL_FLOAT, GL_FALSE, vertex_stride_bytes, (const void*)Geometry::position_offset_bytes(data.format)));
755 }
756
757 if (normal) {
758 glsafe(::glVertexAttribPointer(normal_id, Geometry::normal_stride_floats(data.format), GL_FLOAT, GL_FALSE, vertex_stride_bytes, (const void*)Geometry::normal_offset_bytes(data.format)));
760 }
761
762 shader->set_uniform("uniform_color", data.color);
763
765 glsafe(::glDrawElementsInstanced(mode, indices_count(), index_type, (const void*)0, instances_count));
767
768 if (normal)
770 if (position)
772
775
777#if !SLIC3R_OPENGL_ES
778 if (OpenGLManager::get_gl_info().is_core_profile()) {
779#endif // !SLIC3R_OPENGL_ES
781#if !SLIC3R_OPENGL_ES
782 }
783#endif // !SLIC3R_OPENGL_ES
784}
#define glVertexAttribDivisor
Definition gl.h:5231
int GLint
Definition gl.h:2062
#define glDrawElementsInstanced
Definition gl.h:3639

References Slic3r::GUI::GLModel::Geometry::color, Slic3r::GUI::GLModel::Geometry::format, Slic3r::GLShaderProgram::get_attrib_location(), Slic3r::GUI::OpenGLManager::get_gl_info(), Slic3r::GUI::get_index_type(), Slic3r::GLShaderProgram::get_name(), Slic3r::GUI::get_primitive_mode(), GL_ARRAY_BUFFER, GL_ELEMENT_ARRAY_BUFFER, GL_FALSE, GL_FLOAT, glBindBuffer, glBindVertexArray, glDisableVertexAttribArray, glDrawElementsInstanced, glEnableVertexAttribArray, glsafe, glVertexAttribDivisor, glVertexAttribPointer, Slic3r::GUI::GLModel::Geometry::has_normal(), Slic3r::GUI::GLModel::Geometry::has_position(), indices_count(), m_render_data, Slic3r::normal(), Slic3r::GUI::GLModel::Geometry::normal_offset_bytes(), Slic3r::GUI::GLModel::Geometry::normal_stride_floats(), Slic3r::GUI::GLModel::Geometry::position_offset_bytes(), Slic3r::GUI::GLModel::Geometry::position_stride_floats(), send_to_gpu(), Slic3r::GLShaderProgram::set_uniform(), and Slic3r::GUI::GLModel::Geometry::vertex_stride_bytes().

Here is the call graph for this function:

◆ reset()

void Slic3r::GUI::GLModel::reset ( )
548{
549 // release gpu memory
550 if (m_render_data.ibo_id > 0) {
552 m_render_data.ibo_id = 0;
553 }
554 if (m_render_data.vbo_id > 0) {
556 m_render_data.vbo_id = 0;
557 }
558#if !SLIC3R_OPENGL_ES
559 if (OpenGLManager::get_gl_info().is_core_profile()) {
560#endif // !SLIC3R_OPENGL_ES
561 if (m_render_data.vao_id > 0) {
563 m_render_data.vao_id = 0;
564 }
565#if !SLIC3R_OPENGL_ES
566 }
567#endif // !SLIC3R_OPENGL_ES
568
569 m_render_data.vertices_count = 0;
570 m_render_data.indices_count = 0;
571 m_render_data.geometry.vertices = std::vector<float>();
572 m_render_data.geometry.indices = std::vector<unsigned int>();
573 m_bounding_box = BoundingBoxf3();
574 m_filename = std::string();
575}
#define glDeleteVertexArrays
Definition gl.h:3591
#define glDeleteBuffers
Definition gl.h:3563

References Slic3r::GUI::OpenGLManager::get_gl_info(), glDeleteBuffers, glDeleteVertexArrays, glsafe, m_bounding_box, m_filename, and m_render_data.

Referenced by ~GLModel(), Slic3r::GUI::PartPlate::calc_triangles_from_polygon(), Slic3r::GUI::PartPlate::calc_vertex_for_imex_warn_badge(), Slic3r::GUI::PartPlate::calc_vertex_for_number(), Slic3r::GUI::DesignSketchTool::draw_fill(), Slic3r::GUI::DesignSketchTool::draw_fill_holed(), Slic3r::GUI::DesignSketchTool::draw_quad_strip(), Slic3r::GUI::DesignSketchTool::draw_strokes(), Slic3r::GUI::DesignSketchTool::draw_vertices(), Slic3r::GUI::init_exclusion_volume_prism_model(), Slic3r::GUI::init_from_angle_arc(), Slic3r::GUI::init_model_from_expolygons(), Slic3r::GUI::init_model_from_polygons(), Slic3r::GUI::GLCanvas3D::reload_scene(), and Slic3r::GUI::render_ribbons().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ send_to_gpu()

bool Slic3r::GUI::GLModel::send_to_gpu ( )
private
787{
788 if (m_render_data.vbo_id > 0 || m_render_data.ibo_id > 0) {
789 assert(false);
790 return false;
791 }
792
793 Geometry& data = m_render_data.geometry;
794 if (data.vertices.empty() || data.indices.empty()) {
795 assert(false);
796 return false;
797 }
798
799#if !SLIC3R_OPENGL_ES
800 if (OpenGLManager::get_gl_info().is_core_profile()) {
801#endif // !SLIC3R_OPENGL_ES
804#if !SLIC3R_OPENGL_ES
805 }
806#endif // !SLIC3R_OPENGL_ES
807
808 // vertices
811 glsafe(::glBufferData(GL_ARRAY_BUFFER, data.vertices_size_bytes(), data.vertices.data(), GL_STATIC_DRAW));
813 m_render_data.vertices_count = vertices_count();
814 data.vertices = std::vector<float>();
815
816 // indices
819 const size_t indices_count = data.indices.size();
820 if (m_render_data.vertices_count <= 256) {
821 // convert indices to unsigned char to save gpu memory
822 std::vector<unsigned char> reduced_indices(indices_count);
823 for (size_t i = 0; i < indices_count; ++i) {
824 reduced_indices[i] = (unsigned char)data.indices[i];
825 }
826 data.index_type = Geometry::EIndexType::UBYTE;
827 glsafe(::glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices_count * sizeof(unsigned char), reduced_indices.data(), GL_STATIC_DRAW));
829 }
830 else if (m_render_data.vertices_count <= 65536) {
831 // convert indices to unsigned short to save gpu memory
832 std::vector<unsigned short> reduced_indices(indices_count);
833 for (size_t i = 0; i < data.indices.size(); ++i) {
834 reduced_indices[i] = (unsigned short)data.indices[i];
835 }
836 data.index_type = Geometry::EIndexType::USHORT;
837 glsafe(::glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices_count * sizeof(unsigned short), reduced_indices.data(), GL_STATIC_DRAW));
839 }
840 else {
841 data.index_type = Geometry::EIndexType::UINT;
842 glsafe(::glBufferData(GL_ELEMENT_ARRAY_BUFFER, data.indices_size_bytes(), data.indices.data(), GL_STATIC_DRAW));
844 }
845 m_render_data.indices_count = indices_count;
846 data.indices = std::vector<unsigned int>();
847
848#if !SLIC3R_OPENGL_ES
849 if (OpenGLManager::get_gl_info().is_core_profile()) {
850#endif // !SLIC3R_OPENGL_ES
852#if !SLIC3R_OPENGL_ES
853 }
854#endif // !SLIC3R_OPENGL_ES
855
856 return true;
857}
#define glGenBuffers
Definition gl.h:3769
#define glGenVertexArrays
Definition gl.h:3791
#define glBufferData
Definition gl.h:3339
#define GL_STATIC_DRAW
Definition gl.h:1633

References Slic3r::GUI::OpenGLManager::get_gl_info(), GL_ARRAY_BUFFER, GL_ELEMENT_ARRAY_BUFFER, GL_STATIC_DRAW, glBindBuffer, glBindVertexArray, glBufferData, glGenBuffers, glGenVertexArrays, glsafe, Slic3r::GUI::GLModel::Geometry::index_type, Slic3r::GUI::GLModel::Geometry::indices, indices_count(), Slic3r::GUI::GLModel::Geometry::indices_size_bytes(), m_render_data, Slic3r::GUI::GLModel::Geometry::UBYTE, Slic3r::GUI::GLModel::Geometry::UINT, Slic3r::GUI::GLModel::Geometry::USHORT, Slic3r::GUI::GLModel::Geometry::vertices, vertices_count(), and Slic3r::GUI::GLModel::Geometry::vertices_size_bytes().

Referenced by render(), and render_instanced().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_color()

◆ vertices_count()

◆ vertices_size_bytes()

size_t Slic3r::GUI::GLModel::vertices_size_bytes ( ) const
inline
167{ return vertices_size_floats() * sizeof(float); }
size_t vertices_size_floats() const
Definition GLModel.hpp:166

References vertices_size_floats().

Referenced by cpu_memory_used(), and gpu_memory_used().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ vertices_size_floats()

size_t Slic3r::GUI::GLModel::vertices_size_floats ( ) const
inline
166{ return vertices_count() * Geometry::vertex_stride_floats(m_render_data.geometry.format); }
static size_t vertex_stride_floats(const Format &format)
Definition GLModel.cpp:253

References m_render_data, Slic3r::GUI::GLModel::Geometry::vertex_stride_floats(), and vertices_count().

Referenced by vertices_size_bytes().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ m_bounding_box

BoundingBoxf3 Slic3r::GUI::GLModel::m_bounding_box
private

◆ m_filename

std::string Slic3r::GUI::GLModel::m_filename
private

Referenced by get_filename(), init_from_file(), and reset().

◆ m_render_data

◆ m_render_disabled

bool Slic3r::GUI::GLModel::m_render_disabled { false }
private
153{ false };

Referenced by disable_render(), enable_render(), is_render_disabled(), and render().


The documentation for this class was generated from the following files:
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/GLModel.hpp
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/GLModel.cpp