]> git.lizzy.rs Git - irrlicht.git/blobdiff - source/Irrlicht/CIrrDeviceSDL.cpp
Split new GL3/GLES2 drivers
[irrlicht.git] / source / Irrlicht / CIrrDeviceSDL.cpp
index c66cfda79744947101f8de8e9728f530ef7099b7..6ebf63b975ff7cb316879b9fca6a632b15f227bb 100644 (file)
@@ -2,13 +2,13 @@
 // This file is part of the "Irrlicht Engine".\r
 // For conditions of distribution and use, see copyright notice in irrlicht.h\r
 \r
-#include "IrrCompileConfig.h"\r
 \r
 #ifdef _IRR_COMPILE_WITH_SDL_DEVICE_\r
 \r
 #include "CIrrDeviceSDL.h"\r
 #include "IEventReceiver.h"\r
-#include "irrList.h"\r
+#include "IGUIElement.h"\r
+#include "IGUIEnvironment.h"\r
 #include "os.h"\r
 #include "CTimer.h"\r
 #include "irrString.h"\r
@@ -38,14 +38,42 @@ namespace irr
        {\r
                #ifdef _IRR_COMPILE_WITH_OPENGL_\r
                IVideoDriver* createOpenGLDriver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager);\r
+               #else\r
+               static IVideoDriver* createOpenGLDriver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager)\r
+               {\r
+                       os::Printer::log("No OpenGL support compiled in.", ELL_ERROR);\r
+                       return nullptr;\r
+               }\r
+               #endif\r
+\r
+               #ifdef ENABLE_OPENGL3\r
+               IVideoDriver* createOpenGL3Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager);\r
+               #else\r
+               static IVideoDriver* createOpenGL3Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager)\r
+               {\r
+                       os::Printer::log("No OpenGL 3 support compiled in.", ELL_ERROR);\r
+                       return nullptr;\r
+               }\r
                #endif\r
 \r
                #ifdef _IRR_COMPILE_WITH_OGLES2_\r
                IVideoDriver* createOGLES2Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager);\r
+               #else\r
+               static IVideoDriver* createOGLES2Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager)\r
+               {\r
+                       os::Printer::log("No OpenGL ES 2 support compiled in.", ELL_ERROR);\r
+                       return nullptr;\r
+               }\r
                #endif\r
 \r
                #ifdef _IRR_COMPILE_WITH_WEBGL1_\r
                IVideoDriver* createWebGL1Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager);\r
+               #else\r
+               static IVideoDriver* createWebGL1Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager)\r
+               {\r
+                       os::Printer::log("No WebGL 1 support compiled in.", ELL_ERROR);\r
+                       return nullptr;\r
+               }\r
                #endif\r
        } // end namespace video\r
 \r
@@ -106,33 +134,31 @@ EM_BOOL CIrrDeviceSDL::MouseLeaveCallback(int eventType, const EmscriptenMouseEv
 }\r
 #endif\r
 \r
-bool CIrrDeviceSDL::isNoUnicodeKey(EKEY_CODE key) const\r
+\r
+bool CIrrDeviceSDL::keyIsKnownSpecial(EKEY_CODE key)\r
 {\r
        switch ( key )\r
        {\r
-               // keys which  should not be mapped to a Unicode char\r
-               case KEY_UNKNOWN:\r
-               case KEY_SHIFT:\r
-               case KEY_CONTROL:\r
-               case KEY_MENU:\r
+               // keys which are known to have safe special character interpretation\r
+               // could need changes over time (removals and additions!)\r
+               case KEY_RETURN:\r
                case KEY_PAUSE:\r
-               case KEY_CAPITAL:\r
                case KEY_ESCAPE:\r
                case KEY_PRIOR:\r
                case KEY_NEXT:\r
-               case KEY_END:\r
                case KEY_HOME:\r
+               case KEY_END:\r
                case KEY_LEFT:\r
                case KEY_UP:\r
                case KEY_RIGHT:\r
                case KEY_DOWN:\r
+               case KEY_TAB:\r
                case KEY_PRINT:\r
                case KEY_SNAPSHOT:\r
                case KEY_INSERT:\r
+               case KEY_BACK:\r
                case KEY_DELETE:\r
                case KEY_HELP:\r
-               case KEY_LWIN:\r
-               case KEY_RWIN:\r
                case KEY_APPS:\r
                case KEY_SLEEP:\r
                case KEY_F1:\r
@@ -161,26 +187,52 @@ bool CIrrDeviceSDL::isNoUnicodeKey(EKEY_CODE key) const
                case KEY_F24:\r
                case KEY_NUMLOCK:\r
                case KEY_SCROLL:\r
-               case KEY_LSHIFT:\r
-               case KEY_RSHIFT:\r
                case KEY_LCONTROL:\r
                case KEY_RCONTROL:\r
-               case KEY_LMENU:\r
-               case KEY_RMENU:\r
-               return true;\r
+                       return true;\r
 \r
-       default:\r
-               return false;\r
+               default:\r
+                       return false;\r
+       }\r
+}\r
+\r
+int CIrrDeviceSDL::findCharToPassToIrrlicht(int assumedChar, EKEY_CODE key) {\r
+       // SDL in-place ORs values with no character representation with 1<<30\r
+       // https://wiki.libsdl.org/SDL2/SDLKeycodeLookup\r
+       if (assumedChar & (1<<30))\r
+               return 0;\r
+\r
+       switch (key) {\r
+               case KEY_PRIOR:\r
+               case KEY_NEXT:\r
+               case KEY_HOME:\r
+               case KEY_END:\r
+               case KEY_LEFT:\r
+               case KEY_UP:\r
+               case KEY_RIGHT:\r
+               case KEY_DOWN:\r
+               case KEY_NUMLOCK:\r
+                       return 0;\r
+               default:\r
+                       return assumedChar;\r
        }\r
 }\r
 \r
