summaryrefslogtreecommitdiff
path: root/src/graphics.cpp
diff options
context:
space:
mode:
authorIra Rice <irarice@gmail.com>2009-03-16 22:45:49 -0600
committerIra Rice <irarice@gmail.com>2009-03-16 22:45:49 -0600
commita1eb62126bae54557e03682cac70c8331e359e01 (patch)
tree74e06ee9079e492a14d6e75290460ffc6e4feb47 /src/graphics.cpp
parentd654758ef63f6515d678ceaf77d63a2693e08fb7 (diff)
downloadmana-a1eb62126bae54557e03682cac70c8331e359e01.tar.gz
mana-a1eb62126bae54557e03682cac70c8331e359e01.tar.bz2
mana-a1eb62126bae54557e03682cac70c8331e359e01.tar.xz
mana-a1eb62126bae54557e03682cac70c8331e359e01.zip
Applied a similar optimization as in commit
d654758ef63f6515d678ceaf77d63a2693e08fb7, but for SDL instead. This currently doesn't buy too much, but it's a little better than it used to be. TODO: Find out why SDL is bottlenecked, and try to bring its performance up to OpenGL levels, if possible. Signed-off-by: Ira Rice <irarice@gmail.com>
Diffstat (limited to 'src/graphics.cpp')
-rw-r--r--src/graphics.cpp34
1 files changed, 22 insertions, 12 deletions
diff --git a/src/graphics.cpp b/src/graphics.cpp
index 48fd1340..ca86f536 100644
--- a/src/graphics.cpp
+++ b/src/graphics.cpp
@@ -154,24 +154,34 @@ void Graphics::drawImage(gcn::Image const *image, int srcX, int srcY,
void Graphics::drawImagePattern(Image *image, int x, int y, int w, int h)
{
- int iw = image->getWidth();
- int ih = image->getHeight();
- if (iw == 0 || ih == 0) return;
+ // Check that preconditions for blitting are met.
+ if (!mScreen || !image || !image->mImage) return;
- int px = 0; // X position on pattern plane
- int py = 0; // Y position on pattern plane
+ const int iw = image->getWidth();
+ const int ih = image->getHeight();
+
+ if (iw == 0 || ih == 0) return;
- while (py < h)
+ for (int py = 0; py < h; py += ih) // Y position on pattern plane
{
- while (px < w)
+ int dh = (py + ih >= h) ? h - py : ih;
+ int srcY = image->mBounds.y;
+ int dstY = y + py + mClipStack.top().yOffset;
+
+ for (int px = 0; px < w; px += iw) // X position on pattern plane
{
int dw = (px + iw >= w) ? w - px : iw;
- int dh = (py + ih >= h) ? h - py : ih;
- drawImage(image, 0, 0, x + px, y + py, dw, dh);
- px += iw;
+ int srcX = image->mBounds.x;
+ int dstX = x + px + mClipStack.top().xOffset;
+
+ SDL_Rect dstRect;
+ SDL_Rect srcRect;
+ dstRect.x = dstX; dstRect.y = dstY;
+ srcRect.x = srcX; srcRect.y = srcY;
+ srcRect.w = dw; srcRect.h = dh;
+
+ SDL_BlitSurface(image->mImage, &srcRect, mScreen, &dstRect);
}
- py += ih;
- px = 0;
}
}