Tech ENABLE_GL_CORE_PROFILE - Added command line option '--opengl-core=M.m' which allows the user to select a specific OpenGL version supporting core profile

This commit is contained in:
enricoturri1966 2022-05-30 16:15:25 +02:00
parent a1eb8c5cbd
commit 8d0780aabe
20 changed files with 180 additions and 61 deletions

View File

@ -33,6 +33,9 @@
#include "unix/fhs.hpp" // Generated by CMake from ../platform/unix/fhs.hpp.in #include "unix/fhs.hpp" // Generated by CMake from ../platform/unix/fhs.hpp.in
#include "libslic3r/libslic3r.h" #include "libslic3r/libslic3r.h"
#if ENABLE_GL_CORE_PROFILE
#include <boost/algorithm/string/split.hpp>
#endif // ENABLE_GL_CORE_PROFILE
#include "libslic3r/Config.hpp" #include "libslic3r/Config.hpp"
#include "libslic3r/Geometry.hpp" #include "libslic3r/Geometry.hpp"
#include "libslic3r/GCode/PostProcessor.hpp" #include "libslic3r/GCode/PostProcessor.hpp"
@ -117,6 +120,9 @@ int CLI::run(int argc, char **argv)
// On Unix systems, the prusa-slicer binary may be symlinked to give the application a different meaning. // On Unix systems, the prusa-slicer binary may be symlinked to give the application a different meaning.
boost::algorithm::iends_with(boost::filesystem::path(argv[0]).filename().string(), "gcodeviewer"); boost::algorithm::iends_with(boost::filesystem::path(argv[0]).filename().string(), "gcodeviewer");
#endif // _WIN32 #endif // _WIN32
#if ENABLE_GL_CORE_PROFILE
std::pair<int, int> opengl_version = { 0, 0 };
#endif // ENABLE_GL_CORE_PROFILE
const std::vector<std::string> &load_configs = m_config.option<ConfigOptionStrings>("load", true)->values; const std::vector<std::string> &load_configs = m_config.option<ConfigOptionStrings>("load", true)->values;
const ForwardCompatibilitySubstitutionRule config_substitution_rule = m_config.option<ConfigOptionEnum<ForwardCompatibilitySubstitutionRule>>("config_compatibility", true)->value; const ForwardCompatibilitySubstitutionRule config_substitution_rule = m_config.option<ConfigOptionEnum<ForwardCompatibilitySubstitutionRule>>("config_compatibility", true)->value;
@ -155,6 +161,34 @@ int CLI::run(int argc, char **argv)
m_print_config.apply(config); m_print_config.apply(config);
} }
#if ENABLE_GL_CORE_PROFILE
// search for special keys into command line parameters
auto it = std::find(m_actions.begin(), m_actions.end(), "gcodeviewer");
if (it != m_actions.end()) {
start_gui = true;
start_as_gcodeviewer = true;
m_actions.erase(it);
}
it = std::find(m_actions.begin(), m_actions.end(), "opengl-core");
if (it != m_actions.end()) {
std::string opengl_version_str = m_config.opt_string("opengl-core");
const std::vector<std::string> valid_versions = { "3.3", "4.0", "4.1", "4.2", "4.3", "4.4", "4.5", "4.6" };
if (std::find(valid_versions.begin(), valid_versions.end(), opengl_version_str) == valid_versions.end()) {
boost::nowide::cerr << "Found invalid OpenGL version: " << opengl_version_str << std::endl;
opengl_version_str.clear();
}
if (!opengl_version_str.empty()) {
std::vector<std::string> tokens;
boost::split(tokens, opengl_version_str, boost::is_any_of("."), boost::token_compress_on);
opengl_version.first = std::stoi(tokens[0].c_str());
opengl_version.second = std::stoi(tokens[1].c_str());
}
start_gui = true;
m_actions.erase(it);
}
#else
// are we starting as gcodeviewer ? // are we starting as gcodeviewer ?
for (auto it = m_actions.begin(); it != m_actions.end(); ++it) { for (auto it = m_actions.begin(); it != m_actions.end(); ++it) {
if (*it == "gcodeviewer") { if (*it == "gcodeviewer") {
@ -164,6 +198,7 @@ int CLI::run(int argc, char **argv)
break; break;
} }
} }
#endif // ENABLE_GL_CORE_PROFILE
// Read input file(s) if any. // Read input file(s) if any.
for (const std::string& file : m_input_files) for (const std::string& file : m_input_files)
@ -613,6 +648,9 @@ int CLI::run(int argc, char **argv)
params.extra_config = std::move(m_extra_config); params.extra_config = std::move(m_extra_config);
params.input_files = std::move(m_input_files); params.input_files = std::move(m_input_files);
params.start_as_gcodeviewer = start_as_gcodeviewer; params.start_as_gcodeviewer = start_as_gcodeviewer;
#if ENABLE_GL_CORE_PROFILE
params.opengl_version = opengl_version;
#endif // ENABLE_GL_CORE_PROFILE
return Slic3r::GUI::GUI_Run(params); return Slic3r::GUI::GUI_Run(params);
#else // SLIC3R_GUI #else // SLIC3R_GUI
// No GUI support. Just print out a help. // No GUI support. Just print out a help.

