From 7760ed560001714494d7a7de470123a4cd565873 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 8 Oct 2012 02:52:22 +0300 Subject: improve map draw speed. --- src/normalopenglgraphics.cpp | 69 ++++++++++++++++++++------------------------ 1 file changed, 31 insertions(+), 38 deletions(-) (limited to 'src/normalopenglgraphics.cpp') diff --git a/src/normalopenglgraphics.cpp b/src/normalopenglgraphics.cpp index b0e09b9eb..df52526bc 100644 --- a/src/normalopenglgraphics.cpp +++ b/src/normalopenglgraphics.cpp @@ -611,8 +611,6 @@ void NormalOpenGLGraphics::drawImagePattern2(GraphicsVertexes *const vert, if (!image) return; - NormalOpenGLGraphicsVertexes &ogl = vert->getOGL(); - setColorAlpha(image->mAlpha); #ifdef DEBUG_BIND_TEXTURE debugBindTexture(image); @@ -620,6 +618,12 @@ void NormalOpenGLGraphics::drawImagePattern2(GraphicsVertexes *const vert, bindTexture(OpenGLImageHelper::mTextureType, image->mGLImage); setTexturingAndBlending(true); + drawVertexes(vert->getOGL()); +} + +inline void NormalOpenGLGraphics::drawVertexes(NormalOpenGLGraphicsVertexes + &ogl) +{ std::vector &intVertPool = ogl.mIntVertPool; std::vector::const_iterator iv; std::vector::const_iterator iv_end = intVertPool.end(); @@ -820,11 +824,12 @@ void NormalOpenGLGraphics::calcTile(ImageVertexes *const vert, const float tw = static_cast(image->mTexWidth); const float th = static_cast(image->mTexHeight); - const unsigned int vLimit = 512 * 4; + const unsigned int vLimit = mMaxVertices * 4; NormalOpenGLGraphicsVertexes &ogl = vert->ogl; - unsigned int vp = ogl.ptr; + std::vector *vps = ogl.getVp(); + unsigned int vp = ogl.continueVp(); // Draw a set of textured rectangles if (OpenGLImageHelper::mTextureType == GL_TEXTURE_2D) @@ -832,17 +837,12 @@ void NormalOpenGLGraphics::calcTile(ImageVertexes *const vert, float texX1 = static_cast(srcX) / tw; float texY1 = static_cast(srcY) / th; - if (!ogl.mFloatTexArray) - ogl.mFloatTexArray = new GLfloat[vLimit]; - if (!ogl.mIntVertArray) - ogl.mIntVertArray = new GLint[vLimit]; - - GLfloat *floatTexArray = ogl.mFloatTexArray; - GLint *intVertArray = ogl.mIntVertArray; - float texX2 = static_cast(srcX + w) / tw; float texY2 = static_cast(srcY + h) / th; + GLfloat *floatTexArray = ogl.continueFloatTexArray(); + GLint *intVertArray = ogl.continueIntVertArray(); + floatTexArray[vp + 0] = texX1; floatTexArray[vp + 1] = texY1; @@ -868,22 +868,18 @@ void NormalOpenGLGraphics::calcTile(ImageVertexes *const vert, intVertArray[vp + 7] = dstY + h; vp += 8; - if (vp >= vLimit) { - ogl.ptr = vp; - return; + floatTexArray = ogl.switchFloatTexArray(); + intVertArray = ogl.switchIntVertArray(); + ogl.switchVp(vp); + vp = 0; } } else { - if (!ogl.mIntTexArray) - ogl.mIntTexArray = new GLint[vLimit]; - if (!ogl.mIntVertArray) - ogl.mIntVertArray = new GLint[vLimit]; - - GLint *intTexArray = ogl.mIntTexArray; - GLint *intVertArray = ogl.mIntVertArray; + GLint *intTexArray = ogl.continueIntTexArray(); + GLint *intVertArray = ogl.continueIntVertArray(); intTexArray[vp + 0] = srcX; intTexArray[vp + 1] = srcY; @@ -912,32 +908,28 @@ void NormalOpenGLGraphics::calcTile(ImageVertexes *const vert, vp += 8; if (vp >= vLimit) { - ogl.ptr = vp; - return; + intTexArray = ogl.switchIntTexArray(); + intVertArray = ogl.switchIntVertArray(); + ogl.switchVp(vp); + vp = 0; } } - ogl.ptr = vp; + ogl.switchVp(vp); } -void NormalOpenGLGraphics::drawTile(const ImageVertexes *const vert) +void NormalOpenGLGraphics::drawTile(ImageVertexes *const vert) { if (!vert) return; Image *image = vert->image; - const NormalOpenGLGraphicsVertexes &ogl = vert->ogl; - setColorAlpha(image->mAlpha); #ifdef DEBUG_BIND_TEXTURE debugBindTexture(image); #endif bindTexture(OpenGLImageHelper::mTextureType, image->mGLImage); setTexturingAndBlending(true); - - if (OpenGLImageHelper::mTextureType == GL_TEXTURE_2D) - drawQuadArrayfi(ogl.mIntVertArray, ogl.mFloatTexArray, ogl.ptr); - else - drawQuadArrayii(ogl.mIntVertArray, ogl.mIntTexArray, ogl.ptr); + drawVertexes(vert->ogl); } void NormalOpenGLGraphics::updateScreen() @@ -1268,9 +1260,9 @@ inline void NormalOpenGLGraphics::drawQuadArrayfi(int size) glDrawArrays(GL_QUADS, 0, size / 2); } -inline void NormalOpenGLGraphics::drawQuadArrayfi(GLint *intVertArray, - GLfloat *floatTexArray, - int size) +inline void NormalOpenGLGraphics::drawQuadArrayfi(GLint *const intVertArray, + GLfloat *const floatTexArray, + const int size) { glVertexPointer(2, GL_INT, 0, intVertArray); glTexCoordPointer(2, GL_FLOAT, 0, floatTexArray); @@ -1286,8 +1278,9 @@ inline void NormalOpenGLGraphics::drawQuadArrayii(int size) glDrawArrays(GL_QUADS, 0, size / 2); } -inline void NormalOpenGLGraphics::drawQuadArrayii(GLint *intVertArray, - GLint *intTexArray, int size) +inline void NormalOpenGLGraphics::drawQuadArrayii(GLint *const intVertArray, + GLint *const intTexArray, + const int size) { glVertexPointer(2, GL_INT, 0, intVertArray); glTexCoordPointer(2, GL_INT, 0, intTexArray); -- cgit v1.2.3-60-g2f50