Fixed crash at startup on Mac OS

This commit is contained in:
enricoturri1966 2022-07-13 08:56:00 +02:00
parent a6a0e3e759
commit 22b634ca1d
11 changed files with 95 additions and 110 deletions

View file

@ -173,11 +173,6 @@ int CLI::run(int argc, char **argv)
m_actions.erase(it);
}
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#ifdef __APPLE__
opengl_version = { 3, 2 };
#else
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
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");
@ -196,21 +191,16 @@ int CLI::run(int argc, char **argv)
start_gui = true;
m_actions.erase(it);
}
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#endif // __APPLE__
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
std::cout << "CLI::run(): required OpenGL version: " << opengl_version.first << "." << opengl_version.second << "\n";
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#if ENABLE_OPENGL_DEBUG_OPTION
#ifndef __APPLE__
it = std::find(m_actions.begin(), m_actions.end(), "opengl-debug");
if (it != m_actions.end()) {
start_gui = true;
opengl_debug = true;
m_actions.erase(it);
}
#endif // __APPLE__
#endif // ENABLE_OPENGL_DEBUG_OPTION
#else
// are we starting as gcodeviewer ?

View file

@ -2065,8 +2065,10 @@ void GCodeViewer::load_toolpaths(const GCodeProcessorResult& gcode_result)
#if ENABLE_GL_CORE_PROFILE
GLuint vao_id = 0;
glsafe(::glGenVertexArrays(1, &vao_id));
glsafe(::glBindVertexArray(vao_id));
if (OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0)) {
glsafe(::glGenVertexArrays(1, &vao_id));
glsafe(::glBindVertexArray(vao_id));
}
#endif // ENABLE_GL_CORE_PROFILE
GLuint vbo_id = 0;
@ -2076,9 +2078,10 @@ void GCodeViewer::load_toolpaths(const GCodeProcessorResult& gcode_result)
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0));
#if ENABLE_GL_CORE_PROFILE
glsafe(::glBindVertexArray(0));
t_buffer.vertices.vaos.push_back(static_cast<unsigned int>(vao_id));
if (OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0)) {
glsafe(::glBindVertexArray(0));
t_buffer.vertices.vaos.push_back(static_cast<unsigned int>(vao_id));
}
#endif // ENABLE_GL_CORE_PROFILE
t_buffer.vertices.vbos.push_back(static_cast<unsigned int>(vbo_id));
t_buffer.vertices.sizes.push_back(size_bytes);
@ -2160,10 +2163,11 @@ void GCodeViewer::load_toolpaths(const GCodeProcessorResult& gcode_result)
if (i_multibuffer.empty()) {
i_multibuffer.push_back(IndexBuffer());
#if ENABLE_GL_CORE_PROFILE
if (!t_buffer.vertices.vaos.empty()) {
if (!t_buffer.vertices.vaos.empty() && OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0))
vao_index_list.push_back(t_buffer.vertices.vaos[curr_vertex_buffer.first]);
if (!t_buffer.vertices.vbos.empty())
vbo_index_list.push_back(t_buffer.vertices.vbos[curr_vertex_buffer.first]);
}
#else
if (!t_buffer.vertices.vbos.empty())
vbo_index_list.push_back(t_buffer.vertices.vbos[curr_vertex_buffer.first]);
@ -2176,7 +2180,8 @@ void GCodeViewer::load_toolpaths(const GCodeProcessorResult& gcode_result)
if (i_multibuffer.back().size() * sizeof(IBufferType) >= IBUFFER_THRESHOLD_BYTES - indiced_size_to_add) {
i_multibuffer.push_back(IndexBuffer());
#if ENABLE_GL_CORE_PROFILE
vao_index_list.push_back(t_buffer.vertices.vaos[curr_vertex_buffer.first]);
if (OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0))
vao_index_list.push_back(t_buffer.vertices.vaos[curr_vertex_buffer.first]);
#endif // ENABLE_GL_CORE_PROFILE
vbo_index_list.push_back(t_buffer.vertices.vbos[curr_vertex_buffer.first]);
if (t_buffer.render_primitive_type != TBuffer::ERenderPrimitiveType::BatchedModel) {
@ -2194,7 +2199,8 @@ void GCodeViewer::load_toolpaths(const GCodeProcessorResult& gcode_result)
++curr_vertex_buffer.first;
curr_vertex_buffer.second = 0;
#if ENABLE_GL_CORE_PROFILE
vao_index_list.push_back(t_buffer.vertices.vaos[curr_vertex_buffer.first]);
if (OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0))
vao_index_list.push_back(t_buffer.vertices.vaos[curr_vertex_buffer.first]);
#endif // ENABLE_GL_CORE_PROFILE
vbo_index_list.push_back(t_buffer.vertices.vbos[curr_vertex_buffer.first]);
@ -2254,7 +2260,8 @@ void GCodeViewer::load_toolpaths(const GCodeProcessorResult& gcode_result)
IBuffer& ibuf = t_buffer.indices.back();
ibuf.count = size_elements;
#if ENABLE_GL_CORE_PROFILE
ibuf.vao = vao_indices[i][t_buffer.indices.size() - 1];
if (OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0))
ibuf.vao = vao_indices[i][t_buffer.indices.size() - 1];
#endif // ENABLE_GL_CORE_PROFILE
ibuf.vbo = vbo_indices[i][t_buffer.indices.size() - 1];
@ -2886,7 +2893,8 @@ void GCodeViewer::refresh_render_paths(bool keep_sequential_current_first, bool
const IBuffer& i_buffer = buffer.indices[ibuffer_id];
cap.buffer = &buffer;
#if ENABLE_GL_CORE_PROFILE
cap.vao = i_buffer.vao;
if (OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0))
cap.vao = i_buffer.vao;
#endif // ENABLE_GL_CORE_PROFILE
cap.vbo = i_buffer.vbo;
@ -2934,7 +2942,8 @@ void GCodeViewer::refresh_render_paths(bool keep_sequential_current_first, bool
const IBuffer& i_buffer = buffer.indices[ibuffer_id];
cap.buffer = &buffer;
#if ENABLE_GL_CORE_PROFILE
cap.vao = i_buffer.vao;
if (OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0))
cap.vao = i_buffer.vao;
#endif // ENABLE_GL_CORE_PROFILE
cap.vbo = i_buffer.vbo;
@ -3113,7 +3122,8 @@ void GCodeViewer::render_toolpaths()
const IBuffer& i_buffer = buffer.indices[j];
buffer_range.last = buffer_range.first + i_buffer.count / indices_per_instance;
#if ENABLE_GL_CORE_PROFILE
glsafe(::glBindVertexArray(i_buffer.vao));
if (OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0))
glsafe(::glBindVertexArray(i_buffer.vao));
#endif // ENABLE_GL_CORE_PROFILE
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, i_buffer.vbo));
#if ENABLE_LEGACY_OPENGL_REMOVAL
@ -3172,7 +3182,8 @@ void GCodeViewer::render_toolpaths()
#endif // ENABLE_LEGACY_OPENGL_REMOVAL
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0));
#if ENABLE_GL_CORE_PROFILE
glsafe(::glBindVertexArray(0));
if (OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0))
glsafe(::glBindVertexArray(0));
#endif // ENABLE_GL_CORE_PROFILE
buffer_range.first = buffer_range.last;
@ -3239,7 +3250,8 @@ void GCodeViewer::render_toolpaths()
continue;
#if ENABLE_GL_CORE_PROFILE
glsafe(::glBindVertexArray(i_buffer.vao));
if (OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0))
glsafe(::glBindVertexArray(i_buffer.vao));
#endif // ENABLE_GL_CORE_PROFILE
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, i_buffer.vbo));
#if ENABLE_LEGACY_OPENGL_REMOVAL
@ -3301,7 +3313,8 @@ void GCodeViewer::render_toolpaths()
#endif // ENABLE_LEGACY_OPENGL_REMOVAL
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0));
#if ENABLE_GL_CORE_PROFILE
glsafe(::glBindVertexArray(0));
if (OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0))
glsafe(::glBindVertexArray(0));
#endif // ENABLE_GL_CORE_PROFILE
}
}
@ -3332,7 +3345,8 @@ void GCodeViewer::render_toolpaths()
#endif // ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_GL_CORE_PROFILE
glsafe(::glBindVertexArray(cap.vao));
if (OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0))
glsafe(::glBindVertexArray(cap.vao));
#endif // ENABLE_GL_CORE_PROFILE
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, cap.vbo));
#if ENABLE_LEGACY_OPENGL_REMOVAL
@ -3381,7 +3395,8 @@ void GCodeViewer::render_toolpaths()
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0));
#if ENABLE_GL_CORE_PROFILE
glsafe(::glBindVertexArray(0));
if (OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0))
glsafe(::glBindVertexArray(0));
#endif // ENABLE_GL_CORE_PROFILE
shader->stop_using();

