diff --git a/src/Contexts/EglContext.cpp b/src/Contexts/EglContext.cpp index 323e880e1..96cb8dd4d 100644 --- a/src/Contexts/EglContext.cpp +++ b/src/Contexts/EglContext.cpp @@ -15,9 +15,13 @@ #include "EglContext.h" +#include "Context.h" + namespace Magnum { namespace Contexts { EglContext::~EglContext() { + delete c; + eglDestroyContext(display, context); eglDestroySurface(display, surface); eglTerminate(display); @@ -81,6 +85,8 @@ void EglContext::createContext(EGLNativeWindowType window) { } /** @bug Fixme: On desktop OpenGL and Mesa EGL implementation OpenGL version is 1.0, which is wrong */ + + context = new Context; } }} diff --git a/src/Contexts/EglContext.h b/src/Contexts/EglContext.h index 0190fa299..f0e657690 100644 --- a/src/Contexts/EglContext.h +++ b/src/Contexts/EglContext.h @@ -28,7 +28,11 @@ #include "AbstractContext.h" -namespace Magnum { namespace Contexts { +namespace Magnum { + +class Context; + +namespace Contexts { #ifndef DOXYGEN_GENERATING_OUTPUT /* EGL returns visual ID as int, but Xorg expects long unsigned int */ @@ -64,6 +68,8 @@ class EglContext: public AbstractContext& size = Math::Vector2(800, 600)); + ~GlutWindowContext(); + inline int exec() { glutMainLoop(); return 0; @@ -246,6 +252,8 @@ class GlutWindowContext: public AbstractWindowContext { int& argc; char** argv; + + Context* c; }; /* Implementations for inline functions with unused parameters */ diff --git a/src/Contexts/GlxContext.cpp b/src/Contexts/GlxContext.cpp index 8d36d6f8a..76799d5e6 100644 --- a/src/Contexts/GlxContext.cpp +++ b/src/Contexts/GlxContext.cpp @@ -18,6 +18,8 @@ #include #include +#include "Context.h" + #define None 0L // redef Xlib nonsense namespace Magnum { namespace Contexts { @@ -83,9 +85,13 @@ void GlxContext::createContext(Window nativeWindow) { Error() << "GlxContext: cannot create context."; exit(1); } + + c = new Context; } GlxContext::~GlxContext() { + delete c; + glXMakeCurrent(display, None, nullptr); glXDestroyContext(display, context); } diff --git a/src/Contexts/GlxContext.h b/src/Contexts/GlxContext.h index 5612b3831..3c579ad03 100644 --- a/src/Contexts/GlxContext.h +++ b/src/Contexts/GlxContext.h @@ -27,7 +27,11 @@ #include "AbstractContext.h" -namespace Magnum { namespace Contexts { +namespace Magnum { + +class Context; + +namespace Contexts { /** @brief GLX interface @@ -62,6 +66,8 @@ class GlxContext: public AbstractContext { Window window; GLXFBConfig* configs; GLXContext context; + + Context* c; }; }} diff --git a/src/Contexts/Sdl2WindowContext.cpp b/src/Contexts/Sdl2WindowContext.cpp index 8edc77190..2c2677bfc 100644 --- a/src/Contexts/Sdl2WindowContext.cpp +++ b/src/Contexts/Sdl2WindowContext.cpp @@ -14,6 +14,8 @@ */ #include "Sdl2WindowContext.h" + +#include "Context.h" #include "ExtensionWrangler.h" namespace Magnum { namespace Contexts { @@ -52,9 +54,13 @@ Sdl2WindowContext::Sdl2WindowContext(int, char**, const std::string& name, const sizeEvent->window.data1 = size.x(); sizeEvent->window.data2 = size.y(); SDL_PushEvent(sizeEvent); + + c = new Context; } Sdl2WindowContext::~Sdl2WindowContext() { + delete c; + SDL_GL_DeleteContext(context); SDL_DestroyWindow(window); SDL_Quit(); diff --git a/src/Contexts/Sdl2WindowContext.h b/src/Contexts/Sdl2WindowContext.h index ca80ec681..c0d0f916d 100644 --- a/src/Contexts/Sdl2WindowContext.h +++ b/src/Contexts/Sdl2WindowContext.h @@ -27,7 +27,11 @@ #include "AbstractWindowContext.h" -namespace Magnum { namespace Contexts { +namespace Magnum { + +class Context; + +namespace Contexts { /** @nosubgrouping @brief SDL2 context @@ -179,6 +183,8 @@ class Sdl2WindowContext: public AbstractWindowContext { SDL_Window* window; SDL_GLContext context; + Context* c; + bool _redraw; };