Browse Source

Renamed Contexts::*Context to *ContextHandler.

Finally (and hopefully) consistent and non-confusing naming.
pull/279/head
Vladimír Vondruš 14 years ago
parent
commit
141b20a612
  1. 16
      src/Contexts/AbstractContextHandler.h
  2. 14
      src/Contexts/AbstractXWindowContext.cpp
  3. 10
      src/Contexts/AbstractXWindowContext.h
  4. 18
      src/Contexts/CMakeLists.txt
  5. 8
      src/Contexts/EglContextHandler.cpp
  6. 12
      src/Contexts/EglContextHandler.h
  7. 14
      src/Contexts/GlxContextHandler.cpp
  8. 12
      src/Contexts/GlxContextHandler.h
  9. 6
      src/Contexts/GlxWindowContext.h
  10. 6
      src/Contexts/XEglWindowContext.h

16
src/Contexts/AbstractContext.h → src/Contexts/AbstractContextHandler.h

@ -1,5 +1,5 @@
#ifndef Magnum_Contexts_AbstractContext_h #ifndef Magnum_Contexts_AbstractContextHandler_h
#define Magnum_Contexts_AbstractContext_h #define Magnum_Contexts_AbstractContextHandler_h
/* /*
Copyright © 2010, 2011, 2012 Vladimír Vondruš <mosra@centrum.cz> Copyright © 2010, 2011, 2012 Vladimír Vondruš <mosra@centrum.cz>
@ -16,29 +16,29 @@
*/ */
/** @file /** @file
* @brief Class Magnum::Contexts::AbstractContext * @brief Class Magnum::Contexts::AbstractContextHandler
*/ */
#include "ExtensionWrangler.h" #include "ExtensionWrangler.h"
namespace Magnum { namespace Contexts { namespace Magnum { namespace Contexts {
/** @brief Base for OpenGL contexts */ /** @brief Base for OpenGL context handlers */
template<class Display, class VisualId, class Window> class AbstractContext { template<class Display, class VisualId, class Window> class AbstractContextHandler {
public: public:
/** /**
* @brief Get visual ID * @brief Get visual ID
* *
* Initializes the interface on given display and returns visual ID. * Initializes the handler on given display and returns visual ID.
*/ */
virtual VisualId getVisualId(Display nativeDisplay) = 0; virtual VisualId getVisualId(Display nativeDisplay) = 0;
/** /**
* @brief Destructor * @brief Destructor
* *
* Finalizes and closes the interface. * Finalizes and closes the handler.
*/ */
virtual ~AbstractContext() {} virtual ~AbstractContextHandler() {}
/** @brief Create context */ /** @brief Create context */
virtual void createContext(Window nativeWindow) = 0; virtual void createContext(Window nativeWindow) = 0;

14
src/Contexts/AbstractXWindowContext.cpp

@ -27,12 +27,12 @@ using namespace std;
namespace Magnum { namespace Contexts { namespace Magnum { namespace Contexts {
AbstractXWindowContext::AbstractXWindowContext(AbstractContext<Display*, VisualID, Window>* glInterface, int&, char**, const string& title, const Math::Vector2<GLsizei>& size): glInterface(glInterface), viewportSize(size), flags(Flag::Redraw) { AbstractXWindowContext::AbstractXWindowContext(AbstractContextHandler<Display*, VisualID, Window>* contextHandler, int&, char**, const string& title, const Math::Vector2<GLsizei>& size): contextHandler(contextHandler), viewportSize(size), flags(Flag::Redraw) {
/* Get default X display */ /* Get default X display */
display = XOpenDisplay(0); display = XOpenDisplay(0);
/* Get visual ID */ /* Get visual ID */
VisualID visualId = glInterface->getVisualId(display); VisualID visualId = contextHandler->getVisualId(display);
/* Get visual info */ /* Get visual info */
XVisualInfo *visInfo, visTemplate; XVisualInfo *visInfo, visTemplate;
@ -61,16 +61,16 @@ AbstractXWindowContext::AbstractXWindowContext(AbstractContext<Display*, VisualI
XSetWMProtocols(display, window, &deleteWindow, 1); XSetWMProtocols(display, window, &deleteWindow, 1);
/* Create context */ /* Create context */
glInterface->createContext(window); contextHandler->createContext(window);
/* Capture exposure, keyboard and mouse button events */ /* Capture exposure, keyboard and mouse button events */
XSelectInput(display, window, INPUT_MASK); XSelectInput(display, window, INPUT_MASK);
/* Set OpenGL context as current */ /* Set OpenGL context as current */
glInterface->makeCurrent(); contextHandler->makeCurrent();
/* Initialize extension wrangler */ /* Initialize extension wrangler */
ExtensionWrangler::initialize(glInterface->experimentalExtensionWranglerFeatures()); ExtensionWrangler::initialize(contextHandler->experimentalExtensionWranglerFeatures());
c = new Context; c = new Context;
} }
@ -78,8 +78,8 @@ AbstractXWindowContext::AbstractXWindowContext(AbstractContext<Display*, VisualI
AbstractXWindowContext::~AbstractXWindowContext() { AbstractXWindowContext::~AbstractXWindowContext() {
delete c; delete c;
/* Shut down the interface */ /* Shut down context handler */
delete glInterface; delete contextHandler;
/* Shut down X */ /* Shut down X */
XDestroyWindow(display, window); XDestroyWindow(display, window);

10
src/Contexts/AbstractXWindowContext.h

@ -31,7 +31,7 @@
#include "Math/Vector2.h" #include "Math/Vector2.h"
#include "AbstractWindowContext.h" #include "AbstractWindowContext.h"
#include "AbstractContext.h" #include "AbstractContextHandler.h"
namespace Magnum { namespace Magnum {
@ -50,7 +50,7 @@ class AbstractXWindowContext: public AbstractWindowContext {
public: public:
/** /**
* @brief Constructor * @brief Constructor
* @param glInterface Interface to OpenGL * @param contextHandler OpenGL context handler
* @param argc Count of arguments of `main()` function * @param argc Count of arguments of `main()` function
* @param argv Arguments of `main()` function * @param argv Arguments of `main()` function
* @param title Window title * @param title Window title
@ -58,7 +58,7 @@ class AbstractXWindowContext: public AbstractWindowContext {
* *
* Creates window with double-buffered OpenGL ES 2 context. * Creates window with double-buffered OpenGL ES 2 context.
*/ */
AbstractXWindowContext(AbstractContext<Display*, VisualID, Window>* glInterface, int& argc, char** argv, const std::string& title = "Magnum X/EGL context", const Math::Vector2<GLsizei>& size = Math::Vector2<GLsizei>(800, 600)); AbstractXWindowContext(AbstractContextHandler<Display*, VisualID, Window>* contextHandler, int& argc, char** argv, const std::string& title = "Magnum X/EGL context", const Math::Vector2<GLsizei>& size = Math::Vector2<GLsizei>(800, 600));
/** /**
* @brief Destructor * @brief Destructor
@ -82,7 +82,7 @@ class AbstractXWindowContext: public AbstractWindowContext {
virtual void drawEvent() = 0; virtual void drawEvent() = 0;
/** @copydoc GlutWindowContext::swapBuffers() */ /** @copydoc GlutWindowContext::swapBuffers() */
inline void swapBuffers() { glInterface->swapBuffers(); } inline void swapBuffers() { contextHandler->swapBuffers(); }
/** @copydoc GlutWindowContext::redraw() */ /** @copydoc GlutWindowContext::redraw() */
inline void redraw() { flags |= Flag::Redraw; } inline void redraw() { flags |= Flag::Redraw; }
@ -281,7 +281,7 @@ class AbstractXWindowContext: public AbstractWindowContext {
Window window; Window window;
Atom deleteWindow; Atom deleteWindow;
AbstractContext<Display*, VisualID, Window>* glInterface; AbstractContextHandler<Display*, VisualID, Window>* contextHandler;
Context* c; Context* c;

18
src/Contexts/CMakeLists.txt

@ -2,7 +2,7 @@
add_library(MagnumContextsExtensionWrangler OBJECT ExtensionWrangler.cpp) add_library(MagnumContextsExtensionWrangler OBJECT ExtensionWrangler.cpp)
set(MagnumContexts_HEADERS set(MagnumContexts_HEADERS
AbstractContext.h AbstractContextHandler.h
AbstractWindowContext.h AbstractWindowContext.h
ExtensionWrangler.h) ExtensionWrangler.h)
install(FILES ${MagnumContexts_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts) install(FILES ${MagnumContexts_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts)
@ -42,7 +42,7 @@ if(WITH_GLXWINDOWCONTEXT)
set(NEED_GLXCONTEXT 1) set(NEED_GLXCONTEXT 1)
add_library(MagnumGlxWindowContext STATIC add_library(MagnumGlxWindowContext STATIC
$<TARGET_OBJECTS:MagnumAbstractXWindowContext> $<TARGET_OBJECTS:MagnumAbstractXWindowContext>
$<TARGET_OBJECTS:MagnumGlxContext> $<TARGET_OBJECTS:MagnumGlxContextHandler>
$<TARGET_OBJECTS:MagnumContextsExtensionWrangler>) $<TARGET_OBJECTS:MagnumContextsExtensionWrangler>)
install(FILES GlxWindowContext.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts) install(FILES GlxWindowContext.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts)
install(TARGETS MagnumGlxWindowContext DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) install(TARGETS MagnumGlxWindowContext DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR})
@ -54,7 +54,7 @@ if(WITH_XEGLWINDOWCONTEXT)
set(NEED_EGLCONTEXT 1) set(NEED_EGLCONTEXT 1)
add_library(MagnumXEglWindowContext STATIC add_library(MagnumXEglWindowContext STATIC
$<TARGET_OBJECTS:MagnumAbstractXWindowContext> $<TARGET_OBJECTS:MagnumAbstractXWindowContext>
$<TARGET_OBJECTS:MagnumEglContext> $<TARGET_OBJECTS:MagnumEglContextHandler>
$<TARGET_OBJECTS:MagnumContextsExtensionWrangler>) $<TARGET_OBJECTS:MagnumContextsExtensionWrangler>)
install(FILES XEglWindowContext.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts) install(FILES XEglWindowContext.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts)
install(TARGETS MagnumXEglWindowContext DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}) install(TARGETS MagnumXEglWindowContext DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR})
@ -74,10 +74,10 @@ endif()
# GLX window context # GLX window context
if(NEED_GLXCONTEXT) if(NEED_GLXCONTEXT)
add_library(MagnumGlxContext OBJECT GlxContext.cpp) add_library(MagnumGlxContextHandler OBJECT GlxContextHandler.cpp)
# X11 macros are a mess, disable warnings for C-style casts # X11 macros are a mess, disable warnings for C-style casts
set_target_properties(MagnumGlxContext PROPERTIES COMPILE_FLAGS "-Wno-old-style-cast") set_target_properties(MagnumGlxContextHandler PROPERTIES COMPILE_FLAGS "-Wno-old-style-cast")
install(FILES GlxContext.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts) install(FILES GlxContextHandler.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts)
endif() endif()
# EGL context # EGL context
@ -86,8 +86,8 @@ if(NEED_EGLCONTEXT)
if(NOT EGL_FOUND) if(NOT EGL_FOUND)
message(FATAL_ERROR "EGL library, required by some window contexts, was not found. Set WITH_*EGL*WINDOWCONTEXT to OFF to skip building them.") message(FATAL_ERROR "EGL library, required by some window contexts, was not found. Set WITH_*EGL*WINDOWCONTEXT to OFF to skip building them.")
endif() endif()
add_library(MagnumEglContext OBJECT EglContext.cpp) add_library(MagnumEglContextHandler OBJECT EglContextHandler.cpp)
# X11 macros are a mess, disable warnings for C-style casts # X11 macros are a mess, disable warnings for C-style casts
set_target_properties(MagnumEglContext PROPERTIES COMPILE_FLAGS "-Wno-old-style-cast") set_target_properties(MagnumEglContextHandler PROPERTIES COMPILE_FLAGS "-Wno-old-style-cast")
install(FILES EglContext.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts) install(FILES EglContextHandler.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts)
endif() endif()

8
src/Contexts/EglContext.cpp → src/Contexts/EglContextHandler.cpp

@ -13,19 +13,19 @@
GNU Lesser General Public License version 3 for more details. GNU Lesser General Public License version 3 for more details.
*/ */
#include "EglContext.h" #include "EglContextHandler.h"
#include "Context.h" #include "Context.h"
namespace Magnum { namespace Contexts { namespace Magnum { namespace Contexts {
EglContext::~EglContext() { EglContextHandler::~EglContextHandler() {
eglDestroyContext(display, context); eglDestroyContext(display, context);
eglDestroySurface(display, surface); eglDestroySurface(display, surface);
eglTerminate(display); eglTerminate(display);
} }
VisualId EglContext::getVisualId(EGLNativeDisplayType nativeDisplay) { VisualId EglContextHandler::getVisualId(EGLNativeDisplayType nativeDisplay) {
/* Initialize */ /* Initialize */
display = eglGetDisplay(nativeDisplay); display = eglGetDisplay(nativeDisplay);
eglInitialize(display, 0, 0); eglInitialize(display, 0, 0);
@ -64,7 +64,7 @@ VisualId EglContext::getVisualId(EGLNativeDisplayType nativeDisplay) {
return visualId; return visualId;
} }
void EglContext::createContext(EGLNativeWindowType window) { void EglContextHandler::createContext(EGLNativeWindowType window) {
static const EGLint contextAttributes[] = { static const EGLint contextAttributes[] = {
#ifdef MAGNUM_TARGET_GLES #ifdef MAGNUM_TARGET_GLES
EGL_CONTEXT_CLIENT_VERSION, 2, EGL_CONTEXT_CLIENT_VERSION, 2,

12
src/Contexts/EglContext.h → src/Contexts/EglContextHandler.h

@ -1,5 +1,5 @@
#ifndef Magnum_Contexts_EglContext_h #ifndef Magnum_Contexts_EglContextHandler_h
#define Magnum_Contexts_EglContext_h #define Magnum_Contexts_EglContextHandler_h
/* /*
Copyright © 2010, 2011, 2012 Vladimír Vondruš <mosra@centrum.cz> Copyright © 2010, 2011, 2012 Vladimír Vondruš <mosra@centrum.cz>
@ -16,7 +16,7 @@
*/ */
/** @file /** @file
* @brief Class Magnum::Contexts::EglContext * @brief Class Magnum::Contexts::EglContextHandler
*/ */
#include "Magnum.h" #include "Magnum.h"
@ -26,7 +26,7 @@
#endif #endif
#include <EGL/egl.h> #include <EGL/egl.h>
#include "AbstractContext.h" #include "AbstractContextHandler.h"
namespace Magnum { namespace Contexts { namespace Magnum { namespace Contexts {
@ -44,9 +44,9 @@ typedef EGLInt VisualId;
Used in XEglWindowContext. Used in XEglWindowContext.
*/ */
class EglContext: public AbstractContext<EGLNativeDisplayType, VisualId, EGLNativeWindowType> { class EglContextHandler: public AbstractContextHandler<EGLNativeDisplayType, VisualId, EGLNativeWindowType> {
public: public:
~EglContext(); ~EglContextHandler();
VisualId getVisualId(EGLNativeDisplayType nativeDisplay); VisualId getVisualId(EGLNativeDisplayType nativeDisplay);
void createContext(EGLNativeWindowType nativeWindow); void createContext(EGLNativeWindowType nativeWindow);

14
src/Contexts/GlxContext.cpp → src/Contexts/GlxContextHandler.cpp

@ -13,7 +13,7 @@
GNU Lesser General Public License version 3 for more details. GNU Lesser General Public License version 3 for more details.
*/ */
#include "GlxContext.h" #include "GlxContextHandler.h"
#include <GL/glxext.h> #include <GL/glxext.h>
#include <Utility/Debug.h> #include <Utility/Debug.h>
@ -24,14 +24,14 @@
namespace Magnum { namespace Contexts { namespace Magnum { namespace Contexts {
VisualID GlxContext::getVisualId(Display* nativeDisplay) { VisualID GlxContextHandler::getVisualId(Display* nativeDisplay) {
display = nativeDisplay; display = nativeDisplay;
/* Check version */ /* Check version */
int major, minor; int major, minor;
glXQueryVersion(nativeDisplay, &major, &minor); glXQueryVersion(nativeDisplay, &major, &minor);
if(major == 1 && minor < 4) { if(major == 1 && minor < 4) {
Error() << "GlxContext: GLX version 1.4 or greater is required."; Error() << "GlxContextHandler: GLX version 1.4 or greater is required.";
exit(1); exit(1);
} }
@ -49,7 +49,7 @@ VisualID GlxContext::getVisualId(Display* nativeDisplay) {
}; };
configs = glXChooseFBConfig(nativeDisplay, DefaultScreen(nativeDisplay), attributes, &configCount); configs = glXChooseFBConfig(nativeDisplay, DefaultScreen(nativeDisplay), attributes, &configCount);
if(!configCount) { if(!configCount) {
Error() << "GlxContext: no supported framebuffer configuration found."; Error() << "GlxContextHandler: no supported framebuffer configuration found.";
exit(1); exit(1);
} }
@ -61,7 +61,7 @@ VisualID GlxContext::getVisualId(Display* nativeDisplay) {
return visualId; return visualId;
} }
void GlxContext::createContext(Window nativeWindow) { void GlxContextHandler::createContext(Window nativeWindow) {
window = nativeWindow; window = nativeWindow;
GLint attributes[] = { GLint attributes[] = {
@ -82,12 +82,12 @@ void GlxContext::createContext(Window nativeWindow) {
context = glXCreateContextAttribsARB(display, configs[0], 0, True, attributes); context = glXCreateContextAttribsARB(display, configs[0], 0, True, attributes);
XFree(configs); XFree(configs);
if(!context) { if(!context) {
Error() << "GlxContext: cannot create context."; Error() << "GlxContextHandler: cannot create context.";
exit(1); exit(1);
} }
} }
GlxContext::~GlxContext() { GlxContextHandler::~GlxContextHandler() {
glXMakeCurrent(display, None, nullptr); glXMakeCurrent(display, None, nullptr);
glXDestroyContext(display, context); glXDestroyContext(display, context);
} }

12
src/Contexts/GlxContext.h → src/Contexts/GlxContextHandler.h

@ -1,5 +1,5 @@
#ifndef Magnum_Contexts_GlxContext_h #ifndef Magnum_Contexts_GlxContextHandler_h
#define Magnum_Contexts_GlxContext_h #define Magnum_Contexts_GlxContextHandler_h
/* /*
Copyright © 2010, 2011, 2012 Vladimír Vondruš <mosra@centrum.cz> Copyright © 2010, 2011, 2012 Vladimír Vondruš <mosra@centrum.cz>
@ -16,7 +16,7 @@
*/ */
/** @file /** @file
* @brief Class Magnum::Contexts::GlxContext * @brief Class Magnum::Contexts::GlxContextHandler
*/ */
#include "Magnum.h" #include "Magnum.h"
@ -25,7 +25,7 @@
#undef None #undef None
#undef Always #undef Always
#include "AbstractContext.h" #include "AbstractContextHandler.h"
namespace Magnum { namespace Contexts { namespace Magnum { namespace Contexts {
@ -37,9 +37,9 @@ OpenGL ES.
Used in GlxWindowContext. Used in GlxWindowContext.
*/ */
class GlxContext: public AbstractContext<Display*, VisualID, Window> { class GlxContextHandler: public AbstractContextHandler<Display*, VisualID, Window> {
public: public:
~GlxContext(); ~GlxContextHandler();
VisualID getVisualId(Display* nativeDisplay); VisualID getVisualId(Display* nativeDisplay);
void createContext(Window nativeWindow); void createContext(Window nativeWindow);

6
src/Contexts/GlxWindowContext.h

@ -20,14 +20,14 @@
*/ */
#include "AbstractXWindowContext.h" #include "AbstractXWindowContext.h"
#include "GlxContext.h" #include "GlxContextHandler.h"
namespace Magnum { namespace Contexts { namespace Magnum { namespace Contexts {
/** /**
@brief GLX context @brief GLX context
Uses GlxContext. Uses GlxContextHandler.
*/ */
class GlxWindowContext: public AbstractXWindowContext { class GlxWindowContext: public AbstractXWindowContext {
public: public:
@ -41,7 +41,7 @@ class GlxWindowContext: public AbstractXWindowContext {
* Creates window with double-buffered OpenGL 3.3 core context or * Creates window with double-buffered OpenGL 3.3 core context or
* OpenGL ES 2.0 context, if targetting OpenGL ES. * OpenGL ES 2.0 context, if targetting OpenGL ES.
*/ */
inline GlxWindowContext(int& argc, char** argv, const std::string& title = "Magnum GLX context", const Math::Vector2<GLsizei>& size = Math::Vector2<GLsizei>(800, 600)): AbstractXWindowContext(new GlxContext, argc, argv, title, size) {} inline GlxWindowContext(int& argc, char** argv, const std::string& title = "Magnum GLX context", const Math::Vector2<GLsizei>& size = Math::Vector2<GLsizei>(800, 600)): AbstractXWindowContext(new GlxContextHandler, argc, argv, title, size) {}
}; };
}} }}

6
src/Contexts/XEglWindowContext.h

@ -20,14 +20,14 @@
*/ */
#include "AbstractXWindowContext.h" #include "AbstractXWindowContext.h"
#include "EglContext.h" #include "EglContextHandler.h"
namespace Magnum { namespace Contexts { namespace Magnum { namespace Contexts {
/** /**
@brief X/EGL context @brief X/EGL context
Uses EglContext. Uses EglContextHandler.
*/ */
class XEglWindowContext: public AbstractXWindowContext { class XEglWindowContext: public AbstractXWindowContext {
public: public:
@ -40,7 +40,7 @@ class XEglWindowContext: public AbstractXWindowContext {
* *
* Creates window with double-buffered OpenGL ES 2 context. * Creates window with double-buffered OpenGL ES 2 context.
*/ */
inline XEglWindowContext(int& argc, char** argv, const std::string& title = "Magnum X/EGL context", const Math::Vector2<GLsizei>& size = Math::Vector2<GLsizei>(800, 600)): AbstractXWindowContext(new EglContext, argc, argv, title, size) {} inline XEglWindowContext(int& argc, char** argv, const std::string& title = "Magnum X/EGL context", const Math::Vector2<GLsizei>& size = Math::Vector2<GLsizei>(800, 600)): AbstractXWindowContext(new EglContextHandler, argc, argv, title, size) {}
}; };
}} }}

Loading…
Cancel
Save