diff options
author | Nadia Holmquist Pedersen <nadia@nhp.sh> | 2021-02-22 18:17:48 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-22 18:17:48 +0100 |
commit | 97643586fafd573b02566ddafb92329c40cb44c4 (patch) | |
tree | 464d2b0e19a806b1c7767878d879055c086d020a | |
parent | 532dc57025c4a9643f708dcfde32ce8cd4b453a9 (diff) |
Fix OpenGL display scaling on high DPI (#1011)
* Fix OpenGL display scaling on high DPI
* Scale the OSD too
* Fix indent
-rw-r--r-- | src/frontend/qt_sdl/OSD.cpp | 3 | ||||
-rw-r--r-- | src/frontend/qt_sdl/OSD_shaders.h | 5 | ||||
-rw-r--r-- | src/frontend/qt_sdl/main.cpp | 3 | ||||
-rw-r--r-- | src/frontend/qt_sdl/main_shaders.h | 5 |
4 files changed, 11 insertions, 5 deletions
diff --git a/src/frontend/qt_sdl/OSD.cpp b/src/frontend/qt_sdl/OSD.cpp index 4e4e40f..ad3b2ff 100644 --- a/src/frontend/qt_sdl/OSD.cpp +++ b/src/frontend/qt_sdl/OSD.cpp @@ -59,6 +59,7 @@ std::deque<Item> ItemQueue; QOpenGLShaderProgram* Shader; GLint uScreenSize, uOSDPos, uOSDSize; +GLfloat uScaleFactor; GLuint OSDVertexArray; GLuint OSDVertexBuffer; @@ -86,6 +87,7 @@ bool Init(QOpenGLFunctions_3_2_Core* f) uScreenSize = Shader->uniformLocation("uScreenSize"); uOSDPos = Shader->uniformLocation("uOSDPos"); uOSDSize = Shader->uniformLocation("uOSDSize"); + uScaleFactor = Shader->uniformLocation("uScaleFactor"); float vertices[6*2] = { @@ -430,6 +432,7 @@ void DrawGL(QOpenGLFunctions_3_2_Core* f, float w, float h) Shader->bind(); f->glUniform2f(uScreenSize, w, h); + f->glUniform1f(uScaleFactor, mainWindow->devicePixelRatioF()); f->glBindBuffer(GL_ARRAY_BUFFER, OSDVertexBuffer); f->glBindVertexArray(OSDVertexArray); diff --git a/src/frontend/qt_sdl/OSD_shaders.h b/src/frontend/qt_sdl/OSD_shaders.h index 5a64f66..727dd5d 100644 --- a/src/frontend/qt_sdl/OSD_shaders.h +++ b/src/frontend/qt_sdl/OSD_shaders.h @@ -25,6 +25,7 @@ uniform vec2 uScreenSize; uniform ivec2 uOSDPos; uniform ivec2 uOSDSize; +uniform float uScaleFactor; in vec2 vPosition; @@ -34,11 +35,11 @@ void main() { vec4 fpos; - vec2 osdpos = (vPosition * vec2(uOSDSize)); + vec2 osdpos = (vPosition * vec2(uOSDSize * uScaleFactor)); fTexcoord = osdpos; osdpos += uOSDPos; - fpos.xy = ((osdpos * 2.0) / uScreenSize) - 1.0; + fpos.xy = ((osdpos * 2.0) / uScreenSize * uScaleFactor) - 1.0; fpos.y *= -1; fpos.z = 0.0; fpos.w = 1.0; diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp index fa293cf..c25aa38 100644 --- a/src/frontend/qt_sdl/main.cpp +++ b/src/frontend/qt_sdl/main.cpp @@ -1004,7 +1004,8 @@ void ScreenPanelGL::paintGL() { screenShader->bind(); - screenShader->setUniformValue("uScreenSize", (float)w*factor, (float)h*factor); + screenShader->setUniformValue("uScreenSize", (float)w, (float)h); + screenShader->setUniformValue("uScaleFactor", factor); emuThread->FrontBufferLock.lock(); int frontbuf = emuThread->FrontBuffer; diff --git a/src/frontend/qt_sdl/main_shaders.h b/src/frontend/qt_sdl/main_shaders.h index c55f79e..da5a22a 100644 --- a/src/frontend/qt_sdl/main_shaders.h +++ b/src/frontend/qt_sdl/main_shaders.h @@ -23,6 +23,7 @@ const char* kScreenVS = R"(#version 140 uniform vec2 uScreenSize; uniform mat2x3 uTransform; +uniform float uScaleFactor; in vec2 vPosition; in vec2 vTexcoord; @@ -33,9 +34,9 @@ void main() { vec4 fpos; - fpos.xy = vec3(vPosition, 1.0) * uTransform; + fpos.xy = vec3(vPosition, 1.0) * uTransform * uScaleFactor; - fpos.xy = ((fpos.xy * 2.0) / uScreenSize) - 1.0; + fpos.xy = ((fpos.xy * 2.0) / (uScreenSize * uScaleFactor)) - 1.0; fpos.y *= -1; fpos.z = 0.0; fpos.w = 1.0; |