Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qsgdistancefieldglyphnode_p.cpp
Go to the documentation of this file.
1// Copyright (C) 2019 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
7#include <QtGui/qsurface.h>
8#include <QtGui/qwindow.h>
9#include <qmath.h>
10
12
13static float qt_sg_envFloat(const char *name, float defaultValue)
14{
15 if (Q_LIKELY(!qEnvironmentVariableIsSet(name)))
16 return defaultValue;
17 bool ok = false;
18 const float value = qgetenv(name).toFloat(&ok);
19 return ok ? value : defaultValue;
20}
21
22static float thresholdFunc(float glyphScale)
23{
24 static const float base = qt_sg_envFloat("QT_DF_BASE", 0.5f);
25 static const float baseDev = qt_sg_envFloat("QT_DF_BASEDEVIATION", 0.065f);
26 static const float devScaleMin = qt_sg_envFloat("QT_DF_SCALEFORMAXDEV", 0.15f);
27 static const float devScaleMax = qt_sg_envFloat("QT_DF_SCALEFORNODEV", 0.3f);
28 return base - ((qBound(devScaleMin, glyphScale, devScaleMax) - devScaleMin) / (devScaleMax - devScaleMin) * -baseDev + baseDev);
29}
30
31static float spreadFunc(float glyphScale)
32{
33 static const float range = qt_sg_envFloat("QT_DF_RANGE", 0.06f);
34 return range / glyphScale;
35}
36
38{
39public:
40 QSGDistanceFieldTextMaterialRhiShader(bool alphaTexture, int viewCount);
41
42 bool updateUniformData(RenderState &state,
43 QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
44
45 void updateSampledImage(RenderState &state, int binding, QSGTexture **texture,
46 QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
47
48protected:
49 float m_fontScale = 1.0;
50 float m_matrixScale = 1.0;
52};
53
55{
56 setShaderFileName(VertexStage, QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/distancefieldtext.vert.qsb"), viewCount);
57 if (alphaTexture)
58 setShaderFileName(FragmentStage, QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/distancefieldtext_a.frag.qsb"), viewCount);
59 else
60 setShaderFileName(FragmentStage, QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/distancefieldtext.frag.qsb"), viewCount);
61}
62
64 QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
65{
66 Q_ASSERT(oldMaterial == nullptr || newMaterial->type() == oldMaterial->type());
67 QSGDistanceFieldTextMaterial *mat = static_cast<QSGDistanceFieldTextMaterial *>(newMaterial);
68 QSGDistanceFieldTextMaterial *oldMat = static_cast<QSGDistanceFieldTextMaterial *>(oldMaterial);
69
70 // updateUniformData() is called before updateSampledImage() by the
71 // renderer. Hence updating the glyph cache stuff here.
72 const bool textureUpdated = mat->updateTextureSizeAndWrapper();
73 Q_ASSERT(mat->wrapperTexture());
74 Q_ASSERT(oldMat == nullptr || oldMat->texture());
75
76 bool changed = false;
77 QByteArray *buf = state.uniformData();
78 Q_ASSERT(buf->size() >= 104);
79
80 bool updateRange = false;
81 if (!oldMat || mat->fontScale() != oldMat->fontScale()) {
82 m_fontScale = mat->fontScale();
83 updateRange = true;
84 }
85 if (state.isMatrixDirty()) {
86 m_matrixScale = qSqrt(qAbs(state.determinant())) * state.devicePixelRatio();
87 updateRange = true;
88 }
89 quint32 offset = 0;
90 const int matrixCount = qMin(state.projectionMatrixCount(), newMaterial->viewCount());
91 for (int viewIndex = 0; viewIndex < matrixCount; ++viewIndex) {
92 if (state.isMatrixDirty()) {
93 const QMatrix4x4 m = state.combinedMatrix(viewIndex);
94 memcpy(buf->data() + 64 * viewIndex, m.constData(), 64);
95 changed = true;
96 }
97 offset += 64;
98 }
99 if (textureUpdated || !oldMat || oldMat->texture()->texture != mat->texture()->texture) {
100 const QVector2D ts(1.0f / mat->textureSize().width(), 1.0f / mat->textureSize().height());
101 Q_ASSERT(sizeof(ts) == 8);
102 memcpy(buf->data() + offset, &ts, 8);
103 changed = true;
104 }
105 offset += 8 + 8; // 8 is padding for vec4 alignment
106 if (!oldMat || mat->color() != oldMat->color() || state.isOpacityDirty()) {
107 const QVector4D color = mat->color() * state.opacity();
108 Q_ASSERT(sizeof(color) == 16);
109 memcpy(buf->data() + offset, &color, 16);
110 changed = true;
111 }
112 offset += 16;
113 if (updateRange) { // deferred because depends on m_fontScale and m_matrixScale
114 const float combinedScale = m_fontScale * m_matrixScale;
115 const float base = thresholdFunc(combinedScale);
116 const float range = spreadFunc(combinedScale);
117 const QVector2D alphaMinMax(qMax(0.0f, base - range), qMin(base + range, 1.0f));
118 memcpy(buf->data() + offset, &alphaMinMax, 8);
119 changed = true;
120 }
121 offset += 8; // not adding any padding here since we are not sure what comes afterwards in the subclasses' shaders
122
123 // move texture uploads/copies onto the renderer's soon-to-be-committed list
124 static_cast<QSGRhiDistanceFieldGlyphCache *>(mat->glyphCache())->commitResourceUpdates(state.resourceUpdateBatch());
125
126 m_currentUbufOffset = offset;
127 return changed;
128}
129
130void QSGDistanceFieldTextMaterialRhiShader::updateSampledImage(RenderState &state, int binding, QSGTexture **texture,
131 QSGMaterial *newMaterial, QSGMaterial *)
132{
133 Q_UNUSED(state);
134 if (binding != 1)
135 return;
136
137 QSGDistanceFieldTextMaterial *mat = static_cast<QSGDistanceFieldTextMaterial *>(newMaterial);
138 QSGTexture *t = mat->wrapperTexture();
139 t->setFiltering(QSGTexture::Linear);
140 *texture = t;
141}
142
148
150 : QSGDistanceFieldTextMaterialRhiShader(alphaTexture, viewCount)
151{
152 setShaderFileName(VertexStage, QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/distancefieldtext.vert.qsb"), viewCount);
153 if (alphaTexture)
154 setShaderFileName(FragmentStage, QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/distancefieldtext_a_fwidth.frag.qsb"), viewCount);
155 else
156 setShaderFileName(FragmentStage, QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/distancefieldtext_fwidth.frag.qsb"), viewCount);
157}
158
159QSGDistanceFieldTextMaterial::QSGDistanceFieldTextMaterial()
160 : m_glyph_cache(nullptr)
161 , m_texture(nullptr)
162 , m_fontScale(1.0)
163 , m_sgTexture(nullptr)
164{
165 setFlag(Blending | RequiresDeterminant, true);
166}
167
168QSGDistanceFieldTextMaterial::~QSGDistanceFieldTextMaterial()
169{
170 delete m_sgTexture;
171}
172
173QSGMaterialType *QSGDistanceFieldTextMaterial::type() const
174{
175 static QSGMaterialType type;
176 return &type;
177}
178
179void QSGDistanceFieldTextMaterial::setColor(const QColor &color)
180{
181 float r, g, b, a;
182 color.getRgbF(&r, &g, &b, &a);
183 m_color = QVector4D(r * a, g * a, b * a, a);
184}
185
186QSGMaterialShader *QSGDistanceFieldTextMaterial::createShader(QSGRendererInterface::RenderMode renderMode) const
187{
188 if (renderMode == QSGRendererInterface::RenderMode3D && m_glyph_cache->screenSpaceDerivativesSupported())
189 return new DistanceFieldAnisotropicTextMaterialRhiShader(m_glyph_cache->eightBitFormatIsAlphaSwizzled(), viewCount());
190 else
191 return new QSGDistanceFieldTextMaterialRhiShader(m_glyph_cache->eightBitFormatIsAlphaSwizzled(), viewCount());
192}
193
194bool QSGDistanceFieldTextMaterial::updateTextureSize()
195{
196 if (!m_texture)
197 m_texture = m_glyph_cache->glyphTexture(0); // invalid texture
198
199 if (m_texture->size != m_size) {
200 m_size = m_texture->size;
201 return true;
202 }
203
204 return false;
205}
206
207// When using the RHI we need a QSGTexture wrapping the QRhiTexture, just
208// exposing a QRhiTexture * (which would be the equivalent of GLuint textureId)
209// is not sufficient to play nice with the material.
210bool QSGDistanceFieldTextMaterial::updateTextureSizeAndWrapper()
211{
212 bool updated = updateTextureSize();
213 if (updated) {
214 if (m_sgTexture)
215 delete m_sgTexture;
216 m_sgTexture = new QSGPlainTexture;
217 m_sgTexture->setTexture(m_texture->texture);
218 m_sgTexture->setTextureSize(m_size);
219 m_sgTexture->setOwnsTexture(false);
220 }
221 return updated;
222}
223
224int QSGDistanceFieldTextMaterial::compare(const QSGMaterial *o) const
225{
226 Q_ASSERT(o && type() == o->type());
227 const QSGDistanceFieldTextMaterial *other = static_cast<const QSGDistanceFieldTextMaterial *>(o);
228 if (m_glyph_cache != other->m_glyph_cache)
229 return m_glyph_cache - other->m_glyph_cache;
230 if (m_fontScale != other->m_fontScale) {
231 return int(other->m_fontScale < m_fontScale) - int(m_fontScale < other->m_fontScale);
232 }
233 if (m_color != other->m_color)
234 return &m_color < &other->m_color ? -1 : 1;
235 qintptr t0 = m_texture ? qintptr(m_texture->texture) : 0;
236 qintptr t1 = other->m_texture ? qintptr(other->m_texture->texture) : 0;
237 const qintptr diff = t0 - t1;
238 return diff < 0 ? -1 : (diff > 0 ? 1 : 0);
239}
241{
242public:
243 DistanceFieldStyledTextMaterialRhiShader(bool alphaTexture, int viewCount);
244
245 bool updateUniformData(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
246};
247
252
254 QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
255{
256 bool changed = QSGDistanceFieldTextMaterialRhiShader::updateUniformData(state, newMaterial, oldMaterial);
257 QSGDistanceFieldStyledTextMaterial *mat = static_cast<QSGDistanceFieldStyledTextMaterial *>(newMaterial);
258 QSGDistanceFieldStyledTextMaterial *oldMat = static_cast<QSGDistanceFieldStyledTextMaterial *>(oldMaterial);
259
260 QByteArray *buf = state.uniformData();
261 Q_ASSERT(buf->size() >= 128);
262
263 // must add 8 bytes padding for vec4 alignment, the base class did not do this
264 m_currentUbufOffset += 8; // now at StyleColor
265
266 if (!oldMat || mat->styleColor() != oldMat->styleColor() || state.isOpacityDirty()) {
267 QVector4D styleColor = mat->styleColor();
268 styleColor *= state.opacity();
269
270 memcpy(buf->data() + m_currentUbufOffset, &styleColor, 16);
271 changed = true;
272 }
273 m_currentUbufOffset += 16;
274
275 return changed;
276}
277
278QSGDistanceFieldStyledTextMaterial::QSGDistanceFieldStyledTextMaterial()
279 : QSGDistanceFieldTextMaterial()
280{
281}
282
283QSGDistanceFieldStyledTextMaterial::~QSGDistanceFieldStyledTextMaterial()
284{
285}
286
287void QSGDistanceFieldStyledTextMaterial::setStyleColor(const QColor &color)
288{
289 float r, g, b, a;
290 color.getRgbF(&r, &g, &b, &a);
291 m_styleColor = QVector4D(r * a, g * a, b * a, a);
292}
293
294int QSGDistanceFieldStyledTextMaterial::compare(const QSGMaterial *o) const
295{
296 Q_ASSERT(o && type() == o->type());
297 const QSGDistanceFieldStyledTextMaterial *other = static_cast<const QSGDistanceFieldStyledTextMaterial *>(o);
298 if (m_styleColor != other->m_styleColor)
299 return &m_styleColor < &other->m_styleColor ? -1 : 1;
300 return QSGDistanceFieldTextMaterial::compare(o);
301}
302
304{
305public:
306 DistanceFieldOutlineTextMaterialRhiShader(bool alphaTexture, int viewCount);
307
308 bool updateUniformData(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
309};
310
312 : DistanceFieldStyledTextMaterialRhiShader(alphaTexture, viewCount)
313{
314 setShaderFileName(VertexStage, QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/distancefieldoutlinetext.vert.qsb"), viewCount);
315 if (alphaTexture)
316 setShaderFileName(FragmentStage, QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/distancefieldoutlinetext_a.frag.qsb"), viewCount);
317 else
318 setShaderFileName(FragmentStage, QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/distancefieldoutlinetext.frag.qsb"), viewCount);
319}
320
326
329{
330 setShaderFileName(VertexStage, QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/distancefieldoutlinetext.vert.qsb"), viewCount);
331 if (alphaTexture)
332 setShaderFileName(FragmentStage, QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/distancefieldoutlinetext_a_fwidth.frag.qsb"), viewCount);
333 else
334 setShaderFileName(FragmentStage, QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/distancefieldoutlinetext_fwidth.frag.qsb"), viewCount);
335}
336
338 QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
339{
340 bool changed = DistanceFieldStyledTextMaterialRhiShader::updateUniformData(state, newMaterial, oldMaterial);
341 QSGDistanceFieldOutlineTextMaterial *mat = static_cast<QSGDistanceFieldOutlineTextMaterial *>(newMaterial);
342 QSGDistanceFieldOutlineTextMaterial *oldMat = static_cast<QSGDistanceFieldOutlineTextMaterial *>(oldMaterial);
343
344 QByteArray *buf = state.uniformData();
345 Q_ASSERT(buf->size() >= 136);
346
347 if (!oldMat || mat->fontScale() != oldMat->fontScale() || state.isMatrixDirty()) {
348 float dfRadius = mat->glyphCache()->distanceFieldRadius();
349 float combinedScale = m_fontScale * m_matrixScale;
350 float base = thresholdFunc(combinedScale);
351 float range = spreadFunc(combinedScale);
352 float outlineLimit = qMax(0.2f, base - 0.5f / dfRadius / m_fontScale);
353 float alphaMin = qMax(0.0f, base - range);
354 float styleAlphaMin0 = qMax(0.0f, outlineLimit - range);
355 float styleAlphaMin1 = qMin(outlineLimit + range, alphaMin);
356 memcpy(buf->data() + m_currentUbufOffset, &styleAlphaMin0, 4);
357 memcpy(buf->data() + m_currentUbufOffset + 4, &styleAlphaMin1, 4);
358 changed = true;
359 }
360
361 return changed;
362}
363
364QSGDistanceFieldOutlineTextMaterial::QSGDistanceFieldOutlineTextMaterial()
365 : QSGDistanceFieldStyledTextMaterial()
366{
367}
368
369QSGDistanceFieldOutlineTextMaterial::~QSGDistanceFieldOutlineTextMaterial()
370{
371}
372
373QSGMaterialType *QSGDistanceFieldOutlineTextMaterial::type() const
374{
375 static QSGMaterialType type;
376 return &type;
377}
378
379QSGMaterialShader *QSGDistanceFieldOutlineTextMaterial::createShader(QSGRendererInterface::RenderMode renderMode) const
380{
381 if (renderMode == QSGRendererInterface::RenderMode3D && m_glyph_cache->screenSpaceDerivativesSupported())
382 return new DistanceFieldAnisotropicOutlineTextMaterialRhiShader(m_glyph_cache->eightBitFormatIsAlphaSwizzled(), viewCount());
383 else
384 return new DistanceFieldOutlineTextMaterialRhiShader(m_glyph_cache->eightBitFormatIsAlphaSwizzled(), viewCount());
385}
386
388{
389public:
390 DistanceFieldShiftedStyleTextMaterialRhiShader(bool alphaTexture, int viewCount);
391
392 bool updateUniformData(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
393};
394
396 : DistanceFieldStyledTextMaterialRhiShader(alphaTexture, viewCount)
397{
398 setShaderFileName(VertexStage, QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/distancefieldshiftedtext.vert.qsb"), viewCount);
399 if (alphaTexture)
400 setShaderFileName(FragmentStage, QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/distancefieldshiftedtext_a.frag.qsb"), viewCount);
401 else
402 setShaderFileName(FragmentStage, QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/distancefieldshiftedtext.frag.qsb"), viewCount);
403}
404
406 QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
407{
408 bool changed = DistanceFieldStyledTextMaterialRhiShader::updateUniformData(state, newMaterial, oldMaterial);
409 QSGDistanceFieldShiftedStyleTextMaterial *mat = static_cast<QSGDistanceFieldShiftedStyleTextMaterial *>(newMaterial);
410 QSGDistanceFieldShiftedStyleTextMaterial *oldMat = static_cast<QSGDistanceFieldShiftedStyleTextMaterial *>(oldMaterial);
411
412 QByteArray *buf = state.uniformData();
413 Q_ASSERT(buf->size() >= 136);
414
415 if (!oldMat || oldMat->fontScale() != mat->fontScale() || oldMat->shift() != mat->shift()
416 || oldMat->textureSize() != mat->textureSize())
417 {
418 QVector2D shift(1.0 / mat->fontScale() * mat->shift().x(),
419 1.0 / mat->fontScale() * mat->shift().y());
420 memcpy(buf->data() + m_currentUbufOffset, &shift, 8);
421 changed = true;
422 }
423
424 return changed;
425}
426
432
435{
436 setShaderFileName(VertexStage, QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/distancefieldshiftedtext.vert.qsb"), viewCount);
437 if (alphaTexture)
438 setShaderFileName(FragmentStage, QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/distancefieldshiftedtext_a_fwidth.frag.qsb"), viewCount);
439 else
440 setShaderFileName(FragmentStage, QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/distancefieldshiftedtext_fwidth.frag.qsb"), viewCount);
441}
442
443QSGDistanceFieldShiftedStyleTextMaterial::QSGDistanceFieldShiftedStyleTextMaterial()
444 : QSGDistanceFieldStyledTextMaterial()
445{
446}
447
448QSGDistanceFieldShiftedStyleTextMaterial::~QSGDistanceFieldShiftedStyleTextMaterial()
449{
450}
451
452QSGMaterialType *QSGDistanceFieldShiftedStyleTextMaterial::type() const
453{
454 static QSGMaterialType type;
455 return &type;
456}
457
458QSGMaterialShader *QSGDistanceFieldShiftedStyleTextMaterial::createShader(QSGRendererInterface::RenderMode renderMode) const
459{
460 if (renderMode == QSGRendererInterface::RenderMode3D && m_glyph_cache->screenSpaceDerivativesSupported())
461 return new DistanceFieldAnisotropicShiftedTextMaterialRhiShader(m_glyph_cache->eightBitFormatIsAlphaSwizzled(), viewCount());
462 else
463 return new DistanceFieldShiftedStyleTextMaterialRhiShader(m_glyph_cache->eightBitFormatIsAlphaSwizzled(), viewCount());
464}
465
466int QSGDistanceFieldShiftedStyleTextMaterial::compare(const QSGMaterial *o) const
467{
468 const QSGDistanceFieldShiftedStyleTextMaterial *other = static_cast<const QSGDistanceFieldShiftedStyleTextMaterial *>(o);
469 if (m_shift != other->m_shift)
470 return &m_shift < &other->m_shift ? -1 : 1;
471 return QSGDistanceFieldStyledTextMaterial::compare(o);
472}
473
475{
476public:
477 QSGHiQSubPixelDistanceFieldTextMaterialRhiShader(bool alphaTexture, int viewCount);
478
479 bool updateUniformData(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
480 bool updateGraphicsPipelineState(RenderState &state, GraphicsPipelineState *ps,
481 QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
482};
483
485 : QSGDistanceFieldTextMaterialRhiShader(alphaTexture, viewCount)
486{
487 setFlag(UpdatesGraphicsPipelineState, true);
488 setShaderFileName(VertexStage, QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/hiqsubpixeldistancefieldtext.vert.qsb"), viewCount);
489 if (alphaTexture)
490 setShaderFileName(FragmentStage, QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/hiqsubpixeldistancefieldtext_a.frag.qsb"), viewCount);
491 else
492 setShaderFileName(FragmentStage, QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/hiqsubpixeldistancefieldtext.frag.qsb"), viewCount);
493}
494
496 QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
497{
498 bool changed = QSGDistanceFieldTextMaterialRhiShader::updateUniformData(state, newMaterial, oldMaterial);
499 QSGHiQSubPixelDistanceFieldTextMaterial *mat = static_cast<QSGHiQSubPixelDistanceFieldTextMaterial *>(newMaterial);
500 QSGHiQSubPixelDistanceFieldTextMaterial *oldMat = static_cast<QSGHiQSubPixelDistanceFieldTextMaterial *>(oldMaterial);
501
502 QByteArray *buf = state.uniformData();
503 Q_ASSERT(buf->size() >= 128);
504
505 if (!oldMat || mat->fontScale() != oldMat->fontScale()) {
506 float fontScale = mat->fontScale();
507 memcpy(buf->data() + m_currentUbufOffset, &fontScale, 4);
508 changed = true;
509 }
510 m_currentUbufOffset += 4 + 4; // 4 for padding for vec2 alignment
511
512 if (!oldMat || state.isMatrixDirty()) {
513 int viewportWidth = state.viewportRect().width();
514 QMatrix4x4 mat = state.combinedMatrix().inverted();
515 QVector4D vecDelta = mat.column(0) * (qreal(2) / viewportWidth);
516 memcpy(buf->data() + m_currentUbufOffset, &vecDelta, 16);
517 }
518
519 return changed;
520}
521
522bool QSGHiQSubPixelDistanceFieldTextMaterialRhiShader::updateGraphicsPipelineState(RenderState &state, GraphicsPipelineState *ps,
523 QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
524{
525 Q_UNUSED(state);
526 Q_UNUSED(oldMaterial);
527 QSGHiQSubPixelDistanceFieldTextMaterial *mat = static_cast<QSGHiQSubPixelDistanceFieldTextMaterial *>(newMaterial);
528
529 ps->blendEnable = true;
530 ps->srcColor = GraphicsPipelineState::ConstantColor;
531 ps->dstColor = GraphicsPipelineState::OneMinusSrcColor;
532
533 const QVector4D color = mat->color();
534 // this is dynamic state but it's - magic! - taken care of by the renderer
535 ps->blendConstant = QColor::fromRgbF(color.x(), color.y(), color.z(), 1.0f);
536
537 return true;
538}
539
540QSGMaterialType *QSGHiQSubPixelDistanceFieldTextMaterial::type() const
541{
542 static QSGMaterialType type;
543 return &type;
544}
545
546QSGMaterialShader *QSGHiQSubPixelDistanceFieldTextMaterial::createShader(QSGRendererInterface::RenderMode renderMode) const
547{
548 if (renderMode == QSGRendererInterface::RenderMode3D && m_glyph_cache->screenSpaceDerivativesSupported())
549 return new DistanceFieldAnisotropicTextMaterialRhiShader(m_glyph_cache->eightBitFormatIsAlphaSwizzled(), viewCount());
550 else
551 return new QSGHiQSubPixelDistanceFieldTextMaterialRhiShader(m_glyph_cache->eightBitFormatIsAlphaSwizzled(), viewCount());
552}
553
559
562{
563 setShaderFileName(VertexStage, QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/loqsubpixeldistancefieldtext.vert.qsb"), viewCount);
564 if (alphaTexture)
565 setShaderFileName(FragmentStage, QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/loqsubpixeldistancefieldtext_a.frag.qsb"), viewCount);
566 else
567 setShaderFileName(FragmentStage, QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/loqsubpixeldistancefieldtext.frag.qsb"), viewCount);
568}
569
570QSGMaterialType *QSGLoQSubPixelDistanceFieldTextMaterial::type() const
571{
572 static QSGMaterialType type;
573 return &type;
574}
575
576QSGMaterialShader *QSGLoQSubPixelDistanceFieldTextMaterial::createShader(QSGRendererInterface::RenderMode renderMode) const
577{
578 if (renderMode == QSGRendererInterface::RenderMode3D && m_glyph_cache->screenSpaceDerivativesSupported())
579 return new DistanceFieldAnisotropicTextMaterialRhiShader(m_glyph_cache->eightBitFormatIsAlphaSwizzled(), viewCount());
580 else
581 return new QSGLoQSubPixelDistanceFieldTextMaterialRhiShader(m_glyph_cache->eightBitFormatIsAlphaSwizzled(), viewCount());
582}
583
584QT_END_NAMESPACE
DistanceFieldAnisotropicOutlineTextMaterialRhiShader(bool alphaTexture, int viewCount)
DistanceFieldAnisotropicShiftedTextMaterialRhiShader(bool alphaTexture, int viewCount)
DistanceFieldAnisotropicTextMaterialRhiShader(bool alphaTexture, int viewCount)
bool updateUniformData(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override
This function is called by the scene graph to get the contents of the shader program's uniform buffer...
DistanceFieldOutlineTextMaterialRhiShader(bool alphaTexture, int viewCount)
bool updateUniformData(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override
This function is called by the scene graph to get the contents of the shader program's uniform buffer...
DistanceFieldShiftedStyleTextMaterialRhiShader(bool alphaTexture, int viewCount)
DistanceFieldStyledTextMaterialRhiShader(bool alphaTexture, int viewCount)
bool updateUniformData(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override
This function is called by the scene graph to get the contents of the shader program's uniform buffer...
void updateSampledImage(RenderState &state, int binding, QSGTexture **texture, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override
This function is called by the scene graph to prepare use of sampled images in the shader,...
bool updateUniformData(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override
This function is called by the scene graph to get the contents of the shader program's uniform buffer...
QSGDistanceFieldTextMaterialRhiShader(bool alphaTexture, int viewCount)
QSGHiQSubPixelDistanceFieldTextMaterialRhiShader(bool alphaTexture, int viewCount)
bool updateGraphicsPipelineState(RenderState &state, GraphicsPipelineState *ps, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override
This function is called by the scene graph to enable the material to provide a custom set of graphics...
bool updateUniformData(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override
This function is called by the scene graph to get the contents of the shader program's uniform buffer...
QSGLoQSubPixelDistanceFieldTextMaterialRhiShader(bool alphaTexture, int viewCount)
Combined button and popup list for selecting options.
static float thresholdFunc(float glyphScale)
static QT_BEGIN_NAMESPACE float qt_sg_envFloat(const char *name, float defaultValue)
static float spreadFunc(float glyphScale)