Browse Source

Platform: Move emscripten port of Sdl2Application to SDL2

Signed-off-by: Squareys <squareys@googlemail.com>
pull/218/head
Squareys 9 years ago
parent
commit
5fb3f435dd
  1. 27
      src/Magnum/Platform/Sdl2Application.cpp
  2. 22
      src/Magnum/Platform/Sdl2Application.h

27
src/Magnum/Platform/Sdl2Application.cpp

@ -100,7 +100,6 @@ bool Sdl2Application::tryCreateContext(const Configuration& configuration) {
SDL_GL_SetAttribute(SDL_GL_FRAMEBUFFER_SRGB_CAPABLE, configuration.isSRGBCapable());
#endif
/** @todo Remove when Emscripten has proper SDL2 support */
#ifndef CORRADE_TARGET_EMSCRIPTEN
/* Set context version, if user-specified */
if(configuration.version() != Version::None) {
@ -147,6 +146,7 @@ bool Sdl2Application::tryCreateContext(const Configuration& configuration) {
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
#endif
}
#endif
/* Create window. Hide it by default so we don't have distracting window
blinking in case we have to destroy it again right away */
@ -238,23 +238,12 @@ bool Sdl2Application::tryCreateContext(const Configuration& configuration) {
SDL_GL_GetDrawableSize(_window, &drawableSize.x(), &drawableSize.y());
glViewport(0, 0, drawableSize.x(), drawableSize.y());
#endif
#else
/* Emscripten-specific initialization */
if(!(_glContext = SDL_SetVideoMode(configuration.size().x(), configuration.size().y(), 24, SDL_OPENGL|SDL_HWSURFACE|SDL_DOUBLEBUF))) {
Error() << "Platform::Sdl2Application::tryCreateContext(): cannot create context:" << SDL_GetError();
return false;
}
#endif
/* Destroy everything also when the Magnum context creation fails */
if(!_context->tryCreate()) {
#ifndef CORRADE_TARGET_EMSCRIPTEN
SDL_GL_DeleteContext(_glContext);
SDL_DestroyWindow(_window);
_window = nullptr;
#else
SDL_FreeSurface(_glContext);
#endif
return false;
}
@ -269,21 +258,13 @@ bool Sdl2Application::tryCreateContext(const Configuration& configuration) {
}
Vector2i Sdl2Application::windowSize() {
#ifndef CORRADE_TARGET_EMSCRIPTEN
Vector2i size;
SDL_GetWindowSize(_window, &size.x(), &size.y());
return size;
#else
return {_glContext->w, _glContext->h};
#endif
}
void Sdl2Application::swapBuffers() {
#ifndef CORRADE_TARGET_EMSCRIPTEN
SDL_GL_SwapWindow(_window);
#else
SDL_Flip(_glContext);
#endif
}
Int Sdl2Application::swapInterval() const {
@ -310,12 +291,8 @@ bool Sdl2Application::setSwapInterval(const Int interval) {
Sdl2Application::~Sdl2Application() {
_context.reset();
#ifndef CORRADE_TARGET_EMSCRIPTEN
SDL_GL_DeleteContext(_glContext);
SDL_DestroyWindow(_window);
#else
SDL_FreeSurface(_glContext);
#endif
SDL_Quit();
}
@ -526,7 +503,7 @@ void Sdl2Application::textInputEvent(TextInputEvent&) {}
void Sdl2Application::textEditingEvent(TextEditingEvent&) {}
Sdl2Application::Configuration::Configuration():
#if !defined(CORRADE_TARGET_EMSCRIPTEN) && !defined(CORRADE_TARGET_IOS)
#ifndef CORRADE_TARGET_IOS
_title("Magnum SDL2 Application"),
#endif
#ifdef CORRADE_TARGET_EMSCRIPTEN

22
src/Magnum/Platform/Sdl2Application.h

@ -415,7 +415,6 @@ class Sdl2Application {
*/
void mainLoopIteration();
#ifndef CORRADE_TARGET_EMSCRIPTEN
/**
* @brief Underlying window handle
*
@ -423,7 +422,6 @@ class Sdl2Application {
* @note Not available in @ref CORRADE_TARGET_EMSCRIPTEN "Emscripten".
*/
SDL_Window* window() { return _window; }
#endif
protected:
/* Nobody will need to have (and delete) Sdl2Application*, thus this is
@ -726,12 +724,10 @@ class Sdl2Application {
typedef Containers::EnumSet<Flag> Flags;
CORRADE_ENUMSET_FRIEND_OPERATORS(Flags)
#ifndef CORRADE_TARGET_EMSCRIPTEN
SDL_Window* _window;
SDL_GLContext _glContext;
#ifndef CORRADE_TARGET_EMSCRIPTEN
UnsignedInt _minimalLoopPeriod;
#else
SDL_Surface* _glContext;
#endif
std::unique_ptr<Platform::Context> _context;
@ -830,12 +826,11 @@ class Sdl2Application::Configuration {
/*implicit*/ Configuration();
~Configuration();
#if !defined(CORRADE_TARGET_EMSCRIPTEN) && !defined(CORRADE_TARGET_IOS)
#ifndef CORRADE_TARGET_IOS
/**
* @brief Window title
*
* @note Not available in @ref CORRADE_TARGET_EMSCRIPTEN "Emscripten"
* and @ref CORRADE_TARGET_IOS "iOS".
* @note Not available in @ref CORRADE_TARGET_IOS "iOS".
*/
std::string title() const { return _title; }
#endif
@ -845,12 +840,13 @@ class Sdl2Application::Configuration {
* @return Reference to self (for method chaining)
*
* Default is `"Magnum SDL2 Application"`.
* @note In @ref CORRADE_TARGET_EMSCRIPTEN "Emscripten" and
* @ref CORRADE_TARGET_IOS "iOS" this function does nothing and is
* included only for compatibility. You need to set the title
* @note In @ref CORRADE_TARGET_IOS "iOS" this function does nothing and
* is included only for compatibility. You need to set the title
* separately in platform-specific configuration file.
* In @ref CORRADE_TARGET_EMSCRIPTEN "Emscripten" this title will
* be used to set `document.title`.
*/
#if !defined(CORRADE_TARGET_EMSCRIPTEN) && !defined(CORRADE_TARGET_IOS)
#ifndef CORRADE_TARGET_IOS
Configuration& setTitle(std::string title) {
_title = std::move(title);
return *this;
@ -975,7 +971,7 @@ class Sdl2Application::Configuration {
#endif
private:
#if !defined(CORRADE_TARGET_EMSCRIPTEN) && !defined(CORRADE_TARGET_IOS)
#ifndef CORRADE_TARGET_IOS
std::string _title;
#endif
Vector2i _size;

Loading…
Cancel
Save