1 /****************************************************************************
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #include "qsgdistancefieldglyphnode_p_p.h"
43 #include "qsgdistancefieldglyphcache_p.h"
44 #include <private/qsgtexture_p.h>
45 #include <QtOpenGL/qglfunctions.h>
50 class QSGDistanceFieldTextMaterialShader : public QSGMaterialShader
53 QSGDistanceFieldTextMaterialShader();
55 virtual void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect);
56 virtual char const *const *attributeNames() const;
59 virtual void initialize();
60 virtual const char *vertexShader() const;
61 virtual const char *fragmentShader() const;
63 void updateAlphaRange(ThresholdFunc thresholdFunc, AntialiasingSpreadFunc spreadFunc);
69 int m_textureScale_id;
75 const char *QSGDistanceFieldTextMaterialShader::vertexShader() const {
77 "uniform highp mat4 matrix; \n"
78 "uniform highp vec2 textureScale; \n"
79 "attribute highp vec4 vCoord; \n"
80 "attribute highp vec2 tCoord; \n"
81 "varying highp vec2 sampleCoord; \n"
83 " sampleCoord = tCoord * textureScale; \n"
84 " gl_Position = matrix * vCoord; \n"
88 const char *QSGDistanceFieldTextMaterialShader::fragmentShader() const {
90 "varying highp vec2 sampleCoord; \n"
91 "uniform sampler2D texture; \n"
92 "uniform lowp vec4 color; \n"
93 "uniform highp float alphaMin; \n"
94 "uniform highp float alphaMax; \n"
96 " gl_FragColor = color * smoothstep(alphaMin, \n"
98 " texture2D(texture, sampleCoord).a); \n"
102 char const *const *QSGDistanceFieldTextMaterialShader::attributeNames() const {
103 static char const *const attr[] = { "vCoord", "tCoord", 0 };
107 QSGDistanceFieldTextMaterialShader::QSGDistanceFieldTextMaterialShader()
113 void QSGDistanceFieldTextMaterialShader::updateAlphaRange(ThresholdFunc thresholdFunc, AntialiasingSpreadFunc spreadFunc)
115 float combinedScale = m_fontScale * m_matrixScale;
116 float base = thresholdFunc(combinedScale);
117 float range = spreadFunc(combinedScale);
119 float alphaMin = qMax(0.0f, base - range);
120 float alphaMax = qMin(base + range, 1.0f);
121 program()->setUniformValue(m_alphaMin_id, GLfloat(alphaMin));
122 program()->setUniformValue(m_alphaMax_id, GLfloat(alphaMax));
125 void QSGDistanceFieldTextMaterialShader::initialize()
127 QSGMaterialShader::initialize();
128 m_matrix_id = program()->uniformLocation("matrix");
129 m_textureScale_id = program()->uniformLocation("textureScale");
130 m_color_id = program()->uniformLocation("color");
131 m_alphaMin_id = program()->uniformLocation("alphaMin");
132 m_alphaMax_id = program()->uniformLocation("alphaMax");
135 void QSGDistanceFieldTextMaterialShader::updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect)
137 Q_ASSERT(oldEffect == 0 || newEffect->type() == oldEffect->type());
138 QSGDistanceFieldTextMaterial *material = static_cast<QSGDistanceFieldTextMaterial *>(newEffect);
139 QSGDistanceFieldTextMaterial *oldMaterial = static_cast<QSGDistanceFieldTextMaterial *>(oldEffect);
141 bool updated = material->updateTexture();
142 if (updated && !material->glyphCache()->useWorkaroundBrokenFBOReadback())
146 || material->color() != oldMaterial->color()
147 || state.isOpacityDirty()) {
148 QVector4D color(material->color().redF(), material->color().greenF(),
149 material->color().blueF(), material->color().alphaF());
150 color *= state.opacity();
151 program()->setUniformValue(m_color_id, color);
154 bool updateRange = false;
156 || material->glyphCache()->fontScale() != oldMaterial->glyphCache()->fontScale()) {
157 m_fontScale = material->glyphCache()->fontScale();
160 if (state.isMatrixDirty()) {
161 program()->setUniformValue(m_matrix_id, state.combinedMatrix());
162 m_matrixScale = qSqrt(state.modelViewMatrix().determinant());
166 updateAlphaRange(material->glyphCache()->thresholdFunc(), material->glyphCache()->antialiasingSpreadFunc());
168 Q_ASSERT(material->glyphCache());
172 || oldMaterial->glyphCache()->texture() != material->glyphCache()->texture()) {
173 program()->setUniformValue(m_textureScale_id, QVector2D(1.0 / material->glyphCache()->textureSize().width(),
174 1.0 / material->glyphCache()->textureSize().height()));
175 glBindTexture(GL_TEXTURE_2D, material->glyphCache()->texture());
178 // Set the mag/min filters to be linear. We only need to do this when the texture
179 // has been recreated.
180 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
181 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
182 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
183 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
188 QSGDistanceFieldTextMaterial::QSGDistanceFieldTextMaterial()
191 setFlag(Blending, true);
194 QSGDistanceFieldTextMaterial::~QSGDistanceFieldTextMaterial()
198 QSGMaterialType *QSGDistanceFieldTextMaterial::type() const
200 static QSGMaterialType type;
204 QSGMaterialShader *QSGDistanceFieldTextMaterial::createShader() const
206 return new QSGDistanceFieldTextMaterialShader;
209 bool QSGDistanceFieldTextMaterial::updateTexture()
211 m_glyph_cache->updateCache();
212 QSize glyphCacheSize = m_glyph_cache->textureSize();
213 if (glyphCacheSize != m_size) {
214 m_size = glyphCacheSize;
222 int QSGDistanceFieldTextMaterial::compare(const QSGMaterial *o) const
224 Q_ASSERT(o && type() == o->type());
225 const QSGDistanceFieldTextMaterial *other = static_cast<const QSGDistanceFieldTextMaterial *>(o);
226 if (m_glyph_cache->fontScale() != other->m_glyph_cache->fontScale()) {
227 qreal s1 = m_glyph_cache->fontScale();
228 qreal s2 = other->m_glyph_cache->fontScale();
229 return int(s2 < s1) - int(s1 < s2);
231 QRgb c1 = m_color.rgba();
232 QRgb c2 = other->m_color.rgba();
233 return int(c2 < c1) - int(c1 < c2);
237 class DistanceFieldStyledTextMaterialShader : public QSGDistanceFieldTextMaterialShader
240 DistanceFieldStyledTextMaterialShader();
242 virtual void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect);
245 virtual void initialize();
246 virtual const char *fragmentShader() const = 0;
251 DistanceFieldStyledTextMaterialShader::DistanceFieldStyledTextMaterialShader()
252 : QSGDistanceFieldTextMaterialShader()
256 void DistanceFieldStyledTextMaterialShader::initialize()
258 QSGDistanceFieldTextMaterialShader::initialize();
259 m_styleColor_id = program()->uniformLocation("styleColor");
262 void DistanceFieldStyledTextMaterialShader::updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect)
264 QSGDistanceFieldTextMaterialShader::updateState(state, newEffect, oldEffect);
266 QSGDistanceFieldStyledTextMaterial *material = static_cast<QSGDistanceFieldStyledTextMaterial *>(newEffect);
267 QSGDistanceFieldStyledTextMaterial *oldMaterial = static_cast<QSGDistanceFieldStyledTextMaterial *>(oldEffect);
270 || material->styleColor() != oldMaterial->styleColor()
271 || (state.isOpacityDirty())) {
272 QVector4D color(material->styleColor().redF(), material->styleColor().greenF(),
273 material->styleColor().blueF(), material->styleColor().alphaF());
274 color *= state.opacity();
275 program()->setUniformValue(m_styleColor_id, color);
279 QSGDistanceFieldStyledTextMaterial::QSGDistanceFieldStyledTextMaterial()
280 : QSGDistanceFieldTextMaterial()
284 QSGDistanceFieldStyledTextMaterial::~QSGDistanceFieldStyledTextMaterial()
288 int QSGDistanceFieldStyledTextMaterial::compare(const QSGMaterial *o) const
290 Q_ASSERT(o && type() == o->type());
291 const QSGDistanceFieldStyledTextMaterial *other = static_cast<const QSGDistanceFieldStyledTextMaterial *>(o);
292 if (m_styleColor != other->m_styleColor) {
293 QRgb c1 = m_styleColor.rgba();
294 QRgb c2 = other->m_styleColor.rgba();
295 return int(c2 < c1) - int(c1 < c2);
297 return QSGDistanceFieldTextMaterial::compare(o);
301 class DistanceFieldOutlineTextMaterialShader : public DistanceFieldStyledTextMaterialShader
304 DistanceFieldOutlineTextMaterialShader();
306 virtual void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect);
309 virtual void initialize();
310 virtual const char *fragmentShader() const;
312 void updateOutlineAlphaRange(int dfRadius);
314 int m_outlineAlphaMax0_id;
315 int m_outlineAlphaMax1_id;
318 const char *DistanceFieldOutlineTextMaterialShader::fragmentShader() const {
320 "varying highp vec2 sampleCoord; \n"
321 "uniform sampler2D texture; \n"
322 "uniform lowp vec4 color; \n"
323 "uniform lowp vec4 styleColor; \n"
324 "uniform highp float alphaMin; \n"
325 "uniform highp float alphaMax; \n"
326 "uniform highp float outlineAlphaMax0; \n"
327 "uniform highp float outlineAlphaMax1; \n"
329 " mediump float d = texture2D(texture, sampleCoord).a; \n"
330 " gl_FragColor = mix(styleColor, color, smoothstep(alphaMin, alphaMax, d)) \n"
331 " * smoothstep(outlineAlphaMax0, outlineAlphaMax1, d); \n"
335 DistanceFieldOutlineTextMaterialShader::DistanceFieldOutlineTextMaterialShader()
336 : DistanceFieldStyledTextMaterialShader()
340 void DistanceFieldOutlineTextMaterialShader::initialize()
342 DistanceFieldStyledTextMaterialShader::initialize();
343 m_outlineAlphaMax0_id = program()->uniformLocation("outlineAlphaMax0");
344 m_outlineAlphaMax1_id = program()->uniformLocation("outlineAlphaMax1");
347 void DistanceFieldOutlineTextMaterialShader::updateOutlineAlphaRange(int dfRadius)
349 qreal outlineLimit = qMax(qreal(0.2), qreal(0.5 - 0.5 / dfRadius / m_fontScale));
351 qreal combinedScale = m_fontScale * m_matrixScale;
352 qreal alphaMin = qMax(0.0, 0.5 - 0.07 / combinedScale);
353 qreal styleAlphaMin0 = qMax(0.0, outlineLimit - 0.07 / combinedScale);
354 qreal styleAlphaMin1 = qMin(qreal(outlineLimit + 0.07 / combinedScale), alphaMin);
355 program()->setUniformValue(m_outlineAlphaMax0_id, GLfloat(styleAlphaMin0));
356 program()->setUniformValue(m_outlineAlphaMax1_id, GLfloat(styleAlphaMin1));
359 void DistanceFieldOutlineTextMaterialShader::updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect)
361 DistanceFieldStyledTextMaterialShader::updateState(state, newEffect, oldEffect);
363 QSGDistanceFieldOutlineTextMaterial *material = static_cast<QSGDistanceFieldOutlineTextMaterial *>(newEffect);
364 QSGDistanceFieldOutlineTextMaterial *oldMaterial = static_cast<QSGDistanceFieldOutlineTextMaterial *>(oldEffect);
367 || material->glyphCache()->fontScale() != oldMaterial->glyphCache()->fontScale()
368 || state.isMatrixDirty())
369 updateOutlineAlphaRange(material->glyphCache()->distanceFieldRadius());
373 QSGDistanceFieldOutlineTextMaterial::QSGDistanceFieldOutlineTextMaterial()
374 : QSGDistanceFieldStyledTextMaterial()
378 QSGDistanceFieldOutlineTextMaterial::~QSGDistanceFieldOutlineTextMaterial()
382 QSGMaterialType *QSGDistanceFieldOutlineTextMaterial::type() const
384 static QSGMaterialType type;
388 QSGMaterialShader *QSGDistanceFieldOutlineTextMaterial::createShader() const
390 return new DistanceFieldOutlineTextMaterialShader;
394 class DistanceFieldShiftedStyleTextMaterialShader : public DistanceFieldStyledTextMaterialShader
397 DistanceFieldShiftedStyleTextMaterialShader();
399 virtual void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect);
402 virtual void initialize();
403 virtual const char *vertexShader() const;
404 virtual const char *fragmentShader() const;
406 void updateShift(const QSGDistanceFieldGlyphCache *cache, const QPointF& shift);
411 DistanceFieldShiftedStyleTextMaterialShader::DistanceFieldShiftedStyleTextMaterialShader()
412 : DistanceFieldStyledTextMaterialShader()
416 void DistanceFieldShiftedStyleTextMaterialShader::initialize()
418 DistanceFieldStyledTextMaterialShader::initialize();
419 m_shift_id = program()->uniformLocation("shift");
422 void DistanceFieldShiftedStyleTextMaterialShader::updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect)
424 DistanceFieldStyledTextMaterialShader::updateState(state, newEffect, oldEffect);
426 QSGDistanceFieldShiftedStyleTextMaterial *material = static_cast<QSGDistanceFieldShiftedStyleTextMaterial *>(newEffect);
427 QSGDistanceFieldShiftedStyleTextMaterial *oldMaterial = static_cast<QSGDistanceFieldShiftedStyleTextMaterial *>(oldEffect);
430 || oldMaterial->glyphCache()->fontScale() != material->glyphCache()->fontScale()
431 || oldMaterial->shift() != material->shift()
432 || oldMaterial->glyphCache()->textureSize() != material->glyphCache()->textureSize()) {
433 updateShift(material->glyphCache(), material->shift());
437 void DistanceFieldShiftedStyleTextMaterialShader::updateShift(const QSGDistanceFieldGlyphCache *cache, const QPointF &shift)
439 QPointF texel(1.0 / cache->fontScale() * shift.x(),
440 1.0 / cache->fontScale() * shift.y());
441 program()->setUniformValue(m_shift_id, texel);
444 const char *DistanceFieldShiftedStyleTextMaterialShader::vertexShader() const
447 "uniform highp mat4 matrix; \n"
448 "uniform highp vec2 textureScale; \n"
449 "attribute highp vec4 vCoord; \n"
450 "attribute highp vec2 tCoord; \n"
451 "uniform highp vec2 shift; \n"
452 "varying highp vec2 sampleCoord; \n"
453 "varying highp vec2 shiftedSampleCoord; \n"
455 " sampleCoord = tCoord * textureScale; \n"
456 " shiftedSampleCoord = (tCoord - shift) * textureScale; \n"
457 " gl_Position = matrix * vCoord; \n"
461 const char *DistanceFieldShiftedStyleTextMaterialShader::fragmentShader() const {
463 "varying highp vec2 sampleCoord; \n"
464 "varying highp vec2 shiftedSampleCoord; \n"
465 "uniform sampler2D texture; \n"
466 "uniform lowp vec4 color; \n"
467 "uniform lowp vec4 styleColor; \n"
468 "uniform highp float alphaMin; \n"
469 "uniform highp float alphaMax; \n"
471 " highp float a = smoothstep(alphaMin, alphaMax, texture2D(texture, sampleCoord).a);\n"
472 " highp vec4 shifted = styleColor * smoothstep(alphaMin, \n"
474 " texture2D(texture, shiftedSampleCoord).a); \n"
475 " gl_FragColor = mix(shifted, color, a); \n"
479 QSGDistanceFieldShiftedStyleTextMaterial::QSGDistanceFieldShiftedStyleTextMaterial()
480 : QSGDistanceFieldStyledTextMaterial()
484 QSGDistanceFieldShiftedStyleTextMaterial::~QSGDistanceFieldShiftedStyleTextMaterial()
488 QSGMaterialType *QSGDistanceFieldShiftedStyleTextMaterial::type() const
490 static QSGMaterialType type;
494 QSGMaterialShader *QSGDistanceFieldShiftedStyleTextMaterial::createShader() const
496 return new DistanceFieldShiftedStyleTextMaterialShader;
500 class QSGSubPixelDistanceFieldTextMaterialShader : public QSGDistanceFieldTextMaterialShader
503 virtual void initialize();
504 virtual void activate();
505 virtual void deactivate();
506 virtual void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect);
509 virtual const char *vertexShader() const;
510 virtual const char *fragmentShader() const;
517 const char *QSGSubPixelDistanceFieldTextMaterialShader::vertexShader() const {
519 "uniform highp mat4 matrix; \n"
520 "uniform highp vec2 textureScale; \n"
521 "uniform highp float fontScale; \n"
522 "uniform highp vec4 vecDelta; \n"
523 "attribute highp vec4 vCoord; \n"
524 "attribute highp vec2 tCoord; \n"
525 "varying highp vec2 sampleCoord; \n"
526 "varying highp vec3 sampleFarLeft; \n"
527 "varying highp vec3 sampleNearLeft; \n"
528 "varying highp vec3 sampleNearRight; \n"
529 "varying highp vec3 sampleFarRight; \n"
531 " sampleCoord = tCoord * textureScale; \n"
532 " gl_Position = matrix * vCoord; \n"
533 // Calculate neighbour pixel position in item space.
534 " highp vec3 wDelta = gl_Position.w * vecDelta.xyw; \n"
535 " highp vec3 farLeft = vCoord.xyw - 0.667 * wDelta; \n"
536 " highp vec3 nearLeft = vCoord.xyw - 0.333 * wDelta; \n"
537 " highp vec3 nearRight = vCoord.xyw + 0.333 * wDelta; \n"
538 " highp vec3 farRight = vCoord.xyw + 0.667 * wDelta; \n"
539 // Calculate neighbour texture coordinate.
540 " highp vec2 scale = textureScale / fontScale; \n"
541 " highp vec2 base = sampleCoord - scale * vCoord.xy; \n"
542 " sampleFarLeft = vec3(base * farLeft.z + scale * farLeft.xy, farLeft.z); \n"
543 " sampleNearLeft = vec3(base * nearLeft.z + scale * nearLeft.xy, nearLeft.z); \n"
544 " sampleNearRight = vec3(base * nearRight.z + scale * nearRight.xy, nearRight.z); \n"
545 " sampleFarRight = vec3(base * farRight.z + scale * farRight.xy, farRight.z); \n"
549 const char *QSGSubPixelDistanceFieldTextMaterialShader::fragmentShader() const {
551 "varying highp vec2 sampleCoord; \n"
552 "varying highp vec3 sampleFarLeft; \n"
553 "varying highp vec3 sampleNearLeft; \n"
554 "varying highp vec3 sampleNearRight; \n"
555 "varying highp vec3 sampleFarRight; \n"
556 "uniform sampler2D texture; \n"
557 "uniform lowp vec4 color; \n"
558 "uniform highp float alphaMin; \n"
559 "uniform highp float alphaMax; \n"
562 " n.x = texture2DProj(texture, sampleFarLeft).a; \n"
563 " n.y = texture2DProj(texture, sampleNearLeft).a; \n"
564 " highp float c = texture2D(texture, sampleCoord).a; \n"
565 " n.z = texture2DProj(texture, sampleNearRight).a; \n"
566 " n.w = texture2DProj(texture, sampleFarRight).a; \n"
569 " n = smoothstep(alphaMin, alphaMax, n); \n"
570 " c = smoothstep(alphaMin, alphaMax, c); \n"
573 " highp vec2 d = min(abs(n.yw - n.xz) * 2., 0.67); \n"
574 " highp vec2 lo = mix(vec2(alphaMin), vec2(0.5), d); \n"
575 " highp vec2 hi = mix(vec2(alphaMax), vec2(0.5), d); \n"
576 " n = smoothstep(lo.xxyy, hi.xxyy, n); \n"
577 " c = smoothstep(lo.x + lo.y, hi.x + hi.y, 2. * c); \n"
579 " gl_FragColor = vec4(0.333 * (n.xyz + n.yzw + c), c) * color.w; \n"
583 //const char *QSGSubPixelDistanceFieldTextMaterialShader::fragmentShader() const {
585 // "#extension GL_OES_standard_derivatives: enable \n"
586 // "varying highp vec2 sampleCoord; \n"
587 // "uniform sampler2D texture; \n"
588 // "uniform lowp vec4 color; \n"
589 // "uniform highp float alphaMin; \n"
590 // "uniform highp float alphaMax; \n"
591 // "void main() { \n"
592 // " highp vec2 delta = dFdx(sampleCoord); \n"
593 // " highp vec4 n; \n"
594 // " n.x = texture2D(texture, sampleCoord - 0.667 * delta).a; \n"
595 // " n.y = texture2D(texture, sampleCoord - 0.333 * delta).a; \n"
596 // " highp float c = texture2D(texture, sampleCoord).a; \n"
597 // " n.z = texture2D(texture, sampleCoord + 0.333 * delta).a; \n"
598 // " n.w = texture2D(texture, sampleCoord + 0.667 * delta).a; \n"
599 // " n = smoothstep(alphaMin, alphaMax, n); \n"
600 // " c = smoothstep(alphaMin, alphaMax, c); \n"
601 // " gl_FragColor = vec4(0.333 * (n.xyz + n.yzw + c), c) * color.w; \n"
605 void QSGSubPixelDistanceFieldTextMaterialShader::initialize()
607 QSGDistanceFieldTextMaterialShader::initialize();
608 m_fontScale_id = program()->uniformLocation("fontScale");
609 m_vecDelta_id = program()->uniformLocation("vecDelta");
612 void QSGSubPixelDistanceFieldTextMaterialShader::activate()
614 QSGDistanceFieldTextMaterialShader::activate();
615 glBlendFunc(GL_CONSTANT_COLOR, GL_ONE_MINUS_SRC_COLOR);
618 void QSGSubPixelDistanceFieldTextMaterialShader::deactivate()
620 QSGDistanceFieldTextMaterialShader::deactivate();
621 glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
624 void QSGSubPixelDistanceFieldTextMaterialShader::updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect)
626 Q_ASSERT(oldEffect == 0 || newEffect->type() == oldEffect->type());
627 QSGDistanceFieldTextMaterial *material = static_cast<QSGDistanceFieldTextMaterial *>(newEffect);
628 QSGDistanceFieldTextMaterial *oldMaterial = static_cast<QSGDistanceFieldTextMaterial *>(oldEffect);
630 if (oldMaterial == 0 || material->color() != oldMaterial->color()) {
631 QColor c = material->color();
632 state.context()->functions()->glBlendColor(c.redF(), c.greenF(), c.blueF(), 1.0f);
635 if (oldMaterial == 0 || material->glyphCache()->fontScale() != oldMaterial->glyphCache()->fontScale())
636 program()->setUniformValue(m_fontScale_id, GLfloat(material->glyphCache()->fontScale()));
638 if (oldMaterial == 0 || state.isMatrixDirty()) {
639 int viewportWidth = state.viewportRect().width();
640 QMatrix4x4 mat = state.combinedMatrix().inverted();
641 program()->setUniformValue(m_vecDelta_id, mat.column(0) * (qreal(2) / viewportWidth));
644 QSGDistanceFieldTextMaterialShader::updateState(state, newEffect, oldEffect);
647 QSGMaterialType *QSGSubPixelDistanceFieldTextMaterial::type() const
649 static QSGMaterialType type;
653 QSGMaterialShader *QSGSubPixelDistanceFieldTextMaterial::createShader() const
655 return new QSGSubPixelDistanceFieldTextMaterialShader;