View File

@ -4304,6 +4304,14 @@ CLIActionsConfigDef::CLIActionsConfigDef()
def->cli = "gcodeviewer"; def->cli = "gcodeviewer";
def->set_default_value(new ConfigOptionBool(false)); def->set_default_value(new ConfigOptionBool(false));
#if ENABLE_GL_CORE_PROFILE
def = this->add("opengl-core", coString);
def->label = L("OpenGL core version");
def->tooltip = L("Select the specified OpenGL version supporting core profile");
def->cli = "opengl-core";
def->set_default_value(new ConfigOptionString());
#endif // ENABLE_GL_CORE_PROFILE
def = this->add("slice", coBool); def = this->add("slice", coBool);
def->label = L("Slice"); def->label = L("Slice");
def->tooltip = L("Slice the model as FFF or SLA based on the printer_technology configuration value."); def->tooltip = L("Slice the model as FFF or SLA based on the printer_technology configuration value.");

View File

@ -864,9 +864,10 @@ void Bed3D::render_default(bool bottom, bool picking, bool show_texture)
if (!picking && show_texture) { if (!picking && show_texture) {
// draw grid // draw grid
#if !ENABLE_GL_CORE_PROFILE #if ENABLE_GL_CORE_PROFILE
glsafe(::glLineWidth(1.5f * m_scale_factor)); if (!OpenGLManager::get_gl_info().is_core_profile())
#endif // !ENABLE_GL_CORE_PROFILE #endif // ENABLE_GL_CORE_PROFILE
glsafe(::glLineWidth(1.5f * m_scale_factor));
m_gridlines.set_color(has_model && !bottom ? DEFAULT_SOLID_GRID_COLOR : DEFAULT_TRANSPARENT_GRID_COLOR); m_gridlines.set_color(has_model && !bottom ? DEFAULT_SOLID_GRID_COLOR : DEFAULT_TRANSPARENT_GRID_COLOR);
m_gridlines.render(); m_gridlines.render();
} }
@ -931,7 +932,10 @@ void Bed3D::render_contour(const Transform3d& view_matrix, const Transform3d& pr
glsafe(::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); glsafe(::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));
// draw contour // draw contour
glsafe(::glLineWidth(1.5f * m_scale_factor)); #if ENABLE_GL_CORE_PROFILE
if (!OpenGLManager::get_gl_info().is_core_profile())
#endif // ENABLE_GL_CORE_PROFILE
glsafe(::glLineWidth(1.5f * m_scale_factor));
m_contourlines.render(); m_contourlines.render();
glsafe(::glDisable(GL_BLEND)); glsafe(::glDisable(GL_BLEND));

View File

