From 9815adf88c50af4f5249cfa631d9c565f87428c3 Mon Sep 17 00:00:00 2001 From: Yoann Lopes Date: Thu, 5 May 2011 12:02:20 +0200 Subject: [PATCH] Makes sub-pixel antialiased distance-field text looks slightly sharper. --- src/declarative/scenegraph/qsgdistancefieldglyphnode_p.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/declarative/scenegraph/qsgdistancefieldglyphnode_p.cpp b/src/declarative/scenegraph/qsgdistancefieldglyphnode_p.cpp index e332434..c822810 100644 --- a/src/declarative/scenegraph/qsgdistancefieldglyphnode_p.cpp +++ b/src/declarative/scenegraph/qsgdistancefieldglyphnode_p.cpp @@ -60,7 +60,7 @@ protected: virtual const char *vertexShader() const; virtual const char *fragmentShader() const; - void updateAlphaRange(); + virtual void updateAlphaRange(); qreal m_fontScale; qreal m_matrixScale; @@ -506,6 +506,8 @@ protected: virtual const char *vertexShader() const; virtual const char *fragmentShader() const; + void updateAlphaRange(); + private: int m_fontScale_id; int m_vecDelta_id; @@ -618,6 +620,15 @@ void QSGSubPixelDistanceFieldTextMaterialShader::deactivate() glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); } +void QSGSubPixelDistanceFieldTextMaterialShader::updateAlphaRange() +{ + qreal combinedScale = m_fontScale * m_matrixScale; + qreal alphaMin = qMax(0.0, 0.5 - 0.05 / combinedScale); + qreal alphaMax = qMin(0.5 + 0.05 / combinedScale, 1.0); + m_program.setUniformValue(m_alphaMin_id, GLfloat(alphaMin)); + m_program.setUniformValue(m_alphaMax_id, GLfloat(alphaMax)); +} + void QSGSubPixelDistanceFieldTextMaterialShader::updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) { Q_ASSERT(oldEffect == 0 || newEffect->type() == oldEffect->type()); -- 2.7.4