From d795f07e7b8d4096d5b06ffae88c13f766b619cf Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Wed, 27 Mar 2019 14:42:09 +0100 Subject: [PATCH] Added glsafe() around OpenGL calls where missing --- src/slic3r/GUI/3DBed.cpp | 9 +- src/slic3r/GUI/3DScene.cpp | 132 ++++---- src/slic3r/GUI/3DScene.hpp | 1 + src/slic3r/GUI/GLCanvas3D.cpp | 309 ++++++++++--------- src/slic3r/GUI/GLShader.cpp | 62 ++-- src/slic3r/GUI/GLTexture.cpp | 82 ++--- src/slic3r/GUI/GLToolbar.cpp | 8 +- src/slic3r/GUI/Gizmos/GLGizmoBase.cpp | 66 ++-- src/slic3r/GUI/Gizmos/GLGizmoCut.cpp | 24 +- src/slic3r/GUI/Gizmos/GLGizmoFlatten.cpp | 42 +-- src/slic3r/GUI/Gizmos/GLGizmoMove.cpp | 34 +- src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp | 76 ++--- src/slic3r/GUI/Gizmos/GLGizmoScale.cpp | 26 +- src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp | 94 +++--- src/slic3r/GUI/ImGuiWrapper.cpp | 113 +++---- 15 files changed, 544 insertions(+), 534 deletions(-) diff --git a/src/slic3r/GUI/3DBed.cpp b/src/slic3r/GUI/3DBed.cpp index 236793814..05f4fd8fd 100644 --- a/src/slic3r/GUI/3DBed.cpp +++ b/src/slic3r/GUI/3DBed.cpp @@ -495,11 +495,11 @@ void Bed3D::render_prusa(const std::string &key, bool bottom) const // use anisotropic filter if graphic card allows GLfloat max_anisotropy = 0.0f; if (glewIsSupported("GL_EXT_texture_filter_anisotropic")) - ::glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &max_anisotropy); + glsafe(::glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &max_anisotropy)); // use higher resolution images if graphic card allows GLint max_tex_size; - ::glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_tex_size); + glsafe(::glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_tex_size)); // clamp or the texture generation becomes too slow max_tex_size = std::min(max_tex_size, 8192); @@ -621,7 +621,6 @@ void Bed3D::render_prusa_shader(bool transparent) const m_shader.stop_using(); } } - #else void Bed3D::render_prusa(const std::string &key, float theta, bool useVBOs) const { @@ -629,7 +628,7 @@ void Bed3D::render_prusa(const std::string &key, float theta, bool useVBOs) cons // use higher resolution images if graphic card allows GLint max_tex_size; - ::glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_tex_size); + glsafe(::glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_tex_size)); // temporary set to lowest resolution max_tex_size = 2048; @@ -644,7 +643,7 @@ void Bed3D::render_prusa(const std::string &key, float theta, bool useVBOs) cons // use anisotropic filter if graphic card allows GLfloat max_anisotropy = 0.0f; if (glewIsSupported("GL_EXT_texture_filter_anisotropic")) - ::glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &max_anisotropy); + glsafe(::glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &max_anisotropy)); std::string filename = tex_path + "_top.png"; if ((m_top_texture.get_id() == 0) || (m_top_texture.get_source() != filename)) diff --git a/src/slic3r/GUI/3DScene.cpp b/src/slic3r/GUI/3DScene.cpp index c845ca4b4..aafc3215a 100644 --- a/src/slic3r/GUI/3DScene.cpp +++ b/src/slic3r/GUI/3DScene.cpp @@ -99,25 +99,25 @@ void GLIndexedVertexArray::finalize_geometry(bool use_VBOs) if (use_VBOs) { if (! empty()) { - glsafe(glGenBuffers(1, &this->vertices_and_normals_interleaved_VBO_id)); - glsafe(glBindBuffer(GL_ARRAY_BUFFER, this->vertices_and_normals_interleaved_VBO_id)); - glsafe(glBufferData(GL_ARRAY_BUFFER, this->vertices_and_normals_interleaved.size() * 4, this->vertices_and_normals_interleaved.data(), GL_STATIC_DRAW)); - glsafe(glBindBuffer(GL_ARRAY_BUFFER, 0)); + glsafe(::glGenBuffers(1, &this->vertices_and_normals_interleaved_VBO_id)); + glsafe(::glBindBuffer(GL_ARRAY_BUFFER, this->vertices_and_normals_interleaved_VBO_id)); + glsafe(::glBufferData(GL_ARRAY_BUFFER, this->vertices_and_normals_interleaved.size() * 4, this->vertices_and_normals_interleaved.data(), GL_STATIC_DRAW)); + glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); this->vertices_and_normals_interleaved.clear(); } if (! this->triangle_indices.empty()) { - glsafe(glGenBuffers(1, &this->triangle_indices_VBO_id)); - glsafe(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this->triangle_indices_VBO_id)); - glsafe(glBufferData(GL_ELEMENT_ARRAY_BUFFER, this->triangle_indices.size() * 4, this->triangle_indices.data(), GL_STATIC_DRAW)); + glsafe(::glGenBuffers(1, &this->triangle_indices_VBO_id)); + glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this->triangle_indices_VBO_id)); + glsafe(::glBufferData(GL_ELEMENT_ARRAY_BUFFER, this->triangle_indices.size() * 4, this->triangle_indices.data(), GL_STATIC_DRAW)); this->triangle_indices.clear(); } if (! this->quad_indices.empty()) { - glsafe(glGenBuffers(1, &this->quad_indices_VBO_id)); - glsafe(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this->quad_indices_VBO_id)); - glsafe(glBufferData(GL_ELEMENT_ARRAY_BUFFER, this->quad_indices.size() * 4, this->quad_indices.data(), GL_STATIC_DRAW)); + glsafe(::glGenBuffers(1, &this->quad_indices_VBO_id)); + glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this->quad_indices_VBO_id)); + glsafe(::glBufferData(GL_ELEMENT_ARRAY_BUFFER, this->quad_indices.size() * 4, this->quad_indices.data(), GL_STATIC_DRAW)); this->quad_indices.clear(); } - glsafe(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); + glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); } this->shrink_to_fit(); } @@ -125,15 +125,15 @@ void GLIndexedVertexArray::finalize_geometry(bool use_VBOs) void GLIndexedVertexArray::release_geometry() { if (this->vertices_and_normals_interleaved_VBO_id) { - glsafe(glDeleteBuffers(1, &this->vertices_and_normals_interleaved_VBO_id)); + glsafe(::glDeleteBuffers(1, &this->vertices_and_normals_interleaved_VBO_id)); this->vertices_and_normals_interleaved_VBO_id = 0; } if (this->triangle_indices_VBO_id) { - glsafe(glDeleteBuffers(1, &this->triangle_indices_VBO_id)); + glsafe(::glDeleteBuffers(1, &this->triangle_indices_VBO_id)); this->triangle_indices_VBO_id = 0; } if (this->quad_indices_VBO_id) { - glsafe(glDeleteBuffers(1, &this->quad_indices_VBO_id)); + glsafe(::glDeleteBuffers(1, &this->quad_indices_VBO_id)); this->quad_indices_VBO_id = 0; } this->clear(); @@ -143,42 +143,42 @@ void GLIndexedVertexArray::release_geometry() void GLIndexedVertexArray::render() const { if (this->vertices_and_normals_interleaved_VBO_id) { - glsafe(glBindBuffer(GL_ARRAY_BUFFER, this->vertices_and_normals_interleaved_VBO_id)); - glsafe(glVertexPointer(3, GL_FLOAT, 6 * sizeof(float), (const void*)(3 * sizeof(float)))); - glsafe(glNormalPointer(GL_FLOAT, 6 * sizeof(float), nullptr)); + glsafe(::glBindBuffer(GL_ARRAY_BUFFER, this->vertices_and_normals_interleaved_VBO_id)); + glsafe(::glVertexPointer(3, GL_FLOAT, 6 * sizeof(float), (const void*)(3 * sizeof(float)))); + glsafe(::glNormalPointer(GL_FLOAT, 6 * sizeof(float), nullptr)); } else { - glsafe(glVertexPointer(3, GL_FLOAT, 6 * sizeof(float), this->vertices_and_normals_interleaved.data() + 3)); - glsafe(glNormalPointer(GL_FLOAT, 6 * sizeof(float), this->vertices_and_normals_interleaved.data())); + glsafe(::glVertexPointer(3, GL_FLOAT, 6 * sizeof(float), this->vertices_and_normals_interleaved.data() + 3)); + glsafe(::glNormalPointer(GL_FLOAT, 6 * sizeof(float), this->vertices_and_normals_interleaved.data())); } - glsafe(glEnableClientState(GL_VERTEX_ARRAY)); - glsafe(glEnableClientState(GL_NORMAL_ARRAY)); + glsafe(::glEnableClientState(GL_VERTEX_ARRAY)); + glsafe(::glEnableClientState(GL_NORMAL_ARRAY)); if (this->indexed()) { if (this->vertices_and_normals_interleaved_VBO_id) { // Render using the Vertex Buffer Objects. if (this->triangle_indices_size > 0) { - glsafe(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this->triangle_indices_VBO_id)); - glsafe(glDrawElements(GL_TRIANGLES, GLsizei(this->triangle_indices_size), GL_UNSIGNED_INT, nullptr)); + glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this->triangle_indices_VBO_id)); + glsafe(::glDrawElements(GL_TRIANGLES, GLsizei(this->triangle_indices_size), GL_UNSIGNED_INT, nullptr)); } if (this->quad_indices_size > 0) { - glsafe(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this->quad_indices_VBO_id)); - glsafe(glDrawElements(GL_QUADS, GLsizei(this->quad_indices_size), GL_UNSIGNED_INT, nullptr)); + glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this->quad_indices_VBO_id)); + glsafe(::glDrawElements(GL_QUADS, GLsizei(this->quad_indices_size), GL_UNSIGNED_INT, nullptr)); } glsafe(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); } else { // Render in an immediate mode. if (! this->triangle_indices.empty()) - glsafe(glDrawElements(GL_TRIANGLES, GLsizei(this->triangle_indices_size), GL_UNSIGNED_INT, this->triangle_indices.data())); + glsafe(::glDrawElements(GL_TRIANGLES, GLsizei(this->triangle_indices_size), GL_UNSIGNED_INT, this->triangle_indices.data())); if (! this->quad_indices.empty()) - glsafe(glDrawElements(GL_QUADS, GLsizei(this->quad_indices_size), GL_UNSIGNED_INT, this->quad_indices.data())); + glsafe(::glDrawElements(GL_QUADS, GLsizei(this->quad_indices_size), GL_UNSIGNED_INT, this->quad_indices.data())); } } else - glsafe(glDrawArrays(GL_TRIANGLES, 0, GLsizei(this->vertices_and_normals_interleaved_size / 6))); + glsafe(::glDrawArrays(GL_TRIANGLES, 0, GLsizei(this->vertices_and_normals_interleaved_size / 6))); if (this->vertices_and_normals_interleaved_VBO_id) - glsafe(glBindBuffer(GL_ARRAY_BUFFER, 0)); - glsafe(glDisableClientState(GL_VERTEX_ARRAY)); - glsafe(glDisableClientState(GL_NORMAL_ARRAY)); + glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); + glsafe(::glDisableClientState(GL_VERTEX_ARRAY)); + glsafe(::glDisableClientState(GL_NORMAL_ARRAY)); } void GLIndexedVertexArray::render( @@ -191,35 +191,35 @@ void GLIndexedVertexArray::render( if (this->vertices_and_normals_interleaved_VBO_id) { // Render using the Vertex Buffer Objects. - glsafe(glBindBuffer(GL_ARRAY_BUFFER, this->vertices_and_normals_interleaved_VBO_id)); - glsafe(glVertexPointer(3, GL_FLOAT, 6 * sizeof(float), (const void*)(3 * sizeof(float)))); - glsafe(glNormalPointer(GL_FLOAT, 6 * sizeof(float), nullptr)); - glsafe(glEnableClientState(GL_VERTEX_ARRAY)); - glsafe(glEnableClientState(GL_NORMAL_ARRAY)); + glsafe(::glBindBuffer(GL_ARRAY_BUFFER, this->vertices_and_normals_interleaved_VBO_id)); + glsafe(::glVertexPointer(3, GL_FLOAT, 6 * sizeof(float), (const void*)(3 * sizeof(float)))); + glsafe(::glNormalPointer(GL_FLOAT, 6 * sizeof(float), nullptr)); + glsafe(::glEnableClientState(GL_VERTEX_ARRAY)); + glsafe(::glEnableClientState(GL_NORMAL_ARRAY)); if (this->triangle_indices_size > 0) { - glsafe(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this->triangle_indices_VBO_id)); - glsafe(glDrawElements(GL_TRIANGLES, GLsizei(std::min(this->triangle_indices_size, tverts_range.second - tverts_range.first)), GL_UNSIGNED_INT, (const void*)(tverts_range.first * 4))); + glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this->triangle_indices_VBO_id)); + glsafe(::glDrawElements(GL_TRIANGLES, GLsizei(std::min(this->triangle_indices_size, tverts_range.second - tverts_range.first)), GL_UNSIGNED_INT, (const void*)(tverts_range.first * 4))); } if (this->quad_indices_size > 0) { - glsafe(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this->quad_indices_VBO_id)); - glsafe(glDrawElements(GL_QUADS, GLsizei(std::min(this->quad_indices_size, qverts_range.second - qverts_range.first)), GL_UNSIGNED_INT, (const void*)(qverts_range.first * 4))); + glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this->quad_indices_VBO_id)); + glsafe(::glDrawElements(GL_QUADS, GLsizei(std::min(this->quad_indices_size, qverts_range.second - qverts_range.first)), GL_UNSIGNED_INT, (const void*)(qverts_range.first * 4))); } - glsafe(glBindBuffer(GL_ARRAY_BUFFER, 0)); - glsafe(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); + glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); + glsafe(::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)); } else { // Render in an immediate mode. - glsafe(glVertexPointer(3, GL_FLOAT, 6 * sizeof(float), this->vertices_and_normals_interleaved.data() + 3)); - glsafe(glNormalPointer(GL_FLOAT, 6 * sizeof(float), this->vertices_and_normals_interleaved.data())); - glsafe(glEnableClientState(GL_VERTEX_ARRAY)); - glsafe(glEnableClientState(GL_NORMAL_ARRAY)); + glsafe(::glVertexPointer(3, GL_FLOAT, 6 * sizeof(float), this->vertices_and_normals_interleaved.data() + 3)); + glsafe(::glNormalPointer(GL_FLOAT, 6 * sizeof(float), this->vertices_and_normals_interleaved.data())); + glsafe(::glEnableClientState(GL_VERTEX_ARRAY)); + glsafe(::glEnableClientState(GL_NORMAL_ARRAY)); if (! this->triangle_indices.empty()) - glsafe(glDrawElements(GL_TRIANGLES, GLsizei(std::min(this->triangle_indices_size, tverts_range.second - tverts_range.first)), GL_UNSIGNED_INT, (const void*)(this->triangle_indices.data() + tverts_range.first))); + glsafe(::glDrawElements(GL_TRIANGLES, GLsizei(std::min(this->triangle_indices_size, tverts_range.second - tverts_range.first)), GL_UNSIGNED_INT, (const void*)(this->triangle_indices.data() + tverts_range.first))); if (! this->quad_indices.empty()) - glsafe(glDrawElements(GL_QUADS, GLsizei(std::min(this->quad_indices_size, qverts_range.second - qverts_range.first)), GL_UNSIGNED_INT, (const void*)(this->quad_indices.data() + qverts_range.first))); + glsafe(::glDrawElements(GL_QUADS, GLsizei(std::min(this->quad_indices_size, qverts_range.second - qverts_range.first)), GL_UNSIGNED_INT, (const void*)(this->quad_indices.data() + qverts_range.first))); } - glsafe(glDisableClientState(GL_VERTEX_ARRAY)); - glsafe(glDisableClientState(GL_NORMAL_ARRAY)); + glsafe(::glDisableClientState(GL_VERTEX_ARRAY)); + glsafe(::glDisableClientState(GL_NORMAL_ARRAY)); } const float GLVolume::SELECTED_COLOR[4] = { 0.0f, 1.0f, 0.0f, 1.0f }; @@ -761,12 +761,13 @@ void GLVolumeCollection::render_VBOs(GLVolumeCollection::ERenderType type, bool GLint current_program_id; glsafe(::glGetIntegerv(GL_CURRENT_PROGRAM, ¤t_program_id)); - GLint color_id = (current_program_id > 0) ? glGetUniformLocation(current_program_id, "uniform_color") : -1; - GLint z_range_id = (current_program_id > 0) ? glGetUniformLocation(current_program_id, "z_range") : -1; - GLint print_box_min_id = (current_program_id > 0) ? glGetUniformLocation(current_program_id, "print_box.min") : -1; - GLint print_box_max_id = (current_program_id > 0) ? glGetUniformLocation(current_program_id, "print_box.max") : -1; - GLint print_box_detection_id = (current_program_id > 0) ? glGetUniformLocation(current_program_id, "print_box.volume_detection") : -1; - GLint print_box_worldmatrix_id = (current_program_id > 0) ? glGetUniformLocation(current_program_id, "print_box.volume_world_matrix") : -1; + GLint color_id = (current_program_id > 0) ? ::glGetUniformLocation(current_program_id, "uniform_color") : -1; + GLint z_range_id = (current_program_id > 0) ? ::glGetUniformLocation(current_program_id, "z_range") : -1; + GLint print_box_min_id = (current_program_id > 0) ? ::glGetUniformLocation(current_program_id, "print_box.min") : -1; + GLint print_box_max_id = (current_program_id > 0) ? ::glGetUniformLocation(current_program_id, "print_box.max") : -1; + GLint print_box_detection_id = (current_program_id > 0) ? ::glGetUniformLocation(current_program_id, "print_box.volume_detection") : -1; + GLint print_box_worldmatrix_id = (current_program_id > 0) ? ::glGetUniformLocation(current_program_id, "print_box.volume_world_matrix") : -1; + glcheck(); if (print_box_min_id != -1) glsafe(::glUniform3fv(print_box_min_id, 1, (const GLfloat*)print_box_min)); @@ -797,15 +798,15 @@ void GLVolumeCollection::render_VBOs(GLVolumeCollection::ERenderType type, bool void GLVolumeCollection::render_legacy(ERenderType type, bool disable_cullface, std::function filter_func) const { - glsafe(glEnable(GL_BLEND)); - glsafe(glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); + glsafe(::glEnable(GL_BLEND)); + glsafe(::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); - glsafe(glCullFace(GL_BACK)); + glsafe(::glCullFace(GL_BACK)); if (disable_cullface) glsafe(::glDisable(GL_CULL_FACE)); - glsafe(glEnableClientState(GL_VERTEX_ARRAY)); - glsafe(glEnableClientState(GL_NORMAL_ARRAY)); + glsafe(::glEnableClientState(GL_VERTEX_ARRAY)); + glsafe(::glEnableClientState(GL_NORMAL_ARRAY)); GLVolumesWithZList to_render = volumes_to_render(this->volumes, type, filter_func); for (GLVolumeWithZ& volume : to_render) @@ -814,13 +815,13 @@ void GLVolumeCollection::render_legacy(ERenderType type, bool disable_cullface, volume.first->render_legacy(); } - glsafe(glDisableClientState(GL_VERTEX_ARRAY)); - glsafe(glDisableClientState(GL_NORMAL_ARRAY)); + glsafe(::glDisableClientState(GL_VERTEX_ARRAY)); + glsafe(::glDisableClientState(GL_NORMAL_ARRAY)); if (disable_cullface) glsafe(::glEnable(GL_CULL_FACE)); - glsafe(glDisable(GL_BLEND)); + glsafe(::glDisable(GL_BLEND)); } bool GLVolumeCollection::check_outside_state(const DynamicPrintConfig* config, ModelInstance::EPrintVolumeState* out_state) @@ -1749,7 +1750,8 @@ void GLModel::render_VBOs() const GLint current_program_id; glsafe(::glGetIntegerv(GL_CURRENT_PROGRAM, ¤t_program_id)); - GLint color_id = (current_program_id > 0) ? glGetUniformLocation(current_program_id, "uniform_color") : -1; + GLint color_id = (current_program_id > 0) ? ::glGetUniformLocation(current_program_id, "uniform_color") : -1; + glcheck(); m_volume.render_VBOs(color_id, -1, -1); glsafe(::glBindBuffer(GL_ARRAY_BUFFER, 0)); diff --git a/src/slic3r/GUI/3DScene.hpp b/src/slic3r/GUI/3DScene.hpp index e421997e5..fa58ddb50 100644 --- a/src/slic3r/GUI/3DScene.hpp +++ b/src/slic3r/GUI/3DScene.hpp @@ -19,6 +19,7 @@ extern void glAssertRecentCallImpl(const char *file_name, unsigned int line, const char *function_name); inline void glAssertRecentCall() { glAssertRecentCallImpl(__FILE__, __LINE__, __FUNCTION__); } #define glsafe(cmd) do { cmd; glAssertRecentCallImpl(__FILE__, __LINE__, __FUNCTION__); } while (false) +#define glcheck() do { glAssertRecentCallImpl(__FILE__, __LINE__, __FUNCTION__); } while (false) #else inline void glAssertRecentCall() { } #define glsafe(cmd) cmd diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index fe74bb575..9514eaaa8 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -227,7 +227,7 @@ GLCanvas3D::LayersEditing::~LayersEditing() { if (m_z_texture_id != 0) { - ::glDeleteTextures(1, &m_z_texture_id); + glsafe(::glDeleteTextures(1, &m_z_texture_id)); m_z_texture_id = 0; } delete m_slicing_parameters; @@ -241,14 +241,14 @@ bool GLCanvas3D::LayersEditing::init(const std::string& vertex_shader_filename, if (!m_shader.init(vertex_shader_filename, fragment_shader_filename)) return false; - ::glGenTextures(1, (GLuint*)&m_z_texture_id); - ::glBindTexture(GL_TEXTURE_2D, m_z_texture_id); - ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); - ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); - ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); - ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1); - ::glBindTexture(GL_TEXTURE_2D, 0); + glsafe(::glGenTextures(1, (GLuint*)&m_z_texture_id)); + glsafe(::glBindTexture(GL_TEXTURE_2D, m_z_texture_id)); + 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_MAG_FILTER, GL_LINEAR)); + glsafe(::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST)); + glsafe(::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1)); + glsafe(::glBindTexture(GL_TEXTURE_2D, 0)); return true; } @@ -304,12 +304,12 @@ void GLCanvas3D::LayersEditing::render_overlay(const GLCanvas3D& canvas) const const Rect& bar_rect = get_bar_rect_viewport(canvas); const Rect& reset_rect = get_reset_rect_viewport(canvas); - ::glDisable(GL_DEPTH_TEST); + glsafe(::glDisable(GL_DEPTH_TEST)); // The viewport and camera are set to complete view and glOrtho(-$x / 2, $x / 2, -$y / 2, $y / 2, -$depth, $depth), // where x, y is the window size divided by $self->_zoom. - ::glPushMatrix(); - ::glLoadIdentity(); + glsafe(::glPushMatrix()); + glsafe(::glLoadIdentity()); _render_tooltip_texture(canvas, bar_rect, reset_rect); _render_reset_texture(reset_rect); @@ -317,9 +317,9 @@ void GLCanvas3D::LayersEditing::render_overlay(const GLCanvas3D& canvas) const _render_profile(bar_rect); // Revert the matrices. - ::glPopMatrix(); + glsafe(::glPopMatrix()); - ::glEnable(GL_DEPTH_TEST); + glsafe(::glEnable(GL_DEPTH_TEST)); } float GLCanvas3D::LayersEditing::get_cursor_z_relative(const GLCanvas3D& canvas) @@ -455,8 +455,8 @@ void GLCanvas3D::LayersEditing::_render_active_object_annotations(const GLCanvas // The shader requires the original model coordinates when rendering to the texture, so we pass it the unit matrix m_shader.set_uniform("volume_world_matrix", UNIT_MATRIX); - ::glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - ::glBindTexture(GL_TEXTURE_2D, m_z_texture_id); + glsafe(::glPixelStorei(GL_UNPACK_ALIGNMENT, 1)); + glsafe(::glBindTexture(GL_TEXTURE_2D, m_z_texture_id)); // Render the color bar float l = bar_rect.get_left(); @@ -470,8 +470,8 @@ void GLCanvas3D::LayersEditing::_render_active_object_annotations(const GLCanvas ::glVertex3f(r, b, 0.0f); ::glVertex3f(r, t, m_object_max_z); ::glVertex3f(l, t, m_object_max_z); - ::glEnd(); - ::glBindTexture(GL_TEXTURE_2D, 0); + glsafe(::glEnd()); + glsafe(::glBindTexture(GL_TEXTURE_2D, 0)); m_shader.stop_using(); } @@ -487,18 +487,18 @@ void GLCanvas3D::LayersEditing::_render_profile(const Rect& bar_rect) const float x = bar_rect.get_left() + (float)m_slicing_parameters->layer_height * scale_x; // Baseline - ::glColor3f(0.0f, 0.0f, 0.0f); + glsafe(::glColor3f(0.0f, 0.0f, 0.0f)); ::glBegin(GL_LINE_STRIP); ::glVertex2f(x, bar_rect.get_bottom()); ::glVertex2f(x, bar_rect.get_top()); - ::glEnd(); + glsafe(::glEnd()); // Curve - ::glColor3f(0.0f, 0.0f, 1.0f); + glsafe(::glColor3f(0.0f, 0.0f, 1.0f)); ::glBegin(GL_LINE_STRIP); for (unsigned int i = 0; i < m_layer_height_profile.size(); i += 2) ::glVertex2f(bar_rect.get_left() + (float)m_layer_height_profile[i + 1] * scale_x, bar_rect.get_bottom() + (float)m_layer_height_profile[i] * scale_y); - ::glEnd(); + glsafe(::glEnd()); } void GLCanvas3D::LayersEditing::render_volumes(const GLCanvas3D& canvas, const GLVolumeCollection &volumes) const @@ -509,51 +509,52 @@ void GLCanvas3D::LayersEditing::render_volumes(const GLCanvas3D& canvas, const G assert(shader_id > 0); GLint current_program_id; - glGetIntegerv(GL_CURRENT_PROGRAM, ¤t_program_id); + glsafe(::glGetIntegerv(GL_CURRENT_PROGRAM, ¤t_program_id)); if (shader_id > 0 && shader_id != current_program_id) // The layer editing shader is not yet active. Activate it. - glUseProgram(shader_id); + glsafe(::glUseProgram(shader_id)); else // The layer editing shader was already active. current_program_id = -1; - GLint z_to_texture_row_id = glGetUniformLocation(shader_id, "z_to_texture_row"); - GLint z_texture_row_to_normalized_id = glGetUniformLocation(shader_id, "z_texture_row_to_normalized"); - GLint z_cursor_id = glGetUniformLocation(shader_id, "z_cursor"); - GLint z_cursor_band_width_id = glGetUniformLocation(shader_id, "z_cursor_band_width"); - GLint world_matrix_id = glGetUniformLocation(shader_id, "volume_world_matrix"); + GLint z_to_texture_row_id = ::glGetUniformLocation(shader_id, "z_to_texture_row"); + GLint z_texture_row_to_normalized_id = ::glGetUniformLocation(shader_id, "z_texture_row_to_normalized"); + GLint z_cursor_id = ::glGetUniformLocation(shader_id, "z_cursor"); + GLint z_cursor_band_width_id = ::glGetUniformLocation(shader_id, "z_cursor_band_width"); + GLint world_matrix_id = ::glGetUniformLocation(shader_id, "volume_world_matrix"); + glcheck(); if (z_to_texture_row_id != -1 && z_texture_row_to_normalized_id != -1 && z_cursor_id != -1 && z_cursor_band_width_id != -1 && world_matrix_id != -1) { const_cast(this)->generate_layer_height_texture(); // Uniforms were resolved, go ahead using the layer editing shader. - glUniform1f(z_to_texture_row_id, GLfloat(m_layers_texture.cells - 1) / (GLfloat(m_layers_texture.width) * GLfloat(m_object_max_z))); - glUniform1f(z_texture_row_to_normalized_id, GLfloat(1.0f / m_layers_texture.height)); - glUniform1f(z_cursor_id, GLfloat(m_object_max_z) * GLfloat(this->get_cursor_z_relative(canvas))); - glUniform1f(z_cursor_band_width_id, GLfloat(this->band_width)); + glsafe(::glUniform1f(z_to_texture_row_id, GLfloat(m_layers_texture.cells - 1) / (GLfloat(m_layers_texture.width) * GLfloat(m_object_max_z)))); + glsafe(::glUniform1f(z_texture_row_to_normalized_id, GLfloat(1.0f / m_layers_texture.height))); + glsafe(::glUniform1f(z_cursor_id, GLfloat(m_object_max_z) * GLfloat(this->get_cursor_z_relative(canvas)))); + glsafe(::glUniform1f(z_cursor_band_width_id, GLfloat(this->band_width))); // Initialize the layer height texture mapping. GLsizei w = (GLsizei)m_layers_texture.width; GLsizei h = (GLsizei)m_layers_texture.height; GLsizei half_w = w / 2; GLsizei half_h = h / 2; - ::glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - glBindTexture(GL_TEXTURE_2D, m_z_texture_id); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); - glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, half_w, half_h, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, m_layers_texture.data.data()); - glTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, half_w, half_h, GL_RGBA, GL_UNSIGNED_BYTE, m_layers_texture.data.data() + m_layers_texture.width * m_layers_texture.height * 4); + glsafe(::glPixelStorei(GL_UNPACK_ALIGNMENT, 1)); + glsafe(::glBindTexture(GL_TEXTURE_2D, m_z_texture_id)); + glsafe(::glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0)); + glsafe(::glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, half_w, half_h, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0)); + glsafe(::glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, m_layers_texture.data.data())); + glsafe(::glTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, half_w, half_h, GL_RGBA, GL_UNSIGNED_BYTE, m_layers_texture.data.data() + m_layers_texture.width * m_layers_texture.height * 4)); for (const GLVolume *glvolume : volumes.volumes) { // Render the object using the layer editing shader and texture. if (! glvolume->is_active || glvolume->composite_id.object_id != this->last_object_id || glvolume->is_modifier) continue; - ::glUniformMatrix4fv(world_matrix_id, 1, GL_FALSE, (const GLfloat*)glvolume->world_matrix().cast().data()); + glsafe(::glUniformMatrix4fv(world_matrix_id, 1, GL_FALSE, (const GLfloat*)glvolume->world_matrix().cast().data())); glvolume->render(); } // Revert back to the previous shader. glBindTexture(GL_TEXTURE_2D, 0); if (current_program_id > 0) - glUseProgram(current_program_id); + glsafe(::glUseProgram(current_program_id)); } else { @@ -563,7 +564,7 @@ void GLCanvas3D::LayersEditing::render_volumes(const GLCanvas3D& canvas, const G // Render the object using the layer editing shader and texture. if (!glvolume->is_active || glvolume->composite_id.object_id != this->last_object_id || glvolume->is_modifier) continue; - ::glUniformMatrix4fv(world_matrix_id, 1, GL_FALSE, (const GLfloat*)glvolume->world_matrix().cast().data()); + glsafe(::glUniformMatrix4fv(world_matrix_id, 1, GL_FALSE, (const GLfloat*)glvolume->world_matrix().cast().data())); glvolume->render(); } } @@ -846,14 +847,14 @@ bool GLCanvas3D::WarningTexture::_generate(const std::string& msg_utf8, const GL } // sends buffer to gpu - ::glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - ::glGenTextures(1, &m_id); - ::glBindTexture(GL_TEXTURE_2D, (GLuint)m_id); - ::glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (GLsizei)m_width, (GLsizei)m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, (const void*)data.data()); - ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0); - ::glBindTexture(GL_TEXTURE_2D, 0); + glsafe(::glPixelStorei(GL_UNPACK_ALIGNMENT, 1)); + glsafe(::glGenTextures(1, &m_id)); + glsafe(::glBindTexture(GL_TEXTURE_2D, (GLuint)m_id)); + glsafe(::glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (GLsizei)m_width, (GLsizei)m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, (const void*)data.data())); + glsafe(::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); + glsafe(::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); + glsafe(::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0)); + glsafe(::glBindTexture(GL_TEXTURE_2D, 0)); return true; } @@ -865,9 +866,9 @@ void GLCanvas3D::WarningTexture::render(const GLCanvas3D& canvas) const if ((m_id > 0) && (m_original_width > 0) && (m_original_height > 0) && (m_width > 0) && (m_height > 0)) { - ::glDisable(GL_DEPTH_TEST); - ::glPushMatrix(); - ::glLoadIdentity(); + glsafe(::glDisable(GL_DEPTH_TEST)); + glsafe(::glPushMatrix()); + glsafe(::glLoadIdentity()); const Size& cnv_size = canvas.get_canvas_size(); float zoom = canvas.get_camera_zoom(); @@ -890,8 +891,8 @@ void GLCanvas3D::WarningTexture::render(const GLCanvas3D& canvas) const GLTexture::render_sub_texture(m_id, left, right, bottom, top, uvs); - ::glPopMatrix(); - ::glEnable(GL_DEPTH_TEST); + glsafe(::glPopMatrix()); + glsafe(::glEnable(GL_DEPTH_TEST)); } } @@ -1118,14 +1119,14 @@ bool GLCanvas3D::LegendTexture::generate(const GCodePreviewData& preview_data, c } // sends buffer to gpu - ::glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - ::glGenTextures(1, &m_id); - ::glBindTexture(GL_TEXTURE_2D, (GLuint)m_id); - ::glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (GLsizei)m_width, (GLsizei)m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, (const void*)data.data()); - ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0); - ::glBindTexture(GL_TEXTURE_2D, 0); + glsafe(::glPixelStorei(GL_UNPACK_ALIGNMENT, 1)); + glsafe(::glGenTextures(1, &m_id)); + glsafe(::glBindTexture(GL_TEXTURE_2D, (GLuint)m_id)); + glsafe(::glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (GLsizei)m_width, (GLsizei)m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, (const void*)data.data())); + glsafe(::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); + glsafe(::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); + glsafe(::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0)); + glsafe(::glBindTexture(GL_TEXTURE_2D, 0)); return true; } @@ -1134,9 +1135,9 @@ void GLCanvas3D::LegendTexture::render(const GLCanvas3D& canvas) const { if ((m_id > 0) && (m_original_width > 0) && (m_original_height > 0) && (m_width > 0) && (m_height > 0)) { - ::glDisable(GL_DEPTH_TEST); - ::glPushMatrix(); - ::glLoadIdentity(); + glsafe(::glDisable(GL_DEPTH_TEST)); + glsafe(::glPushMatrix()); + glsafe(::glLoadIdentity()); const Size& cnv_size = canvas.get_canvas_size(); float zoom = canvas.get_camera_zoom(); @@ -1159,8 +1160,8 @@ void GLCanvas3D::LegendTexture::render(const GLCanvas3D& canvas) const GLTexture::render_sub_texture(m_id, left, right, bottom, top, uvs); - ::glPopMatrix(); - ::glEnable(GL_DEPTH_TEST); + glsafe(::glPopMatrix()); + glsafe(::glEnable(GL_DEPTH_TEST)); } } @@ -1249,48 +1250,48 @@ bool GLCanvas3D::init(bool useVBOs, bool use_legacy_opengl) if ((m_canvas == nullptr) || (m_context == nullptr)) return false; - ::glClearColor(1.0f, 1.0f, 1.0f, 1.0f); - ::glClearDepth(1.0f); + glsafe(::glClearColor(1.0f, 1.0f, 1.0f, 1.0f)); + glsafe(::glClearDepth(1.0f)); - ::glDepthFunc(GL_LESS); + glsafe(::glDepthFunc(GL_LESS)); - ::glEnable(GL_DEPTH_TEST); - ::glEnable(GL_CULL_FACE); - ::glEnable(GL_BLEND); - ::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glsafe(::glEnable(GL_DEPTH_TEST)); + glsafe(::glEnable(GL_CULL_FACE)); + glsafe(::glEnable(GL_BLEND)); + glsafe(::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); // Set antialiasing / multisampling - ::glDisable(GL_LINE_SMOOTH); - ::glDisable(GL_POLYGON_SMOOTH); + glsafe(::glDisable(GL_LINE_SMOOTH)); + glsafe(::glDisable(GL_POLYGON_SMOOTH)); // ambient lighting GLfloat ambient[4] = { 0.3f, 0.3f, 0.3f, 1.0f }; - ::glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient); + glsafe(::glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient)); - ::glEnable(GL_LIGHT0); - ::glEnable(GL_LIGHT1); + glsafe(::glEnable(GL_LIGHT0)); + glsafe(::glEnable(GL_LIGHT1)); // light from camera GLfloat specular_cam[4] = { 0.3f, 0.3f, 0.3f, 1.0f }; - ::glLightfv(GL_LIGHT1, GL_SPECULAR, specular_cam); + glsafe(::glLightfv(GL_LIGHT1, GL_SPECULAR, specular_cam)); GLfloat diffuse_cam[4] = { 0.2f, 0.2f, 0.2f, 1.0f }; - ::glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse_cam); + glsafe(::glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse_cam)); // light from above GLfloat specular_top[4] = { 0.2f, 0.2f, 0.2f, 1.0f }; - ::glLightfv(GL_LIGHT0, GL_SPECULAR, specular_top); + glsafe(::glLightfv(GL_LIGHT0, GL_SPECULAR, specular_top)); GLfloat diffuse_top[4] = { 0.5f, 0.5f, 0.5f, 1.0f }; - ::glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse_top); + glsafe(::glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse_top)); // Enables Smooth Color Shading; try GL_FLAT for (lack of) fun. - ::glShadeModel(GL_SMOOTH); + glsafe(::glShadeModel(GL_SMOOTH)); // A handy trick -- have surface material mirror the color. - ::glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); - ::glEnable(GL_COLOR_MATERIAL); + glsafe(::glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE)); + glsafe(::glEnable(GL_COLOR_MATERIAL)); if (m_multisample_allowed) - ::glEnable(GL_MULTISAMPLE); + glsafe(::glEnable(GL_MULTISAMPLE)); if (useVBOs && !m_shader.init("gouraud.vs", "gouraud.fs")) return false; @@ -1605,9 +1606,9 @@ void GLCanvas3D::render() _camera_tranform(); GLfloat position_cam[4] = { 1.0f, 0.0f, 1.0f, 0.0f }; - ::glLightfv(GL_LIGHT1, GL_POSITION, position_cam); + glsafe(::glLightfv(GL_LIGHT1, GL_POSITION, position_cam)); GLfloat position_top[4] = { -0.5f, -0.5f, 1.0f, 0.0f }; - ::glLightfv(GL_LIGHT0, GL_POSITION, position_top); + glsafe(::glLightfv(GL_LIGHT0, GL_POSITION, position_top)); float theta = m_camera.get_theta(); if (theta > 180.f) @@ -1620,7 +1621,7 @@ void GLCanvas3D::render() _picking_pass(); // draw scene - ::glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glsafe(::glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)); _render_background(); // textured bed needs to be rendered after objects if the texture is transparent @@ -2656,7 +2657,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) // get the view matrix back from opengl GLfloat matrix[16]; - ::glGetFloatv(GL_MODELVIEW_MATRIX, matrix); + glsafe(::glGetFloatv(GL_MODELVIEW_MATRIX, matrix)); Vec3d camera_right((double)matrix[0], (double)matrix[4], (double)matrix[8]); Vec3d camera_up((double)matrix[1], (double)matrix[5], (double)matrix[9]); @@ -3339,10 +3340,10 @@ void GLCanvas3D::_resize(unsigned int w, unsigned int h) // ensures that this canvas is current _set_current(); - ::glViewport(0, 0, w, h); + glsafe(::glViewport(0, 0, w, h)); - ::glMatrixMode(GL_PROJECTION); - ::glLoadIdentity(); + glsafe(::glMatrixMode(GL_PROJECTION)); + glsafe(::glLoadIdentity()); const BoundingBoxf3& bbox = _max_bounding_box(); @@ -3362,7 +3363,7 @@ void GLCanvas3D::_resize(unsigned int w, unsigned int h) // FIXME: calculate a tighter value for depth will improve z-fighting float depth = 5.0f * (float)bbox.max_size(); - ::glOrtho(-w2, w2, -h2, h2, -depth, depth); + glsafe(::glOrtho(-w2, w2, -h2, h2, -depth, depth)); break; } @@ -3395,7 +3396,7 @@ void GLCanvas3D::_resize(unsigned int w, unsigned int h) } } - ::glMatrixMode(GL_MODELVIEW); + glsafe(::glMatrixMode(GL_MODELVIEW)); m_dirty = false; } @@ -3434,7 +3435,7 @@ float GLCanvas3D::_get_zoom_to_bounding_box_factor(const BoundingBoxf3& bbox) co // get the view matrix back from opengl GLfloat matrix[16]; - ::glGetFloatv(GL_MODELVIEW_MATRIX, matrix); + glsafe(::glGetFloatv(GL_MODELVIEW_MATRIX, matrix)); // camera axes Vec3d right((double)matrix[0], (double)matrix[4], (double)matrix[8]); @@ -3502,13 +3503,13 @@ void GLCanvas3D::_refresh_if_shown_on_screen() void GLCanvas3D::_camera_tranform() const { - ::glMatrixMode(GL_MODELVIEW); - ::glLoadIdentity(); + glsafe(::glMatrixMode(GL_MODELVIEW)); + glsafe(::glLoadIdentity()); - ::glRotatef(-m_camera.get_theta(), 1.0f, 0.0f, 0.0f); // pitch - ::glRotatef(m_camera.phi, 0.0f, 0.0f, 1.0f); // yaw + glsafe(::glRotatef(-m_camera.get_theta(), 1.0f, 0.0f, 0.0f)); // pitch + glsafe(::glRotatef(m_camera.phi, 0.0f, 0.0f, 1.0f)); // yaw Vec3d target = -m_camera.get_target(); - ::glTranslated(target(0), target(1), target(2)); + glsafe(::glTranslated(target(0), target(1), target(2))); } void GLCanvas3D::_picking_pass() const @@ -3522,18 +3523,18 @@ void GLCanvas3D::_picking_pass() const // Better to use software ray - casting on a bounding - box hierarchy. if (m_multisample_allowed) - ::glDisable(GL_MULTISAMPLE); + glsafe(::glDisable(GL_MULTISAMPLE)); - ::glDisable(GL_BLEND); - ::glEnable(GL_DEPTH_TEST); + glsafe(::glDisable(GL_BLEND)); + glsafe(::glEnable(GL_DEPTH_TEST)); - ::glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glsafe(::glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)); _render_volumes(true); m_gizmos.render_current_gizmo_for_picking_pass(m_selection); if (m_multisample_allowed) - ::glEnable(GL_MULTISAMPLE); + glsafe(::glEnable(GL_MULTISAMPLE)); int volume_id = -1; @@ -3542,7 +3543,7 @@ void GLCanvas3D::_picking_pass() const bool inside = (0 <= pos(0)) && (pos(0) < cnv_size.get_width()) && (0 <= pos(1)) && (pos(1) < cnv_size.get_height()); if (inside) { - ::glReadPixels(pos(0), cnv_size.get_height() - pos(1) - 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, (void*)color); + glsafe(::glReadPixels(pos(0), cnv_size.get_height() - pos(1) - 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, (void*)color)); volume_id = color[0] + color[1] * 256 + color[2] * 256 * 256; } if ((0 <= volume_id) && (volume_id < (int)m_volumes.volumes.size())) @@ -3562,14 +3563,14 @@ void GLCanvas3D::_picking_pass() const void GLCanvas3D::_render_background() const { - ::glPushMatrix(); - ::glLoadIdentity(); - ::glMatrixMode(GL_PROJECTION); - ::glPushMatrix(); - ::glLoadIdentity(); + glsafe(::glPushMatrix()); + glsafe(::glLoadIdentity()); + glsafe(::glMatrixMode(GL_PROJECTION)); + glsafe(::glPushMatrix()); + glsafe(::glLoadIdentity()); // Draws a bottom to top gradient over the complete screen. - ::glDisable(GL_DEPTH_TEST); + glsafe(::glDisable(GL_DEPTH_TEST)); ::glBegin(GL_QUADS); if (m_dynamic_background_enabled && _is_any_volume_outside()) @@ -3587,13 +3588,13 @@ void GLCanvas3D::_render_background() const ::glVertex2f(1.0f, 1.0f); ::glVertex2f(-1.0f, 1.0f); - ::glEnd(); + glsafe(::glEnd()); - ::glEnable(GL_DEPTH_TEST); + glsafe(::glEnable(GL_DEPTH_TEST)); - ::glPopMatrix(); - ::glMatrixMode(GL_MODELVIEW); - ::glPopMatrix(); + glsafe(::glPopMatrix()); + glsafe(::glMatrixMode(GL_MODELVIEW)); + glsafe(::glPopMatrix()); } void GLCanvas3D::_render_bed(float theta) const @@ -3615,8 +3616,8 @@ void GLCanvas3D::_render_objects() const if (m_volumes.empty()) return; - ::glEnable(GL_LIGHTING); - ::glEnable(GL_DEPTH_TEST); + glsafe(::glEnable(GL_LIGHTING)); + glsafe(::glEnable(GL_DEPTH_TEST)); if (m_use_VBOs) { @@ -3660,10 +3661,10 @@ void GLCanvas3D::_render_objects() const { if (m_use_clipping_planes) { - ::glClipPlane(GL_CLIP_PLANE0, (GLdouble*)m_clipping_planes[0].get_data()); - ::glEnable(GL_CLIP_PLANE0); - ::glClipPlane(GL_CLIP_PLANE1, (GLdouble*)m_clipping_planes[1].get_data()); - ::glEnable(GL_CLIP_PLANE1); + glsafe(::glClipPlane(GL_CLIP_PLANE0, (GLdouble*)m_clipping_planes[0].get_data())); + glsafe(::glEnable(GL_CLIP_PLANE0)); + glsafe(::glClipPlane(GL_CLIP_PLANE1, (GLdouble*)m_clipping_planes[1].get_data())); + glsafe(::glEnable(GL_CLIP_PLANE1)); } // do not cull backfaces to show broken geometry, if any @@ -3674,12 +3675,12 @@ void GLCanvas3D::_render_objects() const if (m_use_clipping_planes) { - ::glDisable(GL_CLIP_PLANE0); - ::glDisable(GL_CLIP_PLANE1); + glsafe(::glDisable(GL_CLIP_PLANE0)); + glsafe(::glDisable(GL_CLIP_PLANE1)); } } - ::glDisable(GL_LIGHTING); + glsafe(::glDisable(GL_LIGHTING)); } void GLCanvas3D::_render_selection() const @@ -3719,16 +3720,16 @@ void GLCanvas3D::_render_volumes(bool fake_colors) const static const GLfloat INV_255 = 1.0f / 255.0f; if (!fake_colors) - ::glEnable(GL_LIGHTING); + glsafe(::glEnable(GL_LIGHTING)); // do not cull backfaces to show broken geometry, if any - ::glDisable(GL_CULL_FACE); + glsafe(::glDisable(GL_CULL_FACE)); - ::glEnable(GL_BLEND); - ::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glsafe(::glEnable(GL_BLEND)); + glsafe(::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); - ::glEnableClientState(GL_VERTEX_ARRAY); - ::glEnableClientState(GL_NORMAL_ARRAY); + glsafe(::glEnableClientState(GL_VERTEX_ARRAY)); + glsafe(::glEnableClientState(GL_NORMAL_ARRAY)); unsigned int volume_id = 0; for (GLVolume* vol : m_volumes.volumes) @@ -3739,12 +3740,12 @@ void GLCanvas3D::_render_volumes(bool fake_colors) const unsigned int r = (volume_id & 0x000000FF) >> 0; unsigned int g = (volume_id & 0x0000FF00) >> 8; unsigned int b = (volume_id & 0x00FF0000) >> 16; - ::glColor3f((GLfloat)r * INV_255, (GLfloat)g * INV_255, (GLfloat)b * INV_255); + glsafe(::glColor3f((GLfloat)r * INV_255, (GLfloat)g * INV_255, (GLfloat)b * INV_255)); } else { vol->set_render_color(); - ::glColor4fv(vol->render_color); + glsafe(::glColor4fv(vol->render_color)); } if ((!fake_colors || !vol->disabled) && (vol->composite_id.volume_id >= 0 || m_render_sla_auxiliaries)) @@ -3753,14 +3754,14 @@ void GLCanvas3D::_render_volumes(bool fake_colors) const ++volume_id; } - ::glDisableClientState(GL_NORMAL_ARRAY); - ::glDisableClientState(GL_VERTEX_ARRAY); - ::glDisable(GL_BLEND); + glsafe(::glDisableClientState(GL_NORMAL_ARRAY)); + glsafe(::glDisableClientState(GL_VERTEX_ARRAY)); + glsafe(::glDisable(GL_BLEND)); - ::glEnable(GL_CULL_FACE); + glsafe(::glEnable(GL_CULL_FACE)); if (!fake_colors) - ::glDisable(GL_LIGHTING); + glsafe(::glDisable(GL_LIGHTING)); } void GLCanvas3D::_render_current_gizmo() const @@ -3874,9 +3875,9 @@ void GLCanvas3D::_render_camera_target() const { double half_length = 5.0; - ::glDisable(GL_DEPTH_TEST); + glsafe(::glDisable(GL_DEPTH_TEST)); - ::glLineWidth(2.0f); + glsafe(::glLineWidth(2.0f)); ::glBegin(GL_LINES); const Vec3d& target = m_camera.get_target(); // draw line for x axis @@ -3891,7 +3892,7 @@ void GLCanvas3D::_render_camera_target() const ::glColor3f(0.0f, 0.0f, 1.0f); ::glVertex3d(target(0), target(1), target(2) - half_length); ::glVertex3d(target(0), target(1), target(2) + half_length); - ::glEnd(); + glsafe(::glEnd()); } #endif // ENABLE_SHOW_CAMERA_TARGET @@ -3993,9 +3994,9 @@ void GLCanvas3D::_render_sla_slices() const { for (const InstanceTransform& inst : instance_transforms) { - ::glPushMatrix(); - ::glTranslated(inst.offset(0), inst.offset(1), inst.offset(2)); - ::glRotatef(inst.rotation, 0.0, 0.0, 1.0); + glsafe(::glPushMatrix()); + glsafe(::glTranslated(inst.offset(0), inst.offset(1), inst.offset(2))); + glsafe(::glRotatef(inst.rotation, 0.0, 0.0, 1.0)); ::glBegin(GL_TRIANGLES); @@ -4023,9 +4024,9 @@ void GLCanvas3D::_render_sla_slices() const ::glVertex3dv((GLdouble*)v.data()); } - ::glEnd(); + glsafe(::glEnd()); - ::glPopMatrix(); + glsafe(::glPopMatrix()); } } } @@ -4109,16 +4110,16 @@ Vec3d GLCanvas3D::_mouse_to_3d(const Point& mouse_pos, float* z) _camera_tranform(); GLint viewport[4]; - ::glGetIntegerv(GL_VIEWPORT, viewport); + glsafe(::glGetIntegerv(GL_VIEWPORT, viewport)); GLdouble modelview_matrix[16]; - ::glGetDoublev(GL_MODELVIEW_MATRIX, modelview_matrix); + glsafe(::glGetDoublev(GL_MODELVIEW_MATRIX, modelview_matrix)); GLdouble projection_matrix[16]; - ::glGetDoublev(GL_PROJECTION_MATRIX, projection_matrix); + glsafe(::glGetDoublev(GL_PROJECTION_MATRIX, projection_matrix)); GLint y = viewport[3] - (GLint)mouse_pos(1); GLfloat mouse_z; if (z == nullptr) - ::glReadPixels((GLint)mouse_pos(0), y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, (void*)&mouse_z); + glsafe(::glReadPixels((GLint)mouse_pos(0), y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, (void*)&mouse_z)); else mouse_z = *z; diff --git a/src/slic3r/GUI/GLShader.cpp b/src/slic3r/GUI/GLShader.cpp index f401f5466..7f3bc0893 100644 --- a/src/slic3r/GUI/GLShader.cpp +++ b/src/slic3r/GUI/GLShader.cpp @@ -3,6 +3,7 @@ #include "GLShader.hpp" #include "libslic3r/Utils.hpp" +#include "3DScene.hpp" #include #include @@ -52,21 +53,22 @@ bool GLShader::load_from_text(const char *fragment_shader, const char *vertex_sh } if (fragment_shader != nullptr) { - this->fragment_program_id = glCreateShader(GL_FRAGMENT_SHADER); + this->fragment_program_id = ::glCreateShader(GL_FRAGMENT_SHADER); + glcheck(); if (this->fragment_program_id == 0) { last_error = "glCreateShader(GL_FRAGMENT_SHADER) failed."; return false; } GLint len = (GLint)strlen(fragment_shader); - glShaderSource(this->fragment_program_id, 1, &fragment_shader, &len); - glCompileShader(this->fragment_program_id); + glsafe(::glShaderSource(this->fragment_program_id, 1, &fragment_shader, &len)); + glsafe(::glCompileShader(this->fragment_program_id)); GLint params; - glGetShaderiv(this->fragment_program_id, GL_COMPILE_STATUS, ¶ms); + glsafe(::glGetShaderiv(this->fragment_program_id, GL_COMPILE_STATUS, ¶ms)); if (params == GL_FALSE) { // Compilation failed. Get the log. - glGetShaderiv(this->fragment_program_id, GL_INFO_LOG_LENGTH, ¶ms); + glsafe(::glGetShaderiv(this->fragment_program_id, GL_INFO_LOG_LENGTH, ¶ms)); std::vector msg(params); - glGetShaderInfoLog(this->fragment_program_id, params, ¶ms, msg.data()); + glsafe(::glGetShaderInfoLog(this->fragment_program_id, params, ¶ms, msg.data())); this->last_error = std::string("Fragment shader compilation failed:\n") + msg.data(); this->release(); return false; @@ -74,22 +76,23 @@ bool GLShader::load_from_text(const char *fragment_shader, const char *vertex_sh } if (vertex_shader != nullptr) { - this->vertex_program_id = glCreateShader(GL_VERTEX_SHADER); + this->vertex_program_id = ::glCreateShader(GL_VERTEX_SHADER); + glcheck(); if (this->vertex_program_id == 0) { last_error = "glCreateShader(GL_VERTEX_SHADER) failed."; this->release(); return false; } GLint len = (GLint)strlen(vertex_shader); - glShaderSource(this->vertex_program_id, 1, &vertex_shader, &len); - glCompileShader(this->vertex_program_id); + glsafe(::glShaderSource(this->vertex_program_id, 1, &vertex_shader, &len)); + glsafe(::glCompileShader(this->vertex_program_id)); GLint params; - glGetShaderiv(this->vertex_program_id, GL_COMPILE_STATUS, ¶ms); + glsafe(::glGetShaderiv(this->vertex_program_id, GL_COMPILE_STATUS, ¶ms)); if (params == GL_FALSE) { // Compilation failed. Get the log. - glGetShaderiv(this->vertex_program_id, GL_INFO_LOG_LENGTH, ¶ms); + glsafe(::glGetShaderiv(this->vertex_program_id, GL_INFO_LOG_LENGTH, ¶ms)); std::vector msg(params); - glGetShaderInfoLog(this->vertex_program_id, params, ¶ms, msg.data()); + glsafe(::glGetShaderInfoLog(this->vertex_program_id, params, ¶ms, msg.data())); this->last_error = std::string("Vertex shader compilation failed:\n") + msg.data(); this->release(); return false; @@ -97,7 +100,8 @@ bool GLShader::load_from_text(const char *fragment_shader, const char *vertex_sh } // Link shaders - this->shader_program_id = glCreateProgram(); + this->shader_program_id = ::glCreateProgram(); + glcheck(); if (this->shader_program_id == 0) { last_error = "glCreateProgram() failed."; this->release(); @@ -105,18 +109,18 @@ bool GLShader::load_from_text(const char *fragment_shader, const char *vertex_sh } if (this->fragment_program_id) - glAttachShader(this->shader_program_id, this->fragment_program_id); + glsafe(::glAttachShader(this->shader_program_id, this->fragment_program_id)); if (this->vertex_program_id) - glAttachShader(this->shader_program_id, this->vertex_program_id); - glLinkProgram(this->shader_program_id); + glsafe(::glAttachShader(this->shader_program_id, this->vertex_program_id)); + glsafe(::glLinkProgram(this->shader_program_id)); GLint params; - glGetProgramiv(this->shader_program_id, GL_LINK_STATUS, ¶ms); + glsafe(::glGetProgramiv(this->shader_program_id, GL_LINK_STATUS, ¶ms)); if (params == GL_FALSE) { // Linking failed. Get the log. - glGetProgramiv(this->vertex_program_id, GL_INFO_LOG_LENGTH, ¶ms); + glsafe(::glGetProgramiv(this->vertex_program_id, GL_INFO_LOG_LENGTH, ¶ms)); std::vector msg(params); - glGetProgramInfoLog(this->vertex_program_id, params, ¶ms, msg.data()); + glsafe(::glGetProgramInfoLog(this->vertex_program_id, params, ¶ms, msg.data())); this->last_error = std::string("Shader linking failed:\n") + msg.data(); this->release(); return false; @@ -165,31 +169,31 @@ void GLShader::release() { if (this->shader_program_id) { if (this->vertex_program_id) - glDetachShader(this->shader_program_id, this->vertex_program_id); + glsafe(::glDetachShader(this->shader_program_id, this->vertex_program_id)); if (this->fragment_program_id) - glDetachShader(this->shader_program_id, this->fragment_program_id); - glDeleteProgram(this->shader_program_id); + glsafe(::glDetachShader(this->shader_program_id, this->fragment_program_id)); + glsafe(::glDeleteProgram(this->shader_program_id)); this->shader_program_id = 0; } if (this->vertex_program_id) { - glDeleteShader(this->vertex_program_id); + glsafe(::glDeleteShader(this->vertex_program_id)); this->vertex_program_id = 0; } if (this->fragment_program_id) { - glDeleteShader(this->fragment_program_id); + glsafe(::glDeleteShader(this->fragment_program_id)); this->fragment_program_id = 0; } } void GLShader::enable() const { - glUseProgram(this->shader_program_id); + glsafe(::glUseProgram(this->shader_program_id)); } void GLShader::disable() const { - glUseProgram(0); + glsafe(::glUseProgram(0)); } // Return shader vertex attribute ID @@ -208,7 +212,7 @@ bool GLShader::set_uniform(const char *name, float value) const { int id = this->get_uniform_location(name); if (id >= 0) { - glUniform1fARB(id, value); + glsafe(::glUniform1fARB(id, value)); return true; } return false; @@ -219,7 +223,7 @@ bool GLShader::set_uniform(const char* name, const float* matrix) const int id = get_uniform_location(name); if (id >= 0) { - ::glUniformMatrix4fv(id, 1, GL_FALSE, (const GLfloat*)matrix); + glsafe(::glUniformMatrix4fv(id, 1, GL_FALSE, (const GLfloat*)matrix)); return true; } return false; @@ -230,7 +234,7 @@ bool GLShader::set_uniform(const char* name, int value) const int id = get_uniform_location(name); if (id >= 0) { - ::glUniform1i(id, value); + glsafe(::glUniform1i(id, value)); return true; } return false; diff --git a/src/slic3r/GUI/GLTexture.cpp b/src/slic3r/GUI/GLTexture.cpp index c1a035754..ec41d7e93 100644 --- a/src/slic3r/GUI/GLTexture.cpp +++ b/src/slic3r/GUI/GLTexture.cpp @@ -1,6 +1,8 @@ #include "libslic3r/libslic3r.h" #include "GLTexture.hpp" +#include "3DScene.hpp" + #include #include @@ -177,15 +179,15 @@ bool GLTexture::load_from_svg_files_as_sprites_array(const std::vectorget_instance_transformation().get_matrix(); - ::glPushMatrix(); - ::glTranslatef(0.f, 0.f, selection.get_volume(*selection.get_volume_idxs().begin())->get_sla_shift_z()); - ::glMultMatrixd(m.data()); + glsafe(::glPushMatrix()); + glsafe(::glTranslatef(0.f, 0.f, selection.get_volume(*selection.get_volume_idxs().begin())->get_sla_shift_z())); + glsafe(::glMultMatrixd(m.data())); if (this->is_plane_update_necessary()) const_cast(this)->update_planes(); for (int i = 0; i < (int)m_planes.size(); ++i) { if (i == m_hover_id) - ::glColor4f(0.9f, 0.9f, 0.9f, 0.75f); + glsafe(::glColor4f(0.9f, 0.9f, 0.9f, 0.75f)); else - ::glColor4f(0.9f, 0.9f, 0.9f, 0.5f); + glsafe(::glColor4f(0.9f, 0.9f, 0.9f, 0.5f)); ::glBegin(GL_POLYGON); for (const Vec3d& vertex : m_planes[i].vertices) { ::glVertex3dv(vertex.data()); } - ::glEnd(); + glsafe(::glEnd()); } - ::glPopMatrix(); + glsafe(::glPopMatrix()); } - ::glEnable(GL_CULL_FACE); - ::glDisable(GL_BLEND); + glsafe(::glEnable(GL_CULL_FACE)); + glsafe(::glDisable(GL_BLEND)); } void GLGizmoFlatten::on_render_for_picking(const Selection& selection) const { - ::glDisable(GL_DEPTH_TEST); - ::glDisable(GL_BLEND); + glsafe(::glDisable(GL_DEPTH_TEST)); + glsafe(::glDisable(GL_BLEND)); if (selection.is_single_full_instance()) { const Transform3d& m = selection.get_volume(*selection.get_volume_idxs().begin())->get_instance_transformation().get_matrix(); - ::glPushMatrix(); - ::glTranslatef(0.f, 0.f, selection.get_volume(*selection.get_volume_idxs().begin())->get_sla_shift_z()); - ::glMultMatrixd(m.data()); + glsafe(::glPushMatrix()); + glsafe(::glTranslatef(0.f, 0.f, selection.get_volume(*selection.get_volume_idxs().begin())->get_sla_shift_z())); + glsafe(::glMultMatrixd(m.data())); if (this->is_plane_update_necessary()) const_cast(this)->update_planes(); for (int i = 0; i < (int)m_planes.size(); ++i) { - ::glColor3fv(picking_color_component(i).data()); + glsafe(::glColor3fv(picking_color_component(i).data())); ::glBegin(GL_POLYGON); for (const Vec3d& vertex : m_planes[i].vertices) { ::glVertex3dv(vertex.data()); } - ::glEnd(); + glsafe(::glEnd()); } - ::glPopMatrix(); + glsafe(::glPopMatrix()); } - ::glEnable(GL_CULL_FACE); + glsafe(::glEnable(GL_CULL_FACE)); } void GLGizmoFlatten::set_flattening_data(const ModelObject* model_object) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMove.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMove.cpp index 61f219dbf..7cc5b6485 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMove.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMove.cpp @@ -97,8 +97,8 @@ void GLGizmoMove3D::on_render(const Selection& selection) const else if (!m_grabbers[2].dragging && (m_hover_id == 2)) set_tooltip("Z"); - ::glClear(GL_DEPTH_BUFFER_BIT); - ::glEnable(GL_DEPTH_TEST); + glsafe(::glClear(GL_DEPTH_BUFFER_BIT)); + glsafe(::glEnable(GL_DEPTH_TEST)); const BoundingBoxf3& box = selection.get_bounding_box(); const Vec3d& center = box.center(); @@ -115,7 +115,7 @@ void GLGizmoMove3D::on_render(const Selection& selection) const m_grabbers[2].center = Vec3d(center(0), center(1), box.max(2) + Offset); ::memcpy((void*)m_grabbers[2].color, (const void*)&AXES_COLOR[2], 3 * sizeof(float)); - ::glLineWidth((m_hover_id != -1) ? 2.0f : 1.5f); + glsafe(::glLineWidth((m_hover_id != -1) ? 2.0f : 1.5f)); if (m_hover_id == -1) { @@ -124,11 +124,11 @@ void GLGizmoMove3D::on_render(const Selection& selection) const { if (m_grabbers[i].enabled) { - ::glColor3fv(AXES_COLOR[i]); + glsafe(::glColor3fv(AXES_COLOR[i])); ::glBegin(GL_LINES); ::glVertex3dv(center.data()); ::glVertex3dv(m_grabbers[i].center.data()); - ::glEnd(); + glsafe(::glEnd()); } } @@ -143,11 +143,11 @@ void GLGizmoMove3D::on_render(const Selection& selection) const else { // draw axis - ::glColor3fv(AXES_COLOR[m_hover_id]); + glsafe(::glColor3fv(AXES_COLOR[m_hover_id])); ::glBegin(GL_LINES); ::glVertex3dv(center.data()); ::glVertex3dv(m_grabbers[m_hover_id].center.data()); - ::glEnd(); + glsafe(::glEnd()); // draw grabber m_grabbers[m_hover_id].render(true, box.max_size()); @@ -157,7 +157,7 @@ void GLGizmoMove3D::on_render(const Selection& selection) const void GLGizmoMove3D::on_render_for_picking(const Selection& selection) const { - ::glDisable(GL_DEPTH_TEST); + glsafe(::glDisable(GL_DEPTH_TEST)); const BoundingBoxf3& box = selection.get_bounding_box(); render_grabbers_for_picking(box); @@ -229,25 +229,25 @@ void GLGizmoMove3D::render_grabber_extension(Axis axis, const BoundingBoxf3& box } if (!picking) - ::glEnable(GL_LIGHTING); + glsafe(::glEnable(GL_LIGHTING)); - ::glColor3fv(color); - ::glPushMatrix(); - ::glTranslated(m_grabbers[axis].center(0), m_grabbers[axis].center(1), m_grabbers[axis].center(2)); + glsafe(::glColor3fv(color)); + glsafe(::glPushMatrix()); + glsafe(::glTranslated(m_grabbers[axis].center(0), m_grabbers[axis].center(1), m_grabbers[axis].center(2))); if (axis == X) - ::glRotated(90.0, 0.0, 1.0, 0.0); + glsafe(::glRotated(90.0, 0.0, 1.0, 0.0)); else if (axis == Y) - ::glRotated(-90.0, 1.0, 0.0, 0.0); + glsafe(::glRotated(-90.0, 1.0, 0.0, 0.0)); - ::glTranslated(0.0, 0.0, 2.0 * size); + glsafe(::glTranslated(0.0, 0.0, 2.0 * size)); ::gluQuadricOrientation(m_quadric, GLU_OUTSIDE); ::gluCylinder(m_quadric, 0.75 * size, 0.0, 3.0 * size, 36, 1); ::gluQuadricOrientation(m_quadric, GLU_INSIDE); ::gluDisk(m_quadric, 0.0, 0.75 * size, 36, 1); - ::glPopMatrix(); + glsafe(::glPopMatrix()); if (!picking) - ::glDisable(GL_LIGHTING); + glsafe(::glDisable(GL_LIGHTING)); } diff --git a/src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp b/src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp index e05ad00fe..ff9cf380e 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoRotate.cpp @@ -155,13 +155,13 @@ void GLGizmoRotate::on_render(const Selection& selection) const m_snap_fine_out_radius = m_radius * (1.0f + ScaleLongTooth); } - ::glEnable(GL_DEPTH_TEST); + glsafe(::glEnable(GL_DEPTH_TEST)); - ::glPushMatrix(); + glsafe(::glPushMatrix()); transform_to_local(selection); - ::glLineWidth((m_hover_id != -1) ? 2.0f : 1.5f); - ::glColor3fv((m_hover_id != -1) ? m_drag_color : m_highlight_color); + glsafe(::glLineWidth((m_hover_id != -1) ? 2.0f : 1.5f)); + glsafe(::glColor3fv((m_hover_id != -1) ? m_drag_color : m_highlight_color)); render_circle(); @@ -172,7 +172,7 @@ void GLGizmoRotate::on_render(const Selection& selection) const render_reference_radius(); } - ::glColor3fv(m_highlight_color); + glsafe(::glColor3fv(m_highlight_color)); if (m_hover_id != -1) render_angle(); @@ -180,14 +180,14 @@ void GLGizmoRotate::on_render(const Selection& selection) const render_grabber(box); render_grabber_extension(box, false); - ::glPopMatrix(); + glsafe(::glPopMatrix()); } void GLGizmoRotate::on_render_for_picking(const Selection& selection) const { - ::glDisable(GL_DEPTH_TEST); + glsafe(::glDisable(GL_DEPTH_TEST)); - ::glPushMatrix(); + glsafe(::glPushMatrix()); transform_to_local(selection); @@ -195,7 +195,7 @@ void GLGizmoRotate::on_render_for_picking(const Selection& selection) const render_grabbers_for_picking(box); render_grabber_extension(box, true); - ::glPopMatrix(); + glsafe(::glPopMatrix()); } void GLGizmoRotate::render_circle() const @@ -209,7 +209,7 @@ void GLGizmoRotate::render_circle() const float z = 0.0f; ::glVertex3f((GLfloat)x, (GLfloat)y, (GLfloat)z); } - ::glEnd(); + glsafe(::glEnd()); } void GLGizmoRotate::render_scale() const @@ -232,7 +232,7 @@ void GLGizmoRotate::render_scale() const ::glVertex3f((GLfloat)in_x, (GLfloat)in_y, (GLfloat)in_z); ::glVertex3f((GLfloat)out_x, (GLfloat)out_y, (GLfloat)out_z); } - ::glEnd(); + glsafe(::glEnd()); } void GLGizmoRotate::render_snap_radii() const @@ -257,7 +257,7 @@ void GLGizmoRotate::render_snap_radii() const ::glVertex3f((GLfloat)in_x, (GLfloat)in_y, (GLfloat)in_z); ::glVertex3f((GLfloat)out_x, (GLfloat)out_y, (GLfloat)out_z); } - ::glEnd(); + glsafe(::glEnd()); } void GLGizmoRotate::render_reference_radius() const @@ -265,7 +265,7 @@ void GLGizmoRotate::render_reference_radius() const ::glBegin(GL_LINES); ::glVertex3f(0.0f, 0.0f, 0.0f); ::glVertex3f((GLfloat)(m_radius * (1.0f + GrabberOffset)), 0.0f, 0.0f); - ::glEnd(); + glsafe(::glEnd()); } void GLGizmoRotate::render_angle() const @@ -282,7 +282,7 @@ void GLGizmoRotate::render_angle() const float z = 0.0f; ::glVertex3f((GLfloat)x, (GLfloat)y, (GLfloat)z); } - ::glEnd(); + glsafe(::glEnd()); } void GLGizmoRotate::render_grabber(const BoundingBoxf3& box) const @@ -291,12 +291,12 @@ void GLGizmoRotate::render_grabber(const BoundingBoxf3& box) const m_grabbers[0].center = Vec3d(::cos(m_angle) * grabber_radius, ::sin(m_angle) * grabber_radius, 0.0); m_grabbers[0].angles(2) = m_angle; - ::glColor3fv((m_hover_id != -1) ? m_drag_color : m_highlight_color); + glsafe(::glColor3fv((m_hover_id != -1) ? m_drag_color : m_highlight_color)); ::glBegin(GL_LINES); ::glVertex3f(0.0f, 0.0f, 0.0f); ::glVertex3dv(m_grabbers[0].center.data()); - ::glEnd(); + glsafe(::glEnd()); ::memcpy((void*)m_grabbers[0].color, (const void*)m_highlight_color, 3 * sizeof(float)); render_grabbers(box); @@ -320,56 +320,56 @@ void GLGizmoRotate::render_grabber_extension(const BoundingBoxf3& box, bool pick } if (!picking) - ::glEnable(GL_LIGHTING); + glsafe(::glEnable(GL_LIGHTING)); - ::glColor3fv(color); - ::glPushMatrix(); - ::glTranslated(m_grabbers[0].center(0), m_grabbers[0].center(1), m_grabbers[0].center(2)); - ::glRotated(Geometry::rad2deg(m_angle), 0.0, 0.0, 1.0); - ::glRotated(90.0, 1.0, 0.0, 0.0); - ::glTranslated(0.0, 0.0, 2.0 * size); + glsafe(::glColor3fv(color)); + glsafe(::glPushMatrix()); + glsafe(::glTranslated(m_grabbers[0].center(0), m_grabbers[0].center(1), m_grabbers[0].center(2))); + glsafe(::glRotated(Geometry::rad2deg(m_angle), 0.0, 0.0, 1.0)); + glsafe(::glRotated(90.0, 1.0, 0.0, 0.0)); + glsafe(::glTranslated(0.0, 0.0, 2.0 * size)); ::gluQuadricOrientation(m_quadric, GLU_OUTSIDE); ::gluCylinder(m_quadric, 0.75 * size, 0.0, 3.0 * size, 36, 1); ::gluQuadricOrientation(m_quadric, GLU_INSIDE); ::gluDisk(m_quadric, 0.0, 0.75 * size, 36, 1); - ::glPopMatrix(); - ::glPushMatrix(); - ::glTranslated(m_grabbers[0].center(0), m_grabbers[0].center(1), m_grabbers[0].center(2)); - ::glRotated(Geometry::rad2deg(m_angle), 0.0, 0.0, 1.0); - ::glRotated(-90.0, 1.0, 0.0, 0.0); - ::glTranslated(0.0, 0.0, 2.0 * size); + glsafe(::glPopMatrix()); + glsafe(::glPushMatrix()); + glsafe(::glTranslated(m_grabbers[0].center(0), m_grabbers[0].center(1), m_grabbers[0].center(2))); + glsafe(::glRotated(Geometry::rad2deg(m_angle), 0.0, 0.0, 1.0)); + glsafe(::glRotated(-90.0, 1.0, 0.0, 0.0)); + glsafe(::glTranslated(0.0, 0.0, 2.0 * size)); ::gluQuadricOrientation(m_quadric, GLU_OUTSIDE); ::gluCylinder(m_quadric, 0.75 * size, 0.0, 3.0 * size, 36, 1); ::gluQuadricOrientation(m_quadric, GLU_INSIDE); ::gluDisk(m_quadric, 0.0, 0.75 * size, 36, 1); - ::glPopMatrix(); + glsafe(::glPopMatrix()); if (!picking) - ::glDisable(GL_LIGHTING); + glsafe(::glDisable(GL_LIGHTING)); } void GLGizmoRotate::transform_to_local(const Selection& selection) const { - ::glTranslated(m_center(0), m_center(1), m_center(2)); + glsafe(::glTranslated(m_center(0), m_center(1), m_center(2))); if (selection.is_single_volume() || selection.is_single_modifier() || selection.requires_local_axes()) { Transform3d orient_matrix = selection.get_volume(*selection.get_volume_idxs().begin())->get_instance_transformation().get_matrix(true, false, true, true); - ::glMultMatrixd(orient_matrix.data()); + glsafe(::glMultMatrixd(orient_matrix.data())); } switch (m_axis) { case X: { - ::glRotatef(90.0f, 0.0f, 1.0f, 0.0f); - ::glRotatef(-90.0f, 0.0f, 0.0f, 1.0f); + glsafe(::glRotatef(90.0f, 0.0f, 1.0f, 0.0f)); + glsafe(::glRotatef(-90.0f, 0.0f, 0.0f, 1.0f)); break; } case Y: { - ::glRotatef(-90.0f, 0.0f, 0.0f, 1.0f); - ::glRotatef(-90.0f, 0.0f, 1.0f, 0.0f); + glsafe(::glRotatef(-90.0f, 0.0f, 0.0f, 1.0f)); + glsafe(::glRotatef(-90.0f, 0.0f, 1.0f, 0.0f)); break; } default: @@ -472,7 +472,7 @@ void GLGizmoRotate3D::on_stop_dragging() void GLGizmoRotate3D::on_render(const Selection& selection) const { - ::glClear(GL_DEPTH_BUFFER_BIT); + glsafe(::glClear(GL_DEPTH_BUFFER_BIT)); if ((m_hover_id == -1) || (m_hover_id == 0)) m_gizmos[X].render(selection); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoScale.cpp b/src/slic3r/GUI/Gizmos/GLGizmoScale.cpp index e9f7e2ae2..a4f396934 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoScale.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoScale.cpp @@ -108,8 +108,8 @@ void GLGizmoScale3D::on_render(const Selection& selection) const ((m_hover_id == 6) || (m_hover_id == 7) || (m_hover_id == 8) || (m_hover_id == 9))) set_tooltip("X/Y/Z"); - ::glClear(GL_DEPTH_BUFFER_BIT); - ::glEnable(GL_DEPTH_TEST); + glsafe(::glClear(GL_DEPTH_BUFFER_BIT)); + glsafe(::glEnable(GL_DEPTH_TEST)); BoundingBoxf3 box; Transform3d transform = Transform3d::Identity(); @@ -187,7 +187,7 @@ void GLGizmoScale3D::on_render(const Selection& selection) const m_grabbers[i].angles = angles; } - ::glLineWidth((m_hover_id != -1) ? 2.0f : 1.5f); + glsafe(::glLineWidth((m_hover_id != -1) ? 2.0f : 1.5f)); const BoundingBoxf3& selection_box = selection.get_bounding_box(); @@ -198,20 +198,20 @@ void GLGizmoScale3D::on_render(const Selection& selection) const // draw connections if (m_grabbers[0].enabled && m_grabbers[1].enabled) { - ::glColor3fv(m_grabbers[0].color); + glsafe(::glColor3fv(m_grabbers[0].color)); render_grabbers_connection(0, 1); } if (m_grabbers[2].enabled && m_grabbers[3].enabled) { - ::glColor3fv(m_grabbers[2].color); + glsafe(::glColor3fv(m_grabbers[2].color)); render_grabbers_connection(2, 3); } if (m_grabbers[4].enabled && m_grabbers[5].enabled) { - ::glColor3fv(m_grabbers[4].color); + glsafe(::glColor3fv(m_grabbers[4].color)); render_grabbers_connection(4, 5); } - ::glColor3fv(m_base_color); + glsafe(::glColor3fv(m_base_color)); render_grabbers_connection(6, 7); render_grabbers_connection(7, 8); render_grabbers_connection(8, 9); @@ -222,7 +222,7 @@ void GLGizmoScale3D::on_render(const Selection& selection) const else if ((m_hover_id == 0) || (m_hover_id == 1)) { // draw connection - ::glColor3fv(m_grabbers[0].color); + glsafe(::glColor3fv(m_grabbers[0].color)); render_grabbers_connection(0, 1); // draw grabbers m_grabbers[0].render(true, grabber_mean_size); @@ -231,7 +231,7 @@ void GLGizmoScale3D::on_render(const Selection& selection) const else if ((m_hover_id == 2) || (m_hover_id == 3)) { // draw connection - ::glColor3fv(m_grabbers[2].color); + glsafe(::glColor3fv(m_grabbers[2].color)); render_grabbers_connection(2, 3); // draw grabbers m_grabbers[2].render(true, grabber_mean_size); @@ -240,7 +240,7 @@ void GLGizmoScale3D::on_render(const Selection& selection) const else if ((m_hover_id == 4) || (m_hover_id == 5)) { // draw connection - ::glColor3fv(m_grabbers[4].color); + glsafe(::glColor3fv(m_grabbers[4].color)); render_grabbers_connection(4, 5); // draw grabbers m_grabbers[4].render(true, grabber_mean_size); @@ -249,7 +249,7 @@ void GLGizmoScale3D::on_render(const Selection& selection) const else if (m_hover_id >= 6) { // draw connection - ::glColor3fv(m_drag_color); + glsafe(::glColor3fv(m_drag_color)); render_grabbers_connection(6, 7); render_grabbers_connection(7, 8); render_grabbers_connection(8, 9); @@ -264,7 +264,7 @@ void GLGizmoScale3D::on_render(const Selection& selection) const void GLGizmoScale3D::on_render_for_picking(const Selection& selection) const { - ::glDisable(GL_DEPTH_TEST); + glsafe(::glDisable(GL_DEPTH_TEST)); render_grabbers_for_picking(selection.get_bounding_box()); } @@ -291,7 +291,7 @@ void GLGizmoScale3D::render_grabbers_connection(unsigned int id_1, unsigned int ::glBegin(GL_LINES); ::glVertex3dv(m_grabbers[id_1].center.data()); ::glVertex3dv(m_grabbers[id_2].center.data()); - ::glEnd(); + glsafe(::glEnd()); } } diff --git a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp index 0f6713e0d..ae3d3ee1e 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoSlaSupports.cpp @@ -75,13 +75,13 @@ void GLGizmoSlaSupports::set_sla_support_data(ModelObject* model_object, const S void GLGizmoSlaSupports::on_render(const Selection& selection) const { - ::glEnable(GL_BLEND); - ::glEnable(GL_DEPTH_TEST); + glsafe(::glEnable(GL_BLEND)); + glsafe(::glEnable(GL_DEPTH_TEST)); render_points(selection, false); render_selection_rectangle(); - ::glDisable(GL_BLEND); + glsafe(::glDisable(GL_BLEND)); } void GLGizmoSlaSupports::render_selection_rectangle() const @@ -89,44 +89,44 @@ void GLGizmoSlaSupports::render_selection_rectangle() const if (!m_selection_rectangle_active) return; - ::glLineWidth(1.5f); + glsafe(::glLineWidth(1.5f)); float render_color[3] = {1.f, 0.f, 0.f}; - ::glColor3fv(render_color); + glsafe(::glColor3fv(render_color)); - ::glPushAttrib(GL_TRANSFORM_BIT); // remember current MatrixMode + glsafe(::glPushAttrib(GL_TRANSFORM_BIT)); // remember current MatrixMode - ::glMatrixMode(GL_MODELVIEW); // cache modelview matrix and set to identity - ::glPushMatrix(); - ::glLoadIdentity(); + glsafe(::glMatrixMode(GL_MODELVIEW)); // cache modelview matrix and set to identity + glsafe(::glPushMatrix()); + glsafe(::glLoadIdentity()); - ::glMatrixMode(GL_PROJECTION); // cache projection matrix and set to identity - ::glPushMatrix(); - ::glLoadIdentity(); + glsafe(::glMatrixMode(GL_PROJECTION)); // cache projection matrix and set to identity + glsafe(::glPushMatrix()); + glsafe(::glLoadIdentity()); - ::glOrtho(0.f, m_canvas_width, m_canvas_height, 0.f, -1.f, 1.f); // set projection matrix so that world coords = window coords + glsafe(::glOrtho(0.f, m_canvas_width, m_canvas_height, 0.f, -1.f, 1.f)); // set projection matrix so that world coords = window coords // render the selection rectangle (window coordinates): - ::glPushAttrib(GL_ENABLE_BIT); - ::glLineStipple(4, 0xAAAA); - ::glEnable(GL_LINE_STIPPLE); + glsafe(::glPushAttrib(GL_ENABLE_BIT)); + glsafe(::glLineStipple(4, 0xAAAA)); + glsafe(::glEnable(GL_LINE_STIPPLE)); ::glBegin(GL_LINE_LOOP); ::glVertex3f((GLfloat)m_selection_rectangle_start_corner(0), (GLfloat)m_selection_rectangle_start_corner(1), (GLfloat)0.5f); ::glVertex3f((GLfloat)m_selection_rectangle_end_corner(0), (GLfloat)m_selection_rectangle_start_corner(1), (GLfloat)0.5f); ::glVertex3f((GLfloat)m_selection_rectangle_end_corner(0), (GLfloat)m_selection_rectangle_end_corner(1), (GLfloat)0.5f); ::glVertex3f((GLfloat)m_selection_rectangle_start_corner(0), (GLfloat)m_selection_rectangle_end_corner(1), (GLfloat)0.5f); - ::glEnd(); - ::glPopAttrib(); + glsafe(::glEnd()); + glsafe(::glPopAttrib()); - ::glPopMatrix(); // restore former projection matrix - ::glMatrixMode(GL_MODELVIEW); - ::glPopMatrix(); // restore former modelview matrix - ::glPopAttrib(); // restore former MatrixMode + glsafe(::glPopMatrix()); // restore former projection matrix + glsafe(::glMatrixMode(GL_MODELVIEW)); + glsafe(::glPopMatrix()); // restore former modelview matrix + glsafe(::glPopAttrib()); // restore former MatrixMode } void GLGizmoSlaSupports::on_render_for_picking(const Selection& selection) const { - ::glEnable(GL_DEPTH_TEST); + glsafe(::glEnable(GL_DEPTH_TEST)); render_points(selection, true); } @@ -137,16 +137,16 @@ void GLGizmoSlaSupports::render_points(const Selection& selection, bool picking) return; if (!picking) - ::glEnable(GL_LIGHTING); + glsafe(::glEnable(GL_LIGHTING)); const GLVolume* vol = selection.get_volume(*selection.get_volume_idxs().begin()); double z_shift = vol->get_sla_shift_z(); const Transform3d& instance_scaling_matrix_inverse = vol->get_instance_transformation().get_matrix(true, true, false, true).inverse(); const Transform3d& instance_matrix = vol->get_instance_transformation().get_matrix(); - ::glPushMatrix(); - ::glTranslated(0.0, 0.0, z_shift); - ::glMultMatrixd(instance_matrix.data()); + glsafe(::glPushMatrix()); + glsafe(::glTranslated(0.0, 0.0, z_shift)); + glsafe(::glMultMatrixd(instance_matrix.data())); float render_color[3]; for (int i = 0; i < (int)m_editing_mode_cache.size(); ++i) @@ -178,14 +178,14 @@ void GLGizmoSlaSupports::render_points(const Selection& selection, bool picking) for (unsigned char i=0; i<3; ++i) render_color[i] = 0.5f; } } - ::glColor3fv(render_color); + glsafe(::glColor3fv(render_color)); float render_color_emissive[4] = { 0.5f * render_color[0], 0.5f * render_color[1], 0.5f * render_color[2], 1.f}; - ::glMaterialfv(GL_FRONT, GL_EMISSION, render_color_emissive); + glsafe(::glMaterialfv(GL_FRONT, GL_EMISSION, render_color_emissive)); // Inverse matrix of the instance scaling is applied so that the mark does not scale with the object. - ::glPushMatrix(); - ::glTranslated(support_point.pos(0), support_point.pos(1), support_point.pos(2)); - ::glMultMatrixd(instance_scaling_matrix_inverse.data()); + glsafe(::glPushMatrix()); + glsafe(::glTranslated(support_point.pos(0), support_point.pos(1), support_point.pos(2))); + glsafe(::glMultMatrixd(instance_scaling_matrix_inverse.data())); // Matrices set, we can render the point mark now. // If in editing mode, we'll also render a cone pointing to the sphere. @@ -196,31 +196,31 @@ void GLGizmoSlaSupports::render_points(const Selection& selection, bool picking) Eigen::Quaterniond q; q.setFromTwoVectors(Vec3d{0., 0., 1.}, instance_scaling_matrix_inverse * m_editing_mode_cache[i].normal.cast()); Eigen::AngleAxisd aa(q); - ::glRotated(aa.angle() * (180./M_PI), aa.axis()(0), aa.axis()(1), aa.axis()(2)); + glsafe(::glRotated(aa.angle() * (180. / M_PI), aa.axis()(0), aa.axis()(1), aa.axis()(2))); const float cone_radius = 0.25f; // mm const float cone_height = 0.75f; - ::glPushMatrix(); - ::glTranslatef(0.f, 0.f, m_editing_mode_cache[i].support_point.head_front_radius * RenderPointScale); + glsafe(::glPushMatrix()); + glsafe(::glTranslatef(0.f, 0.f, m_editing_mode_cache[i].support_point.head_front_radius * RenderPointScale)); ::gluCylinder(m_quadric, 0.f, cone_radius, cone_height, 24, 1); - ::glTranslatef(0.f, 0.f, cone_height); + glsafe(::glTranslatef(0.f, 0.f, cone_height)); ::gluDisk(m_quadric, 0.0, cone_radius, 24, 1); - ::glPopMatrix(); + glsafe(::glPopMatrix()); } ::gluSphere(m_quadric, m_editing_mode_cache[i].support_point.head_front_radius * RenderPointScale, 24, 12); - ::glPopMatrix(); + glsafe(::glPopMatrix()); } { // Reset emissive component to zero (the default value) float render_color_emissive[4] = { 0.f, 0.f, 0.f, 1.f }; - ::glMaterialfv(GL_FRONT, GL_EMISSION, render_color_emissive); + glsafe(::glMaterialfv(GL_FRONT, GL_EMISSION, render_color_emissive)); } if (!picking) - ::glDisable(GL_LIGHTING); + glsafe(::glDisable(GL_LIGHTING)); - ::glPopMatrix(); + glsafe(::glPopMatrix()); } bool GLGizmoSlaSupports::is_mesh_update_necessary() const @@ -264,11 +264,11 @@ std::pair GLGizmoSlaSupports::unproject_on_mesh(const Vec2d& mouse update_mesh(); Eigen::Matrix viewport; - ::glGetIntegerv(GL_VIEWPORT, viewport.data()); + glsafe(::glGetIntegerv(GL_VIEWPORT, viewport.data())); Eigen::Matrix modelview_matrix; - ::glGetDoublev(GL_MODELVIEW_MATRIX, modelview_matrix.data()); + glsafe(::glGetDoublev(GL_MODELVIEW_MATRIX, modelview_matrix.data())); Eigen::Matrix projection_matrix; - ::glGetDoublev(GL_PROJECTION_MATRIX, projection_matrix.data()); + glsafe(::glGetDoublev(GL_PROJECTION_MATRIX, projection_matrix.data())); Vec3d point1; Vec3d point2; @@ -356,11 +356,11 @@ bool GLGizmoSlaSupports::gizmo_event(SLAGizmoEventType action, const Vec2d& mous if ((action == SLAGizmoEventType::LeftUp || action == SLAGizmoEventType::ShiftUp) && m_selection_rectangle_active) { const Transform3d& instance_matrix = m_model_object->instances[m_active_instance]->get_transformation().get_matrix(); GLint viewport[4]; - ::glGetIntegerv(GL_VIEWPORT, viewport); + glsafe(::glGetIntegerv(GL_VIEWPORT, viewport)); GLdouble modelview_matrix[16]; - ::glGetDoublev(GL_MODELVIEW_MATRIX, modelview_matrix); + glsafe(::glGetDoublev(GL_MODELVIEW_MATRIX, modelview_matrix)); GLdouble projection_matrix[16]; - ::glGetDoublev(GL_PROJECTION_MATRIX, projection_matrix); + glsafe(::glGetDoublev(GL_PROJECTION_MATRIX, projection_matrix)); const Selection& selection = m_parent.get_selection(); const GLVolume* volume = selection.get_volume(*selection.get_volume_idxs().begin()); diff --git a/src/slic3r/GUI/ImGuiWrapper.cpp b/src/slic3r/GUI/ImGuiWrapper.cpp index 0932c8ce9..46379d616 100644 --- a/src/slic3r/GUI/ImGuiWrapper.cpp +++ b/src/slic3r/GUI/ImGuiWrapper.cpp @@ -19,6 +19,7 @@ #include "libslic3r/libslic3r.h" #include "libslic3r/Utils.hpp" +#include "3DScene.hpp" #include "GUI.hpp" namespace Slic3r { @@ -360,19 +361,19 @@ void ImGuiWrapper::create_fonts_texture() // Upload texture to graphics system GLint last_texture; - glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture); - glGenTextures(1, &m_font_texture); - glBindTexture(GL_TEXTURE_2D, m_font_texture); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); + glsafe(::glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture)); + glsafe(::glGenTextures(1, &m_font_texture)); + glsafe(::glBindTexture(GL_TEXTURE_2D, m_font_texture)); + glsafe(::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); + glsafe(::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); + glsafe(::glPixelStorei(GL_UNPACK_ROW_LENGTH, 0)); + glsafe(::glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels)); // Store our identifier io.Fonts->TexID = (ImTextureID)(intptr_t)m_font_texture; // Restore state - glBindTexture(GL_TEXTURE_2D, last_texture); + glsafe(::glBindTexture(GL_TEXTURE_2D, last_texture)); } void ImGuiWrapper::init_input() @@ -467,39 +468,39 @@ void ImGuiWrapper::render_draw_data(ImDrawData *draw_data) // We are using the OpenGL fixed pipeline to make the example code simpler to read! // Setup render state: alpha-blending enabled, no face culling, no depth testing, scissor enabled, vertex/texcoord/color pointers, polygon fill. - GLint last_texture; glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture); - GLint last_polygon_mode[2]; glGetIntegerv(GL_POLYGON_MODE, last_polygon_mode); - GLint last_viewport[4]; glGetIntegerv(GL_VIEWPORT, last_viewport); - GLint last_scissor_box[4]; glGetIntegerv(GL_SCISSOR_BOX, last_scissor_box); - glPushAttrib(GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT | GL_TRANSFORM_BIT); - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glDisable(GL_CULL_FACE); - glDisable(GL_DEPTH_TEST); - glDisable(GL_LIGHTING); - glDisable(GL_COLOR_MATERIAL); - glEnable(GL_SCISSOR_TEST); - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glEnableClientState(GL_COLOR_ARRAY); - glEnable(GL_TEXTURE_2D); - glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); - glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + GLint last_texture; glsafe(::glGetIntegerv(GL_TEXTURE_BINDING_2D, &last_texture)); + GLint last_polygon_mode[2]; glsafe(::glGetIntegerv(GL_POLYGON_MODE, last_polygon_mode)); + GLint last_viewport[4]; glsafe(::glGetIntegerv(GL_VIEWPORT, last_viewport)); + GLint last_scissor_box[4]; glsafe(::glGetIntegerv(GL_SCISSOR_BOX, last_scissor_box)); + glsafe(::glPushAttrib(GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT | GL_TRANSFORM_BIT)); + glsafe(::glEnable(GL_BLEND)); + glsafe(::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); + glsafe(::glDisable(GL_CULL_FACE)); + glsafe(::glDisable(GL_DEPTH_TEST)); + glsafe(::glDisable(GL_LIGHTING)); + glsafe(::glDisable(GL_COLOR_MATERIAL)); + glsafe(::glEnable(GL_SCISSOR_TEST)); + glsafe(::glEnableClientState(GL_VERTEX_ARRAY)); + glsafe(::glEnableClientState(GL_TEXTURE_COORD_ARRAY)); + glsafe(::glEnableClientState(GL_COLOR_ARRAY)); + glsafe(::glEnable(GL_TEXTURE_2D)); + glsafe(::glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)); + glsafe(::glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE)); GLint texture_env_mode = GL_MODULATE; - glGetTexEnviv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, &texture_env_mode); - glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + glsafe(::glGetTexEnviv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, &texture_env_mode)); + glsafe(::glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE)); //glUseProgram(0); // You may want this if using this code in an OpenGL 3+ context where shaders may be bound // Setup viewport, orthographic projection matrix // Our visible imgui space lies from draw_data->DisplayPps (top left) to draw_data->DisplayPos+data_data->DisplaySize (bottom right). DisplayMin is typically (0,0) for single viewport apps. - glViewport(0, 0, (GLsizei)fb_width, (GLsizei)fb_height); - glMatrixMode(GL_PROJECTION); - glPushMatrix(); - glLoadIdentity(); - glOrtho(draw_data->DisplayPos.x, draw_data->DisplayPos.x + draw_data->DisplaySize.x, draw_data->DisplayPos.y + draw_data->DisplaySize.y, draw_data->DisplayPos.y, -1.0f, +1.0f); - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - glLoadIdentity(); + glsafe(::glViewport(0, 0, (GLsizei)fb_width, (GLsizei)fb_height)); + glsafe(::glMatrixMode(GL_PROJECTION)); + glsafe(::glPushMatrix()); + glsafe(::glLoadIdentity()); + glsafe(::glOrtho(draw_data->DisplayPos.x, draw_data->DisplayPos.x + draw_data->DisplaySize.x, draw_data->DisplayPos.y + draw_data->DisplaySize.y, draw_data->DisplayPos.y, -1.0f, +1.0f)); + glsafe(::glMatrixMode(GL_MODELVIEW)); + glsafe(::glPushMatrix()); + glsafe(::glLoadIdentity()); // Render command lists ImVec2 pos = draw_data->DisplayPos; @@ -508,9 +509,9 @@ void ImGuiWrapper::render_draw_data(ImDrawData *draw_data) const ImDrawList* cmd_list = draw_data->CmdLists[n]; const ImDrawVert* vtx_buffer = cmd_list->VtxBuffer.Data; const ImDrawIdx* idx_buffer = cmd_list->IdxBuffer.Data; - glVertexPointer(2, GL_FLOAT, sizeof(ImDrawVert), (const GLvoid*)((const char*)vtx_buffer + IM_OFFSETOF(ImDrawVert, pos))); - glTexCoordPointer(2, GL_FLOAT, sizeof(ImDrawVert), (const GLvoid*)((const char*)vtx_buffer + IM_OFFSETOF(ImDrawVert, uv))); - glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(ImDrawVert), (const GLvoid*)((const char*)vtx_buffer + IM_OFFSETOF(ImDrawVert, col))); + glsafe(::glVertexPointer(2, GL_FLOAT, sizeof(ImDrawVert), (const GLvoid*)((const char*)vtx_buffer + IM_OFFSETOF(ImDrawVert, pos)))); + glsafe(::glTexCoordPointer(2, GL_FLOAT, sizeof(ImDrawVert), (const GLvoid*)((const char*)vtx_buffer + IM_OFFSETOF(ImDrawVert, uv)))); + glsafe(::glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(ImDrawVert), (const GLvoid*)((const char*)vtx_buffer + IM_OFFSETOF(ImDrawVert, col)))); for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++) { @@ -526,11 +527,11 @@ void ImGuiWrapper::render_draw_data(ImDrawData *draw_data) if (clip_rect.x < fb_width && clip_rect.y < fb_height && clip_rect.z >= 0.0f && clip_rect.w >= 0.0f) { // Apply scissor/clipping rectangle - glScissor((int)clip_rect.x, (int)(fb_height - clip_rect.w), (int)(clip_rect.z - clip_rect.x), (int)(clip_rect.w - clip_rect.y)); + glsafe(::glScissor((int)clip_rect.x, (int)(fb_height - clip_rect.w), (int)(clip_rect.z - clip_rect.x), (int)(clip_rect.w - clip_rect.y))); // Bind texture, Draw - glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->TextureId); - glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, idx_buffer); + glsafe(::glBindTexture(GL_TEXTURE_2D, (GLuint)(intptr_t)pcmd->TextureId)); + glsafe(::glDrawElements(GL_TRIANGLES, (GLsizei)pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT, idx_buffer)); } } idx_buffer += pcmd->ElemCount; @@ -538,19 +539,19 @@ void ImGuiWrapper::render_draw_data(ImDrawData *draw_data) } // Restore modified state - glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, texture_env_mode); - glDisableClientState(GL_COLOR_ARRAY); - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - glDisableClientState(GL_VERTEX_ARRAY); - glBindTexture(GL_TEXTURE_2D, (GLuint)last_texture); - glMatrixMode(GL_MODELVIEW); - glPopMatrix(); - glMatrixMode(GL_PROJECTION); - glPopMatrix(); - glPopAttrib(); - glPolygonMode(GL_FRONT, (GLenum)last_polygon_mode[0]); glPolygonMode(GL_BACK, (GLenum)last_polygon_mode[1]); - glViewport(last_viewport[0], last_viewport[1], (GLsizei)last_viewport[2], (GLsizei)last_viewport[3]); - glScissor(last_scissor_box[0], last_scissor_box[1], (GLsizei)last_scissor_box[2], (GLsizei)last_scissor_box[3]); + glsafe(::glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, texture_env_mode)); + glsafe(::glDisableClientState(GL_COLOR_ARRAY)); + glsafe(::glDisableClientState(GL_TEXTURE_COORD_ARRAY)); + glsafe(::glDisableClientState(GL_VERTEX_ARRAY)); + glsafe(::glBindTexture(GL_TEXTURE_2D, (GLuint)last_texture)); + glsafe(::glMatrixMode(GL_MODELVIEW)); + glsafe(::glPopMatrix()); + glsafe(::glMatrixMode(GL_PROJECTION)); + glsafe(::glPopMatrix()); + glsafe(::glPopAttrib()); + glsafe(::glPolygonMode(GL_FRONT, (GLenum)last_polygon_mode[0]); glPolygonMode(GL_BACK, (GLenum)last_polygon_mode[1])); + glsafe(::glViewport(last_viewport[0], last_viewport[1], (GLsizei)last_viewport[2], (GLsizei)last_viewport[3])); + glsafe(::glScissor(last_scissor_box[0], last_scissor_box[1], (GLsizei)last_scissor_box[2], (GLsizei)last_scissor_box[3])); } bool ImGuiWrapper::display_initialized() const @@ -569,7 +570,7 @@ void ImGuiWrapper::destroy_fonts_texture() if (m_font_texture) { ImGuiIO& io = ImGui::GetIO(); io.Fonts->TexID = 0; - glDeleteTextures(1, &m_font_texture); + glsafe(::glDeleteTextures(1, &m_font_texture)); m_font_texture = 0; } }