+void CIrrDeviceSDL::resetReceiveTextInputEvents() {\r
+       gui::IGUIElement *elem = GUIEnvironment->getFocus();\r
+       if (elem && elem->acceptsIME())\r
+               SDL_StartTextInput();\r
+       else\r
+               SDL_StopTextInput();\r
+}\r
+\r
 //! constructor\r
 CIrrDeviceSDL::CIrrDeviceSDL(const SIrrlichtCreationParameters& param)\r
        : CIrrDeviceStub(param),\r
        Window((SDL_Window*)param.WindowId), SDL_Flags(0),\r
        MouseX(0), MouseY(0), MouseXRel(0), MouseYRel(0), MouseButtonStates(0),\r
        Width(param.WindowSize.Width), Height(param.WindowSize.Height),\r
-       Resizable(param.WindowResizable == 1 ? true : false), WindowMinimized(false)\r
+       Resizable(param.WindowResizable == 1 ? true : false)\r
 {\r
        #ifdef _DEBUG\r
        setDebugName("CIrrDeviceSDL");\r
@@ -188,13 +240,13 @@ CIrrDeviceSDL::CIrrDeviceSDL(const SIrrlichtCreationParameters& param)
 \r
        if ( ++SDLDeviceInstances == 1 )\r
        {\r
-               // Initialize SDL... Timer for sleep, video for the obvious, and\r
-               // noparachute prevents SDL from catching fatal errors.\r
-               if (SDL_Init( SDL_INIT_TIMER|SDL_INIT_VIDEO|\r
+               u32 flags = SDL_INIT_TIMER | SDL_INIT_EVENTS;\r
+               if (CreationParams.DriverType != video::EDT_NULL)\r
+                       flags |= SDL_INIT_VIDEO;\r
 #if defined(_IRR_COMPILE_WITH_JOYSTICK_EVENTS_)\r
-                                       SDL_INIT_JOYSTICK|\r
+               flags |= SDL_INIT_JOYSTICK;\r
 #endif\r
-                                       SDL_INIT_NOPARACHUTE ) < 0)\r
+               if (SDL_Init(flags) < 0)\r
                {\r
                        os::Printer::log( "Unable to initialize SDL!", SDL_GetError());\r
                        Close = true;\r
@@ -208,20 +260,6 @@ CIrrDeviceSDL::CIrrDeviceSDL(const SIrrlichtCreationParameters& param)
        // create keymap\r
        createKeyMap();\r
 \r
-       if ( CreationParams.Fullscreen )\r
-               SDL_Flags |= SDL_WINDOW_FULLSCREEN;\r
-       else if ( Resizable )\r
-               SDL_Flags |= SDL_WINDOW_RESIZABLE;\r
-       if (CreationParams.DriverType == video::EDT_OPENGL)\r
-       {\r
-               SDL_Flags |= SDL_WINDOW_OPENGL;\r
-               if (!CreationParams.Doublebuffer)\r
-                       SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 0);\r
-       }\r
-#ifdef _IRR_EMSCRIPTEN_PLATFORM_\r
-       SDL_Flags |= SDL_WINDOW_OPENGL;\r
-#endif //_IRR_EMSCRIPTEN_PLATFORM_\r
-\r
        // create window\r
        if (CreationParams.DriverType != video::EDT_NULL)\r
        {\r
@@ -229,6 +267,7 @@ CIrrDeviceSDL::CIrrDeviceSDL(const SIrrlichtCreationParameters& param)
                createWindow();\r
        }\r
 \r
+\r
        SDL_VERSION(&Info.version);\r
 \r
 #ifndef _IRR_EMSCRIPTEN_PLATFORM_\r
@@ -310,6 +349,16 @@ void CIrrDeviceSDL::logAttributes()
 \r
 bool CIrrDeviceSDL::createWindow()\r
 {\r
+       if (CreationParams.Fullscreen) {\r
+               SDL_Flags |= SDL_WINDOW_FULLSCREEN;\r
+       } else  {\r
+               if (Resizable)\r
+                       SDL_Flags |= SDL_WINDOW_RESIZABLE;\r
+               if (CreationParams.WindowMaximized)\r
+                       SDL_Flags |= SDL_WINDOW_MAXIMIZED;\r
+       }\r
+       SDL_Flags |= SDL_WINDOW_OPENGL;\r
+\r
 #ifdef _IRR_EMSCRIPTEN_PLATFORM_\r
        if ( Width != 0 || Height != 0 )\r
                emscripten_set_canvas_size( Width, Height);\r
@@ -339,7 +388,7 @@ bool CIrrDeviceSDL::createWindow()
        {\r
                SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0);\r
                SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0);\r
-       }       \r
+       }\r
 \r
        SDL_CreateWindowAndRenderer(0, 0, SDL_Flags, &Window, &Renderer); // 0,0 will use the canvas size\r
 \r
