diff --git a/modules/FindMagnum.cmake b/modules/FindMagnum.cmake index 5568c5999..70b874ff9 100644 --- a/modules/FindMagnum.cmake +++ b/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) diff --git a/src/Contexts/AbstractContext.h b/src/Contexts/AbstractContext.h index f754d1012..93aeb121e 100644 --- a/src/Contexts/AbstractContext.h +++ b/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 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; }; }} diff --git a/src/Contexts/AbstractGlInterface.h b/src/Contexts/AbstractGlInterface.h deleted file mode 100644 index 3f6d14ef6..000000000 --- a/src/Contexts/AbstractGlInterface.h +++ /dev/null @@ -1,64 +0,0 @@ -#ifndef Magnum_Contexts_AbstractGlInterface_h -#define Magnum_Contexts_AbstractGlInterface_h -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - 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 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 diff --git a/src/Contexts/AbstractWindowContext.h b/src/Contexts/AbstractWindowContext.h new file mode 100644 index 000000000..8d5b0ba78 --- /dev/null +++ b/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š + + 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 diff --git a/src/Contexts/AbstractXContext.cpp b/src/Contexts/AbstractXWindowContext.cpp similarity index 92% rename from src/Contexts/AbstractXContext.cpp rename to src/Contexts/AbstractXWindowContext.cpp index 9c0747aaf..061111f5d 100644 --- a/src/Contexts/AbstractXContext.cpp +++ b/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* glInterface, int&, char**, const string& title, const Math::Vector2& size): glInterface(glInterface), viewportSize(size), flags(Flag::Redraw) { +AbstractXWindowContext::AbstractXWindowContext(AbstractContext* glInterface, int&, char**, const string& title, const Math::Vector2& size): glInterface(glInterface), viewportSize(size), flags(Flag::Redraw) { /* Get default X display */ display = XOpenDisplay(0); @@ -72,7 +72,7 @@ AbstractXContext::AbstractXContext(AbstractGlInterfaceexperimentalExtensionWranglerFeatures()); } -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); diff --git a/src/Contexts/AbstractXContext.h b/src/Contexts/AbstractXWindowContext.h similarity index 87% rename from src/Contexts/AbstractXContext.h rename to src/Contexts/AbstractXWindowContext.h index 622e81ef3..c94eb34bd 100644 --- a/src/Contexts/AbstractXContext.h +++ b/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š @@ -16,7 +16,7 @@ */ /** @file - * @brief Class Magnum::Contexts::AbstractXContext + * @brief Class Magnum::Contexts::AbstractXWindowContext */ #include @@ -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* glInterface, int& argc, char** argv, const std::string& title = "Magnum X/EGL context", const Math::Vector2& size = Math::Vector2(800, 600)); + AbstractXWindowContext(AbstractContext* glInterface, int& argc, char** argv, const std::string& title = "Magnum X/EGL context", const Math::Vector2& size = Math::Vector2(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& 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* glInterface; + AbstractContext* glInterface; /** @todo Get this from the created window */ Math::Vector2 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&) {} -inline void AbstractXContext::keyReleaseEvent(Key, Modifiers, const Math::Vector2&) {} -inline void AbstractXContext::mousePressEvent(MouseButton, Modifiers, const Math::Vector2&) {} -inline void AbstractXContext::mouseReleaseEvent(MouseButton, Modifiers, const Math::Vector2&) {} -inline void AbstractXContext::mouseMotionEvent(Modifiers, const Math::Vector2&) {} +inline void AbstractXWindowContext::keyPressEvent(Key, Modifiers, const Math::Vector2&) {} +inline void AbstractXWindowContext::keyReleaseEvent(Key, Modifiers, const Math::Vector2&) {} +inline void AbstractXWindowContext::mousePressEvent(MouseButton, Modifiers, const Math::Vector2&) {} +inline void AbstractXWindowContext::mouseReleaseEvent(MouseButton, Modifiers, const Math::Vector2&) {} +inline void AbstractXWindowContext::mouseMotionEvent(Modifiers, const Math::Vector2&) {} }} diff --git a/src/Contexts/CMakeLists.txt b/src/Contexts/CMakeLists.txt index 7d5cd8fe0..715bb4e5a 100644 --- a/src/Contexts/CMakeLists.txt +++ b/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 $) - 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 $) - 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 - $ - $ + add_library(MagnumGlxWindowContext STATIC + $ + $ $) - 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 - $ - $ + add_library(MagnumXEglWindowContext STATIC + $ + $ $) - 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() diff --git a/src/Contexts/EglInterface.cpp b/src/Contexts/EglContext.cpp similarity index 92% rename from src/Contexts/EglInterface.cpp rename to src/Contexts/EglContext.cpp index 609f37322..323e880e1 100644 --- a/src/Contexts/EglInterface.cpp +++ b/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, diff --git a/src/Contexts/EglInterface.h b/src/Contexts/EglContext.h similarity index 82% rename from src/Contexts/EglInterface.h rename to src/Contexts/EglContext.h index 671d6df18..0190fa299 100644 --- a/src/Contexts/EglInterface.h +++ b/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š @@ -16,7 +16,7 @@ */ /** @file - * @brief Class Magnum::Contexts::EglInterface + * @brief Class Magnum::Contexts::EglContext */ #include "Magnum.h" @@ -26,7 +26,7 @@ #endif #include -#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 { +class EglContext: public AbstractContext { public: - ~EglInterface(); + ~EglContext(); VisualId getVisualId(EGLNativeDisplayType nativeDisplay); void createContext(EGLNativeWindowType nativeWindow); diff --git a/src/Contexts/GlutContext.cpp b/src/Contexts/GlutWindowContext.cpp similarity index 83% rename from src/Contexts/GlutContext.cpp rename to src/Contexts/GlutWindowContext.cpp index 01307482d..785bbda0c 100644 --- a/src/Contexts/GlutContext.cpp +++ b/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& size): argc(argc), argv(argv) { +GlutWindowContext::GlutWindowContext(int& argc, char** argv, const std::string& title, const Math::Vector2& size): argc(argc), argv(argv) { /* Save global instance */ instance = this; diff --git a/src/Contexts/GlutContext.h b/src/Contexts/GlutWindowContext.h similarity index 90% rename from src/Contexts/GlutContext.h rename to src/Contexts/GlutWindowContext.h index 960775a94..ad46a4100 100644 --- a/src/Contexts/GlutContext.h +++ b/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š @@ -16,7 +16,7 @@ */ /** @file - * @brief Class Magnum::Contexts::GlutContext + * @brief Class Magnum::Contexts::GlutWindowContext */ #include @@ -26,7 +26,7 @@ #include -#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& size = Math::Vector2(800, 600)); + GlutWindowContext(int& argc, char** argv, const std::string& title = "Magnum GLUT context", const Math::Vector2& size = Math::Vector2(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&) {} -inline void GlutContext::mousePressEvent(MouseButton, const Math::Vector2&) {} -inline void GlutContext::mouseReleaseEvent(MouseButton, const Math::Vector2&) {} -inline void GlutContext::mouseMotionEvent(const Math::Vector2&) {} +inline void GlutWindowContext::keyPressEvent(Key, const Math::Vector2&) {} +inline void GlutWindowContext::mousePressEvent(MouseButton, const Math::Vector2&) {} +inline void GlutWindowContext::mouseReleaseEvent(MouseButton, const Math::Vector2&) {} +inline void GlutWindowContext::mouseMotionEvent(const Math::Vector2&) {} }} diff --git a/src/Contexts/GlxInterface.cpp b/src/Contexts/GlxContext.cpp similarity index 86% rename from src/Contexts/GlxInterface.cpp rename to src/Contexts/GlxContext.cpp index a9ce9aba0..328edffd7 100644 --- a/src/Contexts/GlxInterface.cpp +++ b/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 #include 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); } diff --git a/src/Contexts/GlxContext.h b/src/Contexts/GlxContext.h index a11b503c7..4f5cc775b 100644 --- a/src/Contexts/GlxContext.h +++ b/src/Contexts/GlxContext.h @@ -19,29 +19,46 @@ * @brief Class Magnum::Contexts::GlxContext */ -#include "AbstractXContext.h" -#include "GlxInterface.h" +#include "Magnum.h" +#include + +#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 { 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& size = Math::Vector2(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; }; }} diff --git a/src/Contexts/GlxInterface.h b/src/Contexts/GlxInterface.h deleted file mode 100644 index e9f3177d8..000000000 --- a/src/Contexts/GlxInterface.h +++ /dev/null @@ -1,66 +0,0 @@ -#ifndef Magnum_Contexts_EglInterface_h -#define Magnum_Contexts_EglInterface_h -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - 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 - -#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 { - 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 diff --git a/src/Contexts/GlxWindowContext.h b/src/Contexts/GlxWindowContext.h new file mode 100644 index 000000000..65f68da50 --- /dev/null +++ b/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š + + 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& size = Math::Vector2(800, 600)): AbstractXWindowContext(new GlxContext, argc, argv, title, size) {} +}; + +}} + +#endif diff --git a/src/Contexts/Sdl2Context.cpp b/src/Contexts/Sdl2WindowContext.cpp similarity index 94% rename from src/Contexts/Sdl2Context.cpp rename to src/Contexts/Sdl2WindowContext.cpp index f55fa6125..8edc77190 100644 --- a/src/Contexts/Sdl2Context.cpp +++ b/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& size): _redraw(true) { +Sdl2WindowContext::Sdl2WindowContext(int, char**, const std::string& name, const Math::Vector2& 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; diff --git a/src/Contexts/Sdl2Context.h b/src/Contexts/Sdl2WindowContext.h similarity index 81% rename from src/Contexts/Sdl2Context.h rename to src/Contexts/Sdl2WindowContext.h index 5f91d9e75..ca80ec681 100644 --- a/src/Contexts/Sdl2Context.h +++ b/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š @@ -16,7 +16,7 @@ */ /** @file - * @brief Class Magnum::Contexts::Sdl2Context + * @brief Class Magnum::Contexts::Sdl2WindowContext */ #include "Math/Vector2.h" @@ -25,7 +25,7 @@ #include #include -#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& size = Math::Vector2(800, 600)); + Sdl2WindowContext(int argc, char** argv, const std::string& title = "Magnum SDL2 context", const Math::Vector2& size = Math::Vector2(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& 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&) {} -inline void Sdl2Context::mouseReleaseEvent(MouseButton, const Math::Vector2&) {} -inline void Sdl2Context::mouseWheelEvent(const Math::Vector2&) {} -inline void Sdl2Context::mouseMotionEvent(const Math::Vector2&, const Math::Vector2&) {} +inline void Sdl2WindowContext::keyPressEvent(Key, Uint8) {} +inline void Sdl2WindowContext::keyReleaseEvent(Key) {} +inline void Sdl2WindowContext::mousePressEvent(MouseButton, const Math::Vector2&) {} +inline void Sdl2WindowContext::mouseReleaseEvent(MouseButton, const Math::Vector2&) {} +inline void Sdl2WindowContext::mouseWheelEvent(const Math::Vector2&) {} +inline void Sdl2WindowContext::mouseMotionEvent(const Math::Vector2&, const Math::Vector2&) {} }} diff --git a/src/Contexts/XEglContext.h b/src/Contexts/XEglWindowContext.h similarity index 66% rename from src/Contexts/XEglContext.h rename to src/Contexts/XEglWindowContext.h index fb368c1db..131c5498c 100644 --- a/src/Contexts/XEglContext.h +++ b/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š @@ -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& size = Math::Vector2(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& size = Math::Vector2(800, 600)): AbstractXWindowContext(new EglContext, argc, argv, title, size) {} }; }}