diff options
author | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io> | 2021-10-14 07:10:18 +0200 |
---|---|---|
committer | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io> | 2021-10-18 07:48:05 +0200 |
commit | 87292038fa4b4a33070e6145d9f88fb6fa2ed627 (patch) | |
tree | 49a0e45c674635b12d6bfefee37724baee8fa8ef | |
parent | 084331dd7322f8e61f59f5293fcba76266ab30f6 (diff) | |
download | qtdeclarative-87292038fa4b4a33070e6145d9f88fb6fa2ed627.tar.gz |
Fix distorted subpixel text for non-RHI code path
This amends 4757cac470edbeaeaceca4e63075d9f1139f546b which is a
cherry-pick of the fix of subpixel positioning of text for the
RHI code path. But this code path is not enabled by default in Qt 5,
so in order to fix this properly, we need to make the equivalent
changes to the runtime-compiled shaders.
Task-number: QTBUG-96112
Task-number: QTBUG-83626
Change-Id: I6c104fd74298e1ec503b9e84b8cc884fb78ddb7b
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
-rw-r--r-- | src/quick/scenegraph/qsgdefaultglyphnode_p.cpp | 21 | ||||
-rw-r--r-- | src/quick/scenegraph/shaders/outlinedtext.vert | 9 | ||||
-rw-r--r-- | src/quick/scenegraph/shaders/outlinedtext_core.vert | 9 | ||||
-rw-r--r-- | src/quick/scenegraph/shaders/styledtext.vert | 7 | ||||
-rw-r--r-- | src/quick/scenegraph/shaders/styledtext_core.vert | 7 | ||||
-rw-r--r-- | src/quick/scenegraph/shaders/textmask.vert | 7 | ||||
-rw-r--r-- | src/quick/scenegraph/shaders/textmask_core.vert | 7 |
7 files changed, 40 insertions, 27 deletions
diff --git a/src/quick/scenegraph/qsgdefaultglyphnode_p.cpp b/src/quick/scenegraph/qsgdefaultglyphnode_p.cpp index 7af1dc9b01..6f3205f526 100644 --- a/src/quick/scenegraph/qsgdefaultglyphnode_p.cpp +++ b/src/quick/scenegraph/qsgdefaultglyphnode_p.cpp @@ -119,7 +119,8 @@ public: protected: void initialize() override; - int m_matrix_id; + int m_projectionMatrix_id; + int m_modelViewMatrix_id; int m_color_id; int m_textureScale_id; float m_devicePixelRatio; @@ -135,7 +136,8 @@ char const *const *QSGTextMaskShader::attributeNames() const QSGTextMaskShader::QSGTextMaskShader(QFontEngine::GlyphFormat glyphFormat) : QSGMaterialShader(*new QSGMaterialShaderPrivate) - , m_matrix_id(-1) + , m_projectionMatrix_id(-1) + , m_modelViewMatrix_id(-1) , m_color_id(-1) , m_textureScale_id(-1) , m_glyphFormat(glyphFormat) @@ -146,7 +148,8 @@ QSGTextMaskShader::QSGTextMaskShader(QFontEngine::GlyphFormat glyphFormat) void QSGTextMaskShader::initialize() { - m_matrix_id = program()->uniformLocation("matrix"); + m_projectionMatrix_id = program()->uniformLocation("projectionMatrix"); + m_modelViewMatrix_id = program()->uniformLocation("modelViewMatrix"); m_color_id = program()->uniformLocation("color"); m_textureScale_id = program()->uniformLocation("textureScale"); m_devicePixelRatio = (float) qsg_device_pixel_ratio(QOpenGLContext::currentContext()); @@ -184,8 +187,10 @@ void QSGTextMaskShader::updateState(const RenderState &state, QSGMaterial *newEf program()->setUniformValue("dpr", m_devicePixelRatio); } - if (state.isMatrixDirty()) - program()->setUniformValue(m_matrix_id, state.combinedMatrix()); + if (state.isMatrixDirty()) { + program()->setUniformValue(m_projectionMatrix_id, state.projectionMatrix()); + program()->setUniformValue(m_modelViewMatrix_id, state.modelViewMatrix()); + } } class QSG8BitTextMaskShader : public QSGTextMaskShader @@ -387,8 +392,10 @@ void QSGStyledTextShader::updateState(const RenderState &state, } } - if (state.isMatrixDirty()) - program()->setUniformValue(m_matrix_id, state.combinedMatrix()); + if (state.isMatrixDirty()) { + program()->setUniformValue(m_projectionMatrix_id, state.projectionMatrix()); + program()->setUniformValue(m_modelViewMatrix_id, state.modelViewMatrix()); + } } class QSGOutlinedTextShader : public QSGStyledTextShader diff --git a/src/quick/scenegraph/shaders/outlinedtext.vert b/src/quick/scenegraph/shaders/outlinedtext.vert index 9df832de3c..42fa577063 100644 --- a/src/quick/scenegraph/shaders/outlinedtext.vert +++ b/src/quick/scenegraph/shaders/outlinedtext.vert @@ -1,4 +1,5 @@ -uniform highp mat4 matrix; +uniform highp mat4 modelViewMatrix; +uniform highp mat4 projectionMatrix; uniform highp vec2 textureScale; uniform highp vec2 shift; uniform highp float dpr; @@ -19,6 +20,6 @@ void main() sCoordDown = (tCoord - vec2(0.0, 1.0)) * textureScale; sCoordLeft = (tCoord - vec2(-1.0, 0.0)) * textureScale; sCoordRight = (tCoord - vec2(1.0, 0.0)) * textureScale; - vec3 dprSnapPos = floor(vCoord.xyz * dpr + 0.5) / dpr; - gl_Position = matrix * vec4(dprSnapPos, vCoord.w); -}
\ No newline at end of file + vec4 xformed = modelViewMatrix * vCoord; + gl_Position = projectionMatrix * vec4(floor(xformed.xyz * dpr + 0.5) / dpr, xformed.w); +} diff --git a/src/quick/scenegraph/shaders/outlinedtext_core.vert b/src/quick/scenegraph/shaders/outlinedtext_core.vert index a854355460..50a1371e89 100644 --- a/src/quick/scenegraph/shaders/outlinedtext_core.vert +++ b/src/quick/scenegraph/shaders/outlinedtext_core.vert @@ -9,7 +9,8 @@ out vec2 sCoordDown; out vec2 sCoordLeft; out vec2 sCoordRight; -uniform mat4 matrix; +uniform mat4 modelViewMatrix; +uniform mat4 projectionMatrix; uniform vec2 textureScale; uniform vec2 shift; uniform float dpr; @@ -21,6 +22,6 @@ void main() sCoordDown = (tCoord - vec2(0.0, 1.0)) * textureScale; sCoordLeft = (tCoord - vec2(-1.0, 0.0)) * textureScale; sCoordRight = (tCoord - vec2(1.0, 0.0)) * textureScale; - vec3 dprSnapPos = floor(vCoord.xyz * dpr + 0.5) / dpr; - gl_Position = matrix * vec4(dprSnapPos, vCoord.w); -}
\ No newline at end of file + vec4 xformed = modelViewMatrix * vCoord; + gl_Position = projectionMatrix * vec4(floor(xformed.xyz * dpr + 0.5) / dpr, xformed.w); +} diff --git a/src/quick/scenegraph/shaders/styledtext.vert b/src/quick/scenegraph/shaders/styledtext.vert index 29c9902609..dc87dadd5f 100644 --- a/src/quick/scenegraph/shaders/styledtext.vert +++ b/src/quick/scenegraph/shaders/styledtext.vert @@ -1,4 +1,5 @@ -uniform highp mat4 matrix; +uniform highp mat4 modelViewMatrix; +uniform highp mat4 projectionMatrix; uniform highp vec2 textureScale; uniform highp vec2 shift; uniform highp float dpr; @@ -13,6 +14,6 @@ void main() { sampleCoord = tCoord * textureScale; shiftedSampleCoord = (tCoord - shift) * textureScale; - vec3 dprSnapPos = floor(vCoord.xyz * dpr + 0.5) / dpr; - gl_Position = matrix * vec4(dprSnapPos, vCoord.w); + vec4 xformed = modelViewMatrix * vCoord; + gl_Position = projectionMatrix * vec4(floor(xformed.xyz * dpr + 0.5) / dpr, xformed.w); } diff --git a/src/quick/scenegraph/shaders/styledtext_core.vert b/src/quick/scenegraph/shaders/styledtext_core.vert index 04a0e88da8..d9a81bf06f 100644 --- a/src/quick/scenegraph/shaders/styledtext_core.vert +++ b/src/quick/scenegraph/shaders/styledtext_core.vert @@ -6,7 +6,8 @@ in vec2 tCoord; out vec2 sampleCoord; out vec2 shiftedSampleCoord; -uniform mat4 matrix; +uniform mat4 modelViewMatrix; +uniform mat4 projectionMatrix; uniform vec2 textureScale; uniform vec2 shift; uniform float dpr; @@ -15,6 +16,6 @@ void main() { sampleCoord = tCoord * textureScale; shiftedSampleCoord = (tCoord - shift) * textureScale; - vec3 dprSnapPos = floor(vCoord.xyz * dpr + 0.5) / dpr; - gl_Position = matrix * vec4(dprSnapPos, vCoord.w); + vec4 xformed = modelViewMatrix * vCoord; + gl_Position = projectionMatrix * vec4(floor(xformed.xyz * dpr + 0.5) / dpr, xformed.w); } diff --git a/src/quick/scenegraph/shaders/textmask.vert b/src/quick/scenegraph/shaders/textmask.vert index 1692159d2c..7f418b0895 100644 --- a/src/quick/scenegraph/shaders/textmask.vert +++ b/src/quick/scenegraph/shaders/textmask.vert @@ -1,4 +1,5 @@ -uniform highp mat4 matrix; +uniform highp mat4 modelViewMatrix; +uniform highp mat4 projectionMatrix; uniform highp vec2 textureScale; uniform highp float dpr; @@ -10,6 +11,6 @@ varying highp vec2 sampleCoord; void main() { sampleCoord = tCoord * textureScale; - vec3 dprSnapPos = floor(vCoord.xyz * dpr + 0.5) / dpr; - gl_Position = matrix * vec4(dprSnapPos, vCoord.w); + vec4 xformed = modelViewMatrix * vCoord; + gl_Position = projectionMatrix * vec4(floor(xformed.xyz * dpr + 0.5) / dpr, xformed.w); } diff --git a/src/quick/scenegraph/shaders/textmask_core.vert b/src/quick/scenegraph/shaders/textmask_core.vert index b0efc1e731..1f88974aed 100644 --- a/src/quick/scenegraph/shaders/textmask_core.vert +++ b/src/quick/scenegraph/shaders/textmask_core.vert @@ -5,13 +5,14 @@ in vec2 tCoord; out vec2 sampleCoord; -uniform mat4 matrix; +uniform mat4 modelViewMatrix; +uniform mat4 projectionMatrix; uniform vec2 textureScale; uniform float dpr; void main() { sampleCoord = tCoord * textureScale; - vec3 dprSnapPos = floor(vCoord.xyz * dpr + 0.5) / dpr; - gl_Position = matrix * vec4(dprSnapPos, vCoord.w); + vec4 xformed = modelViewMatrix * vCoord; + gl_Position = projectionMatrix * vec4(floor(xformed.xyz * dpr + 0.5) / dpr, xformed.w); } |