Browse Source

Platform: pass application configuration via reference, not pointer.

Removes the need for explicit new/delete calls.
pull/278/head
Vladimír Vondruš 13 years ago
parent
commit
4222d8a297
  1. 21
      src/Platform/AbstractXApplication.cpp
  2. 28
      src/Platform/AbstractXApplication.h
  3. 26
      src/Platform/GlutApplication.cpp
  4. 56
      src/Platform/GlutApplication.h
  5. 8
      src/Platform/GlxApplication.h
  6. 30
      src/Platform/NaClApplication.cpp
  7. 42
      src/Platform/NaClApplication.h
  8. 36
      src/Platform/Sdl2Application.cpp
  9. 40
      src/Platform/Sdl2Application.h
  10. 15
      src/Platform/WindowlessGlxApplication.cpp
  11. 14
      src/Platform/WindowlessGlxApplication.h
  12. 22
      src/Platform/WindowlessNaClApplication.cpp
  13. 30
      src/Platform/WindowlessNaClApplication.h
  14. 8
      src/Platform/XEglApplication.h

21
src/Platform/AbstractXApplication.cpp

@ -36,18 +36,22 @@
namespace Magnum { namespace Platform { namespace Magnum { namespace Platform {
AbstractXApplication::AbstractXApplication(AbstractContextHandler<Display*, VisualID, Window>* contextHandler, const Arguments&): contextHandler(contextHandler), c(nullptr), flags(Flag::Redraw) { /** @todo Delegating constructor when support for GCC 4.6 is dropped */
createContext(new Configuration);
AbstractXApplication::AbstractXApplication(AbstractContextHandler<Display*, VisualID, Window>* contextHandler, const Arguments&, const Configuration& configuration): contextHandler(contextHandler), c(nullptr), flags(Flag::Redraw) {
createContext(configuration);
} }
AbstractXApplication::AbstractXApplication(AbstractContextHandler<Display*, VisualID, Window>* contextHandler, const Arguments&, Configuration* configuration): contextHandler(contextHandler), c(nullptr), flags(Flag::Redraw) { AbstractXApplication::AbstractXApplication(AbstractContextHandler<Display*, VisualID, Window>* contextHandler, const Arguments&): contextHandler(contextHandler), c(nullptr), flags(Flag::Redraw) {
if(configuration) createContext(configuration); createContext({});
} }
void AbstractXApplication::createContext(AbstractXApplication::Configuration* configuration) { AbstractXApplication::AbstractXApplication(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", ); CORRADE_ASSERT(!c, "AbstractXApplication::createContext(): context already created", );
viewportSize = configuration->size(); viewportSize = configuration.size();
/* Get default X display */ /* Get default X display */
display = XOpenDisplay(nullptr); display = XOpenDisplay(nullptr);
@ -73,8 +77,8 @@ void AbstractXApplication::createContext(AbstractXApplication::Configuration* co
attr.colormap = XCreateColormap(display, root, visInfo->visual, AllocNone); attr.colormap = XCreateColormap(display, root, visInfo->visual, AllocNone);
attr.event_mask = 0; attr.event_mask = 0;
unsigned long mask = CWBackPixel|CWBorderPixel|CWColormap|CWEventMask; unsigned long mask = CWBackPixel|CWBorderPixel|CWColormap|CWEventMask;
window = XCreateWindow(display, root, 20, 20, configuration->size().x(), configuration->size().y(), 0, visInfo->depth, InputOutput, visInfo->visual, mask, &attr); window = XCreateWindow(display, root, 20, 20, configuration.size().x(), configuration.size().y(), 0, visInfo->depth, InputOutput, visInfo->visual, mask, &attr);
XSetStandardProperties(display, window, configuration->title().c_str(), nullptr, None, nullptr, 0, nullptr); XSetStandardProperties(display, window, configuration.title().data(), nullptr, None, nullptr, 0, nullptr);
XFree(visInfo); XFree(visInfo);
/* Be notified about closing the window */ /* Be notified about closing the window */
@ -94,7 +98,6 @@ void AbstractXApplication::createContext(AbstractXApplication::Configuration* co
ExtensionWrangler::initialize(contextHandler->experimentalExtensionWranglerFeatures()); ExtensionWrangler::initialize(contextHandler->experimentalExtensionWranglerFeatures());
c = new Context; c = new Context;
delete configuration;
} }
AbstractXApplication::~AbstractXApplication() { AbstractXApplication::~AbstractXApplication() {

28
src/Platform/AbstractXApplication.h

@ -73,10 +73,17 @@ class AbstractXApplication {
* @param contextHandler OpenGL context handler * @param contextHandler OpenGL context handler
* @param arguments Application arguments * @param arguments Application arguments
* *
* Creates application with default configuration. See Configuration * Creates application with default or user-specified configuration.
* for more information. * 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); explicit AbstractXApplication(AbstractContextHandler<Display*, VisualID, Window>* contextHandler, const Arguments& arguments);
#endif
/** /**
* @brief Constructor * @brief Constructor
@ -84,11 +91,10 @@ class AbstractXApplication {
* @param arguments Application arguments * @param arguments Application arguments
* @param configuration Configuration * @param configuration Configuration
* *
* The @p configuration is deleted afterwards. If `nullptr` is passed * Unlike above, the context is not created and must be created later
* as @p configuration, the context is not created and must be created * with createContext() or tryCreateContext().
* with createContext().
*/ */
explicit AbstractXApplication(AbstractContextHandler<Display*, VisualID, Window>* contextHandler, const Arguments& arguments, Configuration* configuration); explicit AbstractXApplication(AbstractContextHandler<Display*, VisualID, Window>* contextHandler, const Arguments& arguments, std::nullptr_t);
/** /**
* @brief Execute main loop * @brief Execute main loop
@ -110,7 +116,7 @@ class AbstractXApplication {
~AbstractXApplication(); ~AbstractXApplication();
/** @copydoc GlutApplication::createContext() */ /** @copydoc GlutApplication::createContext() */
void createContext(Configuration* configuration); void createContext(const Configuration& configuration);
/** @{ @name Drawing functions */ /** @{ @name Drawing functions */
@ -202,9 +208,9 @@ class AbstractXApplication::Configuration {
* *
* Default is `"Magnum X Application"`. * Default is `"Magnum X Application"`.
*/ */
Configuration* setTitle(std::string title) { Configuration& setTitle(std::string title) {
_title = std::move(title); _title = std::move(title);
return this; return *this;
} }
/** @brief Window size */ /** @brief Window size */
@ -216,9 +222,9 @@ class AbstractXApplication::Configuration {
* *
* Default is `{800, 600}`. * Default is `{800, 600}`.
*/ */
Configuration* setSize(const Vector2i& size) { Configuration& setSize(const Vector2i& size) {
_size = size; _size = size;
return this; return *this;
} }
private: private:

26
src/Platform/GlutApplication.cpp

@ -31,14 +31,20 @@ namespace Magnum { namespace Platform {
GlutApplication* GlutApplication::instance = nullptr; GlutApplication* GlutApplication::instance = nullptr;
/** @todo Delegating constructor when support for GCC 4.6 is dropped */
GlutApplication::GlutApplication(const Arguments& arguments, const Configuration& configuration): c(nullptr) {
initialize(arguments.argc, arguments.argv);
createContext(configuration);
}
GlutApplication::GlutApplication(const Arguments& arguments): c(nullptr) { GlutApplication::GlutApplication(const Arguments& arguments): c(nullptr) {
initialize(arguments.argc, arguments.argv); initialize(arguments.argc, arguments.argv);
createContext(new Configuration); createContext({});
} }
GlutApplication::GlutApplication(const Arguments& arguments, Configuration* configuration): c(nullptr) { GlutApplication::GlutApplication(const Arguments& arguments, std::nullptr_t): c(nullptr) {
initialize(arguments.argc, arguments.argv); initialize(arguments.argc, arguments.argv);
if(configuration) createContext(configuration);
} }
void GlutApplication::initialize(int& argc, char** argv) { void GlutApplication::initialize(int& argc, char** argv) {
@ -50,26 +56,24 @@ void GlutApplication::initialize(int& argc, char** argv) {
glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_CONTINUE_EXECUTION); glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_CONTINUE_EXECUTION);
} }
void GlutApplication::createContext(Configuration* configuration) { void GlutApplication::createContext(const Configuration& configuration) {
if(!tryCreateContext(configuration)) { if(!tryCreateContext(configuration)) {
Error() << "Platform::GlutApplication::createContext(): cannot create context"; Error() << "Platform::GlutApplication::createContext(): cannot create context";
delete configuration;
std::exit(1); std::exit(1);
}
} else delete configuration;
} }
bool GlutApplication::tryCreateContext(Configuration* configuration) { bool GlutApplication::tryCreateContext(const Configuration& configuration) {
CORRADE_ASSERT(!c, "Platform::GlutApplication::tryCreateContext(): context already created", false); CORRADE_ASSERT(!c, "Platform::GlutApplication::tryCreateContext(): context already created", false);
unsigned int flags = GLUT_DOUBLE|GLUT_RGBA|GLUT_DEPTH|GLUT_STENCIL; unsigned int flags = GLUT_DOUBLE|GLUT_RGBA|GLUT_DEPTH|GLUT_STENCIL;
/* Multisampling */ /* Multisampling */
if(configuration->sampleCount()) flags |= GLUT_MULTISAMPLE; if(configuration.sampleCount()) flags |= GLUT_MULTISAMPLE;
glutInitDisplayMode(flags); glutInitDisplayMode(flags);
glutInitWindowSize(configuration->size().x(), configuration->size().y()); glutInitWindowSize(configuration.size().x(), configuration.size().y());
if(!glutCreateWindow(configuration->title().c_str())) if(!glutCreateWindow(configuration.title().data()))
return false; return false;
glutReshapeFunc(staticViewportEvent); glutReshapeFunc(staticViewportEvent);
glutSpecialFunc(staticKeyEvent); glutSpecialFunc(staticKeyEvent);

56
src/Platform/GlutApplication.h

@ -82,24 +82,28 @@ class GlutApplication {
/** /**
* @brief Default constructor * @brief Default constructor
* @param arguments Application arguments * @param arguments Application arguments
* @param configuration %Configuration
* *
* Creates application with default configuration. See Configuration * Creates application with default or user-specified configuration.
* for more information. The program exits if the context cannot be * See Configuration for more information. The program exits if the
* created, see tryCreateContext() for an alternative. * context cannot be created, see below for an alternative.
*/ */
#ifdef DOXYGEN_GENERATING_OUTPUT
explicit GlutApplication(const Arguments& arguments, const Configuration& configuration = Configuration());
#else
/* To avoid "invalid use of incomplete type" */
explicit GlutApplication(const Arguments& arguments, const Configuration& configuration);
explicit GlutApplication(const Arguments& arguments); explicit GlutApplication(const Arguments& arguments);
#endif
/** /**
* @brief Constructor * @brief Constructor
* @param arguments Application arguments * @param arguments Application arguments
* @param configuration Configuration
* *
* The @p configuration is deleted afterwards. If `nullptr` is passed * Unlike above, the context is not created and must be created later
* as @p configuration, the context is not created and must be created * with createContext() or tryCreateContext().
* with createContext(). The program exits if the context cannot be
* created, see tryCreateContext() for an alternative.
*/ */
explicit GlutApplication(const Arguments& arguments, Configuration* configuration); explicit GlutApplication(const Arguments& arguments, std::nullptr_t);
/** /**
* @brief Execute main loop * @brief Execute main loop
@ -118,21 +122,19 @@ class GlutApplication {
/** /**
* @brief Create context with given configuration * @brief Create context with given configuration
* *
* The @p configuration is deleted afterwards. Must be called if and * Must be called if and only if the context wasn't created by the
* only if the context wasn't created by the constructor itself. The * constructor itself. The program exits if the context cannot be
* program exits if the context cannot be created, see tryCreateContext() * created, see tryCreateContext() for an alternative.
* for an alternative.
*/ */
void createContext(Configuration* configuration); void createContext(const Configuration& configuration);
/** /**
* @brief Try to create context with given configuration * @brief Try to create context with given configuration
* *
* Unlike createContext() the @p configuration is *not* deleted * Unlike createContext() returns `false` if the context cannot be
* afterwards. Returns `false` if the context cannot be created, `true` * created, `true` otherwise.
* otherwise.
*/ */
bool tryCreateContext(Configuration* configuration); bool tryCreateContext(const Configuration& configuration);
/** @{ @name Drawing functions */ /** @{ @name Drawing functions */
@ -288,13 +290,13 @@ class GlutApplication::Configuration {
/** /**
* @brief Set window title * @brief Set window title
* @return Pointer to self (for method chaining) * @return Reference to self (for method chaining)
* *
* Default is `"Magnum GLUT Application"`. * Default is `"Magnum GLUT Application"`.
*/ */
Configuration* setTitle(std::string title) { Configuration& setTitle(std::string title) {
_title = std::move(title); _title = std::move(title);
return this; return *this;
} }
/** @brief Window size */ /** @brief Window size */
@ -302,13 +304,13 @@ class GlutApplication::Configuration {
/** /**
* @brief Set window size * @brief Set window size
* @return Pointer to self (for method chaining) * @return Reference to self (for method chaining)
* *
* Default is `{800, 600}`. * Default is `{800, 600}`.
*/ */
Configuration* setSize(const Vector2i& size) { Configuration& setSize(const Vector2i& size) {
_size = size; _size = size;
return this; return *this;
} }
/** @brief Sample count */ /** @brief Sample count */
@ -316,15 +318,15 @@ class GlutApplication::Configuration {
/** /**
* @brief Set sample count * @brief Set sample count
* @return Pointer to self (for method chaining) * @return Reference to self (for method chaining)
* *
* Default is `0`, thus no multisampling. The actual sample count is * Default is `0`, thus no multisampling. The actual sample count is
* ignored, GLUT either enables it or disables. See also * ignored, GLUT either enables it or disables. See also
* @ref Renderer::Feature "Renderer::Feature::Multisampling". * @ref Renderer::Feature "Renderer::Feature::Multisampling".
*/ */
Configuration* setSampleCount(Int count) { Configuration& setSampleCount(Int count) {
_sampleCount = count; _sampleCount = count;
return this; return *this;
} }
private: private:

8
src/Platform/GlxApplication.h

@ -56,11 +56,11 @@ to simplify porting.
*/ */
class GlxApplication: public AbstractXApplication { class GlxApplication: public AbstractXApplication {
public: public:
/** @copydoc GlutApplication::GlutApplication(const Arguments&) */ /** @copydoc GlutApplication::GlutApplication(const Arguments&, const Configuration&) */
explicit GlxApplication(const Arguments& arguments): AbstractXApplication(new GlxContextHandler, arguments) {} explicit GlxApplication(const Arguments& arguments, const Configuration& configuration = Configuration()): AbstractXApplication(new GlxContextHandler, arguments, configuration) {}
/** @copydoc GlutApplication::GlutApplication(const Arguments&, Configuration*) */ /** @copydoc GlutApplication::GlutApplication(const Arguments&, std::nullptr_t) */
explicit GlxApplication(const Arguments& arguments, Configuration* configuration): AbstractXApplication(new GlxContextHandler, arguments, configuration) {} explicit GlxApplication(const Arguments& arguments, std::nullptr_t): AbstractXApplication(new GlxContextHandler, arguments, nullptr) {}
protected: protected:
/* Nobody will need to have (and delete) GlxApplication*, thus this is /* Nobody will need to have (and delete) GlxApplication*, thus this is

30
src/Platform/NaClApplication.cpp

@ -49,38 +49,42 @@ NaClApplication::ConsoleDebugOutput::ConsoleDebugOutput(pp::Instance* instance):
Error::setOutput(&errorOutput); Error::setOutput(&errorOutput);
} }
/** @todo Delegating constructor when support for GCC 4.6 is dropped */
NaClApplication::NaClApplication(const Arguments& arguments, const Configuration& configuration): Instance(arguments), Graphics3DClient(this), MouseLock(this), graphics(nullptr), fullscreen(nullptr), c(nullptr) {
debugOutput = new ConsoleDebugOutput(this);
createContext(configuration);
}
NaClApplication::NaClApplication(const Arguments& arguments): Instance(arguments), Graphics3DClient(this), MouseLock(this), c(nullptr) { NaClApplication::NaClApplication(const Arguments& arguments): Instance(arguments), Graphics3DClient(this), MouseLock(this), c(nullptr) {
debugOutput = new ConsoleDebugOutput(this); debugOutput = new ConsoleDebugOutput(this);
createContext(new Configuration); createContext({});
} }
NaClApplication::NaClApplication(const Arguments& arguments, Configuration* configuration): Instance(arguments), Graphics3DClient(this), MouseLock(this), graphics(nullptr), fullscreen(nullptr), c(nullptr) { NaClApplication::NaClApplication(const Arguments& arguments, std::nullptr_t): Instance(arguments), Graphics3DClient(this), MouseLock(this), c(nullptr) {
debugOutput = new ConsoleDebugOutput(this); debugOutput = new ConsoleDebugOutput(this);
if(configuration) createContext(configuration);
} }
void NaClApplication::createContext(Configuration* configuration) { void NaClApplication::createContext(const Configuration& configuration) {
if(!tryCreateContext(configuration)) { if(!tryCreateContext(configuration)) {
Error() << "Platform::NaClApplication::createContext(): cannot create context"; Error() << "Platform::NaClApplication::createContext(): cannot create context";
delete configuration;
std::exit(1); std::exit(1);
}
} else delete configuration;
} }
bool NaClApplication::tryCreateContext(Configuration* configuration) { bool NaClApplication::tryCreateContext(const Configuration& configuration) {
CORRADE_ASSERT(!c, "Platform::NaClApplication::tryCreateContext(): context already created", false); CORRADE_ASSERT(!c, "Platform::NaClApplication::tryCreateContext(): context already created", false);
viewportSize = configuration->size(); viewportSize = configuration.size();
const std::int32_t attributes[] = { const std::int32_t attributes[] = {
PP_GRAPHICS3DATTRIB_ALPHA_SIZE, 8, PP_GRAPHICS3DATTRIB_ALPHA_SIZE, 8,
PP_GRAPHICS3DATTRIB_DEPTH_SIZE, 24, PP_GRAPHICS3DATTRIB_DEPTH_SIZE, 24,
PP_GRAPHICS3DATTRIB_STENCIL_SIZE, 8, PP_GRAPHICS3DATTRIB_STENCIL_SIZE, 8,
PP_GRAPHICS3DATTRIB_SAMPLES, configuration->sampleCount(), PP_GRAPHICS3DATTRIB_SAMPLES, configuration.sampleCount(),
PP_GRAPHICS3DATTRIB_SAMPLE_BUFFERS, configuration->sampleCount() > 1? 1 : 0, PP_GRAPHICS3DATTRIB_SAMPLE_BUFFERS, configuration.sampleCount() > 1 ? 1 : 0,
PP_GRAPHICS3DATTRIB_WIDTH, configuration->size().x(), PP_GRAPHICS3DATTRIB_WIDTH, configuration.size().x(),
PP_GRAPHICS3DATTRIB_HEIGHT, configuration->size().y(), PP_GRAPHICS3DATTRIB_HEIGHT, configuration.size().y(),
PP_GRAPHICS3DATTRIB_NONE PP_GRAPHICS3DATTRIB_NONE
}; };

42
src/Platform/NaClApplication.h

@ -137,25 +137,17 @@ class NaClApplication: public pp::Instance, public pp::Graphics3DClient, public
class MouseEvent; class MouseEvent;
class MouseMoveEvent; class MouseMoveEvent;
/** /** @copydoc GlutApplication::GlutApplication(const Arguments&, const Configuration&) */
* @brief Default constructor #ifdef DOXYGEN_GENERATING_OUTPUT
* @param arguments Application arguments explicit NaClApplication(const Arguments& arguments, const Configuration& configuration = Configuration());
* #else
* Creates application with default configuration. See Configuration /* To avoid "invalid use of incomplete type" */
* for more information. explicit NaClApplication(const Arguments& arguments, const Configuration& configuration);
*/
explicit NaClApplication(const Arguments& arguments); explicit NaClApplication(const Arguments& arguments);
#endif
/** /** @copydoc GlutApplication::GlutApplication(const Arguments&, std::nullptr_t) */
* @brief Constructor explicit NaClApplication(const Arguments& arguments, std::nullptr_t);
* @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(const Arguments& arguments, Configuration* configuration);
/** @brief Whether the application runs fullscreen */ /** @brief Whether the application runs fullscreen */
bool isFullscreen(); bool isFullscreen();
@ -176,10 +168,10 @@ class NaClApplication: public pp::Instance, public pp::Graphics3DClient, public
~NaClApplication(); ~NaClApplication();
/** @copydoc GlutApplication::createContext() */ /** @copydoc GlutApplication::createContext() */
void createContext(Configuration* configuration); void createContext(const Configuration& configuration);
/** @copydoc GlutApplication::tryCreateContext() */ /** @copydoc GlutApplication::tryCreateContext() */
bool tryCreateContext(Configuration* configuration); bool tryCreateContext(const Configuration& configuration);
/** @{ @name Drawing functions */ /** @{ @name Drawing functions */
@ -323,13 +315,13 @@ class NaClApplication::Configuration {
/** /**
* @brief Set window size * @brief Set window size
* @return Pointer to self (for method chaining) * @return Reference to self (for method chaining)
* *
* Default is `{640, 480}`. * Default is `{640, 480}`.
*/ */
Configuration* setSize(const Vector2i& size) { Configuration& setSize(const Vector2i& size) {
_size = size; _size = size;
return this; return *this;
} }
/** @brief Sample count */ /** @brief Sample count */
@ -337,14 +329,14 @@ class NaClApplication::Configuration {
/** /**
* @brief Set sample count * @brief Set sample count
* @return Pointer to self (for method chaining) * @return Reference to self (for method chaining)
* *
* Default is `0`, thus no multisampling. See also * Default is `0`, thus no multisampling. See also
* @ref Renderer::Feature "Renderer::Feature::Multisampling". * @ref Renderer::Feature "Renderer::Feature::Multisampling".
*/ */
Configuration* setSampleCount(Int count) { Configuration& setSampleCount(Int count) {
_sampleCount = count; _sampleCount = count;
return this; return *this;
} }
private: private:

36
src/Platform/Sdl2Application.cpp

@ -47,14 +47,20 @@ Sdl2Application::InputEvent::Modifiers fixedModifiers(Uint16 mod) {
} }
/** @todo Delegating constructor when support for GCC 4.6 is dropped */
Sdl2Application::Sdl2Application(const Arguments&, const Configuration& configuration): context(nullptr), flags(Flag::Redraw) {
initialize();
createContext(configuration);
}
Sdl2Application::Sdl2Application(const Arguments&): context(nullptr), flags(Flag::Redraw) { Sdl2Application::Sdl2Application(const Arguments&): context(nullptr), flags(Flag::Redraw) {
initialize(); initialize();
createContext(new Configuration); createContext({});
} }
Sdl2Application::Sdl2Application(const Arguments&, Configuration* configuration): context(nullptr), flags(Flag::Redraw) { Sdl2Application::Sdl2Application(const Arguments&, std::nullptr_t): context(nullptr), flags(Flag::Redraw) {
initialize(); initialize();
if(configuration) createContext(configuration);
} }
void Sdl2Application::initialize() { void Sdl2Application::initialize() {
@ -64,16 +70,14 @@ void Sdl2Application::initialize() {
} }
} }
void Sdl2Application::createContext(Configuration* configuration) { void Sdl2Application::createContext(const Configuration& configuration) {
if(!tryCreateContext(configuration)) { if(!tryCreateContext(configuration)) {
Error() << "Platform::Sdl2Application::createContext(): cannot create context:" << SDL_GetError(); Error() << "Platform::Sdl2Application::createContext(): cannot create context:" << SDL_GetError();
delete configuration;
std::exit(1); std::exit(1);
}
} else delete configuration;
} }
bool Sdl2Application::tryCreateContext(Configuration* configuration) { bool Sdl2Application::tryCreateContext(const Configuration& configuration) {
CORRADE_ASSERT(!context, "Platform::Sdl2Application::tryCreateContext(): context already created", false); CORRADE_ASSERT(!context, "Platform::Sdl2Application::tryCreateContext(): context already created", false);
/* Enable double buffering and 24bt depth buffer */ /* Enable double buffering and 24bt depth buffer */
@ -81,16 +85,16 @@ bool Sdl2Application::tryCreateContext(Configuration* configuration) {
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
/* Multisampling */ /* Multisampling */
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, configuration->sampleCount() > 1 ? 1 : 0); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, configuration.sampleCount() > 1 ? 1 : 0);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, configuration->sampleCount()); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, configuration.sampleCount());
/* Flags: if not hidden, set as shown */ /* Flags: if not hidden, set as shown */
Uint32 flags(configuration->flags()); Uint32 flags(configuration.flags());
if(!(configuration->flags() & Configuration::Flag::Hidden)) flags |= SDL_WINDOW_SHOWN; if(!(configuration.flags() & Configuration::Flag::Hidden)) flags |= SDL_WINDOW_SHOWN;
if(!(window = SDL_CreateWindow(configuration->title().c_str(), if(!(window = SDL_CreateWindow(configuration.title().data(),
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
configuration->size().x(), configuration->size().y(), configuration.size().x(), configuration.size().y(),
SDL_WINDOW_OPENGL|flags))) SDL_WINDOW_OPENGL|flags)))
return false; return false;
@ -108,8 +112,8 @@ bool Sdl2Application::tryCreateContext(Configuration* configuration) {
SDL_Event* sizeEvent = new SDL_Event; SDL_Event* sizeEvent = new SDL_Event;
sizeEvent->type = SDL_WINDOWEVENT; sizeEvent->type = SDL_WINDOWEVENT;
sizeEvent->window.event = SDL_WINDOWEVENT_RESIZED; sizeEvent->window.event = SDL_WINDOWEVENT_RESIZED;
sizeEvent->window.data1 = configuration->size().x(); sizeEvent->window.data1 = configuration.size().x();
sizeEvent->window.data2 = configuration->size().y(); sizeEvent->window.data2 = configuration.size().y();
SDL_PushEvent(sizeEvent); SDL_PushEvent(sizeEvent);
c = new Context; c = new Context;

40
src/Platform/Sdl2Application.h

@ -80,11 +80,17 @@ class Sdl2Application {
class MouseEvent; class MouseEvent;
class MouseMoveEvent; class MouseMoveEvent;
/** @copydoc GlutApplication::GlutApplication(const Arguments&) */ /** @copydoc GlutApplication::GlutApplication(const Arguments&, const Configuration&) */
#ifdef DOXYGEN_GENERATING_OUTPUT
explicit Sdl2Application(const Arguments& arguments, const Configuration& configuration = Configuration());
#else
/* To avoid "invalid use of incomplete type" */
explicit Sdl2Application(const Arguments& arguments, const Configuration& configuration);
explicit Sdl2Application(const Arguments& arguments); explicit Sdl2Application(const Arguments& arguments);
#endif
/** @copydoc GlutApplication::GlutApplication(const Arguments&, Configuration*) */ /** @copydoc GlutApplication::GlutApplication(const Arguments&, std::nullptr_t) */
explicit Sdl2Application(const Arguments& arguments, Configuration* configuration); explicit Sdl2Application(const Arguments& arguments, std::nullptr_t);
/** @copydoc GlutApplication::exec() */ /** @copydoc GlutApplication::exec() */
int exec(); int exec();
@ -98,10 +104,10 @@ class Sdl2Application {
virtual ~Sdl2Application(); virtual ~Sdl2Application();
/** @copydoc GlutApplication::createContext() */ /** @copydoc GlutApplication::createContext() */
void createContext(Configuration* configuration); void createContext(const Configuration& configuration);
/** @copydoc GlutApplication::tryCreateContext() */ /** @copydoc GlutApplication::tryCreateContext() */
bool tryCreateContext(Configuration* configuration); bool tryCreateContext(const Configuration& configuration);
/** @{ @name Drawing functions */ /** @{ @name Drawing functions */
@ -231,13 +237,13 @@ class Sdl2Application::Configuration {
/** /**
* @brief Set window title * @brief Set window title
* @return Pointer to self (for method chaining) * @return Reference to self (for method chaining)
* *
* Default is `"Magnum SDL2 Application"`. * Default is `"Magnum SDL2 Application"`.
*/ */
Configuration* setTitle(std::string title) { Configuration& setTitle(std::string title) {
_title = std::move(title); _title = std::move(title);
return this; return *this;
} }
/** @brief Window size */ /** @brief Window size */
@ -245,13 +251,13 @@ class Sdl2Application::Configuration {
/** /**
* @brief Set window size * @brief Set window size
* @return Pointer to self (for method chaining) * @return Reference to self (for method chaining)
* *
* Default is `{800, 600}`. * Default is `{800, 600}`.
*/ */
Configuration* setSize(const Vector2i& size) { Configuration& setSize(const Vector2i& size) {
_size = size; _size = size;
return this; return *this;
} }
/** @brief Window flags */ /** @brief Window flags */
@ -259,13 +265,13 @@ class Sdl2Application::Configuration {
/** /**
* @brief Set window flags * @brief Set window flags
* @return Pointer to self (for method chaining) * @return Reference to self (for method chaining)
* *
* Default is @ref Flag "Flag::Resizable". * Default is @ref Flag "Flag::Resizable".
*/ */
Configuration* setFlags(const Flags flags) { Configuration& setFlags(const Flags flags) {
_flags = flags; _flags = flags;
return this; return *this;
} }
/** @brief Sample count */ /** @brief Sample count */
@ -273,14 +279,14 @@ class Sdl2Application::Configuration {
/** /**
* @brief Set sample count * @brief Set sample count
* @return Pointer to self (for method chaining) * @return Reference to self (for method chaining)
* *
* Default is `0`, thus no multisampling. See also * Default is `0`, thus no multisampling. See also
* @ref Renderer::Feature "Renderer::Feature::Multisampling". * @ref Renderer::Feature "Renderer::Feature::Multisampling".
*/ */
Configuration* setSampleCount(Int count) { Configuration& setSampleCount(Int count) {
_sampleCount = count; _sampleCount = count;
return this; return *this;
} }
private: private:

15
src/Platform/WindowlessGlxApplication.cpp

@ -33,15 +33,19 @@
namespace Magnum { namespace Platform { namespace Magnum { namespace Platform {
WindowlessGlxApplication::WindowlessGlxApplication(const Arguments&): c(nullptr) { /** @todo Delegating constructor when support for GCC 4.6 is dropped */
createContext(new Configuration);
WindowlessGlxApplication::WindowlessGlxApplication(const Arguments&, const Configuration& configuration): c(nullptr) {
createContext(configuration);
} }
WindowlessGlxApplication::WindowlessGlxApplication(const Arguments&, Configuration* configuration): c(nullptr) { WindowlessGlxApplication::WindowlessGlxApplication(const Arguments&): c(nullptr) {
if(configuration) createContext(configuration); createContext({});
} }
void WindowlessGlxApplication::createContext(Configuration* configuration) { WindowlessGlxApplication::WindowlessGlxApplication(const Arguments&, std::nullptr_t): c(nullptr) {}
void WindowlessGlxApplication::createContext(const Configuration&) {
CORRADE_ASSERT(!c, "WindowlessGlxApplication::createContext(): context already created", ); CORRADE_ASSERT(!c, "WindowlessGlxApplication::createContext(): context already created", );
display = XOpenDisplay(nullptr); display = XOpenDisplay(nullptr);
@ -100,7 +104,6 @@ void WindowlessGlxApplication::createContext(Configuration* configuration) {
ExtensionWrangler::initialize(ExtensionWrangler::ExperimentalFeatures::Enable); ExtensionWrangler::initialize(ExtensionWrangler::ExperimentalFeatures::Enable);
c = new Context; c = new Context;
delete configuration;
} }
WindowlessGlxApplication::~WindowlessGlxApplication() { WindowlessGlxApplication::~WindowlessGlxApplication() {

14
src/Platform/WindowlessGlxApplication.h

@ -73,11 +73,17 @@ class WindowlessGlxApplication {
class Configuration; class Configuration;
/** @copydoc GlutApplication::GlutApplication(const Arguments&) */ /** @copydoc GlutApplication::GlutApplication(const Arguments&, const Configuration&) */
#ifdef DOXYGEN_GENERATING_OUTPUT
explicit WindowlessGlxApplication(const Arguments& arguments, const Configuration& configuration = Configuration());
#else
/* To avoid "invalid use of incomplete type" */
explicit WindowlessGlxApplication(const Arguments& arguments, const Configuration& configuration);
explicit WindowlessGlxApplication(const Arguments& arguments); explicit WindowlessGlxApplication(const Arguments& arguments);
#endif
/** @copydoc GlutApplication::GlutApplication(const Arguments&, Configuration*) */ /** @copydoc GlutApplication::GlutApplication(const Arguments&, std::nullptr_t) */
explicit WindowlessGlxApplication(const Arguments& arguments, Configuration* configuration); explicit WindowlessGlxApplication(const Arguments& arguments, std::nullptr_t);
/** /**
* @brief Execute application * @brief Execute application
@ -91,7 +97,7 @@ class WindowlessGlxApplication {
~WindowlessGlxApplication(); ~WindowlessGlxApplication();
/** @copydoc GlutApplication::createContext() */ /** @copydoc GlutApplication::createContext() */
void createContext(Configuration* configuration); void createContext(const Configuration& configuration);
private: private:
Display* display; Display* display;

22
src/Platform/WindowlessNaClApplication.cpp

@ -41,33 +41,37 @@ struct WindowlessNaClApplication::ConsoleDebugOutput {
WindowlessNaClApplication::ConsoleDebugOutput::ConsoleDebugOutput(pp::Instance* instance): debugBuffer(instance, Utility::NaClConsoleStreamBuffer::LogLevel::Log), warningBuffer(instance, Utility::NaClConsoleStreamBuffer::LogLevel::Warning), errorBuffer(instance, Utility::NaClConsoleStreamBuffer::LogLevel::Error), debugOutput(&debugBuffer), warningOutput(&warningBuffer), errorOutput(&errorBuffer) { WindowlessNaClApplication::ConsoleDebugOutput::ConsoleDebugOutput(pp::Instance* instance): debugBuffer(instance, Utility::NaClConsoleStreamBuffer::LogLevel::Log), warningBuffer(instance, Utility::NaClConsoleStreamBuffer::LogLevel::Warning), errorBuffer(instance, Utility::NaClConsoleStreamBuffer::LogLevel::Error), debugOutput(&debugBuffer), warningOutput(&warningBuffer), errorOutput(&errorBuffer) {
/* Inform about this change on standard output */ /* Inform about this change on standard output */
Debug() << "Platform::NaClApplication: redirecting Debug, Warning and Error output to JavaScript console"; Debug() << "Platform::WindowlessNaClApplication: redirecting Debug, Warning and Error output to JavaScript console";
Debug::setOutput(&debugOutput); Debug::setOutput(&debugOutput);
Warning::setOutput(&warningOutput); Warning::setOutput(&warningOutput);
Error::setOutput(&errorOutput); Error::setOutput(&errorOutput);
} }
/** @todo Delegating constructor when support for GCC 4.6 is dropped */
WindowlessNaClApplication::WindowlessNaClApplication(const Arguments& arguments, const Configuration& configuration): Instance(arguments), Graphics3DClient(this), graphics(nullptr), c(nullptr) {
debugOutput = new ConsoleDebugOutput(this);
createContext(configuration);
}
WindowlessNaClApplication::WindowlessNaClApplication(const Arguments& arguments): Instance(arguments), Graphics3DClient(this), c(nullptr) { WindowlessNaClApplication::WindowlessNaClApplication(const Arguments& arguments): Instance(arguments), Graphics3DClient(this), c(nullptr) {
debugOutput = new ConsoleDebugOutput(this); debugOutput = new ConsoleDebugOutput(this);
createContext(new Configuration); createContext({});
} }
WindowlessNaClApplication::WindowlessNaClApplication(const Arguments& arguments, Configuration* configuration): Instance(arguments), Graphics3DClient(this), graphics(nullptr), c(nullptr) { WindowlessNaClApplication::WindowlessNaClApplication(const Arguments& arguments, std::nullptr_t): Instance(arguments), Graphics3DClient(this), graphics(nullptr), c(nullptr) {
debugOutput = new ConsoleDebugOutput(this); debugOutput = new ConsoleDebugOutput(this);
if(configuration) createContext(configuration);
} }
void WindowlessNaClApplication::createContext(Configuration* configuration) { void WindowlessNaClApplication::createContext(const Configuration& configuration) {
if(!tryCreateContext(configuration)) { if(!tryCreateContext(configuration)) {
Error() << "Platform::WindowlessNaClApplication::createContext(): cannot create context"; Error() << "Platform::WindowlessNaClApplication::createContext(): cannot create context";
delete configuration;
std::exit(1); std::exit(1);
}
} else delete configuration;
} }
bool WindowlessNaClApplication::tryCreateContext(Configuration*) { bool WindowlessNaClApplication::tryCreateContext(const Configuration&) {
CORRADE_ASSERT(!c, "Platform::WindowlessNaClApplication::tryCreateContext(): context already created", false); CORRADE_ASSERT(!c, "Platform::WindowlessNaClApplication::tryCreateContext(): context already created", false);
const std::int32_t attributes[] = { const std::int32_t attributes[] = {

30
src/Platform/WindowlessNaClApplication.h

@ -90,25 +90,17 @@ class WindowlessNaClApplication: public pp::Instance, public pp::Graphics3DClien
class Configuration; class Configuration;
/** /** @copydoc GlutApplication::GlutApplication(const Arguments&, const Configuration&) */
* @brief Default constructor #ifdef DOXYGEN_GENERATING_OUTPUT
* @param arguments Application arguments explicit WindowlessNaClApplication(const Arguments& arguments, const Configuration& configuration = Configuration());
* #else
* Creates application with default configuration. See Configuration /* To avoid "invalid use of incomplete type" */
* for more information. explicit WindowlessNaClApplication(const Arguments& arguments, const Configuration& configuration);
*/
explicit WindowlessNaClApplication(const Arguments& arguments); explicit WindowlessNaClApplication(const Arguments& arguments);
#endif
/** /** @copydoc GlutApplication::GlutApplication(const Arguments&, std::nullptr_t) */
* @brief Constructor explicit WindowlessNaClApplication(const Arguments& arguments, std::nullptr_t);
* @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 WindowlessNaClApplication(const Arguments& arguments, Configuration* configuration);
/** /**
* @brief Execute application * @brief Execute application
@ -122,10 +114,10 @@ class WindowlessNaClApplication: public pp::Instance, public pp::Graphics3DClien
~WindowlessNaClApplication(); ~WindowlessNaClApplication();
/** @copydoc GlutApplication::createContext() */ /** @copydoc GlutApplication::createContext() */
void createContext(Configuration* configuration); void createContext(const Configuration& configuration);
/** @copydoc GlutApplication::tryCreateContext() */ /** @copydoc GlutApplication::tryCreateContext() */
bool tryCreateContext(Configuration* configuration); bool tryCreateContext(const Configuration& configuration);
private: private:
struct ConsoleDebugOutput; struct ConsoleDebugOutput;

8
src/Platform/XEglApplication.h

@ -56,11 +56,11 @@ to simplify porting.
*/ */
class XEglApplication: public AbstractXApplication { class XEglApplication: public AbstractXApplication {
public: public:
/** @copydoc GlutApplication::GlutApplication(const Arguments&) */ /** @copydoc GlutApplication::GlutApplication(const Arguments&, const Configuration&) */
explicit XEglApplication(const Arguments& arguments): AbstractXApplication(new EglContextHandler, arguments) {} explicit XEglApplication(const Arguments& arguments, const Configuration& configuration = Configuration()): AbstractXApplication(new EglContextHandler, arguments, configuration) {}
/** @copydoc GlutApplication::GlutApplication(const Arguments&, Configuration*) */ /** @copydoc GlutApplication::GlutApplication(const Arguments&, std::nullptr_t) */
explicit XEglApplication(const Arguments& arguments, Configuration* configuration): AbstractXApplication(new EglContextHandler, arguments, configuration) {} explicit XEglApplication(const Arguments& arguments, std::nullptr_t): AbstractXApplication(new EglContextHandler, nullptr) {}
protected: protected:
/* Nobody will need to have (and delete) XEglApplication*, thus this is /* Nobody will need to have (and delete) XEglApplication*, thus this is

Loading…
Cancel
Save