Skip to content

Commit

Permalink
Change glReadPixels(GL_DEPTH_COMPONENT) from flaot to int: better per…
Browse files Browse the repository at this point in the history
…formance & compatibility

#2864
  • Loading branch information
supermerill committed Jun 4, 2024
1 parent 9f4e2c0 commit 12c3f49
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/slic3r/GUI/GLCanvas3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5922,11 +5922,20 @@ Vec3d GLCanvas3D::_mouse_to_3d(const Point& mouse_pos, float* z)
Vec4i32 viewport(camera.get_viewport().data());

GLint y = viewport[3] - (GLint)mouse_pos(1);
GLfloat mouse_z;
if (z == nullptr)
glsafe(::glReadPixels((GLint)mouse_pos(0), y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, (void*)&mouse_z));
else
double mouse_z;
if (z == nullptr) {
GLuint render_z;
if(sizeof(render_z)==2)
glsafe(::glReadPixels((GLint) mouse_pos(0), y, 1, 1, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, (void *) &render_z));
else if(sizeof(render_z)==4)
glsafe(::glReadPixels((GLint) mouse_pos(0), y, 1, 1, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, (void *) &render_z));
else {
BOOST_LOG_TRIVIAL(error) << "error, opengl depth buffer of odd size.";
}
mouse_z = (double(render_z)/std::numeric_limits<GLuint>::max());
} else {
mouse_z = *z;
}

Vec3d out;
igl::unproject(Vec3d(mouse_pos(0), y, mouse_z), modelview, projection, viewport, out);
Expand Down

0 comments on commit 12c3f49

Please sign in to comment.