From 883600e373854eef0a5c0ee8f2d1f0c52a0c3c8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 7 Jul 2013 11:14:20 +0200 Subject: [PATCH 1/2] Platform: make Configuration constructors explicit. As it now isn't passed by pointer, this allows doing things like this: /* Lost all hope in this hardware */ if(!awesomeFeatureSupported) createContext({}); --- src/Platform/AbstractXApplication.h | 2 +- src/Platform/GlutApplication.h | 2 +- src/Platform/NaClApplication.h | 2 +- src/Platform/Sdl2Application.h | 2 +- src/Platform/WindowlessGlxApplication.h | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Platform/AbstractXApplication.h b/src/Platform/AbstractXApplication.h index bf9b46a29..7d97d2758 100644 --- a/src/Platform/AbstractXApplication.h +++ b/src/Platform/AbstractXApplication.h @@ -196,7 +196,7 @@ class AbstractXApplication::Configuration { Configuration& operator=(Configuration&&) = delete; public: - explicit Configuration(); + /*implicit*/ Configuration(); ~Configuration(); /** @brief Window title */ diff --git a/src/Platform/GlutApplication.h b/src/Platform/GlutApplication.h index e037a849b..bc0ba31a2 100644 --- a/src/Platform/GlutApplication.h +++ b/src/Platform/GlutApplication.h @@ -282,7 +282,7 @@ class GlutApplication::Configuration { Configuration& operator=(Configuration&&) = delete; public: - explicit Configuration(); + /*implicit*/ Configuration(); ~Configuration(); /** @brief Window title */ diff --git a/src/Platform/NaClApplication.h b/src/Platform/NaClApplication.h index 367baad35..97edf3c44 100644 --- a/src/Platform/NaClApplication.h +++ b/src/Platform/NaClApplication.h @@ -308,7 +308,7 @@ class NaClApplication::Configuration { Configuration& operator=(Configuration&&) = delete; public: - constexpr explicit Configuration(): _size(640, 480), _sampleCount(0) {} + constexpr /*implicit*/ Configuration(): _size(640, 480), _sampleCount(0) {} /** @brief Window size */ Vector2i size() const { return _size; } diff --git a/src/Platform/Sdl2Application.h b/src/Platform/Sdl2Application.h index 1fd62c431..7d1f4732e 100644 --- a/src/Platform/Sdl2Application.h +++ b/src/Platform/Sdl2Application.h @@ -229,7 +229,7 @@ class Sdl2Application::Configuration { SDL_WINDOW_FULLSCREEN|SDL_WINDOW_HIDDEN|SDL_WINDOW_MAXIMIZED| SDL_WINDOW_MINIMIZED|SDL_WINDOW_INPUT_GRABBED> Flags; - explicit Configuration(); + /*implicit*/ Configuration(); ~Configuration(); /** @brief Window title */ diff --git a/src/Platform/WindowlessGlxApplication.h b/src/Platform/WindowlessGlxApplication.h index ed9831b83..3659b92e5 100644 --- a/src/Platform/WindowlessGlxApplication.h +++ b/src/Platform/WindowlessGlxApplication.h @@ -119,7 +119,7 @@ class WindowlessGlxApplication::Configuration { Configuration& operator=(Configuration&&) = delete; public: - explicit Configuration(); + /*implicit*/ Configuration(); ~Configuration(); }; From 231aaeb4aa7eae2f3c1826bc9535e05fc9dc39d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 7 Jul 2013 11:17:13 +0200 Subject: [PATCH 2/2] Platform: documentation updates. It looks much better now without all that explicit/implicit deletion. --- doc/platform.dox | 35 +++++++++++----------- src/Platform/AbstractXApplication.cpp | 2 ++ src/Platform/AbstractXApplication.h | 2 +- src/Platform/GlutApplication.cpp | 2 ++ src/Platform/NaClApplication.cpp | 2 ++ src/Platform/Sdl2Application.cpp | 2 ++ src/Platform/WindowlessGlxApplication.cpp | 2 ++ src/Platform/WindowlessNaClApplication.cpp | 2 ++ 8 files changed, 30 insertions(+), 19 deletions(-) diff --git a/doc/platform.dox b/doc/platform.dox index 365886087..ffecf7b8d 100644 --- a/doc/platform.dox +++ b/doc/platform.dox @@ -147,8 +147,10 @@ window size 800x600 pixels). If you want something else, you can pass constructor. Using method chaining it can be done conveniently like this: @code MyApplication::MyApplication(int& argc, char** argv): - Platform::GlutApplication(argc, argv, (new Configuration) - ->setTitle("My Application")->setSize({800, 600}) { + Platform::GlutApplication(argc, argv, Configuration() + .setTitle("My Application") + .setSize({800, 600}) + { // ... } @endcode @@ -161,33 +163,30 @@ instead of Configuration instance and then specify it later with MyApplication::MyApplication(int& argc, char** argv): Platform::GlutApplication(argc, argv, nullptr) { // ... - createContext((new Configuration) - ->setTitle("My Application") - ->setSize(size)); + createContext(Configuration() + .setTitle("My Application") + .setSize(size)); // ... } @endcode -The configuration passed to constructor and @ref GlutApplication::createContext() "createContext()" -is automaticall deleted afterwards and if the context creation fails, the -application exits. However, it is also possible to negotiate the context using -@ref GlutApplication::tryCreateContext() "tryCreateContext()". The major -difference is that this function returns `false` instead of exiting and it -doesn't delete the configuration afterwards so you can reuse it. You can for -example try enabling MSAA and if the context creation fails, fall back to -no-AA rendering: +If the context creation in constructor or @ref GlutApplication::createContext() "createContext()" +fails, the application exits. However, it is also possible to negotiate the +context using @ref GlutApplication::tryCreateContext() "tryCreateContext()". The +only difference is that this function returns `false` instead of exiting. You +can for example try enabling MSAA and if the context creation fails, fall back +to no-AA rendering: @code MyApplication::MyApplication(int& argc, char** argv): Platform::GlutApplication(argc, argv, nullptr) { // ... - auto conf = new Configuration; - conf->setTitle("My Application") - ->setSampleCount(16); + Configuration conf; + conf.setTitle("My Application") + .setSampleCount(16); if(!tryCreateContext(conf)) - createContext(conf->setSampleCount(0)); - else delete conf; + createContext(conf.setSampleCount(0)); // ... } diff --git a/src/Platform/AbstractXApplication.cpp b/src/Platform/AbstractXApplication.cpp index 8a7a1217a..51f94531a 100644 --- a/src/Platform/AbstractXApplication.cpp +++ b/src/Platform/AbstractXApplication.cpp @@ -42,9 +42,11 @@ AbstractXApplication::AbstractXApplication(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) {} diff --git a/src/Platform/AbstractXApplication.h b/src/Platform/AbstractXApplication.h index 7d97d2758..ae6d1b01a 100644 --- a/src/Platform/AbstractXApplication.h +++ b/src/Platform/AbstractXApplication.h @@ -72,6 +72,7 @@ class AbstractXApplication { * @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 @@ -89,7 +90,6 @@ class AbstractXApplication { * @brief Constructor * @param contextHandler OpenGL context handler * @param arguments Application arguments - * @param configuration Configuration * * Unlike above, the context is not created and must be created later * with createContext() or tryCreateContext(). diff --git a/src/Platform/GlutApplication.cpp b/src/Platform/GlutApplication.cpp index fb92c6c3e..422a2390b 100644 --- a/src/Platform/GlutApplication.cpp +++ b/src/Platform/GlutApplication.cpp @@ -38,10 +38,12 @@ GlutApplication::GlutApplication(const Arguments& arguments, const Configuration createContext(configuration); } +#ifndef DOXYGEN_GENERATING_OUTPUT GlutApplication::GlutApplication(const Arguments& arguments): c(nullptr) { initialize(arguments.argc, arguments.argv); createContext({}); } +#endif GlutApplication::GlutApplication(const Arguments& arguments, std::nullptr_t): c(nullptr) { initialize(arguments.argc, arguments.argv); diff --git a/src/Platform/NaClApplication.cpp b/src/Platform/NaClApplication.cpp index b4a5ba4c2..dbbdaf0a2 100644 --- a/src/Platform/NaClApplication.cpp +++ b/src/Platform/NaClApplication.cpp @@ -56,10 +56,12 @@ NaClApplication::NaClApplication(const Arguments& arguments, const Configuration createContext(configuration); } +#ifndef DOXYGEN_GENERATING_OUTPUT NaClApplication::NaClApplication(const Arguments& arguments): Instance(arguments), Graphics3DClient(this), MouseLock(this), c(nullptr) { debugOutput = new ConsoleDebugOutput(this); createContext({}); } +#endif NaClApplication::NaClApplication(const Arguments& arguments, std::nullptr_t): Instance(arguments), Graphics3DClient(this), MouseLock(this), c(nullptr) { debugOutput = new ConsoleDebugOutput(this); diff --git a/src/Platform/Sdl2Application.cpp b/src/Platform/Sdl2Application.cpp index 734f6312c..d73fdf5c7 100644 --- a/src/Platform/Sdl2Application.cpp +++ b/src/Platform/Sdl2Application.cpp @@ -54,10 +54,12 @@ Sdl2Application::Sdl2Application(const Arguments&, const Configuration& configur createContext(configuration); } +#ifndef DOXYGEN_GENERATING_OUTPUT Sdl2Application::Sdl2Application(const Arguments&): context(nullptr), flags(Flag::Redraw) { initialize(); createContext({}); } +#endif Sdl2Application::Sdl2Application(const Arguments&, std::nullptr_t): context(nullptr), flags(Flag::Redraw) { initialize(); diff --git a/src/Platform/WindowlessGlxApplication.cpp b/src/Platform/WindowlessGlxApplication.cpp index 00fe92feb..325d289fa 100644 --- a/src/Platform/WindowlessGlxApplication.cpp +++ b/src/Platform/WindowlessGlxApplication.cpp @@ -39,9 +39,11 @@ WindowlessGlxApplication::WindowlessGlxApplication(const Arguments&, const Confi createContext(configuration); } +#ifndef DOXYGEN_GENERATING_OUTPUT WindowlessGlxApplication::WindowlessGlxApplication(const Arguments&): c(nullptr) { createContext({}); } +#endif WindowlessGlxApplication::WindowlessGlxApplication(const Arguments&, std::nullptr_t): c(nullptr) {} diff --git a/src/Platform/WindowlessNaClApplication.cpp b/src/Platform/WindowlessNaClApplication.cpp index 5336ba23c..c1e72711f 100644 --- a/src/Platform/WindowlessNaClApplication.cpp +++ b/src/Platform/WindowlessNaClApplication.cpp @@ -55,10 +55,12 @@ WindowlessNaClApplication::WindowlessNaClApplication(const Arguments& arguments, createContext(configuration); } +#ifndef DOXYGEN_GENERATING_OUTPUT WindowlessNaClApplication::WindowlessNaClApplication(const Arguments& arguments): Instance(arguments), Graphics3DClient(this), c(nullptr) { debugOutput = new ConsoleDebugOutput(this); createContext({}); } +#endif WindowlessNaClApplication::WindowlessNaClApplication(const Arguments& arguments, std::nullptr_t): Instance(arguments), Graphics3DClient(this), graphics(nullptr), c(nullptr) { debugOutput = new ConsoleDebugOutput(this);