From dbf1544dc6dd7e31ad884afaffb192944f8bb22f Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 1 Jul 2014 22:00:53 +0300 Subject: In atlasmanager use copy surface to image function. This allow in OpenGL modes copy surface into video memory without software blitting. --- src/resources/atlasmanager.cpp | 39 ++++++++++++++++----------------------- src/resources/textureatlas.h | 2 -- 2 files changed, 16 insertions(+), 25 deletions(-) (limited to 'src/resources') diff --git a/src/resources/atlasmanager.cpp b/src/resources/atlasmanager.cpp index cadf917f9..cdbd26a65 100644 --- a/src/resources/atlasmanager.cpp +++ b/src/resources/atlasmanager.cpp @@ -26,7 +26,9 @@ #include "configuration.h" -#include "render/surfacegraphics.h" +#ifdef DEBUG_IMAGES +#include "logger.h" +#endif #include "utils/mathutils.h" #include "utils/physfscheckutils.h" @@ -39,6 +41,7 @@ #include "resources/imagehelper.h" #include "resources/openglimagehelper.h" #include "resources/resourcemanager.h" +#include "resources/sdlimagehelper.h" #include "resources/textureatlas.h" #include "debug.h" @@ -255,36 +258,19 @@ SDL_Surface *AtlasManager::createSDLAtlas(TextureAtlas *const atlas) } BLOCK_END("AtlasManager::createSDLAtlas create surface") - SurfaceGraphics *const graphics = new SurfaceGraphics(); - graphics->setTarget(surface); - graphics->beginDraw(); + Image *image = imageHelper->load(surface); // drawing SDL images to surface FOR_EACH (std::vector::iterator, it, atlas->items) { AtlasItem *const item = *it; - Image *const image = item->image; - if (image) { - if (image->mSDLSurface) - { - BLOCK_START("AtlasManager::createSDLAtlas set surface attr") -#ifdef USE_SDL2 - SDL_SetSurfaceAlphaMod(image->mSDLSurface, SDL_ALPHA_OPAQUE); - SDL_SetSurfaceBlendMode(image->mSDLSurface, - SDL_BLENDMODE_NONE); -#else - SDL_SetAlpha(image->mSDLSurface, 0, SDL_ALPHA_OPAQUE); -#endif - BLOCK_END("AtlasManager::createSDLAtlas set surface attr") - graphics->drawImage(image, item->x, item->y); - } + imageHelper->copySurfaceToImage(image, item->x, item->y, + item->image->mSDLSurface); } } - - delete graphics; - atlas->surface = surface; + atlas->atlasImage = image; BLOCK_END("AtlasManager::createSDLAtlas") return surface; } @@ -293,7 +279,14 @@ void AtlasManager::convertAtlas(TextureAtlas *const atlas) { // no check for null pointer in atlas because it was in caller // convert surface to OpemGL image - atlas->atlasImage = imageHelper->load(atlas->surface); + Image *const oldImage = atlas->atlasImage; + + if (oldImage->mSDLSurface) + { + atlas->atlasImage = imageHelper->load(atlas->atlasImage->mSDLSurface); + oldImage->decRef(); + } + Image *const image = atlas->atlasImage; if (!image) return; diff --git a/src/resources/textureatlas.h b/src/resources/textureatlas.h index 11a45a5d3..be3d8abd8 100644 --- a/src/resources/textureatlas.h +++ b/src/resources/textureatlas.h @@ -42,7 +42,6 @@ struct TextureAtlas final TextureAtlas() : name(), atlasImage(nullptr), - surface(nullptr), width(0), height(0), items() @@ -53,7 +52,6 @@ struct TextureAtlas final std::string name; Image *atlasImage; - SDL_Surface *surface; int width; int height; std::vector items; -- cgit v1.2.3-60-g2f50