@ -389,9 +389,10 @@ void GLVolume::NonManifoldEdges::render()
{ {
update(); update();
#if !ENABLE_GL_CORE_PROFILE #if ENABLE_GL_CORE_PROFILE
glsafe(::glLineWidth(2.0f)); if (!GUI::OpenGLManager::get_gl_info().is_core_profile())
#endif // !ENABLE_GL_CORE_PROFILE #endif // ENABLE_GL_CORE_PROFILE
glsafe(::glLineWidth(2.0f));
#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
GLShaderProgram* shader = GUI::wxGetApp().get_current_shader(); GLShaderProgram* shader = GUI::wxGetApp().get_current_shader();
if (shader == nullptr) if (shader == nullptr)
@ -1087,7 +1088,7 @@ void GLVolumeCollection::render(GLVolumeCollection::ERenderType type, bool disab
#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
GLShaderProgram* sink_shader = GUI::wxGetApp().get_shader("flat"); GLShaderProgram* sink_shader = GUI::wxGetApp().get_shader("flat");
#if ENABLE_GL_CORE_PROFILE #if ENABLE_GL_CORE_PROFILE
GLShaderProgram* edges_shader = GUI::wxGetApp().get_shader("dashed_thick_lines"); GLShaderProgram* edges_shader = GUI::OpenGLManager::get_gl_info().is_core_profile() ? GUI::wxGetApp().get_shader("dashed_thick_lines") : GUI::wxGetApp().get_shader("flat");
#else #else
GLShaderProgram* edges_shader = GUI::wxGetApp().get_shader("flat"); GLShaderProgram* edges_shader = GUI::wxGetApp().get_shader("flat");
#endif // ENABLE_GL_CORE_PROFILE #endif // ENABLE_GL_CORE_PROFILE

View File

@ -740,7 +740,7 @@ void GCodeViewer::init()
#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
buffer.vertices.format = VBuffer::EFormat::Position; buffer.vertices.format = VBuffer::EFormat::Position;
#if ENABLE_GL_CORE_PROFILE #if ENABLE_GL_CORE_PROFILE
buffer.shader = "dashed_thick_lines"; buffer.shader = OpenGLManager::get_gl_info().is_core_profile() ? "dashed_thick_lines" : "flat";
#else #else
buffer.shader = "flat"; buffer.shader = "flat";
#endif // ENABLE_GL_CORE_PROFILE #endif // ENABLE_GL_CORE_PROFILE
@ -3179,11 +3179,9 @@ void GCodeViewer::render_toolpaths()
} }
}; };
#if !ENABLE_GL_CORE_PROFILE
auto line_width = [](double zoom) { auto line_width = [](double zoom) {
return (zoom < 5.0) ? 1.0 : (1.0 + 5.0 * (zoom - 5.0) / (100.0 - 5.0)); return (zoom < 5.0) ? 1.0 : (1.0 + 5.0 * (zoom - 5.0) / (100.0 - 5.0));
}; };
#endif // !ENABLE_GL_CORE_PROFILE
const unsigned char begin_id = buffer_id(EMoveType::Retract); const unsigned char begin_id = buffer_id(EMoveType::Retract);
const unsigned char end_id = buffer_id(EMoveType::Count); const unsigned char end_id = buffer_id(EMoveType::Count);
@ -3272,9 +3270,12 @@ void GCodeViewer::render_toolpaths()
switch (buffer.render_primitive_type) switch (buffer.render_primitive_type)
{ {
case TBuffer::ERenderPrimitiveType::Line: { case TBuffer::ERenderPrimitiveType::Line: {
#if !ENABLE_GL_CORE_PROFILE #if ENABLE_GL_CORE_PROFILE
if (!OpenGLManager::get_gl_info().is_core_profile())
glsafe(::glLineWidth(static_cast<GLfloat>(line_width(camera.get_zoom()))));
#else
glsafe(::glLineWidth(static_cast<GLfloat>(line_width(zoom)))); glsafe(::glLineWidth(static_cast<GLfloat>(line_width(zoom))));
#endif // !ENABLE_GL_CORE_PROFILE #endif // ENABLE_GL_CORE_PROFILE
render_as_lines(it_path, buffer.render_paths.end(), *shader, uniform_color); render_as_lines(it_path, buffer.render_paths.end(), *shader, uniform_color);
break; break;
} }

View File

@ -504,7 +504,7 @@ void GLCanvas3D::LayersEditing::render_profile(const Rect& bar_rect)
} }
#if ENABLE_GL_CORE_PROFILE #if ENABLE_GL_CORE_PROFILE
GLShaderProgram* shader = wxGetApp().get_shader("dashed_thick_lines"); GLShaderProgram* shader = OpenGLManager::get_gl_info().is_core_profile() ? wxGetApp().get_shader("dashed_thick_lines") : wxGetApp().get_shader("flat");
#else #else
GLShaderProgram* shader = wxGetApp().get_shader("flat"); GLShaderProgram* shader = wxGetApp().get_shader("flat");
#endif // ENABLE_GL_CORE_PROFILE #endif // ENABLE_GL_CORE_PROFILE
@ -6048,9 +6048,10 @@ void GLCanvas3D::_render_camera_target()
static const float half_length = 5.0f; static const float half_length = 5.0f;
glsafe(::glDisable(GL_DEPTH_TEST)); glsafe(::glDisable(GL_DEPTH_TEST));
#if !ENABLE_GL_CORE_PROFILE #if ENABLE_GL_CORE_PROFILE
glsafe(::glLineWidth(2.0f)); if (!OpenGLManager::get_gl_info().is_core_profile())
#endif // !ENABLE_GL_CORE_PROFILE #endif // ENABLE_GL_CORE_PROFILE
glsafe(::glLineWidth(2.0f));
#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
const Vec3f& target = wxGetApp().plater()->get_camera().get_target().cast<float>(); const Vec3f& target = wxGetApp().plater()->get_camera().get_target().cast<float>();
@ -6088,7 +6089,7 @@ void GLCanvas3D::_render_camera_target()
} }
#if ENABLE_GL_CORE_PROFILE #if ENABLE_GL_CORE_PROFILE
GLShaderProgram* shader = wxGetApp().get_shader("dashed_thick_lines"); GLShaderProgram* shader = OpenGLManager::get_gl_info().is_core_profile() ? wxGetApp().get_shader("dashed_thick_lines") : wxGetApp().get_shader("flat");
#else #else
GLShaderProgram* shader = wxGetApp().get_shader("flat"); GLShaderProgram* shader = wxGetApp().get_shader("flat");
#endif // ENABLE_GL_CORE_PROFILE #endif // ENABLE_GL_CORE_PROFILE