@@ -356,54 +405,73 @@ bool CIrrDeviceSDL::createWindow()
        if ( Close )\r
                return false;\r
 \r
-       if (CreationParams.DriverType == video::EDT_OPENGL) {\r
-               if (CreationParams.Bits == 16) {\r
-                       SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 4);\r
-                       SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 4);\r
-                       SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 4);\r
-                       SDL_GL_SetAttribute(\r
-                                       SDL_GL_ALPHA_SIZE, CreationParams.WithAlphaChannel ? 1 : 0);\r
-               } else {\r
-                       SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);\r
-                       SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);\r
-                       SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);\r
-                       SDL_GL_SetAttribute(\r
-                                       SDL_GL_ALPHA_SIZE, CreationParams.WithAlphaChannel ? 8 : 0);\r
-               }\r
-               SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, CreationParams.ZBufferBits);\r
-               if (CreationParams.Doublebuffer)\r
-                       SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);\r
-               SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, CreationParams.Stencilbuffer ? 8 : 0);\r
-               if (CreationParams.Stereobuffer)\r
-                       SDL_GL_SetAttribute(SDL_GL_STEREO, 1);\r
-               if (CreationParams.AntiAlias > 1) {\r
-                       SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);\r
+       switch (CreationParams.DriverType) {\r
+               case video::EDT_OPENGL:\r
+                       SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);\r
+                       SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);\r
+                       break;\r
+               case video::EDT_OPENGL3:\r
+                       SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);\r
+                       SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);\r
+                       SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY);\r
+                       break;\r
+               case video::EDT_OGLES1:\r
+                       SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1);\r
+                       SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);\r
+                       SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);\r
+                       break;\r
+               case video::EDT_OGLES2:\r
+               case video::EDT_WEBGL1:\r
+                       SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);\r
+                       SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);\r
+                       SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);\r
+                       break;\r
+               default:;\r
+       }\r
+\r
+#ifdef _DEBUG\r
+       SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG | SDL_GL_CONTEXT_ROBUST_ACCESS_FLAG);\r
+#endif\r
+\r
+       if (CreationParams.Bits == 16) {\r
+               SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);\r
+               SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);\r
+               SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);\r
+               SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, CreationParams.WithAlphaChannel ? 1 : 0);\r
+       } else {\r
+               SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);\r
+               SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);\r
+               SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);\r
+               SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, CreationParams.WithAlphaChannel ? 8 : 0);\r
+       }\r
+       SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, CreationParams.ZBufferBits);\r
+       SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, CreationParams.Doublebuffer);\r
+       SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, CreationParams.Stencilbuffer ? 8 : 0);\r
+       SDL_GL_SetAttribute(SDL_GL_STEREO, CreationParams.Stereobuffer);\r
+       if (CreationParams.AntiAlias > 1) {\r
+               SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);\r
+               SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, CreationParams.AntiAlias);\r
+       }\r
+       if (!Window)\r
+               Window = SDL_CreateWindow("", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, Width, Height, SDL_Flags);\r
+       if (!Window) {\r
+               os::Printer::log("Could not create window...", SDL_GetError(), ELL_WARNING);\r
+       }\r
+       if (!Window && CreationParams.AntiAlias > 1) {\r
+               while (--CreationParams.AntiAlias > 1) {\r
                        SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, CreationParams.AntiAlias);\r
-               }\r
-               if (!Window)\r
                        Window = SDL_CreateWindow("", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, Width, Height, SDL_Flags);\r
