Fix fractional scaling issues on skin preview (#4310)

This commit is contained in:
Alexandru Ionut Tripon
2025-11-09 23:15:59 +02:00
committed by GitHub
2 changed files with 16 additions and 0 deletions

View File

@@ -202,6 +202,13 @@ void SkinOpenGLWindow::resizeGL(int w, int h)
void SkinOpenGLWindow::paintGL()
{
// Adjust the viewport to account for fractional scaling
qreal dpr = devicePixelRatio();
if (dpr != 1.f) {
QSize scaledSize = size() * dpr;
glViewport(0, 0, scaledSize.width(), scaledSize.height());
}
// Clear color and depth buffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
@@ -235,6 +242,13 @@ void SkinOpenGLWindow::paintGL()
m_scene->draw(m_modelProgram);
m_modelProgram->release();
// Redraw the first frame; this is necessary because the pixel ratio for Wayland fractional scaling is not negotiated properly on the
// first frame
if (m_isFirstFrame) {
m_isFirstFrame = false;
update();
}
}
void SkinOpenGLWindow::updateScene(SkinModel* skin)

View File

@@ -74,6 +74,8 @@ class SkinOpenGLWindow : public QOpenGLWindow, protected QOpenGLFunctions {
float m_yaw = 90; // Horizontal rotation angle
float m_pitch = 0; // Vertical rotation angle
bool m_isFirstFrame = true;
opengl::BoxGeometry* m_background = nullptr;
QOpenGLTexture* m_backgroundTexture = nullptr;
QColor m_baseColor;