From a1a00f0ed5366cfb8dbe448078ccc60331a0cdaa Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 26 Aug 2013 19:27:35 +0300 Subject: improve a bit OpenGL drawing speed. --- src/normalopenglgraphics.cpp | 43 ++++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 23 deletions(-) (limited to 'src/normalopenglgraphics.cpp') diff --git a/src/normalopenglgraphics.cpp b/src/normalopenglgraphics.cpp index 9526d4ee3..66dfadabf 100644 --- a/src/normalopenglgraphics.cpp +++ b/src/normalopenglgraphics.cpp @@ -111,15 +111,13 @@ static inline void drawQuad(const Image *const image, { if (OpenGLImageHelper::mTextureType == GL_TEXTURE_2D) { + const float tw = static_cast(image->mTexWidth); + const float th = static_cast(image->mTexHeight); // Find OpenGL normalized texture coordinates. - const float texX1 = static_cast(srcX) / - static_cast(image->mTexWidth); - const float texY1 = static_cast(srcY) / - static_cast(image->mTexHeight); - const float texX2 = static_cast(srcX + width) / - static_cast(image->mTexWidth); - const float texY2 = static_cast(srcY + height) / - static_cast(image->mTexHeight); + const float texX1 = static_cast(srcX) / tw; + const float texY1 = static_cast(srcY) / th; + const float texX2 = static_cast(srcX + width) / tw; + const float texY2 = static_cast(srcY + height) / th; GLfloat tex[] = { @@ -181,15 +179,13 @@ static inline void drawRescaledQuad(const Image *const image, { if (OpenGLImageHelper::mTextureType == GL_TEXTURE_2D) { + const float tw = static_cast(image->mTexWidth); + const float th = static_cast(image->mTexHeight); // Find OpenGL normalized texture coordinates. - const float texX1 = static_cast(srcX) / - static_cast(image->mTexWidth); - const float texY1 = static_cast(srcY) / - static_cast(image->mTexHeight); - const float texX2 = static_cast(srcX + width) / - static_cast(image->mTexWidth); - const float texY2 = static_cast(srcY + height) / - static_cast(image->mTexHeight); + const float texX1 = static_cast(srcX) / tw; + const float texY1 = static_cast(srcY) / th; + const float texX2 = static_cast(srcX + width) / tw; + const float texY2 = static_cast(srcY + height) / th; GLfloat tex[] = { @@ -254,8 +250,6 @@ bool NormalOpenGLGraphics::drawImage2(const Image *const image, return false; const SDL_Rect &imageRect = image->mBounds; - srcX += imageRect.x; - srcY += imageRect.y; if (!useColor) setColorAlpha(image->mAlpha); @@ -267,7 +261,8 @@ bool NormalOpenGLGraphics::drawImage2(const Image *const image, setTexturingAndBlending(true); - drawQuad(image, srcX, srcY, dstX, dstY, width, height); + drawQuad(image, srcX + imageRect.x, srcY + imageRect.y, + dstX, dstY, width, height); return true; } @@ -1016,10 +1011,11 @@ bool NormalOpenGLGraphics::calcWindow(ImageCollection *const vertCol, vert = vertCol->currentVert; } + const Image *const *const grid = &imgRect.grid[0]; return calcImageRect(vert, x, y, w, h, - imgRect.grid[0], imgRect.grid[2], imgRect.grid[6], imgRect.grid[8], - imgRect.grid[1], imgRect.grid[5], imgRect.grid[7], imgRect.grid[3], - imgRect.grid[4]); + grid[0], grid[2], grid[6], grid[8], + grid[1], grid[5], grid[7], grid[3], + grid[4]); } void NormalOpenGLGraphics::updateScreen() @@ -1134,7 +1130,8 @@ SDL_Surface* NormalOpenGLGraphics::getScreenshot() const unsigned int lineSize = 3 * w; GLubyte *const buf = static_cast(malloc(lineSize)); - for (int i = 0; i < (h / 2); i++) + const int h2 = h / 2; + for (int i = 0; i < h2; i++) { GLubyte *const top = static_cast( screenshot->pixels) + lineSize * i; -- cgit v1.2.3-70-g09d2