aboutsummaryrefslogtreecommitdiff
path: root/backends/graphics/opengl
diff options
context:
space:
mode:
authorJohannes Schickel2015-12-20 09:50:55 +0100
committerJohannes Schickel2016-03-16 20:29:25 +0100
commitd029f167996f3328ac278829802d9c1a32c620e2 (patch)
treeb690bb255b3f2521abb9cf74c566308c2351799a /backends/graphics/opengl
parentfee1aa550203c3f46ff19afbe19a7baa4771a5cd (diff)
downloadscummvm-rg350-d029f167996f3328ac278829802d9c1a32c620e2.tar.gz
scummvm-rg350-d029f167996f3328ac278829802d9c1a32c620e2.tar.bz2
scummvm-rg350-d029f167996f3328ac278829802d9c1a32c620e2.zip
OPENGL: Handle destruction gracefully when no context is setup.
Diffstat (limited to 'backends/graphics/opengl')
-rw-r--r--backends/graphics/opengl/opengl-sys.h10
-rw-r--r--backends/graphics/opengl/shader.cpp13
-rw-r--r--backends/graphics/opengl/shader.h4
-rw-r--r--backends/graphics/opengl/texture.cpp2
4 files changed, 24 insertions, 5 deletions
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();
}