View File

@ -105,9 +105,10 @@ namespace GUI {
const float bottom = (float)std::min(start.y(), end.y()) * inv_zoom; const float bottom = (float)std::min(start.y(), end.y()) * inv_zoom;
#endif // ENABLE_LEGACY_OPENGL_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
#if !ENABLE_GL_CORE_PROFILE #if ENABLE_GL_CORE_PROFILE
glsafe(::glLineWidth(1.5f)); if (!OpenGLManager::get_gl_info().is_core_profile())
#endif // !ENABLE_GL_CORE_PROFILE #endif // ENABLE_GL_CORE_PROFILE
glsafe(::glLineWidth(1.5f));
#if !ENABLE_LEGACY_OPENGL_REMOVAL #if !ENABLE_LEGACY_OPENGL_REMOVAL
float color[3]; float color[3];
color[0] = (m_state == EState::Select) ? 0.3f : 1.0f; color[0] = (m_state == EState::Select) ? 0.3f : 1.0f;
@ -136,7 +137,7 @@ namespace GUI {
#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_GL_CORE_PROFILE #if ENABLE_GL_CORE_PROFILE
GLShaderProgram* shader = wxGetApp().get_shader("dashed_thick_lines"); GLShaderProgram* shader = OpenGLManager::get_gl_info().is_core_profile() ? wxGetApp().get_shader("dashed_thick_lines") : wxGetApp().get_shader("flat");
#else #else
GLShaderProgram* shader = wxGetApp().get_shader("flat"); GLShaderProgram* shader = wxGetApp().get_shader("flat");
#endif // ENABLE_GL_CORE_PROFILE #endif // ENABLE_GL_CORE_PROFILE

View File

@ -3,6 +3,9 @@
#include "GLShadersManager.hpp" #include "GLShadersManager.hpp"
#include "3DScene.hpp" #include "3DScene.hpp"
#include "GUI_App.hpp" #include "GUI_App.hpp"
#if ENABLE_GL_CORE_PROFILE
#include "OpenGLManager.hpp"
#endif // ENABLE_GL_CORE_PROFILE
#include <cassert> #include <cassert>
#include <algorithm> #include <algorithm>
@ -46,8 +49,9 @@ std::pair<bool, std::string> GLShadersManager::init()
// used to render 3D scene background // used to render 3D scene background
valid &= append_shader("background", { prefix + "background.vs", prefix + "background.fs" }); valid &= append_shader("background", { prefix + "background.vs", prefix + "background.fs" });
#if ENABLE_GL_CORE_PROFILE #if ENABLE_GL_CORE_PROFILE
// used to render thick and/or dashed lines if (GUI::OpenGLManager::get_gl_info().is_core_profile())
valid &= append_shader("dashed_thick_lines", { prefix + "dashed_thick_lines.vs", prefix + "dashed_thick_lines.fs", prefix + "dashed_thick_lines.gs" }); // used to render thick and/or dashed lines
valid &= append_shader("dashed_thick_lines", { prefix + "dashed_thick_lines.vs", prefix + "dashed_thick_lines.fs", prefix + "dashed_thick_lines.gs" });
#endif // ENABLE_GL_CORE_PROFILE #endif // ENABLE_GL_CORE_PROFILE
#endif // ENABLE_LEGACY_OPENGL_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_SHOW_TOOLPATHS_COG #if ENABLE_SHOW_TOOLPATHS_COG

View File

@ -847,7 +847,11 @@ std::string GUI_App::get_gl_info(bool for_github)
wxGLContext* GUI_App::init_glcontext(wxGLCanvas& canvas) wxGLContext* GUI_App::init_glcontext(wxGLCanvas& canvas)
{ {
#if ENABLE_GL_CORE_PROFILE
return m_opengl_mgr.init_glcontext(canvas, init_params != nullptr ? init_params->opengl_version : std::make_pair(0, 0));
#else
return m_opengl_mgr.init_glcontext(canvas); return m_opengl_mgr.init_glcontext(canvas);
#endif // ENABLE_GL_CORE_PROFILE
} }
bool GUI_App::init_opengl() bool GUI_App::init_opengl()

View File

@ -1,3 +1,4 @@
#include "libslic3r/Technologies.hpp"
#include "GUI_Init.hpp" #include "GUI_Init.hpp"
#include "libslic3r/AppConfig.hpp" #include "libslic3r/AppConfig.hpp"

View File

@ -21,6 +21,9 @@ struct GUI_InitParams
std::vector<std::string> input_files; std::vector<std::string> input_files;
bool start_as_gcodeviewer; bool start_as_gcodeviewer;
#if ENABLE_GL_CORE_PROFILE
std::pair<int, int> opengl_version;
#endif // ENABLE_GL_CORE_PROFILE
}; };
int GUI_Run(GUI_InitParams &params); int GUI_Run(GUI_InitParams &params);

