diff options
author | Steve Cotton <steve@s.cotton.clara.co.uk> | 2009-03-16 20:46:21 +0000 |
---|---|---|
committer | Steve Cotton <steve@s.cotton.clara.co.uk> | 2009-03-16 20:46:21 +0000 |
commit | d654758ef63f6515d678ceaf77d63a2693e08fb7 (patch) | |
tree | b964fe878c9f7d7329b68eb933ec7ae930fba123 /src/openglgraphics.cpp | |
parent | e90b7ba7d85edf9e5e020f3781f45ac318e7ea22 (diff) | |
download | mana-d654758ef63f6515d678ceaf77d63a2693e08fb7.tar.gz mana-d654758ef63f6515d678ceaf77d63a2693e08fb7.tar.bz2 mana-d654758ef63f6515d678ceaf77d63a2693e08fb7.tar.xz mana-d654758ef63f6515d678ceaf77d63a2693e08fb7.zip |
Optimising OpenGLGraphics::drawImagePattern
Diffstat (limited to 'src/openglgraphics.cpp')
-rw-r--r-- | src/openglgraphics.cpp | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/openglgraphics.cpp b/src/openglgraphics.cpp index 9bd3ab2f..d436e7a5 100644 --- a/src/openglgraphics.cpp +++ b/src/openglgraphics.cpp @@ -162,6 +162,59 @@ bool OpenGLGraphics::drawImage(Image *image, int srcX, int srcY, return true; } +/* Optimising the functions that Graphics::drawImagePattern would call, + * so that glBegin...glEnd are outside the main loop. */ +void OpenGLGraphics::drawImagePattern(Image *image, int x, int y, int w, int h) +{ + if (Image::mTextureType == GL_TEXTURE_2D) + { + /* I'm not seeing this get called at all, so no point in optimising it. */ + Graphics::drawImagePattern(image, x, y, w, h); + return; + } + + const int srcX = image->mBounds.x; + const int srcY = image->mBounds.y; + + int iw = image->getWidth(); + int ih = image->getHeight(); + if (iw == 0 || ih == 0) + return; + + glColor4f(1.0f, 1.0f, 1.0f, image->mAlpha); + + glBindTexture(Image::mTextureType, image->mGLImage); + setTexturingAndBlending(true); + + // Draw a set of textured rectangles + glBegin(GL_QUADS); + + for (int py = 0; py < h; py += ih) + { + int height = (py + ih >= h) ? h - py : ih; + int dstY = y+py; + for (int px = 0; px < w; px += iw) + { + int width = (px + iw >= w) ? w - px : iw; + int dstX = x+px; + + glTexCoord2i(srcX, srcY); + glVertex2i(dstX, dstY); + glTexCoord2i(srcX + width, srcY); + glVertex2i(dstX + width, dstY); + glTexCoord2i(srcX + width, srcY + height); + glVertex2i(dstX + width, dstY + height); + glTexCoord2i(srcX, srcY + height); + glVertex2i(dstX, dstY + height); + } + } + + glEnd(); + + glColor4ub(mColor.r, mColor.g, mColor.b, mColor.a); +} + + void OpenGLGraphics::updateScreen() { glFlush(); |