From 9ade574b1adc30c762a8988537f0d680d6f9e869 Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Thu, 12 May 2022 12:13:08 +0200 Subject: [PATCH] Add devicePixelRatio() to Camera --- GraphicsView/include/CGAL/Qt/camera.h | 4 +++- GraphicsView/include/CGAL/Qt/camera_impl.h | 3 ++- GraphicsView/include/CGAL/Qt/qglviewer_impl.h | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/GraphicsView/include/CGAL/Qt/camera.h b/GraphicsView/include/CGAL/Qt/camera.h index bda76bafb05..70f7c8edd8e 100644 --- a/GraphicsView/include/CGAL/Qt/camera.h +++ b/GraphicsView/include/CGAL/Qt/camera.h @@ -199,6 +199,7 @@ public: CGAL::QGLViewer's window dimensions when the Camera is attached to a CGAL::QGLViewer. See also QOpenGLWidget::height() */ int screenHeight() const { return screenHeight_; } + qreal devicePixelRatio() const { return devicePixelRatio_; } void getViewport(GLint viewport[4]) const; qreal pixelGLRatio(const Vec &position) const; @@ -279,7 +280,7 @@ public Q_SLOTS: setScreenWidthAndHeight(int(100.0 * aspect), 100); } - void setScreenWidthAndHeight(int width, int height); + void setScreenWidthAndHeight(int width, int height, qreal devicePixelRatio = 1.0); /*! Sets the zNearCoefficient() value. */ void setZNearCoefficient(qreal coef) { zNearCoef_ = coef; @@ -444,6 +445,7 @@ private: // C a m e r a p a r a m e t e r s int screenWidth_, screenHeight_; // size of the window, in pixels + qreal devicePixelRatio_; qreal fieldOfView_; // in radians Vec sceneCenter_; qreal sceneRadius_; // OpenGL units diff --git a/GraphicsView/include/CGAL/Qt/camera_impl.h b/GraphicsView/include/CGAL/Qt/camera_impl.h index 672e5d91c23..a963e13574d 100644 --- a/GraphicsView/include/CGAL/Qt/camera_impl.h +++ b/GraphicsView/include/CGAL/Qt/camera_impl.h @@ -160,10 +160,11 @@ frustrum coherence. If your Camera is used without a CGAL::QGLViewer (offscreen rendering, shadow maps), use setAspectRatio() instead to define the projection matrix. */ CGAL_INLINE_FUNCTION -void Camera::setScreenWidthAndHeight(int width, int height) { +void Camera::setScreenWidthAndHeight(int width, int height, qreal devicePixelRatio) { // Prevent negative and zero dimensions that would cause divisions by zero. screenWidth_ = width > 0 ? width : 1; screenHeight_ = height > 0 ? height : 1; + devicePixelRatio_ = devicePixelRatio; projectionMatrixIsUpToDate_ = false; } diff --git a/GraphicsView/include/CGAL/Qt/qglviewer_impl.h b/GraphicsView/include/CGAL/Qt/qglviewer_impl.h index 70fdfdd9a15..87c3b4e3a61 100644 --- a/GraphicsView/include/CGAL/Qt/qglviewer_impl.h +++ b/GraphicsView/include/CGAL/Qt/qglviewer_impl.h @@ -807,7 +807,7 @@ void CGAL::QGLViewer::setCamera(qglviewer::Camera *const camera) { camera->setSceneRadius(sceneRadius()); camera->setSceneCenter(sceneCenter()); - camera->setScreenWidthAndHeight(width(), height()); + camera->setScreenWidthAndHeight(width(), height(), devicePixelRatio()); // Disconnect current camera from this viewer. disconnect(this->camera()->frame(), SIGNAL(manipulated()), this, @@ -2369,7 +2369,7 @@ CGAL_INLINE_FUNCTION void CGAL::QGLViewer::resizeGL(int width, int height) { QOpenGLWidget::resizeGL(width, height); glViewport(0, 0, GLint(width), GLint(height)); - camera()->setScreenWidthAndHeight(this->width(), this->height()); + camera()->setScreenWidthAndHeight(this->width(), this->height(), this->devicePixelRatio()); } //////////////////////////////////////////////////////////////////////////