View file

@ -364,11 +364,7 @@ class GCodeViewer
{
case ERenderPrimitiveType::Line:
case ERenderPrimitiveType::Triangle: {
#if ENABLE_GL_CORE_PROFILE
return !vertices.vaos.empty() && vertices.vaos.front() != 0 && !indices.empty() && indices.front().ibo != 0;
#else
return !vertices.vbos.empty() && vertices.vbos.front() != 0 && !indices.empty() && indices.front().ibo != 0;
#endif // ENABLE_GL_CORE_PROFILE
}
case ERenderPrimitiveType::InstancedModel: { return model.model.is_initialized() && !model.instances.buffer.empty(); }
case ERenderPrimitiveType::BatchedModel: {
@ -377,11 +373,7 @@ class GCodeViewer
#else
return model.data.vertices_count() > 0 && model.data.indices_count() &&
#endif // ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_GL_CORE_PROFILE
!vertices.vaos.empty() && vertices.vaos.front() != 0 && !indices.empty() && indices.front().ibo != 0;
#else
!vertices.vbos.empty() && vertices.vbos.front() != 0 && !indices.empty() && indices.front().ibo != 0;
#endif // ENABLE_GL_CORE_PROFILE
}
default: { return false; }
}

View file

@ -124,8 +124,8 @@ void GLCanvas3D::LayersEditing::init()
glsafe(::glGenTextures(1, (GLuint*)&m_z_texture_id));
glsafe(::glBindTexture(GL_TEXTURE_2D, m_z_texture_id));
if (!OpenGLManager::get_gl_info().is_core_profile() || !OpenGLManager::get_gl_info().is_mesa()) {
glsafe(::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP));
glsafe(::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP));
glsafe(::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
glsafe(::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
}
glsafe(::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
glsafe(::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST));

View file

@ -853,11 +853,7 @@ void GLModel::render(const std::pair<size_t, size_t>& range)
return;
// sends data to gpu if not done yet
#if ENABLE_GL_CORE_PROFILE
if (m_render_data.vao_id == 0) {
#else
if (m_render_data.vbo_id == 0 || m_render_data.ibo_id == 0) {
#endif // ENABLE_GL_CORE_PROFILE
if (m_render_data.geometry.vertices_count() > 0 && m_render_data.geometry.indices_count() > 0 && !send_to_gpu())
return;
}
@ -873,7 +869,8 @@ void GLModel::render(const std::pair<size_t, size_t>& range)
const bool tex_coord = Geometry::has_tex_coord(data.format);
#if ENABLE_GL_CORE_PROFILE
glsafe(::glBindVertexArray(m_render_data.vao_id));
if (OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0))
glsafe(::glBindVertexArray(m_render_data.vao_id));
// the following binding is needed to set the vertex attributes
#endif // ENABLE_GL_CORE_PROFILE
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, m_render_data.vbo_id));
@ -906,9 +903,10 @@ void GLModel::render(const std::pair<size_t, size_t>& range)
shader->set_uniform("uniform_color", data.color);
#if !ENABLE_GL_CORE_PROFILE
glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_render_data.ibo_id));
#endif // !ENABLE_GL_CORE_PROFILE
#if ENABLE_GL_CORE_PROFILE
if (!OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0))
#endif // ENABLE_GL_CORE_PROFILE
glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_render_data.ibo_id));
glsafe(::glDrawElements(mode, range.second - range.first, index_type, (const void*)(range.first * Geometry::index_stride_bytes(data))));
#if !ENABLE_GL_CORE_PROFILE
glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0));
@ -923,7 +921,8 @@ void GLModel::render(const std::pair<size_t, size_t>& range)
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0));
#if ENABLE_GL_CORE_PROFILE
glsafe(::glBindVertexArray(0));
if (OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0))
glsafe(::glBindVertexArray(0));
#endif // ENABLE_GL_CORE_PROFILE
#if ENABLE_GLMODEL_STATISTICS
@ -958,11 +957,7 @@ void GLModel::render_instanced(unsigned int instances_vbo, unsigned int instance
if (offset_id == -1 || scales_id == -1)
return;
#if ENABLE_GL_CORE_PROFILE
if (m_render_data.vao_id == 0) {
#else
if (m_render_data.vbo_id == 0 || m_render_data.ibo_id == 0) {
#endif // ENABLE_GL_CORE_PROFILE
if (!send_to_gpu())
return;
}
@ -981,7 +976,8 @@ void GLModel::render_instanced(unsigned int instances_vbo, unsigned int instance
#endif // ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_GL_CORE_PROFILE
glsafe(::glBindVertexArray(m_render_data.vao_id));
if (OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0))
glsafe(::glBindVertexArray(m_render_data.vao_id));
#endif // ENABLE_GL_CORE_PROFILE
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, instances_vbo));
@ -1097,7 +1093,8 @@ void GLModel::render_instanced(unsigned int instances_vbo, unsigned int instance
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0));
#if ENABLE_GL_CORE_PROFILE
glsafe(::glBindVertexArray(0));
if (OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0))
glsafe(::glBindVertexArray(0));
#endif // ENABLE_GL_CORE_PROFILE
#if ENABLE_GLMODEL_STATISTICS
@ -1120,8 +1117,10 @@ bool GLModel::send_to_gpu()
}
#if ENABLE_GL_CORE_PROFILE
glsafe(::glGenVertexArrays(1, &m_render_data.vao_id));
glsafe(::glBindVertexArray(m_render_data.vao_id));
if (OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0)) {
glsafe(::glGenVertexArrays(1, &m_render_data.vao_id));
glsafe(::glBindVertexArray(m_render_data.vao_id));
}
#endif // ENABLE_GL_CORE_PROFILE
// vertices
@ -1163,9 +1162,11 @@ bool GLModel::send_to_gpu()
glsafe(::glBufferData(GL_ELEMENT_ARRAY_BUFFER, data.indices_size_bytes(), data.indices.data(), GL_STATIC_DRAW));
}
#if !ENABLE_GL_CORE_PROFILE
glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0));
#endif // !ENABLE_GL_CORE_PROFILE
#if ENABLE_GL_CORE_PROFILE
if (!OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0))
#endif // ENABLE_GL_CORE_PROFILE
glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0));
m_render_data.indices_count = indices_count;
#if ENABLE_GLMODEL_STATISTICS
s_statistics.gpu_memory.indices.current += data.indices_size_bytes();
@ -1174,7 +1175,8 @@ bool GLModel::send_to_gpu()
data.indices = std::vector<unsigned int>();
#if ENABLE_GL_CORE_PROFILE
glsafe(::glBindVertexArray(0));
if (OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0))
glsafe(::glBindVertexArray(0));
#endif // ENABLE_GL_CORE_PROFILE
return true;

