350 this->viewMatrix * glm::mat4_cast(this->modelQuaternion), |
350 this->viewMatrix * glm::mat4_cast(this->modelQuaternion), |
351 this->projectionMatrix, |
351 this->projectionMatrix, |
352 viewportVector); |
352 viewportVector); |
353 } |
353 } |
354 |
354 |
355 ldraw::id_t PartRenderer::pick(const QPoint& where) |
355 ldraw::id_t PartRenderer::pick(QPoint where) |
356 { |
356 { |
|
357 // y is flipped, take that into account |
|
358 where.setY(this->height() - where.y()); |
|
359 // Since we are dealing with pixel data right from the framebuffer, its size |
|
360 // will be affected by High DPI scaling. We need to take this into account |
|
361 // and multiply the pixel positions by the screen pixel scaling factor. |
|
362 where *= this->devicePixelRatioF(); |
357 const gl::RenderStyle oldRenderStyle = this->renderPreferences.style; |
363 const gl::RenderStyle oldRenderStyle = this->renderPreferences.style; |
358 this->renderPreferences.style = gl::RenderStyle::PickScene; |
364 this->renderPreferences.style = gl::RenderStyle::PickScene; |
359 this->makeCurrent(); |
365 this->makeCurrent(); |
360 this->renderScene(); |
366 this->renderScene(); |
361 std::array<GLubyte, 3> data; |
367 std::array<GLubyte, 3> data; |
362 this->checkForGLErrors(); |
368 this->checkForGLErrors(); |
363 glReadPixels(where.x(), this->height() - where.y(), 1, 1, GL_RGB, GL_UNSIGNED_BYTE, &data[0]); |
369 glfunc.glReadPixels(where.x(), where.y(), 1, 1, GL_RGB, GL_UNSIGNED_BYTE, &data[0]); |
364 this->checkForGLErrors(); |
370 this->checkForGLErrors(); |
365 this->renderPreferences.style = oldRenderStyle; |
371 this->renderPreferences.style = oldRenderStyle; |
366 this->update(); |
372 this->update(); |
367 return gl::idFromColor(data); |
373 return gl::idFromColor(data); |
368 } |
374 } |