From 42f230fb9bc04d32774f05e9358604720662490a Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Thu, 14 Feb 2013 21:18:59 -0600 Subject: Ensure EtcTexture always provides a valid textureId. Change-Id: I1e7e8095593838f0fc1d78d1cb5a146787f748a7 Reviewed-by: Gunnar Sletta --- examples/quick/textureprovider/etcprovider.cpp | 15 ++++++++++++--- examples/quick/textureprovider/etcprovider.h | 3 ++- 2 files changed, 14 insertions(+), 4 deletions(-) (limited to 'examples/quick/textureprovider') diff --git a/examples/quick/textureprovider/etcprovider.cpp b/examples/quick/textureprovider/etcprovider.cpp index 0bb072ffaf..507965ca9a 100644 --- a/examples/quick/textureprovider/etcprovider.cpp +++ b/examples/quick/textureprovider/etcprovider.cpp @@ -86,7 +86,7 @@ unsigned short getPaddedHeight(ETCHeader *pHeader) } EtcTexture::EtcTexture() - : m_texture_id(0) + : m_texture_id(0), m_uploaded(false) { } @@ -97,14 +97,22 @@ EtcTexture::~EtcTexture() glDeleteTextures(1, &m_texture_id); } +int EtcTexture::textureId() const +{ + if (m_texture_id == 0) + glGenTextures(1, &const_cast(this)->m_texture_id); + return m_texture_id; +} + void EtcTexture::bind() { - if (m_texture_id) { + if (m_uploaded && m_texture_id) { glBindTexture(GL_TEXTURE_2D, m_texture_id); return; } - glGenTextures(1, &m_texture_id); + if (m_texture_id == 0) + glGenTextures(1, &m_texture_id); glBindTexture(GL_TEXTURE_2D, m_texture_id); #ifdef ETC_DEBUG @@ -129,6 +137,7 @@ void EtcTexture::bind() return; } + m_uploaded = true; updateBindOptions(true); } diff --git a/examples/quick/textureprovider/etcprovider.h b/examples/quick/textureprovider/etcprovider.h index 08418f8b4b..24570e90e9 100644 --- a/examples/quick/textureprovider/etcprovider.h +++ b/examples/quick/textureprovider/etcprovider.h @@ -67,7 +67,7 @@ public: void bind(); QSize textureSize() const { return m_size; } - int textureId() const { return m_texture_id; } + int textureId() const; bool hasAlphaChannel() const { return false; } bool hasMipmaps() const { return false; } @@ -76,6 +76,7 @@ public: QSize m_size; QSize m_paddedSize; GLuint m_texture_id; + bool m_uploaded; }; #endif // ETCPROVIDER_H -- cgit v1.2.3