From 36416d77b8f0db6692ffbafd56abf753e51d074f Mon Sep 17 00:00:00 2001 From: bubnikv Date: Thu, 30 Mar 2017 10:25:52 +0200 Subject: Fixes of VBO rendering on Linux with wxWidgets & GTK --- lib/Slic3r/GUI/3DScene.pm | 12 +++++++++++- xs/src/slic3r/GUI/3DScene.hpp | 6 ++++++ xs/xsp/GUI_3DScene.xsp | 1 + 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/Slic3r/GUI/3DScene.pm b/lib/Slic3r/GUI/3DScene.pm index b95e8777f..d4eb1eaea 100644 --- a/lib/Slic3r/GUI/3DScene.pm +++ b/lib/Slic3r/GUI/3DScene.pm @@ -906,13 +906,16 @@ sub UseVBOs { my ($self) = @_; if (! defined ($self->{use_VBOs})) { + # This is a special path for wxWidgets on GTK, where an OpenGL context is initialized + # first when an OpenGL widget is shown for the first time. How ugly. + return 0 if (! $self->init && $^O eq 'linux'); # Don't use VBOs if anything fails. $self->{use_VBOs} = 0; if ($self->GetContext) { $self->SetCurrent($self->GetContext); my @gl_version = split(/\./, glGetString(GL_VERSION)); $self->{use_VBOs} = int($gl_version[0]) >= 2; - # print "InitGL $self OpenGL major: $gl_version[0], minor: $gl_version[1]. Use VBOs: ", $self->{use_VBOs}, "\n"; + # print "UseVBOs $self OpenGL major: $gl_version[0], minor: $gl_version[1]. Use VBOs: ", $self->{use_VBOs}, "\n"; } } return $self->{use_VBOs}; @@ -968,6 +971,13 @@ sub InitGL { return unless $self->GetContext; $self->init(1); + # This is a special path for wxWidgets on GTK, where an OpenGL context is initialized + # first when an OpenGL widget is shown for the first time. How ugly. + # In that case the volumes are wainting to be moved to Vertex Buffer Objects + # after the OpenGL context is being initialized. + $self->volumes->finalize_geometry(1) + if ($^O eq 'linux' && $self->UseVBOs); + glClearColor(0, 0, 0, 1); glColor3f(1, 0, 0); glEnable(GL_DEPTH_TEST); diff --git a/xs/src/slic3r/GUI/3DScene.hpp b/xs/src/slic3r/GUI/3DScene.hpp index 1e5b968ba..ed992754d 100644 --- a/xs/src/slic3r/GUI/3DScene.hpp +++ b/xs/src/slic3r/GUI/3DScene.hpp @@ -264,6 +264,7 @@ public: void set_range(coordf_t low, coordf_t high); void render() const; + void finalize_geometry(bool use_VBOs) { this->indexed_vertex_array.finalize_geometry(use_VBOs); } void release_geometry() { this->indexed_vertex_array.release_geometry(); } /************************************************ Layer height texture ****************************************************/ @@ -312,6 +313,11 @@ public: // Render the volumes by OpenGL. void render_VBOs() const; void render_legacy() const; + + // Finalize the initialization of the geometry & indices, + // upload the geometry and indices to OpenGL VBO objects + // and shrink the allocated data, possibly relasing it if it has been loaded into the VBOs. + void finalize_geometry(bool use_VBOs) { for (auto *v : volumes) v->finalize_geometry(use_VBOs); } // Release the geometry data assigned to the volumes. // If OpenGL VBOs were allocated, an OpenGL context has to be active to release them. void release_geometry() { for (auto *v : volumes) v->release_geometry(); } diff --git a/xs/xsp/GUI_3DScene.xsp b/xs/xsp/GUI_3DScene.xsp index 06ae7ce13..06b042f3b 100644 --- a/xs/xsp/GUI_3DScene.xsp +++ b/xs/xsp/GUI_3DScene.xsp @@ -87,6 +87,7 @@ void render_VBOs() const; void render_legacy() const; + void finalize_geometry(bool use_VBOs); void release_geometry(); %{ -- cgit v1.2.3