-               if (!Window && CreationParams.AntiAlias > 1) {\r
-                       while (--CreationParams.AntiAlias > 1) {\r
-                               SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, CreationParams.AntiAlias);\r
-                               Window = SDL_CreateWindow("", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, Width, Height, SDL_Flags);\r
-                               if (Window)\r
-                                       break;\r
-                       }\r
-                       if (!Window) {\r
-                               SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0);\r
-                               SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0);\r
-                               Window = SDL_CreateWindow("", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, Width, Height, SDL_Flags);\r
-                               if (Window)\r
-                                       os::Printer::log("AntiAliasing disabled due to lack of support!");\r
-                       }\r
+                       if (Window)\r
+                               break;\r
                }\r
-\r
-               if (Window)\r
-               {\r
-                       Context = SDL_GL_CreateContext(Window);\r
+               if (!Window) {\r
+                       SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0);\r
+                       SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0);\r
+                       Window = SDL_CreateWindow("", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, Width, Height, SDL_Flags);\r
+                       if (Window)\r
+                               os::Printer::log("AntiAliasing disabled due to lack of support!", ELL_WARNING);\r
                }\r
-       } else if (!Window)\r
-               Window = SDL_CreateWindow("", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, Width, Height, SDL_Flags);\r
+       }\r
 \r
        if ( !Window && CreationParams.Doublebuffer)\r
        {\r
@@ -414,7 +482,14 @@ bool CIrrDeviceSDL::createWindow()
        }\r
        if ( !Window )\r
        {\r
-               os::Printer::log( "Could not initialize display!" );\r
+               os::Printer::log("Could not initialize display", SDL_GetError(), ELL_ERROR);\r
+               return false;\r
+       }\r
+\r
+       Context = SDL_GL_CreateContext(Window);\r
+       if (!Context) {\r
+               os::Printer::log("Could not initialize context", SDL_GetError(), ELL_ERROR);\r
+               SDL_DestroyWindow(Window);\r
                return false;\r
        }\r
 \r
