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
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)
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;
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...