mirror of
https://git.mirrors.martin98.com/https://github.com/slic3r/Slic3r.git
synced 2025-08-04 13:30:36 +08:00
Significant code cleanup; remember to turn off VBOs after done with use to not interfere with other code.
This commit is contained in:
parent
4cd8ea9e5f
commit
2df6b00f1d
@ -1,9 +1,9 @@
|
|||||||
package Slic3r::GUI::3DScene::Base;
|
package Slic3r::GUI::3DScene::Base;
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
|
|
||||||
use Wx::Event qw(EVT_PAINT EVT_SIZE EVT_ERASE_BACKGROUND EVT_IDLE EVT_MOUSEWHEEL EVT_MOUSE_EVENTS);
|
use Wx::Event qw(EVT_PAINT EVT_SIZE EVT_ERASE_BACKGROUND EVT_IDLE EVT_MOUSEWHEEL EVT_MOUSE_EVENTS);
|
||||||
# must load OpenGL *before* Wx::GLCanvas
|
# must load OpenGL *before* Wx::GLCanvas
|
||||||
|
|
||||||
use OpenGL qw(:glconstants :glfunctions :glufunctions :gluconstants);
|
use OpenGL qw(:glconstants :glfunctions :glufunctions :gluconstants);
|
||||||
use base qw(Wx::GLCanvas Class::Accessor);
|
use base qw(Wx::GLCanvas Class::Accessor);
|
||||||
use Math::Trig qw(asin);
|
use Math::Trig qw(asin);
|
||||||
@ -46,6 +46,8 @@ use constant GROUND_Z => -0.02;
|
|||||||
use constant DEFAULT_COLOR => [1,1,0];
|
use constant DEFAULT_COLOR => [1,1,0];
|
||||||
use constant SELECTED_COLOR => [0,1,0,1];
|
use constant SELECTED_COLOR => [0,1,0,1];
|
||||||
use constant HOVER_COLOR => [0.4,0.9,0,1];
|
use constant HOVER_COLOR => [0.4,0.9,0,1];
|
||||||
|
use constant HAS_VBO => 1;
|
||||||
|
|
||||||
|
|
||||||
# make OpenGL::Array thread-safe
|
# make OpenGL::Array thread-safe
|
||||||
{
|
{
|
||||||
@ -56,6 +58,7 @@ use constant HOVER_COLOR => [0.4,0.9,0,1];
|
|||||||
sub new {
|
sub new {
|
||||||
my ($class, $parent) = @_;
|
my ($class, $parent) = @_;
|
||||||
|
|
||||||
|
|
||||||
# We can only enable multi sample anti aliasing wih wxWidgets 3.0.3 and with a hacked Wx::GLCanvas,
|
# We can only enable multi sample anti aliasing wih wxWidgets 3.0.3 and with a hacked Wx::GLCanvas,
|
||||||
# which exports some new WX_GL_XXX constants, namely WX_GL_SAMPLE_BUFFERS and WX_GL_SAMPLES.
|
# which exports some new WX_GL_XXX constants, namely WX_GL_SAMPLE_BUFFERS and WX_GL_SAMPLES.
|
||||||
my $can_multisample =
|
my $can_multisample =
|
||||||
@ -74,6 +77,7 @@ sub new {
|
|||||||
# we request a depth buffer explicitely because it looks like it's not created by
|
# we request a depth buffer explicitely because it looks like it's not created by
|
||||||
# default on Linux, causing transparency issues
|
# default on Linux, causing transparency issues
|
||||||
my $self = $class->SUPER::new($parent, -1, Wx::wxDefaultPosition, Wx::wxDefaultSize, 0, "", $attrib);
|
my $self = $class->SUPER::new($parent, -1, Wx::wxDefaultPosition, Wx::wxDefaultSize, 0, "", $attrib);
|
||||||
|
|
||||||
if (Wx::wxVERSION >= 3.000003) {
|
if (Wx::wxVERSION >= 3.000003) {
|
||||||
# Wx 3.0.3 contains an ugly hack to support some advanced OpenGL attributes through the attribute list.
|
# Wx 3.0.3 contains an ugly hack to support some advanced OpenGL attributes through the attribute list.
|
||||||
# The attribute list is transferred between the wxGLCanvas and wxGLContext constructors using a single static array s_wglContextAttribs.
|
# The attribute list is transferred between the wxGLCanvas and wxGLContext constructors using a single static array s_wglContextAttribs.
|
||||||
@ -134,6 +138,7 @@ sub new {
|
|||||||
});
|
});
|
||||||
EVT_MOUSE_EVENTS($self, \&mouse_event);
|
EVT_MOUSE_EVENTS($self, \&mouse_event);
|
||||||
|
|
||||||
|
|
||||||
return $self;
|
return $self;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -750,17 +755,7 @@ sub Render {
|
|||||||
# draw ground
|
# draw ground
|
||||||
my $ground_z = GROUND_Z;
|
my $ground_z = GROUND_Z;
|
||||||
if ($self->bed_triangles) {
|
if ($self->bed_triangles) {
|
||||||
my($VertexObjID,$NormalObjID,$ColorObjID);
|
my $norms = OpenGL::Array->new_list(GL_FLOAT,(0.0, 0.0, 1.0)); # common normal for both
|
||||||
my $colors = OpenGL::Array->new_list(GL_FLOAT,(0.8,0.6,0.5,0.4));
|
|
||||||
my $norms = OpenGL::Array->new_list(GL_FLOAT,(0,0,1));
|
|
||||||
($VertexObjID,$NormalObjID,$ColorObjID) =
|
|
||||||
glGenBuffersARB_p(3);
|
|
||||||
$self->bed_triangles->bind($VertexObjID);
|
|
||||||
glBufferDataARB_p(GL_ARRAY_BUFFER_ARB, $self->bed_triangles, GL_STATIC_DRAW_ARB);
|
|
||||||
glVertexPointer_c(3, GL_FLOAT, 0, 0);
|
|
||||||
$norms->bind($NormalObjID);
|
|
||||||
glBufferDataARB_p(GL_ARRAY_BUFFER_ARB, $norms, GL_STATIC_DRAW_ARB);
|
|
||||||
glNormalPointer_c(GL_FLOAT, 0, 0);
|
|
||||||
|
|
||||||
glDisable(GL_DEPTH_TEST);
|
glDisable(GL_DEPTH_TEST);
|
||||||
|
|
||||||
@ -768,8 +763,19 @@ sub Render {
|
|||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
|
||||||
glEnableClientState(GL_VERTEX_ARRAY);
|
glEnableClientState(GL_VERTEX_ARRAY);
|
||||||
#glNormal3d(0,0,1);
|
if (HAS_VBO) {
|
||||||
#glVertexPointer_p(3, $self->bed_triangles);
|
my ($triangle_vertex);
|
||||||
|
($triangle_vertex) =
|
||||||
|
glGenBuffersARB_p(1);
|
||||||
|
$self->bed_triangles->bind($triangle_vertex);
|
||||||
|
glBufferDataARB_p(GL_ARRAY_BUFFER_ARB, $self->bed_triangles, GL_STATIC_DRAW_ARB);
|
||||||
|
glVertexPointer_c(3, GL_FLOAT, 0, 0);
|
||||||
|
} else {
|
||||||
|
# fall back on old behavior
|
||||||
|
glVertexPointer_p(3, $self->bed_triangles);
|
||||||
|
}
|
||||||
|
glColor4f(0.8, 0.6, 0.5, 0.4);
|
||||||
|
glNormal3d(0,0,1);
|
||||||
glDrawArrays(GL_TRIANGLES, 0, $self->bed_triangles->elements / 3);
|
glDrawArrays(GL_TRIANGLES, 0, $self->bed_triangles->elements / 3);
|
||||||
glDisableClientState(GL_VERTEX_ARRAY);
|
glDisableClientState(GL_VERTEX_ARRAY);
|
||||||
|
|
||||||
@ -777,21 +783,31 @@ sub Render {
|
|||||||
# the object from below
|
# the object from below
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
|
||||||
my($GridVertexObjID,$GridNormalObjID,$GridColorObjID);
|
|
||||||
($GridVertexObjID,$GridNormalObjID,$GridColorObjID) =
|
|
||||||
glGenBuffersARB_p(3);
|
|
||||||
glBufferDataARB_p(GL_ARRAY_BUFFER_ARB, $self->bed_grid_lines, GL_STATIC_DRAW_ARB);
|
|
||||||
glVertexPointer_c(3, GL_FLOAT, 0, 0);
|
|
||||||
# draw grid
|
# draw grid
|
||||||
glLineWidth(3);
|
glLineWidth(3);
|
||||||
glColor4f(0.2, 0.2, 0.2, 0.4);
|
|
||||||
glEnableClientState(GL_VERTEX_ARRAY);
|
glEnableClientState(GL_VERTEX_ARRAY);
|
||||||
|
if (HAS_VBO) {
|
||||||
#glVertexPointer_p(3, $self->bed_grid_lines);
|
my ($grid_vertex);
|
||||||
|
($grid_vertex) =
|
||||||
|
glGenBuffersARB_p(1);
|
||||||
|
$self->bed_grid_lines->bind($grid_vertex);
|
||||||
|
glBufferDataARB_p(GL_ARRAY_BUFFER_ARB, $self->bed_grid_lines, GL_STATIC_DRAW_ARB);
|
||||||
|
glVertexPointer_c(3, GL_FLOAT, 0, 0);
|
||||||
|
} else {
|
||||||
|
# fall back on old behavior
|
||||||
|
glVertexPointer_p(3, $self->bed_grid_lines);
|
||||||
|
}
|
||||||
|
glColor4f(0.2, 0.2, 0.2, 0.4);
|
||||||
|
glNormal3d(0,0,1);
|
||||||
glDrawArrays(GL_LINES, 0, $self->bed_grid_lines->elements / 3);
|
glDrawArrays(GL_LINES, 0, $self->bed_grid_lines->elements / 3);
|
||||||
glDisableClientState(GL_VERTEX_ARRAY);
|
glDisableClientState(GL_VERTEX_ARRAY);
|
||||||
|
|
||||||
glDisable(GL_BLEND);
|
glDisable(GL_BLEND);
|
||||||
|
if (HAS_VBO) {
|
||||||
|
# Turn off buffer objects to let the rest of the draw code work.
|
||||||
|
glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
|
||||||
|
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
my $volumes_bb = $self->volumes_bounding_box;
|
my $volumes_bb = $self->volumes_bounding_box;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user