View file

@ -847,11 +847,6 @@ std::string GUI_App::get_gl_info(bool for_github)
wxGLContext* GUI_App::init_glcontext(wxGLCanvas& canvas)
{
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
if (init_params != nullptr)
std::cout << "GUI_App::init_glcontext(): required OpenGL version: " << init_params->opengl_version.first << "." << init_params->opengl_version.second << "\n";
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#if ENABLE_GL_CORE_PROFILE
#if ENABLE_OPENGL_DEBUG_OPTION
return m_opengl_mgr.init_glcontext(canvas, init_params != nullptr ? init_params->opengl_version : std::make_pair(0, 0),

View file

@ -53,11 +53,6 @@ int GUI_Run(GUI_InitParams &params)
// gui->autosave = m_config.opt_string("autosave");
GUI::GUI_App::SetInstance(gui);
gui->init_params = &params;
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
std::cout << "GUI_Run(): required OpenGL version: " << gui->init_params->opengl_version.first << "." << gui->init_params->opengl_version.second << "\n";
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
return wxEntry(params.argc, params.argv);
} catch (const Slic3r::Exception &ex) {
boost::nowide::cerr << ex.what() << std::endl;

View file

@ -709,7 +709,7 @@ void GLMmSegmentationGizmo3DScene::release_geometry() {
triangle_indices_VBO_id = 0;
}
#if ENABLE_GL_CORE_PROFILE
if (this->vertices_VAO_id) {
if (this->vertices_VAO_id > 0) {
glsafe(::glDeleteVertexArrays(1, &this->vertices_VAO_id));
this->vertices_VAO_id = 0;
}
@ -723,7 +723,8 @@ void GLMmSegmentationGizmo3DScene::render(size_t triangle_indices_idx) const
assert(triangle_indices_idx < this->triangle_indices_VBO_ids.size());
assert(this->triangle_indices_sizes.size() == this->triangle_indices_VBO_ids.size());
#if ENABLE_GL_CORE_PROFILE
assert(this->vertices_VAO_id != 0);
if (OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0))
assert(this->vertices_VAO_id != 0);
#endif // ENABLE_GL_CORE_PROFILE
assert(this->vertices_VBO_id != 0);
assert(this->triangle_indices_VBO_ids[triangle_indices_idx] != 0);
@ -735,7 +736,8 @@ void GLMmSegmentationGizmo3DScene::render(size_t triangle_indices_idx) const
#endif // ENABLE_LEGACY_OPENGL_REMOVAL
#if ENABLE_GL_CORE_PROFILE
glsafe(::glBindVertexArray(this->vertices_VAO_id));
if (OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0))
glsafe(::glBindVertexArray(this->vertices_VAO_id));
// the following binding is needed to set the vertex attributes
#endif // ENABLE_GL_CORE_PROFILE
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, this->vertices_VBO_id));
@ -770,20 +772,23 @@ void GLMmSegmentationGizmo3DScene::render(size_t triangle_indices_idx) const
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0));
#if ENABLE_GL_CORE_PROFILE
glsafe(::glBindVertexArray(0));
if (OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0))
glsafe(::glBindVertexArray(0));
#endif // ENABLE_GL_CORE_PROFILE
}
void GLMmSegmentationGizmo3DScene::finalize_vertices()
{
#if ENABLE_GL_CORE_PROFILE
assert(this->vertices_VAO_id == 0);
assert(this->vertices_VAO_id == 0);
#endif // ENABLE_GL_CORE_PROFILE
assert(this->vertices_VBO_id == 0);
if (!this->vertices.empty()) {
#if ENABLE_GL_CORE_PROFILE
glsafe(::glGenVertexArrays(1, &this->vertices_VAO_id));
glsafe(::glBindVertexArray(this->vertices_VAO_id));
if (OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0)) {
glsafe(::glGenVertexArrays(1, &this->vertices_VAO_id));
glsafe(::glBindVertexArray(this->vertices_VAO_id));
}
#endif // ENABLE_GL_CORE_PROFILE
glsafe(::glGenBuffers(1, &this->vertices_VBO_id));
@ -793,6 +798,7 @@ void GLMmSegmentationGizmo3DScene::finalize_vertices()
this->vertices.clear();
#if ENABLE_GL_CORE_PROFILE
if (OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0))
glsafe(::glBindVertexArray(0));
#endif // ENABLE_GL_CORE_PROFILE
}

