Qt5 updates fixed

This commit is contained in:
Uwe Rathmann 2023-12-20 11:19:48 +01:00
parent f9674760c0
commit f3ee4749b8
4 changed files with 72 additions and 15 deletions

View File

@ -140,6 +140,8 @@ namespace
if ( rootNode == nullptr ) if ( rootNode == nullptr )
return nullptr; return nullptr;
const auto rect = overlay->subControlRect( Overlay::Panel );
auto textureNode = static_cast< FilterNode* >( node ); auto textureNode = static_cast< FilterNode* >( node );
if ( textureNode == nullptr ) if ( textureNode == nullptr )
@ -149,22 +151,22 @@ namespace
overlay, &QQuickItem::update ); overlay, &QQuickItem::update );
textureNode = new FilterNode( texture ); textureNode = new FilterNode( texture );
texture->setTextureNode( textureNode );
} }
{ textureNode->setRect( rect );
auto texture = qobject_cast< QskSceneTexture* >( textureNode->texture() );
Q_ASSERT( texture );
auto texture = qobject_cast< QskSceneTexture* >( textureNode->texture() );
Q_ASSERT( texture );
if ( texture->isDirty() )
{
texture->setFiltering( texture->setFiltering(
overlay->smooth() ? QSGTexture::Linear : QSGTexture::Nearest ); overlay->smooth() ? QSGTexture::Linear : QSGTexture::Nearest );
auto finalNode = const_cast< QSGTransformNode* >( qskItemNode( overlay ) ); auto finalNode = const_cast< QSGTransformNode* >( qskItemNode( overlay ) );
texture->render( rootNode, finalNode, overlay->geometry() ); texture->render( rootNode, finalNode, overlay->geometry() );
} textureNode->markDirty( QSGNode::DirtyMaterial );
{
const auto rect = overlay->subControlRect( Overlay::Panel );
textureNode->setRect( rect );
} }
return textureNode; return textureNode;

View File

@ -39,7 +39,7 @@ namespace
} }
void updateState( const QSGMaterialShader::RenderState& state, void updateState( const QSGMaterialShader::RenderState& state,
QSGMaterial* newMaterial, QSGMaterial* ) override QSGMaterial* newMaterial, QSGMaterial* oldMaterial ) override
{ {
auto p = program(); auto p = program();
@ -50,8 +50,22 @@ namespace
p->setUniformValue( m_opacityId, state.opacity() ); p->setUniformValue( m_opacityId, state.opacity() );
auto material = static_cast< TextureFilterMaterial* >( newMaterial ); auto material = static_cast< TextureFilterMaterial* >( newMaterial );
if ( material->texture() )
material->texture()->bind(); if ( auto texture = material->texture() )
{
auto textureId = -1;
if ( auto oldMat = static_cast< TextureFilterMaterial* >( oldMaterial ) )
{
if ( oldMat->texture() )
textureId = oldMat->texture()->textureId();
}
if ( texture->textureId() != textureId )
texture->bind();
else
texture->updateBindOptions();
}
} }
private: private:

View File

