summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-08-14 01:09:49 +0300
committerAndrei Karas <akaras@inbox.ru>2012-08-14 01:57:57 +0300
commitc5fd70049a0ebdc14e49af3e5215521085a44b46 (patch)
tree6654ed70f48e954d39926ff3a14a26d588479cab /src
parentd589fe649959239c268b1affddee8a453f96e969 (diff)
downloadplus-c5fd70049a0ebdc14e49af3e5215521085a44b46.tar.gz
plus-c5fd70049a0ebdc14e49af3e5215521085a44b46.tar.bz2
plus-c5fd70049a0ebdc14e49af3e5215521085a44b46.tar.xz
plus-c5fd70049a0ebdc14e49af3e5215521085a44b46.zip
Fow OpenGL >= 3.0 check extensions in modern way.
Diffstat (limited to 'src')
-rw-r--r--src/client.cpp1
-rw-r--r--src/graphics.cpp9
-rw-r--r--src/graphicsmanager.cpp45
-rw-r--r--src/graphicsmanager.h6
-rw-r--r--src/mgl.cpp1
-rw-r--r--src/mgl.h3
6 files changed, 44 insertions, 21 deletions
diff --git a/src/client.cpp b/src/client.cpp
index 1d1fdeaa5..b636ce2fe 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -535,7 +535,6 @@ void Client::gameInit()
applyVSync();
graphicsManager.setVideoMode();
- graphicsManager.initOpenGLFunctions();
applyGrabMode();
applyGamma();
diff --git a/src/graphics.cpp b/src/graphics.cpp
index 2700df10a..05083506b 100644
--- a/src/graphics.cpp
+++ b/src/graphics.cpp
@@ -166,14 +166,9 @@ bool Graphics::setOpenGLMode()
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.setGLVersion();
+ graphicsManager.initOpenGLFunctions();
+ graphicsManager.updateExtensions();
graphicsManager.updateTextureFormat();
updateMemoryInfo();
diff --git a/src/graphicsmanager.cpp b/src/graphicsmanager.cpp
index 14ea31447..9529cda51 100644
--- a/src/graphicsmanager.cpp
+++ b/src/graphicsmanager.cpp
@@ -80,17 +80,14 @@ bool GraphicsManager::detectGraphics()
logger->log("enable opengl mode");
SDL_SetVideoMode(100, 100, 0, SDL_ANYFORMAT | SDL_OPENGL);
+ setGLVersion();
+ initOpenGLFunctions();
+ updateExtensions();
std::string vendor = getGLString(GL_VENDOR);
std::string renderer = getGLString(GL_RENDERER);
- std::string version = getGLString(GL_VERSION);
logger->log("gl vendor: %s", vendor.c_str());
logger->log("gl renderer: %s", renderer.c_str());
- logger->log("gl version: %s", version.c_str());
- sscanf(version.c_str(), "%5d.%5d", &mMajor, &mMinor);
-
- char const *glExtensions = reinterpret_cast<char const *>(
- glGetString(GL_EXTENSIONS));
- updateExtensions(glExtensions);
+ logger->log("gl version: %s", mVersionString.c_str());
int mode = 1;
@@ -145,7 +142,7 @@ bool GraphicsManager::detectGraphics()
mode = 0;
}
- if (mode > 0 && findI(version, "Mesa") != std::string::npos)
+ if (mode > 0 && findI(mVersionString, "Mesa") != std::string::npos)
{
// Mesa detected
config.setValue("compresstextures", true);
@@ -214,10 +211,32 @@ Graphics *GraphicsManager::createGraphics()
#endif
}
-void GraphicsManager::updateExtensions(const char *extensions)
+void GraphicsManager::updateExtensions()
{
mExtensions.clear();
- splitToStringSet(mExtensions, extensions, ' ');
+ logger->log1("opengl extensions: ");
+ if (checkGLVersion(3, 0))
+ { // get extensions in new way
+ std::string extList;
+ int num = 0;
+ glGetIntegerv(GL_NUM_EXTENSIONS, &num);
+ for (int f = 0; f < num; f ++)
+ {
+ std::string str = reinterpret_cast<const char*>(
+ mglGetStringi(GL_EXTENSIONS, f));
+ mExtensions.insert(str);
+ extList += str + " ";
+ }
+ logger->log1(extList.c_str());
+ }
+ else
+ { // get extensions in old way
+ char const *extensions = reinterpret_cast<char const *>(
+ glGetString(GL_EXTENSIONS));
+ logger->log1(extensions);
+
+ splitToStringSet(mExtensions, extensions, ' ');
+ }
}
bool GraphicsManager::supportExtension(const std::string &ext)
@@ -316,7 +335,8 @@ std::string GraphicsManager::getGLString(int num) const
void GraphicsManager::setGLVersion()
{
- sscanf(getGLString(GL_VERSION).c_str(), "%5d.%5d", &mMajor, &mMinor);
+ mVersionString = getGLString(GL_VERSION);
+ sscanf(mVersionString.c_str(), "%5d.%5d", &mMajor, &mMinor);
}
void GraphicsManager::setVideoMode()
@@ -474,4 +494,7 @@ void GraphicsManager::initOpenGLFunctions()
{ // no frame buffer support
config.setValue("usefbo", false);
}
+
+ if (checkGLVersion(3, 0))
+ assignFunction(glGetStringi, "glGetStringi");
}
diff --git a/src/graphicsmanager.h b/src/graphicsmanager.h
index c7e8ead6a..6a41da035 100644
--- a/src/graphicsmanager.h
+++ b/src/graphicsmanager.h
@@ -41,8 +41,6 @@ class GraphicsManager
bool detectGraphics();
- void updateExtensions(const char *extensions);
-
bool supportExtension(const std::string &ext);
void updateTextureFormat();
@@ -63,11 +61,15 @@ class GraphicsManager
void initOpenGLFunctions();
+ void updateExtensions();
+
Graphics *createGraphics();
private:
std::set<std::string> mExtensions;
+ std::string mVersionString;
+
int mMinor;
int mMajor;
diff --git a/src/mgl.cpp b/src/mgl.cpp
index a73536dac..6dafb1258 100644
--- a/src/mgl.cpp
+++ b/src/mgl.cpp
@@ -33,3 +33,4 @@ defName(glFramebufferTexture2D);
defName(glFramebufferRenderbuffer);
defName(glDeleteFramebuffers);
defName(glDeleteRenderbuffers);
+defName(glGetStringi); \ No newline at end of file
diff --git a/src/mgl.h b/src/mgl.h
index ae2f8583c..8e7002d82 100644
--- a/src/mgl.h
+++ b/src/mgl.h
@@ -26,6 +26,7 @@
#include <SDL_opengl.h>
#include <GL/glext.h>
+#define GL_NUM_EXTENSIONS 0x821D
#define GL_DEPTH_ATTACHMENT 0x8D00
#define GL_COLOR_ATTACHMENT0 0x8CE0
#define GL_FRAMEBUFFER 0x8D40
@@ -47,6 +48,7 @@ typedef void (APIENTRY *glFramebufferRenderbuffer_t)(GLenum target,
GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer);
typedef void (APIENTRY *glDeleteFramebuffers_t) (GLsizei, const GLuint *);
typedef void (APIENTRY *glDeleteRenderbuffers_t) (GLsizei, const GLuint *);
+typedef const GLubyte *(APIENTRY *glGetStringi_t) (GLenum, GLuint);
defNameE(glGenRenderbuffers);
defNameE(glBindRenderbuffer);
@@ -57,5 +59,6 @@ defNameE(glFramebufferTexture2D);
defNameE(glFramebufferRenderbuffer);
defNameE(glDeleteFramebuffers);
defNameE(glDeleteRenderbuffers);
+defNameE(glGetStringi);
#endif