View File

@ -169,7 +169,7 @@ void GLGizmoCut::on_render()
shader->stop_using(); shader->stop_using();
} }
shader = wxGetApp().get_shader("dashed_thick_lines"); shader = OpenGLManager::get_gl_info().is_core_profile() ? wxGetApp().get_shader("dashed_thick_lines") : wxGetApp().get_shader("flat");
if (shader != nullptr) { if (shader != nullptr) {
shader->start_using(); shader->start_using();
@ -191,9 +191,10 @@ void GLGizmoCut::on_render()
glsafe(::glClear(GL_DEPTH_BUFFER_BIT)); glsafe(::glClear(GL_DEPTH_BUFFER_BIT));
#if !ENABLE_GL_CORE_PROFILE #if ENABLE_GL_CORE_PROFILE
glsafe(::glLineWidth(m_hover_id != -1 ? 2.0f : 1.5f)); if (!OpenGLManager::get_gl_info().is_core_profile())
#endif // !ENABLE_GL_CORE_PROFILE #endif // ENABLE_GL_CORE_PROFILE
glsafe(::glLineWidth(m_hover_id != -1 ? 2.0f : 1.5f));
#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
if (!m_grabber_connection.is_initialized() || is_changed) { if (!m_grabber_connection.is_initialized() || is_changed) {
m_grabber_connection.reset(); m_grabber_connection.reset();
@ -257,10 +258,8 @@ void GLGizmoCut::on_render()
glsafe(::glPushMatrix()); glsafe(::glPushMatrix());
glsafe(::glTranslated(m_cut_contours.shift.x(), m_cut_contours.shift.y(), m_cut_contours.shift.z())); glsafe(::glTranslated(m_cut_contours.shift.x(), m_cut_contours.shift.y(), m_cut_contours.shift.z()));
#endif // ENABLE_LEGACY_OPENGL_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
#if !ENABLE_GL_CORE_PROFILE glsafe(::glLineWidth(2.0f));
glsafe(::glLineWidth(2.0f)); m_cut_contours.contours.render();
#endif // !ENABLE_GL_CORE_PROFILE
m_cut_contours.contours.render();
#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
shader->stop_using(); shader->stop_using();
} }

View File

@ -132,9 +132,10 @@ void GLGizmoMove3D::on_render()
m_grabbers[2].center = { center.x(), center.y(), box.max.z() + Offset }; m_grabbers[2].center = { center.x(), center.y(), box.max.z() + Offset };
m_grabbers[2].color = AXES_COLOR[2]; m_grabbers[2].color = AXES_COLOR[2];
#if !ENABLE_GL_CORE_PROFILE #if ENABLE_GL_CORE_PROFILE
glsafe(::glLineWidth((m_hover_id != -1) ? 2.0f : 1.5f)); if (!OpenGLManager::get_gl_info().is_core_profile())
#endif // !ENABLE_GL_CORE_PROFILE #endif // ENABLE_GL_CORE_PROFILE
glsafe(::glLineWidth((m_hover_id != -1) ? 2.0f : 1.5f));
#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
auto render_grabber_connection = [this, &center](unsigned int id) { auto render_grabber_connection = [this, &center](unsigned int id) {
@ -167,7 +168,7 @@ void GLGizmoMove3D::on_render()
if (m_hover_id == -1) { if (m_hover_id == -1) {
#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_GL_CORE_PROFILE #if ENABLE_GL_CORE_PROFILE
GLShaderProgram* shader = wxGetApp().get_shader("dashed_thick_lines"); GLShaderProgram* shader = OpenGLManager::get_gl_info().is_core_profile() ? wxGetApp().get_shader("dashed_thick_lines") : wxGetApp().get_shader("flat");
#else #else
GLShaderProgram* shader = wxGetApp().get_shader("flat"); GLShaderProgram* shader = wxGetApp().get_shader("flat");
#endif // ENABLE_GL_CORE_PROFILE #endif // ENABLE_GL_CORE_PROFILE
@ -217,7 +218,7 @@ void GLGizmoMove3D::on_render()
// draw axis // draw axis
#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_GL_CORE_PROFILE #if ENABLE_GL_CORE_PROFILE
GLShaderProgram* shader = wxGetApp().get_shader("dashed_thick_lines"); GLShaderProgram* shader = OpenGLManager::get_gl_info().is_core_profile() ? wxGetApp().get_shader("dashed_thick_lines") : wxGetApp().get_shader("flat");
#else #else
GLShaderProgram* shader = wxGetApp().get_shader("flat"); GLShaderProgram* shader = wxGetApp().get_shader("flat");
#endif // ENABLE_GL_CORE_PROFILE #endif // ENABLE_GL_CORE_PROFILE

View File

@ -193,9 +193,10 @@ void GLGizmoPainterBase::render_cursor_circle()
center = center * inv_zoom; center = center * inv_zoom;
#endif // ENABLE_LEGACY_OPENGL_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
#if !ENABLE_GL_CORE_PROFILE #if ENABLE_GL_CORE_PROFILE
glsafe(::glLineWidth(1.5f)); if (!OpenGLManager::get_gl_info().is_core_profile())
#endif // !ENABLE_GL_CORE_PROFILE #endif // ENABLE_GL_CORE_PROFILE
glsafe(::glLineWidth(1.5f));
#if !ENABLE_LEGACY_OPENGL_REMOVAL #if !ENABLE_LEGACY_OPENGL_REMOVAL
static const std::array<float, 3> color = { 0.f, 1.f, 0.3f }; static const std::array<float, 3> color = { 0.f, 1.f, 0.3f };
glsafe(::glColor3fv(color.data())); glsafe(::glColor3fv(color.data()));
@ -269,7 +270,7 @@ void GLGizmoPainterBase::render_cursor_circle()
} }
#if ENABLE_GL_CORE_PROFILE #if ENABLE_GL_CORE_PROFILE
GLShaderProgram* shader = wxGetApp().get_shader("dashed_thick_lines"); GLShaderProgram* shader = OpenGLManager::get_gl_info().is_core_profile() ? wxGetApp().get_shader("dashed_thick_lines") : wxGetApp().get_shader("flat");
#else #else
GLShaderProgram* shader = GUI::wxGetApp().get_shader("flat"); GLShaderProgram* shader = GUI::wxGetApp().get_shader("flat");
#endif // ENABLE_GL_CORE_PROFILE #endif // ENABLE_GL_CORE_PROFILE

View File

@ -175,12 +175,13 @@ void GLGizmoRotate::on_render()
transform_to_local(selection); transform_to_local(selection);
#endif // ENABLE_LEGACY_OPENGL_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
#if !ENABLE_GL_CORE_PROFILE #if ENABLE_GL_CORE_PROFILE
glsafe(::glLineWidth((m_hover_id != -1) ? 2.0f : 1.5f)); if (!OpenGLManager::get_gl_info().is_core_profile())
#endif // !ENABLE_GL_CORE_PROFILE #endif // ENABLE_GL_CORE_PROFILE
glsafe(::glLineWidth((m_hover_id != -1) ? 2.0f : 1.5f));
#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_GL_CORE_PROFILE #if ENABLE_GL_CORE_PROFILE
GLShaderProgram* shader = wxGetApp().get_shader("dashed_thick_lines"); GLShaderProgram* shader = OpenGLManager::get_gl_info().is_core_profile() ? wxGetApp().get_shader("dashed_thick_lines") : wxGetApp().get_shader("flat");
#else #else
GLShaderProgram* shader = wxGetApp().get_shader("flat"); GLShaderProgram* shader = wxGetApp().get_shader("flat");
#endif // ENABLE_GL_CORE_PROFILE #endif // ENABLE_GL_CORE_PROFILE

View File

@ -256,9 +256,10 @@ void GLGizmoScale3D::on_render()
m_grabbers[i].angles = angles; m_grabbers[i].angles = angles;
} }
#if !ENABLE_GL_CORE_PROFILE #if ENABLE_GL_CORE_PROFILE
glsafe(::glLineWidth((m_hover_id != -1) ? 2.0f : 1.5f)); if (!OpenGLManager::get_gl_info().is_core_profile())
#endif // !ENABLE_GL_CORE_PROFILE #endif // ENABLE_GL_CORE_PROFILE
glsafe(::glLineWidth((m_hover_id != -1) ? 2.0f : 1.5f));
const BoundingBoxf3& selection_box = selection.get_bounding_box(); const BoundingBoxf3& selection_box = selection.get_bounding_box();
@ -268,7 +269,7 @@ void GLGizmoScale3D::on_render()
#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
// draw connections // draw connections
#if ENABLE_GL_CORE_PROFILE #if ENABLE_GL_CORE_PROFILE
GLShaderProgram* shader = wxGetApp().get_shader("dashed_thick_lines"); GLShaderProgram* shader = OpenGLManager::get_gl_info().is_core_profile() ? wxGetApp().get_shader("dashed_thick_lines") : wxGetApp().get_shader("flat");
#else #else
GLShaderProgram* shader = wxGetApp().get_shader("flat"); GLShaderProgram* shader = wxGetApp().get_shader("flat");
#endif // ENABLE_GL_CORE_PROFILE #endif // ENABLE_GL_CORE_PROFILE
@ -323,7 +324,7 @@ void GLGizmoScale3D::on_render()
#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
// draw connections // draw connections
#if ENABLE_GL_CORE_PROFILE #if ENABLE_GL_CORE_PROFILE
GLShaderProgram* shader = wxGetApp().get_shader("dashed_thick_lines"); GLShaderProgram* shader = OpenGLManager::get_gl_info().is_core_profile() ? wxGetApp().get_shader("dashed_thick_lines") : wxGetApp().get_shader("flat");
#else #else
GLShaderProgram* shader = wxGetApp().get_shader("flat"); GLShaderProgram* shader = wxGetApp().get_shader("flat");
#endif // ENABLE_GL_CORE_PROFILE #endif // ENABLE_GL_CORE_PROFILE
@ -364,7 +365,7 @@ void GLGizmoScale3D::on_render()
#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
// draw connections // draw connections
#if ENABLE_GL_CORE_PROFILE #if ENABLE_GL_CORE_PROFILE
GLShaderProgram* shader = wxGetApp().get_shader("dashed_thick_lines"); GLShaderProgram* shader = OpenGLManager::get_gl_info().is_core_profile() ? wxGetApp().get_shader("dashed_thick_lines") : wxGetApp().get_shader("flat");
#else #else
GLShaderProgram* shader = wxGetApp().get_shader("flat"); GLShaderProgram* shader = wxGetApp().get_shader("flat");
#endif // ENABLE_GL_CORE_PROFILE #endif // ENABLE_GL_CORE_PROFILE
@ -405,7 +406,7 @@ void GLGizmoScale3D::on_render()
#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
// draw connections // draw connections
#if ENABLE_GL_CORE_PROFILE #if ENABLE_GL_CORE_PROFILE
GLShaderProgram* shader = wxGetApp().get_shader("dashed_thick_lines"); GLShaderProgram* shader = OpenGLManager::get_gl_info().is_core_profile() ? wxGetApp().get_shader("dashed_thick_lines") : wxGetApp().get_shader("flat");
#else #else
GLShaderProgram* shader = wxGetApp().get_shader("flat"); GLShaderProgram* shader = wxGetApp().get_shader("flat");
#endif // ENABLE_GL_CORE_PROFILE #endif // ENABLE_GL_CORE_PROFILE
@ -446,7 +447,7 @@ void GLGizmoScale3D::on_render()
#if ENABLE_LEGACY_OPENGL_REMOVAL #if ENABLE_LEGACY_OPENGL_REMOVAL
// draw connections // draw connections
#if ENABLE_GL_CORE_PROFILE #if ENABLE_GL_CORE_PROFILE
GLShaderProgram* shader = wxGetApp().get_shader("dashed_thick_lines"); GLShaderProgram* shader = OpenGLManager::get_gl_info().is_core_profile() ? wxGetApp().get_shader("dashed_thick_lines") : wxGetApp().get_shader("flat");
#else #else
GLShaderProgram* shader = wxGetApp().get_shader("flat"); GLShaderProgram* shader = wxGetApp().get_shader("flat");
#endif // ENABLE_GL_CORE_PROFILE #endif // ENABLE_GL_CORE_PROFILE

View File

@ -772,9 +772,10 @@ void GLGizmoSimplify::on_render()
const ColorRGBA color = glmodel.get_color(); const ColorRGBA color = glmodel.get_color();
glmodel.set_color(ColorRGBA::WHITE()); glmodel.set_color(ColorRGBA::WHITE());
#endif // ENABLE_LEGACY_OPENGL_REMOVAL #endif // ENABLE_LEGACY_OPENGL_REMOVAL
#if !ENABLE_GL_CORE_PROFILE #if ENABLE_GL_CORE_PROFILE
glsafe(::glLineWidth(1.0f)); if (!OpenGLManager::get_gl_info().is_core_profile())
#endif // !ENABLE_GL_CORE_PROFILE #endif // ENABLE_GL_CORE_PROFILE
glsafe(::glLineWidth(1.0f));
glsafe(::glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)); glsafe(::glPolygonMode(GL_FRONT_AND_BACK, GL_LINE));
glmodel.render(); glmodel.render();
glsafe(::glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)); glsafe(::glPolygonMode(GL_FRONT_AND_BACK, GL_FILL));

