mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-24 23:23:59 -06:00
Error reporting on initialization of the Layer Editing OpenGL shaders.
The shaders are initialized when the layer editing button is pressed for the first time. If the initialization fails, a message box is shown and the layer editing will stay disabled.
This commit is contained in:
parent
70229be9bc
commit
898deb48c4
3 changed files with 174 additions and 117 deletions
|
@ -19,7 +19,7 @@ package Slic3r::GUI::3DScene::Base;
|
|||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Wx qw(:timer :bitmap);
|
||||
use Wx qw(:timer :bitmap :icon :dialog);
|
||||
use Wx::Event qw(EVT_PAINT EVT_SIZE EVT_ERASE_BACKGROUND EVT_IDLE EVT_MOUSEWHEEL EVT_MOUSE_EVENTS EVT_TIMER);
|
||||
# must load OpenGL *before* Wx::GLCanvas
|
||||
use OpenGL qw(:glconstants :glfunctions :glufunctions :gluconstants);
|
||||
|
@ -193,24 +193,58 @@ 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);
|
||||
if ($value) {
|
||||
if (! $self->{layer_editing_initialized}) {
|
||||
# Enabling the layer editing for the first time. This triggers compilation of the necessary OpenGL shaders.
|
||||
# If compilation fails, a message box is shown with the error codes.
|
||||
my $shader = $self->{shader} = new Slic3r::GUI::GLShader;
|
||||
my $error_message;
|
||||
if (ref($shader)) {
|
||||
my $info = $shader->Load($self->_fragment_shader, $self->_vertex_shader);
|
||||
if (defined($info)) {
|
||||
# Compilation or linking of the shaders failed.
|
||||
$error_message = "Cannot compile an OpenGL Shader, therefore the Variable Layer Editing will be disabled.\n\n"
|
||||
. $info;
|
||||
} else {
|
||||
($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);
|
||||
}
|
||||
} else {
|
||||
# Cannot initialize the Shader object, some of the OpenGL capabilities are missing.
|
||||
$error_message = "Cannot instantiate an OpenGL Shader, therefore the Variable Layer Editing will be disabled.\n\n"
|
||||
. $shader;
|
||||
}
|
||||
if (defined($error_message)) {
|
||||
# Don't enable the layer editing tool.
|
||||
$self->{layer_editing_enabled} = 0;
|
||||
# 2 means failed
|
||||
$self->{layer_editing_initialized} = 2;
|
||||
# Show the error message.
|
||||
Wx::MessageBox($error_message, "Slic3r Error", wxOK | wxICON_EXCLAMATION, $self);
|
||||
} else {
|
||||
$self->{layer_editing_initialized} = 1;
|
||||
}
|
||||
} elsif ($self->{layer_editing_initialized} == 2) {
|
||||
# Initilization failed before. Don't try to initialize and disable layer editing.
|
||||
$self->{layer_editing_enabled} = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $self->{layer_editing_enabled};
|
||||
}
|
||||
|
||||
sub layer_editing_allowed {
|
||||
my ($self) = @_;
|
||||
# Allow layer editing if either the shaders were not initialized yet and we don't know
|
||||
# whether it will be possible to initialize them,
|
||||
# or if the initialization was done already and it failed.
|
||||
return ! (defined($self->{layer_editing_initialized}) && $self->{layer_editing_initialized} == 2);
|
||||
}
|
||||
|
||||
sub _first_selected_object_id {
|
||||
my ($self) = @_;
|
||||
for my $i (0..$#{$self->volumes}) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue