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