Legend texture moved to c++

This commit is contained in:
Enrico Turri 2018-05-21 14:57:43 +02:00
parent 3fdc5e20a7
commit bf7b9eb3e7
9 changed files with 129 additions and 52 deletions

View File

@ -58,7 +58,6 @@ __PACKAGE__->mk_accessors( qw(_quat init
_layer_height_edited
_legend_enabled
_mouse_dragging
) );
@ -190,9 +189,7 @@ sub new {
# $self->_stheta(45);
# $self->_sphi(45);
# $self->_zoom(1);
#==============================================================================================================================
$self->_legend_enabled(0);
#==============================================================================================================================
# $self->_legend_enabled(0);
# $self->_warning_enabled(0);
#==============================================================================================================================
$self->use_plain_shader(0);
@ -291,12 +288,12 @@ sub new {
return $self;
}
sub set_legend_enabled {
my ($self, $value) = @_;
$self->_legend_enabled($value);
}
#==============================================================================================================================
#sub set_legend_enabled {
# my ($self, $value) = @_;
# $self->_legend_enabled($value);
#}
#
#sub set_warning_enabled {
# my ($self, $value) = @_;
# $self->_warning_enabled($value);
@ -1621,6 +1618,7 @@ sub Render {
#==============================================================================================================================
Slic3r::GUI::_3DScene::render_cutting_plane($self);
Slic3r::GUI::_3DScene::render_warning_texture($self);
Slic3r::GUI::_3DScene::render_legend_texture($self);
# if (defined $self->cutting_plane_z) {
# # draw cutting plane
@ -1652,11 +1650,11 @@ sub Render {
#
# # draw warning message
# $self->draw_warning;
#
# # draw gcode preview legend
# $self->draw_legend;
#==============================================================================================================================
# draw gcode preview legend
$self->draw_legend;
$self->draw_active_object_annotations;
$self->SwapBuffers();
@ -1919,49 +1917,40 @@ sub draw_active_object_annotations {
glEnable(GL_DEPTH_TEST);
}
sub draw_legend {
my ($self) = @_;
if (!$self->_legend_enabled) {
return;
}
# If the legend texture has not been loaded into the GPU, do it now.
my $tex_id = Slic3r::GUI::_3DScene::finalize_legend_texture;
if ($tex_id > 0)
{
my $tex_w = Slic3r::GUI::_3DScene::get_legend_texture_width;
my $tex_h = Slic3r::GUI::_3DScene::get_legend_texture_height;
if (($tex_w > 0) && ($tex_h > 0))
{
glDisable(GL_DEPTH_TEST);
glPushMatrix();
glLoadIdentity();
my ($cw, $ch) = $self->GetSizeWH;
#==============================================================================================================================
my $zoom = Slic3r::GUI::_3DScene::get_camera_zoom($self);
my $l = (-0.5 * $cw) / $zoom;
my $t = (0.5 * $ch) / $zoom;
my $r = $l + $tex_w / $zoom;
my $b = $t - $tex_h / $zoom;
Slic3r::GUI::_3DScene::render_texture($self, $tex_id, $l, $r, $b, $t);
#sub draw_legend {
# my ($self) = @_;
#
# if (!$self->_legend_enabled) {
# return;
# }
#
# # If the legend texture has not been loaded into the GPU, do it now.
# my $tex_id = Slic3r::GUI::_3DScene::finalize_legend_texture;
# if ($tex_id > 0)
# {
# my $tex_w = Slic3r::GUI::_3DScene::get_legend_texture_width;
# my $tex_h = Slic3r::GUI::_3DScene::get_legend_texture_height;
# if (($tex_w > 0) && ($tex_h > 0))
# {
# glDisable(GL_DEPTH_TEST);
# glPushMatrix();
# glLoadIdentity();
#
# my ($cw, $ch) = $self->GetSizeWH;
#
# my $l = (-0.5 * $cw) / $self->_zoom;
# my $t = (0.5 * $ch) / $self->_zoom;
# my $r = $l + $tex_w / $self->_zoom;
# my $b = $t - $tex_h / $self->_zoom;
# $self->_render_texture($tex_id, $l, $r, $b, $t);
#==============================================================================================================================
glPopMatrix();
glEnable(GL_DEPTH_TEST);
}
}
}
#==============================================================================================================================
#
# glPopMatrix();
# glEnable(GL_DEPTH_TEST);
# }
# }
#}
#
#sub draw_warning {
# my ($self) = @_;
#

View File

@ -177,10 +177,16 @@ sub new {
my $preview = $self->{preview_notebook}->GetCurrentPage;
if ($preview == $self->{preview3D})
{
$self->{preview3D}->canvas->set_legend_enabled(1);
#==============================================================================================================================
Slic3r::GUI::_3DScene::enable_legend_texture($self->{preview3D}->canvas, 1);
# $self->{preview3D}->canvas->set_legend_enabled(1);
#==============================================================================================================================
$self->{preview3D}->load_print(1);
} else {
$self->{preview3D}->canvas->set_legend_enabled(0);
#==============================================================================================================================
Slic3r::GUI::_3DScene::enable_legend_texture($self->{preview3D}->canvas, 0);
# $self->{preview3D}->canvas->set_legend_enabled(0);
#==============================================================================================================================
}
$preview->OnActivate if $preview->can('OnActivate');

View File

@ -1903,6 +1903,11 @@ void _3DScene::enable_warning_texture(wxGLCanvas* canvas, bool enable)
s_canvas_mgr.enable_warning_texture(canvas, enable);
}
void _3DScene::enable_legend_texture(wxGLCanvas* canvas, bool enable)
{
s_canvas_mgr.enable_legend_texture(canvas, enable);
}
void _3DScene::zoom_to_bed(wxGLCanvas* canvas)
{
s_canvas_mgr.zoom_to_bed(canvas);
@ -1938,6 +1943,11 @@ void _3DScene::render_warning_texture(wxGLCanvas* canvas)
s_canvas_mgr.render_warning_texture(canvas);
}
void _3DScene::render_legend_texture(wxGLCanvas* canvas)
{
s_canvas_mgr.render_legend_texture(canvas);
}
void _3DScene::render_texture(wxGLCanvas* canvas, unsigned int tex_id, float left, float right, float bottom, float top)
{
s_canvas_mgr.render_texture(canvas, tex_id, left, right, bottom, top);

View File

@ -591,6 +591,7 @@ public:
static bool is_layers_editing_enabled(wxGLCanvas* canvas);
static void enable_warning_texture(wxGLCanvas* canvas, bool enable);
static void enable_legend_texture(wxGLCanvas* canvas, bool enable);
static void zoom_to_bed(wxGLCanvas* canvas);
static void zoom_to_volumes(wxGLCanvas* canvas);
@ -600,6 +601,7 @@ public:
static void render_axes(wxGLCanvas* canvas);
static void render_cutting_plane(wxGLCanvas* canvas);
static void render_warning_texture(wxGLCanvas* canvas);
static void render_legend_texture(wxGLCanvas* canvas);
static void render_texture(wxGLCanvas* canvas, unsigned int tex_id, float left, float right, float bottom, float top);

View File

@ -412,6 +412,7 @@ GLCanvas3D::GLCanvas3D(wxGLCanvas* canvas, wxGLContext* context)
, m_dirty(true)
, m_apply_zoom_to_volumes_filter(false)
, m_warning_texture_enabled(false)
, m_legend_texture_enabled(false)
{
}
@ -688,6 +689,11 @@ void GLCanvas3D::enable_warning_texture(bool enable)
m_warning_texture_enabled = enable;
}
void GLCanvas3D::enable_legend_texture(bool enable)
{
m_legend_texture_enabled = enable;
}
void GLCanvas3D::zoom_to_bed()
{
_zoom_to_bounding_box(bed_bounding_box());
@ -770,7 +776,7 @@ void GLCanvas3D::render_warning_texture()
float zoom = get_camera_zoom();
float inv_zoom = (zoom != 0.0f) ? 1.0f / zoom : 0.0f;
float l = (-0.5f * (float)w) * inv_zoom;
float t = (-0.5f * cnv_size.second + (float)h) * inv_zoom;
float t = (-0.5f * (float)cnv_size.second + (float)h) * inv_zoom;
float r = l + (float)w * inv_zoom;
float b = t - (float)h * inv_zoom;
@ -782,6 +788,38 @@ void GLCanvas3D::render_warning_texture()
}
}
void GLCanvas3D::render_legend_texture()
{
if (!m_legend_texture_enabled)
return;
// If the legend texture has not been loaded into the GPU, do it now.
unsigned int tex_id = _3DScene::finalize_legend_texture();
if (tex_id > 0)
{
unsigned int w = _3DScene::get_legend_texture_width();
unsigned int h = _3DScene::get_legend_texture_height();
if ((w > 0) && (h > 0))
{
::glDisable(GL_DEPTH_TEST);
::glPushMatrix();
::glLoadIdentity();
std::pair<int, int> cnv_size = _get_canvas_size();
float zoom = get_camera_zoom();
float inv_zoom = (zoom != 0.0f) ? 1.0f / zoom : 0.0f;
float l = (-0.5f * (float)cnv_size.first) * inv_zoom;
float t = (0.5f * (float)cnv_size.second) * inv_zoom;
float r = l + (float)w * inv_zoom;
float b = t - (float)h * inv_zoom;
render_texture(tex_id, l, r, b, t);
::glPopMatrix();
::glEnable(GL_DEPTH_TEST);
}
}
}
void GLCanvas3D::render_texture(unsigned int tex_id, float left, float right, float bottom, float top)
{
::glColor4f(1.0f, 1.0f, 1.0f, 1.0f);

View File

@ -152,6 +152,7 @@ private:
bool m_dirty;
bool m_apply_zoom_to_volumes_filter;
bool m_warning_texture_enabled;
bool m_legend_texture_enabled;
PerlCallback m_on_viewport_changed_callback;
@ -215,6 +216,7 @@ public:
bool is_layers_editing_enabled() const;
void enable_warning_texture(bool enable);
void enable_legend_texture(bool enable);
void zoom_to_bed();
void zoom_to_volumes();
@ -224,6 +226,7 @@ public:
void render_axes();
void render_cutting_plane();
void render_warning_texture();
void render_legend_texture();
void render_texture(unsigned int tex_id, float left, float right, float bottom, float top);

View File

@ -362,6 +362,13 @@ void GLCanvas3DManager::enable_warning_texture(wxGLCanvas* canvas, bool enable)
it->second->enable_warning_texture(enable);
}
void GLCanvas3DManager::enable_legend_texture(wxGLCanvas* canvas, bool enable)
{
CanvasesMap::iterator it = _get_canvas(canvas);
if (it != m_canvases.end())
it->second->enable_legend_texture(enable);
}
void GLCanvas3DManager::zoom_to_bed(wxGLCanvas* canvas)
{
CanvasesMap::iterator it = _get_canvas(canvas);
@ -411,6 +418,13 @@ void GLCanvas3DManager::render_warning_texture(wxGLCanvas* canvas)
it->second->render_warning_texture();
}
void GLCanvas3DManager::render_legend_texture(wxGLCanvas* canvas)
{
CanvasesMap::iterator it = _get_canvas(canvas);
if (it != m_canvases.end())
it->second->render_legend_texture();
}
void GLCanvas3DManager::render_texture(wxGLCanvas* canvas, unsigned int tex_id, float left, float right, float bottom, float top)
{
CanvasesMap::iterator it = _get_canvas(canvas);

View File

@ -101,6 +101,7 @@ public:
bool is_layers_editing_enabled(wxGLCanvas* canvas) const;
void enable_warning_texture(wxGLCanvas* canvas, bool enable);
void enable_legend_texture(wxGLCanvas* canvas, bool enable);
void zoom_to_bed(wxGLCanvas* canvas);
void zoom_to_volumes(wxGLCanvas* canvas);
@ -110,6 +111,7 @@ public:
void render_axes(wxGLCanvas* canvas);
void render_cutting_plane(wxGLCanvas* canvas);
void render_warning_texture(wxGLCanvas* canvas);
void render_legend_texture(wxGLCanvas* canvas);
void render_texture(wxGLCanvas* canvas, unsigned int tex_id, float left, float right, float bottom, float top);

View File

@ -418,6 +418,13 @@ enable_warning_texture(canvas, enable)
CODE:
_3DScene::enable_warning_texture((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"), enable);
void
enable_legend_texture(canvas, enable)
SV *canvas;
bool enable;
CODE:
_3DScene::enable_legend_texture((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"), enable);
void
zoom_to_bed(canvas)
SV *canvas;
@ -461,6 +468,12 @@ render_warning_texture(canvas)
CODE:
_3DScene::render_warning_texture((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"));
void
render_legend_texture(canvas)
SV *canvas;
CODE:
_3DScene::render_legend_texture((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"));
void
render_texture(canvas, tex_id, left, right, bottom, top)
SV *canvas;