summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-04-29 16:28:15 +0300
committerAndrei Karas <akaras@inbox.ru>2012-04-29 17:14:01 +0300
commitc25672bd63cce049e931030f70629eb689cf43eb (patch)
treed39d163d02f1c02d5c6cf87ebf98be86493eb45f /src
parent47329e695c95031491161cf45e1fbd118a8797e6 (diff)
downloadplus-c25672bd63cce049e931030f70629eb689cf43eb.tar.gz
plus-c25672bd63cce049e931030f70629eb689cf43eb.tar.bz2
plus-c25672bd63cce049e931030f70629eb689cf43eb.tar.xz
plus-c25672bd63cce049e931030f70629eb689cf43eb.zip
Add graphicsmanager class and move some code to it.
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/Makefile.am2
-rw-r--r--src/client.cpp30
-rw-r--r--src/graphics.cpp176
-rw-r--r--src/graphics.h24
-rw-r--r--src/graphicsmanager.cpp144
-rw-r--r--src/graphicsmanager.h52
-rw-r--r--src/gui/widgets/itemcontainer.cpp2
-rw-r--r--src/opengl1graphics.cpp81
-rw-r--r--src/openglgraphics.cpp192
-rw-r--r--src/openglgraphics.h4
11 files changed, 392 insertions, 317 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 216538041..68a0966a9 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -530,6 +530,8 @@ SET(SRCS
game.h
graphics.cpp
graphics.h
+ graphicsmanager.cpp
+ graphicsmanager.h
graphicsvertexes.cpp
graphicsvertexes.h
guichanfwd.h
diff --git a/src/Makefile.am b/src/Makefile.am
index 293d2bc5a..1f6ebd60f 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -548,6 +548,8 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \
game.h \
graphics.cpp \
graphics.h \
+ graphicsmanager.cpp \
+ graphicsmanager.h \
graphicsvertexes.cpp \
graphicsvertexes.h \
guichanfwd.h \
diff --git a/src/client.cpp b/src/client.cpp
index d85251390..d3a11b369 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -32,6 +32,7 @@
#include "game.h"
#include "guild.h"
#include "guildmanager.h"
+#include "graphicsmanager.h"
#include "graphicsvertexes.h"
#include "itemshortcut.h"
#include "joystick.h"
@@ -509,34 +510,7 @@ void Client::gameInit()
}
#endif
-#ifdef USE_OPENGL
- int useOpenGL = 0;
- if (!mOptions.noOpenGL)
- useOpenGL = config.getIntValue("opengl");
-
- // Setup image loading for the right image format
- Image::setLoadAsOpenGL(useOpenGL);
- GraphicsVertexes::setLoadAsOpenGL(useOpenGL);
-
- // Create the graphics context
- switch (useOpenGL)
- {
- case 0:
- mainGraphics = new Graphics;
- break;
- case 1:
- default:
- mainGraphics = new OpenGLGraphics;
- break;
- case 2:
- mainGraphics = new OpenGL1Graphics;
- break;
- };
-
-#else
- // Create the graphics context
- mainGraphics = new Graphics;
-#endif
+ graphicsManager.initGraphics(mOptions.noOpenGL);
runCounters = config.getBoolValue("packetcounters");
diff --git a/src/graphics.cpp b/src/graphics.cpp
index f07c6b48d..677172420 100644
--- a/src/graphics.cpp
+++ b/src/graphics.cpp
@@ -22,6 +22,10 @@
#include "graphics.h"
+#include "main.h"
+
+#include "configuration.h"
+#include "graphicsmanager.h"
#include "graphicsvertexes.h"
#include "logger.h"
@@ -36,11 +40,21 @@
#include "debug.h"
+#ifdef USE_OPENGL
+#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
+#endif
+
static unsigned int *cR = nullptr;
static unsigned int *cG = nullptr;
static unsigned int *cB = nullptr;
-Graphics::Graphics():
+Graphics::Graphics() :
mWidth(0),
mHeight(0),
mBpp(0),
@@ -54,7 +68,9 @@ Graphics::Graphics():
mEnableResize(false),
mNoFrame(false),
mOldPixel(0),
- mOldAlpha(0)
+ mOldAlpha(0),
+ mName("Software"),
+ mStartFreeMem(0)
{
mRect.x = 0;
mRect.y = 0;
@@ -67,15 +83,13 @@ Graphics::~Graphics()
_endDraw();
}
-bool Graphics::setVideoMode(int w, int h, int bpp, bool fs,
+void Graphics::setMainFlags(int w, int h, int bpp, bool fs,
bool hwaccel, bool resize, bool noFrame)
{
- logger->log1("graphics backend: software");
+ logger->log("graphics backend: %s", getName().c_str());
logger->log("Setting video mode %dx%d %s",
w, h, fs ? "fullscreen" : "windowed");
- int displayFlags = SDL_ANYFORMAT;
-
mWidth = w;
mHeight = h;
mBpp = bpp;
@@ -83,23 +97,160 @@ bool Graphics::setVideoMode(int w, int h, int bpp, bool fs,
mHWAccel = hwaccel;
mEnableResize = resize;
mNoFrame = noFrame;
+}
+
+int Graphics::getOpenGLFlags()
+{
+#ifdef USE_OPENGL
+ int displayFlags = SDL_ANYFORMAT | SDL_OPENGL;
- if (fs)
+ if (mFullscreen)
+ {
displayFlags |= SDL_FULLSCREEN;
- else if (resize)
+ }
+ else
+ {
+ // Resizing currently not supported on Windows, where it would require
+ // reuploading all textures.
+#if !defined(_WIN32)
+ if (mEnableResize)
+ displayFlags |= SDL_RESIZABLE;
+#endif
+ }
+
+ if (mNoFrame)
+ displayFlags |= SDL_NOFRAME;
+
+ return displayFlags;
+#else
+ return 0;
+#endif
+}
+
+bool Graphics::setOpenGLMode()
+{
+#ifdef USE_OPENGL
+ SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
+ if (!(mTarget = SDL_SetVideoMode(mWidth, mHeight, mBpp, getOpenGLFlags())))
+ return false;
+
+#ifdef __APPLE__
+ if (mSync)
+ {
+ const GLint VBL = 1;
+ CGLSetParameter(CGLGetCurrentContext(), kCGLCPSwapInterval, &VBL);
+ }
+#endif
+
+ graphicsManager.logString("gl vendor: %s", GL_VENDOR);
+ graphicsManager.logString("gl renderer: %s", GL_RENDERER);
+ graphicsManager.logString("gl version: %s", GL_VERSION);
+
+ // Setup OpenGL
+ glViewport(0, 0, mWidth, mHeight);
+ glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
+ int gotDoubleBuffer;
+ SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER, &gotDoubleBuffer);
+ logger->log("Using OpenGL %s double buffering.",
+ (gotDoubleBuffer ? "with" : "without"));
+
+ char const *glExtensions = reinterpret_cast<char const *>(
+ glGetString(GL_EXTENSIONS));
+
+ logger->log1("opengl extensions: ");
+ logger->log1(glExtensions);
+
+ graphicsManager.updateExtensions(glExtensions);
+
+ graphicsManager.updateTextureFormat();
+ updateMemoryInfo();
+
+ GLint texSize;
+ bool rectTex = graphicsManager.supportExtension(
+ "GL_ARB_texture_rectangle");
+ if (rectTex && Image::getInternalTextureType() == 4
+ && config.getBoolValue("rectangulartextures"))
+ {
+ logger->log1("using GL_ARB_texture_rectangle");
+ Image::mTextureType = GL_TEXTURE_RECTANGLE_ARB;
+ glEnable(GL_TEXTURE_RECTANGLE_ARB);
+ glGetIntegerv(GL_MAX_RECTANGLE_TEXTURE_SIZE_ARB, &texSize);
+ Image::mTextureSize = texSize;
+ logger->log("OpenGL texture size: %d pixels (rectangle textures)",
+ Image::mTextureSize);
+ }
+ else
+ {
+ Image::mTextureType = GL_TEXTURE_2D;
+ glGetIntegerv(GL_MAX_TEXTURE_SIZE, &texSize);
+ Image::mTextureSize = texSize;
+ logger->log("OpenGL texture size: %d pixels", Image::mTextureSize);
+ }
+ return videoInfo();
+#else
+ return false;
+#endif
+}
+
+int Graphics::getSoftwareFlags()
+{
+ int displayFlags = SDL_ANYFORMAT;
+
+ if (mFullscreen)
+ displayFlags |= SDL_FULLSCREEN;
+ else if (mEnableResize)
displayFlags |= SDL_RESIZABLE;
- if (hwaccel)
+ if (mHWAccel)
displayFlags |= SDL_HWSURFACE | SDL_DOUBLEBUF;
else
displayFlags |= SDL_SWSURFACE;
- if (noFrame)
+ if (mNoFrame)
displayFlags |= SDL_NOFRAME;
- setTarget(SDL_SetVideoMode(w, h, bpp, displayFlags));
+ return displayFlags;
+}
+
+
+void Graphics::updateMemoryInfo()
+{
+#ifdef USE_OPENGL
+ if (mStartFreeMem)
+ return;
+
+ if (graphicsManager.supportExtension("GL_NVX_gpu_memory_info"))
+ {
+ glGetIntegerv(GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX,
+ &mStartFreeMem);
+ logger->log("free video memory: %d", mStartFreeMem);
+ }
+#endif
+}
+
+int Graphics::getMemoryUsage()
+{
+#ifdef USE_OPENGL
+ if (!mStartFreeMem)
+ return 0;
+
+ if (graphicsManager.supportExtension("GL_NVX_gpu_memory_info"))
+ {
+ GLint val;
+ glGetIntegerv(GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX,
+ &val);
+ return mStartFreeMem - val;
+ }
+#endif
+ return 0;
+}
+
+bool Graphics::setVideoMode(int w, int h, int bpp, bool fs,
+ bool hwaccel, bool resize, bool noFrame)
+{
+ setMainFlags(w, h, bpp, fs, hwaccel, resize, noFrame);
- if (!mTarget)
+ if (!(mTarget = SDL_SetVideoMode(w, h, bpp, getSoftwareFlags())))
return false;
mRect.w = mTarget->w;
@@ -112,6 +263,7 @@ bool Graphics::videoInfo()
{
char videoDriverName[65];
+ logger->log("SDL video info");
if (SDL_VideoDriverName(videoDriverName, 64))
logger->log("Using video driver: %s", videoDriverName);
else
diff --git a/src/graphics.h b/src/graphics.h
index 1779a14a5..9b69f2f60 100644
--- a/src/graphics.h
+++ b/src/graphics.h
@@ -254,11 +254,7 @@ class Graphics : public gcn::SDLGraphics
virtual void prepareScreenshot()
{ }
- virtual int getMemoryUsage()
- { return 0; }
-
- virtual void updateTextureFormat()
- { }
+ int getMemoryUsage();
virtual bool drawNet(int x1, int y1, int x2, int y2,
int width, int height);
@@ -299,12 +295,26 @@ class Graphics : public gcn::SDLGraphics
void setNoFrame(bool n)
{ mNoFrame = n; }
- bool videoInfo();
+ const std::string &getName()
+ { return mName; }
int mWidth;
int mHeight;
protected:
+ void setMainFlags(int w, int h, int bpp, bool fs,
+ bool hwaccel, bool resize, bool noFrame);
+
+ int getOpenGLFlags();
+
+ int getSoftwareFlags();
+
+ bool setOpenGLMode();
+
+ void updateMemoryInfo();
+
+ bool videoInfo();
+
int SDL_FakeUpperBlit(SDL_Surface *src, SDL_Rect *srcrect,
SDL_Surface *dst, SDL_Rect *dstrect);
@@ -321,6 +331,8 @@ class Graphics : public gcn::SDLGraphics
bool mNoFrame;
Uint32 mOldPixel;
int mOldAlpha;
+ std::string mName;
+ int mStartFreeMem;
};
extern Graphics *mainGraphics;
diff --git a/src/graphicsmanager.cpp b/src/graphicsmanager.cpp
new file mode 100644
index 000000000..5beede539
--- /dev/null
+++ b/src/graphicsmanager.cpp
@@ -0,0 +1,144 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2012 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "graphicsmanager.h"
+
+#include "configuration.h"
+#include "graphics.h"
+#include "graphicsvertexes.h"
+#include "logger.h"
+
+#include "resources/image.h"
+
+#include "utils/stringutils.h"
+
+#include "debug.h"
+
+GraphicsManager graphicsManager;
+
+GraphicsManager::GraphicsManager()
+{
+}
+
+GraphicsManager::~GraphicsManager()
+{
+}
+
+void GraphicsManager::initGraphics(bool noOpenGL)
+{
+#ifdef USE_OPENGL
+ int useOpenGL = 0;
+ if (!noOpenGL)
+ useOpenGL = config.getIntValue("opengl");
+
+ // Setup image loading for the right image format
+ Image::setLoadAsOpenGL(useOpenGL);
+ GraphicsVertexes::setLoadAsOpenGL(useOpenGL);
+
+ // Create the graphics context
+ switch (useOpenGL)
+ {
+ case 0:
+ mainGraphics = new Graphics;
+ break;
+ case 1:
+ default:
+ mainGraphics = new OpenGLGraphics;
+ break;
+ case 2:
+ mainGraphics = new OpenGL1Graphics;
+ break;
+ };
+
+#else
+ // Create the graphics context
+ mainGraphics = new Graphics;
+#endif
+}
+
+void GraphicsManager::updateExtensions(const char *extensions)
+{
+ mExtensions.clear();
+ splitToStringSet(mExtensions, extensions, ' ');
+}
+
+bool GraphicsManager::supportExtension(const std::string ext)
+{
+ return mExtensions.find(ext) != mExtensions.end();
+}
+
+void GraphicsManager::updateTextureFormat()
+{
+#ifdef USE_OPENGL
+ if (!config.getBoolValue("compresstextures"))
+ return;
+
+ if (supportExtension("GL_ARB_texture_compression"))
+ {
+ if (supportExtension("GL_EXT_texture_compression_s3tc")
+ || supportExtension("3DFX_texture_compression_FXT1"))
+ {
+ GLint num;
+ GLint *formats = nullptr;
+ glGetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS, &num);
+ logger->log("support %d compressed formats", num);
+ formats = new GLint[num > 10 ? num : 10];
+ glGetIntegerv(GL_COMPRESSED_TEXTURE_FORMATS, formats);
+ for (int f = 0; f < num; f ++)
+ {
+ if (formats[f] == GL_COMPRESSED_RGBA_S3TC_DXT5_EXT)
+ {
+ delete []formats;
+ Image::setInternalTextureType(
+ GL_COMPRESSED_RGBA_S3TC_DXT5_EXT);
+ logger->log("using s3tc texture compression");
+ return;
+ }
+ else if (formats[f] == GL_COMPRESSED_RGBA_FXT1_3DFX)
+ {
+ delete []formats;
+ Image::setInternalTextureType(
+ GL_COMPRESSED_RGBA_FXT1_3DFX);
+ logger->log("using fxt1 texture compression");
+ return;
+ }
+ }
+ Image::setInternalTextureType(GL_COMPRESSED_RGBA_ARB);
+ logger->log("using texture compression");
+ }
+ else
+ {
+ Image::setInternalTextureType(GL_COMPRESSED_RGBA_ARB);
+ logger->log("using texture compression");
+ }
+ }
+#endif
+}
+
+void GraphicsManager::logString(const char *format, int num)
+{
+#ifdef USE_OPENGL
+ const char *str = reinterpret_cast<const char*>(glGetString(num));
+ if (!str)
+ logger->log(format, "?");
+ else
+ logger->log(format, str);
+#endif
+}
diff --git a/src/graphicsmanager.h b/src/graphicsmanager.h
new file mode 100644
index 000000000..bd5288ed7
--- /dev/null
+++ b/src/graphicsmanager.h
@@ -0,0 +1,52 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2012 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GRAPHICSMANAGER_H
+#define GRAPHICSMANAGER_H
+
+#include <set>
+#include <string>
+
+class Graphics;
+
+class GraphicsManager
+{
+ public:
+ GraphicsManager();
+
+ virtual ~GraphicsManager();
+
+ void initGraphics(bool noOpenGL);
+
+ void updateExtensions(const char *extensions);
+
+ bool supportExtension(const std::string ext);
+
+ void updateTextureFormat();
+
+ void logString(const char *format, int num);
+
+ private:
+ std::set<std::string> mExtensions;
+};
+
+extern GraphicsManager graphicsManager;
+
+#endif
diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp
index e52cc0e0c..c46131379 100644
--- a/src/gui/widgets/itemcontainer.cpp
+++ b/src/gui/widgets/itemcontainer.cpp
@@ -530,7 +530,7 @@ void ItemContainer::updateMatrix()
}
for (std::vector<ItemIdPair*>::const_iterator iter = sortedItems.begin(),
- iter_end = sortedItems.end(); iter != sortedItems.end(); ++ iter)
+ iter_end = sortedItems.end(); iter != iter_end; ++ iter)
{
if (j >= mGridRows)
break;
diff --git a/src/opengl1graphics.cpp b/src/opengl1graphics.cpp
index 1f08443cc..33eabc236 100644
--- a/src/opengl1graphics.cpp
+++ b/src/opengl1graphics.cpp
@@ -51,6 +51,7 @@ OpenGL1Graphics::OpenGL1Graphics():
mFboId(0), mTextureId(0), mRboId(0)
{
mOpenGL = 2;
+ mName = "safe OpenGL";
}
OpenGL1Graphics::~OpenGL1Graphics()
@@ -65,85 +66,9 @@ 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");
+ setMainFlags(w, h, bpp, fs, hwaccel, resize, noFrame);
- int displayFlags = SDL_ANYFORMAT | SDL_OPENGL;
-
- mWidth = w;
- mHeight = h;
- mBpp = bpp;
- mFullscreen = fs;
- mHWAccel = hwaccel;
- mEnableResize = resize;
- mNoFrame = noFrame;
-
- if (fs)
- {
- displayFlags |= SDL_FULLSCREEN;
- }
- else
- {
- // Resizing currently not supported on Windows, where it would require
- // reuploading all textures.
-#if !defined(_WIN32)
- if (resize)
- displayFlags |= SDL_RESIZABLE;
-#endif
- }
-
- if (noFrame)
- displayFlags |= SDL_NOFRAME;
-
- SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
-
- if (!(mTarget = SDL_SetVideoMode(w, h, bpp, displayFlags)))
- return false;
-
-#ifdef __APPLE__
- if (mSync)
- {
- const GLint VBL = 1;
- CGLSetParameter(CGLGetCurrentContext(), kCGLCPSwapInterval, &VBL);
- }
-#endif
-
- // Setup OpenGL
- glViewport(0, 0, w, h);
- glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
- int gotDoubleBuffer;
- SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER, &gotDoubleBuffer);
- logger->log("Using OpenGL %s double buffering.",
- (gotDoubleBuffer ? "with" : "without"));
-
- 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 && config.getBoolValue("rectangulartextures"))
- {
- logger->log1("using GL_ARB_texture_rectangle");
- Image::mTextureType = GL_TEXTURE_RECTANGLE_ARB;
- glEnable(GL_TEXTURE_RECTANGLE_ARB);
- glGetIntegerv(GL_MAX_RECTANGLE_TEXTURE_SIZE_ARB, &texSize);
- Image::mTextureSize = texSize;
- logger->log("OpenGL texture size: %d pixels (rectangle textures)",
- Image::mTextureSize);
- }
- else
- {
- Image::mTextureType = GL_TEXTURE_2D;
- glGetIntegerv(GL_MAX_TEXTURE_SIZE, &texSize);
- Image::mTextureSize = texSize;
- logger->log("OpenGL texture size: %d pixels", Image::mTextureSize);
- }
-
- return true;
+ return setOpenGLMode();
}
static inline void drawQuad(Image *image,
diff --git a/src/openglgraphics.cpp b/src/openglgraphics.cpp
index 0e5c01ca6..1e4bcd6de 100644
--- a/src/openglgraphics.cpp
+++ b/src/openglgraphics.cpp
@@ -46,23 +46,16 @@
#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), mStartFreeMem(0)
+ mFboId(0), mTextureId(0), mRboId(0)
{
mOpenGL = 1;
+ mName = "fast OpenGL";
mFloatTexArray = new GLfloat[vertexBufSize * 4 + 30];
mIntTexArray = new GLint[vertexBufSize * 4 + 30];
mIntVertArray = new GLint[vertexBufSize * 4 + 30];
@@ -83,98 +76,9 @@ 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");
-
- int displayFlags = SDL_ANYFORMAT | SDL_OPENGL;
+ setMainFlags(w, h, bpp, fs, hwaccel, resize, noFrame);
- mWidth = w;
- mHeight = h;
- mBpp = bpp;
- mFullscreen = fs;
- mHWAccel = hwaccel;
- mEnableResize = resize;
- mNoFrame = noFrame;
-
- if (fs)
- {
- displayFlags |= SDL_FULLSCREEN;
- }
- else
- {
- // Resizing currently not supported on Windows, where it would require
- // reuploading all textures.
-#if !defined(_WIN32)
- if (resize)
- displayFlags |= SDL_RESIZABLE;
-#endif
- }
-
- if (noFrame)
- displayFlags |= SDL_NOFRAME;
-
- SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
-
- if (!(mTarget = SDL_SetVideoMode(w, h, bpp, displayFlags)))
- return false;
-
-#ifdef __APPLE__
- if (mSync)
- {
- const GLint VBL = 1;
- CGLSetParameter(CGLGetCurrentContext(), kCGLCPSwapInterval, &VBL);
- }
-#endif
-
- logString("gl vendor: %s", GL_VENDOR);
- logString("gl renderer: %s", GL_RENDERER);
- logString("gl version: %s", GL_VERSION);
-
-// logger->log("gl extensions: %s", reinterpret_cast<const char*>(
-// glGetString(GL_EXTENSIONS)));
-
- // Setup OpenGL
- glViewport(0, 0, w, h);
- glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
- int gotDoubleBuffer;
- SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER, &gotDoubleBuffer);
- logger->log("Using OpenGL %s double buffering.",
- (gotDoubleBuffer ? "with" : "without"));
-
- char const *glExtensions = reinterpret_cast<char const *>(
- glGetString(GL_EXTENSIONS));
-
- logger->log1("opengl extensions: ");
- logger->log1(glExtensions);
-
- splitToStringSet(mExtensions, glExtensions, ' ');
-
- updateTextureFormat();
- updateMemoryInfo();
-
- GLint texSize;
- bool rectTex = supportExtension("GL_ARB_texture_rectangle");
- if (rectTex && Image::getInternalTextureType() == 4
- && config.getBoolValue("rectangulartextures"))
- {
- logger->log1("using GL_ARB_texture_rectangle");
- Image::mTextureType = GL_TEXTURE_RECTANGLE_ARB;
- glEnable(GL_TEXTURE_RECTANGLE_ARB);
- glGetIntegerv(GL_MAX_RECTANGLE_TEXTURE_SIZE_ARB, &texSize);
- Image::mTextureSize = texSize;
- logger->log("OpenGL texture size: %d pixels (rectangle textures)",
- Image::mTextureSize);
- }
- else
- {
- Image::mTextureType = GL_TEXTURE_2D;
- glGetIntegerv(GL_MAX_TEXTURE_SIZE, &texSize);
- Image::mTextureSize = texSize;
- logger->log("OpenGL texture size: %d pixels", Image::mTextureSize);
- }
-
- return true;
+ return setOpenGLMode();
}
static inline void drawQuad(Image *image,
@@ -1475,92 +1379,4 @@ void OpenGLGraphics::dumpSettings()
}
}
-void OpenGLGraphics::logString(const char *format, GLenum num)
-{
- const char *str = reinterpret_cast<const char*>(glGetString(num));
- if (!str)
- logger->log(format, "?");
- 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;
-}
-
-void OpenGLGraphics::updateTextureFormat()
-{
- if (!config.getBoolValue("compresstextures"))
- return;
-
- if (supportExtension("GL_ARB_texture_compression"))
- {
- if (supportExtension("GL_EXT_texture_compression_s3tc")
- || supportExtension("3DFX_texture_compression_FXT1"))
- {
- GLint num;
- GLint *formats = nullptr;
- glGetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS, &num);
- logger->log("support %d compressed formats", num);
- formats = new GLint[num > 10 ? num : 10];
- glGetIntegerv(GL_COMPRESSED_TEXTURE_FORMATS, formats);
- for (int f = 0; f < num; f ++)
- {
- if (formats[f] == GL_COMPRESSED_RGBA_S3TC_DXT5_EXT)
- {
- delete []formats;
- Image::setInternalTextureType(
- GL_COMPRESSED_RGBA_S3TC_DXT5_EXT);
- logger->log("using s3tc texture compression");
- return;
- }
- else if (formats[f] == GL_COMPRESSED_RGBA_FXT1_3DFX)
- {
- delete []formats;
- Image::setInternalTextureType(
- GL_COMPRESSED_RGBA_FXT1_3DFX);
- logger->log("using fxt1 texture compression");
- return;
- }
- }
- Image::setInternalTextureType(GL_COMPRESSED_RGBA_ARB);
- logger->log("using texture compression");
- }
- else
- {
- Image::setInternalTextureType(GL_COMPRESSED_RGBA_ARB);
- logger->log("using texture compression");
- }
- }
-}
-
#endif // USE_OPENGL
diff --git a/src/openglgraphics.h b/src/openglgraphics.h
index 06f37db0d..944b8c917 100644
--- a/src/openglgraphics.h
+++ b/src/openglgraphics.h
@@ -146,8 +146,6 @@ 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();
void updateTextureFormat();
@@ -173,8 +171,6 @@ class OpenGLGraphics : public Graphics
GLuint mFboId;
GLuint mTextureId;
GLuint mRboId;
- std::set<std::string> mExtensions;
- GLint mStartFreeMem;
};
#endif