summaryrefslogtreecommitdiff
path: root/src/resources/image.cpp
diff options
context:
space:
mode:
authorYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2010-10-22 12:52:35 +0200
committerYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2010-10-22 12:52:35 +0200
commitdbac793645654ac6715e6adecfd9d4a4a1fd8551 (patch)
tree52550aeeb8caec936897a792236300f86aad3884 /src/resources/image.cpp
parenta9bcae9f81d97f67ab21cd26a099449cf0746137 (diff)
downloadmana-dbac793645654ac6715e6adecfd9d4a4a1fd8551.tar.gz
mana-dbac793645654ac6715e6adecfd9d4a4a1fd8551.tar.bz2
mana-dbac793645654ac6715e6adecfd9d4a4a1fd8551.tar.xz
mana-dbac793645654ac6715e6adecfd9d4a4a1fd8551.zip
Turned the OpenGL and disable transparency options as static members.
- Now OpenGL and the transparency disabling are set at startup and not read again for displaying graphics, preventing graphic errors before startup. - We also agreed long time ago that SDL specific functions should have a SDL prefix. The header has been rearranged a bit to do so. - Also fixed a possible discrepancy in the hasAlphaChannel() function. Reviewed-by: CodyMartin. Resolves: Mana-Mantis: #260.
Diffstat (limited to 'src/resources/image.cpp')
-rw-r--r--src/resources/image.cpp35
1 files changed, 19 insertions, 16 deletions
diff --git a/src/resources/image.cpp b/src/resources/image.cpp
index 42a6ab56..63f1bd2c 100644
--- a/src/resources/image.cpp
+++ b/src/resources/image.cpp
@@ -41,11 +41,14 @@ int Image::mTextureSize = 0;
#endif
bool Image::mEnableAlphaCache = false;
+// The low CPU mode is disabled per default
+bool Image::mDisableTransparency = false;
+
Image::Image(SDL_Surface *image, bool hasAlphaChannel, Uint8 *alphaChannel):
mAlpha(1.0f),
- mHasAlphaChannel(hasAlphaChannel),
mSDLSurface(image),
- mAlphaChannel(alphaChannel)
+ mAlphaChannel(alphaChannel),
+ mHasAlphaChannel(hasAlphaChannel)
{
#ifdef USE_OPENGL
mGLImage = 0;
@@ -73,9 +76,9 @@ Image::Image(SDL_Surface *image, bool hasAlphaChannel, Uint8 *alphaChannel):
#ifdef USE_OPENGL
Image::Image(GLuint glimage, int width, int height, int texWidth, int texHeight):
mAlpha(1.0f),
- mHasAlphaChannel(true),
mSDLSurface(0),
mAlphaChannel(0),
+ mHasAlphaChannel(true),
mUseAlphaCache(false),
mGLImage(glimage),
mTexWidth(texWidth),
@@ -172,7 +175,7 @@ Image *Image::load(SDL_Surface *tmpImage)
return _SDLload(tmpImage);
}
-void Image::cleanCache()
+void Image::SDLcleanCache()
{
ResourceManager *resman = ResourceManager::getInstance();
@@ -193,7 +196,7 @@ void Image::unload()
if (mSDLSurface)
{
- cleanCache();
+ SDLcleanCache();
// Free the image surface.
SDL_FreeSurface(mSDLSurface);
mSDLSurface = NULL;
@@ -211,7 +214,7 @@ void Image::unload()
#endif
}
-bool Image::isAnOpenGLOne() const
+bool Image::useOpenGL()
{
#ifdef USE_OPENGL
return mUseOpenGL;
@@ -222,15 +225,15 @@ bool Image::isAnOpenGLOne() const
bool Image::hasAlphaChannel()
{
- if (mLoaded)
- return mHasAlphaChannel;
+ if (!mLoaded)
+ return false;
#ifdef USE_OPENGL
if (mUseOpenGL)
return true;
#endif
- return false;
+ return mHasAlphaChannel;
}
SDL_Surface *Image::getByAlpha(float alpha)
@@ -243,7 +246,7 @@ SDL_Surface *Image::getByAlpha(float alpha)
void Image::setAlpha(float alpha)
{
- if (config.getValue("lowcpu", true) == true)
+ if (!useOpenGL() && mDisableTransparency)
return;
if (mAlpha == alpha)
@@ -260,7 +263,7 @@ void Image::setAlpha(float alpha)
if (!surface)
{
if (mAlphaCache.size() > 100)
- cleanCache();
+ SDLcleanCache();
mAlphaCache[mAlpha] = mSDLSurface;
}
@@ -274,7 +277,7 @@ void Image::setAlpha(float alpha)
}
else
{
- mSDLSurface = Image::duplicateSurface(mSDLSurface);
+ mSDLSurface = Image::SDLduplicateSurface(mSDLSurface);
}
}
@@ -432,7 +435,7 @@ Image* Image::SDLgetScaledImage(int width, int height)
return scaledImage;
}
-SDL_Surface* Image::duplicateSurface(SDL_Surface* tmpImage)
+SDL_Surface* Image::SDLduplicateSurface(SDL_Surface* tmpImage)
{
if (!tmpImage || !tmpImage->format)
return NULL;
@@ -629,9 +632,9 @@ Image *Image::getSubImage(int x, int y, int width, int height)
return new SubImage(this, mSDLSurface, x, y, width, height);
}
-void Image::terminateAlphaCache()
+void Image::SDLterminateAlphaCache()
{
- cleanCache();
+ SDLcleanCache();
mUseAlphaCache = false;
}
@@ -647,7 +650,7 @@ SubImage::SubImage(Image *parent, SDL_Surface *image,
if (mParent)
{
mParent->incRef();
- mParent->terminateAlphaCache();
+ mParent->SDLterminateAlphaCache();
mHasAlphaChannel = mParent->hasAlphaChannel();
mAlphaChannel = mParent->SDLgetAlphaChannel();
}