diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-08-26 19:27:35 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-08-26 19:27:35 +0300 |
commit | a1a00f0ed5366cfb8dbe448078ccc60331a0cdaa (patch) | |
tree | 53118e9c8513217746f16e2cca7ed894b2c4e39f | |
parent | a9b4bdf0bea8fe1b2be8f1839e95d7c0a5d012b1 (diff) | |
download | plus-a1a00f0ed5366cfb8dbe448078ccc60331a0cdaa.tar.gz plus-a1a00f0ed5366cfb8dbe448078ccc60331a0cdaa.tar.bz2 plus-a1a00f0ed5366cfb8dbe448078ccc60331a0cdaa.tar.xz plus-a1a00f0ed5366cfb8dbe448078ccc60331a0cdaa.zip |
improve a bit OpenGL drawing speed.
-rw-r--r-- | src/mobileopenglgraphics.cpp | 36 | ||||
-rw-r--r-- | src/normalopenglgraphics.cpp | 43 | ||||
-rw-r--r-- | src/safeopenglgraphics.cpp | 57 |
3 files changed, 62 insertions, 74 deletions
diff --git a/src/mobileopenglgraphics.cpp b/src/mobileopenglgraphics.cpp index c53de9e0e..ee9761215 100644 --- a/src/mobileopenglgraphics.cpp +++ b/src/mobileopenglgraphics.cpp @@ -111,15 +111,13 @@ static inline void drawQuad(const Image *const image, { // if (OpenGLImageHelper::mTextureType == GL_TEXTURE_2D) { + const float tw = static_cast<float>(image->mTexWidth); + const float th = static_cast<float>(image->mTexHeight); // Find OpenGL normalized texture coordinates. - const float texX1 = static_cast<float>(srcX) / - static_cast<float>(image->mTexWidth); - const float texY1 = static_cast<float>(srcY) / - static_cast<float>(image->mTexHeight); - const float texX2 = static_cast<float>(srcX + width) / - static_cast<float>(image->mTexWidth); - const float texY2 = static_cast<float>(srcY + height) / - static_cast<float>(image->mTexHeight); + const float texX1 = static_cast<float>(srcX) / tw; + const float texY1 = static_cast<float>(srcY) / th; + const float texX2 = static_cast<float>(srcX + width) / tw; + const float texY2 = static_cast<float>(srcY + height) / th; GLfloat tex[] = { @@ -157,15 +155,13 @@ static inline void drawRescaledQuad(const Image *const image, { // if (OpenGLImageHelper::mTextureType == GL_TEXTURE_2D) { + const float tw = static_cast<float>(image->mTexWidth); + const float th = static_cast<float>(image->mTexHeight); // Find OpenGL normalized texture coordinates. - const float texX1 = static_cast<float>(srcX) / - static_cast<float>(image->mTexWidth); - const float texY1 = static_cast<float>(srcY) / - static_cast<float>(image->mTexHeight); - const float texX2 = static_cast<float>(srcX + width) / - static_cast<float>(image->mTexWidth); - const float texY2 = static_cast<float>(srcY + height) / - static_cast<float>(image->mTexHeight); + const float texX1 = static_cast<float>(srcX) / tw; + const float texY1 = static_cast<float>(srcY) / th; + const float texX2 = static_cast<float>(srcX + width) / tw; + const float texY2 = static_cast<float>(srcY + height) / th; GLfloat tex[] = { @@ -207,8 +203,6 @@ bool MobileOpenGLGraphics::drawImage2(const Image *const image, return false; const SDL_Rect &imageRect = image->mBounds; - srcX += imageRect.x; - srcY += imageRect.y; if (!useColor) setColorAlpha(image->mAlpha); @@ -220,7 +214,8 @@ bool MobileOpenGLGraphics::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; } @@ -923,7 +918,8 @@ SDL_Surface* MobileOpenGLGraphics::getScreenshot() const unsigned int lineSize = 3 * w; GLubyte *const buf = static_cast<GLubyte*>(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<GLubyte*>( screenshot->pixels) + lineSize * i; 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<float>(image->mTexWidth); + const float th = static_cast<float>(image->mTexHeight); // Find OpenGL normalized texture coordinates. - const float texX1 = static_cast<float>(srcX) / - static_cast<float>(image->mTexWidth); - const float texY1 = static_cast<float>(srcY) / - static_cast<float>(image->mTexHeight); - const float texX2 = static_cast<float>(srcX + width) / - static_cast<float>(image->mTexWidth); - const float texY2 = static_cast<float>(srcY + height) / - static_cast<float>(image->mTexHeight); + const float texX1 = static_cast<float>(srcX) / tw; + const float texY1 = static_cast<float>(srcY) / th; + const float texX2 = static_cast<float>(srcX + width) / tw; + const float texY2 = static_cast<float>(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<float>(image->mTexWidth); + const float th = static_cast<float>(image->mTexHeight); // Find OpenGL normalized texture coordinates. - const float texX1 = static_cast<float>(srcX) / - static_cast<float>(image->mTexWidth); - const float texY1 = static_cast<float>(srcY) / - static_cast<float>(image->mTexHeight); - const float texX2 = static_cast<float>(srcX + width) / - static_cast<float>(image->mTexWidth); - const float texY2 = static_cast<float>(srcY + height) / - static_cast<float>(image->mTexHeight); + const float texX1 = static_cast<float>(srcX) / tw; + const float texY1 = static_cast<float>(srcY) / th; + const float texX2 = static_cast<float>(srcX + width) / tw; + const float texY2 = static_cast<float>(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<GLubyte *const>(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<GLubyte *const>( screenshot->pixels) + lineSize * i; diff --git a/src/safeopenglgraphics.cpp b/src/safeopenglgraphics.cpp index ef415c5c4..c7af4c6a9 100644 --- a/src/safeopenglgraphics.cpp +++ b/src/safeopenglgraphics.cpp @@ -74,15 +74,13 @@ static inline void drawQuad(const Image *image, { if (OpenGLImageHelper::mTextureType == GL_TEXTURE_2D) { + const float tw = static_cast<float>(image->mTexWidth); + const float th = static_cast<float>(image->mTexHeight); // Find OpenGL normalized texture coordinates. - const float texX1 = static_cast<float>(srcX) - / static_cast<float>(image->mTexWidth); - const float texY1 = static_cast<float>(srcY) - / static_cast<float>(image->mTexHeight); - const float texX2 = static_cast<float>(srcX + width) - / static_cast<float>(image->mTexWidth); - const float texY2 = static_cast<float>(srcY + height) - / static_cast<float>(image->mTexHeight); + const float texX1 = static_cast<float>(srcX) / tw; + const float texY1 = static_cast<float>(srcY) / th; + const float texX2 = static_cast<float>(srcX + width) / tw; + const float texY2 = static_cast<float>(srcY + height) / th; glTexCoord2f(texX1, texY1); glVertex2i(dstX, dstY); @@ -115,15 +113,13 @@ static inline void drawRescaledQuad(const Image *const image, { if (OpenGLImageHelper::mTextureType == GL_TEXTURE_2D) { + const float tw = static_cast<float>(image->mTexWidth); + const float th = static_cast<float>(image->mTexHeight); // Find OpenGL normalized texture coordinates. - const float texX1 = static_cast<float>(srcX) - / static_cast<float>(image->mTexWidth); - const float texY1 = static_cast<float>(srcY) - / static_cast<float>(image->mTexHeight); - const float texX2 = static_cast<float>(srcX + width) - / static_cast<float>(image->mTexWidth); - const float texY2 = static_cast<float>(srcY + height) - / static_cast<float>(image->mTexHeight); + const float texX1 = static_cast<float>(srcX) / tw; + const float texY1 = static_cast<float>(srcY) / th; + const float texX2 = static_cast<float>(srcX + width) / tw; + const float texY2 = static_cast<float>(srcY + height) / th; glTexCoord2f(texX1, texY1); glVertex2i(dstX, dstY); @@ -158,9 +154,6 @@ bool SafeOpenGLGraphics::drawImage2(const Image *const image, if (!image) return false; - srcX += image->mBounds.x; - srcY += image->mBounds.y; - if (!useColor) setColorAlpha(image->mAlpha); @@ -170,7 +163,8 @@ bool SafeOpenGLGraphics::drawImage2(const Image *const image, // Draw a textured quad. glBegin(GL_QUADS); - drawQuad(image, srcX, srcY, dstX, dstY, width, height); + drawQuad(image, srcX + image->mBounds.x, srcY + image->mBounds.y, + dstX, dstY, width, height); glEnd(); return true; @@ -258,13 +252,14 @@ void SafeOpenGLGraphics::drawImagePattern(const Image *const image, if (!image) return; - const int iw = image->mBounds.w; - const int ih = image->mBounds.h; + 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 = image->mBounds.x; - const int srcY = image->mBounds.y; + const int srcX = imageRect.x; + const int srcY = imageRect.y; setColorAlpha(image->mAlpha); bindTexture(OpenGLImageHelper::mTextureType, image->mGLImage); @@ -302,8 +297,9 @@ void SafeOpenGLGraphics::drawRescaledImagePattern(const Image *const image, if (iw == 0 || ih == 0) return; - const int srcX = image->mBounds.x; - const int srcY = image->mBounds.y; + const SDL_Rect &imageRect = image->mBounds; + const int srcX = imageRect.x; + const int srcY = imageRect.y; setColorAlpha(image->mAlpha); bindTexture(OpenGLImageHelper::mTextureType, image->mGLImage); @@ -460,7 +456,8 @@ SDL_Surface* SafeOpenGLGraphics::getScreenshot() unsigned int lineSize = 3 * w; GLubyte* buf = static_cast<GLubyte*>(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<GLubyte*>( screenshot->pixels) + lineSize * i; @@ -500,12 +497,10 @@ bool SafeOpenGLGraphics::pushClipArea(gcn::Rectangle area) const bool result = gcn::Graphics::pushClipArea(area); const gcn::ClipRectangle &clipArea = mClipStack.top(); - transX += clipArea.xOffset; - transY += clipArea.yOffset; glPushMatrix(); - glTranslatef(static_cast<GLfloat>(transX), - static_cast<GLfloat>(transY), 0); + glTranslatef(static_cast<GLfloat>(transX + clipArea.xOffset), + static_cast<GLfloat>(transY + clipArea.yOffset), 0); glScissor(clipArea.x, mRect.h - clipArea.y - clipArea.height, clipArea.width, clipArea.height); |