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:
parent
a1eb8c5cbd
commit
8d0780aabe
@ -33,6 +33,9 @@
|
||||
#include "unix/fhs.hpp" // Generated by CMake from ../platform/unix/fhs.hpp.in
|
||||
|
||||
#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/Geometry.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.
|
||||
boost::algorithm::iends_with(boost::filesystem::path(argv[0]).filename().string(), "gcodeviewer");
|
||||
#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 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);
|
||||
}
|
||||
|
||||
#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 ?
|
||||
for (auto it = m_actions.begin(); it != m_actions.end(); ++it) {
|
||||
if (*it == "gcodeviewer") {
|
||||
@ -164,6 +198,7 @@ int CLI::run(int argc, char **argv)
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif // ENABLE_GL_CORE_PROFILE
|
||||
|
||||
// Read input file(s) if any.
|
||||
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.input_files = std::move(m_input_files);
|
||||
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);
|
||||
#else // SLIC3R_GUI
|
||||
// No GUI support. Just print out a help.
|
||||
|
@ -4304,6 +4304,14 @@ CLIActionsConfigDef::CLIActionsConfigDef()
|
||||
def->cli = "gcodeviewer";
|
||||
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->label = L("Slice");
|
||||
def->tooltip = L("Slice the model as FFF or SLA based on the printer_technology configuration value.");
|
||||
|
@ -864,9 +864,10 @@ void Bed3D::render_default(bool bottom, bool picking, bool show_texture)
|
||||
|
||||
if (!picking && show_texture) {
|
||||
// draw grid
|
||||
#if !ENABLE_GL_CORE_PROFILE
|
||||
#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));
|
||||
#endif // !ENABLE_GL_CORE_PROFILE
|
||||
m_gridlines.set_color(has_model && !bottom ? DEFAULT_SOLID_GRID_COLOR : DEFAULT_TRANSPARENT_GRID_COLOR);
|
||||
m_gridlines.render();
|
||||
}
|
||||
@ -931,6 +932,9 @@ void Bed3D::render_contour(const Transform3d& view_matrix, const Transform3d& pr
|
||||
glsafe(::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));
|
||||
|
||||
// draw contour
|
||||
#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();
|
||||
|
||||
|
@ -389,9 +389,10 @@ void GLVolume::NonManifoldEdges::render()
|
||||
{
|
||||
update();
|
||||
|
||||
#if !ENABLE_GL_CORE_PROFILE
|
||||
#if ENABLE_GL_CORE_PROFILE
|
||||
if (!GUI::OpenGLManager::get_gl_info().is_core_profile())
|
||||
#endif // ENABLE_GL_CORE_PROFILE
|
||||
glsafe(::glLineWidth(2.0f));
|
||||
#endif // !ENABLE_GL_CORE_PROFILE
|
||||
#if ENABLE_LEGACY_OPENGL_REMOVAL
|
||||
GLShaderProgram* shader = GUI::wxGetApp().get_current_shader();
|
||||
if (shader == nullptr)
|
||||
@ -1087,7 +1088,7 @@ void GLVolumeCollection::render(GLVolumeCollection::ERenderType type, bool disab
|
||||
#if ENABLE_LEGACY_OPENGL_REMOVAL
|
||||
GLShaderProgram* sink_shader = GUI::wxGetApp().get_shader("flat");
|
||||
#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
|
||||
GLShaderProgram* edges_shader = GUI::wxGetApp().get_shader("flat");
|
||||
#endif // ENABLE_GL_CORE_PROFILE
|
||||
|
@ -740,7 +740,7 @@ void GCodeViewer::init()
|
||||
#if ENABLE_LEGACY_OPENGL_REMOVAL
|
||||
buffer.vertices.format = VBuffer::EFormat::Position;
|
||||
#if ENABLE_GL_CORE_PROFILE
|
||||
buffer.shader = "dashed_thick_lines";
|
||||
buffer.shader = OpenGLManager::get_gl_info().is_core_profile() ? "dashed_thick_lines" : "flat";
|
||||
#else
|
||||
buffer.shader = "flat";
|
||||
#endif // ENABLE_GL_CORE_PROFILE
|
||||
@ -3179,11 +3179,9 @@ void GCodeViewer::render_toolpaths()
|
||||
}
|
||||
};
|
||||
|
||||
#if !ENABLE_GL_CORE_PROFILE
|
||||
auto line_width = [](double zoom) {
|
||||
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 end_id = buffer_id(EMoveType::Count);
|
||||
@ -3272,9 +3270,12 @@ void GCodeViewer::render_toolpaths()
|
||||
switch (buffer.render_primitive_type)
|
||||
{
|
||||
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))));
|
||||
#endif // !ENABLE_GL_CORE_PROFILE
|
||||
#endif // ENABLE_GL_CORE_PROFILE
|
||||
render_as_lines(it_path, buffer.render_paths.end(), *shader, uniform_color);
|
||||
break;
|
||||
}
|
||||
|
@ -504,7 +504,7 @@ void GLCanvas3D::LayersEditing::render_profile(const Rect& bar_rect)
|
||||
}
|
||||
|
||||
#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
|
||||
GLShaderProgram* shader = wxGetApp().get_shader("flat");
|
||||
#endif // ENABLE_GL_CORE_PROFILE
|
||||
@ -6048,9 +6048,10 @@ void GLCanvas3D::_render_camera_target()
|
||||
static const float half_length = 5.0f;
|
||||
|
||||
glsafe(::glDisable(GL_DEPTH_TEST));
|
||||
#if !ENABLE_GL_CORE_PROFILE
|
||||
#if ENABLE_GL_CORE_PROFILE
|
||||
if (!OpenGLManager::get_gl_info().is_core_profile())
|
||||
#endif // ENABLE_GL_CORE_PROFILE
|
||||
glsafe(::glLineWidth(2.0f));
|
||||
#endif // !ENABLE_GL_CORE_PROFILE
|
||||
|
||||
#if ENABLE_LEGACY_OPENGL_REMOVAL
|
||||
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
|
||||
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
|
||||
GLShaderProgram* shader = wxGetApp().get_shader("flat");
|
||||
#endif // ENABLE_GL_CORE_PROFILE
|
||||
|
@ -105,9 +105,10 @@ namespace GUI {
|
||||
const float bottom = (float)std::min(start.y(), end.y()) * inv_zoom;
|
||||
#endif // ENABLE_LEGACY_OPENGL_REMOVAL
|
||||
|
||||
#if !ENABLE_GL_CORE_PROFILE
|
||||
#if ENABLE_GL_CORE_PROFILE
|
||||
if (!OpenGLManager::get_gl_info().is_core_profile())
|
||||
#endif // ENABLE_GL_CORE_PROFILE
|
||||
glsafe(::glLineWidth(1.5f));
|
||||
#endif // !ENABLE_GL_CORE_PROFILE
|
||||
#if !ENABLE_LEGACY_OPENGL_REMOVAL
|
||||
float color[3];
|
||||
color[0] = (m_state == EState::Select) ? 0.3f : 1.0f;
|
||||
@ -136,7 +137,7 @@ namespace GUI {
|
||||
|
||||
#if ENABLE_LEGACY_OPENGL_REMOVAL
|
||||
#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
|
||||
GLShaderProgram* shader = wxGetApp().get_shader("flat");
|
||||
#endif // ENABLE_GL_CORE_PROFILE
|
||||
|
@ -3,6 +3,9 @@
|
||||
#include "GLShadersManager.hpp"
|
||||
#include "3DScene.hpp"
|
||||
#include "GUI_App.hpp"
|
||||
#if ENABLE_GL_CORE_PROFILE
|
||||
#include "OpenGLManager.hpp"
|
||||
#endif // ENABLE_GL_CORE_PROFILE
|
||||
|
||||
#include <cassert>
|
||||
#include <algorithm>
|
||||
@ -46,6 +49,7 @@ std::pair<bool, std::string> GLShadersManager::init()
|
||||
// used to render 3D scene background
|
||||
valid &= append_shader("background", { prefix + "background.vs", prefix + "background.fs" });
|
||||
#if ENABLE_GL_CORE_PROFILE
|
||||
if (GUI::OpenGLManager::get_gl_info().is_core_profile())
|
||||
// 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
|
||||
|
@ -847,7 +847,11 @@ std::string GUI_App::get_gl_info(bool for_github)
|
||||
|
||||
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);
|
||||
#endif // ENABLE_GL_CORE_PROFILE
|
||||
}
|
||||
|
||||
bool GUI_App::init_opengl()
|
||||
|
@ -1,3 +1,4 @@
|
||||
#include "libslic3r/Technologies.hpp"
|
||||
#include "GUI_Init.hpp"
|
||||
|
||||
#include "libslic3r/AppConfig.hpp"
|
||||
|
@ -21,6 +21,9 @@ struct GUI_InitParams
|
||||
std::vector<std::string> input_files;
|
||||
|
||||
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 ¶ms);
|
||||
|
@ -169,7 +169,7 @@ void GLGizmoCut::on_render()
|
||||
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) {
|
||||
shader->start_using();
|
||||
|
||||
@ -191,9 +191,10 @@ void GLGizmoCut::on_render()
|
||||
|
||||
glsafe(::glClear(GL_DEPTH_BUFFER_BIT));
|
||||
|
||||
#if !ENABLE_GL_CORE_PROFILE
|
||||
#if ENABLE_GL_CORE_PROFILE
|
||||
if (!OpenGLManager::get_gl_info().is_core_profile())
|
||||
#endif // ENABLE_GL_CORE_PROFILE
|
||||
glsafe(::glLineWidth(m_hover_id != -1 ? 2.0f : 1.5f));
|
||||
#endif // !ENABLE_GL_CORE_PROFILE
|
||||
#if ENABLE_LEGACY_OPENGL_REMOVAL
|
||||
if (!m_grabber_connection.is_initialized() || is_changed) {
|
||||
m_grabber_connection.reset();
|
||||
@ -257,9 +258,7 @@ void GLGizmoCut::on_render()
|
||||
glsafe(::glPushMatrix());
|
||||
glsafe(::glTranslated(m_cut_contours.shift.x(), m_cut_contours.shift.y(), m_cut_contours.shift.z()));
|
||||
#endif // ENABLE_LEGACY_OPENGL_REMOVAL
|
||||
#if !ENABLE_GL_CORE_PROFILE
|
||||
glsafe(::glLineWidth(2.0f));
|
||||
#endif // !ENABLE_GL_CORE_PROFILE
|
||||
m_cut_contours.contours.render();
|
||||
#if ENABLE_LEGACY_OPENGL_REMOVAL
|
||||
shader->stop_using();
|
||||
|
@ -132,9 +132,10 @@ void GLGizmoMove3D::on_render()
|
||||
m_grabbers[2].center = { center.x(), center.y(), box.max.z() + Offset };
|
||||
m_grabbers[2].color = AXES_COLOR[2];
|
||||
|
||||
#if !ENABLE_GL_CORE_PROFILE
|
||||
#if ENABLE_GL_CORE_PROFILE
|
||||
if (!OpenGLManager::get_gl_info().is_core_profile())
|
||||
#endif // ENABLE_GL_CORE_PROFILE
|
||||
glsafe(::glLineWidth((m_hover_id != -1) ? 2.0f : 1.5f));
|
||||
#endif // !ENABLE_GL_CORE_PROFILE
|
||||
|
||||
#if ENABLE_LEGACY_OPENGL_REMOVAL
|
||||
auto render_grabber_connection = [this, ¢er](unsigned int id) {
|
||||
@ -167,7 +168,7 @@ void GLGizmoMove3D::on_render()
|
||||
if (m_hover_id == -1) {
|
||||
#if ENABLE_LEGACY_OPENGL_REMOVAL
|
||||
#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
|
||||
GLShaderProgram* shader = wxGetApp().get_shader("flat");
|
||||
#endif // ENABLE_GL_CORE_PROFILE
|
||||
@ -217,7 +218,7 @@ void GLGizmoMove3D::on_render()
|
||||
// draw axis
|
||||
#if ENABLE_LEGACY_OPENGL_REMOVAL
|
||||
#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
|
||||
GLShaderProgram* shader = wxGetApp().get_shader("flat");
|
||||
#endif // ENABLE_GL_CORE_PROFILE
|
||||
|
@ -193,9 +193,10 @@ void GLGizmoPainterBase::render_cursor_circle()
|
||||
center = center * inv_zoom;
|
||||
#endif // ENABLE_LEGACY_OPENGL_REMOVAL
|
||||
|
||||
#if !ENABLE_GL_CORE_PROFILE
|
||||
#if ENABLE_GL_CORE_PROFILE
|
||||
if (!OpenGLManager::get_gl_info().is_core_profile())
|
||||
#endif // ENABLE_GL_CORE_PROFILE
|
||||
glsafe(::glLineWidth(1.5f));
|
||||
#endif // !ENABLE_GL_CORE_PROFILE
|
||||
#if !ENABLE_LEGACY_OPENGL_REMOVAL
|
||||
static const std::array<float, 3> color = { 0.f, 1.f, 0.3f };
|
||||
glsafe(::glColor3fv(color.data()));
|
||||
@ -269,7 +270,7 @@ void GLGizmoPainterBase::render_cursor_circle()
|
||||
}
|
||||
|
||||
#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
|
||||
GLShaderProgram* shader = GUI::wxGetApp().get_shader("flat");
|
||||
#endif // ENABLE_GL_CORE_PROFILE
|
||||
|
@ -175,12 +175,13 @@ void GLGizmoRotate::on_render()
|
||||
transform_to_local(selection);
|
||||
#endif // ENABLE_LEGACY_OPENGL_REMOVAL
|
||||
|
||||
#if !ENABLE_GL_CORE_PROFILE
|
||||
#if ENABLE_GL_CORE_PROFILE
|
||||
if (!OpenGLManager::get_gl_info().is_core_profile())
|
||||
#endif // ENABLE_GL_CORE_PROFILE
|
||||
glsafe(::glLineWidth((m_hover_id != -1) ? 2.0f : 1.5f));
|
||||
#endif // !ENABLE_GL_CORE_PROFILE
|
||||
#if ENABLE_LEGACY_OPENGL_REMOVAL
|
||||
#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
|
||||
GLShaderProgram* shader = wxGetApp().get_shader("flat");
|
||||
#endif // ENABLE_GL_CORE_PROFILE
|
||||
|
@ -256,9 +256,10 @@ void GLGizmoScale3D::on_render()
|
||||
m_grabbers[i].angles = angles;
|
||||
}
|
||||
|
||||
#if !ENABLE_GL_CORE_PROFILE
|
||||
#if ENABLE_GL_CORE_PROFILE
|
||||
if (!OpenGLManager::get_gl_info().is_core_profile())
|
||||
#endif // ENABLE_GL_CORE_PROFILE
|
||||
glsafe(::glLineWidth((m_hover_id != -1) ? 2.0f : 1.5f));
|
||||
#endif // !ENABLE_GL_CORE_PROFILE
|
||||
|
||||
const BoundingBoxf3& selection_box = selection.get_bounding_box();
|
||||
|
||||
@ -268,7 +269,7 @@ void GLGizmoScale3D::on_render()
|
||||
#if ENABLE_LEGACY_OPENGL_REMOVAL
|
||||
// draw connections
|
||||
#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
|
||||
GLShaderProgram* shader = wxGetApp().get_shader("flat");
|
||||
#endif // ENABLE_GL_CORE_PROFILE
|
||||
@ -323,7 +324,7 @@ void GLGizmoScale3D::on_render()
|
||||
#if ENABLE_LEGACY_OPENGL_REMOVAL
|
||||
// draw connections
|
||||
#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
|
||||
GLShaderProgram* shader = wxGetApp().get_shader("flat");
|
||||
#endif // ENABLE_GL_CORE_PROFILE
|
||||
@ -364,7 +365,7 @@ void GLGizmoScale3D::on_render()
|
||||
#if ENABLE_LEGACY_OPENGL_REMOVAL
|
||||
// draw connections
|
||||
#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
|
||||
GLShaderProgram* shader = wxGetApp().get_shader("flat");
|
||||
#endif // ENABLE_GL_CORE_PROFILE
|
||||
@ -405,7 +406,7 @@ void GLGizmoScale3D::on_render()
|
||||
#if ENABLE_LEGACY_OPENGL_REMOVAL
|
||||
// draw connections
|
||||
#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
|
||||
GLShaderProgram* shader = wxGetApp().get_shader("flat");
|
||||
#endif // ENABLE_GL_CORE_PROFILE
|
||||
@ -446,7 +447,7 @@ void GLGizmoScale3D::on_render()
|
||||
#if ENABLE_LEGACY_OPENGL_REMOVAL
|
||||
// draw connections
|
||||
#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
|
||||
GLShaderProgram* shader = wxGetApp().get_shader("flat");
|
||||
#endif // ENABLE_GL_CORE_PROFILE
|
||||
|
@ -772,9 +772,10 @@ void GLGizmoSimplify::on_render()
|
||||
const ColorRGBA color = glmodel.get_color();
|
||||
glmodel.set_color(ColorRGBA::WHITE());
|
||||
#endif // ENABLE_LEGACY_OPENGL_REMOVAL
|
||||
#if !ENABLE_GL_CORE_PROFILE
|
||||
#if ENABLE_GL_CORE_PROFILE
|
||||
if (!OpenGLManager::get_gl_info().is_core_profile())
|
||||
#endif // ENABLE_GL_CORE_PROFILE
|
||||
glsafe(::glLineWidth(1.0f));
|
||||
#endif // !ENABLE_GL_CORE_PROFILE
|
||||
glsafe(::glPolygonMode(GL_FRONT_AND_BACK, GL_LINE));
|
||||
glmodel.render();
|
||||
glsafe(::glPolygonMode(GL_FRONT_AND_BACK, GL_FILL));
|
||||
|
@ -350,13 +350,52 @@ bool OpenGLManager::init_gl()
|
||||
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)
|
||||
#endif // ENABLE_GL_CORE_PROFILE
|
||||
{
|
||||
if (m_context == nullptr) {
|
||||
#if ENABLE_GL_CORE_PROFILE
|
||||
if (required_opengl_version != std::make_pair(0, 0)) { // the user specified a required version in the command line using --opengl=M.m
|
||||
m_required_version = required_opengl_version;
|
||||
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.CoreProfile().ForwardCompatible().OGLVersion(3, 3).EndList();
|
||||
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
|
||||
m_context = new wxGLContext(&canvas);
|
||||
#endif // ENABLE_GL_CORE_PROFILE
|
||||
|
@ -84,6 +84,9 @@ private:
|
||||
|
||||
bool m_gl_initialized{ false };
|
||||
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;
|
||||
static GLInfo s_gl_info;
|
||||
#ifdef __APPLE__
|
||||
@ -99,7 +102,11 @@ public:
|
||||
~OpenGLManager();
|
||||
|
||||
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);
|
||||
#endif // ENABLE_GL_CORE_PROFILE
|
||||
|
||||
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(); }
|
||||
|
@ -2005,11 +2005,14 @@ void Selection::render_bounding_box(const BoundingBoxf3 & box, float* color) con
|
||||
glsafe(::glEnable(GL_DEPTH_TEST));
|
||||
|
||||
#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
|
||||
glsafe(::glLineWidth(2.0f * m_scale_factor));
|
||||
GLShaderProgram* shader = wxGetApp().get_shader("flat");
|
||||
#endif // !ENABLE_GL_CORE_PROFILE
|
||||
#endif // ENABLE_GL_CORE_PROFILE
|
||||
if (shader == nullptr)
|
||||
return;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user