From d029f167996f3328ac278829802d9c1a32c620e2 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sun, 20 Dec 2015 09:50:55 +0100 Subject: OPENGL: Handle destruction gracefully when no context is setup. --- backends/graphics/opengl/opengl-sys.h | 10 ++++++++-- backends/graphics/opengl/shader.cpp | 13 +++++++++++++ backends/graphics/opengl/shader.h | 4 ++-- backends/graphics/opengl/texture.cpp | 2 +- 4 files changed, 24 insertions(+), 5 deletions(-) (limited to 'backends/graphics') diff --git a/backends/graphics/opengl/opengl-sys.h b/backends/graphics/opengl/opengl-sys.h index f8acb9302c..dabd6adaa7 100644 --- a/backends/graphics/opengl/opengl-sys.h +++ b/backends/graphics/opengl/opengl-sys.h @@ -111,7 +111,13 @@ extern Context g_context; } // End of namespace OpenGL -#define GL_CALL(x) GL_WRAP_DEBUG(g_context.x, x) -#define GL_ASSIGN(var, x) GL_WRAP_DEBUG(var = g_context.x, x) +#define GL_CALL(x) GL_WRAP_DEBUG(g_context.x, x) +#define GL_CALL_SAFE(func, params) \ + do { \ + if (g_context.func) { \ + GL_CALL(func params); \ + } \ + } while (0) +#define GL_ASSIGN(var, x) GL_WRAP_DEBUG(var = g_context.x, x) #endif diff --git a/backends/graphics/opengl/shader.cpp b/backends/graphics/opengl/shader.cpp index c28036cb4e..d7fc20574b 100644 --- a/backends/graphics/opengl/shader.cpp +++ b/backends/graphics/opengl/shader.cpp @@ -74,6 +74,15 @@ ShaderARB::ShaderARB(const Common::String &vertex, const Common::String &fragmen : Shader(vertex, fragment), _program(0), _projectionLocation(-1), _textureLocation(-1) { } +ShaderARB::~ShaderARB() { + // According to extension specification glDeleteObjectARB silently ignores + // 0. However, with nVidia drivers this can cause GL_INVALID_VALUE, thus + // we do not call it with 0 as parameter to avoid warnings. + if (_program) { + GL_CALL_SAFE(glDeleteObjectARB, (_program)); + } +} + void ShaderARB::destroy() { // According to extension specification glDeleteObjectARB silently ignores // 0. However, with nVidia drivers this can cause GL_INVALID_VALUE, thus @@ -200,6 +209,10 @@ ShaderGLES2::ShaderGLES2(const Common::String &vertex, const Common::String &fra : Shader(vertex, fragment), _program(0), _projectionLocation(-1), _textureLocation(-1) { } +ShaderGLES2::~ShaderGLES2() { + GL_CALL_SAFE(glDeleteProgram, (_program)); +} + void ShaderGLES2::destroy() { GL_CALL(glDeleteProgram(_program)); _program = 0; diff --git a/backends/graphics/opengl/shader.h b/backends/graphics/opengl/shader.h index 8c457f8f91..60a430214c 100644 --- a/backends/graphics/opengl/shader.h +++ b/backends/graphics/opengl/shader.h @@ -88,7 +88,7 @@ protected: class ShaderARB : public Shader { public: ShaderARB(const Common::String &vertex, const Common::String &fragment); - virtual ~ShaderARB() { destroy(); } + virtual ~ShaderARB(); virtual void destroy(); @@ -127,7 +127,7 @@ private: class ShaderGLES2 : public Shader { public: ShaderGLES2(const Common::String &vertex, const Common::String &fragment); - virtual ~ShaderGLES2() { destroy(); } + virtual ~ShaderGLES2(); virtual void destroy(); diff --git a/backends/graphics/opengl/texture.cpp b/backends/graphics/opengl/texture.cpp index 0b01430728..e394f760f9 100644 --- a/backends/graphics/opengl/texture.cpp +++ b/backends/graphics/opengl/texture.cpp @@ -54,7 +54,7 @@ Texture::Texture(GLenum glIntFormat, GLenum glFormat, GLenum glType, const Graph } Texture::~Texture() { - releaseInternalTexture(); + GL_CALL_SAFE(glDeleteTextures, (1, &_glTexture)); _textureData.free(); } -- cgit v1.2.3