code improved
This commit is contained in:
parent
5757d49ba9
commit
07cdcc56df
|
@ -51,10 +51,12 @@ namespace
|
||||||
setShaderSourceFile( QOpenGLShader::Vertex,
|
setShaderSourceFile( QOpenGLShader::Vertex,
|
||||||
QStringLiteral( ":/qt-project.org/scenegraph/shaders/opaquetexture.vert" ) );
|
QStringLiteral( ":/qt-project.org/scenegraph/shaders/opaquetexture.vert" ) );
|
||||||
|
|
||||||
|
if ( m_isOpaque )
|
||||||
|
{
|
||||||
setShaderSourceFile( QOpenGLShader::Fragment,
|
setShaderSourceFile( QOpenGLShader::Fragment,
|
||||||
QStringLiteral( ":/qt-project.org/scenegraph/shaders/opaquetexture.frag" ) );
|
QStringLiteral( ":/qt-project.org/scenegraph/shaders/opaquetexture.frag" ) );
|
||||||
|
}
|
||||||
if ( !m_isOpaque )
|
else
|
||||||
{
|
{
|
||||||
setShaderSourceFile( QOpenGLShader::Fragment,
|
setShaderSourceFile( QOpenGLShader::Fragment,
|
||||||
QStringLiteral( ":/qt-project.org/scenegraph/shaders/texture.frag" ) );
|
QStringLiteral( ":/qt-project.org/scenegraph/shaders/texture.frag" ) );
|
||||||
|
@ -152,6 +154,30 @@ class QskTextureNodePrivate final : public QSGGeometryNodePrivate
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void updateTextureGeometry()
|
||||||
|
{
|
||||||
|
QRectF r( 0, 0, 1, 1 );
|
||||||
|
|
||||||
|
if ( this->mirrorOrientations & Qt::Horizontal )
|
||||||
|
{
|
||||||
|
r.setLeft( 1 );
|
||||||
|
r.setRight( 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( mirrorOrientations & Qt::Vertical )
|
||||||
|
{
|
||||||
|
r.setTop( 1 );
|
||||||
|
r.setBottom( 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
const qreal ratio = QskTextureRenderer::devicePixelRatio();
|
||||||
|
|
||||||
|
const QRectF scaledRect( rect.x(), rect.y(),
|
||||||
|
rect.width() / ratio, rect.height() / ratio );
|
||||||
|
|
||||||
|
QSGGeometry::updateTexturedRectGeometry( &geometry, scaledRect, r );
|
||||||
|
}
|
||||||
|
|
||||||
QSGGeometry geometry;
|
QSGGeometry geometry;
|
||||||
|
|
||||||
Material opaqueMaterial;
|
Material opaqueMaterial;
|
||||||
|
@ -196,13 +222,13 @@ void QskTextureNode::setRect( const QRectF& r )
|
||||||
{
|
{
|
||||||
Q_D( QskTextureNode );
|
Q_D( QskTextureNode );
|
||||||
|
|
||||||
if ( d->rect == r )
|
if ( d->rect != r )
|
||||||
return;
|
{
|
||||||
|
|
||||||
d->rect = r;
|
d->rect = r;
|
||||||
|
d->updateTextureGeometry();
|
||||||
|
|
||||||
updateTexture();
|
|
||||||
markDirty( DirtyGeometry );
|
markDirty( DirtyGeometry );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QRectF QskTextureNode::rect() const
|
QRectF QskTextureNode::rect() const
|
||||||
|
@ -211,6 +237,25 @@ QRectF QskTextureNode::rect() const
|
||||||
return d->rect;
|
return d->rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QskTextureNode::setMirrored( Qt::Orientations orientations )
|
||||||
|
{
|
||||||
|
Q_D( QskTextureNode );
|
||||||
|
|
||||||
|
if ( d->mirrorOrientations != orientations )
|
||||||
|
{
|
||||||
|
d->mirrorOrientations = orientations;
|
||||||
|
d->updateTextureGeometry();
|
||||||
|
|
||||||
|
markDirty( DirtyMaterial );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Qt::Orientations QskTextureNode::mirrored() const
|
||||||
|
{
|
||||||
|
Q_D( const QskTextureNode );
|
||||||
|
return d->mirrorOrientations;
|
||||||
|
}
|
||||||
|
|
||||||
void QskTextureNode::setTextureId( uint textureId )
|
void QskTextureNode::setTextureId( uint textureId )
|
||||||
{
|
{
|
||||||
Q_D( QskTextureNode );
|
Q_D( QskTextureNode );
|
||||||
|
@ -228,15 +273,8 @@ void QskTextureNode::setTextureId( uint textureId )
|
||||||
|
|
||||||
d->material.setTextureId( textureId );
|
d->material.setTextureId( textureId );
|
||||||
d->opaqueMaterial.setTextureId( textureId );
|
d->opaqueMaterial.setTextureId( textureId );
|
||||||
updateTexture();
|
|
||||||
|
|
||||||
DirtyState dirty = DirtyMaterial;
|
markDirty( DirtyMaterial );
|
||||||
#if 0
|
|
||||||
// if old/new is in the atlas
|
|
||||||
dirty |= DirtyGeometry;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
markDirty( dirty );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint QskTextureNode::textureId() const
|
uint QskTextureNode::textureId() const
|
||||||
|
@ -244,48 +282,3 @@ uint QskTextureNode::textureId() const
|
||||||
Q_D( const QskTextureNode );
|
Q_D( const QskTextureNode );
|
||||||
return d->material.textureId();
|
return d->material.textureId();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QskTextureNode::setMirrored( Qt::Orientations orientations )
|
|
||||||
{
|
|
||||||
Q_D( QskTextureNode );
|
|
||||||
|
|
||||||
if ( d->mirrorOrientations == orientations )
|
|
||||||
return;
|
|
||||||
|
|
||||||
d->mirrorOrientations = orientations;
|
|
||||||
updateTexture();
|
|
||||||
|
|
||||||
markDirty( DirtyMaterial );
|
|
||||||
}
|
|
||||||
|
|
||||||
Qt::Orientations QskTextureNode::mirrored() const
|
|
||||||
{
|
|
||||||
Q_D( const QskTextureNode );
|
|
||||||
return d->mirrorOrientations;
|
|
||||||
}
|
|
||||||
|
|
||||||
void QskTextureNode::updateTexture()
|
|
||||||
{
|
|
||||||
Q_D( QskTextureNode );
|
|
||||||
|
|
||||||
QRectF r( 0, 0, 1, 1 );
|
|
||||||
|
|
||||||
if ( d->mirrorOrientations & Qt::Horizontal )
|
|
||||||
{
|
|
||||||
r.setLeft( 1 );
|
|
||||||
r.setRight( 0 );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( d->mirrorOrientations & Qt::Vertical )
|
|
||||||
{
|
|
||||||
r.setTop( 1 );
|
|
||||||
r.setBottom( 0 );
|
|
||||||
}
|
|
||||||
|
|
||||||
const qreal ratio = QskTextureRenderer::devicePixelRatio();
|
|
||||||
|
|
||||||
const QRectF rect( d->rect.x(), d->rect.y(),
|
|
||||||
d->rect.width() / ratio, d->rect.height() / ratio );
|
|
||||||
|
|
||||||
QSGGeometry::updateTexturedRectGeometry( &d->geometry, rect, r );
|
|
||||||
}
|
|
||||||
|
|
|
@ -29,8 +29,6 @@ class QSK_EXPORT QskTextureNode : public QSGGeometryNode
|
||||||
Qt::Orientations mirrored() const;
|
Qt::Orientations mirrored() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void updateTexture();
|
|
||||||
|
|
||||||
Q_DECLARE_PRIVATE( QskTextureNode )
|
Q_DECLARE_PRIVATE( QskTextureNode )
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue