summaryrefslogtreecommitdiff
path: root/src/resources
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-06-04 23:57:06 +0300
committerAndrei Karas <akaras@inbox.ru>2014-06-04 23:57:06 +0300
commitc0c3782473479460273f1d6e8e0e3e7564ecff89 (patch)
treea955e6376aa7c41d7bed3b60fd5b532fec5a7d20 /src/resources
parent0c72851a2b47acba27944106eea4619b658d40ca (diff)
downloadmanaverse-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')
-rw-r--r--src/resources/imagehelper.cpp4
-rw-r--r--src/resources/imagehelper.h14
-rw-r--r--src/resources/openglimagehelper.cpp34
-rw-r--r--src/resources/openglimagehelper.h22
-rw-r--r--src/resources/sdl2imagehelper.cpp4
-rw-r--r--src/resources/sdl2imagehelper.h4
-rw-r--r--src/resources/sdl2softwareimagehelper.cpp6
-rw-r--r--src/resources/sdl2softwareimagehelper.h7
-rw-r--r--src/resources/sdlimagehelper.cpp8
-rw-r--r--src/resources/sdlimagehelper.h9
10 files changed, 71 insertions, 41 deletions
diff --git a/src/resources/imagehelper.cpp b/src/resources/imagehelper.cpp
index 0092d132b..329a487da 100644
--- a/src/resources/imagehelper.cpp
+++ b/src/resources/imagehelper.cpp
@@ -40,7 +40,7 @@ ImageHelper *surfaceImageHelper = nullptr;
bool ImageHelper::mEnableAlpha = true;
RenderType ImageHelper::mUseOpenGL = RENDER_SOFTWARE;
-Image *ImageHelper::load(SDL_RWops *const rw) const
+Image *ImageHelper::load(SDL_RWops *const rw)
{
SDL_Surface *const tmpImage = loadPng(rw);
if (!tmpImage)
@@ -55,7 +55,7 @@ Image *ImageHelper::load(SDL_RWops *const rw) const
return image;
}
-Image *ImageHelper::load(SDL_RWops *const rw, Dye const &dye) const
+Image *ImageHelper::load(SDL_RWops *const rw, Dye const &dye)
{
SDL_Surface *const tmpImage = loadPng(rw);
if (!tmpImage)
diff --git a/src/resources/imagehelper.h b/src/resources/imagehelper.h
index b91d9aaee..6752f3eae 100644
--- a/src/resources/imagehelper.h
+++ b/src/resources/imagehelper.h
@@ -56,19 +56,18 @@ class ImageHelper notfinal
* @return <code>NULL</code> if an error occurred, a valid pointer
* otherwise.
*/
- Image *load(SDL_RWops *const rw) const A_WARN_UNUSED;
+ Image *load(SDL_RWops *const rw) A_WARN_UNUSED;
- virtual Image *load(SDL_RWops *const rw, Dye
- const &dye) const A_WARN_UNUSED;
+ virtual Image *load(SDL_RWops *const rw, Dye const &dye) A_WARN_UNUSED;
#ifdef __GNUC__
- virtual Image *load(SDL_Surface *const) const A_WARN_UNUSED = 0;
+ virtual Image *load(SDL_Surface *const) A_WARN_UNUSED = 0;
virtual Image *createTextSurface(SDL_Surface *const tmpImage,
const int width, const int height,
- float alpha) const A_WARN_UNUSED = 0;
+ float alpha) A_WARN_UNUSED = 0;
#else
- virtual Image *load(SDL_Surface *) const A_WARN_UNUSED
+ virtual Image *load(SDL_Surface *) A_WARN_UNUSED
{ return nullptr; }
virtual Image *createTextSurface(SDL_Surface *const tmpImage,
@@ -96,6 +95,9 @@ class ImageHelper notfinal
virtual RenderType useOpenGL() const A_WARN_UNUSED
{ return mUseOpenGL; }
+ virtual void postInit()
+ { }
+
protected:
ImageHelper()
{ }
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
diff --git a/src/resources/openglimagehelper.h b/src/resources/openglimagehelper.h
index 2f203a00a..d87052592 100644
--- a/src/resources/openglimagehelper.h
+++ b/src/resources/openglimagehelper.h
@@ -58,14 +58,14 @@ class OpenGLImageHelper final : public ImageHelper
friend class Image;
public:
- OpenGLImageHelper()
+ OpenGLImageHelper() :
+ mFreeTextureIndex(0)
{
}
A_DELETE_COPY(OpenGLImageHelper)
- ~OpenGLImageHelper()
- { }
+ ~OpenGLImageHelper();
/**
* Loads an image from an SDL_RWops structure and recolors it.
@@ -77,18 +77,18 @@ class OpenGLImageHelper final : public ImageHelper
* otherwise.
*/
Image *load(SDL_RWops *const rw,
- Dye const &dye) const override final A_WARN_UNUSED;
+ Dye const &dye) override final A_WARN_UNUSED;
/**
* Loads an image from an SDL surface.
*/
- Image *load(SDL_Surface *const tmpImage) const
+ Image *load(SDL_Surface *const tmpImage)
override final A_WARN_UNUSED;
Image *createTextSurface(SDL_Surface *const tmpImage,
const int width, const int height,
const float alpha)
- const override final A_WARN_UNUSED;
+ override final A_WARN_UNUSED;
// OpenGL only public functions
@@ -119,6 +119,8 @@ class OpenGLImageHelper final : public ImageHelper
SDL_Surface *create32BitSurface(int width,
int height) const override final;
+ void postInit() override final;
+
protected:
/**
* Returns the first power of two equal or bigger than the input.
@@ -126,7 +128,13 @@ class OpenGLImageHelper final : public ImageHelper
static int powerOfTwo(const int input) A_WARN_UNUSED;
Image *glLoad(SDL_Surface *tmpImage,
- int width = 0, int height = 0) const A_WARN_UNUSED;
+ int width = 0, int height = 0) A_WARN_UNUSED;
+
+ GLuint getNewTexture();
+
+ static const size_t texturesSize = 10;
+ size_t mFreeTextureIndex;
+ GLuint mTextures[texturesSize];
static int mTextureSize;
static bool mBlur;
diff --git a/src/resources/sdl2imagehelper.cpp b/src/resources/sdl2imagehelper.cpp
index 3cda18c51..e9d0f11e9 100644
--- a/src/resources/sdl2imagehelper.cpp
+++ b/src/resources/sdl2imagehelper.cpp
@@ -44,7 +44,7 @@ bool SDLImageHelper::mEnableAlphaCache = false;
SDL_Renderer *SDLImageHelper::mRenderer = nullptr;
#endif
-Image *SDLImageHelper::load(SDL_Surface *const tmpImage) const
+Image *SDLImageHelper::load(SDL_Surface *const tmpImage)
{
return _SDLload(tmpImage);
}
@@ -71,7 +71,7 @@ SDL_Surface* SDLImageHelper::SDLDuplicateSurface(SDL_Surface *const tmpImage)
return MSDL_ConvertSurface(tmpImage, tmpImage->format, SDL_SWSURFACE);
}
-Image *SDLImageHelper::_SDLload(SDL_Surface *tmpImage) const
+Image *SDLImageHelper::_SDLload(SDL_Surface *tmpImage)
{
if (!tmpImage)
return nullptr;
diff --git a/src/resources/sdl2imagehelper.h b/src/resources/sdl2imagehelper.h
index 296b50f8a..0ffeee7ae 100644
--- a/src/resources/sdl2imagehelper.h
+++ b/src/resources/sdl2imagehelper.h
@@ -54,7 +54,7 @@ class SDLImageHelper final : public ImageHelper
/**
* Loads an image from an SDL surface.
*/
- Image *load(SDL_Surface *const tmpImage) const
+ Image *load(SDL_Surface *const tmpImage)
override final A_WARN_UNUSED;
Image *createTextSurface(SDL_Surface *const tmpImage,
@@ -83,7 +83,7 @@ class SDLImageHelper final : public ImageHelper
protected:
/** SDL_Surface to SDL_Surface Image loader */
- Image *_SDLload(SDL_Surface *tmpImage) const A_WARN_UNUSED;
+ Image *_SDLload(SDL_Surface *tmpImage) A_WARN_UNUSED;
static bool mEnableAlphaCache;
#ifdef USE_SDL2
diff --git a/src/resources/sdl2softwareimagehelper.cpp b/src/resources/sdl2softwareimagehelper.cpp
index fa0a51606..2e73409ef 100644
--- a/src/resources/sdl2softwareimagehelper.cpp
+++ b/src/resources/sdl2softwareimagehelper.cpp
@@ -41,7 +41,7 @@
bool SDL2SoftwareImageHelper::mEnableAlphaCache = false;
SDL_PixelFormat *SDL2SoftwareImageHelper::mFormat = nullptr;
-Image *SDL2SoftwareImageHelper::load(SDL_Surface *const tmpImage) const
+Image *SDL2SoftwareImageHelper::load(SDL_Surface *const tmpImage)
{
return _SDLload(tmpImage);
}
@@ -49,7 +49,7 @@ Image *SDL2SoftwareImageHelper::load(SDL_Surface *const tmpImage) const
Image *SDL2SoftwareImageHelper::createTextSurface(SDL_Surface *const tmpImage,
const int width A_UNUSED,
const int height A_UNUSED,
- const float alpha) const
+ const float alpha)
{
if (!tmpImage)
return nullptr;
@@ -69,7 +69,7 @@ SDL_Surface* SDL2SoftwareImageHelper::SDLDuplicateSurface(SDL_Surface *const
return MSDL_ConvertSurface(tmpImage, tmpImage->format, SDL_SWSURFACE);
}
-Image *SDL2SoftwareImageHelper::_SDLload(SDL_Surface *tmpImage) const
+Image *SDL2SoftwareImageHelper::_SDLload(SDL_Surface *tmpImage)
{
if (!tmpImage)
return nullptr;
diff --git a/src/resources/sdl2softwareimagehelper.h b/src/resources/sdl2softwareimagehelper.h
index 41af65fdb..3d580a79f 100644
--- a/src/resources/sdl2softwareimagehelper.h
+++ b/src/resources/sdl2softwareimagehelper.h
@@ -54,13 +54,12 @@ class SDL2SoftwareImageHelper final : public ImageHelper
/**
* Loads an image from an SDL surface.
*/
- Image *load(SDL_Surface *const tmpImage) const
- override final A_WARN_UNUSED;
+ Image *load(SDL_Surface *const tmpImage) override final A_WARN_UNUSED;
Image *createTextSurface(SDL_Surface *const tmpImage,
const int width, const int height,
const float alpha)
- const override final A_WARN_UNUSED;
+ override final A_WARN_UNUSED;
static void SDLSetEnableAlphaCache(const bool n)
{ mEnableAlphaCache = n; }
@@ -88,7 +87,7 @@ class SDL2SoftwareImageHelper final : public ImageHelper
protected:
/** SDL_Surface to SDL_Surface Image loader */
- Image *_SDLload(SDL_Surface *tmpImage) const A_WARN_UNUSED;
+ Image *_SDLload(SDL_Surface *tmpImage) A_WARN_UNUSED;
static bool mEnableAlphaCache;
static SDL_PixelFormat *mFormat;
diff --git a/src/resources/sdlimagehelper.cpp b/src/resources/sdlimagehelper.cpp
index 16f0b45ba..7d4090deb 100644
--- a/src/resources/sdlimagehelper.cpp
+++ b/src/resources/sdlimagehelper.cpp
@@ -40,7 +40,7 @@
bool SDLImageHelper::mEnableAlphaCache = false;
-Image *SDLImageHelper::load(SDL_RWops *const rw, Dye const &dye) const
+Image *SDLImageHelper::load(SDL_RWops *const rw, Dye const &dye)
{
SDL_Surface *const tmpImage = loadPng(rw);
if (!tmpImage)
@@ -104,7 +104,7 @@ Image *SDLImageHelper::load(SDL_RWops *const rw, Dye const &dye) const
return image;
}
-Image *SDLImageHelper::load(SDL_Surface *const tmpImage) const
+Image *SDLImageHelper::load(SDL_Surface *const tmpImage)
{
return _SDLload(tmpImage);
}
@@ -112,7 +112,7 @@ Image *SDLImageHelper::load(SDL_Surface *const tmpImage) const
Image *SDLImageHelper::createTextSurface(SDL_Surface *const tmpImage,
const int width A_UNUSED,
const int height A_UNUSED,
- const float alpha) const
+ const float alpha)
{
if (!tmpImage)
return nullptr;
@@ -185,7 +185,7 @@ SDL_Surface* SDLImageHelper::SDLDuplicateSurface(SDL_Surface *const tmpImage)
return MSDL_ConvertSurface(tmpImage, tmpImage->format, SDL_SWSURFACE);
}
-Image *SDLImageHelper::_SDLload(SDL_Surface *tmpImage) const
+Image *SDLImageHelper::_SDLload(SDL_Surface *tmpImage)
{
if (!tmpImage)
return nullptr;
diff --git a/src/resources/sdlimagehelper.h b/src/resources/sdlimagehelper.h
index 18228c2e9..c80a7ba2b 100644
--- a/src/resources/sdlimagehelper.h
+++ b/src/resources/sdlimagehelper.h
@@ -62,18 +62,17 @@ class SDLImageHelper final : public ImageHelper
* otherwise.
*/
Image *load(SDL_RWops *const rw,
- Dye const &dye) const override final A_WARN_UNUSED;
+ Dye const &dye) override final A_WARN_UNUSED;
/**
* Loads an image from an SDL surface.
*/
- Image *load(SDL_Surface *const tmpImage) const
- override final A_WARN_UNUSED;
+ Image *load(SDL_Surface *const tmpImage) override final A_WARN_UNUSED;
Image *createTextSurface(SDL_Surface *const tmpImage,
const int width, const int height,
const float alpha)
- const override final A_WARN_UNUSED;
+ override final A_WARN_UNUSED;
static void SDLSetEnableAlphaCache(const bool n)
{ mEnableAlphaCache = n; }
@@ -91,7 +90,7 @@ class SDLImageHelper final : public ImageHelper
protected:
/** SDL_Surface to SDL_Surface Image loader */
- Image *_SDLload(SDL_Surface *tmpImage) const A_WARN_UNUSED;
+ Image *_SDLload(SDL_Surface *tmpImage) A_WARN_UNUSED;
static bool mEnableAlphaCache;
};