From cd8c7b1c3c4f743bda9b66ef7840606a20e7b9cf Mon Sep 17 00:00:00 2001 From: Gunnar Sletta Date: Wed, 5 Oct 2011 09:38:32 +0200 Subject: [PATCH] Make sure the Image texture provider does not return an atlassed texture This has the implication that textures from texture providers are always the complete texture with coordinates from 0-1, which is means we get a copy for atlas textures which may end up affecting performance. Alternatives are: - ShaderEffect does this, which means texture providers can provide atlas textures. - We expose the subrect to ShaderEffect, which means an API change in all shader effect classes, and let the vertex shader solve this. Worst API, fastest and most memory efficient. Change-Id: Id58eb866f315012637345a6f731626abf4a7a86c Reviewed-on: http://codereview.qt-project.org/6029 Reviewed-by: Qt Sanity Bot Reviewed-by: Kim M. Kalland --- src/declarative/items/qsgimage.cpp | 4 +++ src/declarative/scenegraph/util/qsgtexture.cpp | 26 ++++++++++++++++++++++- src/declarative/scenegraph/util/qsgtexture.h | 3 +- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/declarative/items/qsgimage.cpp b/src/declarative/items/qsgimage.cpp index 92b454b..a23d9ed 100644 --- a/src/declarative/items/qsgimage.cpp +++ b/src/declarative/items/qsgimage.cpp @@ -63,6 +63,10 @@ public: } QSGTexture *texture() const { + + if (m_texture->isAtlasTexture()) + const_cast(this)->m_texture = m_texture->removedFromAtlas(); + if (m_texture) { m_texture->setFiltering(m_smooth ? QSGTexture::Linear : QSGTexture::Nearest); m_texture->setMipmapFiltering(QSGTexture::Nearest); diff --git a/src/declarative/scenegraph/util/qsgtexture.cpp b/src/declarative/scenegraph/util/qsgtexture.cpp index 4e208c0..7cd398d 100644 --- a/src/declarative/scenegraph/util/qsgtexture.cpp +++ b/src/declarative/scenegraph/util/qsgtexture.cpp @@ -193,11 +193,33 @@ QSGTexture::~QSGTexture() Binding a texture may also include uploading the texture data from a previously set QImage. + + \warning This function can only be called from the rendering thread. + */ + +/*! + This function returns a copy of the current texture which is removed + from its atlas. + + The current texture remains unchanged, so texture coordinates do not + need to be updated. + + Removing a texture from an atlas is primarily useful when passing + it to a shader that operates on the texture coordinates 0-1 instead + of the texture subrect inside the atlas. + + If the texture is not part of a texture atlas, this function returns 0. + + Implementations of this function are recommended to return the same instance + for multiple calls to limit memory usage. + + \warning This function can only be called from the rendering thread. */ -void QSGTexture::removeFromAtlas() +QSGTexture *QSGTexture::removedFromAtlas() const { - // default textures are not in atlasses, so do nothing... + Q_ASSERT_X(!isAtlasTexture(), "QSGTexture::removedFromAtlas()", "Called on a non-atlas texture"); + return 0; } /*! diff --git a/src/declarative/scenegraph/util/qsgtexture.h b/src/declarative/scenegraph/util/qsgtexture.h index 5506042..135c5e4 100644 --- a/src/declarative/scenegraph/util/qsgtexture.h +++ b/src/declarative/scenegraph/util/qsgtexture.h @@ -80,7 +80,8 @@ public: virtual QRectF textureSubRect() const; virtual bool isAtlasTexture() const; - virtual void removeFromAtlas(); + + virtual QSGTexture *removedFromAtlas() const; virtual void bind() = 0; void updateBindOptions(bool force = false); -- 1.7.2.5