# HG changeset patch # User Teemu Piippo # Date 1653500194 -10800 # Node ID 6988973515d24ef19d99e14575382625293ba932 # Parent eb9d900dc79add2ad8a1d5cedc57c95b9f1902b0 Fix pick() picking from weird places on the screen with high DPI scaling glReadPixels reads data from the frame buffer, which contains data after high DPI scaling, so any reads to that need to take this scaling into account diff -r eb9d900dc79a -r 6988973515d2 src/gl/partrenderer.cpp --- a/src/gl/partrenderer.cpp Wed May 25 18:33:38 2022 +0300 +++ b/src/gl/partrenderer.cpp Wed May 25 20:36:34 2022 +0300 @@ -352,15 +352,21 @@ viewportVector); } -ldraw::id_t PartRenderer::pick(const QPoint& where) +ldraw::id_t PartRenderer::pick(QPoint where) { + // y is flipped, take that into account + where.setY(this->height() - where.y()); + // Since we are dealing with pixel data right from the framebuffer, its size + // will be affected by High DPI scaling. We need to take this into account + // and multiply the pixel positions by the screen pixel scaling factor. + where *= this->devicePixelRatioF(); const gl::RenderStyle oldRenderStyle = this->renderPreferences.style; this->renderPreferences.style = gl::RenderStyle::PickScene; this->makeCurrent(); this->renderScene(); std::array data; this->checkForGLErrors(); - glReadPixels(where.x(), this->height() - where.y(), 1, 1, GL_RGB, GL_UNSIGNED_BYTE, &data[0]); + glfunc.glReadPixels(where.x(), where.y(), 1, 1, GL_RGB, GL_UNSIGNED_BYTE, &data[0]); this->checkForGLErrors(); this->renderPreferences.style = oldRenderStyle; this->update(); diff -r eb9d900dc79a -r 6988973515d2 src/gl/partrenderer.h --- a/src/gl/partrenderer.h Wed May 25 18:33:38 2022 +0300 +++ b/src/gl/partrenderer.h Wed May 25 20:36:34 2022 +0300 @@ -24,7 +24,7 @@ void setRenderPreferences(const gl::RenderPreferences& newPreferences); ldraw::id_t getHighlightedObject() const; protected: - ldraw::id_t pick(const QPoint& where); + ldraw::id_t pick(QPoint where); void initializeGL() override; void resizeGL(int width, int height) override; void paintGL() override;