From c9f8bba932022ffd90031713c51861587f86b244 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 28 Dec 2013 23:06:17 +0300 Subject: Add cached draw methods into renderers. --- src/render/sdl2graphics.cpp | 83 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) (limited to 'src/render/sdl2graphics.cpp') diff --git a/src/render/sdl2graphics.cpp b/src/render/sdl2graphics.cpp index 6426506ee..00452d9c6 100644 --- a/src/render/sdl2graphics.cpp +++ b/src/render/sdl2graphics.cpp @@ -149,6 +149,89 @@ bool SDLGraphics::drawImage2(const Image *const image, int srcX, int srcY, return !MSDL_RenderCopy(mRenderer, image->mTexture, &srcRect, &dstRect); } +void SDLGraphics::drawImageCached(const Image *const image, + int x, int y) +{ + FUNC_BLOCK("Graphics::drawImageCached", 1) + // Check that preconditions for blitting are met. + if (!mWindow || !image || !image->mTexture) + return; + + const gcn::ClipRectangle &top = mClipStack.top(); + if (!top.width || !top.height) + return; + + const SDL_Rect &bounds = image->mBounds; + const SDL_Rect srcRect = + { + static_cast(bounds.x), + static_cast(bounds.y), + static_cast(bounds.w), + static_cast(bounds.h) + }; + + const SDL_Rect dstRect = + { + static_cast(x + top.xOffset), + static_cast(y + top.yOffset), + static_cast(bounds.w), + static_cast(bounds.h) + }; + + MSDL_RenderCopy(mRenderer, image->mTexture, &srcRect, &dstRect); +} + +void SDLGraphics::drawPatternCached(const Image *const image, + const int x, const int y, + const int w, const int h) +{ + FUNC_BLOCK("Graphics::drawPatternCached", 1) + // Check that preconditions for blitting are met. + if (!mWindow || !image) + return; + if (!image->mTexture) + return; + + const gcn::ClipRectangle &top = mClipStack.top(); + if (!top.width || !top.height) + return; + + const SDL_Rect &bounds = image->mBounds; + const int iw = bounds.w; + const int ih = bounds.h; + if (iw == 0 || ih == 0) + return; + + const int xOffset = top.xOffset + x; + const int yOffset = top.yOffset + y; + + SDL_Rect dstRect; + SDL_Rect srcRect; + srcRect.x = static_cast(bounds.x); + srcRect.y = static_cast(bounds.y); + for (int py = 0; py < h; py += ih) + { + const int dh = (py + ih >= h) ? h - py : ih; + dstRect.y = static_cast(py + yOffset); + srcRect.h = static_cast(dh); + dstRect.h = static_cast(dh); + + for (int px = 0; px < w; px += iw) + { + const int dw = (px + iw >= w) ? w - px : iw; + dstRect.x = static_cast(px + xOffset); + srcRect.w = static_cast(dw); + dstRect.w = static_cast(dw); + + MSDL_RenderCopy(mRenderer, image->mTexture, &srcRect, &dstRect); + } + } +} + +void SDLGraphics::completeCache() +{ +} + void SDLGraphics::drawPattern(const Image *const image, const int x, const int y, const int w, const int h) -- cgit v1.2.3-60-g2f50