View file

@ -1486,7 +1486,9 @@ void ImGuiWrapper::render_draw_data(ImDrawData *draw_data)
GLuint last_program; glsafe(::glGetIntegerv(GL_CURRENT_PROGRAM, (GLint*)&last_program));
GLuint last_texture; glsafe(::glGetIntegerv(GL_TEXTURE_BINDING_2D, (GLint*)&last_texture));
GLuint last_array_buffer; glsafe(::glGetIntegerv(GL_ARRAY_BUFFER_BINDING, (GLint*)&last_array_buffer));
GLuint last_vertex_array_object; glsafe(::glGetIntegerv(GL_VERTEX_ARRAY_BINDING, (GLint*)&last_vertex_array_object));
GLuint last_vertex_array_object = 0;
if (OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0))
glsafe(::glGetIntegerv(GL_VERTEX_ARRAY_BINDING, (GLint*)&last_vertex_array_object));
GLint last_viewport[4]; glsafe(::glGetIntegerv(GL_VIEWPORT, last_viewport));
GLint last_scissor_box[4]; glsafe(::glGetIntegerv(GL_SCISSOR_BOX, last_scissor_box));
GLenum last_blend_src_rgb; glsafe(::glGetIntegerv(GL_BLEND_SRC_RGB, (GLint*)&last_blend_src_rgb));
@ -1583,8 +1585,10 @@ void ImGuiWrapper::render_draw_data(ImDrawData *draw_data)
#if ENABLE_GL_CORE_PROFILE
GLuint vao_id = 0;
glsafe(::glGenVertexArrays(1, &vao_id));
glsafe(::glBindVertexArray(vao_id));
if (OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0)) {
glsafe(::glGenVertexArrays(1, &vao_id));
glsafe(::glBindVertexArray(vao_id));
}
#endif // ENABLE_GL_CORE_PROFILE
GLuint vbo_id;
@ -1669,6 +1673,7 @@ void ImGuiWrapper::render_draw_data(ImDrawData *draw_data)
glsafe(::glDeleteBuffers(1, &ibo_id));
glsafe(::glDeleteBuffers(1, &vbo_id));
#if ENABLE_GL_CORE_PROFILE
if (vao_id > 0)
glsafe(::glDeleteVertexArrays(1, &vao_id));
#endif // ENABLE_GL_CORE_PROFILE
#endif // ENABLE_LEGACY_OPENGL_REMOVAL
@ -1678,7 +1683,8 @@ void ImGuiWrapper::render_draw_data(ImDrawData *draw_data)
// Restore modified GL state
glsafe(::glBindTexture(GL_TEXTURE_2D, last_texture));
glsafe(::glActiveTexture(last_active_texture));
glsafe(::glBindVertexArray(last_vertex_array_object));
if (OpenGLManager::get_gl_info().is_version_greater_or_equal_to(3, 0))
glsafe(::glBindVertexArray(last_vertex_array_object));
glsafe(::glBindBuffer(GL_ARRAY_BUFFER, last_array_buffer));
glsafe(::glBlendEquationSeparate(last_blend_equation_rgb, last_blend_equation_alpha));
glsafe(::glBlendFuncSeparate(last_blend_src_rgb, last_blend_dst_rgb, last_blend_src_alpha, last_blend_dst_alpha));

