diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-12-28 23:06:17 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-12-29 14:55:33 +0300 |
commit | c9f8bba932022ffd90031713c51861587f86b244 (patch) | |
tree | db2184f1a1ac5649792c5ac57415bfa71a2c307a /src/render/safeopenglgraphics.cpp | |
parent | 9bc564d99774045fa0c10f253dd54b223416bc34 (diff) | |
download | mv-c9f8bba932022ffd90031713c51861587f86b244.tar.gz mv-c9f8bba932022ffd90031713c51861587f86b244.tar.bz2 mv-c9f8bba932022ffd90031713c51861587f86b244.tar.xz mv-c9f8bba932022ffd90031713c51861587f86b244.zip |
Add cached draw methods into renderers.
Diffstat (limited to 'src/render/safeopenglgraphics.cpp')
-rw-r--r-- | src/render/safeopenglgraphics.cpp | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/render/safeopenglgraphics.cpp b/src/render/safeopenglgraphics.cpp index e1540dbab..1170f0300 100644 --- a/src/render/safeopenglgraphics.cpp +++ b/src/render/safeopenglgraphics.cpp @@ -165,6 +165,67 @@ bool SafeOpenGLGraphics::drawImage2(const Image *const image, return true; } +void SafeOpenGLGraphics::drawImageCached(const Image *const image, + int x, int y) +{ + FUNC_BLOCK("Graphics::drawImageCached", 1) + if (!image) + return; + + 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, bounds.x, bounds.y, x, y, bounds.w, bounds.h); + glEnd(); +} + +void SafeOpenGLGraphics::drawPatternCached(const Image *const image, + const int x, const int y, + const int w, const int h) +{ + FUNC_BLOCK("Graphics::drawPatternCached", 1) + if (!image) + return; + + const SDL_Rect &imageRect = image->mBounds; + const int iw = imageRect.w; + const int ih = imageRect.h; + if (iw == 0 || ih == 0) + return; + + const int srcX = imageRect.x; + const int srcY = imageRect.y; + + setColorAlpha(image->mAlpha); + bindTexture(OpenGLImageHelper::mTextureType, image->mGLImage); + setTexturingAndBlending(true); + + // Draw a set of textured rectangles + glBegin(GL_QUADS); + + for (int py = 0; py < h; py += ih) + { + const int height = (py + ih >= h) ? h - py : ih; + const int dstY = y + py; + for (int px = 0; px < w; px += iw) + { + int width = (px + iw >= w) ? w - px : iw; + int dstX = x + px; + drawQuad(image, srcX, srcY, dstX, dstY, width, height); + } + } + + glEnd(); +} + +void SafeOpenGLGraphics::completeCache() +{ +} + bool SafeOpenGLGraphics::drawRescaledImage(const Image *const image, int srcX, int srcY, int dstX, int dstY, const int width, const int height, |