summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-11-20 13:29:10 +0300
committerAndrei Karas <akaras@inbox.ru>2012-11-20 22:21:59 +0300
commit6637f4af57cd60008388bfefda1c37376c9d7042 (patch)
treeeb31d1c197c86583e5f2a525ca020de625f32919 /src
parentcadc0f8b6d0bd71f319c3e6576af05dcd0a7533f (diff)
downloadplus-6637f4af57cd60008388bfefda1c37376c9d7042.tar.gz
plus-6637f4af57cd60008388bfefda1c37376c9d7042.tar.bz2
plus-6637f4af57cd60008388bfefda1c37376c9d7042.tar.xz
plus-6637f4af57cd60008388bfefda1c37376c9d7042.zip
Add debug option to show draw calls per frame.
Also fix map draw and text in debug window with mobile OpenGL.
Diffstat (limited to 'src')
-rw-r--r--src/graphics.h4
-rw-r--r--src/gui/debugwindow.cpp21
-rw-r--r--src/gui/debugwindow.h3
-rw-r--r--src/localconsts.h3
-rw-r--r--src/map.cpp4
-rw-r--r--src/mobileopenglgraphics.cpp31
-rw-r--r--src/mobileopenglgraphics.h9
-rw-r--r--src/normalopenglgraphics.cpp41
-rw-r--r--src/normalopenglgraphics.h9
9 files changed, 120 insertions, 5 deletions
diff --git a/src/graphics.h b/src/graphics.h
index d538ef7af..6ef38350a 100644
--- a/src/graphics.h
+++ b/src/graphics.h
@@ -321,6 +321,10 @@ class Graphics : public gcn::SDLGraphics
virtual void initArrays()
{ }
+#ifdef DEBUG_DRAW_CALLS
+ virtual unsigned int getDrawCalls() const
+ { return 0; }
+#endif
int mWidth;
int mHeight;
diff --git a/src/gui/debugwindow.cpp b/src/gui/debugwindow.cpp
index 11a8ca3c0..6e11f83c5 100644
--- a/src/gui/debugwindow.cpp
+++ b/src/gui/debugwindow.cpp
@@ -155,6 +155,10 @@ MapDebugTab::MapDebugTab(const Widget2 *const widget) :
mXYLabel(new Label(this, strprintf("%s (?,?)", _("Player Position:")))),
mTexturesLabel(nullptr),
mUpdateTime(0),
+#ifdef DEBUG_DRAW_CALLS
+ mDrawCallsLabel(new Label(this, strprintf("%s %s",
+ _("Draw calls:"), "?"))),
+#endif
mFPSLabel(new Label(this, strprintf(_("%d FPS"), 0))),
mLPSLabel(new Label(this, strprintf(_("%d LPS"), 0)))
{
@@ -174,6 +178,9 @@ MapDebugTab::MapDebugTab(const Widget2 *const widget) :
case 2:
mFPSText = _("%d FPS (old OpenGL)");
break;
+ case 3:
+ mFPSText = _("%d FPS (mobile OpenGL)");
+ break;
};
#else
mFPSText = _("%d FPS (Software)");
@@ -189,10 +196,15 @@ MapDebugTab::MapDebugTab(const Widget2 *const widget) :
place(0, 7, mParticleCountLabel, 2);
place(0, 8, mMapActorCountLabel, 2);
#ifdef USE_OPENGL
+ int n = 9;
#ifdef DEBUG_OPENGL_LEAKS
mTexturesLabel = new Label(this, strprintf("%s %s",
_("Textures count:"), "?"));
- place(0, 9, mTexturesLabel, 2);
+ place(0, n, mTexturesLabel, 2);
+ n ++;
+#endif
+#ifdef DEBUG_DRAW_CALLS
+ place(0, n, mDrawCallsLabel, 2);
#endif
#endif
place.getCell().matchColWidth(0, 0);
@@ -245,6 +257,13 @@ void MapDebugTab::logic()
mTexturesLabel->setCaption(strprintf("%s %d",
_("Textures count:"), textures_count));
#endif
+#ifdef DEBUG_DRAW_CALLS
+ if (mainGraphics)
+ {
+ mDrawCallsLabel->setCaption(strprintf("%s %d",
+ _("Draw calls:"), mainGraphics->getDrawCalls()));
+ }
+#endif
#endif
}
}
diff --git a/src/gui/debugwindow.h b/src/gui/debugwindow.h
index 5828269c3..62d7aa34f 100644
--- a/src/gui/debugwindow.h
+++ b/src/gui/debugwindow.h
@@ -72,6 +72,9 @@ class MapDebugTab final : public DebugTab
Label *mXYLabel;
Label *mTexturesLabel;
int mUpdateTime;
+#ifdef DEBUG_DRAW_CALLS
+ Label *mDrawCallsLabel;
+#endif
Label *mFPSLabel;
Label *mLPSLabel;
std::string mFPSText;
diff --git a/src/localconsts.h b/src/localconsts.h
index 91c2bb904..1fe828460 100644
--- a/src/localconsts.h
+++ b/src/localconsts.h
@@ -68,4 +68,7 @@
//profiler
//#define USE_PROFILER 1
+//draw calls
+//#define DEBUG_DRAW_CALLS 1
+
#include "utils/perfomance.h"
diff --git a/src/map.cpp b/src/map.cpp
index f0fae1a9c..d5f61261c 100644
--- a/src/map.cpp
+++ b/src/map.cpp
@@ -364,7 +364,7 @@ void Map::draw(Graphics *graphics, int scrollX, int scrollY)
#ifdef USE_OPENGL
int updateFlag = 0;
- if (mOpenGL == 1)
+ if (mOpenGL == 1 || mOpenGL == 3)
{
if (mLastX != startX || mLastY != startY || mLastScrollX != scrollX
|| mLastScrollY != scrollY)
@@ -418,7 +418,7 @@ void Map::draw(Graphics *graphics, int scrollX, int scrollY)
else
{
#ifdef USE_OPENGL
- if (mOpenGL == 1 && updateFlag != 2)
+ if ((mOpenGL == 1 || mOpenGL == 3) && updateFlag != 2)
{
if (updateFlag)
{
diff --git a/src/mobileopenglgraphics.cpp b/src/mobileopenglgraphics.cpp
index 504df6897..dcfe18a92 100644
--- a/src/mobileopenglgraphics.cpp
+++ b/src/mobileopenglgraphics.cpp
@@ -41,6 +41,10 @@
#include "debug.h"
GLuint MobileOpenGLGraphics::mLastImage = 0;
+#ifdef DEBUG_DRAW_CALLS
+unsigned int MobileOpenGLGraphics::mDrawCalls = 0;
+unsigned int MobileOpenGLGraphics::mLastDrawCalls = 0;
+#endif
//unsigned int vertexBufSize = 500;
@@ -135,6 +139,9 @@ static inline void drawQuad(const Image *image,
glVertexPointer(2, GL_SHORT, 0, &vert);
glTexCoordPointer(2, GL_FLOAT, 0, &tex);
+#ifdef DEBUG_DRAW_CALLS
+ MobileOpenGLGraphics::mDrawCalls ++;
+#endif
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
}
@@ -177,6 +184,9 @@ static inline void drawRescaledQuad(const Image *const image,
glVertexPointer(2, GL_SHORT, 0, &vert);
glTexCoordPointer(2, GL_FLOAT, 0, &tex);
+#ifdef DEBUG_DRAW_CALLS
+ MobileOpenGLGraphics::mDrawCalls ++;
+#endif
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
}
@@ -745,9 +755,11 @@ void MobileOpenGLGraphics::updateScreen()
BLOCK_START("Graphics::updateScreen")
// glFlush();
// glFinish();
-// setTexturingAndBlending(true);
+#ifdef DEBUG_DRAW_CALLS
+ mLastDrawCalls = mDrawCalls;
+ mDrawCalls = 0;
+#endif
SDL_GL_SwapBuffers();
-// mLastImage = 0;
// may be need clear?
// glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
BLOCK_END("Graphics::updateScreen")
@@ -1013,6 +1025,9 @@ void MobileOpenGLGraphics::drawRectangle(const gcn::Rectangle& rect,
};
glVertexPointer(2, GL_SHORT, 0, &vert);
+#ifdef DEBUG_DRAW_CALLS
+ mDrawCalls ++;
+#endif
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
else
@@ -1026,6 +1041,9 @@ void MobileOpenGLGraphics::drawRectangle(const gcn::Rectangle& rect,
};
glVertexPointer(2, GL_SHORT, 0, &vert);
+#ifdef DEBUG_DRAW_CALLS
+ mDrawCalls ++;
+#endif
glDrawArrays(GL_LINE_LOOP, 0, 4);
}
BLOCK_END("Graphics::drawRectangle")
@@ -1098,6 +1116,9 @@ inline void MobileOpenGLGraphics::drawTriangleArrayfs(int size)
glVertexPointer(2, GL_SHORT, 0, mShortVertArray);
glTexCoordPointer(2, GL_FLOAT, 0, mFloatTexArray);
+#ifdef DEBUG_DRAW_CALLS
+ mDrawCalls ++;
+#endif
glDrawArrays(GL_TRIANGLES, 0, size / 2);
}
@@ -1110,6 +1131,9 @@ inline void MobileOpenGLGraphics::drawTriangleArrayfs(GLshort *const
glVertexPointer(2, GL_SHORT, 0, shortVertArray);
glTexCoordPointer(2, GL_FLOAT, 0, floatTexArray);
+#ifdef DEBUG_DRAW_CALLS
+ mDrawCalls ++;
+#endif
glDrawArrays(GL_TRIANGLES, 0, size / 2);
}
@@ -1117,6 +1141,9 @@ inline void MobileOpenGLGraphics::drawLineArrays(int size)
{
glVertexPointer(2, GL_SHORT, 0, mShortVertArray);
+#ifdef DEBUG_DRAW_CALLS
+ mDrawCalls ++;
+#endif
glDrawArrays(GL_LINES, 0, size / 2);
}
diff --git a/src/mobileopenglgraphics.h b/src/mobileopenglgraphics.h
index 4402904b7..046fb1f0e 100644
--- a/src/mobileopenglgraphics.h
+++ b/src/mobileopenglgraphics.h
@@ -155,6 +155,15 @@ class MobileOpenGLGraphics final : public Graphics
void updateTextureFormat();
+#ifdef DEBUG_DRAW_CALLS
+ virtual unsigned int getDrawCalls() const
+ { return mLastDrawCalls; }
+
+ static unsigned int mDrawCalls;
+
+ static unsigned int mLastDrawCalls;
+#endif
+
static void bindTexture(GLenum target, GLuint texture);
static GLuint mLastImage;
diff --git a/src/normalopenglgraphics.cpp b/src/normalopenglgraphics.cpp
index 40cd5226b..188a57d69 100644
--- a/src/normalopenglgraphics.cpp
+++ b/src/normalopenglgraphics.cpp
@@ -40,6 +40,10 @@
#include "debug.h"
GLuint NormalOpenGLGraphics::mLastImage = 0;
+#ifdef DEBUG_DRAW_CALLS
+unsigned int NormalOpenGLGraphics::mDrawCalls = 0;
+unsigned int NormalOpenGLGraphics::mLastDrawCalls = 0;
+#endif
//unsigned int vertexBufSize = 500;
@@ -130,6 +134,9 @@ static inline void drawQuad(const Image *image,
glVertexPointer(2, GL_INT, 0, &vert);
glTexCoordPointer(2, GL_FLOAT, 0, &tex);
+#ifdef DEBUG_DRAW_CALLS
+ NormalOpenGLGraphics::mDrawCalls ++;
+#endif
glDrawArrays(GL_QUADS, 0, 4);
}
else
@@ -152,6 +159,9 @@ static inline void drawQuad(const Image *image,
glVertexPointer(2, GL_INT, 0, &vert);
glTexCoordPointer(2, GL_INT, 0, &tex);
+#ifdef DEBUG_DRAW_CALLS
+ NormalOpenGLGraphics::mDrawCalls ++;
+#endif
glDrawArrays(GL_QUADS, 0, 4);
}
}
@@ -192,6 +202,9 @@ static inline void drawRescaledQuad(const Image *const image,
glVertexPointer(2, GL_INT, 0, &vert);
glTexCoordPointer(2, GL_FLOAT, 0, &tex);
+#ifdef DEBUG_DRAW_CALLS
+ NormalOpenGLGraphics::mDrawCalls ++;
+#endif
glDrawArrays(GL_QUADS, 0, 4);
}
else
@@ -214,6 +227,9 @@ static inline void drawRescaledQuad(const Image *const image,
glVertexPointer(2, GL_INT, 0, &vert);
glTexCoordPointer(2, GL_INT, 0, &tex);
+#ifdef DEBUG_DRAW_CALLS
+ NormalOpenGLGraphics::mDrawCalls ++;
+#endif
glDrawArrays(GL_QUADS, 0, 4);
}
}
@@ -934,6 +950,10 @@ void NormalOpenGLGraphics::updateScreen()
BLOCK_START("Graphics::updateScreen")
// glFlush();
// glFinish();
+#ifdef DEBUG_DRAW_CALLS
+ mLastDrawCalls = mDrawCalls;
+ mDrawCalls = 0;
+#endif
SDL_GL_SwapBuffers();
// may be need clear?
// glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
@@ -1197,6 +1217,9 @@ void NormalOpenGLGraphics::drawRectangle(const gcn::Rectangle& rect,
};
glVertexPointer(2, GL_FLOAT, 0, &vert);
+#ifdef DEBUG_DRAW_CALLS
+ mDrawCalls ++;
+#endif
glDrawArrays(filled ? GL_QUADS : GL_LINE_LOOP, 0, 4);
BLOCK_END("Graphics::drawRectangle")
}
@@ -1268,6 +1291,9 @@ inline void NormalOpenGLGraphics::drawQuadArrayfi(int size)
glVertexPointer(2, GL_INT, 0, mIntVertArray);
glTexCoordPointer(2, GL_FLOAT, 0, mFloatTexArray);
+#ifdef DEBUG_DRAW_CALLS
+ mDrawCalls ++;
+#endif
glDrawArrays(GL_QUADS, 0, size / 2);
}
@@ -1278,6 +1304,9 @@ inline void NormalOpenGLGraphics::drawQuadArrayfi(GLint *const intVertArray,
glVertexPointer(2, GL_INT, 0, intVertArray);
glTexCoordPointer(2, GL_FLOAT, 0, floatTexArray);
+#ifdef DEBUG_DRAW_CALLS
+ mDrawCalls ++;
+#endif
glDrawArrays(GL_QUADS, 0, size / 2);
}
@@ -1286,6 +1315,9 @@ inline void NormalOpenGLGraphics::drawQuadArrayii(int size)
glVertexPointer(2, GL_INT, 0, mIntVertArray);
glTexCoordPointer(2, GL_INT, 0, mIntTexArray);
+#ifdef DEBUG_DRAW_CALLS
+ mDrawCalls ++;
+#endif
glDrawArrays(GL_QUADS, 0, size / 2);
}
@@ -1296,6 +1328,9 @@ inline void NormalOpenGLGraphics::drawQuadArrayii(GLint *const intVertArray,
glVertexPointer(2, GL_INT, 0, intVertArray);
glTexCoordPointer(2, GL_INT, 0, intTexArray);
+#ifdef DEBUG_DRAW_CALLS
+ mDrawCalls ++;
+#endif
glDrawArrays(GL_QUADS, 0, size / 2);
}
@@ -1303,6 +1338,9 @@ inline void NormalOpenGLGraphics::drawLineArrayi(int size)
{
glVertexPointer(2, GL_INT, 0, mIntVertArray);
+#ifdef DEBUG_DRAW_CALLS
+ mDrawCalls ++;
+#endif
glDrawArrays(GL_LINES, 0, size / 2);
}
@@ -1310,6 +1348,9 @@ inline void NormalOpenGLGraphics::drawLineArrayf(int size)
{
glVertexPointer(2, GL_FLOAT, 0, mFloatTexArray);
+#ifdef DEBUG_DRAW_CALLS
+ mDrawCalls ++;
+#endif
glDrawArrays(GL_LINES, 0, size / 2);
}
diff --git a/src/normalopenglgraphics.h b/src/normalopenglgraphics.h
index 4c9d9e417..5894aa957 100644
--- a/src/normalopenglgraphics.h
+++ b/src/normalopenglgraphics.h
@@ -163,6 +163,15 @@ class NormalOpenGLGraphics final : public Graphics
void updateTextureFormat();
+#ifdef DEBUG_DRAW_CALLS
+ virtual unsigned int getDrawCalls() const
+ { return mLastDrawCalls; }
+
+ static unsigned int mDrawCalls;
+
+ static unsigned int mLastDrawCalls;
+#endif
+
static void bindTexture(GLenum target, GLuint texture);
static GLuint mLastImage;