From 79075b1688a4218dcee56d727dc2f6c88051c9c0 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Thu, 13 Sep 2012 17:24:06 +0300 Subject: Change some pointers to references in OpenGL draw code. --- src/graphicsvertexes.cpp | 7 ---- src/graphicsvertexes.h | 10 ++--- src/normalopenglgraphics.cpp | 92 ++++++++++++++++++++++---------------------- 3 files changed, 50 insertions(+), 59 deletions(-) diff --git a/src/graphicsvertexes.cpp b/src/graphicsvertexes.cpp index 841873aee..16fe7cec9 100644 --- a/src/graphicsvertexes.cpp +++ b/src/graphicsvertexes.cpp @@ -235,17 +235,10 @@ ImageVertexes::ImageVertexes() : image(nullptr) { sdl.reserve(30); -#ifdef USE_OPENGL - ogl = new NormalOpenGLGraphicsVertexes(); -#endif } ImageVertexes::~ImageVertexes() { delete_all(sdl); sdl.clear(); -#ifdef USE_OPENGL - delete ogl; - ogl = nullptr; -#endif } diff --git a/src/graphicsvertexes.h b/src/graphicsvertexes.h index 4a4fd37f9..b5140aa52 100644 --- a/src/graphicsvertexes.h +++ b/src/graphicsvertexes.h @@ -108,12 +108,10 @@ class NormalOpenGLGraphicsVertexes GLfloat *mFloatTexArray; GLint *mIntTexArray; GLint *mIntVertArray; - - private: + std::vector mVp; std::vector mFloatTexPool; std::vector mIntVertPool; std::vector mIntTexPool; - std::vector mVp; }; #endif @@ -130,7 +128,7 @@ class ImageVertexes DoubleRects sdl; #ifdef USE_OPENGL - NormalOpenGLGraphicsVertexes *ogl; + NormalOpenGLGraphicsVertexes ogl; #endif }; @@ -166,8 +164,8 @@ class GraphicsVertexes { mPtr = num; } #ifdef USE_OPENGL - NormalOpenGLGraphicsVertexes* getOGL() - { return &ogl[mPtr]; } + NormalOpenGLGraphicsVertexes &getOGL() + { return ogl[mPtr]; } #endif int getX() const diff --git a/src/normalopenglgraphics.cpp b/src/normalopenglgraphics.cpp index 7320878c8..86cc70cea 100644 --- a/src/normalopenglgraphics.cpp +++ b/src/normalopenglgraphics.cpp @@ -611,7 +611,7 @@ void NormalOpenGLGraphics::drawImagePattern2(GraphicsVertexes *const vert, if (!image) return; - NormalOpenGLGraphicsVertexes *ogl = vert->getOGL(); + NormalOpenGLGraphicsVertexes &ogl = vert->getOGL(); setColorAlpha(image->mAlpha); #ifdef DEBUG_BIND_TEXTURE @@ -620,22 +620,22 @@ void NormalOpenGLGraphics::drawImagePattern2(GraphicsVertexes *const vert, bindTexture(OpenGLImageHelper::mTextureType, image->mGLImage); setTexturingAndBlending(true); - std::vector *intVertPool = ogl->getIntVertPool(); + std::vector &intVertPool = ogl.mIntVertPool; std::vector::const_iterator iv; - std::vector::const_iterator iv_end = intVertPool->end(); - std::vector *vp = ogl->getVp(); + std::vector::const_iterator iv_end = intVertPool.end(); + std::vector &vp = ogl.mVp; std::vector::const_iterator ivp; - std::vector::const_iterator ivp_end = vp->end(); + std::vector::const_iterator ivp_end = vp.end(); // Draw a set of textured rectangles if (OpenGLImageHelper::mTextureType == GL_TEXTURE_2D) { - std::vector *floatTexPool = ogl->getFloatTexPool(); + std::vector &floatTexPool = ogl.mFloatTexPool; std::vector::const_iterator ft; - std::vector::const_iterator ft_end = floatTexPool->end(); + std::vector::const_iterator ft_end = floatTexPool.end(); - for (iv = intVertPool->begin(), ft = floatTexPool->begin(), - ivp = vp->begin(); + for (iv = intVertPool.begin(), ft = floatTexPool.begin(), + ivp = vp.begin(); iv != iv_end, ft != ft_end, ivp != ivp_end; ++ iv, ++ ft, ++ ivp) @@ -645,12 +645,12 @@ void NormalOpenGLGraphics::drawImagePattern2(GraphicsVertexes *const vert, } else { - std::vector *intTexPool = ogl->getIntTexPool(); + std::vector &intTexPool = ogl.mIntTexPool; std::vector::const_iterator it; - std::vector::const_iterator it_end = intTexPool->end(); + std::vector::const_iterator it_end = intTexPool.end(); - for (iv = intVertPool->begin(), it = intTexPool->begin(), - ivp = vp->begin(); + for (iv = intVertPool.begin(), it = intTexPool.begin(), + ivp = vp.begin(); iv != iv_end, it != it_end, ivp != ivp_end; ++ iv, ++ it, ++ ivp) @@ -689,8 +689,8 @@ void NormalOpenGLGraphics::calcImagePattern(GraphicsVertexes *const vert, unsigned int vp = 0; const unsigned int vLimit = mMaxVertices * 4; - NormalOpenGLGraphicsVertexes *ogl = vert->getOGL(); - ogl->init(); + NormalOpenGLGraphicsVertexes &ogl = vert->getOGL(); + ogl.init(); // Draw a set of textured rectangles if (OpenGLImageHelper::mTextureType == GL_TEXTURE_2D) @@ -698,8 +698,8 @@ void NormalOpenGLGraphics::calcImagePattern(GraphicsVertexes *const vert, float texX1 = static_cast(srcX) / tw; float texY1 = static_cast(srcY) / th; - GLfloat *floatTexArray = ogl->switchFloatTexArray(); - GLint *intVertArray = ogl->switchIntVertArray(); + GLfloat *floatTexArray = ogl.switchFloatTexArray(); + GLint *intVertArray = ogl.switchIntVertArray(); for (int py = 0; py < h; py += ih) { @@ -740,9 +740,9 @@ void NormalOpenGLGraphics::calcImagePattern(GraphicsVertexes *const vert, vp += 8; if (vp >= vLimit) { - floatTexArray = ogl->switchFloatTexArray(); - intVertArray = ogl->switchIntVertArray(); - ogl->switchVp(vp); + floatTexArray = ogl.switchFloatTexArray(); + intVertArray = ogl.switchIntVertArray(); + ogl.switchVp(vp); vp = 0; } } @@ -750,8 +750,8 @@ void NormalOpenGLGraphics::calcImagePattern(GraphicsVertexes *const vert, } else { - GLint *intTexArray = ogl->switchIntTexArray(); - GLint *intVertArray = ogl->switchIntVertArray(); + GLint *intTexArray = ogl.switchIntTexArray(); + GLint *intVertArray = ogl.switchIntVertArray(); for (int py = 0; py < h; py += ih) { @@ -789,15 +789,15 @@ void NormalOpenGLGraphics::calcImagePattern(GraphicsVertexes *const vert, vp += 8; if (vp >= vLimit) { - intTexArray = ogl->switchIntTexArray(); - intVertArray = ogl->switchIntVertArray(); - ogl->switchVp(vp); + intTexArray = ogl.switchIntTexArray(); + intVertArray = ogl.switchIntVertArray(); + ogl.switchVp(vp); vp = 0; } } } } - ogl->switchVp(vp); + ogl.switchVp(vp); vert->incPtr(1); } @@ -822,9 +822,9 @@ void NormalOpenGLGraphics::calcTile(ImageVertexes *const vert, const unsigned int vLimit = 512 * 4; - NormalOpenGLGraphicsVertexes *ogl = vert->ogl; + NormalOpenGLGraphicsVertexes &ogl = vert->ogl; - unsigned int vp = ogl->ptr; + unsigned int vp = ogl.ptr; // Draw a set of textured rectangles if (OpenGLImageHelper::mTextureType == GL_TEXTURE_2D) @@ -832,13 +832,13 @@ 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]; + if (!ogl.mFloatTexArray) + ogl.mFloatTexArray = new GLfloat[vLimit]; + if (!ogl.mIntVertArray) + ogl.mIntVertArray = new GLint[vLimit]; - GLfloat *floatTexArray = ogl->mFloatTexArray; - GLint *intVertArray = ogl->mIntVertArray; + GLfloat *floatTexArray = ogl.mFloatTexArray; + GLint *intVertArray = ogl.mIntVertArray; float texX2 = static_cast(srcX + w) / tw; float texY2 = static_cast(srcY + h) / th; @@ -871,19 +871,19 @@ void NormalOpenGLGraphics::calcTile(ImageVertexes *const vert, if (vp >= vLimit) { - ogl->ptr = vp; + ogl.ptr = vp; return; } } else { - if (!ogl->mIntTexArray) - ogl->mIntTexArray = new GLint[vLimit]; - if (!ogl->mIntVertArray) - ogl->mIntVertArray = new GLint[vLimit]; + 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.mIntTexArray; + GLint *intVertArray = ogl.mIntVertArray; intTexArray[vp + 0] = srcX; intTexArray[vp + 1] = srcY; @@ -912,11 +912,11 @@ void NormalOpenGLGraphics::calcTile(ImageVertexes *const vert, vp += 8; if (vp >= vLimit) { - ogl->ptr = vp; + ogl.ptr = vp; return; } } - ogl->ptr = vp; + ogl.ptr = vp; } void NormalOpenGLGraphics::drawTile(const ImageVertexes *const vert) @@ -925,7 +925,7 @@ void NormalOpenGLGraphics::drawTile(const ImageVertexes *const vert) return; Image *image = vert->image; - NormalOpenGLGraphicsVertexes *ogl = vert->ogl; + const NormalOpenGLGraphicsVertexes &ogl = vert->ogl; setColorAlpha(image->mAlpha); #ifdef DEBUG_BIND_TEXTURE @@ -935,9 +935,9 @@ void NormalOpenGLGraphics::drawTile(const ImageVertexes *const vert) setTexturingAndBlending(true); if (OpenGLImageHelper::mTextureType == GL_TEXTURE_2D) - drawQuadArrayfi(ogl->mIntVertArray, ogl->mFloatTexArray, ogl->ptr); + drawQuadArrayfi(ogl.mIntVertArray, ogl.mFloatTexArray, ogl.ptr); else - drawQuadArrayii(ogl->mIntVertArray, ogl->mIntTexArray, ogl->ptr); + drawQuadArrayii(ogl.mIntVertArray, ogl.mIntTexArray, ogl.ptr); } void NormalOpenGLGraphics::updateScreen() -- cgit v1.2.3-60-g2f50