summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-10-08 02:52:22 +0300
committerAndrei Karas <akaras@inbox.ru>2012-10-08 02:52:22 +0300
commit7760ed560001714494d7a7de470123a4cd565873 (patch)
treeeacc42d883a83191c94edb3e265c982ef8d963fc
parent56cfe4d3a38a2440622cf32f613a2b57ae5b3852 (diff)
downloadplus-7760ed560001714494d7a7de470123a4cd565873.tar.gz
plus-7760ed560001714494d7a7de470123a4cd565873.tar.bz2
plus-7760ed560001714494d7a7de470123a4cd565873.tar.xz
plus-7760ed560001714494d7a7de470123a4cd565873.zip
improve map draw speed.
-rw-r--r--src/graphics.cpp7
-rw-r--r--src/graphics.h2
-rw-r--r--src/graphicsvertexes.cpp7
-rw-r--r--src/graphicsvertexes.h2
-rw-r--r--src/maplayer.cpp27
-rw-r--r--src/normalopenglgraphics.cpp69
-rw-r--r--src/normalopenglgraphics.h16
-rw-r--r--src/safeopenglgraphics.cpp3
-rw-r--r--src/safeopenglgraphics.h2
9 files changed, 74 insertions, 61 deletions
diff --git a/src/graphics.cpp b/src/graphics.cpp
index 6657fe3c1..4580c1015 100644
--- a/src/graphics.cpp
+++ b/src/graphics.cpp
@@ -786,8 +786,9 @@ void Graphics::calcImagePattern(GraphicsVertexes* const vert,
vert->incPtr(1);
}
-void Graphics::calcTile(ImageVertexes *const vert, const Image *const image,
- int x, int y)
+void Graphics::calcTile(ImageVertexes *const vert A_UNUSED,
+ const Image *const image A_UNUSED,
+ int x A_UNUSED, int y A_UNUSED)
{
}
@@ -821,7 +822,7 @@ void Graphics::calcTile(ImageVertexes *const vert, int x, int y)
}
}
-void Graphics::drawTile(const ImageVertexes *const vert)
+void Graphics::drawTile(ImageVertexes *const vert)
{
// vert and img must be != 0
const Image *const img = vert->image;
diff --git a/src/graphics.h b/src/graphics.h
index b95bb3779..efe5d56b5 100644
--- a/src/graphics.h
+++ b/src/graphics.h
@@ -211,7 +211,7 @@ class Graphics : public gcn::SDLGraphics
virtual void calcTile(ImageVertexes *const vert, int x, int y);
- virtual void drawTile(const ImageVertexes *const vert);
+ virtual void drawTile(ImageVertexes *const vert);
virtual void drawImageRect2(GraphicsVertexes *const vert,
const ImageRect &imgRect);
diff --git a/src/graphicsvertexes.cpp b/src/graphicsvertexes.cpp
index 16fe7cec9..407d5ef0c 100644
--- a/src/graphicsvertexes.cpp
+++ b/src/graphicsvertexes.cpp
@@ -134,6 +134,13 @@ int NormalOpenGLGraphicsVertexes::continueVp()
}
}
+void NormalOpenGLGraphicsVertexes::updateVp(int n)
+{
+ if (!mVp.empty())
+ mVp.pop_back();
+ mVp.push_back(n);
+}
+
GLfloat *NormalOpenGLGraphicsVertexes::continueFloatTexArray()
{
if (mFloatTexPool.empty())
diff --git a/src/graphicsvertexes.h b/src/graphicsvertexes.h
index e13623650..c7e9b1961 100644
--- a/src/graphicsvertexes.h
+++ b/src/graphicsvertexes.h
@@ -96,6 +96,8 @@ class NormalOpenGLGraphicsVertexes final
int continueVp();
+ void updateVp(int n);
+
std::vector<int> *getVp()
{ return &mVp; }
diff --git a/src/maplayer.cpp b/src/maplayer.cpp
index f79c8c042..654cb7997 100644
--- a/src/maplayer.cpp
+++ b/src/maplayer.cpp
@@ -255,18 +255,16 @@ void MapLayer::updateOGL(Graphics *const graphics, int startX, int startY,
const bool flag = (debugFlags != Map::MAP_SPECIAL
&& debugFlags != Map::MAP_SPECIAL2);
+ MapRowVertexes *const row = new MapRowVertexes();
+ mTempRows.push_back(row);
+ Image *lastImage = nullptr;
+ ImageVertexes *imgVert = nullptr;
+ std::map<int, ImageVertexes*> imgSet;
+
for (int y = startY; y < endY; y++)
{
- MapRowVertexes *const row = new MapRowVertexes();
- mTempRows.push_back(row);
-
- Image *lastImage = nullptr;
- ImageVertexes *imgVert = nullptr;
-
const int yWidth = y * mWidth;
const int py0 = y * 32 + dy;
- std::map<Image*, ImageVertexes*> imgSet;
-
Image **tilePtr = mTiles + startX + yWidth;
for (int x = startX; x < endX; x++, tilePtr++)
{
@@ -282,20 +280,24 @@ void MapLayer::updateOGL(Graphics *const graphics, int startX, int startY,
if (img->mBounds.w > 32)
imgSet.clear();
- imgSet[lastImage] = imgVert;
- if (imgSet.find(img) != imgSet.end())
+ if (imgSet.find(img->mGLImage) != imgSet.end())
{
- imgVert = imgSet[img];
+ imgVert = imgSet[img->mGLImage];
}
else
{
+ if (lastImage)
+ imgSet[lastImage->mGLImage] = imgVert;
imgVert = new ImageVertexes();
+ imgVert->ogl.init();
imgVert->image = img;
row->images.push_back(imgVert);
}
lastImage = img;
}
lastImage = img;
+// if (imgVert->image->mGLImage != lastImage->mGLImage)
+// logger->log("wrong image draw");
graphics->calcTile(imgVert, lastImage, px, py);
}
}
@@ -308,6 +310,7 @@ void MapLayer::drawOGL(Graphics *const graphics)
{
MapRows::const_iterator rit = mTempRows.begin();
const MapRows::const_iterator rit_end = mTempRows.end();
+// int k = 0;
while (rit != rit_end)
{
MepRowImages *const images = &(*rit)->images;
@@ -317,9 +320,11 @@ void MapLayer::drawOGL(Graphics *const graphics)
{
graphics->drawTile(*iit);
++ iit;
+// k ++;
}
++ rit;
}
+// logger->log("draws: %d", k);
}
void MapLayer::drawFringe(Graphics *const graphics, int startX, int startY,
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<GLint*> &intVertPool = ogl.mIntVertPool;
std::vector<GLint*>::const_iterator iv;
std::vector<GLint*>::const_iterator iv_end = intVertPool.end();
@@ -820,11 +824,12 @@ void NormalOpenGLGraphics::calcTile(ImageVertexes *const vert,
const float tw = static_cast<float>(image->mTexWidth);
const float th = static_cast<float>(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<int> *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<float>(srcX) / tw;
float texY1 = static_cast<float>(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<float>(srcX + w) / tw;
float texY2 = static_cast<float>(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);
diff --git a/src/normalopenglgraphics.h b/src/normalopenglgraphics.h
index 64649f5c8..46f88bfe3 100644
--- a/src/normalopenglgraphics.h
+++ b/src/normalopenglgraphics.h
@@ -39,6 +39,8 @@
#include <set>
+class NormalOpenGLGraphicsVertexes;
+
class NormalOpenGLGraphics final : public Graphics
{
public:
@@ -90,7 +92,7 @@ class NormalOpenGLGraphics final : public Graphics
void calcTile(ImageVertexes *const vert, const Image *const image,
int x, int y) override;
- void drawTile(const ImageVertexes *const vert) override;
+ void drawTile(ImageVertexes *const vert) override;
void drawImagePattern2(GraphicsVertexes *const vert,
const Image *const image) override;
@@ -119,18 +121,22 @@ class NormalOpenGLGraphics final : public Graphics
void drawQuadArrayfi(int size);
- void drawQuadArrayfi(GLint *intVertArray, GLfloat *floatTexArray,
- int size);
+ void drawQuadArrayfi(GLint *intVertArray,
+ GLfloat *floatTexArray,
+ const int size);
void drawQuadArrayii(int size);
- void drawQuadArrayii(GLint *intVertArray, GLint *intTexArray,
- int size);
+ void drawQuadArrayii(GLint *intVertArray,
+ GLint *intTexArray,
+ const int size);
void drawLineArrayi(int size);
void drawLineArrayf(int size);
+ void drawVertexes(NormalOpenGLGraphicsVertexes &ogl);
+
void initArrays() override;
static void dumpSettings();
diff --git a/src/safeopenglgraphics.cpp b/src/safeopenglgraphics.cpp
index 457ef6dfe..c258298db 100644
--- a/src/safeopenglgraphics.cpp
+++ b/src/safeopenglgraphics.cpp
@@ -359,10 +359,9 @@ void SafeOpenGLGraphics::calcTile(ImageVertexes *const vert A_UNUSED,
const Image *const image A_UNUSED,
int x A_UNUSED, int y A_UNUSED)
{
-
}
-void SafeOpenGLGraphics::drawTile(const ImageVertexes *const vert A_UNUSED)
+void SafeOpenGLGraphics::drawTile(ImageVertexes *const vert A_UNUSED)
{
}
diff --git a/src/safeopenglgraphics.h b/src/safeopenglgraphics.h
index 1a0d06f46..f594c57e5 100644
--- a/src/safeopenglgraphics.h
+++ b/src/safeopenglgraphics.h
@@ -97,7 +97,7 @@ class SafeOpenGLGraphics final : public Graphics
void calcTile(ImageVertexes *const vert, const Image *const image,
int x, int y) override;
- void drawTile(const ImageVertexes *const vert) override;
+ void drawTile(ImageVertexes *const vert) override;
void updateScreen() override;