@ -49,6 +49,8 @@ namespace
inline QRhiTexture* texture() const { return m_rhiTexture; } inline QRhiTexture* texture() const { return m_rhiTexture; }
#endif #endif
inline bool isDirty() const { return m_dirty; }
void setFinalNode( QSGTransformNode* ); void setFinalNode( QSGTransformNode* );
void setProjection( const QRectF& ); void setProjection( const QRectF& );
@ -70,6 +72,8 @@ namespace
#else #else
QRhiTexture* m_rhiTexture = nullptr; QRhiTexture* m_rhiTexture = nullptr;
#endif #endif
bool m_dirty = true;
}; };
Renderer::Renderer( QskSceneTexture* texture, QSGDefaultRenderContext* context ) Renderer::Renderer( QskSceneTexture* texture, QSGDefaultRenderContext* context )
@ -148,22 +152,32 @@ namespace
void Renderer::render() void Renderer::render()
{ {
qskTryBlockTrailingNodes( m_finalNode, rootNode(), true, false ); qskTryBlockTrailingNodes( m_finalNode, rootNode(), true, false );
#if 0 #if 0
static int counter = 0;
qDebug() << ++counter;
QSGNodeDumper::dump( rootNode() ); QSGNodeDumper::dump( rootNode() );
#endif #endif
Inherited::render(); Inherited::render();
qskTryBlockTrailingNodes( m_finalNode, rootNode(), false, false ); qskTryBlockTrailingNodes( m_finalNode, rootNode(), false, false );
m_dirty = false;
} }
void Renderer::nodeChanged( QSGNode* node, QSGNode::DirtyState state ) void Renderer::nodeChanged( QSGNode* node, QSGNode::DirtyState state )
{ {
// do not forward nodes that are blocked while rendering Inherited::nodeChanged( node, state );
const bool isTrailingNode = false; // TODO ... /*
We want to limit updates to nodes, that are actually rendered. TODO ...
if ( !isTrailingNode ) In any case we need to block update requests, when the textureNode reports
that it has been updated by us to the renderer of the window.
*/
if ( ( state != QSGNode::DirtyMaterial )
|| ( node != m_texture->textureNode() ) )
{ {
Inherited::nodeChanged( node, state ); m_dirty = true;
Q_EMIT m_texture->updateRequested(); Q_EMIT m_texture->updateRequested();
} }
} }
@ -242,6 +256,8 @@ class QskSceneTexturePrivate final : public QSGTexturePrivate
Renderer* renderer = nullptr; Renderer* renderer = nullptr;
QSGDefaultRenderContext* context = nullptr; QSGDefaultRenderContext* context = nullptr;
const QSGGeometryNode* textureNode = nullptr;
}; };
QskSceneTexture::QskSceneTexture( const QQuickWindow* window ) QskSceneTexture::QskSceneTexture( const QQuickWindow* window )
@ -255,6 +271,16 @@ QskSceneTexture::~QskSceneTexture()
delete d_func()->renderer; delete d_func()->renderer;
} }
void QskSceneTexture::setTextureNode( const QSGGeometryNode* node )
{
d_func()->textureNode = node;
}
const QSGGeometryNode* QskSceneTexture::textureNode() const
{
return d_func()->textureNode;
}
QSize QskSceneTexture::textureSize() const QSize QskSceneTexture::textureSize() const
{ {
Q_D( const QskSceneTexture ); Q_D( const QskSceneTexture );
@ -294,6 +320,12 @@ void QskSceneTexture::render( const QSGRootNode* rootNode,
d->renderer->renderScene(); d->renderer->renderScene();
} }
bool QskSceneTexture::isDirty() const
{
Q_D( const QskSceneTexture );
return d->renderer ? d->renderer->isDirty() : true;
}
QRectF QskSceneTexture::normalizedTextureSubRect() const QRectF QskSceneTexture::normalizedTextureSubRect() const
{ {
return QRectF( 0, 1, 1, -1 ); return QRectF( 0, 1, 1, -1 );

View File

@ -13,6 +13,7 @@ class QskSceneTexturePrivate;
class QSGRootNode; class QSGRootNode;
class QSGTransformNode; class QSGTransformNode;
class QSGGeometryNode;
class QQuickWindow; class QQuickWindow;
class QSK_EXPORT QskSceneTexture : public QSGTexture class QSK_EXPORT QskSceneTexture : public QSGTexture
@ -25,6 +26,12 @@ class QSK_EXPORT QskSceneTexture : public QSGTexture
QskSceneTexture( const QQuickWindow* ); QskSceneTexture( const QQuickWindow* );
~QskSceneTexture(); ~QskSceneTexture();
#if 1
// to avoid recursive update, need to find a better solution
void setTextureNode( const QSGGeometryNode* );
const QSGGeometryNode* textureNode() const;
#endif
void render( const QSGRootNode*, const QSGTransformNode*, const QRectF& ); void render( const QSGRootNode*, const QSGTransformNode*, const QRectF& );
QSize textureSize() const override; QSize textureSize() const override;
@ -43,6 +50,8 @@ class QSK_EXPORT QskSceneTexture : public QSGTexture
bool hasAlphaChannel() const override; bool hasAlphaChannel() const override;
bool hasMipmaps() const override; bool hasMipmaps() const override;
bool isDirty() const;
Q_SIGNALS: Q_SIGNALS:
void updateRequested(); void updateRequested();