View File

@ -350,13 +350,52 @@ bool OpenGLManager::init_gl()
return true; return true;
} }
#if ENABLE_GL_CORE_PROFILE
wxGLContext* OpenGLManager::init_glcontext(wxGLCanvas& canvas, const std::pair<int, int>& required_opengl_version)
#else
wxGLContext* OpenGLManager::init_glcontext(wxGLCanvas& canvas) wxGLContext* OpenGLManager::init_glcontext(wxGLCanvas& canvas)
#endif // ENABLE_GL_CORE_PROFILE
{ {
if (m_context == nullptr) { if (m_context == nullptr) {
#if ENABLE_GL_CORE_PROFILE #if ENABLE_GL_CORE_PROFILE
wxGLContextAttrs attrs; if (required_opengl_version != std::make_pair(0, 0)) { // the user specified a required version in the command line using --opengl=M.m
attrs.CoreProfile().ForwardCompatible().OGLVersion(3, 3).EndList(); m_required_version = required_opengl_version;
m_context = new wxGLContext(&canvas, nullptr, &attrs); const bool supports_core_profile = (m_required_version.first < 3) ? false :
(m_required_version.first > 3) ? true : m_required_version.second >= 3;
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.MajorVersion(m_required_version.first).MinorVersion(m_required_version.second).CoreProfile().ForwardCompatible().EndList();
m_context = new wxGLContext(&canvas, nullptr, &attrs);
if (!m_context->IsOK()) {
BOOST_LOG_TRIVIAL(error) << "Unable to create context for required OpenGL " << required_opengl_version.first << "." << required_opengl_version.second;
delete m_context;
m_context = nullptr;
}
}
}
//else {
// // try to get the highest supported OpenGL version with core profile
// static const std::vector<std::pair<int, int>> valid_core_versions = { {4,6}, {4,5}, {4,4}, {4,3}, {4,2}, {4,1}, {4,0}, {3,3} };
// // disable wxWidgets logging to avoid showing the log dialog in case the following code fails generating a valid gl context
// wxLogNull logNo;
// for (const auto& [major, minor] : valid_core_versions) {
// wxGLContextAttrs attrs;
// attrs.CoreProfile().ForwardCompatible().OGLVersion(major, minor).EndList();
// m_context = new wxGLContext(&canvas, nullptr, &attrs);
// if (m_context->IsOK())
// break;
// else {
// delete m_context;
// m_context = nullptr;
// }
// }
//}
if (m_context == nullptr)
// if no valid context was created use the default one
m_context = new wxGLContext(&canvas);
#else #else
m_context = new wxGLContext(&canvas); m_context = new wxGLContext(&canvas);
#endif // ENABLE_GL_CORE_PROFILE #endif // ENABLE_GL_CORE_PROFILE

View File

@ -84,6 +84,9 @@ private:
bool m_gl_initialized{ false }; bool m_gl_initialized{ false };
wxGLContext* m_context{ nullptr }; wxGLContext* m_context{ nullptr };
#if ENABLE_GL_CORE_PROFILE
std::pair<int, int> m_required_version{ 0, 0 };
#endif // ENABLE_GL_CORE_PROFILE
GLShadersManager m_shaders_manager; GLShadersManager m_shaders_manager;
static GLInfo s_gl_info; static GLInfo s_gl_info;
#ifdef __APPLE__ #ifdef __APPLE__
@ -99,7 +102,11 @@ public:
~OpenGLManager(); ~OpenGLManager();
bool init_gl(); bool init_gl();
#if ENABLE_GL_CORE_PROFILE
wxGLContext* init_glcontext(wxGLCanvas& canvas, const std::pair<int, int>& required_opengl_version);
#else
wxGLContext* init_glcontext(wxGLCanvas& canvas); wxGLContext* init_glcontext(wxGLCanvas& canvas);
#endif // ENABLE_GL_CORE_PROFILE
GLShaderProgram* get_shader(const std::string& shader_name) { return m_shaders_manager.get_shader(shader_name); } GLShaderProgram* get_shader(const std::string& shader_name) { return m_shaders_manager.get_shader(shader_name); }
GLShaderProgram* get_current_shader() { return m_shaders_manager.get_current_shader(); } GLShaderProgram* get_current_shader() { return m_shaders_manager.get_current_shader(); }

View File

@ -2005,11 +2005,14 @@ void Selection::render_bounding_box(const BoundingBoxf3 & box, float* color) con
glsafe(::glEnable(GL_DEPTH_TEST)); glsafe(::glEnable(GL_DEPTH_TEST));
#if ENABLE_GL_CORE_PROFILE #if ENABLE_GL_CORE_PROFILE
GLShaderProgram* shader = wxGetApp().get_shader("dashed_thick_lines"); if (!OpenGLManager::get_gl_info().is_core_profile())
glsafe(::glLineWidth(2.0f * m_scale_factor));
GLShaderProgram* shader = OpenGLManager::get_gl_info().is_core_profile() ? wxGetApp().get_shader("dashed_thick_lines") : wxGetApp().get_shader("flat");
#else #else
glsafe(::glLineWidth(2.0f * m_scale_factor)); glsafe(::glLineWidth(2.0f * m_scale_factor));
GLShaderProgram* shader = wxGetApp().get_shader("flat"); GLShaderProgram* shader = wxGetApp().get_shader("flat");
#endif // !ENABLE_GL_CORE_PROFILE #endif // ENABLE_GL_CORE_PROFILE
if (shader == nullptr) if (shader == nullptr)
return; return;