From b1eac7d3738dcff22a3b553459f1587c18a23c23 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 4 Jun 2012 22:37:02 +0300 Subject: Improve images load speed in openGL modes for correct image sizes. --- src/resources/image.cpp | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/resources/image.cpp b/src/resources/image.cpp index da20719ac..9bb824ea1 100644 --- a/src/resources/image.cpp +++ b/src/resources/image.cpp @@ -761,18 +761,28 @@ Image *Image::_GLload(SDL_Surface *tmpImage) amask = 0xff000000; #endif - SDL_Surface *oldImage = tmpImage; - tmpImage = SDL_CreateRGBSurface(SDL_SWSURFACE, realWidth, realHeight, - 32, rmask, gmask, bmask, amask); + SDL_Surface *oldImage = nullptr; + if (tmpImage->format->BitsPerPixel != 32 + || realWidth != width || realHeight != height) + { + oldImage = tmpImage; + tmpImage = SDL_CreateRGBSurface(SDL_SWSURFACE, realWidth, realHeight, + 32, rmask, gmask, bmask, amask); - if (!tmpImage) + if (!tmpImage) + { + logger->log("Error, image convert failed: out of memory"); + return nullptr; + } + SDL_BlitSurface(oldImage, nullptr, tmpImage, nullptr); + } + else { - logger->log("Error, image convert failed: out of memory"); - return nullptr; + static int cnt = 0; + cnt ++; + logger->log("fast load: %d", cnt); } - SDL_BlitSurface(oldImage, nullptr, tmpImage, nullptr); - GLuint texture; glGenTextures(1, &texture); if (mUseOpenGL == 1) @@ -816,7 +826,8 @@ Image *Image::_GLload(SDL_Surface *tmpImage) if (SDL_MUSTLOCK(tmpImage)) SDL_UnlockSurface(tmpImage); - SDL_FreeSurface(tmpImage); + if (oldImage) + SDL_FreeSurface(tmpImage); GLenum error = glGetError(); if (error) -- cgit v1.2.3-60-g2f50