diff options
author | Andrei Karas <akaras@inbox.ru> | 2012-04-26 21:56:58 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2012-04-26 21:56:58 +0300 |
commit | 129b19f69fbbdcd896150aa8faa7f20254169c0c (patch) | |
tree | dd15d89fa3d6422139a0ba41a22f6f4db3f8b5ee /src/openglgraphics.cpp | |
parent | 5f5ea46910feefc212a98ea715b0d4b0d9d4bc23 (diff) | |
download | manaplus-129b19f69fbbdcd896150aa8faa7f20254169c0c.tar.gz manaplus-129b19f69fbbdcd896150aa8faa7f20254169c0c.tar.bz2 manaplus-129b19f69fbbdcd896150aa8faa7f20254169c0c.tar.xz manaplus-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.
Diffstat (limited to 'src/openglgraphics.cpp')
-rw-r--r-- | src/openglgraphics.cpp | 58 |
1 files changed, 55 insertions, 3 deletions
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 |