From 0b190b7114c816689eeb8478ea5151732bc7a5de Mon Sep 17 00:00:00 2001 From: Yoann Lopes Date: Thu, 21 Mar 2013 16:34:38 +0100 Subject: [PATCH] Fixed distance field text when using non-opaque colors. The alpha has to be premultiplied before passing the color to the shader. Change-Id: If22f0e0892eb4330d5f7398bea2710fce18c4dcb Reviewed-by: Gunnar Sletta --- .../scenegraph/qsgdistancefieldglyphnode_p.cpp | 24 ++++++++++++++++++---- .../scenegraph/qsgdistancefieldglyphnode_p_p.h | 6 ++++-- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/quick/scenegraph/qsgdistancefieldglyphnode_p.cpp b/src/quick/scenegraph/qsgdistancefieldglyphnode_p.cpp index 45fc0f5..86c3356 100644 --- a/src/quick/scenegraph/qsgdistancefieldglyphnode_p.cpp +++ b/src/quick/scenegraph/qsgdistancefieldglyphnode_p.cpp @@ -144,8 +144,8 @@ void QSGDistanceFieldTextMaterialShader::updateState(const RenderState &state, Q if (oldMaterial == 0 || material->color() != oldMaterial->color() || state.isOpacityDirty()) { - QVector4D color(material->color().redF(), material->color().greenF(), - material->color().blueF(), material->color().alphaF()); + QColor c = material->color(); + QVector4D color(c.redF(), c.greenF(), c.blueF(), c.alphaF()); color *= state.opacity(); program()->setUniformValue(m_color_id, color); } @@ -204,6 +204,14 @@ QSGMaterialType *QSGDistanceFieldTextMaterial::type() const return &type; } +void QSGDistanceFieldTextMaterial::setColor(const QColor &color) +{ + m_color = QColor::fromRgbF(color.redF() * color.alphaF(), + color.greenF() * color.alphaF(), + color.blueF() * color.alphaF(), + color.alphaF()); +} + QSGMaterialShader *QSGDistanceFieldTextMaterial::createShader() const { return new QSGDistanceFieldTextMaterialShader; @@ -276,8 +284,8 @@ void DistanceFieldStyledTextMaterialShader::updateState(const RenderState &state if (oldMaterial == 0 || material->styleColor() != oldMaterial->styleColor() || (state.isOpacityDirty())) { - QVector4D color(material->styleColor().redF(), material->styleColor().greenF(), - material->styleColor().blueF(), material->styleColor().alphaF()); + QColor c = material->styleColor(); + QVector4D color(c.redF(), c.greenF(), c.blueF(), c.alphaF()); color *= state.opacity(); program()->setUniformValue(m_styleColor_id, color); } @@ -292,6 +300,14 @@ QSGDistanceFieldStyledTextMaterial::~QSGDistanceFieldStyledTextMaterial() { } +void QSGDistanceFieldStyledTextMaterial::setStyleColor(const QColor &color) +{ + m_styleColor = QColor::fromRgbF(color.redF() * color.alphaF(), + color.greenF() * color.alphaF(), + color.blueF() * color.alphaF(), + color.alphaF()); +} + int QSGDistanceFieldStyledTextMaterial::compare(const QSGMaterial *o) const { Q_ASSERT(o && type() == o->type()); diff --git a/src/quick/scenegraph/qsgdistancefieldglyphnode_p_p.h b/src/quick/scenegraph/qsgdistancefieldglyphnode_p_p.h index d6aa38a..7fea8f6 100644 --- a/src/quick/scenegraph/qsgdistancefieldglyphnode_p_p.h +++ b/src/quick/scenegraph/qsgdistancefieldglyphnode_p_p.h @@ -58,7 +58,7 @@ public: virtual QSGMaterialShader *createShader() const; virtual int compare(const QSGMaterial *other) const; - void setColor(const QColor &color) { m_color = color; } + virtual void setColor(const QColor &color); const QColor &color() const { return m_color; } void setGlyphCache(QSGDistanceFieldGlyphCache *a) { m_glyph_cache = a; } @@ -92,7 +92,7 @@ public: virtual QSGMaterialShader *createShader() const = 0; virtual int compare(const QSGMaterial *other) const; - void setStyleColor(const QColor &color) { m_styleColor = color; } + void setStyleColor(const QColor &color); const QColor &styleColor() const { return m_styleColor; } protected: @@ -130,6 +130,7 @@ class Q_QUICK_PRIVATE_EXPORT QSGHiQSubPixelDistanceFieldTextMaterial : public QS public: virtual QSGMaterialType *type() const; virtual QSGMaterialShader *createShader() const; + void setColor(const QColor &color) { m_color = color; } }; class Q_QUICK_PRIVATE_EXPORT QSGLoQSubPixelDistanceFieldTextMaterial : public QSGDistanceFieldTextMaterial @@ -137,6 +138,7 @@ class Q_QUICK_PRIVATE_EXPORT QSGLoQSubPixelDistanceFieldTextMaterial : public QS public: virtual QSGMaterialType *type() const; virtual QSGMaterialShader *createShader() const; + void setColor(const QColor &color) { m_color = color; } }; QT_END_NAMESPACE -- 2.7.4