Browse Source

Creating Context instance in all *Context classes.

The naming is now kinda schizofrenic, hope I come up with something
better.
pull/279/head
Vladimír Vondruš 14 years ago
parent
commit
13bb600c3e
  1. 6
      src/Contexts/EglContext.cpp
  2. 8
      src/Contexts/EglContext.h
  3. 7
      src/Contexts/GlutWindowContext.cpp
  4. 10
      src/Contexts/GlutWindowContext.h
  5. 6
      src/Contexts/GlxContext.cpp
  6. 8
      src/Contexts/GlxContext.h
  7. 6
      src/Contexts/Sdl2WindowContext.cpp
  8. 8
      src/Contexts/Sdl2WindowContext.h

6
src/Contexts/EglContext.cpp

@ -15,9 +15,13 @@
#include "EglContext.h" #include "EglContext.h"
#include "Context.h"
namespace Magnum { namespace Contexts { namespace Magnum { namespace Contexts {
EglContext::~EglContext() { EglContext::~EglContext() {
delete c;
eglDestroyContext(display, context); eglDestroyContext(display, context);
eglDestroySurface(display, surface); eglDestroySurface(display, surface);
eglTerminate(display); 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 */ /** @bug Fixme: On desktop OpenGL and Mesa EGL implementation OpenGL version is 1.0, which is wrong */
context = new Context;
} }
}} }}

8
src/Contexts/EglContext.h

@ -28,7 +28,11 @@
#include "AbstractContext.h" #include "AbstractContext.h"
namespace Magnum { namespace Contexts { namespace Magnum {
class Context;
namespace Contexts {
#ifndef DOXYGEN_GENERATING_OUTPUT #ifndef DOXYGEN_GENERATING_OUTPUT
/* EGL returns visual ID as int, but Xorg expects long unsigned int */ /* EGL returns visual ID as int, but Xorg expects long unsigned int */
@ -64,6 +68,8 @@ class EglContext: public AbstractContext<EGLNativeDisplayType, VisualId, EGLNati
EGLConfig config; EGLConfig config;
EGLSurface surface; EGLSurface surface;
EGLContext context; EGLContext context;
Context* c;
}; };
}} }}

7
src/Contexts/GlutWindowContext.cpp

@ -15,6 +15,7 @@
#include "GlutWindowContext.h" #include "GlutWindowContext.h"
#include "Context.h"
#include "ExtensionWrangler.h" #include "ExtensionWrangler.h"
namespace Magnum { namespace Contexts { namespace Magnum { namespace Contexts {
@ -38,6 +39,12 @@ GlutWindowContext::GlutWindowContext(int& argc, char** argv, const std::string&
glutDisplayFunc(staticDrawEvent); glutDisplayFunc(staticDrawEvent);
ExtensionWrangler::initialize(); ExtensionWrangler::initialize();
c = new Context;
}
GlutWindowContext::~GlutWindowContext() {
delete c;
} }
}} }}

10
src/Contexts/GlutWindowContext.h

@ -28,7 +28,11 @@
#include "AbstractWindowContext.h" #include "AbstractWindowContext.h"
namespace Magnum { namespace Contexts { namespace Magnum {
class Context;
namespace Contexts {
/** @nosubgrouping /** @nosubgrouping
@brief GLUT context @brief GLUT context
@ -52,6 +56,8 @@ class GlutWindowContext: public AbstractWindowContext {
*/ */
GlutWindowContext(int& argc, char** argv, const std::string& title = "Magnum GLUT context", const Math::Vector2<GLsizei>& size = Math::Vector2<GLsizei>(800, 600)); GlutWindowContext(int& argc, char** argv, const std::string& title = "Magnum GLUT context", const Math::Vector2<GLsizei>& size = Math::Vector2<GLsizei>(800, 600));
~GlutWindowContext();
inline int exec() { inline int exec() {
glutMainLoop(); glutMainLoop();
return 0; return 0;
@ -246,6 +252,8 @@ class GlutWindowContext: public AbstractWindowContext {
int& argc; int& argc;
char** argv; char** argv;
Context* c;
}; };
/* Implementations for inline functions with unused parameters */ /* Implementations for inline functions with unused parameters */

6
src/Contexts/GlxContext.cpp

@ -18,6 +18,8 @@
#include <GL/glxext.h> #include <GL/glxext.h>
#include <Utility/Debug.h> #include <Utility/Debug.h>
#include "Context.h"
#define None 0L // redef Xlib nonsense #define None 0L // redef Xlib nonsense
namespace Magnum { namespace Contexts { namespace Magnum { namespace Contexts {
@ -83,9 +85,13 @@ void GlxContext::createContext(Window nativeWindow) {
Error() << "GlxContext: cannot create context."; Error() << "GlxContext: cannot create context.";
exit(1); exit(1);
} }
c = new Context;
} }
GlxContext::~GlxContext() { GlxContext::~GlxContext() {
delete c;
glXMakeCurrent(display, None, nullptr); glXMakeCurrent(display, None, nullptr);
glXDestroyContext(display, context); glXDestroyContext(display, context);
} }

8
src/Contexts/GlxContext.h

@ -27,7 +27,11 @@
#include "AbstractContext.h" #include "AbstractContext.h"
namespace Magnum { namespace Contexts { namespace Magnum {
class Context;
namespace Contexts {
/** /**
@brief GLX interface @brief GLX interface
@ -62,6 +66,8 @@ class GlxContext: public AbstractContext<Display*, VisualID, Window> {
Window window; Window window;
GLXFBConfig* configs; GLXFBConfig* configs;
GLXContext context; GLXContext context;
Context* c;
}; };
}} }}

6
src/Contexts/Sdl2WindowContext.cpp

@ -14,6 +14,8 @@
*/ */
#include "Sdl2WindowContext.h" #include "Sdl2WindowContext.h"
#include "Context.h"
#include "ExtensionWrangler.h" #include "ExtensionWrangler.h"
namespace Magnum { namespace Contexts { namespace Magnum { namespace Contexts {
@ -52,9 +54,13 @@ Sdl2WindowContext::Sdl2WindowContext(int, char**, const std::string& name, const
sizeEvent->window.data1 = size.x(); sizeEvent->window.data1 = size.x();
sizeEvent->window.data2 = size.y(); sizeEvent->window.data2 = size.y();
SDL_PushEvent(sizeEvent); SDL_PushEvent(sizeEvent);
c = new Context;
} }
Sdl2WindowContext::~Sdl2WindowContext() { Sdl2WindowContext::~Sdl2WindowContext() {
delete c;
SDL_GL_DeleteContext(context); SDL_GL_DeleteContext(context);
SDL_DestroyWindow(window); SDL_DestroyWindow(window);
SDL_Quit(); SDL_Quit();

8
src/Contexts/Sdl2WindowContext.h

@ -27,7 +27,11 @@
#include "AbstractWindowContext.h" #include "AbstractWindowContext.h"
namespace Magnum { namespace Contexts { namespace Magnum {
class Context;
namespace Contexts {
/** @nosubgrouping /** @nosubgrouping
@brief SDL2 context @brief SDL2 context
@ -179,6 +183,8 @@ class Sdl2WindowContext: public AbstractWindowContext {
SDL_Window* window; SDL_Window* window;
SDL_GLContext context; SDL_GLContext context;
Context* c;
bool _redraw; bool _redraw;
}; };

Loading…
Cancel
Save