From dff2d79a70d10043dffe7be1d387fc78c35bc810 Mon Sep 17 00:00:00 2001 From: Jonas Kulla Date: Wed, 25 Sep 2013 17:07:43 +0200 Subject: [PATCH] Implement blits from mega surfaces to regular Bitmaps This is used in events that take their sprite from a tile out of the tileset. --- src/bitmap.cpp | 44 +++++++++++++++++++++++++++++++++++++++++--- src/bitmap.h | 4 ++-- 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/src/bitmap.cpp b/src/bitmap.cpp index f523915..b9f61a7 100644 --- a/src/bitmap.cpp +++ b/src/bitmap.cpp @@ -319,10 +319,48 @@ void Bitmap::stretchBlt(const IntRect &destRect, opacity = clamp(opacity, 0, 255); if (opacity == 0) + return; + + if (source.megaSurface()) { + /* Don't do transparent blits for now */ + if (opacity < 255) + source.ensureNonMega(); + + SDL_Surface *srcSurf = source.megaSurface(); + + int bpp; + Uint32 rMask, gMask, bMask, aMask; + SDL_PixelFormatEnumToMasks(SDL_PIXELFORMAT_ABGR8888, + &bpp, &rMask, &gMask, &bMask, &aMask); + SDL_Surface *blitTemp = + SDL_CreateRGBSurface(0, destRect.w, destRect.h, bpp, rMask, gMask, bMask, aMask); + + SDL_Rect srcRect; + srcRect.x = sourceRect.x; + srcRect.y = sourceRect.y; + srcRect.w = sourceRect.w; + srcRect.h = sourceRect.h; + + SDL_Rect dstRect; + dstRect.x = dstRect.y = 0; + dstRect.w = blitTemp->w; + dstRect.h = blitTemp->h; + + // FXIME: This is supposed to be a scaled blit, put SDL2 for some reason + // makes the source surface unusable after BlitScaled() is called. Investigate! + SDL_BlitSurface(srcSurf, &srcRect, blitTemp, &dstRect); + + TEX::bind(p->tex.tex); + TEX::uploadSubImage(destRect.x, destRect.y, destRect.w, destRect.h, blitTemp->pixels, GL_RGBA); + + SDL_FreeSurface(blitTemp); + + modified(); return; } - else if (opacity == 255 && !p->touchesTaintedArea(destRect)) + + if (opacity == 255 && !p->touchesTaintedArea(destRect)) { /* Fast blit */ flush(); @@ -746,12 +784,12 @@ TEXFBO &Bitmap::getGLTypes() return p->tex; } -SDL_Surface *Bitmap::megaSurface() +SDL_Surface *Bitmap::megaSurface() const { return p->megaSurface; } -void Bitmap::ensureNonMega() +void Bitmap::ensureNonMega() const { if (isDisposed()) return; diff --git a/src/bitmap.h b/src/bitmap.h index 198d6b9..91de0ec 100644 --- a/src/bitmap.h +++ b/src/bitmap.h @@ -105,8 +105,8 @@ public: /* */ void flush() const; TEXFBO &getGLTypes(); - SDL_Surface *megaSurface(); - void ensureNonMega(); + SDL_Surface *megaSurface() const; + void ensureNonMega() const; /* Binds the backing texture and sets the correct * texture size uniform in shader */