diff options
author | Gunnar Sletta <gunnar.sletta@nokia.com> | 2011-10-04 10:41:13 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-10-04 15:10:57 +0200 |
commit | 1b6c8eac6743c7e05031070c61a40141047cc981 (patch) | |
tree | 7aaf4eda5f00d0123442b6c0857065eb3269a972 /src | |
parent | 2b4696230091fd70cd51c07a83c15bd2dbbd21ab (diff) |
Have textureId() return the correct value and document this behavior
Change-Id: Ia75b5fc3b6c9f15bb15e8850295c33ba32a485f1
Reviewed-on: http://codereview.qt-project.org/5970
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Kim M. Kalland <kim.kalland@nokia.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/declarative/scenegraph/util/qsgtexture.cpp | 36 | ||||
-rw-r--r-- | src/declarative/scenegraph/util/qsgtexture_p.h | 3 |
2 files changed, 34 insertions, 5 deletions
diff --git a/src/declarative/scenegraph/util/qsgtexture.cpp b/src/declarative/scenegraph/util/qsgtexture.cpp index bec325f3bb..4e208c02b7 100644 --- a/src/declarative/scenegraph/util/qsgtexture.cpp +++ b/src/declarative/scenegraph/util/qsgtexture.cpp @@ -210,6 +210,19 @@ bool QSGTexture::isAtlasTexture() const return false; } +/*! + \fn int QSGTexture::textureId() const + + Returns the OpenGL texture id for this texture. + + The default value is 0, indicating that it is an invalid texture id. + + The function should at all times return the correct texture id. + + \warning This function can only be called from the rendering thread. + */ + + /*! Returns the rectangle inside textureSize() that this texture @@ -395,6 +408,22 @@ void QSGPlainTexture::setImage(const QImage &image) m_dirty_bind_options = true; } +int QSGPlainTexture::textureId() const +{ + if (m_dirty_texture) { + if (m_image.isNull()) { + // The actual texture and id will be updated/deleted in a later bind() + // or ~QSGPlainTexture so just keep it minimal here. + return 0; + } else { + // Generate a texture id for use later and return it. + glGenTextures(1, &const_cast<QSGPlainTexture *>(this)->m_texture_id); + return m_texture_id; + } + } + return m_texture_id; +} + void QSGPlainTexture::setTextureId(int id) { if (m_texture_id && m_owns_texture) @@ -430,10 +459,10 @@ void QSGPlainTexture::bind() m_dirty_texture = false; - if (m_texture_id && m_owns_texture) - glDeleteTextures(1, &m_texture_id); if (m_image.isNull()) { + if (m_texture_id && m_owns_texture) + glDeleteTextures(1, &m_texture_id); m_texture_id = 0; m_texture_size = QSize(); m_has_mipmaps = false; @@ -441,7 +470,8 @@ void QSGPlainTexture::bind() return; } - glGenTextures(1, &m_texture_id); + if (m_texture_id == 0) + glGenTextures(1, &m_texture_id); glBindTexture(GL_TEXTURE_2D, m_texture_id); // ### TODO: check for out-of-memory situations... diff --git a/src/declarative/scenegraph/util/qsgtexture_p.h b/src/declarative/scenegraph/util/qsgtexture_p.h index 22812f8640..460c0e86b7 100644 --- a/src/declarative/scenegraph/util/qsgtexture_p.h +++ b/src/declarative/scenegraph/util/qsgtexture_p.h @@ -77,8 +77,7 @@ public: bool ownsTexture() const { return m_owns_texture; } void setTextureId(int id); - int textureId() const { return m_texture_id; } - + int textureId() const; void setTextureSize(const QSize &size) { m_texture_size = size; } QSize textureSize() const { return m_texture_size; } |