mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-10-22 08:11:11 -06:00
Objects rendering moved to c++
This commit is contained in:
parent
b4beb7aae9
commit
b36243ba10
9 changed files with 192 additions and 55 deletions
|
@ -1792,6 +1792,16 @@ void _3DScene::reset_volumes(wxGLCanvas* canvas)
|
|||
s_canvas_mgr.reset_volumes(canvas);
|
||||
}
|
||||
|
||||
DynamicPrintConfig* _3DScene::get_config(wxGLCanvas* canvas)
|
||||
{
|
||||
return s_canvas_mgr.get_config(canvas);
|
||||
}
|
||||
|
||||
void _3DScene::set_config(wxGLCanvas* canvas, DynamicPrintConfig* config)
|
||||
{
|
||||
s_canvas_mgr.set_config(canvas, config);
|
||||
}
|
||||
|
||||
void _3DScene::set_bed_shape(wxGLCanvas* canvas, const Pointfs& shape)
|
||||
{
|
||||
return s_canvas_mgr.set_bed_shape(canvas, shape);
|
||||
|
@ -1988,6 +1998,11 @@ void _3DScene::render_volumes(wxGLCanvas* canvas, bool fake_colors)
|
|||
s_canvas_mgr.render_volumes(canvas, fake_colors);
|
||||
}
|
||||
|
||||
void _3DScene::render_objects(wxGLCanvas* canvas, bool useVBOs)
|
||||
{
|
||||
s_canvas_mgr.render_objects(canvas, useVBOs);
|
||||
}
|
||||
|
||||
void _3DScene::render_cutting_plane(wxGLCanvas* canvas)
|
||||
{
|
||||
s_canvas_mgr.render_cutting_plane(canvas);
|
||||
|
@ -2013,6 +2028,11 @@ void _3DScene::register_on_viewport_changed_callback(wxGLCanvas* canvas, void* c
|
|||
s_canvas_mgr.register_on_viewport_changed_callback(canvas, callback);
|
||||
}
|
||||
|
||||
void _3DScene::register_on_mark_volumes_for_layer_height(wxGLCanvas* canvas, void* callback)
|
||||
{
|
||||
s_canvas_mgr.register_on_mark_volumes_for_layer_height(canvas, callback);
|
||||
}
|
||||
|
||||
//void _3DScene::_glew_init()
|
||||
//{
|
||||
// glewInit();
|
||||
|
|
|
@ -555,9 +555,11 @@ public:
|
|||
|
||||
static GLVolumeCollection* get_volumes(wxGLCanvas* canvas);
|
||||
static void set_volumes(wxGLCanvas* canvas, GLVolumeCollection* volumes);
|
||||
|
||||
static void reset_volumes(wxGLCanvas* canvas);
|
||||
|
||||
static DynamicPrintConfig* get_config(wxGLCanvas* canvas);
|
||||
static void set_config(wxGLCanvas* canvas, DynamicPrintConfig* config);
|
||||
|
||||
static void set_bed_shape(wxGLCanvas* canvas, const Pointfs& shape);
|
||||
static void set_auto_bed_shape(wxGLCanvas* canvas);
|
||||
|
||||
|
@ -612,6 +614,7 @@ public:
|
|||
static void render_bed(wxGLCanvas* canvas);
|
||||
static void render_axes(wxGLCanvas* canvas);
|
||||
static void render_volumes(wxGLCanvas* canvas, bool fake_colors);
|
||||
static void render_objects(wxGLCanvas* canvas, bool useVBOs);
|
||||
static void render_cutting_plane(wxGLCanvas* canvas);
|
||||
static void render_warning_texture(wxGLCanvas* canvas);
|
||||
static void render_legend_texture(wxGLCanvas* canvas);
|
||||
|
@ -619,6 +622,7 @@ public:
|
|||
static void render_texture(wxGLCanvas* canvas, unsigned int tex_id, float left, float right, float bottom, float top);
|
||||
|
||||
static void register_on_viewport_changed_callback(wxGLCanvas* canvas, void* callback);
|
||||
static void register_on_mark_volumes_for_layer_height(wxGLCanvas* canvas, void* callback);
|
||||
|
||||
// static void _glew_init();
|
||||
//##################################################################################################################
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include "../../slic3r/GUI/3DScene.hpp"
|
||||
#include "../../slic3r/GUI/GLShader.hpp"
|
||||
#include "../../libslic3r/ClipperUtils.hpp"
|
||||
#include "../../libslic3r/PrintConfig.hpp"
|
||||
|
||||
#include <wx/glcanvas.h>
|
||||
|
||||
|
@ -477,6 +478,7 @@ GLCanvas3D::GLCanvas3D(wxGLCanvas* canvas, wxGLContext* context)
|
|||
: m_canvas(canvas)
|
||||
, m_context(context)
|
||||
, m_volumes(nullptr)
|
||||
, m_config(nullptr)
|
||||
, m_dirty(true)
|
||||
, m_apply_zoom_to_volumes_filter(false)
|
||||
, m_warning_texture_enabled(false)
|
||||
|
@ -612,6 +614,16 @@ void GLCanvas3D::reset_volumes()
|
|||
}
|
||||
}
|
||||
|
||||
DynamicPrintConfig* GLCanvas3D::get_config()
|
||||
{
|
||||
return m_config;
|
||||
}
|
||||
|
||||
void GLCanvas3D::set_config(DynamicPrintConfig* config)
|
||||
{
|
||||
m_config = config;
|
||||
}
|
||||
|
||||
void GLCanvas3D::set_bed_shape(const Pointfs& shape)
|
||||
{
|
||||
m_bed.set_shape(shape);
|
||||
|
@ -935,6 +947,51 @@ void GLCanvas3D::render_volumes(bool fake_colors) const
|
|||
::glEnable(GL_CULL_FACE);
|
||||
}
|
||||
|
||||
void GLCanvas3D::render_objects(bool useVBOs)
|
||||
{
|
||||
if (m_volumes == nullptr)
|
||||
return;
|
||||
|
||||
::glEnable(GL_LIGHTING);
|
||||
|
||||
if (!is_shader_enabled())
|
||||
render_volumes(false);
|
||||
else if (useVBOs)
|
||||
{
|
||||
if (is_picking_enabled())
|
||||
{
|
||||
m_on_mark_volumes_for_layer_height.call();
|
||||
|
||||
if (m_config != nullptr)
|
||||
{
|
||||
const BoundingBoxf3& bed_bb = bed_bounding_box();
|
||||
m_volumes->set_print_box((float)bed_bb.min.x, (float)bed_bb.min.y, 0.0f, (float)bed_bb.max.x, (float)bed_bb.max.y, (float)m_config->opt_float("max_print_height"));
|
||||
m_volumes->check_outside_state(m_config);
|
||||
}
|
||||
// do not cull backfaces to show broken geometry, if any
|
||||
::glDisable(GL_CULL_FACE);
|
||||
}
|
||||
|
||||
start_using_shader();
|
||||
m_volumes->render_VBOs();
|
||||
stop_using_shader();
|
||||
|
||||
if (is_picking_enabled())
|
||||
::glEnable(GL_CULL_FACE);
|
||||
}
|
||||
else
|
||||
{
|
||||
// do not cull backfaces to show broken geometry, if any
|
||||
if (is_picking_enabled())
|
||||
::glDisable(GL_CULL_FACE);
|
||||
|
||||
m_volumes->render_legacy();
|
||||
|
||||
if (is_picking_enabled())
|
||||
::glEnable(GL_CULL_FACE);
|
||||
}
|
||||
}
|
||||
|
||||
void GLCanvas3D::render_cutting_plane() const
|
||||
{
|
||||
m_cutting_plane.render(volumes_bounding_box());
|
||||
|
@ -1036,6 +1093,12 @@ void GLCanvas3D::register_on_viewport_changed_callback(void* callback)
|
|||
m_on_viewport_changed_callback.register_callback(callback);
|
||||
}
|
||||
|
||||
void GLCanvas3D::register_on_mark_volumes_for_layer_height(void* callback)
|
||||
{
|
||||
if (callback != nullptr)
|
||||
m_on_mark_volumes_for_layer_height.register_callback(callback);
|
||||
}
|
||||
|
||||
void GLCanvas3D::on_size(wxSizeEvent& evt)
|
||||
{
|
||||
set_dirty(true);
|
||||
|
@ -1210,6 +1273,7 @@ float GLCanvas3D::_get_zoom_to_bounding_box_factor(const BoundingBoxf3& bbox) co
|
|||
void GLCanvas3D::_deregister_callbacks()
|
||||
{
|
||||
m_on_viewport_changed_callback.deregister_callback();
|
||||
m_on_mark_volumes_for_layer_height.deregister_callback();
|
||||
}
|
||||
|
||||
} // namespace GUI
|
||||
|
|
|
@ -14,6 +14,7 @@ class wxKeyEvent;
|
|||
namespace Slic3r {
|
||||
|
||||
class GLVolumeCollection;
|
||||
class DynamicPrintConfig;
|
||||
class GLShader;
|
||||
class ExPolygon;
|
||||
|
||||
|
@ -171,6 +172,7 @@ private:
|
|||
Shader m_shader;
|
||||
|
||||
GLVolumeCollection* m_volumes;
|
||||
DynamicPrintConfig* m_config;
|
||||
|
||||
bool m_dirty;
|
||||
bool m_apply_zoom_to_volumes_filter;
|
||||
|
@ -179,6 +181,7 @@ private:
|
|||
bool m_picking_enabled;
|
||||
|
||||
PerlCallback m_on_viewport_changed_callback;
|
||||
PerlCallback m_on_mark_volumes_for_layer_height;
|
||||
|
||||
public:
|
||||
GLCanvas3D(wxGLCanvas* canvas, wxGLContext* context);
|
||||
|
@ -197,9 +200,11 @@ public:
|
|||
|
||||
GLVolumeCollection* get_volumes();
|
||||
void set_volumes(GLVolumeCollection* volumes);
|
||||
|
||||
void reset_volumes();
|
||||
|
||||
DynamicPrintConfig* get_config();
|
||||
void set_config(DynamicPrintConfig* config);
|
||||
|
||||
// Set the bed shape to a single closed 2D polygon(array of two element arrays),
|
||||
// triangulate the bed and store the triangles into m_bed.m_triangles,
|
||||
// fills the m_bed.m_grid_lines and sets m_bed.m_origin.
|
||||
|
@ -259,6 +264,7 @@ public:
|
|||
void render_bed() const;
|
||||
void render_axes() const;
|
||||
void render_volumes(bool fake_colors) const;
|
||||
void render_objects(bool useVBOs);
|
||||
void render_cutting_plane() const;
|
||||
void render_warning_texture() const;
|
||||
void render_legend_texture() const;
|
||||
|
@ -266,6 +272,7 @@ public:
|
|||
void render_texture(unsigned int tex_id, float left, float right, float bottom, float top) const;
|
||||
|
||||
void register_on_viewport_changed_callback(void* callback);
|
||||
void register_on_mark_volumes_for_layer_height(void* callback);
|
||||
|
||||
void on_size(wxSizeEvent& evt);
|
||||
void on_idle(wxIdleEvent& evt);
|
||||
|
|
|
@ -200,6 +200,19 @@ void GLCanvas3DManager::reset_volumes(wxGLCanvas* canvas)
|
|||
it->second->reset_volumes();
|
||||
}
|
||||
|
||||
DynamicPrintConfig* GLCanvas3DManager::get_config(wxGLCanvas* canvas)
|
||||
{
|
||||
CanvasesMap::const_iterator it = _get_canvas(canvas);
|
||||
return (it != m_canvases.end()) ? it->second->get_config() : nullptr;
|
||||
}
|
||||
|
||||
void GLCanvas3DManager::set_config(wxGLCanvas* canvas, DynamicPrintConfig* config)
|
||||
{
|
||||
CanvasesMap::iterator it = _get_canvas(canvas);
|
||||
if (it != m_canvases.end())
|
||||
it->second->set_config(config);
|
||||
}
|
||||
|
||||
void GLCanvas3DManager::set_bed_shape(wxGLCanvas* canvas, const Pointfs& shape)
|
||||
{
|
||||
CanvasesMap::iterator it = _get_canvas(canvas);
|
||||
|
@ -463,6 +476,13 @@ void GLCanvas3DManager::render_volumes(wxGLCanvas* canvas, bool fake_colors) con
|
|||
it->second->render_volumes(fake_colors);
|
||||
}
|
||||
|
||||
void GLCanvas3DManager::render_objects(wxGLCanvas* canvas, bool useVBOs)
|
||||
{
|
||||
CanvasesMap::const_iterator it = _get_canvas(canvas);
|
||||
if (it != m_canvases.end())
|
||||
it->second->render_objects(useVBOs);
|
||||
}
|
||||
|
||||
void GLCanvas3DManager::render_cutting_plane(wxGLCanvas* canvas) const
|
||||
{
|
||||
CanvasesMap::const_iterator it = _get_canvas(canvas);
|
||||
|
@ -498,6 +518,13 @@ void GLCanvas3DManager::register_on_viewport_changed_callback(wxGLCanvas* canvas
|
|||
it->second->register_on_viewport_changed_callback(callback);
|
||||
}
|
||||
|
||||
void GLCanvas3DManager::register_on_mark_volumes_for_layer_height(wxGLCanvas* canvas, void* callback)
|
||||
{
|
||||
CanvasesMap::iterator it = _get_canvas(canvas);
|
||||
if (it != m_canvases.end())
|
||||
it->second->register_on_mark_volumes_for_layer_height(callback);
|
||||
}
|
||||
|
||||
GLCanvas3DManager::CanvasesMap::iterator GLCanvas3DManager::_get_canvas(wxGLCanvas* canvas)
|
||||
{
|
||||
return (canvas == nullptr) ? m_canvases.end() : m_canvases.find(canvas);
|
||||
|
|
|
@ -63,9 +63,11 @@ public:
|
|||
|
||||
GLVolumeCollection* get_volumes(wxGLCanvas* canvas);
|
||||
void set_volumes(wxGLCanvas* canvas, GLVolumeCollection* volumes);
|
||||
|
||||
void reset_volumes(wxGLCanvas* canvas);
|
||||
|
||||
DynamicPrintConfig* get_config(wxGLCanvas* canvas);
|
||||
void set_config(wxGLCanvas* canvas, DynamicPrintConfig* config);
|
||||
|
||||
void set_bed_shape(wxGLCanvas* canvas, const Pointfs& shape);
|
||||
void set_auto_bed_shape(wxGLCanvas* canvas);
|
||||
|
||||
|
@ -120,6 +122,7 @@ public:
|
|||
void render_bed(wxGLCanvas* canvas) const;
|
||||
void render_axes(wxGLCanvas* canvas) const;
|
||||
void render_volumes(wxGLCanvas* canvas, bool fake_colors) const;
|
||||
void render_objects(wxGLCanvas* canvas, bool useVBOs);
|
||||
void render_cutting_plane(wxGLCanvas* canvas) const;
|
||||
void render_warning_texture(wxGLCanvas* canvas) const;
|
||||
void render_legend_texture(wxGLCanvas* canvas) const;
|
||||
|
@ -127,6 +130,7 @@ public:
|
|||
void render_texture(wxGLCanvas* canvas, unsigned int tex_id, float left, float right, float bottom, float top) const;
|
||||
|
||||
void register_on_viewport_changed_callback(wxGLCanvas* canvas, void* callback);
|
||||
void register_on_mark_volumes_for_layer_height(wxGLCanvas* canvas, void* callback);
|
||||
|
||||
private:
|
||||
CanvasesMap::iterator _get_canvas(wxGLCanvas* canvas);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue