Browse Source

Contexts refactoring.

Contexts attached to window are now *WindowContext, pure contexts are
just *Context.
vectorfields
Vladimír Vondruš 14 years ago
parent
commit
a5ab6253b7
  1. 20
      modules/FindMagnum.cmake
  2. 52
      src/Contexts/AbstractContext.h
  3. 64
      src/Contexts/AbstractGlInterface.h
  4. 52
      src/Contexts/AbstractWindowContext.h
  5. 8
      src/Contexts/AbstractXWindowContext.cpp
  6. 38
      src/Contexts/AbstractXWindowContext.h
  7. 60
      src/Contexts/CMakeLists.txt
  8. 8
      src/Contexts/EglContext.cpp
  9. 14
      src/Contexts/EglContext.h
  10. 6
      src/Contexts/GlutWindowContext.cpp
  11. 22
      src/Contexts/GlutWindowContext.h
  12. 14
      src/Contexts/GlxContext.cpp
  13. 49
      src/Contexts/GlxContext.h
  14. 66
      src/Contexts/GlxInterface.h
  15. 49
      src/Contexts/GlxWindowContext.h
  16. 8
      src/Contexts/Sdl2WindowContext.cpp
  17. 34
      src/Contexts/Sdl2WindowContext.h
  18. 16
      src/Contexts/XEglWindowContext.h

20
modules/FindMagnum.cmake

@ -86,13 +86,13 @@ foreach(component ${Magnum_FIND_COMPONENTS})
set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_SUFFIX ${component})
# Contexts
if(${component} MATCHES .+Context)
# Window contexts
if(${component} MATCHES .+WindowContext)
set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_SUFFIX Contexts)
set(_MAGNUM_${_COMPONENT}_INCLUDE_PATH_NAMES ${component}.h)
# GLUT context dependencies
if(${component} STREQUAL GlutContext)
# GLUT window context dependencies
if(${component} STREQUAL GlutWindowContext)
find_package(GLUT)
if(GLUT_FOUND)
set(_MAGNUM_${_COMPONENT}_LIBRARIES ${GLUT_LIBRARIES})
@ -101,8 +101,8 @@ foreach(component ${Magnum_FIND_COMPONENTS})
endif()
endif()
# SDL2 context dependencies
if(${component} STREQUAL Sdl2Context)
# SDL2 window context dependencies
if(${component} STREQUAL Sdl2WindowContext)
find_package(SDL2)
if(SDL2_FOUND)
set(_MAGNUM_${_COMPONENT}_LIBRARIES ${SDL2_LIBRARY})
@ -112,8 +112,8 @@ foreach(component ${Magnum_FIND_COMPONENTS})
endif()
endif()
# GLX context dependencies
if(${component} STREQUAL GlxContext)
# GLX window context dependencies
if(${component} STREQUAL GlxWindowContext)
find_package(X11)
if(X11_FOUND)
set(_MAGNUM_${_COMPONENT}_LIBRARIES ${X11_LIBRARIES})
@ -122,8 +122,8 @@ foreach(component ${Magnum_FIND_COMPONENTS})
endif()
endif()
# X/EGL context dependencies
if(${component} STREQUAL XEglContext)
# X/EGL window context dependencies
if(${component} STREQUAL XEglWindowContext)
find_package(EGL)
find_package(X11)
if(EGL_FOUND AND X11_FOUND)

52
src/Contexts/AbstractContext.h

@ -19,32 +19,44 @@
* @brief Class Magnum::Contexts::AbstractContext
*/
namespace Magnum { namespace Contexts {
#include "ExtensionWrangler.h"
/**
@brief Base class for context creation
namespace Magnum { namespace Contexts {
See subclasses documentation for more information. Context classes subclasses
are meant to be used directly in `main()`, for example:
@code
class MyContext: public Magnum::Contexts::GlutContext {
// implement required methods...
};
int main(int argc, char** argv) {
MyContext c(argc, argv);
return c.exec();
}
@endcode
*/
class AbstractContext {
/** @brief Base for OpenGL contexts */
template<class Display, class VisualId, class Window> class AbstractContext {
public:
virtual inline ~AbstractContext() {}
/**
* @brief Get visual ID
*
* Initializes the interface on given display and returns visual ID.
*/
virtual VisualId getVisualId(Display nativeDisplay) = 0;
/**
* @brief Execute main loop
* @return Value for returning from `main()`.
* @brief Destructor
*
* Finalizes and closes the interface.
*/
virtual int exec() = 0;
virtual ~AbstractContext() {}
/** @brief Create context */
virtual void createContext(Window nativeWindow) = 0;
/**
* @brief Whether to enable experimental extension wrangler features
*
* Default is to disable.
*/
virtual inline ExtensionWrangler::ExperimentalFeatures experimentalExtensionWranglerFeatures() const {
return ExtensionWrangler::ExperimentalFeatures::Disable;
}
/** @brief Make the context current */
virtual void makeCurrent() = 0;
/** @brief Swap buffers */
virtual void swapBuffers() = 0;
};
}}

64
src/Contexts/AbstractGlInterface.h

@ -1,64 +0,0 @@
#ifndef Magnum_Contexts_AbstractGlInterface_h
#define Magnum_Contexts_AbstractGlInterface_h
/*
Copyright © 2010, 2011, 2012 Vladimír Vondruš <mosra@centrum.cz>
This file is part of Magnum.
Magnum is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License version 3
only, as published by the Free Software Foundation.
Magnum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License version 3 for more details.
*/
/** @file
* @brief Class Magnum::Contexts::AbstractGlInterface
*/
#include "ExtensionWrangler.h"
namespace Magnum { namespace Contexts {
/** @brief Base for OpenGL interfaces */
template<class Display, class VisualId, class Window> class AbstractGlInterface {
public:
/**
* @brief Get visual ID
*
* Initializes the interface on given display and returns visual ID.
*/
virtual VisualId getVisualId(Display nativeDisplay) = 0;
/**
* @brief Destructor
*
* Finalizes and closes the interface.
*/
virtual ~AbstractGlInterface() {}
/** @brief Create context */
virtual void createContext(Window nativeWindow) = 0;
/**
* @brief Whether to enable experimental extension wrangler features
*
* Default is to disable.
*/
virtual inline ExtensionWrangler::ExperimentalFeatures experimentalExtensionWranglerFeatures() const {
return ExtensionWrangler::ExperimentalFeatures::Disable;
}
/** @brief Make the context current */
virtual void makeCurrent() = 0;
/** @brief Swap buffers */
virtual void swapBuffers() = 0;
};
}}
#endif

52
src/Contexts/AbstractWindowContext.h

@ -0,0 +1,52 @@
#ifndef Magnum_Contexts_AbstractWindowContext_h
#define Magnum_Contexts_AbstractWindowContext_h
/*
Copyright © 2010, 2011, 2012 Vladimír Vondruš <mosra@centrum.cz>
This file is part of Magnum.
Magnum is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License version 3
only, as published by the Free Software Foundation.
Magnum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License version 3 for more details.
*/
/** @file
* @brief Class Magnum::Contexts::AbstractWindowContext
*/
namespace Magnum { namespace Contexts {
/**
@brief Base class for context creation
See subclasses documentation for more information. Context classes subclasses
are meant to be used directly in `main()`, for example:
@code
class MyContext: public Magnum::Contexts::GlutWindowContext {
// implement required methods...
};
int main(int argc, char** argv) {
MyContext c(argc, argv);
return c.exec();
}
@endcode
*/
class AbstractWindowContext {
public:
virtual inline ~AbstractWindowContext() {}
/**
* @brief Execute main loop
* @return Value for returning from `main()`.
*/
virtual int exec() = 0;
};
}}
#endif

8
src/Contexts/AbstractXContext.cpp → src/Contexts/AbstractXWindowContext.cpp

@ -13,7 +13,7 @@
GNU Lesser General Public License version 3 for more details.
*/
#include "AbstractXContext.h"
#include "AbstractXWindowContext.h"
#include "ExtensionWrangler.h"
@ -26,7 +26,7 @@ using namespace std;
namespace Magnum { namespace Contexts {
AbstractXContext::AbstractXContext(AbstractGlInterface<Display*, VisualID, Window>* glInterface, int&, char**, const string& title, const Math::Vector2<GLsizei>& size): glInterface(glInterface), viewportSize(size), flags(Flag::Redraw) {
AbstractXWindowContext::AbstractXWindowContext(AbstractContext<Display*, VisualID, Window>* glInterface, int&, char**, const string& title, const Math::Vector2<GLsizei>& size): glInterface(glInterface), viewportSize(size), flags(Flag::Redraw) {
/* Get default X display */
display = XOpenDisplay(0);
@ -72,7 +72,7 @@ AbstractXContext::AbstractXContext(AbstractGlInterface<Display*, VisualID, Windo
ExtensionWrangler::initialize(glInterface->experimentalExtensionWranglerFeatures());
}
AbstractXContext::~AbstractXContext() {
AbstractXWindowContext::~AbstractXWindowContext() {
/* Shut down the interface */
delete glInterface;
@ -81,7 +81,7 @@ AbstractXContext::~AbstractXContext() {
XCloseDisplay(display);
}
int AbstractXContext::exec() {
int AbstractXWindowContext::exec() {
/* Show window */
XMapWindow(display, window);

38
src/Contexts/AbstractXContext.h → src/Contexts/AbstractXWindowContext.h

@ -1,5 +1,5 @@
#ifndef Magnum_Contexts_AbstractXContext_h
#define Magnum_Contexts_AbstractXContext_h
#ifndef Magnum_Contexts_AbstractXWindowContext_h
#define Magnum_Contexts_AbstractXWindowContext_h
/*
Copyright © 2010, 2011, 2012 Vladimír Vondruš <mosra@centrum.cz>
@ -16,7 +16,7 @@
*/
/** @file
* @brief Class Magnum::Contexts::AbstractXContext
* @brief Class Magnum::Contexts::AbstractXWindowContext
*/
#include <Containers/EnumSet.h>
@ -30,8 +30,8 @@
#undef Always
#include "Math/Vector2.h"
#include "AbstractWindowContext.h"
#include "AbstractContext.h"
#include "AbstractGlInterface.h"
namespace Magnum { namespace Contexts {
@ -42,7 +42,7 @@ Supports keyboard and mouse handling.
@note Not meant to be used directly, see subclasses.
*/
class AbstractXContext: public AbstractContext {
class AbstractXWindowContext: public AbstractWindowContext {
public:
/**
* @brief Constructor
@ -54,14 +54,14 @@ class AbstractXContext: public AbstractContext {
*
* Creates window with double-buffered OpenGL ES 2 context.
*/
AbstractXContext(AbstractGlInterface<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(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));
/**
* @brief Destructor
*
* Deletes context and destroys the window.
*/
virtual ~AbstractXContext() = 0;
virtual ~AbstractXWindowContext() = 0;
int exec();
@ -71,16 +71,16 @@ class AbstractXContext: public AbstractContext {
/** @{ @name Drawing functions */
protected:
/** @copydoc GlutContext::viewportEvent() */
/** @copydoc GlutWindowContext::viewportEvent() */
virtual void viewportEvent(const Math::Vector2<GLsizei>& size) = 0;
/** @copydoc GlutContext::drawEvent() */
/** @copydoc GlutWindowContext::drawEvent() */
virtual void drawEvent() = 0;
/** @copydoc GlutContext::swapBuffers() */
/** @copydoc GlutWindowContext::swapBuffers() */
inline void swapBuffers() { glInterface->swapBuffers(); }
/** @copydoc GlutContext::redraw() */
/** @copydoc GlutWindowContext::redraw() */
inline void redraw() { flags |= Flag::Redraw; }
/*@}*/
@ -277,7 +277,7 @@ class AbstractXContext: public AbstractContext {
Window window;
Atom deleteWindow;
AbstractGlInterface<Display*, VisualID, Window>* glInterface;
AbstractContext<Display*, VisualID, Window>* glInterface;
/** @todo Get this from the created window */
Math::Vector2<GLsizei> viewportSize;
@ -285,15 +285,15 @@ class AbstractXContext: public AbstractContext {
Flags flags;
};
CORRADE_ENUMSET_OPERATORS(AbstractXContext::Modifiers)
CORRADE_ENUMSET_OPERATORS(AbstractXContext::Flags)
CORRADE_ENUMSET_OPERATORS(AbstractXWindowContext::Modifiers)
CORRADE_ENUMSET_OPERATORS(AbstractXWindowContext::Flags)
/* Implementations for inline functions with unused parameters */
inline void AbstractXContext::keyPressEvent(Key, Modifiers, const Math::Vector2<int>&) {}
inline void AbstractXContext::keyReleaseEvent(Key, Modifiers, const Math::Vector2<int>&) {}
inline void AbstractXContext::mousePressEvent(MouseButton, Modifiers, const Math::Vector2<int>&) {}
inline void AbstractXContext::mouseReleaseEvent(MouseButton, Modifiers, const Math::Vector2<int>&) {}
inline void AbstractXContext::mouseMotionEvent(Modifiers, const Math::Vector2<int>&) {}
inline void AbstractXWindowContext::keyPressEvent(Key, Modifiers, const Math::Vector2<int>&) {}
inline void AbstractXWindowContext::keyReleaseEvent(Key, Modifiers, const Math::Vector2<int>&) {}
inline void AbstractXWindowContext::mousePressEvent(MouseButton, Modifiers, const Math::Vector2<int>&) {}
inline void AbstractXWindowContext::mouseReleaseEvent(MouseButton, Modifiers, const Math::Vector2<int>&) {}
inline void AbstractXWindowContext::mouseMotionEvent(Modifiers, const Math::Vector2<int>&) {}
}}

60
src/Contexts/CMakeLists.txt

@ -3,7 +3,7 @@ add_library(MagnumContextsExtensionWrangler OBJECT ExtensionWrangler.cpp)
set(MagnumContexts_HEADERS
AbstractContext.h
AbstractGlInterface.h
AbstractWindowContext.h
ExtensionWrangler.h)
install(FILES ${MagnumContexts_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts)
@ -11,13 +11,13 @@ install(FILES ${MagnumContexts_HEADERS} DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR
if(WITH_GLUTCONTEXT)
find_package(GLUT)
if(GLUT_FOUND)
add_library(MagnumGlutContext STATIC
GlutContext.cpp
add_library(MagnumGlutWindowContext STATIC
GlutWindowContext.cpp
$<TARGET_OBJECTS:MagnumContextsExtensionWrangler>)
install(FILES GlutContext.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts)
install(TARGETS MagnumGlutContext DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR})
install(FILES GlutWindowContext.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts)
install(TARGETS MagnumGlutWindowContext DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR})
else()
message(FATAL_ERROR "GLUT library, required by GlutContext, was not found. Set WITH_GLUTCONTEXT to OFF to skip building it.")
message(FATAL_ERROR "GLUT library, required by GlutWindowContext, was not found. Set WITH_GLUTCONTEXT to OFF to skip building it.")
endif()
endif()
@ -26,13 +26,13 @@ if(WITH_SDL2CONTEXT)
find_package(SDL2)
if(SDL2_FOUND)
include_directories(${SDL2_INCLUDE_DIR})
add_library(MagnumSdl2Context STATIC
Sdl2Context.cpp
add_library(MagnumSdl2WindowContext STATIC
Sdl2WindowContext.cpp
$<TARGET_OBJECTS:MagnumContextsExtensionWrangler>)
install(FILES Sdl2Context.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts)
install(TARGETS MagnumSdl2Context DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR})
install(FILES Sdl2WindowContext.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts)
install(TARGETS MagnumSdl2WindowContext DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR})
else()
message(FATAL_ERROR "SDL2 library, required by Sdl2Context, was not found. Set WITH_SDL2CONTEXT to OFF to skip building it.")
message(FATAL_ERROR "SDL2 library, required by Sdl2WindowContext, was not found. Set WITH_SDL2CONTEXT to OFF to skip building it.")
endif()
endif()
@ -40,24 +40,24 @@ endif()
if(WITH_GLXCONTEXT)
set(NEED_ABSTRACTXCONTEXT 1)
set(NEED_GLXINTERFACE 1)
add_library(MagnumGlxContext STATIC
$<TARGET_OBJECTS:MagnumAbstractXContext>
$<TARGET_OBJECTS:MagnumGlxInterface>
add_library(MagnumGlxWindowContext STATIC
$<TARGET_OBJECTS:MagnumAbstractXWindowContext>
$<TARGET_OBJECTS:MagnumGlxContext>
$<TARGET_OBJECTS:MagnumContextsExtensionWrangler>)
install(FILES GlxContext.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts)
install(TARGETS MagnumGlxContext DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR})
install(FILES GlxWindowContext.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts)
install(TARGETS MagnumGlxWindowContext DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR})
endif()
# X/EGL context
if(WITH_XEGLCONTEXT)
set(NEED_ABSTRACTXCONTEXT 1)
set(NEED_EGLINTERFACE 1)
add_library(MagnumXEglContext STATIC
$<TARGET_OBJECTS:MagnumAbstractXContext>
$<TARGET_OBJECTS:MagnumEglInterface>
add_library(MagnumXEglWindowContext STATIC
$<TARGET_OBJECTS:MagnumAbstractXWindowContext>
$<TARGET_OBJECTS:MagnumEglContext>
$<TARGET_OBJECTS:MagnumContextsExtensionWrangler>)
install(FILES XEglContext.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts)
install(TARGETS MagnumXEglContext DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR})
install(FILES XEglWindowContext.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts)
install(TARGETS MagnumXEglWindowContext DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR})
endif()
# Abstract X context
@ -66,18 +66,18 @@ if(NEED_ABSTRACTXCONTEXT)
if(NOT X11_FOUND)
message(FATAL_ERROR "X11 library, required by some contexts, was not found. Set WITH_*X*CONTEXT to OFF to skip building them.")
endif()
add_library(MagnumAbstractXContext OBJECT AbstractXContext.cpp)
add_library(MagnumAbstractXWindowContext OBJECT AbstractXWindowContext.cpp)
# X11 macros are a mess, disable warnings for C-style casts
set_target_properties(MagnumAbstractXContext PROPERTIES COMPILE_FLAGS "-Wno-old-style-cast")
install(FILES AbstractXContext.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts)
set_target_properties(MagnumAbstractXWindowContext PROPERTIES COMPILE_FLAGS "-Wno-old-style-cast")
install(FILES AbstractXWindowContext.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts)
endif()
# GLX interface
if(NEED_GLXINTERFACE)
add_library(MagnumGlxInterface OBJECT GlxInterface.cpp)
add_library(MagnumGlxContext OBJECT GlxContext.cpp)
# X11 macros are a mess, disable warnings for C-style casts
set_target_properties(MagnumGlxInterface PROPERTIES COMPILE_FLAGS "-Wno-old-style-cast")
install(FILES GlxInterface.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts)
set_target_properties(MagnumGlxContext PROPERTIES COMPILE_FLAGS "-Wno-old-style-cast")
install(FILES GlxContext.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts)
endif()
# EGL interface
@ -86,8 +86,8 @@ if(NEED_EGLINTERFACE)
if(NOT EGL_FOUND)
message(FATAL_ERROR "EGL library, required by some contexts, was not found. Set WITH_*EGL*CONTEXT to OFF to skip building them.")
endif()
add_library(MagnumEglInterface OBJECT EglInterface.cpp)
add_library(MagnumEglContext OBJECT EglContext.cpp)
# X11 macros are a mess, disable warnings for C-style casts
set_target_properties(MagnumEglInterface PROPERTIES COMPILE_FLAGS "-Wno-old-style-cast")
install(FILES EglInterface.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts)
set_target_properties(MagnumEglContext PROPERTIES COMPILE_FLAGS "-Wno-old-style-cast")
install(FILES EglContext.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Contexts)
endif()

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

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

14
src/Contexts/EglInterface.h → src/Contexts/EglContext.h

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

6
src/Contexts/GlutContext.cpp → src/Contexts/GlutWindowContext.cpp

@ -13,15 +13,15 @@
GNU Lesser General Public License version 3 for more details.
*/
#include "GlutContext.h"
#include "GlutWindowContext.h"
#include "ExtensionWrangler.h"
namespace Magnum { namespace Contexts {
GlutContext* GlutContext::instance = nullptr;
GlutWindowContext* GlutWindowContext::instance = nullptr;
GlutContext::GlutContext(int& argc, char** argv, const std::string& title, const Math::Vector2<GLsizei>& size): argc(argc), argv(argv) {
GlutWindowContext::GlutWindowContext(int& argc, char** argv, const std::string& title, const Math::Vector2<GLsizei>& size): argc(argc), argv(argv) {
/* Save global instance */
instance = this;

22
src/Contexts/GlutContext.h → src/Contexts/GlutWindowContext.h

@ -1,5 +1,5 @@
#ifndef Magnum_Contexts_GlutContext_h
#define Magnum_Contexts_GlutContext_h
#ifndef Magnum_Contexts_GlutWindowContext_h
#define Magnum_Contexts_GlutWindowContext_h
/*
Copyright © 2010, 2011, 2012 Vladimír Vondruš <mosra@centrum.cz>
@ -16,7 +16,7 @@
*/
/** @file
* @brief Class Magnum::Contexts::GlutContext
* @brief Class Magnum::Contexts::GlutWindowContext
*/
#include <string>
@ -26,7 +26,7 @@
#include <GL/freeglut.h>
#include "AbstractContext.h"
#include "AbstractWindowContext.h"
namespace Magnum { namespace Contexts {
@ -39,7 +39,7 @@ support for changing cursor and mouse tracking and warping.
You need to implement at least drawEvent() and viewportEvent() to be able to
draw on the screen.
*/
class GlutContext: public AbstractContext {
class GlutWindowContext: public AbstractWindowContext {
public:
/**
* @brief Constructor
@ -50,7 +50,7 @@ class GlutContext: public AbstractContext {
*
* Creates double-buffered RGBA window with depth and stencil buffers.
*/
GlutContext(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));
inline int exec() {
glutMainLoop();
@ -242,17 +242,17 @@ class GlutContext: public AbstractContext {
instance->drawEvent();
}
static GlutContext* instance;
static GlutWindowContext* instance;
int& argc;
char** argv;
};
/* Implementations for inline functions with unused parameters */
inline void GlutContext::keyPressEvent(Key, const Math::Vector2<int>&) {}
inline void GlutContext::mousePressEvent(MouseButton, const Math::Vector2<int>&) {}
inline void GlutContext::mouseReleaseEvent(MouseButton, const Math::Vector2<int>&) {}
inline void GlutContext::mouseMotionEvent(const Math::Vector2<int>&) {}
inline void GlutWindowContext::keyPressEvent(Key, const Math::Vector2<int>&) {}
inline void GlutWindowContext::mousePressEvent(MouseButton, const Math::Vector2<int>&) {}
inline void GlutWindowContext::mouseReleaseEvent(MouseButton, const Math::Vector2<int>&) {}
inline void GlutWindowContext::mouseMotionEvent(const Math::Vector2<int>&) {}
}}

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

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

49
src/Contexts/GlxContext.h

@ -19,29 +19,46 @@
* @brief Class Magnum::Contexts::GlxContext
*/
#include "AbstractXContext.h"
#include "GlxInterface.h"
#include "Magnum.h"
#include <GL/glx.h>
#include "AbstractContext.h"
namespace Magnum { namespace Contexts {
/**
@brief GLX context
@brief GLX interface
Creates OpenGL 3.3 core context or OpenGL ES 2.0 context, if targetting
OpenGL ES.
Uses GlxInterface.
Used in GlxWindowContext.
*/
class GlxContext: public AbstractXContext {
class GlxContext: public AbstractContext<Display*, VisualID, Window> {
public:
/**
* @brief Constructor
* @param argc Count of arguments of `main()` function
* @param argv Arguments of `main()` function
* @param title Window title
* @param size Window size
*
* Creates window with double-buffered OpenGL 3.3 core context or
* OpenGL ES 2.0 context, if targetting OpenGL ES.
*/
inline GlxContext(int& argc, char** argv, const std::string& title = "Magnum GLX context", const Math::Vector2<GLsizei>& size = Math::Vector2<GLsizei>(800, 600)): AbstractXContext(new GlxInterface, argc, argv, title, size) {}
~GlxContext();
VisualID getVisualId(Display* nativeDisplay);
void createContext(Window nativeWindow);
/* This must be enabled, otherwise (on my NVidia) it crashes when creating VAO. WTF. */
inline ExtensionWrangler::ExperimentalFeatures experimentalExtensionWranglerFeatures() const {
return ExtensionWrangler::ExperimentalFeatures::Enable;
}
inline void makeCurrent() {
glXMakeCurrent(display, window, context);
}
inline void swapBuffers() {
glXSwapBuffers(display, window);
}
private:
Display* display;
Window window;
GLXFBConfig* configs;
GLXContext context;
};
}}

66
src/Contexts/GlxInterface.h

@ -1,66 +0,0 @@
#ifndef Magnum_Contexts_EglInterface_h
#define Magnum_Contexts_EglInterface_h
/*
Copyright © 2010, 2011, 2012 Vladimír Vondruš <mosra@centrum.cz>
This file is part of Magnum.
Magnum is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License version 3
only, as published by the Free Software Foundation.
Magnum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License version 3 for more details.
*/
/** @file
* @brief Class Magnum::Contexts::GlxInterface
*/
#include "Magnum.h"
#include <GL/glx.h>
#include "AbstractGlInterface.h"
namespace Magnum { namespace Contexts {
/**
@brief GLX interface
Creates OpenGL 3.3 core context or OpenGL ES 2.0 context, if targetting
OpenGL ES.
Used in GlxContext.
*/
class GlxInterface: public AbstractGlInterface<Display*, VisualID, Window> {
public:
~GlxInterface();
VisualID getVisualId(Display* nativeDisplay);
void createContext(Window nativeWindow);
/* This must be enabled, otherwise (on my NVidia) it crashes when creating VAO. WTF. */
inline ExtensionWrangler::ExperimentalFeatures experimentalExtensionWranglerFeatures() const {
return ExtensionWrangler::ExperimentalFeatures::Enable;
}
inline void makeCurrent() {
glXMakeCurrent(display, window, context);
}
inline void swapBuffers() {
glXSwapBuffers(display, window);
}
private:
Display* display;
Window window;
GLXFBConfig* configs;
GLXContext context;
};
}}
#endif

49
src/Contexts/GlxWindowContext.h

@ -0,0 +1,49 @@
#ifndef Magnum_Contexts_GlxWindowContext_h
#define Magnum_Contexts_GlxWindowContext_h
/*
Copyright © 2010, 2011, 2012 Vladimír Vondruš <mosra@centrum.cz>
This file is part of Magnum.
Magnum is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License version 3
only, as published by the Free Software Foundation.
Magnum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License version 3 for more details.
*/
/** @file
* @brief Class Magnum::Contexts::GlxWindowContext
*/
#include "AbstractXWindowContext.h"
#include "GlxContext.h"
namespace Magnum { namespace Contexts {
/**
@brief GLX context
Uses GlxContext.
*/
class GlxWindowContext: public AbstractXWindowContext {
public:
/**
* @brief Constructor
* @param argc Count of arguments of `main()` function
* @param argv Arguments of `main()` function
* @param title Window title
* @param size Window size
*
* 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) {}
};
}}
#endif

8
src/Contexts/Sdl2Context.cpp → src/Contexts/Sdl2WindowContext.cpp

@ -13,12 +13,12 @@
GNU Lesser General Public License version 3 for more details.
*/
#include "Sdl2Context.h"
#include "Sdl2WindowContext.h"
#include "ExtensionWrangler.h"
namespace Magnum { namespace Contexts {
Sdl2Context::Sdl2Context(int, char**, const std::string& name, const Math::Vector2<GLsizei>& size): _redraw(true) {
Sdl2WindowContext::Sdl2WindowContext(int, char**, const std::string& name, const Math::Vector2<GLsizei>& size): _redraw(true) {
if(SDL_Init(SDL_INIT_VIDEO) < 0) {
Error() << "Cannot initialize SDL.";
exit(1);
@ -54,13 +54,13 @@ Sdl2Context::Sdl2Context(int, char**, const std::string& name, const Math::Vecto
SDL_PushEvent(sizeEvent);
}
Sdl2Context::~Sdl2Context() {
Sdl2WindowContext::~Sdl2WindowContext() {
SDL_GL_DeleteContext(context);
SDL_DestroyWindow(window);
SDL_Quit();
}
int Sdl2Context::exec() {
int Sdl2WindowContext::exec() {
for(;;) {
SDL_Event event;

34
src/Contexts/Sdl2Context.h → src/Contexts/Sdl2WindowContext.h

@ -1,5 +1,5 @@
#ifndef Magnum_Contexts_Sdl2Context_h
#define Magnum_Contexts_Sdl2Context_h
#ifndef Magnum_Contexts_Sdl2WindowContext_h
#define Magnum_Contexts_Sdl2WindowContext_h
/*
Copyright © 2010, 2011, 2012 Vladimír Vondruš <mosra@centrum.cz>
@ -16,7 +16,7 @@
*/
/** @file
* @brief Class Magnum::Contexts::Sdl2Context
* @brief Class Magnum::Contexts::Sdl2WindowContext
*/
#include "Math/Vector2.h"
@ -25,7 +25,7 @@
#include <SDL2/SDL.h>
#include <SDL2/SDL_scancode.h>
#include "AbstractContext.h"
#include "AbstractWindowContext.h"
namespace Magnum { namespace Contexts {
@ -37,7 +37,7 @@ Supports keyboard and mouse handling.
You need to implement at least drawEvent() and viewportEvent() to be able to
draw on the screen.
*/
class Sdl2Context: public AbstractContext {
class Sdl2WindowContext: public AbstractWindowContext {
public:
/**
* @brief Constructor
@ -49,30 +49,30 @@ class Sdl2Context: public AbstractContext {
* Creates centered non-resizable window with double-buffered
* OpenGL 3.3 context with 24bit depth buffer.
*/
Sdl2Context(int argc, char** argv, const std::string& title = "Magnum SDL2 context", const Math::Vector2<GLsizei>& size = Math::Vector2<GLsizei>(800, 600));
Sdl2WindowContext(int argc, char** argv, const std::string& title = "Magnum SDL2 context", const Math::Vector2<GLsizei>& size = Math::Vector2<GLsizei>(800, 600));
/**
* @brief Destructor
*
* Deletes context and destroys the window.
*/
~Sdl2Context();
~Sdl2WindowContext();
int exec();
/** @{ @name Drawing functions */
protected:
/** @copydoc GlutContext::viewportEvent() */
/** @copydoc GlutWindowContext::viewportEvent() */
virtual void viewportEvent(const Math::Vector2<GLsizei>& size) = 0;
/** @copydoc GlutContext::drawEvent() */
/** @copydoc GlutWindowContext::drawEvent() */
virtual void drawEvent() = 0;
/** @copydoc GlutContext::swapBuffers() */
/** @copydoc GlutWindowContext::swapBuffers() */
inline void swapBuffers() { SDL_GL_SwapWindow(window); }
/** @copydoc GlutContext::redraw() */
/** @copydoc GlutWindowContext::redraw() */
inline void redraw() { _redraw = true; }
/*@}*/
@ -183,12 +183,12 @@ class Sdl2Context: public AbstractContext {
};
/* Implementations for inline functions with unused parameters */
inline void Sdl2Context::keyPressEvent(Key, Uint8) {}
inline void Sdl2Context::keyReleaseEvent(Key) {}
inline void Sdl2Context::mousePressEvent(MouseButton, const Math::Vector2<int>&) {}
inline void Sdl2Context::mouseReleaseEvent(MouseButton, const Math::Vector2<int>&) {}
inline void Sdl2Context::mouseWheelEvent(const Math::Vector2<int>&) {}
inline void Sdl2Context::mouseMotionEvent(const Math::Vector2<int>&, const Math::Vector2<int>&) {}
inline void Sdl2WindowContext::keyPressEvent(Key, Uint8) {}
inline void Sdl2WindowContext::keyReleaseEvent(Key) {}
inline void Sdl2WindowContext::mousePressEvent(MouseButton, const Math::Vector2<int>&) {}
inline void Sdl2WindowContext::mouseReleaseEvent(MouseButton, const Math::Vector2<int>&) {}
inline void Sdl2WindowContext::mouseWheelEvent(const Math::Vector2<int>&) {}
inline void Sdl2WindowContext::mouseMotionEvent(const Math::Vector2<int>&, const Math::Vector2<int>&) {}
}}

16
src/Contexts/XEglContext.h → src/Contexts/XEglWindowContext.h

@ -1,5 +1,5 @@
#ifndef Magnum_Contexts_XEglContext_h
#define Magnum_Contexts_XEglContext_h
#ifndef Magnum_Contexts_XEglWindowContext_h
#define Magnum_Contexts_XEglWindowContext_h
/*
Copyright © 2010, 2011, 2012 Vladimír Vondruš <mosra@centrum.cz>
@ -16,20 +16,20 @@
*/
/** @file
* @brief Class Magnum::Contexts::XEglContext
* @brief Class Magnum::Contexts::XEglWindowContext
*/
#include "AbstractXContext.h"
#include "EglInterface.h"
#include "AbstractXWindowContext.h"
#include "EglContext.h"
namespace Magnum { namespace Contexts {
/**
@brief X/EGL context
Uses EglInterface.
Uses EglContext.
*/
class XEglContext: public AbstractXContext {
class XEglWindowContext: public AbstractXWindowContext {
public:
/**
* @brief Constructor
@ -40,7 +40,7 @@ class XEglContext: public AbstractXContext {
*
* Creates window with double-buffered OpenGL ES 2 context.
*/
inline XEglContext(int& argc, char** argv, const std::string& title = "Magnum X/EGL context", const Math::Vector2<GLsizei>& size = Math::Vector2<GLsizei>(800, 600)): AbstractXContext(new EglInterface, 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 EglContext, argc, argv, title, size) {}
};
}}
Loading…
Cancel
Save