summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-04-26 21:56:58 +0300
committerAndrei Karas <akaras@inbox.ru>2012-04-26 21:56:58 +0300
commit129b19f69fbbdcd896150aa8faa7f20254169c0c (patch)
treedd15d89fa3d6422139a0ba41a22f6f4db3f8b5ee
parent5f5ea46910feefc212a98ea715b0d4b0d9d4bc23 (diff)
downloadplus-129b19f69fbbdcd896150aa8faa7f20254169c0c.tar.gz
plus-129b19f69fbbdcd896150aa8faa7f20254169c0c.tar.bz2
plus-129b19f69fbbdcd896150aa8faa7f20254169c0c.tar.xz
plus-129b19f69fbbdcd896150aa8faa7f20254169c0c.zip
Add to log draw backend name.
Add ability to get free video memory (fast openg with NVIDIA). Add test with id 100 for long perfomance testing.
-rw-r--r--src/graphics.cpp1
-rw-r--r--src/graphics.h3
-rw-r--r--src/opengl1graphics.cpp6
-rw-r--r--src/openglgraphics.cpp58
-rw-r--r--src/openglgraphics.h12
-rw-r--r--src/test/testlauncher.cpp50
-rw-r--r--src/test/testlauncher.h2
-rw-r--r--src/utils/stringutils.cpp13
-rw-r--r--src/utils/stringutils.h3
9 files changed, 144 insertions, 4 deletions
diff --git a/src/graphics.cpp b/src/graphics.cpp
index 44ff11783..04754a975 100644
--- a/src/graphics.cpp
+++ b/src/graphics.cpp
@@ -70,6 +70,7 @@ Graphics::~Graphics()
bool Graphics::setVideoMode(int w, int h, int bpp, bool fs,
bool hwaccel, bool resize, bool noFrame)
{
+ logger->log1("graphics backend: software");
logger->log("Setting video mode %dx%d %s",
w, h, fs ? "fullscreen" : "windowed");
diff --git a/src/graphics.h b/src/graphics.h
index 0955bf6d7..3ae2a7718 100644
--- a/src/graphics.h
+++ b/src/graphics.h
@@ -254,6 +254,9 @@ class Graphics : public gcn::SDLGraphics
virtual void prepareScreenshot()
{ }
+ virtual int getMemoryUsage()
+ { return 0; }
+
virtual bool drawNet(int x1, int y1, int x2, int y2,
int width, int height);
diff --git a/src/opengl1graphics.cpp b/src/opengl1graphics.cpp
index b04deedac..8563ab0d2 100644
--- a/src/opengl1graphics.cpp
+++ b/src/opengl1graphics.cpp
@@ -65,6 +65,7 @@ void OpenGL1Graphics::setSync(bool sync)
bool OpenGL1Graphics::setVideoMode(int w, int h, int bpp, bool fs,
bool hwaccel, bool resize, bool noFrame)
{
+ logger->log1("graphics backend: safe OpenGL");
logger->log("Setting video mode %dx%d %s",
w, h, fs ? "fullscreen" : "windowed");
@@ -118,10 +119,15 @@ bool OpenGL1Graphics::setVideoMode(int w, int h, int bpp, bool fs,
char const *glExtensions = reinterpret_cast<char const *>(
glGetString(GL_EXTENSIONS));
+
+ logger->log1("opengl extensions: ");
+ logger->log1(glExtensions);
+
GLint texSize;
bool rectTex = strstr(glExtensions, "GL_ARB_texture_rectangle");
if (rectTex)
{
+ logger->log1("using GL_ARB_texture_rectangle");
Image::mTextureType = GL_TEXTURE_RECTANGLE_ARB;
glGetIntegerv(GL_MAX_RECTANGLE_TEXTURE_SIZE_ARB, &texSize);
}
diff --git a/src/openglgraphics.cpp b/src/openglgraphics.cpp
index aba5a7233..e5523c479 100644
--- a/src/openglgraphics.cpp
+++ b/src/openglgraphics.cpp
@@ -46,13 +46,21 @@
#define GL_MAX_RECTANGLE_TEXTURE_SIZE_ARB 0x84F8
#endif
+#ifndef GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX
+//#define GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX 0x9047
+//#define GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX 0x9048
+#define GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX 0x9049
+//#define GPU_MEMORY_INFO_EVICTION_COUNT_NVX 0x904A
+//#define GPU_MEMORY_INFO_EVICTED_MEMORY_NVX 0x904B
+#endif
+
const unsigned int vertexBufSize = 500;
GLuint OpenGLGraphics::mLastImage = 0;
OpenGLGraphics::OpenGLGraphics():
mAlpha(false), mTexture(false), mColorAlpha(false), mSync(false),
- mFboId(0), mTextureId(0), mRboId(0)
+ mFboId(0), mTextureId(0), mRboId(0), mStartFreeMem(0)
{
mOpenGL = 1;
mFloatTexArray = new GLfloat[vertexBufSize * 4 + 30];
@@ -75,6 +83,7 @@ void OpenGLGraphics::setSync(bool sync)
bool OpenGLGraphics::setVideoMode(int w, int h, int bpp, bool fs,
bool hwaccel, bool resize, bool noFrame)
{
+ logger->log1("graphics backend: fast OpenGL");
logger->log("Setting video mode %dx%d %s",
w, h, fs ? "fullscreen" : "windowed");
@@ -135,10 +144,19 @@ bool OpenGLGraphics::setVideoMode(int w, int h, int bpp, bool fs,
char const *glExtensions = reinterpret_cast<char const *>(
glGetString(GL_EXTENSIONS));
+
+ logger->log1("opengl extensions: ");
+ logger->log1(glExtensions);
+
+ splitToStringSet(mExtensions, glExtensions, ' ');
+
+ updateMemoryInfo();
+
GLint texSize;
- bool rectTex = strstr(glExtensions, "GL_ARB_texture_rectangle");
+ bool rectTex = supportExtension("GL_ARB_texture_rectangle");
if (rectTex)
{
+ logger->log1("using GL_ARB_texture_rectangle");
Image::mTextureType = GL_TEXTURE_RECTANGLE_ARB;
glGetIntegerv(GL_MAX_RECTANGLE_TEXTURE_SIZE_ARB, &texSize);
}
@@ -1452,7 +1470,7 @@ void OpenGLGraphics::dumpSettings()
}
}
-void OpenGLGraphics::logString(char *format, GLenum num)
+void OpenGLGraphics::logString(const char *format, GLenum num)
{
const char *str = reinterpret_cast<const char*>(glGetString(num));
if (!str)
@@ -1460,4 +1478,38 @@ void OpenGLGraphics::logString(char *format, GLenum num)
else
logger->log(format, str);
}
+
+bool OpenGLGraphics::supportExtension(std::string name)
+{
+ return mExtensions.find(name) != mExtensions.end();
+}
+
+void OpenGLGraphics::updateMemoryInfo()
+{
+ if (mStartFreeMem)
+ return;
+
+ if (supportExtension("GL_NVX_gpu_memory_info"))
+ {
+ glGetIntegerv(GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX,
+ &mStartFreeMem);
+ logger->log("free video memory: %d", mStartFreeMem);
+ }
+}
+
+int OpenGLGraphics::getMemoryUsage()
+{
+ if (!mStartFreeMem)
+ return 0;
+
+ if (supportExtension("GL_NVX_gpu_memory_info"))
+ {
+ GLint val;
+ glGetIntegerv(GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX,
+ &val);
+ return mStartFreeMem - val;
+ }
+ return 0;
+}
+
#endif // USE_OPENGL
diff --git a/src/openglgraphics.h b/src/openglgraphics.h
index d602f3126..652447447 100644
--- a/src/openglgraphics.h
+++ b/src/openglgraphics.h
@@ -34,6 +34,8 @@
#include <SDL_opengl.h>
//#include <GL/glext.h>
+#include <set>
+
class OpenGLGraphics : public Graphics
{
public:
@@ -144,6 +146,10 @@ class OpenGLGraphics : public Graphics
bool drawNet(int x1, int y1, int x2, int y2, int width, int height);
+ bool supportExtension(std::string name);
+
+ int getMemoryUsage();
+
static void bindTexture(GLenum target, GLuint texture);
static GLuint mLastImage;
@@ -151,7 +157,9 @@ class OpenGLGraphics : public Graphics
protected:
void setTexturingAndBlending(bool enable);
- void logString(char *format, GLenum num);
+ void logString(const char *format, GLenum num);
+
+ void updateMemoryInfo();
private:
GLfloat *mFloatTexArray;
@@ -163,6 +171,8 @@ class OpenGLGraphics : public Graphics
GLuint mFboId;
GLuint mTextureId;
GLuint mRboId;
+ std::set<std::string> mExtensions;
+ GLint mStartFreeMem;
};
#endif
diff --git a/src/test/testlauncher.cpp b/src/test/testlauncher.cpp
index d3caa8938..55273ab41 100644
--- a/src/test/testlauncher.cpp
+++ b/src/test/testlauncher.cpp
@@ -69,6 +69,8 @@ int TestLauncher::exec()
return testRescale();
else if (mTest == "8" || mTest == "9" || mTest == "10")
return testFps();
+ else if (mTest == "100")
+ return testInternal();
return -1;
}
@@ -155,6 +157,54 @@ int TestLauncher::testFps()
return 0;
}
+int TestLauncher::testInternal()
+{
+ timeval start;
+ timeval end;
+
+ Wallpaper::loadWallpapers();
+ Wallpaper::getWallpaper(800, 600);
+ Image *img[4];
+
+ img[0] = Theme::getImageFromTheme("graphics/sprites/manaplus_emotions.png");
+ img[1] = Theme::getImageFromTheme("graphics/sprites/manaplus_emotions.png");
+ img[2] = Theme::getImageFromTheme("graphics/sprites/arrow_left.gif");
+ img[3] = Theme::getImageFromTheme("graphics/sprites/arrow_right.gif");
+ int idx = 0;
+ int mem = mainGraphics->getMemoryUsage();
+
+// int cnt = 5;
+ int cnt = 5000;
+
+ gettimeofday(&start, nullptr);
+ for (int k = 0; k < cnt; k ++)
+ {
+ for (int x = 0; x < 800; x += 20)
+ {
+ for (int y = 0; y < 600; y += 25)
+ {
+ mainGraphics->drawImage(img[idx], x, y);
+ mainGraphics->drawImage(img[idx], x + 1, y);
+ mainGraphics->drawImage(img[idx], x, y + 5);
+
+ idx ++;
+ if (idx > 3)
+ idx = 0;
+ }
+ }
+ mainGraphics->updateScreen();
+ }
+
+ gettimeofday(&end, nullptr);
+ int tFps = calcFps(&start, &end, cnt);
+ file << mTest << std::endl;
+ file << tFps << std::endl;
+ file << mem << std::endl;
+
+ sleep(1);
+ return 0;
+}
+
int TestLauncher::calcFps(timeval *start, timeval *end, int calls)
{
long mtime;
diff --git a/src/test/testlauncher.h b/src/test/testlauncher.h
index b1031a9c1..1f86dc396 100644
--- a/src/test/testlauncher.h
+++ b/src/test/testlauncher.h
@@ -45,6 +45,8 @@ class TestLauncher
int testFps();
+ int testInternal();
+
private:
std::string mTest;
diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp
index fcafd7711..1808ea173 100644
--- a/src/utils/stringutils.cpp
+++ b/src/utils/stringutils.cpp
@@ -460,6 +460,19 @@ void splitToStringVector(StringVect &tokens, const std::string &text,
}
}
+void splitToStringSet(std::set<std::string> &tokens, const std::string &text,
+ char separator)
+{
+ std::stringstream ss(text);
+ std::string item;
+ while (std::getline(ss, item, separator))
+ {
+ item = trim(item);
+ if (!item.empty())
+ tokens.insert(item);
+ }
+}
+
std::string combineDye(std::string file, std::string dye)
{
if (dye.empty())
diff --git a/src/utils/stringutils.h b/src/utils/stringutils.h
index 94c455025..917ea3ab6 100644
--- a/src/utils/stringutils.h
+++ b/src/utils/stringutils.h
@@ -182,6 +182,9 @@ std::list<std::string> splitToStringList(const std::string &text,
void splitToStringVector(StringVect &tokens,
const std::string &text, char separator);
+void splitToStringSet(std::set<std::string> &tokens,
+ const std::string &text, char separator);
+
std::string combineDye(std::string file, std::string dye);
std::string combineDye2(std::string file, std::string dye);