diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-12-30 14:17:37 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-12-30 14:17:37 +0300 |
commit | 31fcdb31fb406531bec49ee2d1b3cc286ed3b5a8 (patch) | |
tree | b7f2a06054bacc8208d8fb429fc811ed199b4453 /src/render | |
parent | 74f89c500d278b6ac668c313b63d0f1e76f4acaf (diff) | |
download | ManaVerse-31fcdb31fb406531bec49ee2d1b3cc286ed3b5a8.tar.gz ManaVerse-31fcdb31fb406531bec49ee2d1b3cc286ed3b5a8.tar.bz2 ManaVerse-31fcdb31fb406531bec49ee2d1b3cc286ed3b5a8.tar.xz ManaVerse-31fcdb31fb406531bec49ee2d1b3cc286ed3b5a8.zip |
Improve drawRescaledImage in renderers.
Diffstat (limited to 'src/render')
-rw-r--r-- | src/render/graphics.h | 8 | ||||
-rw-r--r-- | src/render/mobileopenglgraphics.cpp | 57 | ||||
-rw-r--r-- | src/render/mobileopenglgraphics.h | 16 | ||||
-rw-r--r-- | src/render/normalopenglgraphics.cpp | 57 | ||||
-rw-r--r-- | src/render/normalopenglgraphics.h | 16 | ||||
-rw-r--r-- | src/render/nullopenglgraphics.cpp | 57 | ||||
-rw-r--r-- | src/render/nullopenglgraphics.h | 16 | ||||
-rw-r--r-- | src/render/safeopenglgraphics.cpp | 59 | ||||
-rw-r--r-- | src/render/safeopenglgraphics.h | 16 | ||||
-rw-r--r-- | src/render/sdl2graphics.cpp | 13 | ||||
-rw-r--r-- | src/render/sdl2graphics.h | 8 | ||||
-rw-r--r-- | src/render/sdl2softwaregraphics.cpp | 13 | ||||
-rw-r--r-- | src/render/sdl2softwaregraphics.h | 5 | ||||
-rw-r--r-- | src/render/sdlgraphics.cpp | 13 | ||||
-rw-r--r-- | src/render/sdlgraphics.h | 8 | ||||
-rw-r--r-- | src/render/surfacegraphics.h | 6 |
16 files changed, 68 insertions, 300 deletions
diff --git a/src/render/graphics.h b/src/render/graphics.h index a0c0c64eb..e1d4f1ec4 100644 --- a/src/render/graphics.h +++ b/src/render/graphics.h @@ -152,12 +152,10 @@ class Graphics : public gcn::Graphics /** * Draws a resclaled version of the image */ - virtual bool drawRescaledImage(const Image *const image, int srcX, - int srcY, int dstX, int dstY, - const int width, const int height, + virtual bool drawRescaledImage(const Image *const image, + int dstX, int dstY, const int desiredWidth, - const int desiredHeight, - const bool useColor = false) = 0; + const int desiredHeight) = 0; virtual void drawPattern(const Image *const image, const int x, const int y, diff --git a/src/render/mobileopenglgraphics.cpp b/src/render/mobileopenglgraphics.cpp index 202d03a37..bec9c221c 100644 --- a/src/render/mobileopenglgraphics.cpp +++ b/src/render/mobileopenglgraphics.cpp @@ -371,73 +371,30 @@ void MobileOpenGLGraphics::completeCache() } bool MobileOpenGLGraphics::drawRescaledImage(const Image *const image, - int srcX, int srcY, int dstX, int dstY, - const int width, const int height, const int desiredWidth, - const int desiredHeight, - const bool useColor) -{ - return drawRescaledImage(image, srcX, srcY, - dstX, dstY, - width, height, - desiredWidth, desiredHeight, - useColor, true); -} - -bool MobileOpenGLGraphics::drawRescaledImage(const Image *const image, - int srcX, int srcY, - int dstX, int dstY, - const int width, const int height, - const int desiredWidth, - const int desiredHeight, - const bool useColor, - bool smooth) + const int desiredHeight) { FUNC_BLOCK("Graphics::drawRescaledImage", 1) if (!image) return false; - // Just draw the image normally when no resizing is necessary, - if (width == desiredWidth && height == desiredHeight) - return drawImage2(image, dstX, dstY); - - // When the desired image is smaller than the current one, - // disable smooth effect. - if (width > desiredWidth && height > desiredHeight) - smooth = false; - const SDL_Rect &imageRect = image->mBounds; - srcX += imageRect.x; - srcY += imageRect.y; - if (!useColor) - setColorAlpha(image->mAlpha); + // Just draw the image normally when no resizing is necessary, + if (imageRect.w == desiredWidth && imageRect.h == desiredHeight) + return drawImage2(image, dstX, dstY); + setColorAlpha(image->mAlpha); #ifdef DEBUG_BIND_TEXTURE debugBindTexture(image); #endif bindTexture(OpenGLImageHelper::mTextureType, image->mGLImage); - setTexturingAndBlending(true); // Draw a textured quad. - drawRescaledQuad(image, srcX, srcY, dstX, dstY, width, height, - desiredWidth, desiredHeight); - - if (smooth) // A basic smooth effect... - { - setColorAlpha(0.2F); - drawRescaledQuad(image, srcX, srcY, dstX - 1, dstY - 1, width, height, - desiredWidth + 1, desiredHeight + 1); - drawRescaledQuad(image, srcX, srcY, dstX + 1, dstY + 1, width, height, - desiredWidth - 1, desiredHeight - 1); - - drawRescaledQuad(image, srcX, srcY, dstX + 1, dstY, width, height, - desiredWidth - 1, desiredHeight); - drawRescaledQuad(image, srcX, srcY, dstX, dstY + 1, width, height, - desiredWidth, desiredHeight - 1); - } + drawRescaledQuad(image, imageRect.x, imageRect.y, dstX, dstY, + imageRect.w, imageRect.h, desiredWidth, desiredHeight); return true; } diff --git a/src/render/mobileopenglgraphics.h b/src/render/mobileopenglgraphics.h index 74b4aa458..6580ea74d 100644 --- a/src/render/mobileopenglgraphics.h +++ b/src/render/mobileopenglgraphics.h @@ -67,20 +67,10 @@ class MobileOpenGLGraphics final : public Graphics /** * Draws a resclaled version of the image */ - bool drawRescaledImage(const Image *const image, int srcX, int srcY, + bool drawRescaledImage(const Image *const image, int dstX, int dstY, - const int width, const int height, - const int desiredWidth, const int desiredHeight, - const bool useColor) override final; - - /** - * Used to get the smooth rescale option over the standard function. - */ - bool drawRescaledImage(const Image *const image, int srcX, int srcY, - int dstX, int dstY, - const int width, const int height, - const int desiredWidth, const int desiredHeight, - const bool useColor, bool smooth); + const int desiredWidth, + const int desiredHeight) override final; void drawPattern(const Image *const image, const int x, const int y, diff --git a/src/render/normalopenglgraphics.cpp b/src/render/normalopenglgraphics.cpp index 28572f9ba..ea1bd7242 100644 --- a/src/render/normalopenglgraphics.cpp +++ b/src/render/normalopenglgraphics.cpp @@ -485,73 +485,30 @@ void NormalOpenGLGraphics::completeCache() } bool NormalOpenGLGraphics::drawRescaledImage(const Image *const image, - int srcX, int srcY, int dstX, int dstY, - const int width, const int height, const int desiredWidth, - const int desiredHeight, - const bool useColor) -{ - return drawRescaledImage(image, srcX, srcY, - dstX, dstY, - width, height, - desiredWidth, desiredHeight, - useColor, true); -} - -bool NormalOpenGLGraphics::drawRescaledImage(const Image *const image, - int srcX, int srcY, - int dstX, int dstY, - const int width, const int height, - const int desiredWidth, - const int desiredHeight, - const bool useColor, - bool smooth) + const int desiredHeight) { FUNC_BLOCK("Graphics::drawRescaledImage", 1) if (!image) return false; - // Just draw the image normally when no resizing is necessary, - if (width == desiredWidth && height == desiredHeight) - return drawImage2(image, dstX, dstY); - - // When the desired image is smaller than the current one, - // disable smooth effect. - if (width > desiredWidth && height > desiredHeight) - smooth = false; - const SDL_Rect &imageRect = image->mBounds; - srcX += imageRect.x; - srcY += imageRect.y; - if (!useColor) - setColorAlpha(image->mAlpha); + // Just draw the image normally when no resizing is necessary, + if (imageRect.w == desiredWidth && imageRect.h == desiredHeight) + return drawImage2(image, dstX, dstY); + setColorAlpha(image->mAlpha); #ifdef DEBUG_BIND_TEXTURE debugBindTexture(image); #endif bindTexture(OpenGLImageHelper::mTextureType, image->mGLImage); - setTexturingAndBlending(true); // Draw a textured quad. - drawRescaledQuad(image, srcX, srcY, dstX, dstY, width, height, - desiredWidth, desiredHeight); - - if (smooth) // A basic smooth effect... - { - setColorAlpha(0.2F); - drawRescaledQuad(image, srcX, srcY, dstX - 1, dstY - 1, width, height, - desiredWidth + 1, desiredHeight + 1); - drawRescaledQuad(image, srcX, srcY, dstX + 1, dstY + 1, width, height, - desiredWidth - 1, desiredHeight - 1); - - drawRescaledQuad(image, srcX, srcY, dstX + 1, dstY, width, height, - desiredWidth - 1, desiredHeight); - drawRescaledQuad(image, srcX, srcY, dstX, dstY + 1, width, height, - desiredWidth, desiredHeight - 1); - } + drawRescaledQuad(image, imageRect.x, imageRect.y, dstX, dstY, + imageRect.w, imageRect.h, desiredWidth, desiredHeight); return true; } diff --git a/src/render/normalopenglgraphics.h b/src/render/normalopenglgraphics.h index 27e6120b4..13546b805 100644 --- a/src/render/normalopenglgraphics.h +++ b/src/render/normalopenglgraphics.h @@ -67,20 +67,10 @@ class NormalOpenGLGraphics final : public Graphics /** * Draws a resclaled version of the image */ - bool drawRescaledImage(const Image *const image, int srcX, int srcY, + bool drawRescaledImage(const Image *const image, int dstX, int dstY, - const int width, const int height, - const int desiredWidth, const int desiredHeight, - const bool useColor) override final; - - /** - * Used to get the smooth rescale option over the standard function. - */ - bool drawRescaledImage(const Image *const image, int srcX, int srcY, - int dstX, int dstY, - const int width, const int height, - const int desiredWidth, const int desiredHeight, - const bool useColor, bool smooth); + const int desiredWidth, + const int desiredHeight) override final; void drawPattern(const Image *const image, const int x, const int y, diff --git a/src/render/nullopenglgraphics.cpp b/src/render/nullopenglgraphics.cpp index 7cf4c2f34..3ad9b9e83 100644 --- a/src/render/nullopenglgraphics.cpp +++ b/src/render/nullopenglgraphics.cpp @@ -176,73 +176,30 @@ void NullOpenGLGraphics::completeCache() } bool NullOpenGLGraphics::drawRescaledImage(const Image *const image, - int srcX, int srcY, int dstX, int dstY, - const int width, const int height, const int desiredWidth, - const int desiredHeight, - const bool useColor) -{ - return drawRescaledImage(image, srcX, srcY, - dstX, dstY, - width, height, - desiredWidth, desiredHeight, - useColor, true); -} - -bool NullOpenGLGraphics::drawRescaledImage(const Image *const image, - int srcX, int srcY, - int dstX, int dstY, - const int width, const int height, - const int desiredWidth, - const int desiredHeight, - const bool useColor, - bool smooth) + const int desiredHeight) { FUNC_BLOCK("Graphics::drawRescaledImage", 1) if (!image) return false; - // Just draw the image normally when no resizing is necessary, - if (width == desiredWidth && height == desiredHeight) - return drawImage2(image, dstX, dstY); - - // When the desired image is smaller than the current one, - // disable smooth effect. - if (width > desiredWidth && height > desiredHeight) - smooth = false; - const SDL_Rect &imageRect = image->mBounds; - srcX += imageRect.x; - srcY += imageRect.y; - if (!useColor) - setColorAlpha(image->mAlpha); + // Just draw the image normally when no resizing is necessary, + if (imageRect.w == desiredWidth && imageRect.h == desiredHeight) + return drawImage2(image, dstX, dstY); + setColorAlpha(image->mAlpha); #ifdef DEBUG_BIND_TEXTURE debugBindTexture(image); #endif bindTexture(OpenGLImageHelper::mTextureType, image->mGLImage); - setTexturingAndBlending(true); // Draw a textured quad. - drawRescaledQuad(image, srcX, srcY, dstX, dstY, width, height, - desiredWidth, desiredHeight); - - if (smooth) // A basic smooth effect... - { - setColorAlpha(0.2F); - drawRescaledQuad(image, srcX, srcY, dstX - 1, dstY - 1, width, height, - desiredWidth + 1, desiredHeight + 1); - drawRescaledQuad(image, srcX, srcY, dstX + 1, dstY + 1, width, height, - desiredWidth - 1, desiredHeight - 1); - - drawRescaledQuad(image, srcX, srcY, dstX + 1, dstY, width, height, - desiredWidth - 1, desiredHeight); - drawRescaledQuad(image, srcX, srcY, dstX, dstY + 1, width, height, - desiredWidth, desiredHeight - 1); - } + drawRescaledQuad(image, imageRect.x, imageRect.y, dstX, dstY, + imageRect.w, imageRect.h, desiredWidth, desiredHeight); return true; } diff --git a/src/render/nullopenglgraphics.h b/src/render/nullopenglgraphics.h index abb2f836f..7508e65b3 100644 --- a/src/render/nullopenglgraphics.h +++ b/src/render/nullopenglgraphics.h @@ -67,20 +67,10 @@ class NullOpenGLGraphics final : public Graphics /** * Draws a resclaled version of the image */ - bool drawRescaledImage(const Image *const image, int srcX, int srcY, + bool drawRescaledImage(const Image *const image, int dstX, int dstY, - const int width, const int height, - const int desiredWidth, const int desiredHeight, - const bool useColor) override final; - - /** - * Used to get the smooth rescale option over the standard function. - */ - bool drawRescaledImage(const Image *const image, int srcX, int srcY, - int dstX, int dstY, - const int width, const int height, - const int desiredWidth, const int desiredHeight, - const bool useColor, bool smooth); + const int desiredWidth, + const int desiredHeight) override final; void drawPattern(const Image *const image, const int x, const int y, diff --git a/src/render/safeopenglgraphics.cpp b/src/render/safeopenglgraphics.cpp index 614c4158c..f92455e58 100644 --- a/src/render/safeopenglgraphics.cpp +++ b/src/render/safeopenglgraphics.cpp @@ -221,70 +221,29 @@ void SafeOpenGLGraphics::completeCache() { } -bool SafeOpenGLGraphics::drawRescaledImage(const Image *const image, int srcX, - int srcY, int dstX, int dstY, - const int width, const int height, +bool SafeOpenGLGraphics::drawRescaledImage(const Image *const image, + int dstX, int dstY, const int desiredWidth, - const int desiredHeight, - const bool useColor) -{ - return drawRescaledImage(image, srcX, srcY, - dstX, dstY, - width, height, - desiredWidth, desiredHeight, - useColor, true); -} - -bool SafeOpenGLGraphics::drawRescaledImage(const Image *const image, int srcX, - int srcY, int dstX, int dstY, - const int width, const int height, - const int desiredWidth, - const int desiredHeight, - const bool useColor, - bool smooth) + const int desiredHeight) { FUNC_BLOCK("Graphics::drawRescaledImage", 1) if (!image) return false; + const SDL_Rect &imageRect = image->mBounds; + // Just draw the image normally when no resizing is necessary, - if (width == desiredWidth && height == desiredHeight) + if (imageRect.w == desiredWidth && imageRect.h == desiredHeight) return drawImage2(image, dstX, dstY); - // When the desired image is smaller than the current one, - // disable smooth effect. - if (width > desiredWidth && height > desiredHeight) - smooth = false; - - srcX += image->mBounds.x; - srcY += image->mBounds.y; - - if (!useColor) - setColorAlpha(image->mAlpha); - + setColorAlpha(image->mAlpha); bindTexture(OpenGLImageHelper::mTextureType, image->mGLImage); - setTexturingAndBlending(true); // Draw a textured quad. glBegin(GL_QUADS); - drawRescaledQuad(image, srcX, srcY, dstX, dstY, width, height, - desiredWidth, desiredHeight); - - if (smooth) // A basic smooth effect... - { - setColorAlpha(0.2F); - drawRescaledQuad(image, srcX, srcY, dstX - 1, dstY - 1, width, height, - desiredWidth + 1, desiredHeight + 1); - drawRescaledQuad(image, srcX, srcY, dstX + 1, dstY + 1, width, height, - desiredWidth - 1, desiredHeight - 1); - - drawRescaledQuad(image, srcX, srcY, dstX + 1, dstY, width, height, - desiredWidth - 1, desiredHeight); - drawRescaledQuad(image, srcX, srcY, dstX, dstY + 1, width, height, - desiredWidth, desiredHeight - 1); - } - + drawRescaledQuad(image, imageRect.x, imageRect.y, dstX, dstY, + imageRect.w, imageRect.h, desiredWidth, desiredHeight); glEnd(); return true; diff --git a/src/render/safeopenglgraphics.h b/src/render/safeopenglgraphics.h index 2fdc3b3f2..0803e9948 100644 --- a/src/render/safeopenglgraphics.h +++ b/src/render/safeopenglgraphics.h @@ -60,20 +60,10 @@ class SafeOpenGLGraphics final : public Graphics /** * Draws a resclaled version of the image */ - bool drawRescaledImage(const Image *const image, int srcX, int srcY, + bool drawRescaledImage(const Image *const image, int dstX, int dstY, - const int width, const int height, - const int desiredWidth, const int desiredHeight, - const bool useColor) override final; - - /** - * Used to get the smooth rescale option over the standard function. - */ - bool drawRescaledImage(const Image *const image, int srcX, int srcY, - int dstX, int dstY, - const int width, const int height, - const int desiredWidth, const int desiredHeight, - const bool useColor, bool smooth); + const int desiredWidth, + const int desiredHeight) override final; void drawPattern(const Image *const image, const int x, const int y, diff --git a/src/render/sdl2graphics.cpp b/src/render/sdl2graphics.cpp index d9844ee6d..45f09f0f7 100644 --- a/src/render/sdl2graphics.cpp +++ b/src/render/sdl2graphics.cpp @@ -81,12 +81,9 @@ SDLGraphics::~SDLGraphics() } bool SDLGraphics::drawRescaledImage(const Image *const image, - int srcX, int srcY, int dstX, int dstY, - const int width, const int height, const int desiredWidth, - const int desiredHeight, - const bool useColor A_UNUSED) + const int desiredHeight) { FUNC_BLOCK("Graphics::drawRescaledImage", 1) // Check that preconditions for blitting are met. @@ -99,10 +96,10 @@ bool SDLGraphics::drawRescaledImage(const Image *const image, 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 = { diff --git a/src/render/sdl2graphics.h b/src/render/sdl2graphics.h index 9ab56afe7..b489f2475 100644 --- a/src/render/sdl2graphics.h +++ b/src/render/sdl2graphics.h @@ -62,12 +62,10 @@ class SDLGraphics final : public Graphics void popClipArea() override final; - bool drawRescaledImage(const Image *const image, int srcX, - int srcY, int dstX, int dstY, - const int width, const int height, + bool drawRescaledImage(const Image *const image, + int dstX, int dstY, const int desiredWidth, - const int desiredHeight, - const bool useColor = false) override final; + const int desiredHeight) override final; void drawPattern(const Image *const image, const int x, const int y, diff --git a/src/render/sdl2softwaregraphics.cpp b/src/render/sdl2softwaregraphics.cpp index fa92f6030..7210e8bbf 100644 --- a/src/render/sdl2softwaregraphics.cpp +++ b/src/render/sdl2softwaregraphics.cpp @@ -62,12 +62,9 @@ SDL2SoftwareGraphics::~SDL2SoftwareGraphics() } bool SDL2SoftwareGraphics::drawRescaledImage(const Image *const image, - int srcX, int srcY, int dstX, int dstY, - const int width, const int height, const int desiredWidth, - const int desiredHeight, - const bool useColor A_UNUSED) + const int desiredHeight) { FUNC_BLOCK("Graphics::drawRescaledImage", 1) // Check that preconditions for blitting are met. @@ -89,10 +86,10 @@ bool SDL2SoftwareGraphics::drawRescaledImage(const Image *const image, SDL_Rect srcRect = { - static_cast<int16_t>(srcX + bounds.x), - static_cast<int16_t>(srcY + bounds.y), - static_cast<uint16_t>(width), - static_cast<uint16_t>(height) + static_cast<int16_t>(bounds.x), + static_cast<int16_t>(bounds.y), + static_cast<uint16_t>(bounds.w), + static_cast<uint16_t>(bounds.h) }; SDL_Rect dstRect = diff --git a/src/render/sdl2softwaregraphics.h b/src/render/sdl2softwaregraphics.h index 718088972..658f1d127 100644 --- a/src/render/sdl2softwaregraphics.h +++ b/src/render/sdl2softwaregraphics.h @@ -63,12 +63,9 @@ class SDL2SoftwareGraphics final : public Graphics void popClipArea(); bool drawRescaledImage(const Image *const image, - int srcX, int srcY, int dstX, int dstY, - const int width, const int height, const int desiredWidth, - const int desiredHeight, - const bool useColor = false) override final; + const int desiredHeight) override final; void drawPattern(const Image *const image, const int x, const int y, diff --git a/src/render/sdlgraphics.cpp b/src/render/sdlgraphics.cpp index ef1f2d2a5..5680243ca 100644 --- a/src/render/sdlgraphics.cpp +++ b/src/render/sdlgraphics.cpp @@ -55,12 +55,9 @@ SDLGraphics::~SDLGraphics() } bool SDLGraphics::drawRescaledImage(const Image *const image, - int srcX, int srcY, int dstX, int dstY, - const int width, const int height, const int desiredWidth, - const int desiredHeight, - const bool useColor A_UNUSED) + const int desiredHeight) { FUNC_BLOCK("Graphics::drawRescaledImage", 1) // Check that preconditions for blitting are met. @@ -82,10 +79,10 @@ bool SDLGraphics::drawRescaledImage(const Image *const image, SDL_Rect srcRect = { - static_cast<int16_t>(srcX + bounds.x), - static_cast<int16_t>(srcY + bounds.y), - static_cast<uint16_t>(width), - static_cast<uint16_t>(height) + static_cast<int16_t>(bounds.x), + static_cast<int16_t>(bounds.y), + static_cast<uint16_t>(bounds.w), + static_cast<uint16_t>(bounds.h) }; SDL_Rect dstRect = diff --git a/src/render/sdlgraphics.h b/src/render/sdlgraphics.h index 2c1847751..c705368e9 100644 --- a/src/render/sdlgraphics.h +++ b/src/render/sdlgraphics.h @@ -62,12 +62,10 @@ class SDLGraphics final : public Graphics void popClipArea() override final; - bool drawRescaledImage(const Image *const image, int srcX, - int srcY, int dstX, int dstY, - const int width, const int height, + bool drawRescaledImage(const Image *const image, + int dstX, int dstY, const int desiredWidth, - const int desiredHeight, - const bool useColor = false) override final; + const int desiredHeight) override final; void drawPattern(const Image *const image, const int x, const int y, diff --git a/src/render/surfacegraphics.h b/src/render/surfacegraphics.h index 6b8051c6a..dc26ac05e 100644 --- a/src/render/surfacegraphics.h +++ b/src/render/surfacegraphics.h @@ -70,13 +70,9 @@ class SurfaceGraphics final : public Graphics { } bool drawRescaledImage(const Image *const image A_UNUSED, - int srcX A_UNUSED, int srcY A_UNUSED, int dstX A_UNUSED, int dstY A_UNUSED, - const int width A_UNUSED, - const int height A_UNUSED, const int desiredWidth A_UNUSED, - const int desiredHeight A_UNUSED, - const bool useColor A_UNUSED = false) + const int desiredHeight A_UNUSED) override final { return false; } |