diff options
Diffstat (limited to 'src/resources')
-rw-r--r-- | src/resources/ambientlayer.cpp | 4 | ||||
-rw-r--r-- | src/resources/ambientoverlay.cpp | 4 | ||||
-rw-r--r-- | src/resources/image.cpp | 35 | ||||
-rw-r--r-- | src/resources/image.h | 54 |
4 files changed, 56 insertions, 41 deletions
diff --git a/src/resources/ambientlayer.cpp b/src/resources/ambientlayer.cpp index 50fe8bd9..b662ddeb 100644 --- a/src/resources/ambientlayer.cpp +++ b/src/resources/ambientlayer.cpp @@ -33,7 +33,7 @@ AmbientLayer::AmbientLayer(Image *img, float parallax, mKeepRatio(keepRatio) { - if (keepRatio && !mImage->isAnOpenGLOne() + if (keepRatio && !mImage->useOpenGL() && defaultScreenWidth != 0 && defaultScreenHeight != 0 && graphics->getWidth() != defaultScreenWidth @@ -92,7 +92,7 @@ void AmbientLayer::update(int timePassed, float dx, float dy) void AmbientLayer::draw(Graphics *graphics, int x, int y) { - if (!mImage->isAnOpenGLOne() || !mKeepRatio) + if (!mImage->useOpenGL() || !mKeepRatio) graphics->drawImagePattern(mImage, (int) -mPosX, (int) -mPosY, x + (int) mPosX, y + (int) mPosY); else diff --git a/src/resources/ambientoverlay.cpp b/src/resources/ambientoverlay.cpp index 64a46676..aba12f84 100644 --- a/src/resources/ambientoverlay.cpp +++ b/src/resources/ambientoverlay.cpp @@ -34,7 +34,7 @@ AmbientOverlay::AmbientOverlay(Image *img, float parallax, mKeepRatio(keepRatio) { - if (keepRatio && !mImage->isAnOpenGLOne() + if (keepRatio && !mImage->useOpenGL() && defaultScreenWidth != 0 && defaultScreenHeight != 0 && graphics->getWidth() != defaultScreenWidth @@ -92,7 +92,7 @@ void AmbientOverlay::update(int timePassed, float dx, float dy) void AmbientOverlay::draw(Graphics *graphics, int x, int y) { - if (!mImage->isAnOpenGLOne() || !mKeepRatio) + if (!mImage->useOpenGL() || !mKeepRatio) graphics->drawImagePattern(mImage, (int) -mPosX, (int) -mPosY, x + (int) mPosX, y + (int) mPosY); else 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(); } diff --git a/src/resources/image.h b/src/resources/image.h index 815b7764..1db52ca0 100644 --- a/src/resources/image.h +++ b/src/resources/image.h @@ -113,16 +113,10 @@ class Image : public Resource { return mBounds.h; } /** - * Tells if the image was loaded using OpenGL or SDL + * Tells if the system is using OpenGL or SDL * @return true if OpenGL, false if SDL. */ - bool isAnOpenGLOne() const; - - /** - * Tells if the image has got an alpha channel - * @return true if it's true, false otherwise. - */ - bool hasAlphaChannel(); + static bool useOpenGL(); /** * Sets the alpha value of this image. @@ -143,10 +137,24 @@ class Image : public Resource */ virtual Image *getSubImage(int x, int y, int width, int height); + /** + * Tells if the image has got an alpha channel + * @return true if it's true, false otherwise. + */ + bool hasAlphaChannel(); // SDL only public functions /** + * Disable the transparency handling (for low CPUs in SDL Mode) + */ + static void SDLdisableTransparency() + { mDisableTransparency = true; } + + static bool SDLisTransparencyDisabled() + { return mDisableTransparency; } + + /** * Gets an scaled instance of an image. * * @param width The desired width of the scaled image. @@ -171,13 +179,13 @@ class Image : public Resource Uint8 *SDLgetAlphaChannel() const { return mAlphaChannel; } - SDL_Surface* duplicateSurface(SDL_Surface* tmpImage); + SDL_Surface* SDLduplicateSurface(SDL_Surface* tmpImage); - void cleanCache(); + void SDLcleanCache(); - void terminateAlphaCache(); + void SDLterminateAlphaCache(); - static void setEnableAlphaCache(bool n) + static void SDLsetEnableAlphaCache(bool n) { mEnableAlphaCache = n; } #ifdef USE_OPENGL @@ -199,18 +207,17 @@ class Image : public Resource protected: - // ----------------------- - // Generic protected members - // ----------------------- + // ----------------------- + // Generic protected members + // ----------------------- SDL_Rect mBounds; bool mLoaded; float mAlpha; - bool mHasAlphaChannel; - // ----------------------- - // SDL protected members - // ----------------------- + // ----------------------- + // SDL protected members + // ----------------------- /** SDL Constructor */ Image(SDL_Surface *image, bool hasAlphaChannel = false, @@ -225,13 +232,18 @@ class Image : public Resource /** Alpha Channel pointer used for 32bit based SDL surfaces */ Uint8 *mAlphaChannel; + bool mHasAlphaChannel; + /** Alpha cache: The cache stores a copy of the image + for specific requested opacities, hence, increasing + the image disply speed */ std::map<float, SDL_Surface*> mAlphaCache; - bool mUseAlphaCache; - static bool mEnableAlphaCache; + /** Stores whether the transparency is disabled */ + static bool mDisableTransparency; + // ----------------------- // OpenGL protected members // ----------------------- |