QskArcRenderer API in line with QskBoxRenderer

This commit is contained in:
Uwe Rathmann 2024-09-19 10:49:36 +02:00
parent 31470a7a50
commit 98967a5619
3 changed files with 86 additions and 59 deletions

View File

@ -14,7 +14,11 @@
class QskArcRenderNodePrivate final : public QskFillNodePrivate
{
public:
inline void resetValues() { hash = 0; }
inline void resetNode( QskArcRenderNode* node )
{
hash = 0;
node->resetGeometry();
}
QskHashValue hash = 0;
};
@ -55,9 +59,7 @@ void QskArcRenderNode::updateNode(
if ( rect.isEmpty() || metrics.isNull() || !( hasFill || hasBorder ) )
{
d->resetValues();
QskSGNode::resetGeometry( this );
d->resetNode( this );
return;
}
@ -77,45 +79,18 @@ void QskArcRenderNode::updateNode(
d->hash = hash;
auto coloring = QskFillNode::Polychrome;
#if 0
if ( !( hasFill && hasBorder ) )
{
if ( hasBorder || ( hasFill && gradient.isMonochrome() ) )
coloring = QskFillNode::Monochrome;
}
#if 1
const bool coloredGeometry = hasHint( PreferColoredGeometry )
&& QskArcRenderer::isGradientSupported( rect, metrics, gradient );
Q_ASSERT( coloredGeometry ); // TODO ...
#endif
auto& geometry = *this->geometry();
if ( coloring == QskFillNode::Polychrome )
{
setColoring( coloring );
setColoring( QskFillNode::Polychrome );
QskArcRenderer::renderArc( rect, metrics, radial,
borderWidth, gradient, borderColor, geometry );
}
else
{
if ( hasFill )
{
setColoring( gradient.rgbStart() );
QskArcRenderer::renderArc( rect, metrics, radial,
borderWidth, gradient, borderColor, geometry );
}
else
{
setColoring( borderColor );
QskArcRenderer::renderArc( rect, metrics, radial,
borderWidth, gradient, borderColor, geometry );
}
}
QskArcRenderer::setColoredBorderAndFillLines( rect, metrics, radial,
borderWidth, borderColor, gradient, geometry );
markDirty( QSGNode::DirtyGeometry );
markDirty( QSGNode::DirtyMaterial );
geometry.markVertexDataDirty();
}

View File

@ -11,7 +11,6 @@
#include "QskRgbValue.h"
#include <qsggeometry.h>
#include <qdebug.h>
static inline QskVertex::Line* qskAllocateLines(
QSGGeometry& geometry, int lineCount )
@ -466,8 +465,8 @@ bool QskArcRenderer::isGradientSupported( const QRectF& rect,
if ( qskFuzzyCompare( direction.aspectRatio(), aspectRatio ) )
{
/*
we should be able to create a list of stops from
this gradient that works for the renderer. TODO ...
we should be able to create a list of stops from
this gradient that works for the renderer. TODO ...
*/
}
}
@ -483,17 +482,55 @@ bool QskArcRenderer::isGradientSupported( const QRectF& rect,
return false;
}
void QskArcRenderer::renderArc( const QRectF& rect, const QskArcMetrics& metrics,
bool radial, const QskGradient& gradient, QSGGeometry& geometry )
{
renderArc( rect, metrics, radial, 0, gradient, QColor(), geometry );
}
void QskArcRenderer::renderArc( const QRectF& rect, const QskArcMetrics& metrics,
bool radial, qreal borderWidth, const QskGradient& gradient,
void QskArcRenderer::setColoredBorderLines( const QRectF& rect,
const QskArcMetrics& metrics, bool radial, qreal borderWidth,
const QColor& borderColor, QSGGeometry& geometry )
{
geometry.setDrawingMode( QSGGeometry::DrawTriangleStrip );
geometry.markVertexDataDirty();
if ( borderWidth <= 0.0 || !( borderColor.isValid() && borderColor.alpha() > 0 ) )
{
qskAllocateColoredLines( geometry, 0 );
return;
}
const Renderer renderer( rect, metrics, radial, QskGradient(), borderColor );
if ( const auto lines = qskAllocateColoredLines( geometry, renderer.borderCount() ) )
{
renderer.renderArc( metrics.thickness(), borderWidth,
static_cast< QskVertex::ColoredLine* >( nullptr ), lines );
}
}
void QskArcRenderer::setColoredFillLines( const QRectF& rect, const QskArcMetrics& metrics,
bool radial, const QskGradient& gradient, QSGGeometry& geometry )
{
geometry.setDrawingMode( QSGGeometry::DrawTriangleStrip );
geometry.markVertexDataDirty();
if ( !gradient.isVisible() )
{
qskAllocateColoredLines( geometry, 0 );
return;
}
const Renderer renderer( rect, metrics, radial, gradient, QColor( 0, 0, 0, 0 ) );
if ( const auto lines = qskAllocateColoredLines( geometry, renderer.fillCount() ) )
{
renderer.renderArc( metrics.thickness(), 0.0, lines,
static_cast< QskVertex::ColoredLine* >( nullptr ) );
}
}
void QskArcRenderer::setColoredBorderAndFillLines( const QRectF& rect,
const QskArcMetrics& metrics, bool radial, qreal borderWidth,
const QColor& borderColor, const QskGradient& gradient, QSGGeometry& geometry )
{
geometry.setDrawingMode( QSGGeometry::DrawTriangleStrip );
geometry.markVertexDataDirty();
const Renderer renderer( rect, metrics, radial, gradient,
borderColor.isValid() ? borderColor : QColor( 0, 0, 0, 0 ) );
@ -523,13 +560,20 @@ void QskArcRenderer::renderArc( const QRectF& rect, const QskArcMetrics& metrics
}
}
void QskArcRenderer::renderBorderGeometry( const QRectF& rect,
void QskArcRenderer::setBorderLines( const QRectF& rect,
const QskArcMetrics& metrics, bool radial, qreal borderWidth, QSGGeometry& geometry )
{
geometry.setDrawingMode( QSGGeometry::DrawTriangleStrip );
geometry.markVertexDataDirty();
if ( borderWidth <= 0.0 )
{
qskAllocateLines( geometry, 0 );
return;
}
const Renderer renderer( rect, metrics, radial, QskGradient(), 0 );
const auto lines = qskAllocateLines( geometry, renderer.borderCount() );
if ( lines )
{
@ -538,10 +582,11 @@ void QskArcRenderer::renderBorderGeometry( const QRectF& rect,
}
}
void QskArcRenderer::renderFillGeometry( const QRectF& rect,
void QskArcRenderer::setFillLines( const QRectF& rect,
const QskArcMetrics& metrics, bool radial, qreal borderWidth, QSGGeometry& geometry )
{
geometry.setDrawingMode( QSGGeometry::DrawTriangleStrip );
geometry.markVertexDataDirty();
const Renderer renderer( rect, metrics, radial, QskRgb::Black, 0 );

View File

@ -25,24 +25,31 @@ namespace QskArcRenderer
- using shaders setting the colors
*/
QSK_EXPORT void renderBorderGeometry( const QRectF&,
QSK_EXPORT void setBorderLines( const QRectF&,
const QskArcMetrics&, bool radial, qreal borderWidth, QSGGeometry& );
QSK_EXPORT void renderFillGeometry( const QRectF&,
QSK_EXPORT void setFillLines( const QRectF&,
const QskArcMetrics&, bool radial, qreal borderWidth, QSGGeometry& );
/*
Filling the geometry with color information:
see QSGGeometry::defaultAttributes_ColoredPoint2D()
Usually used in combination with QSGVertexColorMaterial
*/
QSK_EXPORT bool isGradientSupported(
const QRectF&, const QskArcMetrics&, const QskGradient& );
QSK_EXPORT void renderArc( const QRectF&, const QskArcMetrics&, bool radial,
qreal borderWidth, const QskGradient&, const QColor& borderColor, QSGGeometry& );
QSK_EXPORT void setColoredBorderLines( const QRectF&,
const QskArcMetrics&, bool radial, qreal borderWidth,
const QColor& borderColor, QSGGeometry& );
QSK_EXPORT void renderArc( const QRectF&, const QskArcMetrics&, bool radial,
const QskGradient&, QSGGeometry& );
QSK_EXPORT void setColoredFillLines( const QRectF&,
const QskArcMetrics&, bool radial, const QskGradient&, QSGGeometry& );
QSK_EXPORT void setColoredBorderAndFillLines( const QRectF&,
const QskArcMetrics&, bool radial, qreal borderWidth,
const QColor& borderColor, const QskGradient&, QSGGeometry& );
}
#endif