forked from viewit/OrcaSlicer-KX
Includes (but is not limited to) the following commits: SPE-2218 - libvgcode - Fixed color of wipe moves for speed range view SPE-2218 - libvgcode - Fixed detection of fan speed range SPE-2218 - libvgcode - Fixed detection of temperature range SPE-2218 - libvgcode - Fixed colors for Actual volumetric flow rate view SPE-2214 - Fixed detection of toolpaths bounding box in GCodeViewer SPE-2206 - Modified LibBGCode.cmake to get latest version of libbgcode which fixed parsing of gcode lines G4 libvgcode - Fixed potential out of bound access in ViewerImpl::update_view_full_range() Tech ENABLE_GL_CORE_PROFILE set as default Tech ENABLE_OPENGL_ES replaced by build option SLIC3R_OPENGL_ES libvgcode - Precompiler definition of ENABLE_OPENGL_ES moved into CMakeLists.txt Added missing include libvgcode - Textures setup modified to work when building using emscripten libvgcode - small optimization libvgcode - fixed OpenGLWrapper::unload_opengl() libvgcode - CMakeLists.txt modified to work with emscripten libvgcode - Replace 'glVertexAttribIPointer()' with 'glVertexAttribPointer()' in SegmentTemplate::init() for OpenGL ES libvgcode - Replace 'xor' with '^' Bitset.hpp libvgcode - Newer glad library for OpenGL 4.6 and OpenGL ES 3.0 libvgcode - Alternate fix in method ViewerImpl::update_heights_widths() for OpenGL ES libvgcode - Fixes in glAssertRecentCallImpl() libvgcode - Fixes in method ViewerImpl::update_heights_widths() for OpenGL ES Fixed ES shaders so they work with OpenGL ES 3.0 libvgcode - Use multiple plain textures in place of texture buffers for OpenGL ES libvgcode - Use plain textures in place of texture buffers for OpenGL ES (partial implementation using one texture per buffer) libvgcode - refactoring of class OpenGLWrapper libvgcode - small refactoring in shaders libvgcode - replacement of glMapBuffer() call for OpenGL ES Fixed warning libvgcode - Changes into CMakeLists.txt Fixed debug export of gcode data to be configuration indipendent Disabled tech ENABLE_NEW_GCODE_VIEWER_DEBUG Removed obsolete tech ENABLE_GCODE_VIEWER_DATA_CHECKING Code cleanup and techs removal - completed Code cleanup and techs removal - step 1 SPE-1872: Implemented G2/G3 lines discretization for gcfMarlinFirmware firmware flavour SPE-1872: Corrections into GCodeProcessor::process_G2_G3() to match firmware code SPE-1872: Actual speed profile - Further enhancements of imgui debug window SPE-1872: Actual speed profile - Rework in its calculation + enhanced imgui debug window SPE-1872: New imgui widget to show actual speed profile SPE-1872: Fixed actual speed for seam moves and at extrusion/travel/wipe start SPE-1872: Fixed rendering of wipe moves when actual speed view is selected SPE-1872: Actual speed profile extended to travel and wipe moves SPE-1872: Fixes in function recalculate_trapezoids() and method GCodeProcessor::TimeMachine::calculate_time() to smooth actual speed profile SPE-1872: Added debug graphic to show move actual speed profile SPE-1872: libvgcode library: replace volumetric flow rate data with mm3_per_mm to reduce memory usage SPE-1872: Added visualization of actual volumetric flow rate SPE-1872: Fixes in calculating actual speed SPE-1872: Added visualization of actual speed in gcode preview SPE-2124: Added command line option 'opengl-aa' to allow the user to turn on the automatic selection of max number of supported samples for OpenGL antialising #12117: Reduced moire patterns by using the highest number of samples available for multisampling New gcode visualization integration - Partially enabled imgui debug window New gcode visualization integration - Fixed center of gravity calculation and rendering New gcode visualization library - Interface for estimated times New gcode visualization library - Tool marker rendering New gcode visualization library - Axes aligned bounding boxes calculation Removed obsolete debug code New gcode visualization library - Added statistic of used memory New gcode visualization library - Separation of tool colors and color changes colors to simplify client code Added missing include New gcode visualization library - Added print color changes detection New gcode visualization library - Modified OpenGL ES context detection New gcode visualization library - Another makefile cleanup New gcode visualization library - Makefiles cleanup New gcode visualization library - Added suppression of error 'This function or variable may be unsafe' in VS2022 New gcode visualization library - Compatibility with OpenGL ES New gcode visualization library - Interface cleanup and documentation New gcode visualization library - Extended interface to give access to estimated times New gcode visualization integration - Toggling of top layer only view state New gcode visualization integration - Removed imperial units from tool position data Small refactoring New gcode visualization library - Custom values for travel and wipe moves radius New gcode visualization library - Allow customization of range colors New gcode visualization library - Partial update of interface comments/documentation New gcode visualization integration - Follow-up of 35ee55e29bb231fd01a2eb71ae293832a37ca65d - Better fix for toolpaths visible range when toggling options' visibility New gcode visualization integration - Fixed toolpaths reset New gcode visualization library - Fixed method set_option_color() New gcode visualization library - Fixed method ViewerImpl::set_extrusion_role_color() New gcode visualization library - Added methods to release gpu resources on demand. New gcode visualization library - Travel and wipe moves as options New gcode visualization integration - Fixed toolpaths visible range when toggling options' visibility New gcode visualization integration - Fixed management of gcode preview view type New gcode visualization - Fixed wrong include New gcode visualization - Added missing headers New gcode visualization - Refactoring + added missing headers New gcode visualization - New code set as standalone library + embed glad library to load OpenGL functions New gcode visualization - Fixed errors and warnings when building the new code as a standalone library New gcode visualization integration - Fixed layers ordering in pre-gcode preview New gcode visualization integration - Fixed objects' tool colors in pre-gcode preview Code cleanup New gcode visualization integration - Tool position properties data window New gcode visualization integration - Fixed in export toolpaths to obj New gcode visualization - Inlining in source code Refactoring New gcode visualization integration - Export toolpaths to obj Some refactoring and warning fix New gcode visualization integration - Customizable travel moves colors New gcode visualization integration - Customizable options colors New gcode visualization integration - Customizable extrusion roles colors New gcode visualization integration - Fixed pre-gcode preview layers times New gcode visualization integration - Modify pre-gcode preview to use the new toolpaths renderer, objects WIP New gcode visualization - Modify pre-gcode preview to use the new toolpaths renderer, WIP (brim/skirt/wipe tower) New gcode visualization integration - Do not reset visible range when toggling options/roles visibility New gcode visualization - Fixed color of first vertex of top layer (when top layer only option is enabled) New gcode visualization - Customizable travels and wipes segment radius New gcode visualization integration - Removed tech ENABLE_GCODE_VIEWER_STATISTICS New gcode visualization integration - Added check of OpenGL version New gcode visualization integration - Removed GCodeProcessorResult::spiral_vase_layers Another bunch of warnings fixes Fixed warnings New gcode visualization integration - Removal of old visualization Fixed includes New gcode visualization integration - File structure of new code separated in api + src New gcode visualization integration - View ranges management moved to new visualizer New gcode visualization integration - Fixed top layer only visualization for MMU printers New gcode visualization integration - Removed dependency on imgui from new visualizer Some refactoring New gcode visualization integration - Removed dependency on Slic3r::GCodeProcessorResult from new visualizer New gcode visualization integration - Moves' data conversion moved to client side New gcode visualization: layers times refactoring A bunch of fixes for the new gcode visualization New gcode visualization: render in gray color layers containing pause print or custom gcode options when in Color Print view New gcode visualization integration - Tool colors New gcode visualization integration - Layers times New gcode visualization integration - Travels and Extrusion roles times Fixed detection of start/end of contiguous extrusion paths New gcode visualization integration - Extrusion roles New gcode visualization integration - Colors New gcode visualization integration - Tool position Center of gravity and tool marker may both be rendered with fixed screen size and a scaling factor Fixed rendering of options in new gcode visualization Tool marker NOT rendered by the new visualization code Center of gravity marker NOT rendered by the new visualization code Fixed toolpaths_cog shaders Tool position window for new gcode visualization Top layer only coloring for neww gcode visualization Refactoring in preview's new visualization Hidden imgui debug dialog for new visualization in preview Synchronization of moves between old and new visualization Fixed missing gcode window in new visualization Rendering of debug imgui dialog moved from class libvgcode::Viewer to class libvgcode::Toolpaths + warnings fixing Some functionality moved from class libvgcode::Viewer to class libvgcode::Toolpaths Some refactoring and cleanup Refatoring of PathVertex and Toolpaths::load() SPE-1982: Tech ENABLE_NEW_GCODE_VIEWER - 1st installment of new toolpaths rendering code (WIP)
462 lines
17 KiB
C++
462 lines
17 KiB
C++
#include "libslic3r/libslic3r.h"
|
|
#include "OpenGLManager.hpp"
|
|
|
|
#include "GUI.hpp"
|
|
#include "I18N.hpp"
|
|
#include "3DScene.hpp"
|
|
|
|
#include "libslic3r/Platform.hpp"
|
|
|
|
#include <GL/glew.h>
|
|
|
|
#include <boost/algorithm/string/split.hpp>
|
|
#include <boost/algorithm/string/classification.hpp>
|
|
#include <boost/log/trivial.hpp>
|
|
|
|
#include <wx/glcanvas.h>
|
|
#include <wx/msgdlg.h>
|
|
|
|
#include "GUI_Init.hpp"
|
|
|
|
#ifdef __APPLE__
|
|
// Part of hack to remove crash when closing the application on OSX 10.9.5 when building against newer wxWidgets
|
|
#include <wx/platinfo.h>
|
|
|
|
#include "../Utils/MacDarkMode.hpp"
|
|
#endif // __APPLE__
|
|
|
|
namespace Slic3r {
|
|
namespace GUI {
|
|
|
|
// A safe wrapper around glGetString to report a "N/A" string in case glGetString returns nullptr.
|
|
std::string gl_get_string_safe(GLenum param, const std::string& default_value)
|
|
{
|
|
const char* value = (const char*)::glGetString(param);
|
|
return std::string((value != nullptr) ? value : default_value);
|
|
}
|
|
|
|
const std::string& OpenGLManager::GLInfo::get_version() const
|
|
{
|
|
if (!m_detected)
|
|
detect();
|
|
|
|
return m_version;
|
|
}
|
|
|
|
const std::string& OpenGLManager::GLInfo::get_glsl_version() const
|
|
{
|
|
if (!m_detected)
|
|
detect();
|
|
|
|
return m_glsl_version;
|
|
}
|
|
|
|
const std::string& OpenGLManager::GLInfo::get_vendor() const
|
|
{
|
|
if (!m_detected)
|
|
detect();
|
|
|
|
return m_vendor;
|
|
}
|
|
|
|
const std::string& OpenGLManager::GLInfo::get_renderer() const
|
|
{
|
|
if (!m_detected)
|
|
detect();
|
|
|
|
return m_renderer;
|
|
}
|
|
|
|
bool OpenGLManager::GLInfo::is_mesa() const
|
|
{
|
|
return boost::icontains(m_version, "mesa");
|
|
}
|
|
|
|
int OpenGLManager::GLInfo::get_max_tex_size() const
|
|
{
|
|
if (!m_detected)
|
|
detect();
|
|
|
|
// clamp to avoid the texture generation become too slow and use too much GPU memory
|
|
#ifdef __APPLE__
|
|
// and use smaller texture for non retina systems
|
|
return (Slic3r::GUI::mac_max_scaling_factor() > 1.0) ? std::min(m_max_tex_size, 8192) : std::min(m_max_tex_size / 2, 4096);
|
|
#else
|
|
// and use smaller texture for older OpenGL versions
|
|
return is_version_greater_or_equal_to(3, 0) ? std::min(m_max_tex_size, 8192) : std::min(m_max_tex_size / 2, 4096);
|
|
#endif // __APPLE__
|
|
}
|
|
|
|
float OpenGLManager::GLInfo::get_max_anisotropy() const
|
|
{
|
|
if (!m_detected)
|
|
detect();
|
|
|
|
return m_max_anisotropy;
|
|
}
|
|
|
|
void OpenGLManager::GLInfo::detect() const
|
|
{
|
|
*const_cast<std::string*>(&m_version) = gl_get_string_safe(GL_VERSION, "N/A");
|
|
*const_cast<std::string*>(&m_glsl_version) = gl_get_string_safe(GL_SHADING_LANGUAGE_VERSION, "N/A");
|
|
*const_cast<std::string*>(&m_vendor) = gl_get_string_safe(GL_VENDOR, "N/A");
|
|
*const_cast<std::string*>(&m_renderer) = gl_get_string_safe(GL_RENDERER, "N/A");
|
|
|
|
BOOST_LOG_TRIVIAL(info) << boost::format("got opengl version %1%, glsl version %2%, vendor %3%")%m_version %m_glsl_version %m_vendor<< std::endl;
|
|
|
|
int* max_tex_size = const_cast<int*>(&m_max_tex_size);
|
|
glsafe(::glGetIntegerv(GL_MAX_TEXTURE_SIZE, max_tex_size));
|
|
|
|
*max_tex_size /= 2;
|
|
|
|
if (Slic3r::total_physical_memory() / (1024 * 1024 * 1024) < 6)
|
|
*max_tex_size /= 2;
|
|
|
|
if (GLEW_EXT_texture_filter_anisotropic) {
|
|
float* max_anisotropy = const_cast<float*>(&m_max_anisotropy);
|
|
glsafe(::glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, max_anisotropy));
|
|
}
|
|
|
|
if (!GLEW_ARB_compatibility)
|
|
*const_cast<bool*>(&m_core_profile) = true;
|
|
|
|
*const_cast<bool*>(&m_detected) = true;
|
|
}
|
|
|
|
static bool version_greater_or_equal_to(const std::string& version, unsigned int major, unsigned int minor)
|
|
{
|
|
if (version == "N/A")
|
|
return false;
|
|
|
|
std::vector<std::string> tokens;
|
|
boost::split(tokens, version, boost::is_any_of(" "), boost::token_compress_on);
|
|
|
|
if (tokens.empty())
|
|
return false;
|
|
|
|
std::vector<std::string> numbers;
|
|
boost::split(numbers, tokens[0], boost::is_any_of("."), boost::token_compress_on);
|
|
|
|
unsigned int gl_major = 0;
|
|
unsigned int gl_minor = 0;
|
|
|
|
if (numbers.size() > 0)
|
|
gl_major = ::atoi(numbers[0].c_str());
|
|
|
|
if (numbers.size() > 1)
|
|
gl_minor = ::atoi(numbers[1].c_str());
|
|
|
|
if (gl_major < major)
|
|
return false;
|
|
else if (gl_major > major)
|
|
return true;
|
|
else
|
|
return gl_minor >= minor;
|
|
}
|
|
|
|
bool OpenGLManager::GLInfo::is_version_greater_or_equal_to(unsigned int major, unsigned int minor) const
|
|
{
|
|
if (!m_detected)
|
|
detect();
|
|
|
|
return version_greater_or_equal_to(m_version, major, minor);
|
|
}
|
|
|
|
bool OpenGLManager::GLInfo::is_glsl_version_greater_or_equal_to(unsigned int major, unsigned int minor) const
|
|
{
|
|
if (!m_detected)
|
|
detect();
|
|
|
|
return version_greater_or_equal_to(m_glsl_version, major, minor);
|
|
}
|
|
|
|
// If formatted for github, plaintext with OpenGL extensions enclosed into <details>.
|
|
// Otherwise HTML formatted for the system info dialog.
|
|
std::string OpenGLManager::GLInfo::to_string(bool for_github) const
|
|
{
|
|
if (!m_detected)
|
|
detect();
|
|
|
|
std::stringstream out;
|
|
|
|
const bool format_as_html = ! for_github;
|
|
std::string h2_start = format_as_html ? "<b>" : "";
|
|
std::string h2_end = format_as_html ? "</b>" : "";
|
|
std::string b_start = format_as_html ? "<b>" : "";
|
|
std::string b_end = format_as_html ? "</b>" : "";
|
|
std::string line_end = format_as_html ? "<br>" : "\n";
|
|
|
|
out << h2_start << "OpenGL installation" << h2_end << line_end;
|
|
out << b_start << "GL version: " << b_end << m_version << line_end;
|
|
#if !SLIC3R_OPENGL_ES
|
|
out << b_start << "Profile: " << b_end << (is_core_profile() ? "Core" : "Compatibility") << line_end;
|
|
#endif // !SLIC3R_OPENGL_ES
|
|
out << b_start << "Vendor: " << b_end << m_vendor << line_end;
|
|
out << b_start << "Renderer: " << b_end << m_renderer << line_end;
|
|
out << b_start << "GLSL version: " << b_end << m_glsl_version << line_end;
|
|
|
|
{
|
|
std::vector<std::string> extensions_list;
|
|
std::string extensions_str = gl_get_string_safe(GL_EXTENSIONS, "");
|
|
boost::split(extensions_list, extensions_str, boost::is_any_of(" "), boost::token_compress_on);
|
|
|
|
if (!extensions_list.empty()) {
|
|
if (for_github)
|
|
out << "<details>\n<summary>Installed extensions:</summary>\n";
|
|
else
|
|
out << h2_start << "Installed extensions:" << h2_end << line_end;
|
|
|
|
std::sort(extensions_list.begin(), extensions_list.end());
|
|
for (const std::string& ext : extensions_list)
|
|
if (! ext.empty())
|
|
out << ext << line_end;
|
|
|
|
if (for_github)
|
|
out << "</details>\n";
|
|
}
|
|
}
|
|
|
|
return out.str();
|
|
}
|
|
|
|
OpenGLManager::GLInfo OpenGLManager::s_gl_info;
|
|
bool OpenGLManager::s_compressed_textures_supported = false;
|
|
bool OpenGLManager::s_force_power_of_two_textures = false;
|
|
OpenGLManager::EMultisampleState OpenGLManager::s_multisample = OpenGLManager::EMultisampleState::Unknown;
|
|
OpenGLManager::EFramebufferType OpenGLManager::s_framebuffers_type = OpenGLManager::EFramebufferType::Unknown;
|
|
|
|
#ifdef __APPLE__
|
|
// Part of hack to remove crash when closing the application on OSX 10.9.5 when building against newer wxWidgets
|
|
OpenGLManager::OSInfo OpenGLManager::s_os_info;
|
|
#endif // __APPLE__
|
|
|
|
OpenGLManager::~OpenGLManager()
|
|
{
|
|
m_shaders_manager.shutdown();
|
|
|
|
#ifdef __APPLE__
|
|
// This is an ugly hack needed to solve the crash happening when closing the application on OSX 10.9.5 with newer wxWidgets
|
|
// The crash is triggered inside wxGLContext destructor
|
|
if (s_os_info.major != 10 || s_os_info.minor != 9 || s_os_info.micro != 5)
|
|
{
|
|
#endif //__APPLE__
|
|
if (m_context != nullptr)
|
|
delete m_context;
|
|
#ifdef __APPLE__
|
|
}
|
|
#endif //__APPLE__
|
|
}
|
|
|
|
bool OpenGLManager::init_gl(bool popup_error)
|
|
{
|
|
if (!m_gl_initialized) {
|
|
glewExperimental = true;
|
|
GLenum result = glewInit();
|
|
if (result != GLEW_OK) {
|
|
BOOST_LOG_TRIVIAL(error) << "Unable to init glew library";
|
|
return false;
|
|
}
|
|
//BOOST_LOG_TRIVIAL(info) << "glewInit Success."<< std::endl;
|
|
m_gl_initialized = true;
|
|
if (GLEW_EXT_texture_compression_s3tc)
|
|
s_compressed_textures_supported = true;
|
|
else
|
|
s_compressed_textures_supported = false;
|
|
|
|
if (GLEW_ARB_framebuffer_object) {
|
|
s_framebuffers_type = EFramebufferType::Arb;
|
|
BOOST_LOG_TRIVIAL(info) << "Found Framebuffer Type ARB."<< std::endl;
|
|
}
|
|
else if (GLEW_EXT_framebuffer_object) {
|
|
BOOST_LOG_TRIVIAL(info) << "Found Framebuffer Type Ext."<< std::endl;
|
|
s_framebuffers_type = EFramebufferType::Ext;
|
|
}
|
|
else {
|
|
s_framebuffers_type = EFramebufferType::Unknown;
|
|
BOOST_LOG_TRIVIAL(warning) << "Found Framebuffer Type unknown!"<< std::endl;
|
|
}
|
|
|
|
bool valid_version = s_gl_info.is_version_greater_or_equal_to(2, 0);
|
|
if (!valid_version) {
|
|
BOOST_LOG_TRIVIAL(error) << "Found opengl version <= 3.2"<< std::endl;
|
|
// Complain about the OpenGL version.
|
|
if (popup_error) {
|
|
wxString message = from_u8((boost::format(
|
|
_utf8(L("The application cannot run normally because OpenGL version is lower than 3.2.\n")))).str());
|
|
message += "\n";
|
|
message += _L("Please upgrade your graphics card driver.");
|
|
wxMessageBox(message, _L("Unsupported OpenGL version"), wxOK | wxICON_ERROR);
|
|
}
|
|
}
|
|
|
|
if (valid_version)
|
|
{
|
|
// load shaders
|
|
auto [result, error] = m_shaders_manager.init();
|
|
if (!result) {
|
|
BOOST_LOG_TRIVIAL(error) << "Unable to load shaders: "<<error<< std::endl;
|
|
if (popup_error) {
|
|
wxString message = from_u8((boost::format(
|
|
_utf8(L("Unable to load shaders:\n%s"))) % error).str());
|
|
wxMessageBox(message, _L("Error loading shaders"), wxOK | wxICON_ERROR);
|
|
}
|
|
}
|
|
}
|
|
|
|
#ifdef _WIN32
|
|
// Since AMD driver version 22.7.1, there is probably some bug in the driver that causes the issue with the missing
|
|
// texture of the bed (see: https://github.com/prusa3d/PrusaSlicer/issues/8417).
|
|
// It seems that this issue only triggers when mipmaps are generated manually
|
|
// (combined with a texture compression) with texture size not being power of two.
|
|
// When mipmaps are generated through OpenGL function glGenerateMipmap() the driver works fine,
|
|
// but the mipmap generation is quite slow on some machines.
|
|
// There is no an easy way to detect the driver version without using Win32 API because the strings returned by OpenGL
|
|
// have no standardized format, only some of them contain the driver version.
|
|
// Until we do not know that driver will be fixed (if ever) we force the use of power of two textures on all cards
|
|
// 1) containing the string 'Radeon' in the string returned by glGetString(GL_RENDERER)
|
|
// 2) containing the string 'Custom' in the string returned by glGetString(GL_RENDERER)
|
|
const auto& gl_info = OpenGLManager::get_gl_info();
|
|
if (boost::contains(gl_info.get_vendor(), "ATI Technologies Inc.") &&
|
|
(boost::contains(gl_info.get_renderer(), "Radeon") ||
|
|
boost::contains(gl_info.get_renderer(), "Custom")))
|
|
s_force_power_of_two_textures = true;
|
|
#endif // _WIN32
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
wxGLContext* OpenGLManager::init_glcontext(wxGLCanvas& canvas, const std::pair<int, int>& required_opengl_version, bool enable_compatibility_profile,
|
|
bool enable_debug)
|
|
{
|
|
if (m_context == nullptr) {
|
|
// m_debug_enabled = enable_debug;
|
|
|
|
const int gl_major = required_opengl_version.first;
|
|
const int gl_minor = required_opengl_version.second;
|
|
const bool supports_core_profile =
|
|
std::find(OpenGLVersions::core.begin(), OpenGLVersions::core.end(), std::make_pair(gl_major, gl_minor)) != OpenGLVersions::core.end();
|
|
|
|
if (gl_major == 0 && !enable_compatibility_profile) {
|
|
// search for highest supported core profile version
|
|
// disable wxWidgets logging to avoid showing the log dialog in case the following code fails generating a valid gl context
|
|
wxLogNull logNo;
|
|
for (auto v = OpenGLVersions::core.rbegin(); v != OpenGLVersions::core.rend(); ++v) {
|
|
wxGLContextAttrs attrs;
|
|
attrs.PlatformDefaults().MajorVersion(v->first).MinorVersion(v->second).CoreProfile().ForwardCompatible();
|
|
// if (m_debug_enabled)
|
|
// attrs.DebugCtx();
|
|
attrs.EndList();
|
|
m_context = new wxGLContext(&canvas, nullptr, &attrs);
|
|
if (m_context->IsOK())
|
|
break;
|
|
else {
|
|
delete m_context;
|
|
m_context = nullptr;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (m_context == nullptr) {
|
|
// search for requested compatibility profile version
|
|
if (enable_compatibility_profile) {
|
|
// disable wxWidgets logging to avoid showing the log dialog in case the following code fails generating a valid gl context
|
|
wxLogNull logNo;
|
|
wxGLContextAttrs attrs;
|
|
attrs.PlatformDefaults().CompatibilityProfile();
|
|
// if (m_debug_enabled)
|
|
// attrs.DebugCtx();
|
|
attrs.EndList();
|
|
m_context = new wxGLContext(&canvas, nullptr, &attrs);
|
|
if (!m_context->IsOK()) {
|
|
delete m_context;
|
|
m_context = nullptr;
|
|
}
|
|
}
|
|
// search for requested core profile version
|
|
else if (supports_core_profile) {
|
|
// disable wxWidgets logging to avoid showing the log dialog in case the following code fails generating a valid gl context
|
|
wxLogNull logNo;
|
|
wxGLContextAttrs attrs;
|
|
attrs.PlatformDefaults().MajorVersion(gl_major).MinorVersion(gl_minor).CoreProfile().ForwardCompatible();
|
|
// if (m_debug_enabled)
|
|
// attrs.DebugCtx();
|
|
attrs.EndList();
|
|
m_context = new wxGLContext(&canvas, nullptr, &attrs);
|
|
if (!m_context->IsOK()) {
|
|
delete m_context;
|
|
m_context = nullptr;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (m_context == nullptr) {
|
|
wxGLContextAttrs attrs;
|
|
attrs.PlatformDefaults();
|
|
// if (m_debug_enabled)
|
|
// attrs.DebugCtx();
|
|
attrs.EndList();
|
|
// if no valid context was created use the default one
|
|
m_context = new wxGLContext(&canvas, nullptr, &attrs);
|
|
}
|
|
|
|
#ifdef __APPLE__
|
|
// Part of hack to remove crash when closing the application on OSX 10.9.5 when building against newer wxWidgets
|
|
s_os_info.major = wxPlatformInfo::Get().GetOSMajorVersion();
|
|
s_os_info.minor = wxPlatformInfo::Get().GetOSMinorVersion();
|
|
s_os_info.micro = wxPlatformInfo::Get().GetOSMicroVersion();
|
|
#endif //__APPLE__
|
|
}
|
|
return m_context;
|
|
}
|
|
|
|
wxGLCanvas* OpenGLManager::create_wxglcanvas(wxWindow& parent)
|
|
{
|
|
int attribList[] = {
|
|
WX_GL_RGBA,
|
|
WX_GL_DOUBLEBUFFER,
|
|
// RGB channels each should be allocated with 8 bit depth. One should almost certainly get these bit depths by default.
|
|
WX_GL_MIN_RED, 8,
|
|
WX_GL_MIN_GREEN, 8,
|
|
WX_GL_MIN_BLUE, 8,
|
|
// Requesting an 8 bit alpha channel. Interestingly, the NVIDIA drivers would most likely work with some alpha plane, but glReadPixels would not return
|
|
// the alpha channel on NVIDIA if not requested when the GL context is created.
|
|
WX_GL_MIN_ALPHA, 8,
|
|
WX_GL_DEPTH_SIZE, 24,
|
|
//BBS: turn on stencil buffer for outline
|
|
WX_GL_STENCIL_SIZE, 8,
|
|
WX_GL_SAMPLE_BUFFERS, GL_TRUE,
|
|
WX_GL_SAMPLES, 4,
|
|
0
|
|
};
|
|
|
|
if (s_multisample == EMultisampleState::Unknown) {
|
|
detect_multisample(attribList);
|
|
// // debug output
|
|
// std::cout << "Multisample " << (can_multisample() ? "enabled" : "disabled") << std::endl;
|
|
}
|
|
|
|
if (! can_multisample())
|
|
attribList[12] = 0;
|
|
|
|
return new wxGLCanvas(&parent, wxID_ANY, attribList, wxDefaultPosition, wxDefaultSize, wxWANTS_CHARS);
|
|
}
|
|
|
|
void OpenGLManager::detect_multisample(int* attribList)
|
|
{
|
|
int wxVersion = wxMAJOR_VERSION * 10000 + wxMINOR_VERSION * 100 + wxRELEASE_NUMBER;
|
|
bool enable_multisample = wxVersion >= 30003;
|
|
s_multisample =
|
|
enable_multisample &&
|
|
// Disable multi-sampling on ChromeOS, as the OpenGL virtualization swaps Red/Blue channels with multi-sampling enabled,
|
|
// at least on some platforms.
|
|
platform_flavor() != PlatformFlavor::LinuxOnChromium &&
|
|
wxGLCanvas::IsDisplaySupported(attribList)
|
|
? EMultisampleState::Enabled : EMultisampleState::Disabled;
|
|
// Alternative method: it was working on previous version of wxWidgets but not with the latest, at least on Windows
|
|
// s_multisample = enable_multisample && wxGLCanvas::IsExtensionSupported("WGL_ARB_multisample");
|
|
}
|
|
|
|
} // namespace GUI
|
|
} // namespace Slic3r
|