diff --git a/lib/Slic3r/GUI/3DScene.pm b/lib/Slic3r/GUI/3DScene.pm index 740fbcc1092..e7a3791b88c 100644 --- a/lib/Slic3r/GUI/3DScene.pm +++ b/lib/Slic3r/GUI/3DScene.pm @@ -61,7 +61,6 @@ __PACKAGE__->mk_accessors( qw(_quat _dirty init _drag_start_xy _dragged - layer_editing_enabled _layer_height_edited _camera_type @@ -190,6 +189,28 @@ sub Destroy { return $self->SUPER::Destroy; } +sub layer_editing_enabled { + my ($self, $value) = @_; + if (@_ == 2) { + $self->{layer_editing_enabled} = $value; + if ($value && ! $self->{layer_editing_initialized}) { + # Enabling the layer editing for the first time. This triggers compilation of the necessary OpenGL shaders. + # If compilation fails, the compile log is printed into the console. + $self->{layer_editing_initialized} = 1; + my $shader = $self->{shader} = new Slic3r::GUI::GLShader; + my $info = $shader->Load($self->_fragment_shader, $self->_vertex_shader); + print $info if $info; + ($self->{layer_preview_z_texture_id}) = glGenTextures_p(1); + glBindTexture(GL_TEXTURE_2D, $self->{layer_preview_z_texture_id}); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1); + glBindTexture(GL_TEXTURE_2D, 0); + } + } + return $self->{layer_editing_enabled}; +} + sub _first_selected_object_id { my ($self) = @_; for my $i (0..$#{$self->volumes}) { @@ -893,16 +914,6 @@ sub InitGL { return unless $self->GetContext; $self->init(1); - my $shader = $self->{shader} = new Slic3r::GUI::GLShader; - my $info = $shader->Load($self->_fragment_shader, $self->_vertex_shader); -# print $info if $info; - ($self->{layer_preview_z_texture_id}) = glGenTextures_p(1); - glBindTexture(GL_TEXTURE_2D, $self->{layer_preview_z_texture_id}); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1); - glBindTexture(GL_TEXTURE_2D, 0); - glClearColor(0, 0, 0, 1); glColor3f(1, 0, 0); glEnable(GL_DEPTH_TEST);