From be877e12682b6f0e697b024f96a1dcaf4d0c8206 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 29 Jun 2014 22:31:02 +0300 Subject: In renderers add copyImage function. For now it same with drawImage. --- src/render/graphics.h | 3 +++ src/render/graphicsdef.hpp | 3 +++ src/render/mobileopenglgraphics.cpp | 6 ++++++ src/render/modernopenglgraphics.cpp | 6 ++++++ src/render/normalopenglgraphics.cpp | 6 ++++++ src/render/nullopenglgraphics.cpp | 6 ++++++ src/render/safeopenglgraphics.cpp | 6 ++++++ src/render/sdl2graphics.cpp | 6 ++++++ src/render/sdl2softwaregraphics.cpp | 6 ++++++ src/render/sdlgraphics.cpp | 6 ++++++ src/render/surfacegraphics.cpp | 28 ++++++++++++++++++++++++++++ src/render/surfacegraphics.h | 3 +++ 12 files changed, 85 insertions(+) (limited to 'src/render') diff --git a/src/render/graphics.h b/src/render/graphics.h index 2c4bc57ec..5e536235f 100644 --- a/src/render/graphics.h +++ b/src/render/graphics.h @@ -347,6 +347,9 @@ class Graphics notfinal virtual bool drawImage(const Image *const image, int dstX, int dstY) = 0; + virtual bool copyImage(const Image *const image, + int dstX, int dstY) = 0; + virtual void drawImageCached(const Image *const image, int srcX, int srcY) = 0; diff --git a/src/render/graphicsdef.hpp b/src/render/graphicsdef.hpp index 6d3511f6b..19282584c 100644 --- a/src/render/graphicsdef.hpp +++ b/src/render/graphicsdef.hpp @@ -114,6 +114,9 @@ public: bool drawImage(const Image *const image, int dstX, int dstY) override final; + bool copyImage(const Image *const image, + int dstX, int dstY) override final; + void drawImageCached(const Image *const image, int x, int y) override final; diff --git a/src/render/mobileopenglgraphics.cpp b/src/render/mobileopenglgraphics.cpp index 35b99c43a..346fe60ec 100644 --- a/src/render/mobileopenglgraphics.cpp +++ b/src/render/mobileopenglgraphics.cpp @@ -267,6 +267,12 @@ bool MobileOpenGLGraphics::drawImageInline(const Image *const image, return true; } +bool MobileOpenGLGraphics::copyImage(const Image *const image, + int dstX, int dstY) +{ + return drawImageInline(image, dstX, dstY); +} + void MobileOpenGLGraphics::drawImageCached(const Image *const image, int x, int y) { diff --git a/src/render/modernopenglgraphics.cpp b/src/render/modernopenglgraphics.cpp index ccab406d2..faaa206d7 100644 --- a/src/render/modernopenglgraphics.cpp +++ b/src/render/modernopenglgraphics.cpp @@ -343,6 +343,12 @@ bool ModernOpenGLGraphics::drawImageInline(const Image *const image, return true; } +bool ModernOpenGLGraphics::copyImage(const Image *const image, + int dstX, int dstY) +{ + return drawImageInline(image, dstX, dstY); +} + void ModernOpenGLGraphics::testDraw() { /* diff --git a/src/render/normalopenglgraphics.cpp b/src/render/normalopenglgraphics.cpp index 8d662ec98..57f1d58cb 100644 --- a/src/render/normalopenglgraphics.cpp +++ b/src/render/normalopenglgraphics.cpp @@ -358,6 +358,12 @@ bool NormalOpenGLGraphics::drawImageInline(const Image *const image, return true; } +bool NormalOpenGLGraphics::copyImage(const Image *const image, + int dstX, int dstY) +{ + return drawImageInline(image, dstX, dstY); +} + void NormalOpenGLGraphics::testDraw() { if (OpenGLImageHelper::mTextureType == GL_TEXTURE_2D) diff --git a/src/render/nullopenglgraphics.cpp b/src/render/nullopenglgraphics.cpp index bfe9172c8..dce5f93ee 100644 --- a/src/render/nullopenglgraphics.cpp +++ b/src/render/nullopenglgraphics.cpp @@ -157,6 +157,12 @@ bool NullOpenGLGraphics::drawImage(const Image *const image, return drawImageInline(image, dstX, dstY); } +bool NullOpenGLGraphics::copyImage(const Image *const image, + int dstX, int dstY) +{ + return drawImageInline(image, dstX, dstY); +} + bool NullOpenGLGraphics::drawImageInline(const Image *const image, int dstX, int dstY) { diff --git a/src/render/safeopenglgraphics.cpp b/src/render/safeopenglgraphics.cpp index 28f34dcde..53b842839 100644 --- a/src/render/safeopenglgraphics.cpp +++ b/src/render/safeopenglgraphics.cpp @@ -176,6 +176,12 @@ bool SafeOpenGLGraphics::drawImageInline(const Image *const image, return true; } +bool SafeOpenGLGraphics::copyImage(const Image *const image, + int dstX, int dstY) +{ + return drawImageInline(image, dstX, dstY); +} + void SafeOpenGLGraphics::testDraw() { if (OpenGLImageHelper::mTextureType == GL_TEXTURE_2D) diff --git a/src/render/sdl2graphics.cpp b/src/render/sdl2graphics.cpp index 1acca0a6c..fc9c8222d 100644 --- a/src/render/sdl2graphics.cpp +++ b/src/render/sdl2graphics.cpp @@ -212,6 +212,12 @@ bool SDLGraphics::drawImageInline(const Image *const image, return !MSDL_RenderCopy(mRenderer, image->mTexture, &srcRect, &dstRect); } +bool SDLGraphics::copyImage(const Image *const image, + int dstX, int dstY) +{ + return drawImageInline(image, dstX, dstY); +} + void SDLGraphics::drawImageCached(const Image *const image, int x, int y) { diff --git a/src/render/sdl2softwaregraphics.cpp b/src/render/sdl2softwaregraphics.cpp index 49e450507..65053696d 100644 --- a/src/render/sdl2softwaregraphics.cpp +++ b/src/render/sdl2softwaregraphics.cpp @@ -213,6 +213,12 @@ bool SDL2SoftwareGraphics::drawImageInline(const Image *const image, return 0; } +bool SDL2SoftwareGraphics::copyImage(const Image *const image, + int dstX, int dstY) +{ + return drawImageInline(image, dstX, dstY); +} + void SDL2SoftwareGraphics::drawImageCached(const Image *const image, int x, int y) { diff --git a/src/render/sdlgraphics.cpp b/src/render/sdlgraphics.cpp index 494e17e0e..e9b6bef4a 100644 --- a/src/render/sdlgraphics.cpp +++ b/src/render/sdlgraphics.cpp @@ -198,6 +198,12 @@ bool SDLGraphics::drawImageInline(const Image *const image, return 0; } +bool SDLGraphics::copyImage(const Image *const image, + int dstX, int dstY) +{ + return drawImageInline(image, dstX, dstY); +} + void SDLGraphics::drawImageCached(const Image *const image, int x, int y) { diff --git a/src/render/surfacegraphics.cpp b/src/render/surfacegraphics.cpp index e6aee752f..8691274dd 100644 --- a/src/render/surfacegraphics.cpp +++ b/src/render/surfacegraphics.cpp @@ -77,6 +77,34 @@ bool SurfaceGraphics::drawImage(const Image *const image, #endif } +bool SurfaceGraphics::copyImage(const Image *const image, + int dstX, int dstY) +{ + FUNC_BLOCK("Graphics::drawImage", 1) + // Check that preconditions for blitting are met. + if (!mTarget || !image || !image->mSDLSurface) + return false; + + const SDL_Rect &imageRect = image->mBounds; + SDL_Rect dstRect; + SDL_Rect srcRect; + dstRect.x = static_cast(dstX); + dstRect.y = static_cast(dstY); + srcRect.x = static_cast(imageRect.x); + srcRect.y = static_cast(imageRect.y); + srcRect.w = static_cast(imageRect.w); + srcRect.h = static_cast(imageRect.h); + +#ifdef USE_SDL2 + // probably need change some flags + return !(SDL_BlitSurface(image->mSDLSurface, &srcRect, + mTarget, &dstRect) < 0); +#else + return !(SDL_BlitSurface(image->mSDLSurface, &srcRect, + mTarget, &dstRect) < 0); +#endif +} + void SurfaceGraphics::drawImageCached(const Image *const image, int x, int y) { diff --git a/src/render/surfacegraphics.h b/src/render/surfacegraphics.h index ab569acb0..7150b6ede 100644 --- a/src/render/surfacegraphics.h +++ b/src/render/surfacegraphics.h @@ -182,6 +182,9 @@ class SurfaceGraphics final : public Graphics bool drawImage(const Image *const image, int dstX, int dstY) override final; + bool copyImage(const Image *const image, + int dstX, int dstY) override final; + void drawImageCached(const Image *const image, int x, int y) override final; -- cgit v1.2.3-60-g2f50