aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEirik Aavitsland <eirik.aavitsland@qt.io>2024-05-02 16:45:20 +0200
committerEirik Aavitsland <eirik.aavitsland@qt.io>2024-05-03 12:14:05 +0200
commit68b2bab607d6c913447b1f6c6790ad657a6ab618 (patch)
treef374208048ed00c62518746e91c2c6a76c0d38f2 /src
parentc63bb2bad5b4e741ed8a1e16d8f1f916c9baf61d (diff)
Clean up Curve renderer fill material and shader
Remove remnants of earlier stroking implementation that was still present in the fill material and shader. Also avoid copying the GradientDesc structure on every frame. Change-Id: Ic5d6d64bff096ab26b1597221ad22040aec5e9c8 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/quick/scenegraph/qsgcurvefillnode_p.cpp95
-rw-r--r--src/quick/scenegraph/qsgcurvefillnode_p.h38
-rw-r--r--src/quick/scenegraph/shaders_ng/shapecurve.frag26
-rw-r--r--src/quick/scenegraph/shaders_ng/shapecurve.vert8
4 files changed, 29 insertions, 138 deletions
diff --git a/src/quick/scenegraph/qsgcurvefillnode_p.cpp b/src/quick/scenegraph/qsgcurvefillnode_p.cpp
index 22cda00550..387f4b3ce6 100644
--- a/src/quick/scenegraph/qsgcurvefillnode_p.cpp
+++ b/src/quick/scenegraph/qsgcurvefillnode_p.cpp
@@ -15,9 +15,8 @@ namespace {
{
public:
QSGCurveFillMaterialShader(QGradient::Type gradientType,
- bool includeStroke,
- bool useDerivatives,
- int viewCount);
+ bool useDerivatives,
+ int viewCount);
bool updateUniformData(RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) override;
void updateSampledImage(RenderState &state, int binding, QSGTexture **texture,
@@ -25,9 +24,8 @@ namespace {
};
QSGCurveFillMaterialShader::QSGCurveFillMaterialShader(QGradient::Type gradientType,
- bool includeStroke,
- bool useDerivatives,
- int viewCount)
+ bool useDerivatives,
+ int viewCount)
{
QString baseName = QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/shapecurve");
@@ -39,9 +37,6 @@ namespace {
baseName += QStringLiteral("_cg");
}
- if (includeStroke)
- baseName += QStringLiteral("_stroke");
-
if (useDerivatives)
baseName += QStringLiteral("_derivatives");
@@ -50,7 +45,7 @@ namespace {
}
void QSGCurveFillMaterialShader::updateSampledImage(RenderState &state, int binding, QSGTexture **texture,
- QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
+ QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
{
Q_UNUSED(oldMaterial);
const QSGCurveFillMaterial *m = static_cast<QSGCurveFillMaterial *>(newMaterial);
@@ -58,8 +53,8 @@ namespace {
if (binding != 1 || node->gradientType() == QGradient::NoGradient)
return;
- const QSGGradientCacheKey cacheKey(node->fillGradient().stops,
- node->fillGradient().spread);
+ const QSGGradientCacheKey cacheKey(node->fillGradient()->stops,
+ node->fillGradient()->spread);
QSGTexture *t = QSGGradientCache::cacheForRhi(state.rhi())->get(cacheKey);
t->commitTextureOperations(state.rhi(), state.resourceUpdateBatch());
*texture = t;
@@ -110,35 +105,6 @@ namespace {
}
offset += 8;
- if (newNode->hasStroke()) {
- Q_ASSERT(buf->size() >= offset + 32);
- QVector4D newStrokeColor(newNode->strokeColor().redF(),
- newNode->strokeColor().greenF(),
- newNode->strokeColor().blueF(),
- newNode->strokeColor().alphaF());
- QVector4D oldStrokeColor = oldNode != nullptr
- ? QVector4D(oldNode->strokeColor().redF(),
- oldNode->strokeColor().greenF(),
- oldNode->strokeColor().blueF(),
- oldNode->strokeColor().alphaF())
- : QVector4D{};
-
- if (oldNode == nullptr || oldStrokeColor != newStrokeColor) {
- memcpy(buf->data() + offset, &newStrokeColor, 16);
- changed = true;
- }
- offset += 16;
-
- if (oldNode == nullptr
- || !qFuzzyCompare(newNode->strokeWidth(), oldNode->strokeWidth())
- || (state.isMatrixDirty() && newNode->strokeWidth() > 0.0f)) {
- float w = newNode->strokeWidth() * matrixScale; // matrixScale calculated earlier
- memcpy(buf->data() + offset, &w, 4);
- changed = true;
- }
- offset += 16;
- }
-
if (newNode->gradientType() == QGradient::NoGradient) {
Q_ASSERT(buf->size() >= offset + 16);
@@ -162,9 +128,9 @@ namespace {
} else if (newNode->gradientType() == QGradient::LinearGradient) {
Q_ASSERT(buf->size() >= offset + 8 + 8);
- QVector2D newGradientStart = QVector2D(newNode->fillGradient().a);
+ QVector2D newGradientStart = QVector2D(newNode->fillGradient()->a);
QVector2D oldGradientStart = oldNode != nullptr
- ? QVector2D(oldNode->fillGradient().a)
+ ? QVector2D(oldNode->fillGradient()->a)
: QVector2D{};
if (newGradientStart != oldGradientStart || oldEffect == nullptr) {
@@ -173,9 +139,9 @@ namespace {
}
offset += 8;
- QVector2D newGradientEnd = QVector2D(newNode->fillGradient().b);
+ QVector2D newGradientEnd = QVector2D(newNode->fillGradient()->b);
QVector2D oldGradientEnd = oldNode!= nullptr
- ? QVector2D(oldNode->fillGradient().b)
+ ? QVector2D(oldNode->fillGradient()->b)
: QVector2D{};
if (newGradientEnd != oldGradientEnd || oldEffect == nullptr) {
@@ -187,9 +153,9 @@ namespace {
} else if (newNode->gradientType() == QGradient::RadialGradient) {
Q_ASSERT(buf->size() >= offset + 8 + 8 + 4 + 4);
- QVector2D newFocalPoint = QVector2D(newNode->fillGradient().b);
+ QVector2D newFocalPoint = QVector2D(newNode->fillGradient()->b);
QVector2D oldFocalPoint = oldNode != nullptr
- ? QVector2D(oldNode->fillGradient().b)
+ ? QVector2D(oldNode->fillGradient()->b)
: QVector2D{};
if (oldNode == nullptr || newFocalPoint != oldFocalPoint) {
memcpy(buf->data() + offset, &newFocalPoint, 8);
@@ -197,9 +163,9 @@ namespace {
}
offset += 8;
- QVector2D newCenterPoint = QVector2D(newNode->fillGradient().a);
+ QVector2D newCenterPoint = QVector2D(newNode->fillGradient()->a);
QVector2D oldCenterPoint = oldNode != nullptr
- ? QVector2D(oldNode->fillGradient().a)
+ ? QVector2D(oldNode->fillGradient()->a)
: QVector2D{};
QVector2D newCenterToFocal = newCenterPoint - newFocalPoint;
@@ -210,9 +176,9 @@ namespace {
}
offset += 8;
- float newCenterRadius = newNode->fillGradient().v0;
+ float newCenterRadius = newNode->fillGradient()->v0;
float oldCenterRadius = oldNode != nullptr
- ? oldNode->fillGradient().v0
+ ? oldNode->fillGradient()->v0
: 0.0f;
if (oldNode == nullptr || !qFuzzyCompare(newCenterRadius, oldCenterRadius)) {
memcpy(buf->data() + offset, &newCenterRadius, 4);
@@ -220,9 +186,9 @@ namespace {
}
offset += 4;
- float newFocalRadius = newNode->fillGradient().v1;
+ float newFocalRadius = newNode->fillGradient()->v1;
float oldFocalRadius = oldNode != nullptr
- ? oldNode->fillGradient().v1
+ ? oldNode->fillGradient()->v1
: 0.0f;
if (oldNode == nullptr || !qFuzzyCompare(newFocalRadius, oldFocalRadius)) {
memcpy(buf->data() + offset, &newFocalRadius, 4);
@@ -233,9 +199,9 @@ namespace {
} else if (newNode->gradientType() == QGradient::ConicalGradient) {
Q_ASSERT(buf->size() >= offset + 8 + 4);
- QVector2D newFocalPoint = QVector2D(newNode->fillGradient().a);
+ QVector2D newFocalPoint = QVector2D(newNode->fillGradient()->a);
QVector2D oldFocalPoint = oldNode != nullptr
- ? QVector2D(oldNode->fillGradient().a)
+ ? QVector2D(oldNode->fillGradient()->a)
: QVector2D{};
if (oldNode == nullptr || newFocalPoint != oldFocalPoint) {
memcpy(buf->data() + offset, &newFocalPoint, 8);
@@ -243,9 +209,9 @@ namespace {
}
offset += 8;
- float newAngle = newNode->fillGradient().v0;
+ float newAngle = newNode->fillGradient()->v0;
float oldAngle = oldNode != nullptr
- ? oldNode->fillGradient().v0
+ ? oldNode->fillGradient()->v0
: 0.0f;
if (oldNode == nullptr || !qFuzzyCompare(newAngle, oldAngle)) {
newAngle = -qDegreesToRadians(newAngle);
@@ -257,6 +223,7 @@ namespace {
return changed;
}
+
}
QSGCurveFillMaterial::QSGCurveFillMaterial(QSGCurveFillNode *node)
@@ -279,9 +246,6 @@ int QSGCurveFillMaterial::compare(const QSGMaterial *other) const
if (a == b)
return 0;
- if (int d = a->strokeColor().rgba() - b->strokeColor().rgba())
- return d;
-
if (a->gradientType() == QGradient::NoGradient) {
if (int d = a->color().red() - b->color().red())
return d;
@@ -292,8 +256,8 @@ int QSGCurveFillMaterial::compare(const QSGMaterial *other) const
if (int d = a->color().alpha() - b->color().alpha())
return d;
} else {
- const QSGGradientCache::GradientDesc &ga = a->fillGradient();
- const QSGGradientCache::GradientDesc &gb = b->fillGradient();
+ const QSGGradientCache::GradientDesc &ga = *a->fillGradient();
+ const QSGGradientCache::GradientDesc &gb = *b->fillGradient();
if (int d = ga.a.x() - gb.a.x())
return d;
@@ -328,23 +292,18 @@ int QSGCurveFillMaterial::compare(const QSGMaterial *other) const
QSGMaterialType *QSGCurveFillMaterial::type() const
{
- static QSGMaterialType type[8];
+ static QSGMaterialType type[4];
uint index = node()->gradientType();
Q_ASSERT((index & ~3) == 0); // Only two first bits for gradient type
- if (node()->hasStroke())
- index |= 4;
-
return &type[index];
}
QSGMaterialShader *QSGCurveFillMaterial::createShader(QSGRendererInterface::RenderMode renderMode) const
{
return new QSGCurveFillMaterialShader(node()->gradientType(),
- node()->hasStroke(),
renderMode == QSGRendererInterface::RenderMode3D,
viewCount());
}
-
QT_END_NAMESPACE
diff --git a/src/quick/scenegraph/qsgcurvefillnode_p.h b/src/quick/scenegraph/qsgcurvefillnode_p.h
index d96a78cde9..c90c5b8d38 100644
--- a/src/quick/scenegraph/qsgcurvefillnode_p.h
+++ b/src/quick/scenegraph/qsgcurvefillnode_p.h
@@ -43,40 +43,14 @@ public:
return m_color;
}
- void setStrokeColor(QColor col)
- {
- const bool hadStroke = hasStroke();
- m_strokeColor = col;
- if (hadStroke != hasStroke())
- updateMaterial();
- }
-
- QColor strokeColor() const
- {
- return m_strokeColor;
- }
-
- void setStrokeWidth(float width)
- {
- const bool hadStroke = hasStroke();
- m_strokeWidth = width;
- if (hadStroke != hasStroke())
- updateMaterial();
- }
-
- float strokeWidth() const
- {
- return m_strokeWidth;
- }
-
void setFillGradient(const QSGGradientCache::GradientDesc &fillGradient)
{
m_fillGradient = fillGradient;
}
- QSGGradientCache::GradientDesc fillGradient() const
+ const QSGGradientCache::GradientDesc *fillGradient() const
{
- return m_fillGradient;
+ return &m_fillGradient;
}
void setGradientType(QGradient::Type type)
@@ -102,12 +76,6 @@ public:
m_debug = newDebug;
}
-
- bool hasStroke() const
- {
- return m_strokeWidth > 0.0f && m_strokeColor.alpha() > 0;
- }
-
void appendTriangle(const std::array<QVector2D, 3> &v, // triangle vertices
const std::array<QVector2D, 3> &n, // vertex normals
std::function<QVector3D(QVector2D)> uvForPoint
@@ -215,8 +183,6 @@ private:
static const QSGGeometry::AttributeSet &attributes();
QColor m_color = Qt::white;
- QColor m_strokeColor = Qt::transparent;
- float m_strokeWidth = 0.0f;
float m_debug = 0.0f;
QSGGradientCache::GradientDesc m_fillGradient;
QGradient::Type m_gradientType = QGradient::NoGradient;
diff --git a/src/quick/scenegraph/shaders_ng/shapecurve.frag b/src/quick/scenegraph/shaders_ng/shapecurve.frag
index 594bed7c11..bd0d02b73b 100644
--- a/src/quick/scenegraph/shaders_ng/shapecurve.frag
+++ b/src/quick/scenegraph/shaders_ng/shapecurve.frag
@@ -26,14 +26,6 @@ layout(std140, binding = 0) uniform buf {
float debug;
float reserved3;
-#if defined(STROKE)
- vec4 strokeColor;
- float strokeWidth;
- float reserved4;
- float reserved5;
- float reserved6;
-#endif
-
#if defined(LINEARGRADIENT)
vec2 gradientStart;
vec2 gradientEnd;
@@ -142,27 +134,9 @@ void main()
float debugB = isCurve * min(1.0, 1.0 - qt_TexCoord.z * -1.0) + debugG;
vec3 debugColor = vec3(debugR, debugG, debugB);
-#if defined(STROKE)
- float distance = (f / df); // distance from centre of fragment to line
-
- float halfStrokeWidth = ubuf.strokeWidth / 2.0;
-
- // calculate stroke
- float strokeCoverage = 1.0 - clamp(0.5 + abs(distance) - halfStrokeWidth, 0.0, 1.0);
- vec4 stroke = ubuf.strokeColor * strokeCoverage;
-
- float fillCoverage = clamp(0.5 + f / df, 0.0, 1.0);
- vec4 fill = baseColor() * fillCoverage;
-
- vec4 combined = fill * (1.0 - stroke.a) + stroke * stroke.a;
-
- // finally mix in debug
- fragColor = mix(combined, vec4(debugColor, 1.0), ubuf.debug) * ubuf.opacity;
-#else
// Special case: mask out concave curve in "negative space".
int specialCaseMask = 1 - int(qt_TexCoord.w != 0.0) * (int(qt_TexCoord.x < 0.0) + int(qt_TexCoord.x > 1.0));
float fillCoverage = clamp(0.5 + f / df, 0.0, 1.0) * float(specialCaseMask);
fragColor = mix(baseColor() * fillCoverage, vec4(debugColor, 1.0), ubuf.debug) * ubuf.opacity;
-#endif
}
diff --git a/src/quick/scenegraph/shaders_ng/shapecurve.vert b/src/quick/scenegraph/shaders_ng/shapecurve.vert
index 59f4ddb77d..688aa83139 100644
--- a/src/quick/scenegraph/shaders_ng/shapecurve.vert
+++ b/src/quick/scenegraph/shaders_ng/shapecurve.vert
@@ -25,14 +25,6 @@ layout(std140, binding = 0) uniform buf {
float debug;
float reserved3;
-#if defined(STROKE)
- vec4 strokeColor;
- float strokeWidth;
- float reserved4;
- float reserved5;
- float reserved6;
-#endif
-
#if defined(LINEARGRADIENT)
vec2 gradientStart;
vec2 gradientEnd;