diff options
author | Andrei Karas <akaras@inbox.ru> | 2014-06-04 23:57:06 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2014-06-04 23:57:06 +0300 |
commit | c0c3782473479460273f1d6e8e0e3e7564ecff89 (patch) | |
tree | a955e6376aa7c41d7bed3b60fd5b532fec5a7d20 /src/resources/openglimagehelper.cpp | |
parent | 0c72851a2b47acba27944106eea4619b658d40ca (diff) | |
download | manaverse-c0c3782473479460273f1d6e8e0e3e7564ecff89.tar.gz manaverse-c0c3782473479460273f1d6e8e0e3e7564ecff89.tar.bz2 manaverse-c0c3782473479460273f1d6e8e0e3e7564ecff89.tar.xz manaverse-c0c3782473479460273f1d6e8e0e3e7564ecff89.zip |
Create empty OpenGL textures in batches.
Diffstat (limited to 'src/resources/openglimagehelper.cpp')
-rw-r--r-- | src/resources/openglimagehelper.cpp | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/src/resources/openglimagehelper.cpp b/src/resources/openglimagehelper.cpp index 292b2fb22..d06500a18 100644 --- a/src/resources/openglimagehelper.cpp +++ b/src/resources/openglimagehelper.cpp @@ -48,7 +48,13 @@ int OpenGLImageHelper::mTextureSize = 0; bool OpenGLImageHelper::mBlur = true; bool OpenGLImageHelper::mUseTextureSampler = false; -Image *OpenGLImageHelper::load(SDL_RWops *const rw, Dye const &dye) const +OpenGLImageHelper::~OpenGLImageHelper() +{ + glDeleteTextures(texturesSize - mFreeTextureIndex, + &mTextures[mFreeTextureIndex]); +} + +Image *OpenGLImageHelper::load(SDL_RWops *const rw, Dye const &dye) { SDL_Surface *const tmpImage = loadPng(rw); if (!tmpImage) @@ -92,14 +98,14 @@ Image *OpenGLImageHelper::load(SDL_RWops *const rw, Dye const &dye) const return image; } -Image *OpenGLImageHelper::load(SDL_Surface *const tmpImage) const +Image *OpenGLImageHelper::load(SDL_Surface *const tmpImage) { return glLoad(tmpImage); } Image *OpenGLImageHelper::createTextSurface(SDL_Surface *const tmpImage, const int width, const int height, - const float alpha) const + const float alpha) { if (!tmpImage) return nullptr; @@ -127,7 +133,7 @@ int OpenGLImageHelper::powerOfTwo(const int input) } Image *OpenGLImageHelper::glLoad(SDL_Surface *tmpImage, - int width, int height) const + int width, int height) { if (!tmpImage) return nullptr; @@ -191,8 +197,7 @@ Image *OpenGLImageHelper::glLoad(SDL_Surface *tmpImage, SDL_BlitSurface(oldImage, nullptr, tmpImage, nullptr); } - GLuint texture; - glGenTextures(1, &texture); + const GLuint texture = getNewTexture(); switch (mUseOpenGL) { #ifndef ANDROID @@ -321,4 +326,21 @@ SDL_Surface *OpenGLImageHelper::create32BitSurface(int width, width, height, 32, rmask, gmask, bmask, amask); } +GLuint OpenGLImageHelper::getNewTexture() +{ + GLuint texture = mTextures[mFreeTextureIndex]; + mFreeTextureIndex ++; + if (mFreeTextureIndex == texturesSize) + { + mFreeTextureIndex = 0; + postInit(); + } + return texture; +} + +void OpenGLImageHelper::postInit() +{ + glGenTextures(texturesSize, &mTextures[mFreeTextureIndex]); +} + #endif |