diff options
author | Michael Brasser <michael.brasser@live.com> | 2013-02-14 21:18:59 -0600 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-02-15 14:38:00 +0100 |
commit | 42f230fb9bc04d32774f05e9358604720662490a (patch) | |
tree | d23495a9f4f1a7557ba40938cddbb9fadf9db506 /examples | |
parent | 5e6b2bf68b2338ad9424b48193b860a70addd022 (diff) |
Ensure EtcTexture always provides a valid textureId.
Change-Id: I1e7e8095593838f0fc1d78d1cb5a146787f748a7
Reviewed-by: Gunnar Sletta <gunnar.sletta@digia.com>
Diffstat (limited to 'examples')
-rw-r--r-- | examples/quick/textureprovider/etcprovider.cpp | 15 | ||||
-rw-r--r-- | examples/quick/textureprovider/etcprovider.h | 3 |
2 files changed, 14 insertions, 4 deletions
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<EtcTexture *>(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 |