Browse Source

Platform: portable application arguments specification.

Last PITA when porting to NaCl removed. Yay!
pull/278/head
Vladimír Vondruš 13 years ago
parent
commit
dfdec44b01
  1. 8
      doc/platform.dox
  2. 2
      doc/portability.dox
  3. 4
      src/Platform/AbstractXApplication.cpp
  4. 13
      src/Platform/AbstractXApplication.h
  5. 8
      src/Platform/GlutApplication.cpp
  6. 17
      src/Platform/GlutApplication.h
  7. 12
      src/Platform/GlxApplication.h
  8. 4
      src/Platform/NaClApplication.cpp
  9. 11
      src/Platform/NaClApplication.h
  10. 4
      src/Platform/Sdl2Application.cpp
  11. 15
      src/Platform/Sdl2Application.h
  12. 4
      src/Platform/WindowlessGlxApplication.cpp
  13. 16
      src/Platform/WindowlessGlxApplication.h
  14. 12
      src/Platform/XEglApplication.h
  15. 4
      src/Platform/magnum-info.cpp

8
doc/platform.dox

@ -58,13 +58,13 @@ using namespace Magnum;
class MyApplication: public Platform::GlutApplication {
public:
MyApplication(int& argc, char** argv);
MyApplication(const Arguments& arguments);
void viewportEvent(const Vector2i& viewport) override;
void drawEvent() override;
};
MyApplication::MyApplication(int& argc, char** argv): Platform::GlutApplication(argc, argv) {
MyApplication::MyApplication(const Arguments& arguments): Platform::GlutApplication(arguments) {
// Set clear color to dark blue
Renderer::setClearColor({0.0f, 0.0f, 0.4f});
}
@ -104,12 +104,12 @@ using namespace Magnum;
class MyApplication: public Platform::WindowlessGlxApplication {
public:
MyApplication(int& argc, char** argv);
MyApplication(const Arguments& arguments);
int exec() override;
};
MyApplication::MyApplication(int& argc, char** argv): Platform::WindowlessGlxApplication(argc, argv) {}
MyApplication::MyApplication(const Arguments& arguments): Platform::WindowlessGlxApplication(arguments) {}
int MyApplication::exec() {
Debug() << "OpenGL version:" << Context::current()->versionString();

2
doc/portability.dox

@ -185,7 +185,7 @@ particular *Event class implementations:
class MyApplication: public Platform::Application {
public:
MyApplication(int& argc, char** argv): Platform::Application(argc, argv, "My Application");
MyApplication(const Arguments& arguments);
protected:
void viewportEvent(const Vector2i& size) override;

4
src/Platform/AbstractXApplication.cpp

@ -36,11 +36,11 @@
namespace Magnum { namespace Platform {
AbstractXApplication::AbstractXApplication(AbstractContextHandler<Display*, VisualID, Window>* contextHandler, int&, char**): contextHandler(contextHandler), c(nullptr), flags(Flag::Redraw) {
AbstractXApplication::AbstractXApplication(AbstractContextHandler<Display*, VisualID, Window>* contextHandler, const Arguments&): contextHandler(contextHandler), c(nullptr), flags(Flag::Redraw) {
createContext(new Configuration);
}
AbstractXApplication::AbstractXApplication(AbstractContextHandler<Display*, VisualID, Window>* contextHandler, int&, char**, Configuration* configuration): contextHandler(contextHandler), c(nullptr), flags(Flag::Redraw) {
AbstractXApplication::AbstractXApplication(AbstractContextHandler<Display*, VisualID, Window>* contextHandler, const Arguments&, Configuration* configuration): contextHandler(contextHandler), c(nullptr), flags(Flag::Redraw) {
if(configuration) createContext(configuration);
}

13
src/Platform/AbstractXApplication.h

@ -55,6 +55,9 @@ Supports keyboard and mouse handling. See @ref platform for brief introduction.
*/
class AbstractXApplication {
public:
/** @brief Application arguments */
typedef std::pair<int&, char**> Arguments;
class Configuration;
class InputEvent;
class KeyEvent;
@ -64,26 +67,24 @@ class AbstractXApplication {
/**
* @brief Default constructor
* @param contextHandler OpenGL context handler
* @param argc Count of arguments of `main()` function
* @param argv Arguments of `main()` function
* @param arguments Application arguments
*
* Creates application with default configuration. See Configuration
* for more information.
*/
explicit AbstractXApplication(AbstractContextHandler<Display*, VisualID, Window>* contextHandler, int& argc, char** argv);
explicit AbstractXApplication(AbstractContextHandler<Display*, VisualID, Window>* contextHandler, const Arguments& arguments);
/**
* @brief Constructor
* @param contextHandler OpenGL context handler
* @param argc Count of arguments of `main()` function
* @param argv Arguments of `main()` function
* @param arguments Application arguments
* @param configuration Configuration
*
* The @p configuration is deleted afterwards. If `nullptr` is passed
* as @p configuration, the context is not created and must be created
* with createContext().
*/
explicit AbstractXApplication(AbstractContextHandler<Display*, VisualID, Window>* contextHandler, int& argc, char** argv, Configuration* configuration);
explicit AbstractXApplication(AbstractContextHandler<Display*, VisualID, Window>* contextHandler, const Arguments& arguments, Configuration* configuration);
/**
* @brief Destructor

8
src/Platform/GlutApplication.cpp

@ -31,13 +31,13 @@ namespace Magnum { namespace Platform {
GlutApplication* GlutApplication::instance = nullptr;
GlutApplication::GlutApplication(int& argc, char** argv): c(nullptr) {
initialize(argc, argv);
GlutApplication::GlutApplication(const Arguments& arguments): c(nullptr) {
initialize(arguments.first, arguments.second);
createContext(new Configuration);
}
GlutApplication::GlutApplication(int& argc, char** argv, Configuration* configuration): c(nullptr) {
initialize(argc, argv);
GlutApplication::GlutApplication(const Arguments& arguments, Configuration* configuration): c(nullptr) {
initialize(arguments.first, arguments.second);
if(configuration) createContext(configuration);
}

17
src/Platform/GlutApplication.h

@ -67,6 +67,9 @@ to simplify porting.
*/
class GlutApplication {
public:
/** @brief Application arguments */
typedef std::pair<int&, char**> Arguments;
class Configuration;
class InputEvent;
class KeyEvent;
@ -75,25 +78,23 @@ class GlutApplication {
/**
* @brief Default constructor
* @param argc Count of arguments of `main()` function
* @param argv Arguments of `main()` function
* @param arguments Application arguments
*
* Creates application with default configuration. See Configuration
* for more information.
*/
explicit GlutApplication(int& argc, char** argv);
explicit GlutApplication(const Arguments& arguments);
/**
* @brief Constructor
* @param argc Count of arguments of `main()` function
* @param argv Arguments of `main()` function
* @param arguments Application arguments
* @param configuration Configuration
*
* The @p configuration is deleted afterwards. If `nullptr` is passed
* as @p configuration, the context is not created and must be created
* with createContext().
*/
explicit GlutApplication(int& argc, char** argv, Configuration* configuration);
explicit GlutApplication(const Arguments& arguments, Configuration* configuration);
virtual ~GlutApplication();
@ -465,7 +466,7 @@ code to achieve better portability, see @ref portability-applications for more
information.
@code
int main(int argc, char** argv) {
className app(argc, argv);
className app({argc, argv});
return app.exec();
}
@endcode
@ -474,7 +475,7 @@ When no other application header is included this macro is also aliased to
*/
#define MAGNUM_GLUTAPPLICATION_MAIN(className) \
int main(int argc, char** argv) { \
className app(argc, argv); \
className app({argc, argv}); \
return app.exec(); \
}

12
src/Platform/GlxApplication.h

@ -56,11 +56,11 @@ to simplify porting.
*/
class GlxApplication: public AbstractXApplication {
public:
/** @copydoc GlutApplication::GlutApplication(int&, char**) */
inline explicit GlxApplication(int& argc, char** argv): AbstractXApplication(new GlxContextHandler, argc, argv) {}
/** @copydoc GlutApplication::GlutApplication(const Arguments&) */
inline explicit GlxApplication(const Arguments& arguments): AbstractXApplication(new GlxContextHandler, arguments) {}
/** @copydoc GlutApplication::GlutApplication(int&, char**, Configuration*) */
inline explicit GlxApplication(int& argc, char** argv, Configuration* configuration): AbstractXApplication(new GlxContextHandler, argc, argv, configuration) {}
/** @copydoc GlutApplication::GlutApplication(const Arguments&, Configuration*) */
inline explicit GlxApplication(const Arguments& arguments, Configuration* configuration): AbstractXApplication(new GlxContextHandler, arguments, configuration) {}
};
/** @hideinitializer
@ -72,7 +72,7 @@ to achieve better portability, see @ref portability-applications for more
information.
@code
int main(int argc, char** argv) {
className app(argc, argv);
className app({argc, argv});
return app.exec();
}
@endcode
@ -81,7 +81,7 @@ When no other application header is included this macro is also aliased to
*/
#define MAGNUM_GLXAPPLICATION_MAIN(className) \
int main(int argc, char** argv) { \
className app(argc, argv); \
className app({argc, argv}); \
return app.exec(); \
}

4
src/Platform/NaClApplication.cpp

@ -32,11 +32,11 @@
namespace Magnum { namespace Platform {
NaClApplication::NaClApplication(PP_Instance instance): Instance(instance), Graphics3DClient(this), MouseLock(this), c(nullptr) {
NaClApplication::NaClApplication(const Arguments& arguments): Instance(arguments), Graphics3DClient(this), MouseLock(this), c(nullptr) {
createContext(new Configuration);
}
NaClApplication::NaClApplication(PP_Instance instance, Configuration* configuration): Instance(instance), Graphics3DClient(this), MouseLock(this), c(nullptr) {
NaClApplication::NaClApplication(const Arguments& arguments, Configuration* configuration): Instance(arguments), Graphics3DClient(this), MouseLock(this), c(nullptr) {
if(configuration) createContext(configuration);
}

11
src/Platform/NaClApplication.h

@ -73,6 +73,9 @@ to simplify porting.
*/
class NaClApplication: public pp::Instance, public pp::Graphics3DClient, public pp::MouseLock {
public:
/** @brief Application arguments */
typedef PP_Instance Arguments;
class Configuration;
class InputEvent;
class KeyEvent;
@ -81,23 +84,23 @@ class NaClApplication: public pp::Instance, public pp::Graphics3DClient, public
/**
* @brief Default constructor
* @param instance Module instance
* @param arguments Application arguments
*
* Creates application with default configuration. See Configuration
* for more information.
*/
explicit NaClApplication(PP_Instance instance);
explicit NaClApplication(const Arguments& arguments);
/**
* @brief Constructor
* @param instance Module instance
* @param arguments Application arguments
* @param configuration Configuration
*
* The @p configuration is deleted afterwards. If `nullptr` is passed
* as @p configuration, the context is not created and must be created
* with createContext().
*/
explicit NaClApplication(PP_Instance instance, Configuration* configuration);
explicit NaClApplication(const Arguments& arguments, Configuration* configuration);
~NaClApplication();

4
src/Platform/Sdl2Application.cpp

@ -49,11 +49,11 @@ Sdl2Application::InputEvent::Modifiers fixedModifiers(Uint16 mod) {
}
Sdl2Application::Sdl2Application(int&, char**): context(nullptr), flags(Flag::Redraw) {
Sdl2Application::Sdl2Application(const Arguments&): context(nullptr), flags(Flag::Redraw) {
createContext(new Configuration);
}
Sdl2Application::Sdl2Application(int&, char**, Configuration* configuration): context(nullptr), flags(Flag::Redraw) {
Sdl2Application::Sdl2Application(const Arguments&, Configuration* configuration): context(nullptr), flags(Flag::Redraw) {
if(configuration) createContext(configuration);
}

15
src/Platform/Sdl2Application.h

@ -68,17 +68,20 @@ to simplify porting.
*/
class Sdl2Application {
public:
/** @brief Application arguments */
typedef std::pair<int&, char**> Arguments;
class Configuration;
class InputEvent;
class KeyEvent;
class MouseEvent;
class MouseMoveEvent;
/** @copydoc GlutApplication::GlutApplication(int&, char**) */
explicit Sdl2Application(int& argc, char** argv);
/** @copydoc GlutApplication::GlutApplication(const Arguments&) */
explicit Sdl2Application(const Arguments& arguments);
/** @copydoc GlutApplication::GlutApplication(int&, char**, Configuration*) */
explicit Sdl2Application(int& argc, char** argv, Configuration* configuration);
/** @copydoc GlutApplication::GlutApplication(const Arguments&, Configuration*) */
explicit Sdl2Application(const Arguments& arguments, Configuration* configuration);
virtual ~Sdl2Application();
@ -481,7 +484,7 @@ code to achieve better portability, see @ref portability-applications for more
information.
@code
int main(int argc, char** argv) {
className app(argc, argv);
className app({argc, argv});
return app.exec();
}
@endcode
@ -490,7 +493,7 @@ When no other application header is included this macro is also aliased to
*/
#define MAGNUM_SDL2APPLICATION_MAIN(className) \
int main(int argc, char** argv) { \
className app(argc, argv); \
className app({argc, argv}); \
return app.exec(); \
}

4
src/Platform/WindowlessGlxApplication.cpp

@ -33,11 +33,11 @@
namespace Magnum { namespace Platform {
WindowlessGlxApplication::WindowlessGlxApplication(int&, char**) {
WindowlessGlxApplication::WindowlessGlxApplication(const Arguments&) {
createContext(new Configuration);
}
WindowlessGlxApplication::WindowlessGlxApplication(int&, char**, Configuration* configuration) {
WindowlessGlxApplication::WindowlessGlxApplication(const Arguments&, Configuration* configuration) {
if(configuration) createContext(configuration);
}

16
src/Platform/WindowlessGlxApplication.h

@ -28,6 +28,7 @@
* @brief Class Magnum::Platform::WindowlessGlxApplication
*/
#include <utility>
#include "OpenGL.h"
#include <GL/glx.h>
#include <X11/Xlib.h>
@ -64,13 +65,16 @@ If no other application header is included this class is also aliased to
*/
class WindowlessGlxApplication {
public:
/** @brief Application arguments */
typedef std::pair<int&, char**> Arguments;
class Configuration;
/** @copydoc GlutApplication::GlutApplication(int&, char**) */
explicit WindowlessGlxApplication(int& argc, char** argv);
/** @copydoc GlutApplication::GlutApplication(const Arguments&) */
explicit WindowlessGlxApplication(const Arguments& arguments);
/** @copydoc GlutApplication::GlutApplication(int&, char**, Configuration*) */
explicit WindowlessGlxApplication(int& argc, char** argv, Configuration* configuration);
/** @copydoc GlutApplication::GlutApplication(const Arguments&, Configuration*) */
explicit WindowlessGlxApplication(const Arguments& arguments, Configuration* configuration);
~WindowlessGlxApplication();
@ -116,7 +120,7 @@ Can be used as equivalent to the following code to achieve better portability,
see @ref portability-applications for more information.
@code
int main(int argc, char** argv) {
className app(argc, argv);
className app({argc, argv});
return app.exec();
}
@endcode
@ -125,7 +129,7 @@ aliased to `MAGNUM_WINDOWLESSAPPLICATION_MAIN()`.
*/
#define MAGNUM_WINDOWLESSGLXAPPLICATION_MAIN(className) \
int main(int argc, char** argv) { \
className app(argc, argv); \
className app({argc, argv}); \
return app.exec(); \
}

12
src/Platform/XEglApplication.h

@ -56,11 +56,11 @@ to simplify porting.
*/
class XEglApplication: public AbstractXApplication {
public:
/** @copydoc GlutApplication::GlutApplication(int&, char**) */
inline explicit XEglApplication(int& argc, char** argv): AbstractXApplication(new EglContextHandler, argc, argv) {}
/** @copydoc GlutApplication::GlutApplication(const Arguments&) */
inline explicit XEglApplication(const Arguments& arguments): AbstractXApplication(new EglContextHandler, arguments) {}
/** @copydoc GlutApplication::GlutApplication(int&, char**, Configuration*) */
inline explicit XEglApplication(int& argc, char** argv, Configuration* configuration): AbstractXApplication(new EglContextHandler, argc, argv, configuration) {}
/** @copydoc GlutApplication::GlutApplication(const Arguments&, Configuration*) */
inline explicit XEglApplication(const Arguments& arguments, Configuration* configuration): AbstractXApplication(new EglContextHandler, arguments, configuration) {}
};
/** @hideinitializer
@ -72,7 +72,7 @@ to achieve better portability, see @ref portability-applications for more
information.
@code
int main(int argc, char** argv) {
className app(argc, argv);
className app({argc, argv});
return app.exec();
}
@endcode
@ -81,7 +81,7 @@ When no other application header is included this macro is also aliased to
*/
#define MAGNUM_XEGLAPPLICATION_MAIN(className) \
int main(int argc, char** argv) { \
className app(argc, argv); \
className app({argc, argv}); \
return app.exec(); \
}

4
src/Platform/magnum-info.cpp

@ -32,12 +32,12 @@ namespace Magnum {
class MagnumInfo: public Platform::WindowlessGlxApplication {
public:
MagnumInfo(int& argc, char** argv);
explicit MagnumInfo(const Arguments& arguments);
inline int exec() override { return 0; }
};
MagnumInfo::MagnumInfo(int& argc, char** argv): WindowlessGlxApplication(argc, argv) {
MagnumInfo::MagnumInfo(const Arguments& arguments): WindowlessGlxApplication(arguments) {
Context* c = Context::current();
Debug() << "";

Loading…
Cancel
Save