diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-12-29 21:22:33 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-12-29 21:22:33 +0300 |
commit | f94a6551b8d140e272ac1c46bce1ff0e5df34986 (patch) | |
tree | 35c764dfec7b76f926c30cd186b6fe36968b6529 /src/render | |
parent | 0336b91f51cdf14e022f74d16c15892b63b658eb (diff) | |
download | mv-f94a6551b8d140e272ac1c46bce1ff0e5df34986.tar.gz mv-f94a6551b8d140e272ac1c46bce1ff0e5df34986.tar.bz2 mv-f94a6551b8d140e272ac1c46bce1ff0e5df34986.tar.xz mv-f94a6551b8d140e272ac1c46bce1ff0e5df34986.zip |
improve draw image calls.
Diffstat (limited to 'src/render')
-rw-r--r-- | src/render/graphics.cpp | 8 | ||||
-rw-r--r-- | src/render/graphics.h | 14 | ||||
-rw-r--r-- | src/render/mobileopenglgraphics.cpp | 22 | ||||
-rw-r--r-- | src/render/mobileopenglgraphics.h | 5 | ||||
-rw-r--r-- | src/render/normalopenglgraphics.cpp | 21 | ||||
-rw-r--r-- | src/render/normalopenglgraphics.h | 5 | ||||
-rw-r--r-- | src/render/nullopenglgraphics.cpp | 23 | ||||
-rw-r--r-- | src/render/nullopenglgraphics.h | 5 | ||||
-rw-r--r-- | src/render/safeopenglgraphics.cpp | 20 | ||||
-rw-r--r-- | src/render/safeopenglgraphics.h | 5 | ||||
-rw-r--r-- | src/render/sdl2graphics.cpp | 17 | ||||
-rw-r--r-- | src/render/sdl2graphics.h | 5 | ||||
-rw-r--r-- | src/render/sdl2softwaregraphics.cpp | 17 | ||||
-rw-r--r-- | src/render/sdl2softwaregraphics.h | 5 | ||||
-rw-r--r-- | src/render/sdlgraphics.cpp | 17 | ||||
-rw-r--r-- | src/render/sdlgraphics.h | 5 | ||||
-rw-r--r-- | src/render/surfacegraphics.cpp | 18 | ||||
-rw-r--r-- | src/render/surfacegraphics.h | 5 |
18 files changed, 67 insertions, 150 deletions
diff --git a/src/render/graphics.cpp b/src/render/graphics.cpp index 9072c0a29..cd2332d19 100644 --- a/src/render/graphics.cpp +++ b/src/render/graphics.cpp @@ -482,17 +482,17 @@ void Graphics::drawImageRect(const int x, const int y, // Draw the corners if (drawMain) { - DRAW_IMAGE(this, topLeft, x, y); + drawImage2(topLeft, x, y); const int trw = topRight->getWidth(); if (w > trw) { - DRAW_IMAGE(this, topRight, x + w - trw, y); + drawImage2(topRight, x + w - trw, y); } - DRAW_IMAGE(this, bottomLeft, x, h - bottomLeft->getHeight() + y); + drawImage2(bottomLeft, x, h - bottomLeft->getHeight() + y); const int brw = bottomRight->getWidth(); if (w > brw) { - DRAW_IMAGE(this, bottomRight, + drawImage2(bottomRight, x + w - brw, y + h - bottomRight->getHeight()); } diff --git a/src/render/graphics.h b/src/render/graphics.h index 82bf220ab..a0c0c64eb 100644 --- a/src/render/graphics.h +++ b/src/render/graphics.h @@ -47,15 +47,6 @@ struct SDL_Window; static const int defaultScreenWidth = 800; static const int defaultScreenHeight = 600; -#define DRAW_IMAGE(graphics, image, x, y) \ - { \ - if (image) \ - { \ - (graphics)->drawImage2(image, 0, 0, x, y, \ - (image)->mBounds.w, (image)->mBounds.h, false); \ - } \ - } - /** * 9 images defining a rectangle. 4 corners, 4 sides and a middle area. The * topology is as follows: @@ -380,10 +371,7 @@ class Graphics : public gcn::Graphics * <code>false</code> otherwise. */ virtual bool drawImage2(const Image *const image, - int srcX, int srcY, - int dstX, int dstY, - const int width, const int height, - const bool useColor) = 0; + int dstX, int dstY) = 0; virtual void drawImageCached(const Image *const image, int srcX, int srcY) = 0; diff --git a/src/render/mobileopenglgraphics.cpp b/src/render/mobileopenglgraphics.cpp index dc3341fd2..8a1f47bef 100644 --- a/src/render/mobileopenglgraphics.cpp +++ b/src/render/mobileopenglgraphics.cpp @@ -218,29 +218,22 @@ static inline void drawRescaledQuad(const Image *const image, bool MobileOpenGLGraphics::drawImage2(const Image *const image, - int srcX, int srcY, - int dstX, int dstY, - const int width, const int height, - const bool useColor) + int dstX, int dstY) { FUNC_BLOCK("Graphics::drawImage2", 1) if (!image) return false; - const SDL_Rect &imageRect = image->mBounds; - - if (!useColor) - setColorAlpha(image->mAlpha); - + setColorAlpha(image->mAlpha); #ifdef DEBUG_BIND_TEXTURE debugBindTexture(image); #endif bindTexture(OpenGLImageHelper::mTextureType, image->mGLImage); - setTexturingAndBlending(true); - drawQuad(image, srcX + imageRect.x, srcY + imageRect.y, - dstX, dstY, width, height); + const SDL_Rect &imageRect = image->mBounds; + drawQuad(image, imageRect.x, imageRect.y, + dstX, dstY, imageRect.w, imageRect.h); return true; } @@ -407,10 +400,7 @@ bool MobileOpenGLGraphics::drawRescaledImage(const Image *const image, // Just draw the image normally when no resizing is necessary, if (width == desiredWidth && height == desiredHeight) - { - return drawImage2(image, srcX, srcY, dstX, dstY, - width, height, useColor); - } + return drawImage2(image, dstX, dstY); // When the desired image is smaller than the current one, // disable smooth effect. diff --git a/src/render/mobileopenglgraphics.h b/src/render/mobileopenglgraphics.h index 447415823..74b4aa458 100644 --- a/src/render/mobileopenglgraphics.h +++ b/src/render/mobileopenglgraphics.h @@ -190,10 +190,7 @@ class MobileOpenGLGraphics final : public Graphics void updateTextureFormat(); bool drawImage2(const Image *const image, - int srcX, int srcY, - int dstX, int dstY, - const int width, const int height, - const bool useColor) override final; + int dstX, int dstY) override final; void drawImageCached(const Image *const image, int x, int y) override final; diff --git a/src/render/normalopenglgraphics.cpp b/src/render/normalopenglgraphics.cpp index 0f7cc966b..28572f9ba 100644 --- a/src/render/normalopenglgraphics.cpp +++ b/src/render/normalopenglgraphics.cpp @@ -285,29 +285,23 @@ static inline void drawRescaledQuad(const Image *const image, bool NormalOpenGLGraphics::drawImage2(const Image *const image, - int srcX, int srcY, - int dstX, int dstY, - const int width, const int height, - const bool useColor) + int dstX, int dstY) { FUNC_BLOCK("Graphics::drawImage2", 1) if (!image) return false; - const SDL_Rect &imageRect = image->mBounds; - - if (!useColor) - setColorAlpha(image->mAlpha); + setColorAlpha(image->mAlpha); #ifdef DEBUG_BIND_TEXTURE debugBindTexture(image); #endif bindTexture(OpenGLImageHelper::mTextureType, image->mGLImage); - setTexturingAndBlending(true); - drawQuad(image, srcX + imageRect.x, srcY + imageRect.y, - dstX, dstY, width, height); + const SDL_Rect &imageRect = image->mBounds; + drawQuad(image, imageRect.x, imageRect.y, + dstX, dstY, imageRect.w, imageRect.h); return true; } @@ -520,10 +514,7 @@ bool NormalOpenGLGraphics::drawRescaledImage(const Image *const image, // Just draw the image normally when no resizing is necessary, if (width == desiredWidth && height == desiredHeight) - { - return drawImage2(image, srcX, srcY, dstX, dstY, - width, height, useColor); - } + return drawImage2(image, dstX, dstY); // When the desired image is smaller than the current one, // disable smooth effect. diff --git a/src/render/normalopenglgraphics.h b/src/render/normalopenglgraphics.h index 73457ef0d..27e6120b4 100644 --- a/src/render/normalopenglgraphics.h +++ b/src/render/normalopenglgraphics.h @@ -199,10 +199,7 @@ class NormalOpenGLGraphics final : public Graphics void updateTextureFormat(); bool drawImage2(const Image *const image, - int srcX, int srcY, - int dstX, int dstY, - const int width, const int height, - const bool useColor) override final; + int dstX, int dstY) override final; void drawImageCached(const Image *const image, int x, int y) override final; diff --git a/src/render/nullopenglgraphics.cpp b/src/render/nullopenglgraphics.cpp index ab1291233..9e0b49aeb 100644 --- a/src/render/nullopenglgraphics.cpp +++ b/src/render/nullopenglgraphics.cpp @@ -138,30 +138,22 @@ static inline void drawRescaledQuad(const Image *const image A_UNUSED, bool NullOpenGLGraphics::drawImage2(const Image *const image, - int srcX, int srcY, - int dstX, int dstY, - const int width, const int height, - const bool useColor) + int dstX, int dstY) { FUNC_BLOCK("Graphics::drawImage2", 1) if (!image) return false; - const SDL_Rect &imageRect = image->mBounds; - srcX += imageRect.x; - srcY += imageRect.y; - - if (!useColor) - setColorAlpha(image->mAlpha); - + setColorAlpha(image->mAlpha); #ifdef DEBUG_BIND_TEXTURE debugBindTexture(image); #endif bindTexture(OpenGLImageHelper::mTextureType, image->mGLImage); - setTexturingAndBlending(true); - drawQuad(image, srcX, srcY, dstX, dstY, width, height); + const SDL_Rect &imageRect = image->mBounds; + drawQuad(image, imageRect.x, imageRect.y, dstX, dstY, + imageRect.w, imageRect.h); return true; } @@ -211,10 +203,7 @@ bool NullOpenGLGraphics::drawRescaledImage(const Image *const image, // Just draw the image normally when no resizing is necessary, if (width == desiredWidth && height == desiredHeight) - { - return drawImage2(image, srcX, srcY, dstX, dstY, - width, height, useColor); - } + return drawImage2(image, dstX, dstY); // When the desired image is smaller than the current one, // disable smooth effect. diff --git a/src/render/nullopenglgraphics.h b/src/render/nullopenglgraphics.h index 7b15cfbf5..abb2f836f 100644 --- a/src/render/nullopenglgraphics.h +++ b/src/render/nullopenglgraphics.h @@ -195,10 +195,7 @@ class NullOpenGLGraphics final : public Graphics void updateTextureFormat(); bool drawImage2(const Image *const image, - int srcX, int srcY, - int dstX, int dstY, - const int width, const int height, - const bool useColor) override final; + int dstX, int dstY) override final; void drawImageCached(const Image *const image, int x, int y) override final; diff --git a/src/render/safeopenglgraphics.cpp b/src/render/safeopenglgraphics.cpp index 1170f0300..614c4158c 100644 --- a/src/render/safeopenglgraphics.cpp +++ b/src/render/safeopenglgraphics.cpp @@ -140,26 +140,21 @@ static inline void drawRescaledQuad(const Image *const image, bool SafeOpenGLGraphics::drawImage2(const Image *const image, - int srcX, int srcY, - int dstX, int dstY, - const int width, const int height, - const bool useColor) + int dstX, int dstY) { FUNC_BLOCK("Graphics::drawImage2", 1) if (!image) return false; - if (!useColor) - setColorAlpha(image->mAlpha); - + setColorAlpha(image->mAlpha); bindTexture(OpenGLImageHelper::mTextureType, image->mGLImage); - setTexturingAndBlending(true); + const SDL_Rect &bounds = image->mBounds; // Draw a textured quad. glBegin(GL_QUADS); - drawQuad(image, srcX + image->mBounds.x, srcY + image->mBounds.y, - dstX, dstY, width, height); + drawQuad(image, bounds.x, bounds.y, + dstX, dstY, bounds.w, bounds.h); glEnd(); return true; @@ -254,10 +249,7 @@ bool SafeOpenGLGraphics::drawRescaledImage(const Image *const image, int srcX, // Just draw the image normally when no resizing is necessary, if (width == desiredWidth && height == desiredHeight) - { - return drawImage2(image, srcX, srcY, dstX, dstY, - width, height, useColor); - } + return drawImage2(image, dstX, dstY); // When the desired image is smaller than the current one, // disable smooth effect. diff --git a/src/render/safeopenglgraphics.h b/src/render/safeopenglgraphics.h index dac61cb47..2fdc3b3f2 100644 --- a/src/render/safeopenglgraphics.h +++ b/src/render/safeopenglgraphics.h @@ -158,10 +158,7 @@ class SafeOpenGLGraphics final : public Graphics void prepareScreenshot() override final; bool drawImage2(const Image *const image, - int srcX, int srcY, - int dstX, int dstY, - const int width, const int height, - const bool useColor) override final; + int dstX, int dstY) override final; void drawImageCached(const Image *const image, int x, int y) override final; diff --git a/src/render/sdl2graphics.cpp b/src/render/sdl2graphics.cpp index 00452d9c6..d9844ee6d 100644 --- a/src/render/sdl2graphics.cpp +++ b/src/render/sdl2graphics.cpp @@ -116,9 +116,8 @@ bool SDLGraphics::drawRescaledImage(const Image *const image, &srcRect, &dstRect) < 0); } -bool SDLGraphics::drawImage2(const Image *const image, int srcX, int srcY, - int dstX, int dstY, const int width, - const int height, const bool useColor A_UNUSED) +bool SDLGraphics::drawImage2(const Image *const image, + int dstX, int dstY) { FUNC_BLOCK("Graphics::drawImage2", 1) // Check that preconditions for blitting are met. @@ -132,18 +131,18 @@ bool SDLGraphics::drawImage2(const Image *const image, int srcX, int srcY, const SDL_Rect &bounds = image->mBounds; const SDL_Rect srcRect = { - static_cast<int32_t>(srcX + bounds.x), - static_cast<int32_t>(srcY + bounds.y), - static_cast<int32_t>(width), - static_cast<int32_t>(height) + static_cast<int32_t>(bounds.x), + static_cast<int32_t>(bounds.y), + static_cast<int32_t>(bounds.w), + static_cast<int32_t>(bounds.h) }; const SDL_Rect dstRect = { static_cast<int32_t>(dstX + top.xOffset), static_cast<int32_t>(dstY + top.yOffset), - static_cast<int32_t>(width), - static_cast<int32_t>(height) + static_cast<int32_t>(bounds.w), + static_cast<int32_t>(bounds.h) }; return !MSDL_RenderCopy(mRenderer, image->mTexture, &srcRect, &dstRect); diff --git a/src/render/sdl2graphics.h b/src/render/sdl2graphics.h index f1960d358..9ab56afe7 100644 --- a/src/render/sdl2graphics.h +++ b/src/render/sdl2graphics.h @@ -137,10 +137,7 @@ class SDLGraphics final : public Graphics { mRendererFlags = flags; } bool drawImage2(const Image *const image, - int srcX, int srcY, - int dstX, int dstY, - const int width, const int height, - const bool useColor) override final; + int dstX, int dstY) override final; void drawImageCached(const Image *const image, int x, int y) override final; diff --git a/src/render/sdl2softwaregraphics.cpp b/src/render/sdl2softwaregraphics.cpp index b0d76bd57..fa92f6030 100644 --- a/src/render/sdl2softwaregraphics.cpp +++ b/src/render/sdl2softwaregraphics.cpp @@ -112,10 +112,7 @@ bool SDL2SoftwareGraphics::drawRescaledImage(const Image *const image, } bool SDL2SoftwareGraphics::drawImage2(const Image *const image, - int srcX, int srcY, - int dstX, int dstY, const int width, - const int height, - const bool useColor A_UNUSED) + int dstX, int dstY) { FUNC_BLOCK("Graphics::drawImage2", 1) // Check that preconditions for blitting are met. @@ -127,13 +124,13 @@ bool SDL2SoftwareGraphics::drawImage2(const Image *const image, SDL_Surface *const src = image->mSDLSurface; - srcX += bounds.x; - srcY += bounds.y; + int srcX = bounds.x; + int srcY = bounds.y; dstX += top.xOffset; dstY += top.yOffset; - int w = width; - int h = height; + int w = bounds.w; + int h = bounds.h; if (srcX < 0) { w += srcX; @@ -183,8 +180,8 @@ bool SDL2SoftwareGraphics::drawImage2(const Image *const image, { SDL_Rect srcRect = { - static_cast<int16_t>(srcX), - static_cast<int16_t>(srcY), + static_cast<int16_t>(0), + static_cast<int16_t>(0), static_cast<uint16_t>(w), static_cast<uint16_t>(h) }; diff --git a/src/render/sdl2softwaregraphics.h b/src/render/sdl2softwaregraphics.h index ab9fb7ce4..718088972 100644 --- a/src/render/sdl2softwaregraphics.h +++ b/src/render/sdl2softwaregraphics.h @@ -140,10 +140,7 @@ class SDL2SoftwareGraphics final : public Graphics bool resizeScreen(const int width, const int height) override final; bool drawImage2(const Image *const image, - int srcX, int srcY, - int dstX, int dstY, - const int width, const int height, - const bool useColor) override final; + int dstX, int dstY) override final; void drawImageCached(const Image *const image, int x, int y) override final; diff --git a/src/render/sdlgraphics.cpp b/src/render/sdlgraphics.cpp index c46b65000..ef1f2d2a5 100644 --- a/src/render/sdlgraphics.cpp +++ b/src/render/sdlgraphics.cpp @@ -104,9 +104,8 @@ bool SDLGraphics::drawRescaledImage(const Image *const image, return returnValue; } -bool SDLGraphics::drawImage2(const Image *const image, int srcX, int srcY, - int dstX, int dstY, const int width, - const int height, const bool useColor A_UNUSED) +bool SDLGraphics::drawImage2(const Image *const image, + int dstX, int dstY) { FUNC_BLOCK("Graphics::drawImage2", 1) // Check that preconditions for blitting are met. @@ -118,13 +117,13 @@ bool SDLGraphics::drawImage2(const Image *const image, int srcX, int srcY, SDL_Surface *const src = image->mSDLSurface; - srcX += bounds.x; - srcY += bounds.y; + int srcX = bounds.x; + int srcY = bounds.y; dstX += top.xOffset; dstY += top.yOffset; - int w = width; - int h = height; + int w = bounds.w; + int h = bounds.h; if (srcX < 0) { w += srcX; @@ -174,8 +173,8 @@ bool SDLGraphics::drawImage2(const Image *const image, int srcX, int srcY, { SDL_Rect srcRect = { - static_cast<int16_t>(srcX), - static_cast<int16_t>(srcY), + static_cast<int16_t>(0), + static_cast<int16_t>(0), static_cast<uint16_t>(w), static_cast<uint16_t>(h) }; diff --git a/src/render/sdlgraphics.h b/src/render/sdlgraphics.h index aa7a250f8..2c1847751 100644 --- a/src/render/sdlgraphics.h +++ b/src/render/sdlgraphics.h @@ -134,10 +134,7 @@ class SDLGraphics final : public Graphics const bool noFrame) override final; bool drawImage2(const Image *const image, - int srcX, int srcY, - int dstX, int dstY, - const int width, const int height, - const bool useColor) override final; + int dstX, int dstY) override final; void drawImageCached(const Image *const image, int x, int y) override final; diff --git a/src/render/surfacegraphics.cpp b/src/render/surfacegraphics.cpp index db2722164..fe2926473 100644 --- a/src/render/surfacegraphics.cpp +++ b/src/render/surfacegraphics.cpp @@ -42,27 +42,23 @@ SurfaceGraphics::~SurfaceGraphics() { } -bool SurfaceGraphics::drawImage2(const Image *const image, int srcX, int srcY, - int dstX, int dstY, - const int width, const int height, - const bool useColor A_UNUSED) +bool SurfaceGraphics::drawImage2(const Image *const image, + int dstX, int dstY) { FUNC_BLOCK("Graphics::drawImage2", 1) // Check that preconditions for blitting are met. if (!mTarget || !image || !image->mSDLSurface) return false; - srcX += image->mBounds.x; - srcY += image->mBounds.y; - + const SDL_Rect &imageRect = image->mBounds; SDL_Rect dstRect; SDL_Rect srcRect; dstRect.x = static_cast<int16_t>(dstX); dstRect.y = static_cast<int16_t>(dstY); - srcRect.x = static_cast<int16_t>(srcX); - srcRect.y = static_cast<int16_t>(srcY); - srcRect.w = static_cast<uint16_t>(width); - srcRect.h = static_cast<uint16_t>(height); + srcRect.x = static_cast<int16_t>(imageRect.x); + srcRect.y = static_cast<int16_t>(imageRect.y); + srcRect.w = static_cast<uint16_t>(imageRect.w); + srcRect.h = static_cast<uint16_t>(imageRect.h); #ifdef USE_SDL2 return !(SDL_BlitSurface(image->mSDLSurface, &srcRect, diff --git a/src/render/surfacegraphics.h b/src/render/surfacegraphics.h index 6a2a7f3cb..b606d0ddf 100644 --- a/src/render/surfacegraphics.h +++ b/src/render/surfacegraphics.h @@ -183,10 +183,7 @@ class SurfaceGraphics final : public Graphics { return false; } bool drawImage2(const Image *const image, - int srcX, int srcY, - int dstX, int dstY, - const int width, const int height, - const bool useColor) override final; + int dstX, int dstY) override final; void drawImageCached(const Image *const image, int x, int y) override final; |