From 2a5095a1ea6053270e6e382d52d53c07f87f5fcc Mon Sep 17 00:00:00 2001 From: bubnikv Date: Wed, 14 Sep 2016 16:31:26 +0200 Subject: [PATCH] OpenGL support through GLEW. Only active if compiled with SLIC3R_GUI=1. --- lib/Slic3r/GUI/3DScene.pm | 11 +++++++++++ xs/Build.PL | 23 ++++++++++++++++++----- xs/MANIFEST | 4 ++++ xs/src/glew/include/GL/wglew.h | 3 +++ xs/src/glew/src/glew.c | 4 ++++ xs/src/libslic3r/EdgeGrid.cpp | 19 +++++++++++++------ xs/src/libslic3r/EdgeGrid.hpp | 2 ++ xs/src/libslic3r/Print.cpp | 4 +++- 8 files changed, 58 insertions(+), 12 deletions(-) diff --git a/lib/Slic3r/GUI/3DScene.pm b/lib/Slic3r/GUI/3DScene.pm index 893f62d40..e33b7254d 100644 --- a/lib/Slic3r/GUI/3DScene.pm +++ b/lib/Slic3r/GUI/3DScene.pm @@ -1083,6 +1083,10 @@ sub load_object { $color_idx = $obj_idx; } + # Using the colors 'yellowish', 'greenish', 'blueish' for both the extrusion paths + # and the volumes of a single multi-color object. + #FIXME so for 4 or more color print, there will be only 3 colors displayed, which will + # not correspond to the color of the filament. my $color = [ @{COLORS->[ $color_idx % scalar(@{&COLORS}) ]} ]; $color->[3] = $volume->modifier ? 0.5 : 1; push @{$self->volumes}, my $v = Slic3r::GUI::3DScene::Volume->new( @@ -1114,6 +1118,7 @@ sub load_object { return @volumes_idx; } +# Called possibly by utils/view-toolpaths.pl, likely broken. sub load_print_object_slices { my ($self, $object) = @_; @@ -1168,6 +1173,8 @@ sub load_print_object_slices { ); } +# Create 3D thick extrusion lines for a skirt and brim. +# Adds a new Slic3r::GUI::3DScene::Volume to $self->volumes. sub load_print_toolpaths { my ($self, $print) = @_; @@ -1221,6 +1228,9 @@ sub load_print_toolpaths { ); } +# Create 3D thick extrusion lines for object forming extrusions. +# Adds a new Slic3r::GUI::3DScene::Volume to $self->volumes, +# one for perimeters, one for infill and one for supports. sub load_print_object_toolpaths { my ($self, $object) = @_; @@ -1319,6 +1329,7 @@ sub set_toolpaths_range { } } +# called by load_print_object_slices, probably not used. sub _expolygons_to_verts { my ($self, $expolygons, $z, $verts, $norms) = @_; diff --git a/xs/Build.PL b/xs/Build.PL index 7c9465020..9ec345206 100644 --- a/xs/Build.PL +++ b/xs/Build.PL @@ -14,7 +14,7 @@ my $mswin = $^O eq 'MSWin32'; # HAS_BOOL : stops Perl/lib/CORE/handy.h from doing "# define bool char" for MSVC # NOGDI : prevents inclusion of wingdi.h which defines functions Polygon() and Polyline() in global namespace # BOOST_ASIO_DISABLE_KQUEUE : prevents a Boost ASIO bug on OS X: https://svn.boost.org/trac/boost/ticket/5339 -my @cflags = qw(-D_GLIBCXX_USE_C99 -DHAS_BOOL -DNOGDI -DSLIC3RXS -DBOOST_ASIO_DISABLE_KQUEUE); +my @cflags = qw(-D_GLIBCXX_USE_C99 -DHAS_BOOL -DNOGDI -DSLIC3RXS -DBOOST_ASIO_DISABLE_KQUEUE -DGLEW_STATIC); my @ldflags = (); if ($^O eq 'darwin') { push @ldflags, qw(-framework IOKit -framework CoreFoundation); @@ -22,14 +22,14 @@ if ($^O eq 'darwin') { if ($mswin) { # In case windows.h is included, we don't want the min / max macros to be active. # If is included, we want the #defines to be active (M_PI etc.) - push @cflags, qw(-DNOMINMAX -D_USE_MATH_DEFINES); + push @cflags, qw(-D_WIN32 -DNOMINMAX -D_USE_MATH_DEFINES); } my @early_includes = (); -my @INC = qw(-Isrc/libslic3r); +my @INC = qw(-Isrc/libslic3r -Isrc/glew/include); my @LIBS = $cpp_guess->is_msvc ? qw(-LIBPATH:src/libslic3r) : qw(-Lsrc/libslic3r); - -#if ($ENV{SLIC3R_GUI}) + +if ($ENV{SLIC3R_GUI}) { print "Slic3r will be built with GUI support\n"; require Alien::wxWidgets; @@ -163,6 +163,19 @@ is handy, if you have built Boost libraries with mutliple settings. EOF +# Add the OpenGL and GLU libraries. +if ($ENV{SLIC3R_GUI}) { + if ($mswin) { + if ($cpp_guess->is_msvc) { + push @LIBS, qw(OpenGL32.Lib GlU32.Lib); + } else { + push @LIBS, qw(-lopengl32); + } + } else { + push @LIBS, qw(-lgl -lglu); + } +} + if ($ENV{SLIC3R_DEBUG}) { # only on newer GCCs: -ftemplate-backtrace-limit=0 push @cflags, '-DSLIC3R_DEBUG'; diff --git a/xs/MANIFEST b/xs/MANIFEST index 9aaaa377d..4594a074a 100644 --- a/xs/MANIFEST +++ b/xs/MANIFEST @@ -18,6 +18,8 @@ src/libslic3r/ClipperUtils.cpp src/libslic3r/ClipperUtils.hpp src/libslic3r/Config.cpp src/libslic3r/Config.hpp +src/libslic3r/EdgeGrid.cpp +src/libslic3r/EdgeGrid.hpp src/libslic3r/ExPolygon.cpp src/libslic3r/ExPolygon.hpp src/libslic3r/ExPolygonCollection.cpp @@ -136,6 +138,8 @@ src/Shiny/ShinyNodeState.c src/Shiny/ShinyOutput.c src/Shiny/ShinyTools.c src/Shiny/ShinyZone.c +src/glew/LICENSE.txt +src/glew/README.md src/glew/src/glew.c src/glew/include/GL/glew.h src/glew/include/GL/glxew.h diff --git a/xs/src/glew/include/GL/wglew.h b/xs/src/glew/include/GL/wglew.h index 23e4d3fba..c13c54a5f 100644 --- a/xs/src/glew/include/GL/wglew.h +++ b/xs/src/glew/include/GL/wglew.h @@ -67,6 +67,9 @@ # ifndef WIN32_LEAN_AND_MEAN # define WIN32_LEAN_AND_MEAN 1 # endif +# ifdef NOGDI +# undef NOGDI +# endif #include # undef WIN32_LEAN_AND_MEAN #endif diff --git a/xs/src/glew/src/glew.c b/xs/src/glew/src/glew.c index fe2a190ef..1c81adc46 100644 --- a/xs/src/glew/src/glew.c +++ b/xs/src/glew/src/glew.c @@ -30,6 +30,8 @@ ** THE POSSIBILITY OF SUCH DAMAGE. */ +#ifdef SLIC3R_GUI + #include #if defined(_WIN32) @@ -18605,3 +18607,5 @@ GLboolean glxewIsSupported (const char* name) } #endif /* _WIN32 */ + +#endif /* SLIC3R_GUI */ diff --git a/xs/src/libslic3r/EdgeGrid.cpp b/xs/src/libslic3r/EdgeGrid.cpp index bc60ff4ad..54cda9f8c 100644 --- a/xs/src/libslic3r/EdgeGrid.cpp +++ b/xs/src/libslic3r/EdgeGrid.cpp @@ -2,7 +2,9 @@ #include #include +#ifdef SLIC3R_GUI #include +#endif /* SLIC3R_GUI */ #include "libslic3r.h" #include "EdgeGrid.hpp" @@ -551,7 +553,8 @@ void EdgeGrid::Grid::calculate_sdf() } } -#if 1 +#if 0 +//#ifdef SLIC3R_GUI { wxImage img(ncols, nrows); unsigned char *data = img.GetData(); @@ -609,7 +612,7 @@ void EdgeGrid::Grid::calculate_sdf() } img.SaveFile("out\\signed_df.png", wxBITMAP_TYPE_PNG); } -#endif +#endif /* SLIC3R_GUI */ // 2) Propagate the signum. #define PROPAGATE_SIGNUM_SINGLE_STEP(DELTA) do { \ @@ -681,7 +684,8 @@ void EdgeGrid::Grid::calculate_sdf() } } -#if 1 +#if 0 +//#ifdef SLIC3R_GUI { wxImage img(ncols, nrows); unsigned char *data = img.GetData(); @@ -733,9 +737,10 @@ void EdgeGrid::Grid::calculate_sdf() } img.SaveFile("out\\signed_df-signs.png", wxBITMAP_TYPE_PNG); } -#endif +#endif /* SLIC3R_GUI */ -#if 1 +#if 0 +//#ifdef SLIC3R_GUI { wxImage img(ncols, nrows); unsigned char *data = img.GetData(); @@ -761,7 +766,7 @@ void EdgeGrid::Grid::calculate_sdf() } img.SaveFile("out\\signed_df2.png", wxBITMAP_TYPE_PNG); } -#endif +#endif /* SLIC3R_GUI */ } float EdgeGrid::Grid::signed_distance_bilinear(const Point &pt) const @@ -932,6 +937,7 @@ bool EdgeGrid::Grid::signed_distance(const Point &pt, coord_t search_radius, coo return true; } +#ifdef SLIC3R_GUI void EdgeGrid::save_png(const EdgeGrid::Grid &grid, const BoundingBox &bbox, coord_t resolution, const char *path) { unsigned int w = (bbox.max.x - bbox.min.x + resolution - 1) / resolution; @@ -1022,5 +1028,6 @@ void EdgeGrid::save_png(const EdgeGrid::Grid &grid, const BoundingBox &bbox, coo img.SaveFile(path, wxBITMAP_TYPE_PNG); } +#endif /* SLIC3R_GUI */ } // namespace Slic3r diff --git a/xs/src/libslic3r/EdgeGrid.hpp b/xs/src/libslic3r/EdgeGrid.hpp index 860b1f647..959165866 100644 --- a/xs/src/libslic3r/EdgeGrid.hpp +++ b/xs/src/libslic3r/EdgeGrid.hpp @@ -72,8 +72,10 @@ protected: std::vector m_signed_distance_field; }; +#ifdef SLIC3R_GUI // Debugging utility. Save the signed distance field. extern void save_png(const Grid &grid, const BoundingBox &bbox, coord_t resolution, const char *path); +#endif /* SLIC3R_GUI */ } // namespace EdgeGrid } // namespace Slic3r diff --git a/xs/src/libslic3r/Print.cpp b/xs/src/libslic3r/Print.cpp index 185c59aad..329843f5c 100644 --- a/xs/src/libslic3r/Print.cpp +++ b/xs/src/libslic3r/Print.cpp @@ -235,7 +235,9 @@ Print::invalidate_state_by_config_options(const std::vector || *opt_key == "use_relative_e_distances" || *opt_key == "vibration_limit" || *opt_key == "wipe" - || *opt_key == "z_offset") { + || *opt_key == "z_offset" + || *opt_key == "max_volumetric_extrusion_rate_slope_negative" + || *opt_key == "max_volumetric_extrusion_rate_slope_positive") { // these options only affect G-code export, so nothing to invalidate } else if (*opt_key == "first_layer_extrusion_width") { osteps.insert(posPerimeters);