From e5e234b864e75862a2de72ee6c3b8bda47f41c23 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Thu, 10 Dec 2015 16:42:56 +0100 Subject: OPENGL: Refactor GL extension handling slightly. --- backends/graphics/opengl/extensions.cpp | 13 +++++++++---- backends/graphics/opengl/extensions.h | 23 ++++++++++++++++++----- backends/graphics/opengl/opengl-graphics.cpp | 1 + backends/graphics/opengl/opengl-graphics.h | 6 ++++++ backends/graphics/opengl/texture.cpp | 2 +- 5 files changed, 35 insertions(+), 10 deletions(-) (limited to 'backends') diff --git a/backends/graphics/opengl/extensions.cpp b/backends/graphics/opengl/extensions.cpp index 4482ef82b5..c76f8d7ca6 100644 --- a/backends/graphics/opengl/extensions.cpp +++ b/backends/graphics/opengl/extensions.cpp @@ -22,25 +22,30 @@ #include "backends/graphics/opengl/extensions.h" #include "backends/graphics/opengl/opengl-sys.h" +#include "backends/graphics/opengl/opengl-graphics.h" #include "common/tokenizer.h" namespace OpenGL { -bool g_extNPOTSupported = false; +void ExtensionsDesc::reset() { + NPOTSupported = false; +} + +ExtensionsDesc g_extensions; -void initializeGLExtensions() { +void OpenGLGraphicsManager::initializeGLExtensions() { const char *extString = (const char *)glGetString(GL_EXTENSIONS); // Initialize default state. - g_extNPOTSupported = false; + g_extensions.reset(); Common::StringTokenizer tokenizer(extString, " "); while (!tokenizer.empty()) { Common::String token = tokenizer.nextToken(); if (token == "GL_ARB_texture_non_power_of_two") { - g_extNPOTSupported = true; + g_extensions.NPOTSupported = true; } } } diff --git a/backends/graphics/opengl/extensions.h b/backends/graphics/opengl/extensions.h index 87452429e2..5b9eb538d9 100644 --- a/backends/graphics/opengl/extensions.h +++ b/backends/graphics/opengl/extensions.h @@ -26,15 +26,28 @@ namespace OpenGL { /** - * Checks for availability of extensions we want to use and initializes them - * when available. + * Description structure of all available extensions. + * + * This includes information whether extensions we are interested in is + * available or not. If extensions we are interested in add additional + * functions, we keep function pointers around in here too. */ -void initializeGLExtensions(); +struct ExtensionsDesc { + /** + * Reset extension state. + * + * This marks all extensions as unavailable. + */ + void reset(); + + /** Whether GL_ARB_texture_non_power_of_two is available or not. */ + bool NPOTSupported; +}; /** - * Whether non power of two textures are supported + * Description of all available extensions. */ -extern bool g_extNPOTSupported; +extern ExtensionsDesc g_extensions; } // End of namespace OpenGL diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp index ac6d41d47d..d738f31a37 100644 --- a/backends/graphics/opengl/opengl-graphics.cpp +++ b/backends/graphics/opengl/opengl-graphics.cpp @@ -58,6 +58,7 @@ OpenGLGraphicsManager::OpenGLGraphicsManager() #endif { memset(_gamePalette, 0, sizeof(_gamePalette)); + g_extensions.reset(); } OpenGLGraphicsManager::~OpenGLGraphicsManager() { diff --git a/backends/graphics/opengl/opengl-graphics.h b/backends/graphics/opengl/opengl-graphics.h index 9578839383..2a03b878ce 100644 --- a/backends/graphics/opengl/opengl-graphics.h +++ b/backends/graphics/opengl/opengl-graphics.h @@ -280,6 +280,12 @@ private: // OpenGL utilities // + /** + * Checks for availability of extensions we want to use and initializes them + * when available. + */ + void initializeGLExtensions(); + /** * Try to determine the internal parameters for a given pixel format. * diff --git a/backends/graphics/opengl/texture.cpp b/backends/graphics/opengl/texture.cpp index 7b0b22d630..36fe5ab744 100644 --- a/backends/graphics/opengl/texture.cpp +++ b/backends/graphics/opengl/texture.cpp @@ -105,7 +105,7 @@ void Texture::enableLinearFiltering(bool enable) { void Texture::allocate(uint width, uint height) { uint texWidth = width, texHeight = height; - if (!g_extNPOTSupported) { + if (!g_extensions.NPOTSupported) { texWidth = nextHigher2(texWidth); texHeight = nextHigher2(texHeight); } -- cgit v1.2.3