Background rendering moved to c++

This commit is contained in:
Enrico Turri 2018-05-21 15:24:52 +02:00
parent bf7b9eb3e7
commit 0f035d0bae
8 changed files with 105 additions and 42 deletions

View File

@ -46,7 +46,6 @@ __PACKAGE__->mk_accessors( qw(_quat init
on_move
on_model_update
volumes
background
_mouse_pos
_hover_volume_idx
@ -183,7 +182,9 @@ sub new {
#==============================================================================================================================
$self->{can_multisample} = $can_multisample;
$self->background(1);
#==============================================================================================================================
# $self->background(1);
#==============================================================================================================================
$self->_quat((0, 0, 0, 1));
#==============================================================================================================================
# $self->_stheta(45);
@ -1491,38 +1492,40 @@ sub Render {
}
}
# draw fixed background
if ($self->background) {
glDisable(GL_LIGHTING);
glPushMatrix();
glLoadIdentity();
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
# Draws a bluish bottom to top gradient over the complete screen.
glDisable(GL_DEPTH_TEST);
glBegin(GL_QUADS);
glColor3f(0.0,0.0,0.0);
glVertex3f(-1.0,-1.0, 1.0);
glVertex3f( 1.0,-1.0, 1.0);
glColor3f(10/255,98/255,144/255);
glVertex3f( 1.0, 1.0, 1.0);
glVertex3f(-1.0, 1.0, 1.0);
glEnd();
glPopMatrix();
glEnable(GL_DEPTH_TEST);
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glEnable(GL_LIGHTING);
}
# draw ground and axes
glDisable(GL_LIGHTING);
#==============================================================================================================================
Slic3r::GUI::_3DScene::render_background($self);
# # draw fixed background
# if ($self->background) {
# glDisable(GL_LIGHTING);
# glPushMatrix();
# glLoadIdentity();
#
# glMatrixMode(GL_PROJECTION);
# glPushMatrix();
# glLoadIdentity();
#
# # Draws a bluish bottom to top gradient over the complete screen.
# glDisable(GL_DEPTH_TEST);
# glBegin(GL_QUADS);
# glColor3f(0.0,0.0,0.0);
# glVertex3f(-1.0,-1.0, 1.0);
# glVertex3f( 1.0,-1.0, 1.0);
# glColor3f(10/255,98/255,144/255);
# glVertex3f( 1.0, 1.0, 1.0);
# glVertex3f(-1.0, 1.0, 1.0);
# glEnd();
# glPopMatrix();
# glEnable(GL_DEPTH_TEST);
#
# glMatrixMode(GL_MODELVIEW);
# glPopMatrix();
# glEnable(GL_LIGHTING);
# }
#
# # draw ground and axes
# glDisable(GL_LIGHTING);
#
# # draw ground
# my $ground_z = GROUND_Z;
#==============================================================================================================================

View File

@ -1923,6 +1923,11 @@ void _3DScene::select_view(wxGLCanvas* canvas, const std::string& direction)
s_canvas_mgr.select_view(canvas, direction);
}
void _3DScene::render_background(wxGLCanvas* canvas)
{
s_canvas_mgr.render_background(canvas);
}
void _3DScene::render_bed(wxGLCanvas* canvas)
{
s_canvas_mgr.render_bed(canvas);

View File

@ -597,6 +597,7 @@ public:
static void zoom_to_volumes(wxGLCanvas* canvas);
static void select_view(wxGLCanvas* canvas, const std::string& direction);
static void render_background(wxGLCanvas* canvas);
static void render_bed(wxGLCanvas* canvas);
static void render_axes(wxGLCanvas* canvas);
static void render_cutting_plane(wxGLCanvas* canvas);

View File

@ -208,6 +208,7 @@ void GLCanvas3D::Bed::render()
unsigned int triangles_vcount = m_triangles.get_data_size() / 3;
if (triangles_vcount > 0)
{
::glDisable(GL_LIGHTING);
::glDisable(GL_DEPTH_TEST);
::glEnable(GL_BLEND);
@ -312,6 +313,7 @@ void GLCanvas3D::Axes::set_length(float length)
void GLCanvas3D::Axes::render()
{
::glDisable(GL_LIGHTING);
// disable depth testing so that axes are not covered by ground
::glDisable(GL_DEPTH_TEST);
::glLineWidth(2.0f);
@ -350,12 +352,18 @@ bool GLCanvas3D::CuttingPlane::set(float z, const ExPolygons& polygons)
return m_lines.set_from_lines(lines, m_z);
}
void GLCanvas3D::CuttingPlane::render_plane(const BoundingBoxf3& bb)
void GLCanvas3D::CuttingPlane::render(const BoundingBoxf3& bb)
{
::glDisable(GL_LIGHTING);
_render_plane(bb);
_render_contour();
}
void GLCanvas3D::CuttingPlane::_render_plane(const BoundingBoxf3& bb)
{
if (m_z >= 0.0f)
{
::glDisable(GL_CULL_FACE);
::glDisable(GL_LIGHTING);
::glEnable(GL_BLEND);
::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@ -378,7 +386,7 @@ void GLCanvas3D::CuttingPlane::render_plane(const BoundingBoxf3& bb)
}
}
void GLCanvas3D::CuttingPlane::render_contour()
void GLCanvas3D::CuttingPlane::_render_contour()
{
::glEnableClientState(GL_VERTEX_ARRAY);
@ -737,22 +745,50 @@ void GLCanvas3D::select_view(const std::string& direction)
}
}
void GLCanvas3D::render_background()
{
static const float COLOR[3] = { 10.0f / 255.0f, 98.0f / 255.0f, 144.0f / 255.0f };
::glDisable(GL_LIGHTING);
::glPushMatrix();
::glLoadIdentity();
::glMatrixMode(GL_PROJECTION);
::glPushMatrix();
::glLoadIdentity();
// Draws a bluish bottom to top gradient over the complete screen.
::glDisable(GL_DEPTH_TEST);
::glBegin(GL_QUADS);
::glColor3f(0.0f, 0.0f, 0.0f);
::glVertex3f(-1.0f, -1.0f, 1.0f);
::glVertex3f(1.0f, -1.0f, 1.0f);
::glColor3f(COLOR[0], COLOR[1], COLOR[2]);
::glVertex3f(1.0f, 1.0f, 1.0f);
::glVertex3f(-1.0f, 1.0f, 1.0f);
::glEnd();
::glEnable(GL_DEPTH_TEST);
::glPopMatrix();
::glMatrixMode(GL_MODELVIEW);
::glPopMatrix();
}
void GLCanvas3D::render_bed()
{
::glDisable(GL_LIGHTING);
m_bed.render();
}
void GLCanvas3D::render_axes()
{
::glDisable(GL_LIGHTING);
m_axes.render();
}
void GLCanvas3D::render_cutting_plane()
{
m_cutting_plane.render_plane(volumes_bounding_box());
m_cutting_plane.render_contour();
m_cutting_plane.render(volumes_bounding_box());
}
void GLCanvas3D::render_warning_texture()

View File

@ -124,8 +124,11 @@ public:
bool set(float z, const ExPolygons& polygons);
void render_plane(const BoundingBoxf3& bb);
void render_contour();
void render(const BoundingBoxf3& bb);
private:
void _render_plane(const BoundingBoxf3& bb);
void _render_contour();
};
class LayersEditing
@ -222,6 +225,7 @@ public:
void zoom_to_volumes();
void select_view(const std::string& direction);
void render_background();
void render_bed();
void render_axes();
void render_cutting_plane();

View File

@ -390,6 +390,13 @@ void GLCanvas3DManager::select_view(wxGLCanvas* canvas, const std::string& direc
it->second->select_view(direction);
}
void GLCanvas3DManager::render_background(wxGLCanvas* canvas)
{
CanvasesMap::iterator it = _get_canvas(canvas);
if (it != m_canvases.end())
it->second->render_background();
}
void GLCanvas3DManager::render_bed(wxGLCanvas* canvas)
{
CanvasesMap::iterator it = _get_canvas(canvas);

View File

@ -107,6 +107,7 @@ public:
void zoom_to_volumes(wxGLCanvas* canvas);
void select_view(wxGLCanvas* canvas, const std::string& direction);
void render_background(wxGLCanvas* canvas);
void render_bed(wxGLCanvas* canvas);
void render_axes(wxGLCanvas* canvas);
void render_cutting_plane(wxGLCanvas* canvas);

View File

@ -444,6 +444,12 @@ select_view(canvas, direction)
CODE:
_3DScene::select_view((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"), direction);
void
render_background(canvas)
SV *canvas;
CODE:
_3DScene::render_background((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"));
void
render_bed(canvas)
SV *canvas;