@@ -426,95 +501,22 @@ bool CIrrDeviceSDL::createWindow()
 //! create the driver\r
 void CIrrDeviceSDL::createDriver()\r
 {\r
-       switch(CreationParams.DriverType)\r
-       {\r
-       case video::DEPRECATED_EDT_DIRECT3D8_NO_LONGER_EXISTS:\r
-               os::Printer::log("DIRECT3D8 Driver is no longer supported in Irrlicht. Try another one.", ELL_ERROR);\r
-               break;\r
-\r
-       case video::EDT_DIRECT3D9:\r
-               #ifdef _IRR_COMPILE_WITH_DIRECT3D_9_\r
-               os::Printer::log("SDL device does not support DIRECT3D9 driver. Try another one.", ELL_ERROR);\r
-               #else\r
-               os::Printer::log("DIRECT3D9 Driver was not compiled into this dll. Try another one.", ELL_ERROR);\r
-               #endif // _IRR_COMPILE_WITH_DIRECT3D_9_\r
-\r
-               break;\r
-\r
-       case video::EDT_SOFTWARE:\r
-               #ifdef _IRR_COMPILE_WITH_SOFTWARE_\r
-               VideoDriver = video::createSoftwareDriver(CreationParams.WindowSize, CreationParams.Fullscreen, FileSystem, this);\r
-               #else\r
-               os::Printer::log("No Software driver support compiled in.", ELL_ERROR);\r
-               #endif\r
-               break;\r
-\r
-       case video::EDT_BURNINGSVIDEO:\r
-               #ifdef _IRR_COMPILE_WITH_BURNINGSVIDEO_\r
-               VideoDriver = video::createBurningVideoDriver(CreationParams, FileSystem, this);\r
-               #else\r
-               os::Printer::log("Burning's video driver was not compiled in.", ELL_ERROR);\r
-               #endif\r
-               break;\r
-\r
-       case video::EDT_OPENGL:\r
-               #ifdef _IRR_COMPILE_WITH_OPENGL_\r
-               ContextManager = new video::CSDLManager(this);\r
-               VideoDriver = video::createOpenGLDriver(CreationParams, FileSystem, ContextManager);\r
-               #else\r
-               os::Printer::log("No OpenGL support compiled in.", ELL_ERROR);\r
-               #endif\r
-               break;\r
-\r
-       case video::EDT_OGLES2:\r
-#if defined(_IRR_COMPILE_WITH_OGLES2_) && defined(_IRR_EMSCRIPTEN_PLATFORM_)\r
-               {\r
-                       video::SExposedVideoData data;\r
-\r
-                       ContextManager = new video::CEGLManager();\r
-                       ContextManager->initialize(CreationParams, data);\r
-\r
-                       VideoDriver = video::createOGLES2Driver(CreationParams, FileSystem, ContextManager);\r
-               }\r
-#else\r
-               os::Printer::log("No OpenGL-ES2 support compiled in.", ELL_ERROR);\r
-#endif\r
-               break;\r
-\r
-       case video::EDT_WEBGL1:\r
-#if defined(_IRR_COMPILE_WITH_WEBGL1_) && defined(_IRR_EMSCRIPTEN_PLATFORM_)\r
-               {\r
-                       video::SExposedVideoData data;\r
-\r
-                       ContextManager = new video::CEGLManager();\r
-                       ContextManager->initialize(CreationParams, data);\r
-\r
-                       VideoDriver = video::createWebGL1Driver(CreationParams, FileSystem, ContextManager);\r
-               }\r
-#else\r
-               os::Printer::log("No WebGL1 support compiled in.", ELL_ERROR);\r
-#endif\r
-               break;\r
-\r
-       case video::EDT_NULL:\r
+       if (CreationParams.DriverType == video::EDT_NULL) {\r
                VideoDriver = video::createNullDriver(FileSystem, CreationParams.WindowSize);\r
-               break;\r
-\r
-       default:\r
-               os::Printer::log("Unable to create video driver of unknown type.", ELL_ERROR);\r
-               break;\r
+               return;\r
        }\r
 \r
-       // In case we got the size from the canvas\r
-       if ( VideoDriver && CreationParams.WindowSize.Width == 0 && CreationParams.WindowSize.Height == 0 && Width > 0 && Height > 0 )\r
+       ContextManager = new video::CSDLManager(this);\r
+       switch(CreationParams.DriverType)\r
        {\r
-#ifdef _IRR_EMSCRIPTEN_PLATFORM_\r
-               SDL_CreateWindowAndRenderer(Width, Height, SDL_Flags, &Window, &Renderer);\r
-#else //_IRR_EMSCRIPTEN_PLATFORM_\r
-               Window = SDL_CreateWindow("", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, Width, Height, SDL_Flags);\r
-#endif //_IRR_EMSCRIPTEN_PLATFOR\r
-               VideoDriver->OnResize(core::dimension2d<u32>(Width, Height));\r
+       case video::EDT_OPENGL: VideoDriver = video::createOpenGLDriver(CreationParams, FileSystem, ContextManager); break;\r
+       case video::EDT_OPENGL3: VideoDriver = video::createOpenGL3Driver(CreationParams, FileSystem, ContextManager); break;\r
+       case video::EDT_OGLES2: VideoDriver = video::createOGLES2Driver(CreationParams, FileSystem, ContextManager); break;\r
+       case video::EDT_WEBGL1: VideoDriver = video::createWebGL1Driver(CreationParams, FileSystem, ContextManager); break;\r
+       default:;\r
        }\r
+       if (!VideoDriver)\r
+               os::Printer::log("Could not create video driver", ELL_ERROR);\r
 }\r
 \r
 \r
@@ -532,7 +534,9 @@ bool CIrrDeviceSDL::run()
 \r
                switch ( SDL_event.type )\r
                {\r
-               case SDL_MOUSEMOTION:\r
+               case SDL_MOUSEMOTION: {\r
+                       SDL_Keymod keymod = SDL_GetModState();\r
+\r
                        irrevent.EventType = irr::EET_MOUSE_INPUT_EVENT;\r
                        irrevent.MouseInput.Event = irr::EMIE_MOUSE_MOVED;\r
                        MouseX = irrevent.MouseInput.X = SDL_event.motion.x;\r
@@ -540,20 +544,35 @@ bool CIrrDeviceSDL::run()
                        MouseXRel = SDL_event.motion.xrel;\r
                        MouseYRel = SDL_event.motion.yrel;\r
                        irrevent.MouseInput.ButtonStates = MouseButtonStates;\r
+                       irrevent.MouseInput.Shift = (keymod & KMOD_SHIFT) != 0;\r
+                       irrevent.MouseInput.Control = (keymod & KMOD_CTRL) != 0;\r
 \r
                        postEventFromUser(irrevent);\r
                        break;\r
-               case SDL_MOUSEWHEEL:\r
+               }\r
+               case SDL_MOUSEWHEEL: {\r
+                       SDL_Keymod keymod = SDL_GetModState();\r
+\r
                        irrevent.EventType = irr::EET_MOUSE_INPUT_EVENT;\r
                        irrevent.MouseInput.Event = irr::EMIE_MOUSE_WHEEL;\r
                        irrevent.MouseInput.Wheel = static_cast<float>(SDL_event.wheel.y);\r
+                       irrevent.MouseInput.Shift = (keymod & KMOD_SHIFT) != 0;\r
+                       irrevent.MouseInput.Control = (keymod & KMOD_CTRL) != 0;\r
+                       irrevent.MouseInput.X = MouseX;\r
+                       irrevent.MouseInput.Y = MouseY;\r
+\r
                        postEventFromUser(irrevent);\r
                        break;\r
+               }\r
                case SDL_MOUSEBUTTONDOWN:\r
-               case SDL_MOUSEBUTTONUP:\r
+               case SDL_MOUSEBUTTONUP: {\r
+                       SDL_Keymod keymod = SDL_GetModState();\r
+\r
                        irrevent.EventType = irr::EET_MOUSE_INPUT_EVENT;\r
                        irrevent.MouseInput.X = SDL_event.button.x;\r
                        irrevent.MouseInput.Y = SDL_event.button.y;\r
+                       irrevent.MouseInput.Shift = (keymod & KMOD_SHIFT) != 0;\r
+                       irrevent.MouseInput.Control = (keymod & KMOD_CTRL) != 0;\r
 \r
                        irrevent.MouseInput.Event = irr::EMIE_MOUSE_MOVED;\r
 \r
@@ -648,6 +667,18 @@ bool CIrrDeviceSDL::run()
                                }\r
                        }\r
                        break;\r
+               }\r
+\r
+               case SDL_TEXTINPUT:\r
+                       {\r
+                               irrevent.EventType = irr::EET_STRING_INPUT_EVENT;\r
+                               irrevent.StringInput.Str = new core::stringw();\r
+                               irr::core::multibyteToWString(*irrevent.StringInput.Str, SDL_event.text.text);\r
+                               postEventFromUser(irrevent);\r
+                               delete irrevent.StringInput.Str;\r
+                               irrevent.StringInput.Str = NULL;\r
+                       }\r
+                       break;\r
 \r
                case SDL_KEYDOWN:\r
                case SDL_KEYUP:\r
