diff options
Diffstat (limited to 'src/declarative/scenegraph/util/qsgtexture.cpp')
-rw-r--r-- | src/declarative/scenegraph/util/qsgtexture.cpp | 36 |
1 files changed, 33 insertions, 3 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... |