View file

@ -363,6 +363,7 @@ bool OpenGLManager::init_gl()
#else
bool valid_version = s_gl_info.is_version_greater_or_equal_to(2, 0);
#endif // ENABLE_GL_CORE_PROFILE
if (!valid_version) {
// Complain about the OpenGL version.
wxString message = from_u8((boost::format(
@ -420,10 +421,6 @@ wxGLContext* OpenGLManager::init_glcontext(wxGLCanvas& canvas)
m_debug_enabled = enable_debug;
#endif // ENABLE_OPENGL_DEBUG_OPTION
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
std::cout << "OpenGLManager::init_glcontext(): required OpenGL version: " << required_opengl_version.first << "." << required_opengl_version.second << "\n";
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
if (required_opengl_version != std::make_pair(0, 0)) { // the user specified a required version in the command line using --opengl-core=M.m
const bool supports_core_profile = (required_opengl_version.first < 3) ? false :
(required_opengl_version.first > 3) ? true : required_opengl_version.second >= 2;
@ -445,7 +442,9 @@ wxGLContext* OpenGLManager::init_glcontext(wxGLCanvas& canvas)
delete m_context;
m_context = nullptr;
}
}
else
s_gl_info.set_core_profile(true);
}
}
//else {
// // try to get the highest supported OpenGL version with core profile
@ -467,30 +466,12 @@ wxGLContext* OpenGLManager::init_glcontext(wxGLCanvas& canvas)
#if ENABLE_OPENGL_DEBUG_OPTION
if (m_context == nullptr) {
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
wxGLContextAttrs attrs;
if (m_debug_enabled)
attrs.DebugCtx();
attrs.EndList();
// if no valid context was created use the default one
if (m_debug_enabled) {
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
std::cout << "OpenGLManager::init_glcontext(): create debug compatibility profile (" << required_opengl_version.first << "." << required_opengl_version.second << ")\n";
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
wxGLContextAttrs attrs;
attrs.DebugCtx().EndList();
m_context = new wxGLContext(&canvas, nullptr, &attrs);
}
else {
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
std::cout << "OpenGLManager::init_glcontext(): create compatibility profile (" << required_opengl_version.first << "." << required_opengl_version.second << ")\n";
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
m_context = new wxGLContext(&canvas);
}
// wxGLContextAttrs attrs;
// 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);
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
m_context = new wxGLContext(&canvas, nullptr, &attrs);
}
#else
if (m_context == nullptr)

View file

@ -27,6 +27,7 @@ public:
class GLInfo
{
bool m_detected{ false };
bool m_core_profile{ false };
int m_max_tex_size{ 0 };
float m_max_anisotropy{ 0.0f };
@ -44,6 +45,8 @@ public:
const std::string& get_renderer() const;
bool is_core_profile() const;
void set_core_profile(bool value) { m_core_profile = value; }
bool is_mesa() const;
int get_max_tex_size() const;