Browse Source

Renamed Contexts::*Context to *ContextHandler.

Finally (and hopefully) consistent and non-confusing naming.
vectorfields
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
#define Magnum_Contexts_AbstractContext_h
#ifndef Magnum_Contexts_AbstractContextHandler_h
#define Magnum_Contexts_AbstractContextHandler_h
/*
Copyright © 2010, 2011, 2012 Vladimír Vondruš <mosra@centrum.cz>
@ -16,29 +16,29 @@
*/
/** @file
* @brief Class Magnum::Contexts::AbstractContext
* @brief Class Magnum::Contexts::AbstractContextHandler
*/
#include "ExtensionWrangler.h"
namespace Magnum { namespace Contexts {
/** @brief Base for OpenGL contexts */
template<class Display, class VisualId, class Window> class AbstractContext {
/** @brief Base for OpenGL context handlers */
template<class Display, class VisualId, class Window> class AbstractContextHandler {
public:
/**
* @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;
/**
* @brief Destructor
*
* Finalizes and closes the interface.
* Finalizes and closes the handler.
*/
virtual ~AbstractContext() {}
virtual ~AbstractContextHandler() {}
/** @brief Create context */
virtual void createContext(Window nativeWindow) = 0;

14
src/Contexts/AbstractXWindowContext.cpp

@ -27,12 +27,12 @@ using namespace std;
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 */
display = XOpenDisplay(0);
/* Get visual ID */
VisualID visualId = glInterface->getVisualId(display);
VisualID visualId = contextHandler->getVisualId(display);
/* Get visual info */
XVisualInfo *visInfo, visTemplate;
@ -61,16 +61,16 @@ AbstractXWindowContext::AbstractXWindowContext(AbstractContext<Display*, VisualI
XSetWMProtocols(display, window, &deleteWindow, 1);
/* Create context */
glInterface->createContext(window);
contextHandler->createContext(window);
/* Capture exposure, keyboard and mouse button events */
XSelectInput(display, window, INPUT_MASK);
/* Set OpenGL context as current */
glInterface->makeCurrent();
contextHandler->makeCurrent();
/* Initialize extension wrangler */
ExtensionWrangler::initialize(glInterface->experimentalExtensionWranglerFeatures());
ExtensionWrangler::initialize(contextHandler->experimentalExtensionWranglerFeatures());
c = new Context;
}
@ -78,8 +78,8 @@ AbstractXWindowContext::AbstractXWindowContext(AbstractContext<Display*, VisualI
AbstractXWindowContext::~AbstractXWindowContext() {
delete c;
/* Shut down the interface */
delete glInterface;
/* Shut down context handler */
delete contextHandler;
/* Shut down X */
XDestroyWindow(display, window);

10
src/Contexts/AbstractXWindowContext.h

@ -31,7 +31,7 @@
#include "Math/Vector2.h"
#include "AbstractWindowContext.h"
#include "AbstractContext.h"
#include "AbstractContextHandler.h"
namespace Magnum {
@ -50,7 +50,7 @@ class AbstractXWindowContext: public AbstractWindowContext {
public:
/**
* @brief Constructor
* @param glInterface Interface to OpenGL
* @param contextHandler OpenGL context handler
* @param argc Count of arguments of `main()` function
* @param argv Arguments of `main()` function
* @param title Window title
@ -58,7 +58,7 @@ class AbstractXWindowContext: public AbstractWindowContext {
*
* 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
@ -82,7 +82,7 @@ class AbstractXWindowContext: public AbstractWindowContext {
virtual void drawEvent() = 0;
/** @copydoc GlutWindowContext::swapBuffers() */
inline void swapBuffers() { glInterface->swapBuffers(); }
inline void swapBuffers() { contextHandler->swapBuffers(); }
/** @copydoc GlutWindowContext::redraw() */
inline void redraw() { flags |= Flag::Redraw; }
@ -281,7 +281,7 @@ class AbstractXWindowContext: public AbstractWindowContext {
Window window;
Atom deleteWindow;
AbstractContext<Display*, VisualID, Window>* glInterface;
AbstractContextHandler<Display*, VisualID, Window>* contextHandler;
Context* c;

18
src/Contexts/CMakeLists.txt

@ -2,7 +2,7 @@
add_library(MagnumContextsExtensionWrangler OBJECT ExtensionWrangler.cpp)
set(MagnumContexts_HEADERS
AbstractContext.h
AbstractContextHandler.h
AbstractWindowContext.h
ExtensionWrangler.h)
install(FILES ${MagnumContexts_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts)
@ -42,7 +42,7 @@ if(WITH_GLXWINDOWCONTEXT)
set(NEED_GLXCONTEXT 1)
add_library(MagnumGlxWindowContext STATIC
$<TARGET_OBJECTS:MagnumAbstractXWindowContext>
$<TARGET_OBJECTS:MagnumGlxContext>
$<TARGET_OBJECTS:MagnumGlxContextHandler>
$<TARGET_OBJECTS:MagnumContextsExtensionWrangler>)
install(FILES GlxWindowContext.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts)
install(TARGETS MagnumGlxWindowContext DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR})
@ -54,7 +54,7 @@ if(WITH_XEGLWINDOWCONTEXT)
set(NEED_EGLCONTEXT 1)
add_library(MagnumXEglWindowContext STATIC
$<TARGET_OBJECTS:MagnumAbstractXWindowContext>
$<TARGET_OBJECTS:MagnumEglContext>
$<TARGET_OBJECTS:MagnumEglContextHandler>
$<TARGET_OBJECTS:MagnumContextsExtensionWrangler>)
install(FILES XEglWindowContext.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts)
install(TARGETS MagnumXEglWindowContext DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR})
@ -74,10 +74,10 @@ endif()
# GLX window context
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
set_target_properties(MagnumGlxContext PROPERTIES COMPILE_FLAGS "-Wno-old-style-cast")
install(FILES GlxContext.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts)
set_target_properties(MagnumGlxContextHandler PROPERTIES COMPILE_FLAGS "-Wno-old-style-cast")
install(FILES GlxContextHandler.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts)
endif()
# EGL context
@ -86,8 +86,8 @@ if(NEED_EGLCONTEXT)
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.")
endif()
add_library(MagnumEglContext OBJECT EglContext.cpp)
add_library(MagnumEglContextHandler OBJECT EglContextHandler.cpp)
# X11 macros are a mess, disable warnings for C-style casts
set_target_properties(MagnumEglContext PROPERTIES COMPILE_FLAGS "-Wno-old-style-cast")
install(FILES EglContext.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts)
set_target_properties(MagnumEglContextHandler PROPERTIES COMPILE_FLAGS "-Wno-old-style-cast")
install(FILES EglContextHandler.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts)
endif()

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

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

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

@ -1,5 +1,5 @@
#ifndef Magnum_Contexts_EglContext_h
#define Magnum_Contexts_EglContext_h
#ifndef Magnum_Contexts_EglContextHandler_h
#define Magnum_Contexts_EglContextHandler_h
/*
Copyright © 2010, 2011, 2012 Vladimír Vondruš <mosra@centrum.cz>
@ -16,7 +16,7 @@
*/
/** @file
* @brief Class Magnum::Contexts::EglContext
* @brief Class Magnum::Contexts::EglContextHandler
*/
#include "Magnum.h"
@ -26,7 +26,7 @@
#endif
#include <EGL/egl.h>
#include "AbstractContext.h"
#include "AbstractContextHandler.h"
namespace Magnum { namespace Contexts {
@ -44,9 +44,9 @@ typedef EGLInt VisualId;
Used in XEglWindowContext.
*/
class EglContext: public AbstractContext<EGLNativeDisplayType, VisualId, EGLNativeWindowType> {
class EglContextHandler: public AbstractContextHandler<EGLNativeDisplayType, VisualId, EGLNativeWindowType> {
public:
~EglContext();
~EglContextHandler();
VisualId getVisualId(EGLNativeDisplayType nativeDisplay);
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.
*/
#include "GlxContext.h"
#include "GlxContextHandler.h"
#include <GL/glxext.h>
#include <Utility/Debug.h>
@ -24,14 +24,14 @@
namespace Magnum { namespace Contexts {
VisualID GlxContext::getVisualId(Display* nativeDisplay) {
VisualID GlxContextHandler::getVisualId(Display* nativeDisplay) {
display = nativeDisplay;
/* Check version */
int major, minor;
glXQueryVersion(nativeDisplay, &major, &minor);
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);
}
@ -49,7 +49,7 @@ VisualID GlxContext::getVisualId(Display* nativeDisplay) {
};
configs = glXChooseFBConfig(nativeDisplay, DefaultScreen(nativeDisplay), attributes, &configCount);
if(!configCount) {
Error() << "GlxContext: no supported framebuffer configuration found.";
Error() << "GlxContextHandler: no supported framebuffer configuration found.";
exit(1);
}
@ -61,7 +61,7 @@ VisualID GlxContext::getVisualId(Display* nativeDisplay) {
return visualId;
}
void GlxContext::createContext(Window nativeWindow) {
void GlxContextHandler::createContext(Window nativeWindow) {
window = nativeWindow;
GLint attributes[] = {
@ -82,12 +82,12 @@ void GlxContext::createContext(Window nativeWindow) {
context = glXCreateContextAttribsARB(display, configs[0], 0, True, attributes);
XFree(configs);
if(!context) {
Error() << "GlxContext: cannot create context.";
Error() << "GlxContextHandler: cannot create context.";
exit(1);
}
}
GlxContext::~GlxContext() {
GlxContextHandler::~GlxContextHandler() {
glXMakeCurrent(display, None, nullptr);
glXDestroyContext(display, context);
}

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

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

6
src/Contexts/GlxWindowContext.h

@ -20,14 +20,14 @@
*/
#include "AbstractXWindowContext.h"
#include "GlxContext.h"
#include "GlxContextHandler.h"
namespace Magnum { namespace Contexts {
/**
@brief GLX context
Uses GlxContext.
Uses GlxContextHandler.
*/
class GlxWindowContext: public AbstractXWindowContext {
public:
@ -41,7 +41,7 @@ class GlxWindowContext: public AbstractXWindowContext {
* Creates window with double-buffered OpenGL 3.3 core context or
* 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 "EglContext.h"
#include "EglContextHandler.h"
namespace Magnum { namespace Contexts {
/**
@brief X/EGL context
Uses EglContext.
Uses EglContextHandler.
*/
class XEglWindowContext: public AbstractXWindowContext {
public:
@ -40,7 +40,7 @@ class XEglWindowContext: public AbstractXWindowContext {
*
* 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