Snap native glyphs to pixel grid in vertex shader.
authorGunnar Sletta <gunnar@sletta.org>
Mon, 8 Sep 2014 10:38:02 +0000 (12:38 +0200)
committerGunnar Sletta <gunnar@sletta.org>
Thu, 11 Sep 2014 08:34:55 +0000 (10:34 +0200)
The implementation relied on the full matrix, but did not
set the RequiresFullMatrix flag. Setting the flag would
have serious negative performance impact as it prevents
batching, so we solve it in the vertex shader instead.

Task-number: QTBUG-38702
Change-Id: I0c245ea9e18b0b29dd9e3073a2648a7f4e061685
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>
src/quick/scenegraph/qsgdefaultglyphnode_p.cpp
src/quick/scenegraph/shaders/styledtext.vert
src/quick/scenegraph/shaders/styledtext_core.vert
src/quick/scenegraph/shaders/textmask.vert
src/quick/scenegraph/shaders/textmask_core.vert

index 16feafe..802c92b 100644 (file)
@@ -128,28 +128,8 @@ void QSGTextMaskShader::updateState(const RenderState &state, QSGMaterial *newEf
         }
     }
 
-    if (state.isMatrixDirty()) {
-        QMatrix4x4 transform = state.modelViewMatrix();
-        qreal xTranslation = transform(0, 3);
-        qreal yTranslation = transform(1, 3);
-
-        // Remove translation and check identity to see if matrix is only translating.
-        // If it is, we can round the translation to make sure the text is pixel aligned,
-        // which is the only thing that works with GL_NEAREST filtering. Adding rotations
-        // and scales to native rendered text is not a prioritized use case, since the
-        // default rendering type is designed for that.
-        transform(0, 3) = 0.0;
-        transform(1, 3) = 0.0;
-        if (transform.isIdentity()) {
-            transform(0, 3) = qRound(xTranslation);
-            transform(1, 3) = qRound(yTranslation);
-
-            transform = state.projectionMatrix() * transform;
-            program()->setUniformValue(m_matrix_id, transform);
-        } else {
-            program()->setUniformValue(m_matrix_id, state.combinedMatrix());
-        }
-    }
+    if (state.isMatrixDirty())
+        program()->setUniformValue(m_matrix_id, state.combinedMatrix());
 }
 
 class QSG8BitTextMaskShader : public QSGTextMaskShader
index 3ad9497..14fefc2 100644 (file)
@@ -12,5 +12,5 @@ void main()
 {
      sampleCoord = tCoord * textureScale;
      shiftedSampleCoord = (tCoord - shift) * textureScale;
-     gl_Position = matrix * vCoord;
-}
\ No newline at end of file
+     gl_Position = matrix * floor(vCoord + 0.5);
+}
index b7a3ecc..65bdb66 100644 (file)
@@ -14,5 +14,5 @@ void main()
 {
      sampleCoord = tCoord * textureScale;
      shiftedSampleCoord = (tCoord - shift) * textureScale;
-     gl_Position = matrix * vCoord;
-}
\ No newline at end of file
+     gl_Position = matrix * round(vCoord);
+}
index 1f45e9c..dd89188 100644 (file)
@@ -9,5 +9,5 @@ varying highp vec2 sampleCoord;
 void main()
 {
      sampleCoord = tCoord * textureScale;
-     gl_Position = matrix * vCoord;
+     gl_Position = matrix * floor(vCoord + 0.5);
 }
index 619248d..d145d33 100644 (file)
@@ -11,5 +11,5 @@ uniform vec2 textureScale;
 void main()
 {
      sampleCoord = tCoord * textureScale;
-     gl_Position = matrix * vCoord;
+     gl_Position = matrix * round(vCoord);
 }