Browse Source

Platform: hide those ugly *ContextHandlers into Implementation namespace.

They are now not exposed to the user at all, as their API will be
probably changed and reworked in the future to allow GLX/EGL-specific
extension to be used. Also this looks scary in the documentation.
pull/34/head
Vladimír Vondruš 13 years ago
parent
commit
4fcd57fb31
  1. 11
      src/Platform/AbstractXApplication.cpp
  2. 51
      src/Platform/AbstractXApplication.h
  3. 12
      src/Platform/CMakeLists.txt
  4. 35
      src/Platform/GlxApplication.cpp
  5. 7
      src/Platform/GlxApplication.h
  6. 12
      src/Platform/Implementation/AbstractContextHandler.h
  7. 4
      src/Platform/Implementation/EglContextHandler.cpp
  8. 12
      src/Platform/Implementation/EglContextHandler.h
  9. 4
      src/Platform/Implementation/GlxContextHandler.cpp
  10. 12
      src/Platform/Implementation/GlxContextHandler.h
  11. 35
      src/Platform/XEglApplication.cpp
  12. 7
      src/Platform/XEglApplication.h

11
src/Platform/AbstractXApplication.cpp

@ -27,6 +27,7 @@
#include <Utility/utilities.h>
#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<Display*, VisualID, Window>* contextHandler, const Arguments&, const Configuration& configuration): contextHandler(contextHandler), c(nullptr), flags(Flag::Redraw) {
AbstractXApplication::AbstractXApplication(Implementation::AbstractContextHandler<Display*, VisualID, Window>* contextHandler, const Arguments&, const Configuration& configuration): contextHandler(contextHandler), c(nullptr), flags(Flag::Redraw) {
createContext(configuration);
}
#ifndef DOXYGEN_GENERATING_OUTPUT
AbstractXApplication::AbstractXApplication(AbstractContextHandler<Display*, VisualID, Window>* contextHandler, const Arguments&): contextHandler(contextHandler), c(nullptr), flags(Flag::Redraw) {
AbstractXApplication::AbstractXApplication(Implementation::AbstractContextHandler<Display*, VisualID, Window>* contextHandler, const Arguments&): contextHandler(contextHandler), c(nullptr), flags(Flag::Redraw) {
createContext({});
}
#endif
AbstractXApplication::AbstractXApplication(AbstractContextHandler<Display*, VisualID, Window>* contextHandler, const Arguments&, std::nullptr_t): contextHandler(contextHandler), c(nullptr), flags(Flag::Redraw) {}
AbstractXApplication::AbstractXApplication(Implementation::AbstractContextHandler<Display*, VisualID, Window>* 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);

51
src/Platform/AbstractXApplication.h

@ -25,7 +25,7 @@
*/
/** @file
* @brief Class Magnum::Platform::AbstractXApplication
* @brief Class @ref Magnum::Platform::AbstractXApplication
*/
#include <Containers/EnumSet.h>
@ -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, class, class> 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<Display*, VisualID, Window>* contextHandler, const Arguments& arguments, const Configuration& configuration = Configuration());
#else
/* To avoid "invalid use of incomplete type" */
explicit AbstractXApplication(AbstractContextHandler<Display*, VisualID, Window>* contextHandler, const Arguments& arguments, const Configuration& configuration);
explicit AbstractXApplication(AbstractContextHandler<Display*, VisualID, Window>* 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<Display*, VisualID, Window>* 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<Display*, VisualID, Window>* contextHandler, const Arguments& arguments, const Configuration& configuration);
explicit AbstractXApplication(Implementation::AbstractContextHandler<Display*, VisualID, Window>* contextHandler, const Arguments& arguments);
explicit AbstractXApplication(Implementation::AbstractContextHandler<Display*, VisualID, Window>* 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<Display*, VisualID, Window>* contextHandler;
Implementation::AbstractContextHandler<Display*, VisualID, Window>* contextHandler;
Context* c;

12
src/Platform/CMakeLists.txt

@ -100,7 +100,8 @@ if(WITH_GLXAPPLICATION)
set(NEED_GLXCONTEXT 1)
add_library(MagnumGlxApplication STATIC
$<TARGET_OBJECTS:MagnumAbstractXApplication>
$<TARGET_OBJECTS:MagnumGlxContextHandler>)
$<TARGET_OBJECTS:MagnumGlxContextHandler>
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
$<TARGET_OBJECTS:MagnumAbstractXApplication>
$<TARGET_OBJECTS:MagnumEglContextHandler>)
$<TARGET_OBJECTS:MagnumEglContextHandler>
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

35
src/Platform/GlxApplication.cpp

@ -0,0 +1,35 @@
/*
This file is part of Magnum.
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz>
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) {}
}}

7
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

12
src/Platform/AbstractContextHandler.h → 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 Display, class VisualId, class Window> class AbstractContextHandl
virtual void swapBuffers() = 0;
};
}}
}}}
#endif

4
src/Platform/EglContextHandler.cpp → 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 {};
}
}}
}}}

12
src/Platform/EglContextHandler.h → 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<EGLNativeDisplayType, Vis
EGLContext context;
};
}}
}}}
#endif

4
src/Platform/GlxContextHandler.cpp → src/Platform/Implementation/GlxContextHandler.cpp

@ -31,7 +31,7 @@
#define None 0L // redef Xlib nonsense
namespace Magnum { namespace Platform {
namespace Magnum { namespace Platform { namespace Implementation {
VisualID GlxContextHandler::getVisualId(Display* nativeDisplay) {
display = nativeDisplay;
@ -97,4 +97,4 @@ GlxContextHandler::~GlxContextHandler() {
glXDestroyContext(display, context);
}
}}
}}}

12
src/Platform/GlxContextHandler.h → src/Platform/Implementation/GlxContextHandler.h

@ -1,5 +1,5 @@
#ifndef Magnum_Platform_GlxContextHandler_h
#define Magnum_Platform_GlxContextHandler_h
#ifndef Magnum_Platform_Implementation_GlxContextHandler_h
#define Magnum_Platform_Implementation_GlxContextHandler_h
/*
This file is part of Magnum.
@ -24,10 +24,6 @@
DEALINGS IN THE SOFTWARE.
*/
/** @file
* @brief Class Magnum::Platform::GlxContextHandler
*/
#include "OpenGL.h"
#include <GL/glx.h>
/* 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<Display*, VisualID, Windo
GLXContext context;
};
}}
}}}
#endif

35
src/Platform/XEglApplication.cpp

@ -0,0 +1,35 @@
/*
This file is part of Magnum.
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz>
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) {}
}}

7
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

Loading…
Cancel
Save