@@ -662,6 +693,10 @@ bool CIrrDeviceSDL::run()
                                else\r
                                        key = (EKEY_CODE)KeyMap[idx].Win32Key;\r
 \r
+                               // Make sure to only input special characters if something is in focus, as SDL_TEXTINPUT handles normal unicode already\r
+                               if (SDL_IsTextInputActive() && !keyIsKnownSpecial(key) && (SDL_event.key.keysym.mod & KMOD_CTRL) == 0)\r
+                                       break;\r
+\r
 #ifdef _IRR_WINDOWS_API_\r
                                // handle alt+f4 in Windows, because SDL seems not to\r
                                if ( (SDL_event.key.keysym.mod & KMOD_LALT) && key == KEY_F4)\r
@@ -671,25 +706,11 @@ bool CIrrDeviceSDL::run()
                                }\r
 #endif\r
                                irrevent.EventType = irr::EET_KEY_INPUT_EVENT;\r
-\r
-                               if (isNoUnicodeKey(key))\r
-                                       irrevent.KeyInput.Char = 0;\r
-                               else\r
-                                       irrevent.KeyInput.Char = SDL_event.key.keysym.sym;\r
-\r
                                irrevent.KeyInput.Key = key;\r
                                irrevent.KeyInput.PressedDown = (SDL_event.type == SDL_KEYDOWN);\r
                                irrevent.KeyInput.Shift = (SDL_event.key.keysym.mod & KMOD_SHIFT) != 0;\r
                                irrevent.KeyInput.Control = (SDL_event.key.keysym.mod & KMOD_CTRL ) != 0;\r
-\r
-                               // SDL2 no longer provides unicode character in the key event so we ensure the character is in the correct case\r
-                               // TODO: Unicode input doesn't work like this, should probably use SDL_TextInputEvent\r
-                               bool convertCharToUppercase =\r
-                                       irrevent.KeyInput.Shift != !!(SDL_event.key.keysym.mod & KMOD_CAPS);\r
-\r
-                               if (convertCharToUppercase)\r
-                                       irrevent.KeyInput.Char = irr::core::locale_upper(irrevent.KeyInput.Char);\r
-\r
+                               irrevent.KeyInput.Char = findCharToPassToIrrlicht(mp.SDLKey, key);\r
                                postEventFromUser(irrevent);\r
                        }\r
                        break;\r
@@ -701,12 +722,6 @@ bool CIrrDeviceSDL::run()
                case SDL_WINDOWEVENT:\r
                        switch (SDL_event.window.event)\r
                        {\r
-                       case SDL_WINDOWEVENT_MAXIMIZED:\r
-                               WindowMinimized = true;\r
-                               break;\r
-                       case SDL_WINDOWEVENT_RESTORED:\r
-                               WindowMinimized = false;\r
-                               break;\r
                        case SDL_WINDOWEVENT_RESIZED:\r
                                if ((SDL_event.window.data1 != (int)Width) || (SDL_event.window.data2 != (int)Height))\r
                                {\r
@@ -729,7 +744,7 @@ bool CIrrDeviceSDL::run()
                default:\r
                        break;\r
                } // end switch\r
-\r
+       resetReceiveTextInputEvents();\r
        } // end while\r
 \r
 #if defined(_IRR_COMPILE_WITH_JOYSTICK_EVENTS_)\r
