diff --git a/src/Platform/AbstractXApplication.cpp b/src/Platform/AbstractXApplication.cpp index 591b72dfe..0b4e99f31 100644 --- a/src/Platform/AbstractXApplication.cpp +++ b/src/Platform/AbstractXApplication.cpp @@ -27,6 +27,7 @@ #include #include "Context.h" +#include "Platform/Implementation/AbstractContextHandler.h" #define None 0L // redef Xlib nonsense @@ -37,17 +38,17 @@ namespace Magnum { namespace Platform { /** @todo Delegating constructor when support for GCC 4.6 is dropped */ -AbstractXApplication::AbstractXApplication(AbstractContextHandler* contextHandler, const Arguments&, const Configuration& configuration): contextHandler(contextHandler), c(nullptr), flags(Flag::Redraw) { +AbstractXApplication::AbstractXApplication(Implementation::AbstractContextHandler* contextHandler, const Arguments&, const Configuration& configuration): contextHandler(contextHandler), c(nullptr), flags(Flag::Redraw) { createContext(configuration); } #ifndef DOXYGEN_GENERATING_OUTPUT -AbstractXApplication::AbstractXApplication(AbstractContextHandler* contextHandler, const Arguments&): contextHandler(contextHandler), c(nullptr), flags(Flag::Redraw) { +AbstractXApplication::AbstractXApplication(Implementation::AbstractContextHandler* contextHandler, const Arguments&): contextHandler(contextHandler), c(nullptr), flags(Flag::Redraw) { createContext({}); } #endif -AbstractXApplication::AbstractXApplication(AbstractContextHandler* contextHandler, const Arguments&, std::nullptr_t): contextHandler(contextHandler), c(nullptr), flags(Flag::Redraw) {} +AbstractXApplication::AbstractXApplication(Implementation::AbstractContextHandler* contextHandler, const Arguments&, std::nullptr_t): contextHandler(contextHandler), c(nullptr), flags(Flag::Redraw) {} void AbstractXApplication::createContext(const Configuration& configuration) { CORRADE_ASSERT(!c, "AbstractXApplication::createContext(): context already created", ); @@ -109,6 +110,10 @@ AbstractXApplication::~AbstractXApplication() { XCloseDisplay(display); } +void AbstractXApplication::swapBuffers() { + contextHandler->swapBuffers(); +} + int AbstractXApplication::exec() { /* Show window */ XMapWindow(display, window); diff --git a/src/Platform/AbstractXApplication.h b/src/Platform/AbstractXApplication.h index 514a9f627..807c0fd77 100644 --- a/src/Platform/AbstractXApplication.h +++ b/src/Platform/AbstractXApplication.h @@ -25,7 +25,7 @@ */ /** @file - * @brief Class Magnum::Platform::AbstractXApplication + * @brief Class @ref Magnum::Platform::AbstractXApplication */ #include @@ -40,7 +40,6 @@ #undef Always #include "Math/Vector2.h" -#include "AbstractContextHandler.h" namespace Magnum { @@ -48,6 +47,10 @@ class Context; namespace Platform { +namespace Implementation { + template class AbstractContextHandler; +} + /** @nosubgrouping @brief Base for X11-based applications @@ -68,34 +71,6 @@ class AbstractXApplication { class MouseEvent; class MouseMoveEvent; - /** - * @brief Default constructor - * @param contextHandler OpenGL context handler - * @param arguments Application arguments - * @param configuration %Configuration - * - * Creates application with default or user-specified configuration. - * See Configuration for more information. The program exits if the - * context cannot be created, see below for an alternative. - */ - #ifdef DOXYGEN_GENERATING_OUTPUT - explicit AbstractXApplication(AbstractContextHandler* contextHandler, const Arguments& arguments, const Configuration& configuration = Configuration()); - #else - /* To avoid "invalid use of incomplete type" */ - explicit AbstractXApplication(AbstractContextHandler* contextHandler, const Arguments& arguments, const Configuration& configuration); - explicit AbstractXApplication(AbstractContextHandler* contextHandler, const Arguments& arguments); - #endif - - /** - * @brief Constructor - * @param contextHandler OpenGL context handler - * @param arguments Application arguments - * - * Unlike above, the context is not created and must be created later - * with createContext() or tryCreateContext(). - */ - explicit AbstractXApplication(AbstractContextHandler* contextHandler, const Arguments& arguments, std::nullptr_t); - /** * @brief Execute main loop * @return Value for returning from `main()`. @@ -127,7 +102,7 @@ class AbstractXApplication { virtual void drawEvent() = 0; /** @copydoc GlutApplication::swapBuffers() */ - void swapBuffers() { contextHandler->swapBuffers(); } + void swapBuffers(); /** @copydoc GlutApplication::redraw() */ void redraw() { flags |= Flag::Redraw; } @@ -157,6 +132,18 @@ class AbstractXApplication { /*@}*/ + #ifdef DOXYGEN_GENERATING_OUTPUT + private: + #else + protected: + #endif + /* These two are split to avoid "invalid use of incomplete type" when + using default argument for configuration */ + explicit AbstractXApplication(Implementation::AbstractContextHandler* contextHandler, const Arguments& arguments, const Configuration& configuration); + explicit AbstractXApplication(Implementation::AbstractContextHandler* contextHandler, const Arguments& arguments); + + explicit AbstractXApplication(Implementation::AbstractContextHandler* contextHandler, const Arguments& arguments, std::nullptr_t); + private: enum class Flag: unsigned int { Redraw = 1 << 0, @@ -170,7 +157,7 @@ class AbstractXApplication { Window window; Atom deleteWindow; - AbstractContextHandler* contextHandler; + Implementation::AbstractContextHandler* contextHandler; Context* c; diff --git a/src/Platform/CMakeLists.txt b/src/Platform/CMakeLists.txt index f9303e2ef..fd5a95731 100644 --- a/src/Platform/CMakeLists.txt +++ b/src/Platform/CMakeLists.txt @@ -100,7 +100,8 @@ if(WITH_GLXAPPLICATION) set(NEED_GLXCONTEXT 1) add_library(MagnumGlxApplication STATIC $ - $) + $ + GlxApplication.cpp) install(FILES GlxApplication.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform) install(TARGETS MagnumGlxApplication RUNTIME DESTINATION ${MAGNUM_BINARY_INSTALL_DIR} @@ -114,7 +115,8 @@ if(WITH_XEGLAPPLICATION) set(NEED_EGLCONTEXT 1) add_library(MagnumXEglApplication STATIC $ - $) + $ + XEglApplication.cpp) install(FILES XEglApplication.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform) install(TARGETS MagnumXEglApplication RUNTIME DESTINATION ${MAGNUM_BINARY_INSTALL_DIR} @@ -151,10 +153,9 @@ endif() # GLX context if(NEED_GLXCONTEXT) - add_library(MagnumGlxContextHandler OBJECT GlxContextHandler.cpp) + add_library(MagnumGlxContextHandler OBJECT Implementation/GlxContextHandler.cpp) # X11 macros are a mess, disable warnings for C-style casts set_target_properties(MagnumGlxContextHandler PROPERTIES COMPILE_FLAGS "-Wno-old-style-cast") - install(FILES GlxContextHandler.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform) endif() # EGL context @@ -163,10 +164,9 @@ if(NEED_EGLCONTEXT) if(NOT EGL_FOUND) message(FATAL_ERROR "EGL library, required by some window contexts, was not found. Set WITH_*EGL*APPLICATION to OFF to skip building them.") endif() - add_library(MagnumEglContextHandler OBJECT EglContextHandler.cpp) + add_library(MagnumEglContextHandler OBJECT Implementation/EglContextHandler.cpp) # X11 macros are a mess, disable warnings for C-style casts set_target_properties(MagnumEglContextHandler PROPERTIES COMPILE_FLAGS "-Wno-old-style-cast") - install(FILES EglContextHandler.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform) endif() # Magnum Info diff --git a/src/Platform/GlxApplication.cpp b/src/Platform/GlxApplication.cpp new file mode 100644 index 000000000..848ba0af0 --- /dev/null +++ b/src/Platform/GlxApplication.cpp @@ -0,0 +1,35 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +#include "GlxApplication.h" + +#include "Platform/Implementation/GlxContextHandler.h" + +namespace Magnum { namespace Platform { + +GlxApplication::GlxApplication(const Arguments& arguments, const Configuration& configuration): AbstractXApplication(new Implementation::GlxContextHandler, arguments, configuration) {} + +GlxApplication::GlxApplication(const Arguments& arguments, std::nullptr_t): AbstractXApplication(new Implementation::GlxContextHandler, arguments, nullptr) {} + +}} diff --git a/src/Platform/GlxApplication.h b/src/Platform/GlxApplication.h index b3aeb562a..91533277b 100644 --- a/src/Platform/GlxApplication.h +++ b/src/Platform/GlxApplication.h @@ -28,8 +28,7 @@ * @brief Class Magnum::Platform::GlxApplication */ -#include "AbstractXApplication.h" -#include "GlxContextHandler.h" +#include "Platform/AbstractXApplication.h" namespace Magnum { namespace Platform { @@ -57,10 +56,10 @@ to simplify porting. class GlxApplication: public AbstractXApplication { public: /** @copydoc GlutApplication::GlutApplication(const Arguments&, const Configuration&) */ - explicit GlxApplication(const Arguments& arguments, const Configuration& configuration = Configuration()): AbstractXApplication(new GlxContextHandler, arguments, configuration) {} + explicit GlxApplication(const Arguments& arguments, const Configuration& configuration = Configuration()); /** @copydoc GlutApplication::GlutApplication(const Arguments&, std::nullptr_t) */ - explicit GlxApplication(const Arguments& arguments, std::nullptr_t): AbstractXApplication(new GlxContextHandler, arguments, nullptr) {} + explicit GlxApplication(const Arguments& arguments, std::nullptr_t); protected: /* Nobody will need to have (and delete) GlxApplication*, thus this is diff --git a/src/Platform/AbstractContextHandler.h b/src/Platform/Implementation/AbstractContextHandler.h similarity index 90% rename from src/Platform/AbstractContextHandler.h rename to src/Platform/Implementation/AbstractContextHandler.h index 1da12affa..01a7eeb7a 100644 --- a/src/Platform/AbstractContextHandler.h +++ b/src/Platform/Implementation/AbstractContextHandler.h @@ -1,5 +1,5 @@ -#ifndef Magnum_Platform_AbstractContextHandler_h -#define Magnum_Platform_AbstractContextHandler_h +#ifndef Magnum_Platform_Implementation_AbstractContextHandler_h +#define Magnum_Platform_Implementation_AbstractContextHandler_h /* This file is part of Magnum. @@ -24,11 +24,7 @@ DEALINGS IN THE SOFTWARE. */ -/** @file - * @brief Class Magnum::Platform::AbstractContextHandler - */ - -namespace Magnum { namespace Platform { +namespace Magnum { namespace Platform { namespace Implementation { /** @brief Base for OpenGL context handlers @@ -63,6 +59,6 @@ template class AbstractContextHandl virtual void swapBuffers() = 0; }; -}} +}}} #endif diff --git a/src/Platform/EglContextHandler.cpp b/src/Platform/Implementation/EglContextHandler.cpp similarity index 98% rename from src/Platform/EglContextHandler.cpp rename to src/Platform/Implementation/EglContextHandler.cpp index 56dd92cd1..ed7d523a0 100644 --- a/src/Platform/EglContextHandler.cpp +++ b/src/Platform/Implementation/EglContextHandler.cpp @@ -28,7 +28,7 @@ #include "Context.h" -namespace Magnum { namespace Platform { +namespace Magnum { namespace Platform { namespace Implementation { EglContextHandler::~EglContextHandler() { eglDestroyContext(display, context); @@ -131,4 +131,4 @@ const char* EglContextHandler::errorString(EGLint error) { return {}; } -}} +}}} diff --git a/src/Platform/EglContextHandler.h b/src/Platform/Implementation/EglContextHandler.h similarity index 92% rename from src/Platform/EglContextHandler.h rename to src/Platform/Implementation/EglContextHandler.h index 6c1869b7c..32cc2da94 100644 --- a/src/Platform/EglContextHandler.h +++ b/src/Platform/Implementation/EglContextHandler.h @@ -1,5 +1,5 @@ -#ifndef Magnum_Platform_EglContextHandler_h -#define Magnum_Platform_EglContextHandler_h +#ifndef Magnum_Platform_Implementation_EglContextHandler_h +#define Magnum_Platform_Implementation_EglContextHandler_h /* This file is part of Magnum. @@ -24,10 +24,6 @@ DEALINGS IN THE SOFTWARE. */ -/** @file - * @brief Class Magnum::Platform::EglContextHandler - */ - #include "Magnum.h" #ifndef SUPPORT_X11 @@ -42,7 +38,7 @@ #include "corradeCompatibility.h" -namespace Magnum { namespace Platform { +namespace Magnum { namespace Platform { namespace Implementation { #ifndef DOXYGEN_GENERATING_OUTPUT /* EGL returns visual ID as int, but Xorg expects long unsigned int */ @@ -83,6 +79,6 @@ class EglContextHandler: public AbstractContextHandler /* undef Xlib nonsense to avoid conflicts */ @@ -39,7 +35,7 @@ #include "corradeCompatibility.h" -namespace Magnum { namespace Platform { +namespace Magnum { namespace Platform { namespace Implementation { /** @brief GLX context @@ -68,6 +64,6 @@ class GlxContextHandler: public AbstractContextHandler + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +#include "XEglApplication.h" + +#include "Platform/Implementation/EglContextHandler.h" + +namespace Magnum { namespace Platform { + +XEglApplication::XEglApplication(const Arguments& arguments, const Configuration& configuration): AbstractXApplication(new Implementation::EglContextHandler, arguments, configuration) {} + +XEglApplication::XEglApplication(const Arguments& arguments, std::nullptr_t): AbstractXApplication(new Implementation::EglContextHandler, arguments, nullptr) {} + +}} diff --git a/src/Platform/XEglApplication.h b/src/Platform/XEglApplication.h index 1b99b87f1..4f0182757 100644 --- a/src/Platform/XEglApplication.h +++ b/src/Platform/XEglApplication.h @@ -28,8 +28,7 @@ * @brief Class Magnum::Platform::XEglApplication */ -#include "AbstractXApplication.h" -#include "EglContextHandler.h" +#include "Platform/AbstractXApplication.h" namespace Magnum { namespace Platform { @@ -57,10 +56,10 @@ to simplify porting. class XEglApplication: public AbstractXApplication { public: /** @copydoc GlutApplication::GlutApplication(const Arguments&, const Configuration&) */ - explicit XEglApplication(const Arguments& arguments, const Configuration& configuration = Configuration()): AbstractXApplication(new EglContextHandler, arguments, configuration) {} + explicit XEglApplication(const Arguments& arguments, const Configuration& configuration = Configuration()); /** @copydoc GlutApplication::GlutApplication(const Arguments&, std::nullptr_t) */ - explicit XEglApplication(const Arguments& arguments, std::nullptr_t): AbstractXApplication(new EglContextHandler, nullptr) {} + explicit XEglApplication(const Arguments& arguments, std::nullptr_t); protected: /* Nobody will need to have (and delete) XEglApplication*, thus this is