From 0d3d7c908ef6d294b14f55f09c9d83767fbc5f32 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 12 Oct 2010 19:59:25 +0300 Subject: Implement opacity cache for SDL surfaces. Enabled by default. Can be disabled in configuration option "alphaCache" if set it to 0. Reviewed-by: Bertram --- src/resources/image.cpp | 94 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 87 insertions(+), 7 deletions(-) (limited to 'src/resources/image.cpp') diff --git a/src/resources/image.cpp b/src/resources/image.cpp index 82799bce..cd6bda15 100644 --- a/src/resources/image.cpp +++ b/src/resources/image.cpp @@ -22,6 +22,7 @@ #include "resources/image.h" #include "resources/dye.h" +#include "resources/resourcemanager.h" #ifdef USE_OPENGL #include "openglgraphics.h" @@ -37,6 +38,7 @@ bool Image::mUseOpenGL = false; int Image::mTextureType = 0; int Image::mTextureSize = 0; #endif +bool Image::mEnableAlphaCache = false; Image::Image(SDL_Surface *image, bool hasAlphaChannel, Uint8 *alphaChannel): mAlpha(1.0f), @@ -48,6 +50,8 @@ Image::Image(SDL_Surface *image, bool hasAlphaChannel, Uint8 *alphaChannel): mGLImage = 0; #endif + mUseAlphaCache = Image::mEnableAlphaCache; + mBounds.x = 0; mBounds.y = 0; @@ -71,6 +75,7 @@ Image::Image(GLuint glimage, int width, int height, int texWidth, int texHeight) mHasAlphaChannel(true), mSDLSurface(0), mAlphaChannel(0), + mUseAlphaCache(false), mGLImage(glimage), mTexWidth(texWidth), mTexHeight(texHeight) @@ -166,12 +171,28 @@ Image *Image::load(SDL_Surface *tmpImage) return _SDLload(tmpImage); } +void Image::cleanCache() +{ + ResourceManager *resman = ResourceManager::getInstance(); + + for (std::map::iterator + i = mAlphaCache.begin(), i_end = mAlphaCache.end(); + i != i_end; ++i) + { + if (mSDLSurface != i->second) + resman->scheduleDelete(i->second); + i->second = 0; + } + mAlphaCache.clear(); +} + void Image::unload() { mLoaded = false; if (mSDLSurface) { + cleanCache(); // Free the image surface. SDL_FreeSurface(mSDLSurface); mSDLSurface = NULL; @@ -211,6 +232,14 @@ bool Image::hasAlphaChannel() return false; } +SDL_Surface *Image::getByAlpha(float alpha) +{ + std::map::iterator it = mAlphaCache.find(alpha); + if (it != mAlphaCache.end()) + return (*it).second; + return 0; +} + void Image::setAlpha(float alpha) { if (mAlpha == alpha) @@ -219,10 +248,34 @@ void Image::setAlpha(float alpha) if (alpha < 0.0f || alpha > 1.0f) return; - mAlpha = alpha; - if (mSDLSurface) { + if (mUseAlphaCache) + { + SDL_Surface *surface = getByAlpha(mAlpha); + if (!surface) + { + if (mAlphaCache.size() > 100) + cleanCache(); + + mAlphaCache[mAlpha] = mSDLSurface; + } + surface = getByAlpha(alpha); + if (surface) + { + mAlphaCache.erase(alpha); + mSDLSurface = surface; + mAlpha = alpha; + return; + } + else + { + mSDLSurface = Image::duplicateSurface(mSDLSurface); + } + } + + mAlpha = alpha; + if (!hasAlphaChannel()) { // Set the alpha value this image is drawn at @@ -263,6 +316,10 @@ void Image::setAlpha(float alpha) SDL_UnlockSurface(mSDLSurface); } } + else + { + mAlpha = alpha; + } } Image* Image::SDLmerge(Image *image, int x, int y) @@ -371,6 +428,14 @@ Image* Image::SDLgetScaledImage(int width, int height) return scaledImage; } +SDL_Surface* Image::duplicateSurface(SDL_Surface* tmpImage) +{ + if (!tmpImage || !tmpImage->format) + return NULL; + + return SDL_ConvertSurface(tmpImage, tmpImage->format, SDL_SWSURFACE); +} + Image *Image::_SDLload(SDL_Surface *tmpImage) { if (!tmpImage) @@ -560,25 +625,40 @@ Image *Image::getSubImage(int x, int y, int width, int height) return new SubImage(this, mSDLSurface, x, y, width, height); } +void Image::terminateAlphaCache() +{ + cleanCache(); + mUseAlphaCache = false; +} + //============================================================================ // SubImage Class //============================================================================ SubImage::SubImage(Image *parent, SDL_Surface *image, - int x, int y, int width, int height): + int x, int y, int width, int height): Image(image), mParent(parent) { - mParent->incRef(); - - mHasAlphaChannel = mParent->hasAlphaChannel(); - mAlphaChannel = mParent->SDLgetAlphaChannel(); + if (mParent) + { + mParent->incRef(); + mParent->terminateAlphaCache(); + mHasAlphaChannel = mParent->hasAlphaChannel(); + mAlphaChannel = mParent->SDLgetAlphaChannel(); + } + else + { + mHasAlphaChannel = false; + mAlphaChannel = 0; + } // Set up the rectangle. mBounds.x = x; mBounds.y = y; mBounds.w = width; mBounds.h = height; + mUseAlphaCache = false; } #ifdef USE_OPENGL -- cgit v1.2.3-70-g09d2 From 9824ccf5946c86df1cf497b797c5f3da5d481d28 Mon Sep 17 00:00:00 2001 From: "madcamel@gmail.com" Date: Sat, 16 Oct 2010 14:35:24 +0200 Subject: Added Low CPU Mode toggle in video setup. Defaults to On. This disables the Image::setAlpha() function, which uses 60% of the client's CPU cycles. When enabled, visual quality is slightly decreased, especially with the particle system. Toggling this setting On from an Off state requires a client restart or the graphics look quite funny. Bertram's addition: - Renamed 'Low CPU' to 'Disable transparency (Low CPU)' in the gui for better understanding. - Removed the sprite display with 30% opacity when disabling transparency since it made monsters and drops be drawn above all layers at full opacity. - Made the OpenGL mode disable the 'low CPU mode'. - Fixed the GUI logic as much as possible. Please note that the GUI opacity slider stays enabled when transparency is disabled even if told to be disabled in that case. Reviewed-by: CodyMartin, 4144, MadCamel. --- src/client.cpp | 1 + src/gui/setup_video.cpp | 55 ++++++++++++++++++++++++++++++++++++++++++++++--- src/gui/setup_video.h | 3 +++ src/map.cpp | 24 ++++++++++++--------- src/resources/image.cpp | 4 ++++ 5 files changed, 74 insertions(+), 13 deletions(-) (limited to 'src/resources/image.cpp') diff --git a/src/client.cpp b/src/client.cpp index 2d5bdc3f..0b62a48d 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -1107,6 +1107,7 @@ void Client::initConfiguration() config.setValue("customcursor", true); config.setValue("useScreenshotDirectorySuffix", true); config.setValue("ChatLogLength", 128); + config.setValue("lowcpu", true); // Checking if the configuration file exists... otherwise create it with // default options. diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp index ba967275..1a3d15bf 100644 --- a/src/gui/setup_video.cpp +++ b/src/gui/setup_video.cpp @@ -211,6 +211,7 @@ Setup_Video::Setup_Video(): mPickupParticleEnabled(config.getValue("showpickupparticle", false)), mOpacity(config.getValue("guialpha", 0.8)), mFps((int) config.getValue("fpslimit", 60)), + mLowCPUEnabled(config.getValue("lowcpu", true)), mSpeechMode(static_cast( config.getValue("speech", Being::TEXT_OVERHEAD))), mModeListModel(new ModeListModel), @@ -243,7 +244,9 @@ Setup_Video::Setup_Video(): mParticleDetail(3 - (int) config.getValue("particleEmitterSkip", 1)), mParticleDetailSlider(new Slider(0, 3)), mParticleDetailField(new Label), - mFontSize((int) config.getValue("fontSize", 11)) + mFontSize((int) config.getValue("fontSize", 11)), + mLowCPUCheckBox(new CheckBox(_("Disable transparency (Low CPU mode)"), + mLowCPUEnabled)) { setName(_("Video")); @@ -277,6 +280,10 @@ Setup_Video::Setup_Video(): mFpsSlider->setEnabled(mFps > 0); mFpsCheckBox->setSelected(mFps > 0); + // If the openGL Mode is enabled, disabling the transaprency + // is irrelelvant. + mLowCPUCheckBox->setEnabled(!mOpenGLEnabled); + // Pre-select the current video mode. std::string videoMode = toString(graphics->getWidth()) + "x" + toString(graphics->getHeight()); @@ -297,6 +304,7 @@ Setup_Video::Setup_Video(): mFpsSlider->setActionEventId("fpslimitslider"); mOverlayDetailSlider->setActionEventId("overlaydetailslider"); mOverlayDetailField->setActionEventId("overlaydetailfield"); + mOpenGLCheckBox->setActionEventId("opengl"); mParticleDetailSlider->setActionEventId("particledetailslider"); mParticleDetailField->setActionEventId("particledetailfield"); @@ -304,6 +312,7 @@ Setup_Video::Setup_Video(): mCustomCursorCheckBox->addActionListener(this); mShowMonsterDamageCheckBox->addActionListener(this); mVisibleNamesCheckBox->addActionListener(this); + mOpenGLCheckBox->addActionListener(this); mParticleEffectsCheckBox->addActionListener(this); mPickupChatCheckBox->addActionListener(this); mPickupParticleCheckBox->addActionListener(this); @@ -317,6 +326,7 @@ Setup_Video::Setup_Video(): mOverlayDetailField->addKeyListener(this); mParticleDetailSlider->addActionListener(this); mParticleDetailField->addKeyListener(this); + mLowCPUCheckBox->addActionListener(this); mSpeechLabel->setCaption(speechModeToString(mSpeechMode)); mSpeechSlider->setValue(mSpeechMode); @@ -374,6 +384,8 @@ Setup_Video::Setup_Video(): place(1, 11, particleDetailLabel); place(2, 11, mParticleDetailField, 3).setPadding(2); + place(0, 12, mLowCPUCheckBox, 4); + setDimension(gcn::Rectangle(0, 0, 365, 300)); } @@ -444,8 +456,9 @@ void Setup_Video::apply() { new OkDialog(_("Changing to OpenGL"), _("Applying change to OpenGL requires restart. " - "In case OpenGL messes up your game graphics, restart " - "the game with the command line option \"--no-opengl\".")); + "In case OpenGL messes up your game graphics, " + "restart the game with the command line option " + "\"--no-opengl\".")); } else { @@ -454,6 +467,30 @@ void Setup_Video::apply() } } + // If LowCPU is enabled from a disabled state we warn the user + if (mLowCPUCheckBox->isSelected()) + { + if (config.getValue("lowcpu", true) == false) + { + new OkDialog(_("Low CPU Mode Enabled"), + _("You must restart to prevent graphical errors.")); + } + + mLowCPUEnabled = true; + config.setValue("lowcpu", true); + } + else + { + if (config.getValue("lowcpu", true) == true) + { + new OkDialog(_("Low CPU Mode Disabled"), + _("You must restart to apply changes.")); + } + + mLowCPUEnabled = false; + config.setValue("lowcpu", false); + } + mFps = mFpsCheckBox->isSelected() ? (int) mFpsSlider->getValue() : 0; mFpsSlider->setEnabled(mFps > 0); @@ -476,6 +513,7 @@ void Setup_Video::apply() mOpenGLEnabled = config.getValue("opengl", false); mPickupChatEnabled = config.getValue("showpickupchat", true); mPickupParticleEnabled = config.getValue("showpickupparticle", false); + mLowCPUEnabled = config.getValue("lowcpu", true); } void Setup_Video::cancel() @@ -497,6 +535,7 @@ void Setup_Video::cancel() mParticleDetailSlider->setValue(mParticleDetail); std::string text = mFpsCheckBox->isSelected() ? toString(mFps) : _("None"); mFpsLabel->setCaption(text); + mLowCPUCheckBox->setSelected(mLowCPUEnabled); config.setValue("screen", mFullScreenEnabled); @@ -628,4 +667,14 @@ void Setup_Video::action(const gcn::ActionEvent &event) mFpsSlider->setValue(mFps); mFpsSlider->setEnabled(mFps > 0); } + else if (id == "opengl") + { + // Disable low cpu mode when in OpenGL. + mLowCPUCheckBox->setEnabled(!mOpenGLCheckBox->isSelected()); + // Disable gui opacity slider when disabling transparency. + if (mLowCPUCheckBox->isEnabled()) + mAlphaSlider->setEnabled(!mLowCPUCheckBox->isSelected()); + else + mAlphaSlider->setEnabled(true); + } } diff --git a/src/gui/setup_video.h b/src/gui/setup_video.h index ae0786b1..0f8a1e70 100644 --- a/src/gui/setup_video.h +++ b/src/gui/setup_video.h @@ -62,6 +62,7 @@ class Setup_Video : public SetupTab, public gcn::ActionListener, bool mPickupParticleEnabled; double mOpacity; int mFps; + bool mLowCPUEnabled; Being::Speech mSpeechMode; ModeListModel *mModeListModel; @@ -106,6 +107,8 @@ class Setup_Video : public SetupTab, public gcn::ActionListener, int mFontSize; gcn::DropDown *mFontSizeDropDown; + + gcn::CheckBox *mLowCPUCheckBox; }; #endif diff --git a/src/map.cpp b/src/map.cpp index f1f8d091..2de0a4a8 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -330,21 +330,25 @@ void Map::draw(Graphics *graphics, int scrollX, int scrollY) mSprites, mDebugFlags); } - // Draws beings with a lower opacity to make them visible - // even when covered by a wall or some other elements... - MapSprites::const_iterator si = mSprites.begin(); - while (si != mSprites.end()) + // If the transparency hasn't been disabled, + if (config.getValue("opengl", false) || !config.getValue("lowcpu", true)) { - if (Sprite *sprite = *si) + // We draw beings with a lower opacity to make them visible + // even when covered by a wall or some other elements... + MapSprites::const_iterator si = mSprites.begin(); + while (si != mSprites.end()) { - // For now, just draw sprites with only one layer. - if (sprite->getNumberOfLayers() == 1) + if (Sprite *sprite = *si) { - sprite->setAlpha(0.3f); - sprite->draw(graphics, -scrollX, -scrollY); + // For now, just draw sprites with only one layer. + if (sprite->getNumberOfLayers() == 1) + { + sprite->setAlpha(0.3f); + sprite->draw(graphics, -scrollX, -scrollY); + } } + si++; } - si++; } drawAmbientLayers(graphics, FOREGROUND_LAYERS, scrollX, scrollY, diff --git a/src/resources/image.cpp b/src/resources/image.cpp index cd6bda15..42a6ab56 100644 --- a/src/resources/image.cpp +++ b/src/resources/image.cpp @@ -29,6 +29,7 @@ #endif #include "log.h" +#include "configuration.h" #include #include @@ -242,6 +243,9 @@ SDL_Surface *Image::getByAlpha(float alpha) void Image::setAlpha(float alpha) { + if (config.getValue("lowcpu", true) == true) + return; + if (mAlpha == alpha) return; -- cgit v1.2.3-70-g09d2 From dbac793645654ac6715e6adecfd9d4a4a1fd8551 Mon Sep 17 00:00:00 2001 From: Yohann Ferreira Date: Fri, 22 Oct 2010 12:52:35 +0200 Subject: 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. --- src/client.cpp | 9 +++++-- src/gui/widgets/desktop.cpp | 4 +-- src/map.cpp | 2 +- src/resources/ambientlayer.cpp | 4 +-- src/resources/ambientoverlay.cpp | 4 +-- src/resources/image.cpp | 35 ++++++++++++++------------ src/resources/image.h | 54 ++++++++++++++++++++++++---------------- 7 files changed, 66 insertions(+), 46 deletions(-) (limited to 'src/resources/image.cpp') diff --git a/src/client.cpp b/src/client.cpp index 2681a254..3ed3fb34 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -253,7 +253,7 @@ Client::Client(const Options &options): "Exiting.", mLocalDataDir.c_str())); } - Image::setEnableAlphaCache(config.getValue("alphaCache", true)); + Image::SDLsetEnableAlphaCache(config.getValue("alphaCache", true)); #if defined __APPLE__ CFBundleRef mainBundle = CFBundleGetMainBundle(); @@ -317,9 +317,14 @@ Client::Client(const Options &options): } #endif -#ifdef USE_OPENGL bool useOpenGL = !mOptions.noOpenGL && (config.getValue("opengl", 0) == 1); + // Set up the transparency option for low CPU when not using OpenGL. + if (!useOpenGL && (config.getValue("lowcpu", 0) == 1)) + Image::SDLdisableTransparency(); + +#ifdef USE_OPENGL + // Setup image loading for the right image format Image::setLoadAsOpenGL(useOpenGL); diff --git a/src/gui/widgets/desktop.cpp b/src/gui/widgets/desktop.cpp index 2a80cc11..23dd3eb5 100644 --- a/src/gui/widgets/desktop.cpp +++ b/src/gui/widgets/desktop.cpp @@ -85,7 +85,7 @@ void Desktop::draw(gcn::Graphics *graphics) if (mWallpaper) { - if (!mWallpaper->isAnOpenGLOne()) + if (!mWallpaper->useOpenGL()) g->drawImage(mWallpaper, (getWidth() - mWallpaper->getWidth()) / 2, (getHeight() - mWallpaper->getHeight()) / 2); @@ -114,7 +114,7 @@ void Desktop::setBestFittingWallpaper() if (mWallpaper) mWallpaper->decRef(); - if (!nWallPaper->isAnOpenGLOne() && (nWallPaper->getWidth() != getWidth() + if (!nWallPaper->useOpenGL() && (nWallPaper->getWidth() != getWidth() || nWallPaper->getHeight() != getHeight())) { // We rescale to obtain a fullscreen wallpaper... diff --git a/src/map.cpp b/src/map.cpp index 2de0a4a8..f845f2ff 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -331,7 +331,7 @@ void Map::draw(Graphics *graphics, int scrollX, int scrollY) } // If the transparency hasn't been disabled, - if (config.getValue("opengl", false) || !config.getValue("lowcpu", true)) + if (Image::useOpenGL() || !Image::SDLisTransparencyDisabled()) { // We draw beings with a lower opacity to make them visible // even when covered by a wall or some other elements... 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,9 +137,23 @@ 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. * @@ -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 mAlphaCache; - bool mUseAlphaCache; - static bool mEnableAlphaCache; + /** Stores whether the transparency is disabled */ + static bool mDisableTransparency; + // ----------------------- // OpenGL protected members // ----------------------- -- cgit v1.2.3-70-g09d2