aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGunnar Sletta <gunnar.sletta@nokia.com>2011-10-05 09:38:32 +0200
committerQt by Nokia <qt-info@nokia.com>2011-10-05 12:36:15 +0200
commitcd8c7b1c3c4f743bda9b66ef7840606a20e7b9cf (patch)
tree6119d091782428e8e03570110d2b7b49e4405cd8
parent40c9607befb1cce6ef771dc9bd77ac91a7e1f3b4 (diff)
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 <qt_sanity_bot@ovi.com> Reviewed-by: Kim M. Kalland <kim.kalland@nokia.com>
-rw-r--r--src/declarative/items/qsgimage.cpp4
-rw-r--r--src/declarative/scenegraph/util/qsgtexture.cpp26
-rw-r--r--src/declarative/scenegraph/util/qsgtexture.h3
3 files changed, 30 insertions, 3 deletions
diff --git a/src/declarative/items/qsgimage.cpp b/src/declarative/items/qsgimage.cpp
index 92b454b695..a23d9ede1b 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<QSGImageTextureProvider *>(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 4e208c02b7..7cd398d9e0 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 5506042c6a..135c5e403f 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);