summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSteve Cotton <steve@s.cotton.clara.co.uk>2009-03-16 20:46:21 +0000
committerSteve Cotton <steve@s.cotton.clara.co.uk>2009-03-16 20:46:21 +0000
commitd654758ef63f6515d678ceaf77d63a2693e08fb7 (patch)
treeb964fe878c9f7d7329b68eb933ec7ae930fba123 /src
parente90b7ba7d85edf9e5e020f3781f45ac318e7ea22 (diff)
downloadmana-client-d654758ef63f6515d678ceaf77d63a2693e08fb7.tar.gz
mana-client-d654758ef63f6515d678ceaf77d63a2693e08fb7.tar.bz2
mana-client-d654758ef63f6515d678ceaf77d63a2693e08fb7.tar.xz
mana-client-d654758ef63f6515d678ceaf77d63a2693e08fb7.zip
Optimising OpenGLGraphics::drawImagePattern
Diffstat (limited to 'src')
-rw-r--r--src/openglgraphics.cpp53
-rw-r--r--src/openglgraphics.h4
2 files changed, 57 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();
diff --git a/src/openglgraphics.h b/src/openglgraphics.h
index 207d6725..a7181420 100644
--- a/src/openglgraphics.h
+++ b/src/openglgraphics.h
@@ -47,6 +47,10 @@ class OpenGLGraphics : public Graphics
int width, int height,
bool useColor);
+ void drawImagePattern(Image *image,
+ int x, int y,
+ int w, int h);
+
void updateScreen();
void _beginDraw();