diff options
Diffstat (limited to 'src/runtime/q3dsscenemanager.cpp')
-rw-r--r-- | src/runtime/q3dsscenemanager.cpp | 84 |
1 files changed, 74 insertions, 10 deletions
diff --git a/src/runtime/q3dsscenemanager.cpp b/src/runtime/q3dsscenemanager.cpp index d6f909c..8dc7aa2 100644 --- a/src/runtime/q3dsscenemanager.cpp +++ b/src/runtime/q3dsscenemanager.cpp @@ -4761,10 +4761,9 @@ Qt3DCore::QEntity *Q3DSSceneManager::buildText(Q3DSTextNode *text3DS, Q3DSLayerN } #if QT_VERSION >= QT_VERSION_CHECK(5,12,2) - static bool distanceFieldRendering = distanceFieldsEnabled(); + static bool shouldDistanceFieldRender = distanceFieldsEnabled(); - bool shouldDistanceFieldRender = distanceFieldRendering && !text3DS->shadow(); - if (data->entity != nullptr && shouldDistanceFieldRender != data->distanceFieldText) { + if (data->entity != nullptr && text3DS->shadow() != data->dropShadow) { for (int i = 0; i < data->glyphsReferencedInSubentity.size(); ++i) { QPair<Q3DSDistanceFieldGlyphCache *, QVector<quint32> > &glyphsReferenced = data->glyphsReferencedInSubentity[i]; if (glyphsReferenced.first != nullptr && !glyphsReferenced.second.isEmpty()) @@ -4791,6 +4790,7 @@ Qt3DCore::QEntity *Q3DSSceneManager::buildText(Q3DSTextNode *text3DS, Q3DSLayerN #if QT_VERSION >= QT_VERSION_CHECK(5,12,2) if (shouldDistanceFieldRender) { data->distanceFieldText = true; + data->dropShadow = text3DS->shadow(); QVector2D boundingBox = text3DS->boundingBox(); QRawFont font = m_fontDatabase->findFont(text3DS->font()); @@ -4969,6 +4969,8 @@ Qt3DCore::QEntity *Q3DSSceneManager::buildText(Q3DSTextNode *text3DS, Q3DSLayerN QVector<quint32> glyphIndexes; Q3DSDistanceFieldGlyphCache *cache; float fontScale; + float shadowOffsetX; + float shadowOffsetY; }; QHash<Q3DSDistanceFieldGlyphCache::TextureInfo *, GlyphInfo> glyphsPerTexture; @@ -5021,6 +5023,8 @@ Qt3DCore::QEntity *Q3DSSceneManager::buildText(Q3DSTextNode *text3DS, Q3DSLayerN cache->processPendingGlyphs(); qreal fontPixelSize = glyphRun.rawFont().pixelSize(); + float shadowOffsetX = float(fontPixelSize) * text3DS->shadowOffsetX() / 1000.0f; + float shadowOffsetY = float(fontPixelSize) * text3DS->shadowOffsetY() / 1000.0f; qreal maxTexMargin = cache->distanceFieldRadius(); qreal fontScale = cache->fontScale(fontPixelSize); qreal margin = 2; @@ -5056,11 +5060,24 @@ Qt3DCore::QEntity *Q3DSSceneManager::buildText(Q3DSTextNode *text3DS, Q3DSLayerN float cy1 = float(position.y() - metrics.baselineY) + offsetY; float cy2 = cy1 + float(metrics.height); + if (text3DS->shadow()) { + cx2 += shadowOffsetX; + cy2 += shadowOffsetY; + } + float tx1 = float(c.x + c.xMargin); float tx2 = tx1 + float(c.width); float ty1 = float(c.y + c.yMargin); float ty2 = ty1 + float(c.height); + float ttx2 = tx2; + float tty2 = ty2; + + if (text3DS->shadow()) { + tx2 += float(c.width) * shadowOffsetX / float(metrics.width); + ty2 += float(c.height) * shadowOffsetY / float(metrics.height); + } + const QSGDistanceFieldGlyphCache::Texture *texture = cache->glyphTexture(glyphIndex); if (texture->textureId == 0) { qWarning() << "Empty texture for glyph" << glyphIndex; @@ -5071,9 +5088,11 @@ Qt3DCore::QEntity *Q3DSSceneManager::buildText(Q3DSTextNode *text3DS, Q3DSLayerN GlyphInfo &glyphInfo = glyphsPerTexture[textureInfo]; glyphInfo.fontScale = float(fontScale); + glyphInfo.shadowOffsetX = shadowOffsetX; + glyphInfo.shadowOffsetY = shadowOffsetY; QVector<float> &vertexes = glyphInfo.vertexes; - vertexes.reserve(vertexes.size() + 10); + vertexes.reserve(vertexes.size() + 20 + (text3DS->shadow() ? 16 : 0)); vertexes.append(cx1); vertexes.append(0.0); @@ -5081,23 +5100,51 @@ Qt3DCore::QEntity *Q3DSSceneManager::buildText(Q3DSTextNode *text3DS, Q3DSLayerN vertexes.append(tx1); vertexes.append(ty1); + if (text3DS->shadow()) { + vertexes.append(tx1); + vertexes.append(ty1); + vertexes.append(ttx2); + vertexes.append(tty2); + } + vertexes.append(cx2); vertexes.append(0.0); vertexes.append(cy1); vertexes.append(tx2); vertexes.append(ty1); + if (text3DS->shadow()) { + vertexes.append(tx1); + vertexes.append(ty1); + vertexes.append(ttx2); + vertexes.append(tty2); + } + vertexes.append(cx2); vertexes.append(0.0); vertexes.append(cy2); vertexes.append(tx2); vertexes.append(ty2); + if (text3DS->shadow()) { + vertexes.append(tx1); + vertexes.append(ty1); + vertexes.append(ttx2); + vertexes.append(tty2); + } + vertexes.append(cx1); vertexes.append(0.0); vertexes.append(cy2); vertexes.append(tx1); vertexes.append(ty2); + + if (text3DS->shadow()) { + vertexes.append(tx1); + vertexes.append(ty1); + vertexes.append(ttx2); + vertexes.append(tty2); + } } } } @@ -5140,11 +5187,23 @@ Qt3DCore::QEntity *Q3DSSceneManager::buildText(Q3DSTextNode *text3DS, Q3DSLayerN Qt3DRender::QParameter *fontScaleParam = new Qt3DRender::QParameter; fontScaleParam->setName(QLatin1String("fontScale")); - Qt3DRender::QMaterial *material = m_distanceFieldMaterialGenerator->generateMaterial({ colorParam, - textureParam, - fontScaleParam, - textureWidthParam, - textureHeightParam }); + QVector<Qt3DRender::QParameter *> params = { colorParam, + textureParam, + fontScaleParam, + textureWidthParam, + textureHeightParam }; + + if (text3DS->shadow()) { + Qt3DRender::QParameter *shadowColorParam = new Qt3DRender::QParameter; + shadowColorParam->setName(QLatin1String("shadowColor")); + params.append(shadowColorParam); + + Qt3DRender::QParameter *shadowOffsetParam = new Qt3DRender::QParameter; + shadowOffsetParam->setName(QLatin1String("shadowOffset")); + params.append(shadowOffsetParam); + } + + Qt3DRender::QMaterial *material = m_distanceFieldMaterialGenerator->generateMaterial(params, text3DS->shadow()); subentity->addComponent(material); subentities.append(subentity); } @@ -5152,6 +5211,7 @@ Qt3DCore::QEntity *Q3DSSceneManager::buildText(Q3DSTextNode *text3DS, Q3DSLayerN QHash<Q3DSDistanceFieldGlyphCache::TextureInfo *, GlyphInfo>::const_iterator it; int subentityIndex = 0; + int shadowRgb = int(2.55f * (100 - int(text3DS->shadowStrength()))); for (it = glyphsPerTexture.constBegin(); it != glyphsPerTexture.constEnd(); ++it) { const GlyphInfo &glyphInfo = it.value(); const QVector<float> &vertexes = glyphInfo.vertexes; @@ -5168,7 +5228,7 @@ Qt3DCore::QEntity *Q3DSSceneManager::buildText(Q3DSTextNode *text3DS, Q3DSLayerN { Q3DSTextMesh *mesh = qobject_cast<Q3DSTextMesh *>(component); if (mesh != nullptr) - mesh->setVertexes(vertexes); + mesh->setVertexes(vertexes, text3DS->shadow()); } { @@ -5184,6 +5244,10 @@ Qt3DCore::QEntity *Q3DSSceneManager::buildText(Q3DSTextNode *text3DS, Q3DSLayerN parameter->setValue(color * data->globalOpacity); data->colorParam.append(parameter); + } else if (parameter->name() == QLatin1String("shadowColor")) { + parameter->setValue(QColor(shadowRgb, shadowRgb, shadowRgb)); + } else if (parameter->name() == QLatin1String("shadowOffset")) { + parameter->setValue(QVector2D(glyphInfo.shadowOffsetX, glyphInfo.shadowOffsetY)); } else if (parameter->name() == QLatin1String("_qt_texture")) { parameter->setValue(QVariant::fromValue(it.key()->texture)); } else if (parameter->name() == QLatin1String("fontScale")) { |