diff options
author | Eli Fidler <efidler@topologyinc.com> | 2015-06-19 16:44:29 -0400 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@theqtcompany.com> | 2015-06-23 14:57:35 +0000 |
commit | 3e5a89ae70eb612afef0d593f180a57da17c782f (patch) | |
tree | d7eeea56893329590b455fb4b57645859525873f /src/quick/scenegraph/qsgdefaultglyphnode_p.cpp | |
parent | 9dee99ece7a10fa7a9b723b0d733c3d99b6cf57f (diff) |
Support 32-bit color bitmap glyphs in native text rendering.
We had been accidentally using the 8-bit alpha glyph shader, which
resulted in rendering solid black outlines of the glyphs.
Task-number: QTBUG-37986
Task-number: QTBUG-45514
Change-Id: Ie8728d50068f58d659e24bc5db2d73e01ca8db75
Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@theqtcompany.com>
Diffstat (limited to 'src/quick/scenegraph/qsgdefaultglyphnode_p.cpp')
-rw-r--r-- | src/quick/scenegraph/qsgdefaultglyphnode_p.cpp | 49 |
1 files changed, 43 insertions, 6 deletions
diff --git a/src/quick/scenegraph/qsgdefaultglyphnode_p.cpp b/src/quick/scenegraph/qsgdefaultglyphnode_p.cpp index 102985f2c7..c84e6628a5 100644 --- a/src/quick/scenegraph/qsgdefaultglyphnode_p.cpp +++ b/src/quick/scenegraph/qsgdefaultglyphnode_p.cpp @@ -264,6 +264,30 @@ void QSG24BitTextMaskShader::updateState(const RenderState &state, QSGMaterial * } } +class QSG32BitColorTextShader : public QSGTextMaskShader +{ +public: + QSG32BitColorTextShader(QFontEngine::GlyphFormat glyphFormat) + : QSGTextMaskShader(glyphFormat) + { + setShaderSourceFile(QOpenGLShader::Fragment, QStringLiteral(":/scenegraph/shaders/32bitcolortext.frag")); + } + + void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) Q_DECL_OVERRIDE; +}; + +void QSG32BitColorTextShader::updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) +{ + QSGTextMaskShader::updateState(state, newEffect, oldEffect); + QSGTextMaskMaterial *material = static_cast<QSGTextMaskMaterial *>(newEffect); + QSGTextMaskMaterial *oldMaterial = static_cast<QSGTextMaskMaterial *>(oldEffect); + + if (oldMaterial == Q_NULLPTR || material->color() != oldMaterial->color() || state.isOpacityDirty()) { + float opacity = material->color().w() * state.opacity(); + program()->setUniformValue(m_color_id, opacity); + } +} + class QSGStyledTextShader : public QSG8BitTextMaskShader { public: @@ -492,8 +516,16 @@ void QSGTextMaskMaterial::populate(const QPointF &p, QSGMaterialType *QSGTextMaskMaterial::type() const { - static QSGMaterialType rgb, gray; - return glyphCache()->glyphFormat() == QFontEngine::Format_A32 ? &rgb : &gray; + static QSGMaterialType argb, rgb, gray; + switch (glyphCache()->glyphFormat()) { + case QFontEngine::Format_ARGB: + return &argb; + case QFontEngine::Format_A32: + return &rgb; + case QFontEngine::Format_A8: + default: + return &gray; + } } QOpenGLTextureGlyphCache *QSGTextMaskMaterial::glyphCache() const @@ -503,10 +535,15 @@ QOpenGLTextureGlyphCache *QSGTextMaskMaterial::glyphCache() const QSGMaterialShader *QSGTextMaskMaterial::createShader() const { - QFontEngine::GlyphFormat glyphFormat = glyphCache()->glyphFormat(); - return glyphFormat == QFontEngine::Format_A32 - ? (QSGMaterialShader *) new QSG24BitTextMaskShader(glyphFormat) - : (QSGMaterialShader *) new QSG8BitTextMaskShader(glyphFormat); + switch (QFontEngine::GlyphFormat glyphFormat = glyphCache()->glyphFormat()) { + case QFontEngine::Format_ARGB: + return new QSG32BitColorTextShader(glyphFormat); + case QFontEngine::Format_A32: + return new QSG24BitTextMaskShader(glyphFormat); + case QFontEngine::Format_A8: + default: + return new QSG8BitTextMaskShader(glyphFormat); + } } static inline int qsg_colorDiff(const QVector4D &a, const QVector4D &b) |