@@ -895,90 +910,6 @@ void CIrrDeviceSDL::setWindowCaption(const wchar_t* text)
 }\r
 \r
 \r
-//! presents a surface in the client area\r
-bool CIrrDeviceSDL::present(video::IImage* surface, void* windowId, core::rect<s32>* srcClip)\r
-{\r
-#ifdef _IRR_EMSCRIPTEN_PLATFORM_\r
-       return true;\r
-#else // !_IRR_EMSCRIPTEN_PLATFORM_\r
-       SDL_Surface *sdlSurface = SDL_CreateRGBSurfaceFrom(\r
-                       surface->getData(), surface->getDimension().Width, surface->getDimension().Height,\r
-                       surface->getBitsPerPixel(), surface->getPitch(),\r
-                       surface->getRedMask(), surface->getGreenMask(), surface->getBlueMask(), surface->getAlphaMask());\r
-       if (!sdlSurface)\r
-               return false;\r
-       SDL_SetSurfaceAlphaMod(sdlSurface, 0);\r
-       SDL_SetColorKey(sdlSurface, 0, 0);\r
-       sdlSurface->format->BitsPerPixel=surface->getBitsPerPixel();\r
-       sdlSurface->format->BytesPerPixel=surface->getBytesPerPixel();\r
-       if ((surface->getColorFormat()==video::ECF_R8G8B8) ||\r
-                       (surface->getColorFormat()==video::ECF_A8R8G8B8))\r
-       {\r
-               sdlSurface->format->Rloss=0;\r
-               sdlSurface->format->Gloss=0;\r
-               sdlSurface->format->Bloss=0;\r
-               sdlSurface->format->Rshift=16;\r
-               sdlSurface->format->Gshift=8;\r
-               sdlSurface->format->Bshift=0;\r
-               if (surface->getColorFormat()==video::ECF_R8G8B8)\r
-               {\r
-                       sdlSurface->format->Aloss=8;\r
-                       sdlSurface->format->Ashift=32;\r
-               }\r
-               else\r
-               {\r
-                       sdlSurface->format->Aloss=0;\r
-                       sdlSurface->format->Ashift=24;\r
-               }\r
-       }\r
-       else if (surface->getColorFormat()==video::ECF_R5G6B5)\r
-       {\r
-               sdlSurface->format->Rloss=3;\r
-               sdlSurface->format->Gloss=2;\r
-               sdlSurface->format->Bloss=3;\r
-               sdlSurface->format->Aloss=8;\r
-               sdlSurface->format->Rshift=11;\r
-               sdlSurface->format->Gshift=5;\r
-               sdlSurface->format->Bshift=0;\r
-               sdlSurface->format->Ashift=16;\r
-       }\r
-       else if (surface->getColorFormat()==video::ECF_A1R5G5B5)\r
-       {\r
-               sdlSurface->format->Rloss=3;\r
-               sdlSurface->format->Gloss=3;\r
-               sdlSurface->format->Bloss=3;\r
-               sdlSurface->format->Aloss=7;\r
-               sdlSurface->format->Rshift=10;\r
-               sdlSurface->format->Gshift=5;\r
-               sdlSurface->format->Bshift=0;\r
-               sdlSurface->format->Ashift=15;\r
-       }\r
-\r
-       SDL_Surface* scr = (SDL_Surface* )windowId;\r
-       if (!scr)\r
-               scr = SDL_GetWindowSurface(Window);\r
-       if (scr)\r
-       {\r
-               if (srcClip)\r
-               {\r
-                       SDL_Rect sdlsrcClip;\r
-                       sdlsrcClip.x = srcClip->UpperLeftCorner.X;\r
-                       sdlsrcClip.y = srcClip->UpperLeftCorner.Y;\r
-                       sdlsrcClip.w = srcClip->getWidth();\r
-                       sdlsrcClip.h = srcClip->getHeight();\r
-                       SDL_BlitSurface(sdlSurface, &sdlsrcClip, scr, NULL);\r
-               }\r
-               else\r
-                       SDL_BlitSurface(sdlSurface, NULL, scr, NULL);\r
-               SDL_RenderPresent(SDL_GetRenderer(Window));\r
-       }\r
-\r
-       SDL_FreeSurface(sdlSurface);\r
-       return (scr != 0);\r
-#endif // !_IRR_EMSCRIPTEN_PLATFORM_\r
-}\r
-\r
-\r
 //! notifies the device that it should close itself\r
 void CIrrDeviceSDL::closeDevice()\r
 {\r
@@ -993,7 +924,7 @@ void CIrrDeviceSDL::setResizable(bool resize)
        os::Printer::log("Resizable not available on the web." , ELL_WARNING);\r
        return;\r
 #else // !_IRR_EMSCRIPTEN_PLATFORM_\r
-       if (resize != Resizable) { \r
+       if (resize != Resizable) {\r
                if (resize)\r
                        SDL_Flags |= SDL_WINDOW_RESIZABLE;\r
                else\r
@@ -1011,16 +942,16 @@ void CIrrDeviceSDL::setResizable(bool resize)
 //! Minimizes window if possible\r
 void CIrrDeviceSDL::minimizeWindow()\r
 {\r
-       if (Window) {\r
+       if (Window)\r
                SDL_MinimizeWindow(Window);\r
-       }\r
 }\r
 \r
 \r
 //! Maximize window\r
 void CIrrDeviceSDL::maximizeWindow()\r
 {\r
-       // do nothing\r
+       if (Window)\r
+               SDL_MaximizeWindow(Window);\r
 }\r
 \r
 //! Get the position of this window on screen\r
@@ -1033,7 +964,13 @@ core::position2di CIrrDeviceSDL::getWindowPosition()
 //! Restore original window size\r
 void CIrrDeviceSDL::restoreWindow()\r
 {\r
-       // do nothing\r
+       if (Window)\r
+               SDL_RestoreWindow(Window);\r
+}\r
+\r
+bool CIrrDeviceSDL::isWindowMaximized() const\r
+{\r
+       return Window && (SDL_GetWindowFlags(Window) & SDL_WINDOW_MAXIMIZED) != 0;\r
 }\r
 \r
 bool CIrrDeviceSDL::isFullscreen() const\r
@@ -1068,36 +1005,17 @@ bool CIrrDeviceSDL::isWindowActive() const
 //! returns if window has focus.\r
 bool CIrrDeviceSDL::isWindowFocused() const\r
 {\r
-       return SDL_GetWindowFlags(Window) & SDL_WINDOW_INPUT_FOCUS;\r
+       return Window && (SDL_GetWindowFlags(Window) & SDL_WINDOW_INPUT_FOCUS) != 0;\r
 }\r
 \r
 \r
 //! returns if window is minimized.\r
 bool CIrrDeviceSDL::isWindowMinimized() const\r
 {\r
-       return WindowMinimized;\r
+       return Window && (SDL_GetWindowFlags(Window) & SDL_WINDOW_MINIMIZED) != 0;\r
 }\r
 \r
 \r
-//! Set the current Gamma Value for the Display\r
-bool CIrrDeviceSDL::setGammaRamp( f32 red, f32 green, f32 blue, f32 brightness, f32 contrast )\r
-{\r
-       /*\r
-       // todo: Gamma in SDL takes ints, what does Irrlicht use?\r
-       return (SDL_SetGamma(red, green, blue) != -1);\r
-       */\r
-       return false;\r
-}\r
-\r
-//! Get the current Gamma Value for the Display\r
-bool CIrrDeviceSDL::getGammaRamp( f32 &red, f32 &green, f32 &blue, f32 &brightness, f32 &contrast )\r
-{\r
-/*     brightness = 0.f;\r
-       contrast = 0.f;\r
-       return (SDL_GetGamma(&red, &green, &blue) != -1);*/\r
-       return false;\r
-}\r
-\r
 //! returns color format of the window.\r
 video::ECOLOR_FORMAT CIrrDeviceSDL::getColorFormat() const\r
 {\r
@@ -1265,6 +1183,25 @@ void CIrrDeviceSDL::createKeyMap()
        KeyMap.sort();\r
 }\r
 \r
+void CIrrDeviceSDL::CCursorControl::initCursors()\r
+{\r
+       Cursors.reserve(gui::ECI_COUNT);\r
+\r
+       Cursors.emplace_back(SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW));     // ECI_NORMAL\r
+       Cursors.emplace_back(SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_CROSSHAIR)); // ECI_CROSS\r
+       Cursors.emplace_back(SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_HAND));      // ECI_HAND\r
+       Cursors.emplace_back(nullptr);                                             // ECI_HELP\r
+       Cursors.emplace_back(SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_IBEAM));     // ECI_IBEAM\r
+       Cursors.emplace_back(SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_NO));        // ECI_NO\r
+       Cursors.emplace_back(SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_WAIT));      // ECI_WAIT\r
+       Cursors.emplace_back(SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZEALL));   // ECI_SIZEALL\r
+       Cursors.emplace_back(SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZENESW));  // ECI_SIZENESW\r
+       Cursors.emplace_back(SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZENWSE));  // ECI_SIZENWSE\r
+       Cursors.emplace_back(SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZENS));    // ECI_SIZENS\r
+       Cursors.emplace_back(SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZEWE));    // ECI_SIZEWE\r
+       Cursors.emplace_back(nullptr);                                             // ECI_UP\r
+}\r
+\r
 } // end namespace irr\r
 \r
 #endif // _IRR_COMPILE_WITH_SDL_DEVICE_\r