mirror of https://github.com/CGAL/cgal
Add a function read_depth_under_pixel
The function takes care of HiDPI screen, using `devicePixelRatio()`.
This commit is contained in:
parent
9ade574b1a
commit
225e3c2217
|
|
@ -18,6 +18,7 @@
|
|||
#include <CGAL/Qt/quaternion.h>
|
||||
#include <CGAL/export/Qt.h>
|
||||
#include <QOpenGLFunctions_2_1>
|
||||
#include <QOpenGLFunctions>
|
||||
|
||||
namespace CGAL{
|
||||
class QGLViewer;
|
||||
|
|
@ -469,6 +470,16 @@ private:
|
|||
KeyFrameInterpolator *interpolationKfi_;
|
||||
};
|
||||
|
||||
inline float read_depth_under_pixel(const QPoint &pixel, QOpenGLFunctions *p,
|
||||
const Camera *camera) {
|
||||
float depth = 2.0f;
|
||||
const auto pixel_ratio = camera->devicePixelRatio();
|
||||
p->glReadPixels(pixel.x() * pixel_ratio,
|
||||
(camera->screenHeight() - 1 - pixel.y()) * pixel_ratio, 1, 1,
|
||||
GL_DEPTH_COMPONENT, GL_FLOAT, &depth);
|
||||
return depth;
|
||||
}
|
||||
|
||||
} // namespace qglviewer
|
||||
} //CGAL
|
||||
#endif // QGLVIEWER_CAMERA_H
|
||||
|
|
|
|||
|
|
@ -885,8 +885,7 @@ Vec Camera::pointUnderPixel(const QPoint &pixel, bool &found) const {
|
|||
// Qt uses upper corner for its origin while GL uses the lower corner.
|
||||
if(auto p = dynamic_cast<QOpenGLFunctions*>(parent()))
|
||||
{
|
||||
p->glReadPixels(pixel.x(), screenHeight() - 1 - pixel.y(), 1, 1,
|
||||
GL_DEPTH_COMPONENT, GL_FLOAT, &depth);
|
||||
depth = read_depth_under_pixel(pixel, p, this);
|
||||
}
|
||||
found = depth < 1.0;
|
||||
Vec point(pixel.x(), pixel.y(), depth);
|
||||
|
|
|
|||
|
|
@ -564,7 +564,7 @@ void Scene::renderScene(const QList<Scene_interface::Item_id> &items,
|
|||
|
||||
// read depth buffer at pick location;
|
||||
float depth = 1.0;
|
||||
viewer->glReadPixels(picked_pixel.x(),viewer->camera()->screenHeight()-1-picked_pixel.y(),1,1,GL_DEPTH_COMPONENT, GL_FLOAT, &depth);
|
||||
depth = read_depth_under_pixel(picked_pixel, viewer, viewer->camera());
|
||||
if (depth != 1.0)
|
||||
{
|
||||
//add object to list of picked objects;
|
||||
|
|
@ -634,7 +634,7 @@ void Scene::renderWireScene(const QList<Scene_interface::Item_id> &items,
|
|||
|
||||
// read depth buffer at pick location;
|
||||
float depth = 1.0;
|
||||
viewer->glReadPixels(picked_pixel.x(),viewer->camera()->screenHeight()-1-picked_pixel.y(),1,1,GL_DEPTH_COMPONENT, GL_FLOAT, &depth);
|
||||
depth = read_depth_under_pixel(picked_pixel, viewer, viewer->camera());
|
||||
if (depth != 1.0)
|
||||
{
|
||||
//add object to list of picked objects;
|
||||
|
|
@ -676,7 +676,7 @@ void Scene::renderPointScene(const QList<Scene_interface::Item_id> &items,
|
|||
if(item.renderingMode() == Points && with_names) {
|
||||
// read depth buffer at pick location;
|
||||
float depth = 1.0;
|
||||
viewer->glReadPixels(picked_pixel.x(),viewer->camera()->screenHeight()-1-picked_pixel.y(),1,1,GL_DEPTH_COMPONENT, GL_FLOAT, &depth);
|
||||
depth = read_depth_under_pixel(picked_pixel, viewer, viewer->camera());
|
||||
if (depth != 1.0)
|
||||
{
|
||||
//add object to list of picked objects;
|
||||
|
|
|
|||
|
|
@ -211,7 +211,7 @@ void Scene_group_item::renderChildren(Viewer_interface *viewer,
|
|||
if(with_names) {
|
||||
// read depth buffer at pick location;
|
||||
float depth = 1.0;
|
||||
viewer->glReadPixels(picked_pixel.x(),viewer->camera()->screenHeight()-1-picked_pixel.y(),1,1,GL_DEPTH_COMPONENT, GL_FLOAT, &depth);
|
||||
depth = read_depth_under_pixel(picked_pixel, viewer, viewer->camera());
|
||||
if (depth != 1.0)
|
||||
{
|
||||
//add object to list of picked objects;
|
||||
|
|
|
|||
|
|
@ -1696,9 +1696,9 @@ void Viewer::drawWithNames()
|
|||
rendering_program.release();
|
||||
|
||||
//read depth and store in map
|
||||
GLfloat depth = 1.0f;
|
||||
glReadPixels(picking_pos.x(),camera()->screenHeight()-1-picking_pos.y(),1,1,GL_DEPTH_COMPONENT, GL_FLOAT, &depth);
|
||||
if (depth != 1.0)
|
||||
GLfloat depth = 2.0f;
|
||||
depth = read_depth_under_pixel(picking_pos, this, this->camera());
|
||||
if (depth < 2.0f)
|
||||
{
|
||||
picked_IDs[depth] = i;
|
||||
}
|
||||
|
|
@ -1740,9 +1740,9 @@ void Viewer::drawWithNames()
|
|||
rendering_program.release();
|
||||
|
||||
//read depth and store in map
|
||||
GLfloat depth = 1.0f;
|
||||
glReadPixels(picking_pos.x(),camera()->screenHeight()-1-picking_pos.y(),1,1,GL_DEPTH_COMPONENT, GL_FLOAT, &depth);
|
||||
if (depth != 1.0)
|
||||
GLfloat depth = 2.0f;
|
||||
depth = read_depth_under_pixel(picking_pos, this, this->camera());
|
||||
if (depth < 2.0f)
|
||||
{
|
||||
picked_IDs[depth] = -1;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue