summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2009-04-14 00:23:30 +0200
committerBjørn Lindeijer <bjorn@lindeijer.nl>2009-04-14 00:23:30 +0200
commitff5dcb946d1efc9248a2f1b88015119d2f267b35 (patch)
tree15c1ff33e39c4776813c7374543ae49cf85f852c /src
parent0eddf44c73dc3a0e9fe20106e91b648197898b3b (diff)
downloadmana-client-ff5dcb946d1efc9248a2f1b88015119d2f267b35.tar.gz
mana-client-ff5dcb946d1efc9248a2f1b88015119d2f267b35.tar.bz2
mana-client-ff5dcb946d1efc9248a2f1b88015119d2f267b35.tar.xz
mana-client-ff5dcb946d1efc9248a2f1b88015119d2f267b35.zip
Unduplicated the code that draws a quad
Shouldn't affect performance.
Diffstat (limited to 'src')
-rw-r--r--src/openglgraphics.cpp94
-rw-r--r--src/openglgraphics.h2
-rw-r--r--src/resources/image.h4
3 files changed, 41 insertions, 59 deletions
diff --git a/src/openglgraphics.cpp b/src/openglgraphics.cpp
index 7a1d259e..b9d837ad 100644
--- a/src/openglgraphics.cpp
+++ b/src/openglgraphics.cpp
@@ -106,33 +106,17 @@ bool OpenGLGraphics::setVideoMode(int w, int h, int bpp, bool fs, bool hwaccel)
return true;
}
-bool OpenGLGraphics::drawImage(Image *image, int srcX, int srcY,
- int dstX, int dstY, int width, int height, bool useColor)
+static inline void drawQuad(Image *image,
+ int srcX, int srcY, int dstX, int dstY,
+ int width, int height)
{
- if (!image) return false;
-
- srcX += image->mBounds.x;
- srcY += image->mBounds.y;
-
- if (!useColor)
- {
- glColor4f(1.0f, 1.0f, 1.0f, image->mAlpha);
- }
-
- glBindTexture(Image::mTextureType, image->mGLImage);
-
- setTexturingAndBlending(true);
-
- // Draw a textured quad.
- glBegin(GL_QUADS);
-
- if (Image::mTextureType == GL_TEXTURE_2D)
+ if (image->getTextureType() == GL_TEXTURE_2D)
{
// Find OpenGL normalized texture coordinates.
- float texX1 = srcX / (float)image->mTexWidth;
- float texY1 = srcY / (float)image->mTexHeight;
- float texX2 = (srcX + width) / (float)image->mTexWidth;
- float texY2 = (srcY + height) / (float)image->mTexHeight;
+ float texX1 = srcX / (float) image->getTextureWidth();
+ float texY1 = srcY / (float) image->getTextureHeight();
+ float texX2 = (srcX + width) / (float) image->getTextureWidth();
+ float texY2 = (srcY + height) / (float) image->getTextureHeight();
glTexCoord2f(texX1, texY1);
glVertex2i(dstX, dstY);
@@ -154,7 +138,28 @@ bool OpenGLGraphics::drawImage(Image *image, int srcX, int srcY,
glTexCoord2i(srcX, srcY + height);
glVertex2i(dstX, dstY + height);
}
+}
+bool OpenGLGraphics::drawImage(Image *image, int srcX, int srcY,
+ int dstX, int dstY,
+ int width, int height, bool useColor)
+{
+ if (!image)
+ return false;
+
+ srcX += image->mBounds.x;
+ srcY += image->mBounds.y;
+
+ if (!useColor)
+ glColor4f(1.0f, 1.0f, 1.0f, image->mAlpha);
+
+ glBindTexture(Image::mTextureType, image->mGLImage);
+
+ setTexturingAndBlending(true);
+
+ // Draw a textured quad.
+ glBegin(GL_QUADS);
+ drawQuad(image, srcX, srcY, dstX, dstY, width, height);
glEnd();
if (!useColor)
@@ -167,16 +172,14 @@ bool OpenGLGraphics::drawImage(Image *image, int srcX, int srcY,
* so that glBegin...glEnd are outside the main loop. */
void OpenGLGraphics::drawImagePattern(Image *image, int x, int y, int w, int h)
{
- if (!image) return;
+ if (!image)
+ return;
const int srcX = image->mBounds.x;
const int srcY = image->mBounds.y;
- const float texX1 = srcX / (float)image->mTexWidth;
- const float texY1 = srcY / (float)image->mTexHeight;
-
- int iw = image->getWidth();
- int ih = image->getHeight();
+ const int iw = image->getWidth();
+ const int ih = image->getHeight();
if (iw == 0 || ih == 0)
return;
@@ -191,39 +194,14 @@ void OpenGLGraphics::drawImagePattern(Image *image, int x, int y, int w, int h)
for (int py = 0; py < h; py += ih)
{
- int height = (py + ih >= h) ? h - py : ih;
- int dstY = y + py;
+ 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;
- if (Image::mTextureType == GL_TEXTURE_2D)
- {
- // Find OpenGL normalized texture coordinates.
- float texX2 = (srcX + width) / (float) image->mTexWidth;
- float texY2 = (srcY + height) / (float) image->mTexHeight;
-
- glTexCoord2f(texX1, texY1);
- glVertex2i(dstX, dstY);
- glTexCoord2f(texX2, texY1);
- glVertex2i(dstX + width, dstY);
- glTexCoord2f(texX2, texY2);
- glVertex2i(dstX + width, dstY + height);
- glTexCoord2f(texX1, texY2);
- glVertex2i(dstX, dstY + height);
- }
- else
- {
- 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);
- }
+ drawQuad(image, srcX, srcY, dstX, dstY, width, height);
}
}
diff --git a/src/openglgraphics.h b/src/openglgraphics.h
index 469e1f53..dc748804 100644
--- a/src/openglgraphics.h
+++ b/src/openglgraphics.h
@@ -75,7 +75,7 @@ class OpenGLGraphics : public Graphics
/**
* Takes a screenshot and returns it as SDL surface.
*/
- SDL_Surface* getScreenshot();
+ SDL_Surface *getScreenshot();
protected:
void setTexturingAndBlending(bool enable);
diff --git a/src/resources/image.h b/src/resources/image.h
index 3cfb9216..4422fcc8 100644
--- a/src/resources/image.h
+++ b/src/resources/image.h
@@ -128,6 +128,10 @@ class Image : public Resource
* <code>true</code> for OpenGL.
*/
static void setLoadAsOpenGL(bool useOpenGL);
+
+ int getTextureWidth() const { return mTexWidth; }
+ int getTextureHeight() const { return mTexHeight; }
+ static int getTextureType() { return mTextureType; }
#endif
/**