Advertisement
FloatyBoaty

Irrlicht SDL2 upgrade diff

Sep 19th, 2014
1,017
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 159.19 KB | None | 0 0
  1. Index: Android.mk
  2. ===================================================================
  3. --- Android.mk  (revision 0)
  4. +++ Android.mk  (working copy)
  5. @@ -0,0 +1,145 @@
  6. +LOCAL_PATH := $(call my-dir)
  7. +
  8. +SDL_PATH := ../SDL
  9. +
  10. +###########################
  11. +#
  12. +# Irrlicht shared library
  13. +#
  14. +###########################
  15. +
  16. +include $(CLEAR_VARS)
  17. +
  18. +LOCAL_MODULE := Irrlicht
  19. +
  20. +LOCAL_CFLAGS := -D_IRR_COMPILE_WITH_SDL2_DEVICE_ -DNO_IRR_COMPILE_WITH_OPENGL_
  21. +
  22. +LOCAL_CFLAGS += -Wall -pipe -fno-exceptions -fno-rtti -fstrict-aliasing -fexpensive-optimizations -O3
  23. +
  24. +SRC_PATH := $(LOCAL_PATH)/source/Irrlicht
  25. +
  26. +LOCAL_C_INCLUDES := $(LOCAL_PATH)/include $(LOCAL_PATH)/$(SDL_PATH)/include $(SRC_PATH)
  27. +
  28. +LOCAL_EXPORT_C_INCLUDES := $(LOCAL_C_INCLUDES)
  29. +
  30. +LOCAL_SRC_FILES :=     $(subst $(LOCAL_PATH)/,, \
  31. +                   $(wildcard $(SRC_PATH)/Android/*.cpp) \
  32. +                   $(SRC_PATH)/aesGladman/aescrypt.cpp \
  33. +                   $(SRC_PATH)/aesGladman/aeskey.cpp \
  34. +                   $(SRC_PATH)/aesGladman/aestab.cpp \
  35. +                   $(SRC_PATH)/aesGladman/fileenc.cpp \
  36. +                   $(SRC_PATH)/aesGladman/hmac.cpp \
  37. +                   $(SRC_PATH)/aesGladman/prng.cpp \
  38. +                   $(SRC_PATH)/aesGladman/pwd2key.cpp \
  39. +                   $(SRC_PATH)/aesGladman/sha1.cpp \
  40. +                   $(SRC_PATH)/aesGladman/sha2.cpp \
  41. +                   $(wildcard $(SRC_PATH)/*.cpp) \
  42. +                   $(SRC_PATH)/bzip2/blocksort.c \
  43. +                   $(SRC_PATH)/bzip2/bzcompress.c \
  44. +                   $(SRC_PATH)/bzip2/bzlib.c \
  45. +                   $(SRC_PATH)/bzip2/crctable.c \
  46. +                   $(SRC_PATH)/bzip2/decompress.c \
  47. +                   $(SRC_PATH)/bzip2/huffman.c \
  48. +                   $(SRC_PATH)/bzip2/randtable.c \
  49. +                   $(SRC_PATH)/jpeglib/jaricom.c \
  50. +                   $(SRC_PATH)/jpeglib/jcapimin.c \
  51. +                   $(SRC_PATH)/jpeglib/jcapistd.c \
  52. +                   $(SRC_PATH)/jpeglib/jcarith.c \
  53. +                   $(SRC_PATH)/jpeglib/jccoefct.c \
  54. +                   $(SRC_PATH)/jpeglib/jccolor.c \
  55. +                   $(SRC_PATH)/jpeglib/jcdctmgr.c \
  56. +                   $(SRC_PATH)/jpeglib/jchuff.c \
  57. +                   $(SRC_PATH)/jpeglib/jcinit.c \
  58. +                   $(SRC_PATH)/jpeglib/jcmainct.c \
  59. +                   $(SRC_PATH)/jpeglib/jcmarker.c \
  60. +                   $(SRC_PATH)/jpeglib/jcmaster.c \
  61. +                   $(SRC_PATH)/jpeglib/jcomapi.c \
  62. +                   $(SRC_PATH)/jpeglib/jcparam.c \
  63. +                   $(SRC_PATH)/jpeglib/jcprepct.c \
  64. +                   $(SRC_PATH)/jpeglib/jcsample.c \
  65. +                   $(SRC_PATH)/jpeglib/jctrans.c \
  66. +                   $(SRC_PATH)/jpeglib/jdapimin.c \
  67. +                   $(SRC_PATH)/jpeglib/jdapistd.c \
  68. +                   $(SRC_PATH)/jpeglib/jdarith.c \
  69. +                   $(SRC_PATH)/jpeglib/jdatadst.c \
  70. +                   $(SRC_PATH)/jpeglib/jdatasrc.c \
  71. +                   $(SRC_PATH)/jpeglib/jdcoefct.c \
  72. +                   $(SRC_PATH)/jpeglib/jdcolor.c \
  73. +                   $(SRC_PATH)/jpeglib/jddctmgr.c \
  74. +                   $(SRC_PATH)/jpeglib/jdhuff.c \
  75. +                   $(SRC_PATH)/jpeglib/jdinput.c \
  76. +                   $(SRC_PATH)/jpeglib/jdmainct.c \
  77. +                   $(SRC_PATH)/jpeglib/jdmarker.c \
  78. +                   $(SRC_PATH)/jpeglib/jdmaster.c \
  79. +                   $(SRC_PATH)/jpeglib/jdmerge.c \
  80. +                   $(SRC_PATH)/jpeglib/jdpostct.c \
  81. +                   $(SRC_PATH)/jpeglib/jdsample.c \
  82. +                   $(SRC_PATH)/jpeglib/jdtrans.c \
  83. +                   $(SRC_PATH)/jpeglib/jerror.c \
  84. +                   $(SRC_PATH)/jpeglib/jfdctflt.c \
  85. +                   $(SRC_PATH)/jpeglib/jfdctfst.c \
  86. +                   $(SRC_PATH)/jpeglib/jfdctint.c \
  87. +                   $(SRC_PATH)/jpeglib/jidctflt.c \
  88. +                   $(SRC_PATH)/jpeglib/jidctfst.c \
  89. +                   $(SRC_PATH)/jpeglib/jidctint.c \
  90. +                   $(SRC_PATH)/jpeglib/jmemmgr.c \
  91. +                   $(SRC_PATH)/jpeglib/jmemnobs.c \
  92. +                   $(SRC_PATH)/jpeglib/jquant1.c \
  93. +                   $(SRC_PATH)/jpeglib/jquant2.c \
  94. +                   $(SRC_PATH)/jpeglib/jutils.c \
  95. +                   $(SRC_PATH)/libpng/png.c \
  96. +                   $(SRC_PATH)/libpng/pngerror.c \
  97. +                   $(SRC_PATH)/libpng/pngget.c \
  98. +                   $(SRC_PATH)/libpng/pngmem.c \
  99. +                   $(SRC_PATH)/libpng/pngpread.c \
  100. +                   $(SRC_PATH)/libpng/pngread.c \
  101. +                   $(SRC_PATH)/libpng/pngrio.c \
  102. +                   $(SRC_PATH)/libpng/pngrtran.c \
  103. +                   $(SRC_PATH)/libpng/pngrutil.c \
  104. +                   $(SRC_PATH)/libpng/pngset.c \
  105. +                   $(SRC_PATH)/libpng/pngtrans.c \
  106. +                   $(SRC_PATH)/libpng/pngwio.c \
  107. +                   $(SRC_PATH)/libpng/pngwrite.c \
  108. +                   $(SRC_PATH)/libpng/pngwtran.c \
  109. +                   $(SRC_PATH)/libpng/pngwutil.c \
  110. +                   $(SRC_PATH)/lzma/LzmaDec.c \
  111. +                   $(SRC_PATH)/zlib/adler32.c \
  112. +                   $(SRC_PATH)/zlib/crc32.c \
  113. +                   $(SRC_PATH)/zlib/gzclose.c \
  114. +                   $(SRC_PATH)/zlib/gzread.c \
  115. +                   $(SRC_PATH)/zlib/infback.c \
  116. +                   $(SRC_PATH)/zlib/inflate.c \
  117. +                   $(SRC_PATH)/zlib/trees.c \
  118. +                   $(SRC_PATH)/zlib/zutil.c \
  119. +                   $(SRC_PATH)/zlib/compress.c \
  120. +                   $(SRC_PATH)/zlib/deflate.c \
  121. +                   $(SRC_PATH)/zlib/gzlib.c \
  122. +                   $(SRC_PATH)/zlib/gzwrite.c \
  123. +                   $(SRC_PATH)/zlib/inffast.c \
  124. +                   $(SRC_PATH)/zlib/inftrees.c \
  125. +                   $(SRC_PATH)/zlib/uncompr.c)
  126. +
  127. +LOCAL_SHARED_LIBRARIES := SDL2
  128. +
  129. +LOCAL_LDLIBS := -lEGL -llog -lGLESv1_CM -lGLESv2 -lz -landroid
  130. +
  131. +LOCAL_STATIC_LIBRARIES := android_native_app_glue
  132. +
  133. +include $(BUILD_SHARED_LIBRARY)
  134. +
  135. +###########################
  136. +#
  137. +# Irrlicht static library
  138. +#
  139. +###########################
  140. +
  141. +#LOCAL_MODULE := Irrlicht_static
  142. +
  143. +#LOCAL_MODULE_FILENAME := Irrlicht
  144. +
  145. +#LOCAL_LDLIBS :=
  146. +#LOCAL_EXPORT_LDLIBS := -lEGL -llog -lGLESv1_CM -lGLESv2 -lz -landroid -lSDL2
  147. +
  148. +#include $(BUILD_STATIC_LIBRARY)
  149. +
  150. +$(call import-module,android/native_app_glue)
  151. Index: changes.txt
  152. ===================================================================
  153. --- changes.txt (revision 4940)
  154. +++ changes.txt (working copy)
  155. @@ -3,6 +3,7 @@
  156.  
  157.  - Merge material changes for COGLES1MaterialRenderer_LIGHTMAP and COpenGLMaterialRenderer_TRANSPARENT_ALPHA_CHANNEL which had been done in OGL in trunk (r2740) to ensure materials look the same on all platforms.
  158.  - Added support for PVR textures. Loader offer support for compressed DXT1-5, PVRTC/PVRTC-II, ETC1/ETC2 texture formats.
  159. +- Added SDL2 device.  Works on Linux with GL & BurningsVideo and Android with GLES1&2.
  160.  
  161.  --------------------------
  162.  Changes in 1.9 (not yet released)
  163. Index: include/EDeviceTypes.h
  164. ===================================================================
  165. --- include/EDeviceTypes.h  (revision 4940)
  166. +++ include/EDeviceTypes.h  (working copy)
  167. @@ -1,6 +1,10 @@
  168.  // Copyright (C) 2002-2012 Nikolaus Gebhardt
  169.  // This file is part of the "Irrlicht Engine".
  170.  // For conditions of distribution and use, see copyright notice in irrlicht.h
  171. +//
  172. +// SDL2 upgrade
  173. +// Jonathan Frisch
  174. +// Sep 15, 2014
  175.  
  176.  #ifndef __E_DEVICE_TYPES_H_INCLUDED__
  177.  #define __E_DEVICE_TYPES_H_INCLUDED__
  178. @@ -28,7 +32,7 @@
  179.         //! A device native to Mac OSX
  180.         /** This device uses Apple's Cocoa API and works in Mac OSX 10.2 and above. */
  181.         EIDT_OSX,
  182. -        
  183. +
  184.          //! A device native to the IPhone/IPod touch
  185.         /** This device should be used with the OpenGL-ES driver. */
  186.         EIDT_IPHONE,
  187. @@ -56,12 +60,17 @@
  188.         will be tried. This ensures that Irrlicht will run even if your platform is unsupported,
  189.         although it may not be able to render anything. */
  190.         EIDT_BEST,
  191. -      
  192. +
  193.         //! A device for Android platforms
  194.         /** Best used with embedded devices and mobile systems.
  195.         Does not need X11 or other graphical subsystems.
  196.         May support hw-acceleration via OpenGL-ES */
  197. -       EIDT_ANDROID,      
  198. +       EIDT_ANDROID,
  199. +
  200. +       //! A device which uses Simple DirectMedia Layer
  201. +       /** The SDL2 device works under all platforms supported by SDL2 but first must be compiled
  202. +       in by defining the IRR_USE_SDL2_DEVICE macro in IrrCompileConfig.h */
  203. +       EIDT_SDL2
  204.     };
  205.  
  206.  } // end namespace irr
  207. Index: include/IrrCompileConfig.h
  208. ===================================================================
  209. --- include/IrrCompileConfig.h  (revision 4940)
  210. +++ include/IrrCompileConfig.h  (working copy)
  211. @@ -1,6 +1,10 @@
  212.  // Copyright (C) 2002-2012 Nikolaus Gebhardt
  213.  // This file is part of the "Irrlicht Engine".
  214.  // For conditions of distribution and use, see copyright notice in irrlicht.h
  215. +//
  216. +// SDL2 upgrade
  217. +// Jonathan Frisch
  218. +// Sep 15, 2014
  219.  
  220.  #ifndef __IRR_COMPILE_CONFIG_H_INCLUDED__
  221.  #define __IRR_COMPILE_CONFIG_H_INCLUDED__
  222. @@ -51,6 +55,12 @@
  223.  #undef _IRR_COMPILE_WITH_SDL_DEVICE_
  224.  #endif
  225.  
  226. +//! Uncomment this line to compile with the SDL2 device
  227. +//#define _IRR_COMPILE_WITH_SDL2_DEVICE_
  228. +#ifdef NO_IRR_COMPILE_WITH_SDL2_DEVICE_
  229. +#undef _IRR_COMPILE_WITH_SDL2_DEVICE_
  230. +#endif
  231. +
  232.  //! Comment this line to compile without the fallback console device.
  233.  #define _IRR_COMPILE_WITH_CONSOLE_DEVICE_
  234.  #ifdef NO_IRR_COMPILE_WITH_CONSOLE_DEVICE_
  235. @@ -124,10 +134,10 @@
  236.  #endif
  237.  #endif
  238.  
  239. -#if !defined(_IRR_WINDOWS_API_) && !defined(_IRR_OSX_PLATFORM_) && !defined(_IRR_ANDROID_PLATFORM_)
  240. -#ifndef _IRR_SOLARIS_PLATFORM_
  241. -#define _IRR_LINUX_PLATFORM_
  242. -#endif
  243. +#if !defined(_IRR_WINDOWS_API_) && !defined(_IRR_OSX_PLATFORM_) && !defined(_IRR_ANDROID_PLATFORM_) && !defined(_IRR_COMPILE_WITH_SDL2_DEVICE_)
  244. +   #ifndef _IRR_SOLARIS_PLATFORM_
  245. +   #define _IRR_LINUX_PLATFORM_
  246. +   #endif // _IRR_SOLARIS_PLATFORM_
  247.  #define _IRR_POSIX_API_
  248.  #define _IRR_COMPILE_WITH_X11_DEVICE_
  249.  #endif
  250. Index: source/Irrlicht/CEGLManager.cpp
  251. ===================================================================
  252. --- source/Irrlicht/CEGLManager.cpp (revision 4940)
  253. +++ source/Irrlicht/CEGLManager.cpp (working copy)
  254. @@ -1,6 +1,10 @@
  255.  // Copyright (C) 2013 Patryk Nadrowski
  256.  // This file is part of the "Irrlicht Engine".
  257. -// For conditions of distribution and use, see copyright notice in Irrlicht.h
  258. +// For conditions of distribution and use, see copyright notice in Irrlicht.h
  259. +//
  260. +// SDL2 upgrade
  261. +// Jonathan Frisch
  262. +// Sep 15, 2014
  263.  
  264.  #include "CEGLManager.h"
  265.  
  266. @@ -7,7 +11,11 @@
  267.  #ifdef _IRR_COMPILE_WITH_EGL_MANAGER_
  268.  
  269.  #include "irrString.h"
  270. -#include "os.h"
  271. +#include "os.h"
  272. +
  273. +#if defined(_IRR_COMPILE_WITH_SDL2_DEVICE_)
  274. +#include <SDL2/SDL.h>
  275. +#endif // defined
  276.  
  277.  namespace irr
  278.  {
  279. @@ -34,6 +42,10 @@
  280.     // store new data
  281.     Params=params;
  282.     Data=data;
  283. +
  284. +#if defined(_IRR_COMPILE_WITH_SDL2_DEVICE_)
  285. +    if(Params.DeviceType == EIDT_SDL2) return true;
  286. +#endif // _IRR_COMPILE_WITH_SDL2_DEVICE_
  287.  
  288.     if (EglWindow != 0 && EglDisplay != EGL_NO_DISPLAY)
  289.          return true;
  290. @@ -72,7 +84,7 @@
  291.          return false;
  292.      }
  293.     else
  294. -       os::Printer::log("EGL version", core::stringc(MajorVersion+(MinorVersion*0.1f)).c_str());
  295. +       os::Printer::log("EGL version", core::stringc(MajorVersion+(MinorVersion*0.1f)).c_str());
  296.  
  297.      return true;
  298.  }
  299. @@ -79,6 +91,9 @@
  300.  
  301.  void CEGLManager::terminate()
  302.  {
  303. +    MajorVersion = 0;
  304. +    MinorVersion = 0;
  305. +
  306.      if (EglWindow == 0 && EglDisplay == EGL_NO_DISPLAY)
  307.          return;
  308.  
  309. @@ -98,13 +113,14 @@
  310.          Data.OpenGLWin32.HDc = 0;
  311.      }
  312.  #endif
  313. -
  314. -    MajorVersion = 0;
  315. -    MinorVersion = 0;
  316.  }
  317.  
  318.  bool CEGLManager::generateSurface()
  319. -{
  320. +{
  321. +#if defined(_IRR_COMPILE_WITH_SDL2_DEVICE_)
  322. +    if(Params.DeviceType == EIDT_SDL2) return true;
  323. +#endif // _IRR_COMPILE_WITH_SDL2_DEVICE_
  324. +
  325.      if (EglDisplay == EGL_NO_DISPLAY)
  326.          return false;
  327.  
  328. @@ -260,7 +276,7 @@
  329.  #endif
  330.  
  331.      if (Params.Vsync)
  332. -       eglSwapInterval(EglDisplay, 1);
  333. +       eglSwapInterval(EglDisplay, 1);
  334.  
  335.      return true;
  336.  }
  337. @@ -278,7 +294,11 @@
  338.  }
  339.  
  340.  bool CEGLManager::generateContext()
  341. -{
  342. +{
  343. +#if defined(_IRR_COMPILE_WITH_SDL2_DEVICE_)
  344. +    if(Params.DeviceType == EIDT_SDL2) return true;
  345. +#endif // _IRR_COMPILE_WITH_SDL2_DEVICE_
  346. +
  347.      if (EglDisplay == EGL_NO_DISPLAY || EglSurface == EGL_NO_SURFACE)
  348.          return false;
  349.  
  350. @@ -328,12 +348,19 @@
  351.     // We must unbind current EGL context before destroy it.
  352.     eglMakeCurrent(EglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
  353.     eglDestroyContext(EglDisplay, EglContext);
  354. -
  355.      EglContext = EGL_NO_CONTEXT;
  356.  }
  357.  
  358.  bool CEGLManager::activateContext(const SExposedVideoData& videoData)
  359. -{
  360. +{
  361. +#if defined(_IRR_COMPILE_WITH_SDL2_DEVICE_)
  362. +    if(Params.DeviceType == EIDT_SDL2)
  363. +    {
  364. +        Data = videoData;
  365. +        return true;
  366. +    }
  367. +#endif // _IRR_COMPILE_WITH_SDL2_DEVICE_
  368. +
  369.     eglMakeCurrent(EglDisplay, EglSurface, EglSurface, EglContext);
  370.  
  371.     if (testEGLError())
  372. @@ -350,8 +377,13 @@
  373.  }
  374.  
  375.  bool CEGLManager::swapBuffers()
  376. -{
  377. -    return (eglSwapBuffers(EglDisplay, EglSurface)==EGL_TRUE);
  378. +{
  379. +#if !defined(_IRR_COMPILE_WITH_SDL2_DEVICE_)
  380. +    return (eglSwapBuffers(EglDisplay, EglSurface) == EGL_TRUE);
  381. +#else
  382. +    SDL_GL_SwapWindow((SDL_Window*)Params.WindowId);
  383. +    return true;
  384. +#endif // _IRR_COMPILE_WITH_SDL2_DEVICE_
  385.  }
  386.  
  387.  bool CEGLManager::testEGLError()
  388. Index: source/Irrlicht/CEGLManager.h
  389. ===================================================================
  390. --- source/Irrlicht/CEGLManager.h   (revision 4940)
  391. +++ source/Irrlicht/CEGLManager.h   (working copy)
  392. @@ -1,6 +1,10 @@
  393.  // Copyright (C) 2013 Patryk Nadrowski
  394.  // This file is part of the "Irrlicht Engine".
  395. -// For conditions of distribution and use, see copyright notice in Irrlicht.h
  396. +// For conditions of distribution and use, see copyright notice in Irrlicht.h
  397. +//
  398. +// SDL2 upgrade
  399. +// Jonathan Frisch
  400. +// Sep 15, 2014
  401.  
  402.  #ifndef __C_EGL_MANAGER_H_INCLUDED__
  403.  #define __C_EGL_MANAGER_H_INCLUDED__
  404. @@ -7,12 +11,16 @@
  405.  
  406.  #include "IrrCompileConfig.h"
  407.  
  408. -#ifdef _IRR_COMPILE_WITH_EGL_MANAGER_
  409. +#ifdef _IRR_COMPILE_WITH_EGL_MANAGER_
  410.  
  411. -#if defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_) || defined(_IRR_COMPILE_WITH_FB_DEVICE_)
  412. +#ifdef _IRR_COMPILE_WITH_SDL2_DEVICE_
  413. +#include <SDL2/SDL_egl.h>
  414. +#endif
  415. +
  416. +#if !defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_)
  417.  #include <EGL/egl.h>
  418.  #else
  419. -#include <GLES/egl.h>
  420. +#include <GLES/egl.h> // is this even needed?
  421.  #endif
  422.  
  423.  #include "SIrrCreationParameters.h"
  424. Index: source/Irrlicht/CFileSystem.cpp
  425. ===================================================================
  426. --- source/Irrlicht/CFileSystem.cpp (revision 4940)
  427. +++ source/Irrlicht/CFileSystem.cpp (working copy)
  428. @@ -25,14 +25,14 @@
  429.  #include "CWriteFile.h"
  430.  #include "irrList.h"
  431.  
  432. -#if defined (_IRR_WINDOWS_API_)
  433. -   #if !defined ( _WIN32_WCE )
  434. +#if defined (_IRR_WINDOWS_API_) && !defined ( _WIN32_WCE )
  435.         #include <direct.h> // for _chdir
  436.         #include <io.h> // for _access
  437.         #include <tchar.h>
  438. -   #endif
  439. -#else
  440. -   #if (defined(_IRR_POSIX_API_) || defined(_IRR_OSX_PLATFORM_) || defined(_IRR_ANDROID_PLATFORM_))
  441. +#elif defined(_IRR_COMPILE_WITH_SDL2_DEVICE_)
  442. +   #include <SDL2/SDL.h>
  443. +   #include <SDL2/SDL_rwops.h>
  444. +#else // if (defined(_IRR_POSIX_API_) || defined(_IRR_OSX_PLATFORM_) || defined(_IRR_ANDROID_PLATFORM_))
  445.         #include <stdio.h>
  446.         #include <stdlib.h>
  447.         #include <string.h>
  448. @@ -41,7 +41,6 @@
  449.         #include <dirent.h>
  450.         #include <sys/stat.h>
  451.         #include <unistd.h>
  452. -   #endif
  453.  #endif
  454.  
  455.  namespace irr
  456. @@ -593,21 +592,21 @@
  457.     {
  458.         WorkingDirectory[FILESYSTEM_NATIVE] = newDirectory;
  459.  
  460. -#if defined(_IRR_WINDOWS_CE_PLATFORM_)
  461. -       success = true;
  462. -#elif defined(_MSC_VER)
  463. -   #if defined(_IRR_WCHAR_FILESYSTEM)
  464. -       success = (_wchdir(newDirectory.c_str()) == 0);
  465. -   #else
  466. -       success = (_chdir(newDirectory.c_str()) == 0);
  467. -   #endif
  468. -#else
  469. -   #if defined(_IRR_WCHAR_FILESYSTEM)
  470. -       success = (_wchdir(newDirectory.c_str()) == 0);
  471. -   #else
  472. -       success = (chdir(newDirectory.c_str()) == 0);
  473. -   #endif
  474. -#endif
  475. +        #if defined(_IRR_WINDOWS_CE_PLATFORM_) || defined(_IRR_COMPILE_WITH_SDL2_DEVICE_)
  476. +                success = true;
  477. +        #elif defined(_MSC_VER)
  478. +            #if defined(_IRR_WCHAR_FILESYSTEM)
  479. +                success = (_wchdir(newDirectory.c_str()) == 0);
  480. +            #else
  481. +                success = (_chdir(newDirectory.c_str()) == 0);
  482. +            #endif
  483. +        #else
  484. +            #if defined(_IRR_WCHAR_FILESYSTEM)
  485. +                success = (_wchdir(newDirectory.c_str()) == 0);
  486. +            #else
  487. +                success = (chdir(newDirectory.c_str()) == 0);
  488. +            #endif
  489. +        #endif
  490.     }
  491.  
  492.     return success;
  493. @@ -962,16 +961,16 @@
  494.  //! determines if a file exists and would be able to be opened.
  495.  bool CFileSystem::existFile(const io::path& filename) const
  496.  {
  497. -   for (u32 i=0; i < FileArchives.size(); ++i)
  498. -       if (FileArchives[i]->getFileList()->findFile(filename)!=-1)
  499. +   for (u32 i = 0; i < FileArchives.size(); ++i)
  500. +       if (FileArchives[i]->getFileList()->findFile(filename) != -1)
  501.             return true;
  502.  
  503.  #if defined(_IRR_WINDOWS_CE_PLATFORM_)
  504. -#if defined(_IRR_WCHAR_FILESYSTEM)
  505. -   HANDLE hFile = CreateFileW(filename.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
  506. -#else
  507. -   HANDLE hFile = CreateFileW(core::stringw(filename).c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
  508. -#endif
  509. +    #if defined(_IRR_WCHAR_FILESYSTEM)
  510. +        HANDLE hFile = CreateFileW(filename.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
  511. +    #else
  512. +        HANDLE hFile = CreateFileW(core::stringw(filename).c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
  513. +    #endif
  514.     if (hFile == INVALID_HANDLE_VALUE)
  515.         return false;
  516.     else
  517. @@ -979,24 +978,38 @@
  518.         CloseHandle(hFile);
  519.         return true;
  520.     }
  521. +#elif defined(_IRR_COMPILE_WITH_SDL2_DEVICE_)
  522. +    bool e = false;
  523. +    SDL_RWops* f;
  524. +    #if defined(_IRR_WCHAR_FILESYSTEM)
  525. +        f = SDL_RWFromFile(filename.c_str(), L"rb");
  526. +    #else
  527. +        f = SDL_RWFromFile(filename.c_str(), "rb");
  528. +    #endif
  529. +    if(f)
  530. +    {
  531. +        e = true;
  532. +        SDL_RWclose(f);
  533. +    }
  534. +    return e;
  535.  #else
  536.     _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
  537. -#if defined(_MSC_VER)
  538. -   #if defined(_IRR_WCHAR_FILESYSTEM)
  539. -       return (_waccess(filename.c_str(), 0) != -1);
  540. -   #else
  541. -       return (_access(filename.c_str(), 0) != -1);
  542. -   #endif
  543. -#elif defined(F_OK)
  544. -   #if defined(_IRR_WCHAR_FILESYSTEM)
  545. -       return (_waccess(filename.c_str(), F_OK) != -1);
  546. -   #else
  547. -       return (access(filename.c_str(), F_OK) != -1);
  548. -   #endif
  549. -#else
  550. -   return (access(filename.c_str(), 0) != -1);
  551. +    #if defined(_MSC_VER)
  552. +        #if defined(_IRR_WCHAR_FILESYSTEM)
  553. +            return (_waccess(filename.c_str(), 0) != -1);
  554. +        #else
  555. +            return (_access(filename.c_str(), 0) != -1);
  556. +        #endif
  557. +    #elif defined(F_OK)
  558. +        #if defined(_IRR_WCHAR_FILESYSTEM)
  559. +            return (_waccess(filename.c_str(), F_OK) != -1);
  560. +        #else
  561. +            return (access(filename.c_str(), F_OK) != -1);
  562. +        #endif
  563. +    #else
  564. +        return (access(filename.c_str(), 0) != -1);
  565. +    #endif
  566.  #endif
  567. -#endif
  568.  }
  569.  
  570.  
  571. @@ -1114,4 +1127,3 @@
  572.  
  573.  } // end namespace irr
  574.  } // end namespace io
  575. -
  576. Index: source/Irrlicht/CIrrDeviceSDL2.cpp
  577. ===================================================================
  578. --- source/Irrlicht/CIrrDeviceSDL2.cpp  (revision 0)
  579. +++ source/Irrlicht/CIrrDeviceSDL2.cpp  (working copy)
  580. @@ -0,0 +1,1590 @@
  581. +// Copyright (C) 2002-2012 Nikolaus Gebhardt
  582. +// This file is part of the "Irrlicht Engine".
  583. +// For conditions of distribution and use, see copyright notice in irrlicht.h
  584. +//
  585. +// SDL2 upgrade
  586. +// Jonathan Frisch
  587. +// Sep 15, 2014
  588. +
  589. +#include "IrrCompileConfig.h"
  590. +
  591. +#ifdef _IRR_COMPILE_WITH_SDL2_DEVICE_
  592. +
  593. +#include "CIrrDeviceSDL2.h"
  594. +#include "IEventReceiver.h"
  595. +#include "irrList.h"
  596. +#include "os.h"
  597. +#include "CTimer.h"
  598. +#include "irrString.h"
  599. +#include "Keycodes.h"
  600. +#include "COSOperator.h"
  601. +#include <stdio.h>
  602. +#include <stdlib.h>
  603. +#include "SIrrCreationParameters.h"
  604. +#include "CEGLManager.h"
  605. +#include "SExposedVideoData.h"
  606. +#include "ISceneManager.h"
  607. +#include "ICameraSceneNode.h"
  608. +#include "CLogger.h"
  609. +
  610. +#ifdef _MSC_VER
  611. +#pragma comment(lib, "SDL2.lib")
  612. +#endif // _MSC_VER
  613. +
  614. +#define A_TITLE "Irrlicht on SDL2"
  615. +
  616. +namespace irr
  617. +{
  618. +   namespace video
  619. +   {
  620. +       #ifdef _IRR_COMPILE_WITH_DIRECT3D_8_
  621. +       //IVideoDriver* createDirectX8Driver(const irr::SIrrlichtCreationParameters &params, io::IFileSystem* io, HWND window);
  622. +       #endif
  623. +
  624. +       #ifdef _IRR_COMPILE_WITH_DIRECT3D_9_
  625. +       //IVideoDriver* createDirectX9Driver(const irr::SIrrlichtCreationParameters &params, io::IFileSystem* io, HWND window);
  626. +       #endif
  627. +
  628. +       #ifdef _IRR_COMPILE_WITH_OPENGL_
  629. +       IVideoDriver* createOpenGLDriver(const SIrrlichtCreationParameters &params, io::IFileSystem* io, CIrrDeviceSDL2* device);
  630. +       #endif
  631. +
  632. +       #ifdef _IRR_COMPILE_WITH_OGLES1_
  633. +       IVideoDriver* createOGLES1Driver(const SIrrlichtCreationParameters &params, io::IFileSystem* io, IContextManager* manager);
  634. +       #endif
  635. +
  636. +       #ifdef _IRR_COMPILE_WITH_OGLES2_
  637. +       IVideoDriver* createOGLES2Driver(const SIrrlichtCreationParameters &params, io::IFileSystem* io, IContextManager* manager);
  638. +       #endif
  639. +   } // end namespace video
  640. +} // end namespace irr
  641. +
  642. +namespace irr
  643. +{
  644. +    //! constructor
  645. +    CIrrDeviceSDL2::CIrrDeviceSDL2(const SIrrlichtCreationParameters &param)
  646. +            : CIrrDeviceStub(param), MouseX(0), MouseY(0), MouseButtonStates(0),
  647. +            Width(param.WindowSize.Width), Height(param.WindowSize.Height), Resizable(true),
  648. +            WindowHasFocus(false), WindowMinimized(false), window((SDL_Window*)param.WindowId),
  649. +            glContext(NULL), renderer(NULL), rendFlags(0), winFlags(SDL_WINDOW_RESIZABLE), filler()
  650. +    {
  651. +        #ifdef _DEBUG
  652. +        setDebugName("CIrrDeviceSDL2");
  653. +        #endif
  654. +
  655. +        #if defined(_IRR_COMPILE_WITH_JOYSTICK_EVENTS_)
  656. +        SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1");
  657. +        SDL_SetHint(SDL_HINT_IDLE_TIMER_DISABLED, "1");
  658. +        SDL_SetHint(SDL_HINT_ACCELEROMETER_AS_JOYSTICK, "1");
  659. +        #endif // defined
  660. +        SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");  // make the scaled rendering look smoother.
  661. +        SDL_SetHint(SDL_HINT_MOUSE_RELATIVE_MODE_WARP, "1");
  662. +
  663. +        // Initialize SDL2... everything, because it's easier
  664. +        if(SDL_Init(SDL_INIT_EVERYTHING) == 0)
  665. +        {
  666. +            // create keymap
  667. +            createKeyMap();
  668. +
  669. +            // create window
  670. +            if(createWindow())
  671. +            {
  672. +                SDL_VERSION(&Info.version); // initialize info structure with SDL version info
  673. +                if(SDL_GetWindowWMInfo(window, &Info)) { // the call returns true on success
  674. +                    // success
  675. +                    const char *subsystem = "an unknown system!";
  676. +                    switch(Info.subsystem) {
  677. +                        case SDL_SYSWM_WINDOWS:
  678. +                            subsystem = "Microsoft Windows(TM)";
  679. +                            break;
  680. +                        case SDL_SYSWM_X11:
  681. +                            subsystem = "X Window System";
  682. +                            break;
  683. +                        #if SDL_VERSION_ATLEAST(2, 0, 3)
  684. +                        case SDL_SYSWM_WINRT:
  685. +                            subsystem = "WinRT";
  686. +                            break;
  687. +                        #endif
  688. +                        case SDL_SYSWM_DIRECTFB:
  689. +                            subsystem = "DirectFB";
  690. +                            break;
  691. +                        case SDL_SYSWM_COCOA:
  692. +                            subsystem = "Apple OS X";
  693. +                            break;
  694. +                        case SDL_SYSWM_UIKIT:
  695. +                            subsystem = "UIKit";
  696. +                            break;
  697. +                        #if SDL_VERSION_ATLEAST(2, 0, 2)
  698. +                        case SDL_SYSWM_WAYLAND:
  699. +                            subsystem = "Wayland";
  700. +                            break;
  701. +                        case SDL_SYSWM_MIR:
  702. +                            subsystem = "Mir";
  703. +                            break;
  704. +                        #endif
  705. +                        #if SDL_VERSION_ATLEAST(2, 0, 4)
  706. +                        case SDL_SYSWM_ANDROID:
  707. +                            subsystem = "Android";
  708. +                            break;
  709. +                        #endif
  710. +                        default:
  711. +                            break;
  712. +                    }
  713. +                    core::stringc sdlversion = "This program is running SDL version ";
  714. +                    sdlversion += Info.version.major;
  715. +                    sdlversion += ".";
  716. +                    sdlversion += Info.version.minor;
  717. +                    sdlversion += ".";
  718. +                    sdlversion += Info.version.patch;
  719. +                    sdlversion += " on ";
  720. +                    sdlversion += subsystem;
  721. +                    Operator = new COSOperator(sdlversion);
  722. +                    os::Printer::Logger->log(sdlversion.c_str(), ELL_INFORMATION);
  723. +                }
  724. +                else
  725. +                {
  726. +                    // call failed
  727. +                    char log[300];
  728. +                    sprintf(log, "Couldn't get window information: %s\n", SDL_GetError());
  729. +                    os::Printer::Logger->log(log, ELL_ERROR);
  730. +                }
  731. +
  732. +                if(createRenderer())
  733. +                {
  734. +                    // create cursor control
  735. +                    CursorControl = new CCursorControlSDL2(this, window);
  736. +
  737. +                    // create driver
  738. +                    createDriver();
  739. +
  740. +                    if(VideoDriver) createGUIAndScene();
  741. +                    else
  742. +                    {
  743. +                        os::Printer::Logger->log("Unable to create video driver!", ELL_ERROR);
  744. +                        Close = true;
  745. +                    }
  746. +                }
  747. +                else
  748. +                {
  749. +                    char log[300];
  750. +                    sprintf(log, "Unable to create SDL renderer!  %s\n", SDL_GetError());
  751. +                    os::Printer::Logger->log(log, ELL_ERROR);
  752. +                    Close = true;
  753. +                }
  754. +            }
  755. +            else
  756. +            {
  757. +                char log[300];
  758. +                sprintf(log, "Unable to get or create SDL window!  %s\n", SDL_GetError());
  759. +                os::Printer::Logger->log(log, ELL_ERROR);
  760. +                Close = true;
  761. +            }
  762. +        }
  763. +        else
  764. +        {
  765. +            char log[300];
  766. +            sprintf(log, "Unable to initialize SDL!  %s\n", SDL_GetError());
  767. +            os::Printer::Logger->log(log, ELL_ERROR);
  768. +            Close = true;
  769. +        }
  770. +    }
  771. +
  772. +    //! destructor
  773. +    CIrrDeviceSDL2::~CIrrDeviceSDL2()
  774. +    {
  775. +        #if defined(_IRR_COMPILE_WITH_JOYSTICK_EVENTS_)
  776. +        const u32 numJoysticks = Joysticks.size();
  777. +        for(u32 i = 0; i < numJoysticks; ++i) SDL_JoystickClose(Joysticks[i]);
  778. +        #endif
  779. +        if(glContext) SDL_GL_DeleteContext(glContext);
  780. +        if(renderer) SDL_DestroyRenderer(renderer);
  781. +        if(window) SDL_DestroyWindow(window);
  782. +        SDL_Quit();
  783. +    }
  784. +
  785. +    bool CIrrDeviceSDL2::createWindow()
  786. +    {
  787. +        if(!window)
  788. +        {
  789. +            if(CreationParams.DriverType == video::EDT_NULL) winFlags |= SDL_WINDOW_HIDDEN;
  790. +            else winFlags |= SDL_WINDOW_SHOWN;
  791. +
  792. +            if(CreationParams.Fullscreen) winFlags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
  793. +
  794. +            int x = SDL_WINDOWPOS_CENTERED, y = SDL_WINDOWPOS_CENTERED, w = 800, h = 600;
  795. +            if(CreationParams.WindowPosition.X >= 0 && CreationParams.WindowPosition.Y >= 0)
  796. +            {
  797. +                x = CreationParams.WindowPosition.X;
  798. +                y = CreationParams.WindowPosition.Y;
  799. +            }
  800. +            if(CreationParams.WindowSize.Width > 0 && CreationParams.WindowSize.Height > 0)
  801. +            {
  802. +                w = CreationParams.WindowSize.Width;
  803. +                h = CreationParams.WindowSize.Height;
  804. +            }
  805. +            /*
  806. +            CreationParams.WindowId = window = SDL_CreateWindow(A_TITLE, x, y, w, h, winFlags);
  807. +            /*/
  808. +            if(CreationParams.DriverType == video::EDT_OPENGL
  809. +               || CreationParams.DriverType == video::EDT_OGLES1
  810. +               || CreationParams.DriverType == video::EDT_OGLES2)
  811. +            {
  812. +                winFlags |= SDL_WINDOW_OPENGL;
  813. +                if(CreationParams.DriverType == video::EDT_OPENGL)
  814. +                {
  815. +                    os::Printer::Logger->log("EDT_OPENGL", ELL_DEBUG);
  816. +                    SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY);
  817. +                }
  818. +                else // if(CreationParams.DriverType & (video::EDT_OGLES1 | video::EDT_OGLES2))
  819. +                {
  820. +                    SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES | SDL_GL_CONTEXT_PROFILE_COMPATIBILITY);
  821. +                    if(CreationParams.DriverType == video::EDT_OGLES1)
  822. +                    {
  823. +                        os::Printer::Logger->log("EDT_OGLES1", ELL_DEBUG);
  824. +                        SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1);
  825. +                        SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
  826. +                    }
  827. +                    else
  828. +                    {
  829. +                        os::Printer::Logger->log("EDT_OGLES2", ELL_DEBUG);
  830. +                        SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
  831. +                        SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
  832. +                    }
  833. +                }
  834. +
  835. +                if(CreationParams.Bits < 24)
  836. +                {
  837. +                    SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 4);
  838. +                    SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 4);
  839. +                    SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 4);
  840. +                    SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, CreationParams.WithAlphaChannel ? 1 : 0);
  841. +                }
  842. +                else
  843. +                {
  844. +                    SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
  845. +                    SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
  846. +                    SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
  847. +                    SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, CreationParams.WithAlphaChannel ? 8 : 0);
  848. +                }
  849. +
  850. +                SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, CreationParams.Bits);
  851. +                SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, CreationParams.ZBufferBits);
  852. +
  853. +                if(CreationParams.Doublebuffer) SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
  854. +                if(CreationParams.Stereobuffer) SDL_GL_SetAttribute(SDL_GL_STEREO, 1);
  855. +                if(CreationParams.AntiAlias > 1)
  856. +                {
  857. +                    SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
  858. +                    SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, CreationParams.AntiAlias);
  859. +                }
  860. +
  861. +                window = SDL_CreateWindow(A_TITLE, x, y, w, h, winFlags);
  862. +
  863. +                if(!window && CreationParams.Stereobuffer)
  864. +                {
  865. +                    SDL_GL_SetAttribute(SDL_GL_STEREO, 0);
  866. +                    window = SDL_CreateWindow(A_TITLE, x, y, w, h, winFlags);
  867. +                    if(window) os::Printer::Logger->log("StereoBuffer disabled due to lack of support!", ELL_WARNING);
  868. +                }
  869. +                if(!window && CreationParams.AntiAlias > 1)
  870. +                {
  871. +                    while(--CreationParams.AntiAlias > 1)
  872. +                    {
  873. +                        SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, CreationParams.AntiAlias);
  874. +                        window = SDL_CreateWindow(A_TITLE, x, y, w, h, winFlags);
  875. +                        if(window) break;
  876. +                    }
  877. +                    if(!window)
  878. +                    {
  879. +                        SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0);
  880. +                        SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0);
  881. +                        window = SDL_CreateWindow(A_TITLE, x, y, w, h, winFlags);
  882. +                        if(window) os::Printer::Logger->log("AntiAliasing disabled due to lack of support!", ELL_WARNING);
  883. +                    }
  884. +                }
  885. +                if(!window && CreationParams.Doublebuffer)
  886. +                {
  887. +                    // Try single buffer
  888. +                    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 0);
  889. +                    window = SDL_CreateWindow(A_TITLE, x, y, w, h, winFlags);
  890. +                    if(window) os::Printer::Logger->log("DoubleBuffer disabled due to lack of support!", ELL_WARNING);
  891. +                }
  892. +            }
  893. +            else window = SDL_CreateWindow(A_TITLE, x, y, w, h, winFlags);
  894. +
  895. +            CreationParams.WindowId = window;
  896. +            if(!window)
  897. +            {
  898. +                os::Printer::Logger->log("Could not initialize Window!", ELL_ERROR);
  899. +                return false;
  900. +            }
  901. +        }
  902. +        return true;
  903. +    }
  904. +
  905. +    bool CIrrDeviceSDL2::createRenderer()
  906. +    {
  907. +        if(Close) return false;
  908. +
  909. +        switch(CreationParams.DriverType)
  910. +        {
  911. +            case video::EDT_OGLES1:
  912. +            case video::EDT_OGLES2:
  913. +            case video::EDT_OPENGL:
  914. +                glContext = SDL_GL_CreateContext(window);
  915. +                if(glContext)
  916. +                {
  917. +                    SDL_GL_SetSwapInterval(CreationParams.Vsync ? 0 : 1);
  918. +                    SDL_GL_MakeCurrent(window, glContext);
  919. +                    return true;
  920. +                }
  921. +                return false;
  922. +            case video::EDT_BURNINGSVIDEO:
  923. +                rendFlags |= SDL_RENDERER_ACCELERATED;
  924. +                break;
  925. +            case video::EDT_SOFTWARE:
  926. +                rendFlags |= SDL_RENDERER_SOFTWARE;
  927. +                break;
  928. +            case video::EDT_NULL:
  929. +                rendFlags |= SDL_RENDERER_TARGETTEXTURE;
  930. +                break;
  931. +            default:
  932. +                return false;
  933. +        }
  934. +        if(CreationParams.Vsync) rendFlags |= SDL_RENDERER_PRESENTVSYNC;
  935. +
  936. +        renderer = SDL_CreateRenderer(window, -1, rendFlags);
  937. +
  938. +        if(renderer)
  939. +        {
  940. +            if(CreationParams.Fullscreen)
  941. +            {
  942. +                SDL_RenderSetLogicalSize(renderer, CreationParams.WindowSize.Width, CreationParams.WindowSize.Height);
  943. +            }
  944. +            SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
  945. +            SDL_RenderClear(renderer);
  946. +            SDL_RenderPresent(renderer);
  947. +            return true;
  948. +        }
  949. +        return false;
  950. +    }
  951. +
  952. +    //! create the driver
  953. +    void CIrrDeviceSDL2::createDriver()
  954. +    {
  955. +        switch(CreationParams.DriverType)
  956. +        {
  957. +            case video::EDT_OPENGL:
  958. +                #ifdef _IRR_COMPILE_WITH_OPENGL_
  959. +                VideoDriver = video::createOpenGLDriver(CreationParams, FileSystem, this);
  960. +                #else
  961. +                os::Printer::log("No OpenGL support compiled in.", ELL_ERROR);
  962. +                #endif
  963. +                break;
  964. +
  965. +            case video::EDT_OGLES1:
  966. +                #ifdef _IRR_COMPILE_WITH_OGLES1_
  967. +                ContextManager = new video::CEGLManager();
  968. +                ContextManager->initialize(CreationParams, filler);
  969. +                VideoDriver = video::createOGLES1Driver(CreationParams, FileSystem, ContextManager);
  970. +                #else
  971. +                os::Printer::log("No OGLES1 support compiled in.", ELL_ERROR);
  972. +                #endif
  973. +                break;
  974. +
  975. +            case video::EDT_OGLES2:
  976. +                #ifdef _IRR_COMPILE_WITH_OGLES2_
  977. +                ContextManager = new video::CEGLManager();
  978. +                ContextManager->initialize(CreationParams, filler);
  979. +                VideoDriver = video::createOGLES2Driver(CreationParams, FileSystem, ContextManager);
  980. +                #else
  981. +                os::Printer::log("No OGLES2 support compiled in.", ELL_ERROR);
  982. +                #endif
  983. +                break;
  984. +
  985. +            case video::EDT_BURNINGSVIDEO:
  986. +                #ifdef _IRR_COMPILE_WITH_BURNINGSVIDEO_
  987. +                VideoDriver = video::createBurningVideoDriver(CreationParams, FileSystem, this);
  988. +                #else
  989. +                os::Printer::log("Burning's video driver was not compiled in.", ELL_ERROR);
  990. +                #endif
  991. +                break;
  992. +
  993. +            case video::EDT_SOFTWARE:
  994. +                #ifdef _IRR_COMPILE_WITH_SOFTWARE_
  995. +                VideoDriver = video::createSoftwareDriver(CreationParams.WindowSize, CreationParams.Fullscreen, FileSystem, this);
  996. +                #else
  997. +                os::Printer::log("No Software driver support compiled in.", ELL_ERROR);
  998. +                #endif
  999. +                break;
  1000. +
  1001. +            case video::EDT_NULL:
  1002. +                VideoDriver = video::createNullDriver(FileSystem, CreationParams.WindowSize);
  1003. +                break;
  1004. +
  1005. +            case video::EDT_DIRECT3D8:
  1006. +//                #ifdef _IRR_COMPILE_WITH_DIRECT3D_8_
  1007. +//                VideoDriver = video::createDirectX8Driver(CreationParams, FileSystem, HWnd);
  1008. +//                if(!VideoDriver)
  1009. +//                {
  1010. +//                    os::Printer::log("Could not create DIRECT3D8 Driver.", ELL_ERROR);
  1011. +//                }
  1012. +//                #else
  1013. +                os::Printer::log("DIRECT3D8 Driver is not currently setup for SDL2.", ELL_ERROR);
  1014. +//                #endif // _IRR_COMPILE_WITH_DIRECT3D_8_
  1015. +                break;
  1016. +
  1017. +            case video::EDT_DIRECT3D9:
  1018. +//                #ifdef _IRR_COMPILE_WITH_DIRECT3D_9_
  1019. +//                VideoDriver = video::createDirectX9Driver(CreationParams, FileSystem, HWnd);
  1020. +//                if(!VideoDriver)
  1021. +//                {
  1022. +//                    os::Printer::log("Could not create DIRECT3D9 Driver.", ELL_ERROR);
  1023. +//                }
  1024. +//                #else
  1025. +                os::Printer::log("DIRECT3D9 Driver is not currently setup for SDL2.", ELL_ERROR);
  1026. +//                #endif // _IRR_COMPILE_WITH_DIRECT3D_9_
  1027. +                break;
  1028. +
  1029. +            default:
  1030. +                os::Printer::log("Unable to create video driver of unknown type.", ELL_ERROR);
  1031. +                break;
  1032. +        }
  1033. +    }
  1034. +
  1035. +    //! runs the device. Returns false if device wants to be deleted
  1036. +    bool CIrrDeviceSDL2::run()
  1037. +    {
  1038. +        os::Timer::tick();
  1039. +        SDL_Event SDL_event;
  1040. +        bool kHandled = false;
  1041. +
  1042. +        while(!Close && SDL_PollEvent(&SDL_event))
  1043. +        {
  1044. +            SEvent irrevent;
  1045. +            switch(SDL_event.type)
  1046. +            {
  1047. +                case SDL_QUIT:
  1048. +                    {
  1049. +                        os::Printer::Logger->log("SDL_QUIT", ELL_DEBUG);
  1050. +                        Close = true;
  1051. +                        return false;
  1052. +                    }
  1053. +                    break;
  1054. +                case SDL_APP_TERMINATING:
  1055. +                    {
  1056. +                        os::Printer::Logger->log("SDL_APP_TERMINATING", ELL_DEBUG);
  1057. +                        Close = true;
  1058. +                        return false;
  1059. +                    }
  1060. +                    break;
  1061. +                case SDL_APP_LOWMEMORY:
  1062. +                    {
  1063. +                        os::Printer::Logger->log("SDL_APP_LOWMEMORY", ELL_WARNING);
  1064. +                    }
  1065. +                    break;
  1066. +                case SDL_APP_WILLENTERBACKGROUND:
  1067. +                    {
  1068. +                        os::Printer::Logger->log("SDL_APP_WILLENTERBACKGROUND", ELL_DEBUG);
  1069. +                        WindowHasFocus = false;
  1070. +                        WindowMinimized = true;
  1071. +                    }
  1072. +                    break;
  1073. +                case SDL_APP_DIDENTERBACKGROUND:
  1074. +                    {
  1075. +                        os::Printer::Logger->log("SDL_APP_DIDENTERBACKGROUND", ELL_DEBUG);
  1076. +                        WindowHasFocus = false;
  1077. +                        WindowMinimized = true;
  1078. +                    }
  1079. +                    break;
  1080. +                case SDL_APP_WILLENTERFOREGROUND:
  1081. +                    {
  1082. +                        os::Printer::Logger->log("SDL_APP_WILLENTERFOREGROUND", ELL_DEBUG);
  1083. +                        WindowHasFocus = true;
  1084. +                        WindowMinimized = false;
  1085. +                    }
  1086. +                    break;
  1087. +                case SDL_APP_DIDENTERFOREGROUND:
  1088. +                    {
  1089. +                        os::Printer::Logger->log("SDL_APP_DIDENTERFOREGROUND", ELL_DEBUG);
  1090. +                        WindowHasFocus = true;
  1091. +                        WindowMinimized = false;
  1092. +                    }
  1093. +                    break;
  1094. +                case SDL_WINDOWEVENT:
  1095. +                    {
  1096. +                        os::Printer::Logger->log("SDL_WINDOWEVENT", ELL_DEBUG);
  1097. +                        switch(SDL_event.window.event)
  1098. +                        {
  1099. +                            case SDL_WINDOWEVENT_SHOWN:
  1100. +                                {
  1101. +                                    char m[300];
  1102. +                                    sprintf(m, "SDL_WINDOWEVENT_SHOWN::Window %d shown", SDL_event.window.windowID);
  1103. +                                    os::Printer::Logger->log(m, ELL_DEBUG);
  1104. +                                    WindowMinimized = false;
  1105. +                                }
  1106. +                                break;
  1107. +                            case SDL_WINDOWEVENT_HIDDEN:
  1108. +                                {
  1109. +                                    char m[300];
  1110. +                                    sprintf(m, "SDL_WINDOWEVENT_HIDDEN::Window %d hidden", SDL_event.window.windowID);
  1111. +                                    os::Printer::Logger->log(m, ELL_DEBUG);
  1112. +                                    WindowMinimized = true;
  1113. +                                }
  1114. +                                break;
  1115. +                            case SDL_WINDOWEVENT_EXPOSED:
  1116. +                                {
  1117. +                                    char m[300];
  1118. +                                    sprintf(m, "SDL_WINDOWEVENT_EXPOSED::Window %d exposed", SDL_event.window.windowID);
  1119. +                                    os::Printer::Logger->log(m, ELL_DEBUG);
  1120. +                                    WindowMinimized = false;
  1121. +                                }
  1122. +                                break;
  1123. +                            case SDL_WINDOWEVENT_MOVED:
  1124. +                                {
  1125. +                                    char m[300];
  1126. +                                    sprintf(m, "SDL_WINDOWEVENT_MOVED::Window %d moved to %d,%d",
  1127. +                                            SDL_event.window.windowID, SDL_event.window.data1, SDL_event.window.data2);
  1128. +                                    os::Printer::Logger->log(m, ELL_DEBUG);
  1129. +                                }
  1130. +                                break;
  1131. +                            case SDL_WINDOWEVENT_RESIZED:
  1132. +                                {
  1133. +                                    char m[300];
  1134. +                                    sprintf(m, "SDL_WINDOWEVENT_RESIZED::Window %d resized to %dx%d",
  1135. +                                            SDL_event.window.windowID, SDL_event.window.data1, SDL_event.window.data2);
  1136. +                                    os::Printer::Logger->log(m, ELL_DEBUG);
  1137. +                                    updateWindowSize();
  1138. +                                }
  1139. +                                break;
  1140. +                            case SDL_WINDOWEVENT_SIZE_CHANGED:
  1141. +                                {
  1142. +                                    char m[300];
  1143. +                                    sprintf(m, "SDL_WINDOWEVENT_SIZE_CHANGED::Window %d size changed to %dx%d",
  1144. +                                            SDL_event.window.windowID, SDL_event.window.data1, SDL_event.window.data2);
  1145. +                                    os::Printer::Logger->log(m, ELL_DEBUG);
  1146. +                                    updateWindowSize();
  1147. +                                }
  1148. +                                break;
  1149. +                            case SDL_WINDOWEVENT_MINIMIZED:
  1150. +                                {
  1151. +                                    char m[300];
  1152. +                                    sprintf(m, "SDL_WINDOWEVENT_MINIMIZED::Window %d minimized", SDL_event.window.windowID);
  1153. +                                    os::Printer::Logger->log(m, ELL_DEBUG);
  1154. +                                    WindowMinimized = true;
  1155. +                                }
  1156. +                                break;
  1157. +                            case SDL_WINDOWEVENT_MAXIMIZED:
  1158. +                                {
  1159. +                                    char m[300];
  1160. +                                    sprintf(m, "SDL_WINDOWEVENT_MAXIMIZED::Window %d maximized", SDL_event.window.windowID);
  1161. +                                    os::Printer::Logger->log(m, ELL_DEBUG);
  1162. +                                    WindowMinimized = false;
  1163. +                                }
  1164. +                                break;
  1165. +                            case SDL_WINDOWEVENT_RESTORED:
  1166. +                                {
  1167. +                                    char m[300];
  1168. +                                    sprintf(m, "SDL_WINDOWEVENT_RESTORED::Window %d restored", SDL_event.window.windowID);
  1169. +                                    os::Printer::Logger->log(m, ELL_DEBUG);
  1170. +                                    WindowMinimized = false;
  1171. +                                }
  1172. +                                break;
  1173. +                            case SDL_WINDOWEVENT_ENTER:
  1174. +                                {
  1175. +                                    char m[300];
  1176. +                                    sprintf(m, "SDL_WINDOWEVENT_ENTER::Mouse entered window %d", SDL_event.window.windowID);
  1177. +                                    os::Printer::Logger->log(m, ELL_DEBUG);
  1178. +                                }
  1179. +                                break;
  1180. +                            case SDL_WINDOWEVENT_LEAVE:
  1181. +                                {
  1182. +                                    char m[300];
  1183. +                                    sprintf(m, "SDL_WINDOWEVENT_LEAVE::Mouse left window %d", SDL_event.window.windowID);
  1184. +                                    os::Printer::Logger->log(m, ELL_DEBUG);
  1185. +                                }
  1186. +                                break;
  1187. +                            case SDL_WINDOWEVENT_FOCUS_GAINED:
  1188. +                                {
  1189. +                                    char m[300];
  1190. +                                    sprintf(m, "SDL_WINDOWEVENT_LEAVE::Window %d gained keyboard focus", SDL_event.window.windowID);
  1191. +                                    os::Printer::Logger->log(m, ELL_DEBUG);
  1192. +                                    WindowHasFocus = true;
  1193. +                                }
  1194. +                                break;
  1195. +                            case SDL_WINDOWEVENT_FOCUS_LOST:
  1196. +                                {
  1197. +                                    char m[300];
  1198. +                                    sprintf(m, "SDL_WINDOWEVENT_LEAVE::Window %d lost keyboard focus", SDL_event.window.windowID);
  1199. +                                    os::Printer::Logger->log(m, ELL_DEBUG);
  1200. +                                    WindowHasFocus = false;
  1201. +                                }
  1202. +                                break;
  1203. +                            case SDL_WINDOWEVENT_CLOSE:
  1204. +                                {
  1205. +                                    char m[300];
  1206. +                                    sprintf(m, "SDL_WINDOWEVENT_CLOSE::Window %d closed", SDL_event.window.windowID);
  1207. +                                    os::Printer::Logger->log(m, ELL_DEBUG);
  1208. +                                    Close = true;
  1209. +                                    return false;
  1210. +                                }
  1211. +                                break;
  1212. +                            default:
  1213. +                                {
  1214. +                                    char m[300];
  1215. +                                    sprintf(m, "Window %d got unknown event %d", SDL_event.window.windowID, SDL_event.window.event);
  1216. +                                    os::Printer::Logger->log(m, ELL_DEBUG);
  1217. +                                }
  1218. +                                break;
  1219. +                        }
  1220. +                    }
  1221. +                    break;
  1222. +                case SDL_SYSWMEVENT:
  1223. +                    {
  1224. +                        os::Printer::Logger->log("SDL_SYSWMEVENT", ELL_DEBUG);
  1225. +                    }
  1226. +                    break;
  1227. +                case SDL_KEYDOWN:
  1228. +                    {
  1229. +                        os::Printer::Logger->log("SDL_KEYDOWN", ELL_DEBUG);
  1230. +                        kHandled = true;
  1231. +
  1232. +                        SKeyMap key(SDL_event.key.keysym.sym, KEY_UNKNOWN);
  1233. +                        s32 idx = KeyMap.binary_search(key);
  1234. +
  1235. +                        if(idx > -1) key.IrrKey = KeyMap[idx].IrrKey;
  1236. +
  1237. +                        irrevent.EventType = irr::EET_KEY_INPUT_EVENT;
  1238. +                        irrevent.KeyInput.Char = (wchar_t)SDL_event.key.keysym.sym;
  1239. +                        irrevent.KeyInput.Key = (EKEY_CODE)key.IrrKey;
  1240. +                        irrevent.KeyInput.PressedDown = true;
  1241. +                        irrevent.KeyInput.Shift = (SDL_event.key.keysym.mod & KMOD_SHIFT) != 0;
  1242. +                        irrevent.KeyInput.Control = (SDL_event.key.keysym.mod & KMOD_CTRL) != 0;
  1243. +
  1244. +                        postEventFromUser(irrevent);
  1245. +
  1246. +                    }
  1247. +                    break;
  1248. +                case SDL_KEYUP:
  1249. +                    {
  1250. +                        os::Printer::Logger->log("SDL_KEYUP", ELL_DEBUG);
  1251. +                        SKeyMap key(SDL_event.key.keysym.sym, KEY_UNKNOWN);
  1252. +                        s32 idx = KeyMap.binary_search(key);
  1253. +
  1254. +                        if(idx > -1) key.IrrKey = KeyMap[idx].IrrKey;
  1255. +
  1256. +                        irrevent.EventType = irr::EET_KEY_INPUT_EVENT;
  1257. +                        irrevent.KeyInput.Char = (wchar_t)SDL_event.key.keysym.sym;
  1258. +                        irrevent.KeyInput.Key = (EKEY_CODE)key.IrrKey;
  1259. +                        irrevent.KeyInput.PressedDown = false;
  1260. +                        irrevent.KeyInput.Shift = (SDL_event.key.keysym.mod & KMOD_SHIFT) != 0;
  1261. +                        irrevent.KeyInput.Control = (SDL_event.key.keysym.mod & KMOD_CTRL) != 0;
  1262. +
  1263. +                        postEventFromUser(irrevent);
  1264. +
  1265. +                        wchar_t test = (wchar_t)irrevent.KeyInput.Key;
  1266. +                        os::Printer::Logger->log(&test, ELL_DEBUG);
  1267. +                        kHandled = false;
  1268. +                    }
  1269. +                    break;
  1270. +                case SDL_TEXTEDITING:
  1271. +                    {
  1272. +                        os::Printer::Logger->log("SDL_TEXTEDITING", ELL_DEBUG);
  1273. +                    }
  1274. +                    break;
  1275. +                case SDL_TEXTINPUT:
  1276. +                    {
  1277. +                        os::Printer::Logger->log("SDL_TEXTINPUT", ELL_DEBUG);
  1278. +                        if(!kHandled)
  1279. +                        {
  1280. +                            wchar_t wc;
  1281. +                            core::utf8ToWchar(&SDL_event.text.text[0], &wc, 1);
  1282. +
  1283. +                            SKeyMap key((s32)wc, KEY_UNKNOWN);
  1284. +                            s32 idx = KeyMap.binary_search(key);
  1285. +
  1286. +                            if(idx > -1) key.IrrKey = KeyMap[idx].IrrKey;
  1287. +
  1288. +                            irrevent.EventType = irr::EET_KEY_INPUT_EVENT;
  1289. +                            irrevent.KeyInput.Char = wc;
  1290. +                            irrevent.KeyInput.Key = (EKEY_CODE)key.IrrKey;
  1291. +                            irrevent.KeyInput.PressedDown = true;
  1292. +                            irrevent.KeyInput.Control = false;
  1293. +                            irrevent.KeyInput.Shift = false;
  1294. +
  1295. +                            postEventFromUser(irrevent);
  1296. +                            irrevent.KeyInput.PressedDown = false;
  1297. +                            postEventFromUser(irrevent);
  1298. +
  1299. +                            os::Printer::Logger->log(&irrevent.KeyInput.Char, ELL_DEBUG);
  1300. +                        }
  1301. +                    }
  1302. +                    break;
  1303. +                case SDL_MOUSEMOTION:
  1304. +                    {
  1305. +                        os::Printer::Logger->log("SDL_MOUSEMOTION", ELL_DEBUG);
  1306. +                        if(SDL_event.motion.which != SDL_TOUCH_MOUSEID)
  1307. +                        {
  1308. +                            irrevent.EventType = irr::EET_MOUSE_INPUT_EVENT;
  1309. +                            irrevent.MouseInput.Event = irr::EMIE_MOUSE_MOVED;
  1310. +                            MouseX = irrevent.MouseInput.X = SDL_event.motion.x;
  1311. +                            MouseY = irrevent.MouseInput.Y = SDL_event.motion.y;
  1312. +                            MouseButtonStates = SDL_event.motion.state & SDL_BUTTON_LMASK ? irr::EMBSM_LEFT : 0;
  1313. +                            MouseButtonStates |= SDL_event.motion.state & SDL_BUTTON_MMASK ? irr::EMBSM_MIDDLE : 0;
  1314. +                            MouseButtonStates |= SDL_event.motion.state & SDL_BUTTON_RMASK ? irr::EMBSM_RIGHT : 0;
  1315. +                            MouseButtonStates |= SDL_event.motion.state & SDL_BUTTON_X1MASK ? irr::EMBSM_EXTRA1 : 0;
  1316. +                            MouseButtonStates |= SDL_event.motion.state & SDL_BUTTON_X2MASK ? irr:: EMBSM_EXTRA2 : 0;
  1317. +                            irrevent.MouseInput.ButtonStates = MouseButtonStates;
  1318. +                            irrevent.MouseInput.Control = (SDL_event.key.keysym.mod & KMOD_CTRL) != 0;
  1319. +                            irrevent.MouseInput.Shift = (SDL_event.key.keysym.mod & KMOD_SHIFT) != 0;
  1320. +
  1321. +                            postEventFromUser(irrevent);
  1322. +                        }
  1323. +                    }
  1324. +                    break;
  1325. +                case SDL_MOUSEBUTTONDOWN:
  1326. +                    {
  1327. +                        os::Printer::Logger->log("SDL_MOUSEBUTTONDOWN", ELL_DEBUG);
  1328. +                        if(SDL_event.button.which != SDL_TOUCH_MOUSEID)
  1329. +                        {
  1330. +                            irrevent.EventType = irr::EET_MOUSE_INPUT_EVENT;
  1331. +                            MouseX = irrevent.MouseInput.X = SDL_event.button.x;
  1332. +                            MouseY = irrevent.MouseInput.Y = SDL_event.button.y;
  1333. +                            irrevent.MouseInput.ButtonStates = MouseButtonStates;
  1334. +                            irrevent.MouseInput.Control = (SDL_event.key.keysym.mod & KMOD_CTRL) != 0;
  1335. +                            irrevent.MouseInput.Shift = (SDL_event.key.keysym.mod & KMOD_SHIFT) != 0;
  1336. +
  1337. +                            switch(SDL_event.button.button)
  1338. +                            {
  1339. +                                case SDL_BUTTON_LEFT:
  1340. +                                    os::Printer::Logger->log("SDL_BUTTON_LEFT", ELL_DEBUG);
  1341. +                                    switch(SDL_event.button.clicks)
  1342. +                                    {
  1343. +                                        case 1:
  1344. +                                            os::Printer::Logger->log("single click", ELL_DEBUG);
  1345. +                                            irrevent.MouseInput.Event = irr::EMIE_LMOUSE_PRESSED_DOWN;
  1346. +                                            break;
  1347. +                                        case 2:
  1348. +                                            os::Printer::Logger->log("double click", ELL_DEBUG);
  1349. +                                            irrevent.MouseInput.Event = irr::EMIE_LMOUSE_DOUBLE_CLICK;
  1350. +                                            break;
  1351. +                                        case 3:
  1352. +                                            os::Printer::Logger->log("triple click", ELL_DEBUG);
  1353. +                                            irrevent.MouseInput.Event = irr::EMIE_LMOUSE_TRIPLE_CLICK;
  1354. +                                            break;
  1355. +                                        default:
  1356. +                                            os::Printer::Logger->log("unhandled click count", ELL_DEBUG);
  1357. +                                            break;
  1358. +                                    }
  1359. +                                    break;
  1360. +                                case SDL_BUTTON_RIGHT:
  1361. +                                    os::Printer::Logger->log("SDL_BUTTON_RIGHT", ELL_DEBUG);
  1362. +                                    switch(SDL_event.button.clicks)
  1363. +                                    {
  1364. +                                        case 1:
  1365. +                                            os::Printer::Logger->log("single click", ELL_DEBUG);
  1366. +                                            irrevent.MouseInput.Event = irr::EMIE_RMOUSE_PRESSED_DOWN;
  1367. +                                            break;
  1368. +                                        case 2:
  1369. +                                            os::Printer::Logger->log("double click", ELL_DEBUG);
  1370. +                                            irrevent.MouseInput.Event = irr::EMIE_RMOUSE_DOUBLE_CLICK;
  1371. +                                            break;
  1372. +                                        case 3:
  1373. +                                            os::Printer::Logger->log("triple click", ELL_DEBUG);
  1374. +                                            irrevent.MouseInput.Event = irr::EMIE_RMOUSE_TRIPLE_CLICK;
  1375. +                                            break;
  1376. +                                        default:
  1377. +                                            os::Printer::Logger->log("unhandled click count", ELL_DEBUG);
  1378. +                                            break;
  1379. +                                    }
  1380. +                                    break;
  1381. +                                case SDL_BUTTON_MIDDLE:
  1382. +                                    os::Printer::Logger->log("SDL_BUTTON_MIDDLE", ELL_DEBUG);
  1383. +                                    switch(SDL_event.button.clicks)
  1384. +                                    {
  1385. +                                        case 1:
  1386. +                                            os::Printer::Logger->log("single click", ELL_DEBUG);
  1387. +                                            irrevent.MouseInput.Event = irr::EMIE_MMOUSE_PRESSED_DOWN;
  1388. +                                            break;
  1389. +                                        case 2:
  1390. +                                            os::Printer::Logger->log("double click", ELL_DEBUG);
  1391. +                                            irrevent.MouseInput.Event = irr::EMIE_MMOUSE_DOUBLE_CLICK;
  1392. +                                            break;
  1393. +                                        case 3:
  1394. +                                            os::Printer::Logger->log("triple click", ELL_DEBUG);
  1395. +                                            irrevent.MouseInput.Event = irr::EMIE_MMOUSE_TRIPLE_CLICK;
  1396. +                                            break;
  1397. +                                        default:
  1398. +                                            os::Printer::Logger->log("unhandled click count", ELL_DEBUG);
  1399. +                                            break;
  1400. +                                    }
  1401. +                                    break;
  1402. +                                default:
  1403. +                                    os::Printer::Logger->log("unhandled sdl mouse button down event", ELL_DEBUG);
  1404. +                                    break;
  1405. +                            }
  1406. +
  1407. +                            postEventFromUser(irrevent);
  1408. +                        }
  1409. +                    }
  1410. +                    break;
  1411. +                case SDL_MOUSEBUTTONUP:
  1412. +                    {
  1413. +                        os::Printer::Logger->log("SDL_MOUSEBUTTONUP", ELL_DEBUG);
  1414. +                        if(SDL_event.button.which != SDL_TOUCH_MOUSEID)
  1415. +                        {
  1416. +                            irrevent.EventType = irr::EET_MOUSE_INPUT_EVENT;
  1417. +                            MouseX = irrevent.MouseInput.X = SDL_event.button.x;
  1418. +                            MouseY = irrevent.MouseInput.Y = SDL_event.button.y;
  1419. +                            irrevent.MouseInput.ButtonStates = MouseButtonStates;
  1420. +                            irrevent.MouseInput.Control = (SDL_event.key.keysym.mod & KMOD_CTRL) != 0;
  1421. +                            irrevent.MouseInput.Shift = (SDL_event.key.keysym.mod & KMOD_SHIFT) != 0;
  1422. +
  1423. +                            switch(SDL_event.button.button)
  1424. +                            {
  1425. +                                case SDL_BUTTON_LEFT:
  1426. +                                    os::Printer::Logger->log("SDL_BUTTON_LEFT", ELL_DEBUG);
  1427. +                                    irrevent.MouseInput.Event = irr::EMIE_LMOUSE_LEFT_UP;
  1428. +                                    break;
  1429. +                                case SDL_BUTTON_RIGHT:
  1430. +                                    os::Printer::Logger->log("SDL_BUTTON_RIGHT", ELL_DEBUG);
  1431. +                                    irrevent.MouseInput.Event = irr::EMIE_RMOUSE_LEFT_UP;
  1432. +                                    break;
  1433. +                                case SDL_BUTTON_MIDDLE:
  1434. +                                    os::Printer::Logger->log("SDL_BUTTON_MIDDLE", ELL_DEBUG);
  1435. +                                    irrevent.MouseInput.Event = irr::EMIE_MMOUSE_LEFT_UP;
  1436. +                                    break;
  1437. +                                default:
  1438. +                                    os::Printer::Logger->log("unhandled sdl mouse button up event", ELL_DEBUG);
  1439. +                                    break;
  1440. +                            }
  1441. +
  1442. +                            postEventFromUser(irrevent);
  1443. +                        }
  1444. +                    }
  1445. +                    break;
  1446. +                case SDL_MOUSEWHEEL:
  1447. +                    {
  1448. +                        os::Printer::Logger->log("SDL_MOUSEWHEEL", ELL_DEBUG);
  1449. +                        if(SDL_event.button.which != SDL_TOUCH_MOUSEID)
  1450. +                        {
  1451. +                            irrevent.EventType = irr::EET_MOUSE_INPUT_EVENT;
  1452. +                            MouseX = irrevent.MouseInput.X = SDL_event.button.x;
  1453. +                            MouseY = irrevent.MouseInput.Y = SDL_event.button.y;
  1454. +                            irrevent.MouseInput.ButtonStates = MouseButtonStates;
  1455. +                            irrevent.MouseInput.Event = irr::EMIE_MOUSE_WHEEL;
  1456. +                            irrevent.MouseInput.Wheel = (f32)SDL_event.wheel.x;
  1457. +                            irrevent.MouseInput.Control = (SDL_event.key.keysym.mod & KMOD_CTRL) != 0;
  1458. +                            irrevent.MouseInput.Shift = (SDL_event.key.keysym.mod & KMOD_SHIFT) != 0;
  1459. +
  1460. +                            postEventFromUser(irrevent);
  1461. +                        }
  1462. +                    }
  1463. +                    break;
  1464. +                #ifdef _IRR_COMPILE_WITH_JOYSTICK_EVENTS_
  1465. +                case SDL_JOYAXISMOTION:
  1466. +                    {
  1467. +                        SDL_JoyAxisEvent jaxis = SDL_event.jaxis;
  1468. +                        char logString[256];
  1469. +                        sprintf(logString, "SDL_JOYAXISMOTION: axis %d, value %d", jaxis.axis, jaxis.value);
  1470. +                        os::Printer::Logger->log(logString, ELL_DEBUG);
  1471. +                    }
  1472. +                    break;
  1473. +                case SDL_JOYBALLMOTION:
  1474. +                    {
  1475. +                        os::Printer::Logger->log("SDL_JOYBALLMOTION", ELL_DEBUG);
  1476. +                    }
  1477. +                    break;
  1478. +                case SDL_JOYHATMOTION:
  1479. +                    {
  1480. +                        os::Printer::Logger->log("SDL_JOYHATMOTION", ELL_DEBUG);
  1481. +                    }
  1482. +                    break;
  1483. +                case SDL_JOYBUTTONDOWN:
  1484. +                    {
  1485. +                        os::Printer::Logger->log("SDL_JOYBUTTONDOWN", ELL_DEBUG);
  1486. +                    }
  1487. +                    break;
  1488. +                case SDL_JOYBUTTONUP:
  1489. +                    {
  1490. +                        os::Printer::Logger->log("SDL_JOYBUTTONUP", ELL_DEBUG);
  1491. +                    }
  1492. +                    break;
  1493. +                case SDL_JOYDEVICEADDED:
  1494. +                    {
  1495. +                        os::Printer::Logger->log("SDL_JOYDEVICEADDED", ELL_DEBUG);
  1496. +                        int j = SDL_event.jdevice.which;
  1497. +
  1498. +                        SDL_Joystick* joy = SDL_JoystickOpen(j);
  1499. +                        if(j < Joysticks.size()) Joysticks.erase(j);
  1500. +                        Joysticks.insert(joy, j);
  1501. +
  1502. +                        SJoystickInfo info;
  1503. +                        info.Joystick = j;
  1504. +                        info.Axes = SDL_JoystickNumAxes(joy);
  1505. +                        info.Buttons = SDL_JoystickNumButtons(joy);
  1506. +                        info.Name = SDL_JoystickName(joy);
  1507. +                        info.PovHat = (SDL_JoystickNumHats(joy) > 0) ? SJoystickInfo::POV_HAT_PRESENT : SJoystickInfo::POV_HAT_ABSENT;
  1508. +                        if(joyinfo)
  1509. +                        {
  1510. +                            if(j < joyinfo->size()) joyinfo->erase(j);
  1511. +                            joyinfo->insert(info, j);
  1512. +                        }
  1513. +
  1514. +                        char logString[256];
  1515. +                        sprintf(logString, "Found joystick %d ('%s'): %d axes, %d buttons, %s POV hat",
  1516. +                                j, info.Name.c_str(), info.Axes, info.Buttons, info.PovHat == SJoystickInfo::POV_HAT_PRESENT ? "with" : "no");
  1517. +                        os::Printer::log(logString, ELL_INFORMATION);
  1518. +                    }
  1519. +                    break;
  1520. +                case SDL_JOYDEVICEREMOVED:
  1521. +                    {
  1522. +                        os::Printer::Logger->log("SDL_JOYDEVICEREMOVED", ELL_DEBUG);
  1523. +                        int j = SDL_event.jdevice.which;
  1524. +
  1525. +                        char logString[256];
  1526. +                        sprintf(logString, "Lost joystick %d ('%s')", j, SDL_JoystickName(Joysticks[j]));
  1527. +                        os::Printer::log(logString, ELL_INFORMATION);
  1528. +
  1529. +                        SDL_JoystickClose(Joysticks[SDL_event.jdevice.which]);
  1530. +                    }
  1531. +                    break;
  1532. +                case SDL_CONTROLLERAXISMOTION:
  1533. +                    {
  1534. +                        os::Printer::Logger->log("SDL_CONTROLLERAXISMOTION", ELL_DEBUG);
  1535. +                    }
  1536. +                    break;
  1537. +                case SDL_CONTROLLERBUTTONDOWN:
  1538. +                    {
  1539. +                        os::Printer::Logger->log("SDL_CONTROLLERBUTTONDOWN", ELL_DEBUG);
  1540. +                    }
  1541. +                    break;
  1542. +                case SDL_CONTROLLERBUTTONUP:
  1543. +                    {
  1544. +                        os::Printer::Logger->log("SDL_CONTROLLERBUTTONUP", ELL_DEBUG);
  1545. +                    }
  1546. +                    break;
  1547. +                case SDL_CONTROLLERDEVICEADDED:
  1548. +                    {
  1549. +                        os::Printer::Logger->log("SDL_CONTROLLERDEVICEADDED", ELL_DEBUG);
  1550. +                    }
  1551. +                    break;
  1552. +                case SDL_CONTROLLERDEVICEREMOVED:
  1553. +                    {
  1554. +                        os::Printer::Logger->log("SDL_CONTROLLERDEVICEREMOVED", ELL_DEBUG);
  1555. +                    }
  1556. +                    break;
  1557. +                case SDL_CONTROLLERDEVICEREMAPPED:
  1558. +                    {
  1559. +                        os::Printer::Logger->log("SDL_CONTROLLERDEVICEREMAPPED", ELL_DEBUG);
  1560. +                    }
  1561. +                    break;
  1562. +                #endif // _IRR_COMPILE_WITH_JOYSTICK_EVENTS_
  1563. +                case SDL_FINGERDOWN:
  1564. +                    {
  1565. +                        os::Printer::Logger->log("SDL_FINGERDOWN", ELL_DEBUG);
  1566. +                        irrevent.EventType = irr::EET_TOUCH_INPUT_EVENT;
  1567. +                        irrevent.TouchInput.ID = SDL_event.tfinger.fingerId;
  1568. +                        irrevent.TouchInput.X = SDL_event.tfinger.x * (s32)Width;
  1569. +                        irrevent.TouchInput.Y = SDL_event.tfinger.y * (s32)Height;
  1570. +                        irrevent.TouchInput.Event = irr::ETIE_PRESSED_DOWN;
  1571. +
  1572. +                        postEventFromUser(irrevent);
  1573. +                    }
  1574. +                    break;
  1575. +                case SDL_FINGERUP:
  1576. +                    {
  1577. +                        os::Printer::Logger->log("SDL_FINGERUP", ELL_DEBUG);
  1578. +                        irrevent.EventType = irr::EET_TOUCH_INPUT_EVENT;
  1579. +                        irrevent.TouchInput.ID = SDL_event.tfinger.fingerId;
  1580. +                        irrevent.TouchInput.X = SDL_event.tfinger.x * (s32)Width;
  1581. +                        irrevent.TouchInput.Y = SDL_event.tfinger.y * (s32)Height;
  1582. +                        irrevent.TouchInput.Event = irr::ETIE_LEFT_UP;
  1583. +
  1584. +                        postEventFromUser(irrevent);
  1585. +                    }
  1586. +                    break;
  1587. +                case SDL_FINGERMOTION:
  1588. +                    {
  1589. +                        os::Printer::Logger->log("SDL_FINGERMOTION", ELL_DEBUG);
  1590. +                        irrevent.EventType = irr::EET_TOUCH_INPUT_EVENT;
  1591. +                        irrevent.TouchInput.ID = SDL_event.tfinger.fingerId;
  1592. +                        irrevent.TouchInput.X = SDL_event.tfinger.x * (s32)Width;
  1593. +                        irrevent.TouchInput.Y = SDL_event.tfinger.y * (s32)Height;
  1594. +                        irrevent.TouchInput.Event = irr::ETIE_MOVED;
  1595. +
  1596. +                        postEventFromUser(irrevent);
  1597. +                    }
  1598. +                    break;
  1599. +                case SDL_DOLLARGESTURE:
  1600. +                    {
  1601. +                        os::Printer::Logger->log("SDL_DOLLARGESTURE", ELL_DEBUG);
  1602. +                    }
  1603. +                    break;
  1604. +                case SDL_DOLLARRECORD:
  1605. +                    {
  1606. +                        os::Printer::Logger->log("SDL_DOLLARRECORD", ELL_DEBUG);
  1607. +                    }
  1608. +                    break;
  1609. +                case SDL_MULTIGESTURE:
  1610. +                    {
  1611. +                        os::Printer::Logger->log("SDL_MULTIGESTURE", ELL_DEBUG);
  1612. +                    }
  1613. +                    break;
  1614. +                case SDL_CLIPBOARDUPDATE:
  1615. +                    {
  1616. +                        os::Printer::Logger->log("SDL_CLIPBOARDUPDATE", ELL_DEBUG);
  1617. +                    }
  1618. +                    break;
  1619. +                case SDL_DROPFILE:
  1620. +                    {
  1621. +                        os::Printer::Logger->log("SDL_DROPFILE", ELL_DEBUG);
  1622. +                    }
  1623. +                    break;
  1624. +                case SDL_RENDER_TARGETS_RESET:
  1625. +                    {
  1626. +                        os::Printer::Logger->log("SDL_RENDER_TARGETS_RESET", ELL_DEBUG);
  1627. +                    }
  1628. +                    break;
  1629. +                case SDL_USEREVENT:
  1630. +                    {
  1631. +                        os::Printer::Logger->log("SDL_USEREVENT", ELL_DEBUG);
  1632. +                        irrevent.EventType = irr::EET_USER_EVENT;
  1633. +                        irrevent.UserEvent.UserData1 = *(reinterpret_cast<s32*>(&SDL_event.user.data1));
  1634. +                        irrevent.UserEvent.UserData2 = *(reinterpret_cast<s32*>(&SDL_event.user.data2));
  1635. +
  1636. +                        postEventFromUser(irrevent);
  1637. +                    }
  1638. +                    break;
  1639. +                default:
  1640. +                    {
  1641. +                        char m[300];
  1642. +                        sprintf(m, "unknown/unhandled event %d", SDL_event.type);
  1643. +                        os::Printer::Logger->log(m, ELL_DEBUG);
  1644. +                    }
  1645. +                    break;
  1646. +            } // end switch
  1647. +
  1648. +        } // end while
  1649. +
  1650. +        #if defined(_IRR_COMPILE_WITH_JOYSTICK_EVENTS_)
  1651. +        // TODO: Check if the multiple open/close calls are too expensive, then
  1652. +        // open/close in the constructor/destructor instead
  1653. +
  1654. +        // we'll always send joystick input events...
  1655. +        SEvent joyevent;
  1656. +        joyevent.EventType = EET_JOYSTICK_INPUT_EVENT;
  1657. +        for(u32 i = 0; i < Joysticks.size(); ++i)
  1658. +        {
  1659. +            SDL_Joystick* joystick = Joysticks[i];
  1660. +            int j;
  1661. +            // query all buttons
  1662. +            const int numButtons = core::min_(SDL_JoystickNumButtons(joystick), 32);
  1663. +            joyevent.JoystickEvent.ButtonStates = 0;
  1664. +            for(j = 0; j < numButtons; ++j)
  1665. +                joyevent.JoystickEvent.ButtonStates |= (SDL_JoystickGetButton(joystick, j)<<j);
  1666. +
  1667. +            // query all axes, already in correct range
  1668. +            const int numAxes = core::min_(SDL_JoystickNumAxes(joystick), (int)SEvent::SJoystickEvent::NUMBER_OF_AXES);
  1669. +            joyevent.JoystickEvent.Axis[SEvent::SJoystickEvent::AXIS_X] = 0;
  1670. +            joyevent.JoystickEvent.Axis[SEvent::SJoystickEvent::AXIS_Y] = 0;
  1671. +            joyevent.JoystickEvent.Axis[SEvent::SJoystickEvent::AXIS_Z] = 0;
  1672. +            joyevent.JoystickEvent.Axis[SEvent::SJoystickEvent::AXIS_R] = 0;
  1673. +            joyevent.JoystickEvent.Axis[SEvent::SJoystickEvent::AXIS_U] = 0;
  1674. +            joyevent.JoystickEvent.Axis[SEvent::SJoystickEvent::AXIS_V] = 0;
  1675. +            for(j = 0; j < numAxes; ++j) joyevent.JoystickEvent.Axis[j] = SDL_JoystickGetAxis(joystick, j);
  1676. +
  1677. +            // we can only query one hat, SDL only supports 8 directions
  1678. +            joyevent.JoystickEvent.POV = 65535; // center/none
  1679. +            if(SDL_JoystickNumHats(joystick) > 0)
  1680. +            {
  1681. +                switch(SDL_JoystickGetHat(joystick, 0))
  1682. +                {
  1683. +                    case SDL_HAT_UP:
  1684. +                        joyevent.JoystickEvent.POV = 0;
  1685. +                        break;
  1686. +                    case SDL_HAT_RIGHTUP:
  1687. +                        joyevent.JoystickEvent.POV = 4500;
  1688. +                        break;
  1689. +                    case SDL_HAT_RIGHT:
  1690. +                        joyevent.JoystickEvent.POV = 9000;
  1691. +                        break;
  1692. +                    case SDL_HAT_RIGHTDOWN:
  1693. +                        joyevent.JoystickEvent.POV = 13500;
  1694. +                        break;
  1695. +                    case SDL_HAT_DOWN:
  1696. +                        joyevent.JoystickEvent.POV = 18000;
  1697. +                        break;
  1698. +                    case SDL_HAT_LEFTDOWN:
  1699. +                        joyevent.JoystickEvent.POV = 22500;
  1700. +                        break;
  1701. +                    case SDL_HAT_LEFT:
  1702. +                        joyevent.JoystickEvent.POV = 27000;
  1703. +                        break;
  1704. +                    case SDL_HAT_LEFTUP:
  1705. +                        joyevent.JoystickEvent.POV = 31500;
  1706. +                        break;
  1707. +                    case SDL_HAT_CENTERED:
  1708. +                    default:
  1709. +                        break;
  1710. +                }
  1711. +            }
  1712. +
  1713. +            // we map the number directly
  1714. +            joyevent.JoystickEvent.Joystick = static_cast<u8>(i);
  1715. +            // now post the event
  1716. +            postEventFromUser(joyevent);
  1717. +            // and close the joystick
  1718. +        }
  1719. +        #endif
  1720. +        return !Close;
  1721. +    }
  1722. +
  1723. +    void CIrrDeviceSDL2::updateWindowSize()
  1724. +    {
  1725. +        int w, h;
  1726. +        if(glContext) SDL_GL_GetDrawableSize(window, &w, &h);
  1727. +        else SDL_GetWindowSize(window, &w, &h);
  1728. +        if(w > 0) Width = (u32)w;
  1729. +        if(h > 0) Height = (u32)h;
  1730. +        VideoDriver->OnResize(core::dimension2du(Width, Height));
  1731. +        char l[200];
  1732. +        sprintf(l, "Viewport size is %dx%d", Width, Height);
  1733. +        os::Printer::Logger->log(l, ELL_DEBUG);
  1734. +
  1735. +        if(SceneManager)
  1736. +        {
  1737. +            scene::ICameraSceneNode* cam = SceneManager->getActiveCamera();
  1738. +            if(cam)
  1739. +            {
  1740. +                cam->setAspectRatio((f32)Width / (f32)Height);
  1741. +
  1742. +                sprintf(l, "Camera aspect ratio is %.4f", cam->getAspectRatio());
  1743. +                os::Printer::Logger->log(l, ELL_DEBUG);
  1744. +            }
  1745. +        }
  1746. +    }
  1747. +
  1748. +    //! Sets a new event receiver to receive events
  1749. +    void CIrrDeviceSDL2::setEventReceiver(IEventReceiver* receiver)
  1750. +    {
  1751. +        if(!sdlEventReceiver) sdlEventReceiver = new SDL2EventReceiver();
  1752. +        sdlEventReceiver->actual = receiver;
  1753. +        CIrrDeviceStub::setEventReceiver(sdlEventReceiver);
  1754. +    }
  1755. +
  1756. +    //! Activate any joysticks, and generate events for them.
  1757. +    bool CIrrDeviceSDL2::activateJoysticks(core::array<SJoystickInfo> &joystickInfo)
  1758. +    {
  1759. +        #if defined(_IRR_COMPILE_WITH_JOYSTICK_EVENTS_)
  1760. +        joystickInfo.clear();
  1761. +
  1762. +        int joystick = 0;
  1763. +        for(; joystick < Joysticks.size(); joystick++)
  1764. +        {
  1765. +            SJoystickInfo info;
  1766. +
  1767. +            info.Joystick = joystick;
  1768. +            info.Axes = SDL_JoystickNumAxes(Joysticks[joystick]);
  1769. +            info.Buttons = SDL_JoystickNumButtons(Joysticks[joystick]);
  1770. +            info.Name = SDL_JoystickName(Joysticks[joystick]);
  1771. +            info.PovHat = (SDL_JoystickNumHats(Joysticks[joystick]) > 0)
  1772. +                            ? SJoystickInfo::POV_HAT_PRESENT : SJoystickInfo::POV_HAT_ABSENT;
  1773. +
  1774. +            joystickInfo.push_back(info);
  1775. +
  1776. +            char logString[256];
  1777. +            sprintf(logString, "Found joystick %d ('%s'): %d axes, %d buttons, %s POV hat",
  1778. +                    joystick, info.Name.c_str(), info.Axes, info.Buttons, info.PovHat == SJoystickInfo::POV_HAT_PRESENT ? "with" : "no");
  1779. +            os::Printer::log(logString, ELL_INFORMATION);
  1780. +        }
  1781. +        joyinfo = &joystickInfo;
  1782. +
  1783. +        return true;
  1784. +        #else
  1785. +        return false;
  1786. +        #endif // _IRR_COMPILE_WITH_JOYSTICK_EVENTS_
  1787. +    }
  1788. +
  1789. +    //! pause execution temporarily
  1790. +    void CIrrDeviceSDL2::yield()
  1791. +    {
  1792. +        sleep(0, false);
  1793. +    }
  1794. +
  1795. +    //! pause execution for a specified time
  1796. +    void CIrrDeviceSDL2::sleep(u32 timeMs, bool pauseTimer)
  1797. +    {
  1798. +        const bool wasStopped = Timer ? Timer->isStopped() : true;
  1799. +        if(pauseTimer && !wasStopped) Timer->stop();
  1800. +        SDL_Delay(timeMs);
  1801. +        if(pauseTimer && !wasStopped) Timer->start();
  1802. +    }
  1803. +
  1804. +    //! sets the caption of the window
  1805. +    void CIrrDeviceSDL2::setWindowCaption(const wchar_t* text)
  1806. +    {
  1807. +        core::stringc textc = text;
  1808. +        SDL_SetWindowTitle(window, textc.c_str());
  1809. +    }
  1810. +
  1811. +    //! presents a surface in the client area
  1812. +    bool CIrrDeviceSDL2::present(video::IImage* irrSurface, void* windowId, core::recti* srcClip)
  1813. +    {
  1814. +        SDL_Surface *sdlSurface = SDL_CreateRGBSurfaceFrom(irrSurface->lock(),
  1815. +                irrSurface->getDimension().Width, irrSurface->getDimension().Height,
  1816. +                irrSurface->getBitsPerPixel(), irrSurface->getPitch(), irrSurface->getRedMask(),
  1817. +                irrSurface->getGreenMask(), irrSurface->getBlueMask(), irrSurface->getAlphaMask());
  1818. +        if(!sdlSurface) return false;
  1819. +        //SDL_SetAlpha(sdlSurface, 0, 0); // what is this doing?
  1820. +        //SDL_SetColorKey(sdlSurface, 0, 0); // what is this doing?
  1821. +        sdlSurface->format->BitsPerPixel = irrSurface->getBitsPerPixel();
  1822. +        sdlSurface->format->BytesPerPixel = irrSurface->getBytesPerPixel();
  1823. +        switch(irrSurface->getColorFormat())
  1824. +        {
  1825. +            case video::ECF_R8G8B8:
  1826. +            case video::ECF_A8R8G8B8:
  1827. +                sdlSurface->format->Rloss = 0;
  1828. +                sdlSurface->format->Gloss = 0;
  1829. +                sdlSurface->format->Bloss = 0;
  1830. +                sdlSurface->format->Rshift = 16;
  1831. +                sdlSurface->format->Gshift = 8;
  1832. +                sdlSurface->format->Bshift = 0;
  1833. +                if(irrSurface->getColorFormat() == video::ECF_R8G8B8)
  1834. +                {
  1835. +                    sdlSurface->format->Aloss = 8;
  1836. +                    sdlSurface->format->Ashift = 32;
  1837. +                }
  1838. +                else
  1839. +                {
  1840. +                    sdlSurface->format->Aloss = 0;
  1841. +                    sdlSurface->format->Ashift = 24;
  1842. +                }
  1843. +                break;
  1844. +            case video::ECF_R5G6B5:
  1845. +                sdlSurface->format->Rloss = 3;
  1846. +                sdlSurface->format->Gloss = 2;
  1847. +                sdlSurface->format->Bloss = 3;
  1848. +                sdlSurface->format->Aloss = 8;
  1849. +                sdlSurface->format->Rshift = 11;
  1850. +                sdlSurface->format->Gshift = 5;
  1851. +                sdlSurface->format->Bshift = 0;
  1852. +                sdlSurface->format->Ashift = 16;
  1853. +                break;
  1854. +            case video::ECF_A1R5G5B5:
  1855. +                sdlSurface->format->Rloss = 3;
  1856. +                sdlSurface->format->Gloss = 3;
  1857. +                sdlSurface->format->Bloss = 3;
  1858. +                sdlSurface->format->Aloss = 7;
  1859. +                sdlSurface->format->Rshift = 10;
  1860. +                sdlSurface->format->Gshift = 5;
  1861. +                sdlSurface->format->Bshift = 0;
  1862. +                sdlSurface->format->Ashift = 15;
  1863. +                break;
  1864. +            default:
  1865. +                break;
  1866. +        }
  1867. +
  1868. +        if(renderer)
  1869. +        {
  1870. +            SDL_Texture* sdlTexture = SDL_CreateTextureFromSurface(renderer, sdlSurface);
  1871. +            if(sdlTexture)
  1872. +            {
  1873. +                SDL_UpdateTexture(sdlTexture, NULL, sdlSurface->pixels, sdlSurface->pitch);
  1874. +                if(srcClip)
  1875. +                {
  1876. +                    SDL_Rect sdlsrcClip;
  1877. +                    sdlsrcClip.x = srcClip->UpperLeftCorner.X;
  1878. +                    sdlsrcClip.y = srcClip->UpperLeftCorner.Y;
  1879. +                    sdlsrcClip.w = srcClip->getWidth();
  1880. +                    sdlsrcClip.h = srcClip->getHeight();
  1881. +                    SDL_RenderCopy(renderer, sdlTexture, &sdlsrcClip, NULL);
  1882. +                }
  1883. +                else SDL_RenderCopy(renderer, sdlTexture, NULL, NULL);
  1884. +            }
  1885. +            else
  1886. +            {
  1887. +                os::Printer::log("Error creating SDL_Texture: %s", SDL_GetError());
  1888. +            }
  1889. +            SDL_RenderPresent(renderer);
  1890. +            SDL_DestroyTexture(sdlTexture);
  1891. +        }
  1892. +
  1893. +        SDL_FreeSurface(sdlSurface);
  1894. +        irrSurface->unlock();
  1895. +        return true;//sdlTexture != NULL;
  1896. +    }
  1897. +
  1898. +    //! notifies the device that it should close itself
  1899. +    void CIrrDeviceSDL2::closeDevice()
  1900. +    {
  1901. +        Close = true;
  1902. +    }
  1903. +
  1904. +    //! \return Pointer to a list with all video modes supported
  1905. +    video::IVideoModeList* CIrrDeviceSDL2::getVideoModeList()
  1906. +    {
  1907. +        if(!VideoModeList->getVideoModeCount())
  1908. +        {
  1909. +            // enumerate video modes.
  1910. +            SDL_DisplayMode current;
  1911. +            for(int i = 0; i < SDL_GetNumVideoDisplays(); ++i)
  1912. +            {
  1913. +                if(SDL_GetCurrentDisplayMode(i, &current) == 0)
  1914. +                {
  1915. +                    VideoModeList->addMode(core::dimension2du(current.w, current.h), SDL_BITSPERPIXEL(current.format));
  1916. +                }
  1917. +                else
  1918. +                {
  1919. +                    char msg[300];
  1920. +                    sprintf(msg, "Could not get display mode for video display #%d: %s", i, SDL_GetError());
  1921. +                    os::Printer::Logger->log(msg, ELL_DEBUG);
  1922. +                }
  1923. +            }
  1924. +        }
  1925. +
  1926. +        return VideoModeList;
  1927. +    }
  1928. +
  1929. +    //! Sets if the window should be resizable in windowed mode.
  1930. +    void CIrrDeviceSDL2::setResizable(bool resize)
  1931. +    {
  1932. +        // meh... leave it always resizable - let SDL take care of stuff.
  1933. +    }
  1934. +
  1935. +    //! Minimizes window if possible
  1936. +    void CIrrDeviceSDL2::minimizeWindow()
  1937. +    {
  1938. +        SDL_MinimizeWindow(window);
  1939. +        WindowMinimized = true;
  1940. +        WindowHasFocus = false;
  1941. +    }
  1942. +
  1943. +    //! Maximize window
  1944. +    void CIrrDeviceSDL2::maximizeWindow()
  1945. +    {
  1946. +        SDL_MaximizeWindow(window);
  1947. +        WindowMinimized = false;
  1948. +        WindowHasFocus = true;
  1949. +    }
  1950. +
  1951. +    //! Get the position of this window on screen
  1952. +    core::position2di CIrrDeviceSDL2::getWindowPosition()
  1953. +    {
  1954. +        int x, y;
  1955. +        SDL_GetWindowPosition(window, &x, &y);
  1956. +        return core::position2di(s32(x), s32(y));
  1957. +    }
  1958. +
  1959. +    //! Restore original window size
  1960. +    void CIrrDeviceSDL2::restoreWindow()
  1961. +    {
  1962. +        SDL_RestoreWindow(window);
  1963. +        WindowMinimized = false;
  1964. +    }
  1965. +
  1966. +    //! returns if window is active. if not, nothing need to be drawn
  1967. +    bool CIrrDeviceSDL2::isWindowActive() const
  1968. +    {
  1969. +        return WindowHasFocus || SDL_GetMouseFocus() == window || SDL_GetKeyboardFocus() == window;// (WindowHasFocus && !WindowMinimized);
  1970. +    }
  1971. +
  1972. +    //! returns if window has focus.
  1973. +    bool CIrrDeviceSDL2::isWindowFocused() const
  1974. +    {
  1975. +        return WindowHasFocus || SDL_GetMouseFocus() == window || SDL_GetKeyboardFocus() == window;
  1976. +    }
  1977. +
  1978. +    //! returns if window is minimized.
  1979. +    bool CIrrDeviceSDL2::isWindowMinimized() const
  1980. +    {
  1981. +        return WindowMinimized;
  1982. +    }
  1983. +
  1984. +    //! Set the current Gamma Value for the Display
  1985. +    bool CIrrDeviceSDL2::setGammaRamp(f32 red, f32 green, f32 blue, f32 brightness, f32 contrast)
  1986. +    {
  1987. +        //! TODO -- https://wiki.libsdl.org/SDL_SetWindowGammaRamp
  1988. +        //! manual...
  1989. +        return false;
  1990. +    }
  1991. +
  1992. +    //! Get the current Gamma Value for the Display
  1993. +    bool CIrrDeviceSDL2::getGammaRamp(f32 &red, f32 &green, f32 &blue, f32 &brightness, f32 &contrast)
  1994. +    {
  1995. +        //! TODO -- https://wiki.libsdl.org/SDL_GetWindowGammaRamp
  1996. +        //! manual...
  1997. +        return false;
  1998. +    }
  1999. +
  2000. +    //! returns color format of the window.
  2001. +    video::ECOLOR_FORMAT CIrrDeviceSDL2::getColorFormat() const
  2002. +    {
  2003. +        if(window)
  2004. +        {
  2005. +            u32 cfrmt = SDL_GetWindowPixelFormat(window);
  2006. +            if(SDL_BITSPERPIXEL(cfrmt) < 24)
  2007. +            {
  2008. +                if(SDL_ISPIXELFORMAT_ALPHA(cfrmt)) return video::ECF_A1R5G5B5;
  2009. +                else return video::ECF_R5G6B5;
  2010. +            }
  2011. +            else
  2012. +            {
  2013. +                if(SDL_ISPIXELFORMAT_ALPHA(cfrmt)) return video::ECF_A8R8G8B8;
  2014. +                else return video::ECF_R8G8B8;
  2015. +            }
  2016. +        }
  2017. +        return CIrrDeviceStub::getColorFormat();
  2018. +    }
  2019. +
  2020. +    void CIrrDeviceSDL2::createKeyMap()
  2021. +    {
  2022. +        // I don't know if this is the best method  to create
  2023. +        // the lookuptable, but I'll leave it like that until
  2024. +        // I find a better version.
  2025. +
  2026. +        KeyMap.reallocate(105);
  2027. +
  2028. +        KeyMap.push_back(SKeyMap(SDLK_0, KEY_KEY_0));
  2029. +        KeyMap.push_back(SKeyMap(SDLK_1, KEY_KEY_1));
  2030. +        KeyMap.push_back(SKeyMap(SDLK_2, KEY_KEY_2));
  2031. +        KeyMap.push_back(SKeyMap(SDLK_3, KEY_KEY_3));
  2032. +        KeyMap.push_back(SKeyMap(SDLK_4, KEY_KEY_4));
  2033. +        KeyMap.push_back(SKeyMap(SDLK_5, KEY_KEY_5));
  2034. +        KeyMap.push_back(SKeyMap(SDLK_6, KEY_KEY_6));
  2035. +        KeyMap.push_back(SKeyMap(SDLK_7, KEY_KEY_7));
  2036. +        KeyMap.push_back(SKeyMap(SDLK_8, KEY_KEY_8));
  2037. +        KeyMap.push_back(SKeyMap(SDLK_9, KEY_KEY_9));
  2038. +        KeyMap.push_back(SKeyMap(SDLK_a, KEY_KEY_A));
  2039. +        KeyMap.push_back(SKeyMap(SDLK_APPLICATION, KEY_APPS));
  2040. +        KeyMap.push_back(SKeyMap(SDLK_AUDIOPLAY, KEY_PLAY));
  2041. +        KeyMap.push_back(SKeyMap(SDLK_b, KEY_KEY_B));
  2042. +        KeyMap.push_back(SKeyMap(SDLK_BACKSPACE, KEY_BACK));
  2043. +        KeyMap.push_back(SKeyMap(SDLK_c, KEY_KEY_C));
  2044. +        KeyMap.push_back(SKeyMap(SDLK_CAPSLOCK, KEY_CAPITAL));
  2045. +        KeyMap.push_back(SKeyMap(SDLK_CLEAR, KEY_CLEAR));
  2046. +        KeyMap.push_back(SKeyMap(SDLK_COMMA,  KEY_COMMA));
  2047. +        KeyMap.push_back(SKeyMap(SDLK_CRSEL,  KEY_CRSEL));
  2048. +        KeyMap.push_back(SKeyMap(SDLK_d, KEY_KEY_D));
  2049. +        KeyMap.push_back(SKeyMap(SDLK_DELETE, KEY_DELETE));
  2050. +        KeyMap.push_back(SKeyMap(SDLK_DOWN, KEY_DOWN));
  2051. +        KeyMap.push_back(SKeyMap(SDLK_e, KEY_KEY_E));
  2052. +        KeyMap.push_back(SKeyMap(SDLK_END, KEY_END));
  2053. +        KeyMap.push_back(SKeyMap(SDLK_ESCAPE, KEY_ESCAPE));
  2054. +        KeyMap.push_back(SKeyMap(SDLK_EXECUTE, KEY_EXECUT));
  2055. +        KeyMap.push_back(SKeyMap(SDLK_EXSEL, KEY_EXSEL));
  2056. +        KeyMap.push_back(SKeyMap(SDLK_f, KEY_KEY_F));
  2057. +        KeyMap.push_back(SKeyMap(SDLK_F1,  KEY_F1));
  2058. +        KeyMap.push_back(SKeyMap(SDLK_F2,  KEY_F2));
  2059. +        KeyMap.push_back(SKeyMap(SDLK_F3,  KEY_F3));
  2060. +        KeyMap.push_back(SKeyMap(SDLK_F4,  KEY_F4));
  2061. +        KeyMap.push_back(SKeyMap(SDLK_F5,  KEY_F5));
  2062. +        KeyMap.push_back(SKeyMap(SDLK_F6,  KEY_F6));
  2063. +        KeyMap.push_back(SKeyMap(SDLK_F7,  KEY_F7));
  2064. +        KeyMap.push_back(SKeyMap(SDLK_F8,  KEY_F8));
  2065. +        KeyMap.push_back(SKeyMap(SDLK_F9,  KEY_F9));
  2066. +        KeyMap.push_back(SKeyMap(SDLK_F10, KEY_F10));
  2067. +        KeyMap.push_back(SKeyMap(SDLK_F11, KEY_F11));
  2068. +        KeyMap.push_back(SKeyMap(SDLK_F12, KEY_F12));
  2069. +        KeyMap.push_back(SKeyMap(SDLK_F13, KEY_F13));
  2070. +        KeyMap.push_back(SKeyMap(SDLK_F14, KEY_F14));
  2071. +        KeyMap.push_back(SKeyMap(SDLK_F15, KEY_F15));
  2072. +        KeyMap.push_back(SKeyMap(SDLK_F16, KEY_F16));
  2073. +        KeyMap.push_back(SKeyMap(SDLK_F17, KEY_F17));
  2074. +        KeyMap.push_back(SKeyMap(SDLK_F18, KEY_F18));
  2075. +        KeyMap.push_back(SKeyMap(SDLK_F19, KEY_F19));
  2076. +        KeyMap.push_back(SKeyMap(SDLK_F20, KEY_F20));
  2077. +        KeyMap.push_back(SKeyMap(SDLK_F21, KEY_F21));
  2078. +        KeyMap.push_back(SKeyMap(SDLK_F22, KEY_F22));
  2079. +        KeyMap.push_back(SKeyMap(SDLK_F23, KEY_F23));
  2080. +        KeyMap.push_back(SKeyMap(SDLK_F24, KEY_F24));
  2081. +        KeyMap.push_back(SKeyMap(SDLK_g, KEY_KEY_G));
  2082. +        KeyMap.push_back(SKeyMap(SDLK_h, KEY_KEY_H));
  2083. +        KeyMap.push_back(SKeyMap(SDLK_HELP, KEY_HELP));
  2084. +        KeyMap.push_back(SKeyMap(SDLK_HOME, KEY_HOME));
  2085. +        KeyMap.push_back(SKeyMap(SDLK_i, KEY_KEY_I));
  2086. +        KeyMap.push_back(SKeyMap(SDLK_INSERT, KEY_INSERT));
  2087. +        KeyMap.push_back(SKeyMap(SDLK_j, KEY_KEY_J));
  2088. +        KeyMap.push_back(SKeyMap(SDLK_k, KEY_KEY_K));
  2089. +        KeyMap.push_back(SKeyMap(SDLK_KP_0, KEY_NUMPAD0));
  2090. +        KeyMap.push_back(SKeyMap(SDLK_KP_00, KEY_NUMPAD0));
  2091. +        KeyMap.push_back(SKeyMap(SDLK_KP_000, KEY_NUMPAD0));
  2092. +        KeyMap.push_back(SKeyMap(SDLK_KP_1, KEY_NUMPAD1));
  2093. +        KeyMap.push_back(SKeyMap(SDLK_KP_2, KEY_NUMPAD2));
  2094. +        KeyMap.push_back(SKeyMap(SDLK_KP_3, KEY_NUMPAD3));
  2095. +        KeyMap.push_back(SKeyMap(SDLK_KP_4, KEY_NUMPAD4));
  2096. +        KeyMap.push_back(SKeyMap(SDLK_KP_5, KEY_NUMPAD5));
  2097. +        KeyMap.push_back(SKeyMap(SDLK_KP_6, KEY_NUMPAD6));
  2098. +        KeyMap.push_back(SKeyMap(SDLK_KP_7, KEY_NUMPAD7));
  2099. +        KeyMap.push_back(SKeyMap(SDLK_KP_8, KEY_NUMPAD8));
  2100. +        KeyMap.push_back(SKeyMap(SDLK_KP_9, KEY_NUMPAD9));
  2101. +        KeyMap.push_back(SKeyMap(SDLK_KP_A, KEY_KEY_A));
  2102. +        KeyMap.push_back(SKeyMap(SDLK_KP_B, KEY_KEY_B));
  2103. +        KeyMap.push_back(SKeyMap(SDLK_KP_BACKSPACE, KEY_BACK));
  2104. +        KeyMap.push_back(SKeyMap(SDLK_KP_C, KEY_KEY_C));
  2105. +        KeyMap.push_back(SKeyMap(SDLK_KP_CLEAR, KEY_CLEAR));
  2106. +        KeyMap.push_back(SKeyMap(SDLK_KP_D, KEY_KEY_D));
  2107. +        KeyMap.push_back(SKeyMap(SDLK_KP_DECIMAL, KEY_DECIMAL));
  2108. +        KeyMap.push_back(SKeyMap(SDLK_KP_DIVIDE, KEY_DIVIDE));
  2109. +        KeyMap.push_back(SKeyMap(SDLK_KP_E, KEY_KEY_E));
  2110. +        KeyMap.push_back(SKeyMap(SDLK_KP_ENTER, KEY_RETURN));
  2111. +        KeyMap.push_back(SKeyMap(SDLK_KP_F, KEY_KEY_F));
  2112. +        KeyMap.push_back(SKeyMap(SDLK_KP_MEMADD, KEY_PLUS));
  2113. +        KeyMap.push_back(SKeyMap(SDLK_KP_MEMCLEAR, KEY_CLEAR));
  2114. +        KeyMap.push_back(SKeyMap(SDLK_KP_MEMDIVIDE, KEY_DIVIDE));
  2115. +        KeyMap.push_back(SKeyMap(SDLK_KP_MEMMULTIPLY, KEY_MULTIPLY));
  2116. +        KeyMap.push_back(SKeyMap(SDLK_KP_MEMSUBTRACT, KEY_MINUS));
  2117. +        KeyMap.push_back(SKeyMap(SDLK_KP_MEMDIVIDE, KEY_DIVIDE));
  2118. +        KeyMap.push_back(SKeyMap(SDLK_KP_MINUS, KEY_SUBTRACT));
  2119. +        KeyMap.push_back(SKeyMap(SDLK_KP_MULTIPLY, KEY_MULTIPLY));
  2120. +        KeyMap.push_back(SKeyMap(SDLK_KP_PLUS, KEY_ADD));
  2121. +        KeyMap.push_back(SKeyMap(SDLK_KP_SPACE, KEY_SPACE));
  2122. +        KeyMap.push_back(SKeyMap(SDLK_KP_TAB, KEY_TAB));
  2123. +        KeyMap.push_back(SKeyMap(SDLK_l, KEY_KEY_L));
  2124. +        KeyMap.push_back(SKeyMap(SDLK_LALT,  KEY_LMENU));
  2125. +        KeyMap.push_back(SKeyMap(SDLK_LCTRL,  KEY_LCONTROL));
  2126. +        KeyMap.push_back(SKeyMap(SDLK_LEFT, KEY_LEFT));
  2127. +        KeyMap.push_back(SKeyMap(SDLK_LGUI, KEY_LWIN));
  2128. +        KeyMap.push_back(SKeyMap(SDLK_LSHIFT, KEY_LSHIFT));
  2129. +        KeyMap.push_back(SKeyMap(SDLK_m, KEY_KEY_M));
  2130. +        KeyMap.push_back(SKeyMap(SDLK_MENU,  KEY_RMENU));
  2131. +        KeyMap.push_back(SKeyMap(SDLK_MINUS,  KEY_MINUS));
  2132. +        KeyMap.push_back(SKeyMap(SDLK_n, KEY_KEY_N));
  2133. +        KeyMap.push_back(SKeyMap(SDLK_NUMLOCKCLEAR, KEY_NUMLOCK));
  2134. +        KeyMap.push_back(SKeyMap(SDLK_o, KEY_KEY_O));
  2135. +        KeyMap.push_back(SKeyMap(SDLK_p, KEY_KEY_P));
  2136. +        KeyMap.push_back(SKeyMap(SDLK_PAGEDOWN, KEY_NEXT));
  2137. +        KeyMap.push_back(SKeyMap(SDLK_PAGEUP, KEY_PRIOR));
  2138. +        KeyMap.push_back(SKeyMap(SDLK_PAUSE, KEY_PAUSE));
  2139. +        KeyMap.push_back(SKeyMap(SDLK_PERIOD, KEY_PERIOD));
  2140. +        KeyMap.push_back(SKeyMap(SDLK_PLUS,   KEY_PLUS));
  2141. +        KeyMap.push_back(SKeyMap(SDLK_PRINTSCREEN, KEY_SNAPSHOT));
  2142. +        KeyMap.push_back(SKeyMap(SDLK_q, KEY_KEY_Q));
  2143. +        KeyMap.push_back(SKeyMap(SDLK_r, KEY_KEY_R));
  2144. +        KeyMap.push_back(SKeyMap(SDLK_RALT,  KEY_RMENU));
  2145. +        KeyMap.push_back(SKeyMap(SDLK_RCTRL,  KEY_RCONTROL));
  2146. +        KeyMap.push_back(SKeyMap(SDLK_RETURN, KEY_RETURN));
  2147. +        KeyMap.push_back(SKeyMap(SDLK_RGUI, KEY_RWIN));
  2148. +        KeyMap.push_back(SKeyMap(SDLK_RIGHT, KEY_RIGHT));
  2149. +        KeyMap.push_back(SKeyMap(SDLK_RSHIFT, KEY_RSHIFT));
  2150. +        KeyMap.push_back(SKeyMap(SDLK_s, KEY_KEY_S));
  2151. +        KeyMap.push_back(SKeyMap(SDLK_SCROLLLOCK, KEY_SCROLL));
  2152. +       KeyMap.push_back(SKeyMap(SDLK_SEPARATOR, KEY_SEPARATOR));
  2153. +       KeyMap.push_back(SKeyMap(SDLK_SLASH, KEY_DIVIDE));
  2154. +       KeyMap.push_back(SKeyMap(SDLK_SLEEP, KEY_SLEEP));
  2155. +        KeyMap.push_back(SKeyMap(SDLK_SPACE, KEY_SPACE));
  2156. +        KeyMap.push_back(SKeyMap(SDLK_t, KEY_KEY_T));
  2157. +        KeyMap.push_back(SKeyMap(SDLK_TAB, KEY_TAB));
  2158. +        KeyMap.push_back(SKeyMap(SDLK_u, KEY_KEY_U));
  2159. +        KeyMap.push_back(SKeyMap(SDLK_UP, KEY_UP));
  2160. +        KeyMap.push_back(SKeyMap(SDLK_v, KEY_KEY_V));
  2161. +        KeyMap.push_back(SKeyMap(SDLK_w, KEY_KEY_W));
  2162. +        KeyMap.push_back(SKeyMap(SDLK_x, KEY_KEY_X));
  2163. +        KeyMap.push_back(SKeyMap(SDLK_y, KEY_KEY_Y));
  2164. +        KeyMap.push_back(SKeyMap(SDLK_z, KEY_KEY_Z));
  2165. +
  2166. +        KeyMap.sort();
  2167. +    }
  2168. +} // end namespace irr
  2169. +
  2170. +#endif // _IRR_COMPILE_WITH_SDL2_DEVICE_
  2171. Index: source/Irrlicht/CIrrDeviceSDL2.h
  2172. ===================================================================
  2173. --- source/Irrlicht/CIrrDeviceSDL2.h    (revision 0)
  2174. +++ source/Irrlicht/CIrrDeviceSDL2.h    (working copy)
  2175. @@ -0,0 +1,295 @@
  2176. +// Copyright (C) 2002-2012 Nikolaus Gebhardt
  2177. +// This file is part of the "Irrlicht Engine".
  2178. +// For conditions of distribution and use, see copyright notice in irrlicht.h
  2179. +// This device code is based on the original SDL device implementation
  2180. +// contributed by Shane Parker (sirshane).
  2181. +//
  2182. +// SDL2 upgrade
  2183. +// Jonathan Frisch
  2184. +// Sep 15, 2014
  2185. +
  2186. +#ifndef __C_IRR_DEVICE_SDL2_H_INCLUDED__
  2187. +#define __C_IRR_DEVICE_SDL2_H_INCLUDED__
  2188. +
  2189. +#include "IrrCompileConfig.h"
  2190. +
  2191. +#ifdef _IRR_COMPILE_WITH_SDL2_DEVICE_
  2192. +
  2193. +#include "IrrlichtDevice.h"
  2194. +#include "CIrrDeviceStub.h"
  2195. +#include "IImagePresenter.h"
  2196. +#include "ICursorControl.h"
  2197. +#include "IGUIElement.h"
  2198. +#include "EGUIElementTypes.h"
  2199. +#include "IGUIEnvironment.h"
  2200. +#include "os.h"
  2201. +
  2202. +#include <SDL2/SDL.h>
  2203. +#include <SDL2/SDL_syswm.h>
  2204. +
  2205. +namespace irr
  2206. +{
  2207. +
  2208. +   class CIrrDeviceSDL2 : public CIrrDeviceStub, video::IImagePresenter
  2209. +   {
  2210. +        public:
  2211. +            //! constructor
  2212. +            CIrrDeviceSDL2(const SIrrlichtCreationParameters &param);
  2213. +
  2214. +            //! destructor
  2215. +            virtual ~CIrrDeviceSDL2();
  2216. +
  2217. +            //! runs the device. Returns false if device wants to be deleted
  2218. +            virtual bool run() _IRR_OVERRIDE_;
  2219. +
  2220. +            //! send the event to the right receiver
  2221. +            //virtual bool postEventFromUser(const SEvent& event) _IRR_OVERRIDE_;
  2222. +
  2223. +            //! Sets a new event receiver to receive events
  2224. +            virtual void setEventReceiver(IEventReceiver* receiver) _IRR_OVERRIDE_;
  2225. +
  2226. +            //! pause execution temporarily
  2227. +            virtual void yield() _IRR_OVERRIDE_;
  2228. +
  2229. +            //! pause execution for a specified time
  2230. +            virtual void sleep(u32 timeMs, bool pauseTimer) _IRR_OVERRIDE_;
  2231. +
  2232. +            //! sets the caption of the window
  2233. +            virtual void setWindowCaption(const wchar_t* text) _IRR_OVERRIDE_;
  2234. +
  2235. +            //! returns if window is active. if not, nothing need to be drawn
  2236. +            virtual bool isWindowActive() const _IRR_OVERRIDE_;
  2237. +
  2238. +            //! returns if window has focus.
  2239. +            bool isWindowFocused() const;
  2240. +
  2241. +            //! returns if window is minimized.
  2242. +            bool isWindowMinimized() const;
  2243. +
  2244. +            //! returns color format of the window.
  2245. +            video::ECOLOR_FORMAT getColorFormat() const;
  2246. +
  2247. +            //! presents a surface in the client area
  2248. +            virtual bool present(video::IImage* irrSurface, void* windowId = 0, core::recti* src = 0) _IRR_OVERRIDE_;
  2249. +
  2250. +            //! notifies the device that it should close itself
  2251. +            virtual void closeDevice() _IRR_OVERRIDE_;
  2252. +
  2253. +            //! \return Returns a pointer to a list with all video modes supported
  2254. +            virtual video::IVideoModeList* getVideoModeList() _IRR_OVERRIDE_;
  2255. +
  2256. +            //! Sets if the window should be resizable in windowed mode.
  2257. +            virtual void setResizable(bool resize = false) _IRR_OVERRIDE_;
  2258. +
  2259. +            //! Minimizes the window.
  2260. +            virtual void minimizeWindow() _IRR_OVERRIDE_;
  2261. +
  2262. +            //! Maximizes the window.
  2263. +            virtual void maximizeWindow() _IRR_OVERRIDE_;
  2264. +
  2265. +            //! Restores the window size.
  2266. +            virtual void restoreWindow() _IRR_OVERRIDE_;
  2267. +
  2268. +            //! Get the position of this window on screen
  2269. +            virtual core::position2di getWindowPosition() _IRR_OVERRIDE_;
  2270. +
  2271. +            //! Activate any joysticks, and generate events for them.
  2272. +            virtual bool activateJoysticks(core::array<SJoystickInfo> &joystickInfo) _IRR_OVERRIDE_;
  2273. +
  2274. +            //! Set the current Gamma Value for the Display
  2275. +            virtual bool setGammaRamp(f32 red, f32 green, f32 blue, f32 brightness, f32 contrast) _IRR_OVERRIDE_;
  2276. +
  2277. +            //! Get the current Gamma Value for the Display
  2278. +            virtual bool getGammaRamp(f32 &red, f32 &green, f32 &blue, f32 &brightness, f32 &contrast) _IRR_OVERRIDE_;
  2279. +
  2280. +            //! Get the device type
  2281. +            virtual E_DEVICE_TYPE getType() const _IRR_OVERRIDE_
  2282. +            {
  2283. +                return EIDT_SDL2;
  2284. +            }
  2285. +
  2286. +        private:
  2287. +            //! Implementation of the linux cursor control
  2288. +            class CCursorControlSDL2 : public gui::ICursorControl
  2289. +            {
  2290. +                public:
  2291. +                    CCursorControlSDL2(CIrrDeviceSDL2* dev, SDL_Window* SDLWindow) :
  2292. +                        Device(dev), IsVisible(true), win(SDLWindow)
  2293. +                    {
  2294. +                    }
  2295. +
  2296. +                    //! Changes the visible state of the mouse cursor.
  2297. +                    virtual void setVisible(bool visible) _IRR_OVERRIDE_
  2298. +                    {
  2299. +                        IsVisible = visible;
  2300. +                        SDL_ShowCursor(IsVisible ? SDL_ENABLE : SDL_DISABLE);
  2301. +                    }
  2302. +
  2303. +                    //! Returns if the cursor is currently visible.
  2304. +                    virtual bool isVisible() const _IRR_OVERRIDE_
  2305. +                    {
  2306. +                        return IsVisible;
  2307. +                    }
  2308. +
  2309. +                    //! Sets the new position of the cursor.
  2310. +                    virtual void setPosition(const core::position2df &pos) _IRR_OVERRIDE_
  2311. +                    {
  2312. +                        setPosition(pos.X, pos.Y);
  2313. +                    }
  2314. +
  2315. +                    //! Sets the new position of the cursor.
  2316. +                    virtual void setPosition(f32 x, f32 y) _IRR_OVERRIDE_
  2317. +                    {
  2318. +                        setPosition(s32(x * Device->Width), s32(y * Device->Height));
  2319. +                    }
  2320. +
  2321. +                    //! Sets the new position of the cursor.
  2322. +                    virtual void setPosition(const core::position2di &pos) _IRR_OVERRIDE_
  2323. +                    {
  2324. +                        setPosition(pos.X, pos.Y);
  2325. +                    }
  2326. +
  2327. +                    //! Sets the new position of the cursor.
  2328. +                    virtual void setPosition(s32 x, s32 y) _IRR_OVERRIDE_
  2329. +                    {
  2330. +                        SDL_WarpMouseInWindow(win, x, y);
  2331. +                    }
  2332. +
  2333. +                    //! Returns the current position of the mouse cursor.
  2334. +                    virtual const core::position2di &getPosition() _IRR_OVERRIDE_
  2335. +                    {
  2336. +                        updateCursorPos();
  2337. +                        return CursorPos;
  2338. +                    }
  2339. +
  2340. +                    //! Returns the current position of the mouse cursor.
  2341. +                    virtual core::position2df getRelativePosition() _IRR_OVERRIDE_
  2342. +                    {
  2343. +                        updateCursorPos();
  2344. +                        return core::position2df(CursorPos.X / f32(Device->Width), CursorPos.Y / f32(Device->Height));
  2345. +                    }
  2346. +
  2347. +                    virtual void setReferenceRect(core::recti* rect = 0) _IRR_OVERRIDE_
  2348. +                    {
  2349. +                    }
  2350. +
  2351. +                private:
  2352. +                    void updateCursorPos()
  2353. +                    {
  2354. +                        CursorPos.X = Device->MouseX;
  2355. +                        CursorPos.Y = Device->MouseY;
  2356. +
  2357. +                        if(CursorPos.X < 0) CursorPos.X = 0;
  2358. +                        if(CursorPos.X > s32(Device->Width)) CursorPos.X = Device->Width;
  2359. +                        if(CursorPos.Y < 0) CursorPos.Y = 0;
  2360. +                        if(CursorPos.Y > s32(Device->Height)) CursorPos.Y = Device->Height;
  2361. +                    }
  2362. +
  2363. +                    CIrrDeviceSDL2* Device;
  2364. +                    core::position2di CursorPos;
  2365. +                    bool IsVisible;
  2366. +                    SDL_Window* win;
  2367. +            };
  2368. +
  2369. +            class SDL2EventReceiver : public IEventReceiver
  2370. +            {
  2371. +                public:
  2372. +                    SDL2EventReceiver() {}
  2373. +
  2374. +                    bool OnEvent(const SEvent& event)
  2375. +                    {
  2376. +                        if(actual && actual->OnEvent(event)) return true;
  2377. +                        #ifdef _IRR_COMPILE_WITH_GUI_
  2378. +                        if(event.EventType == EET_GUI_EVENT && event.GUIEvent.Caller->getType() == gui::EGUIET_EDIT_BOX)
  2379. +                        {
  2380. +                            /*! Show and hide the soft input keyboard when an edit-box get's the focus. */
  2381. +                            switch(event.GUIEvent.EventType)
  2382. +                            {
  2383. +                                case gui::EGET_ELEMENT_FOCUS_LOST:
  2384. +                                    {
  2385. +                                        SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "EGUIET_EDIT_BOX && EGET_ELEMENT_FOCUS_LOST");
  2386. +                                        SDL_StopTextInput();
  2387. +                                    }
  2388. +                                    break;
  2389. +                                case gui::EGET_ELEMENT_FOCUSED:
  2390. +                                    {
  2391. +                                        SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "EGUIET_EDIT_BOX && EGET_ELEMENT_FOCUSED");
  2392. +                                        SDL_StartTextInput();
  2393. +                                    }
  2394. +                                    break;
  2395. +                                case gui::EGET_EDITBOX_CHANGED:
  2396. +                                    {
  2397. +                                        SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "EGUIET_EDIT_BOX && EGET_EDITBOX_CHANGED");
  2398. +                                    }
  2399. +                                    break;
  2400. +                                default:
  2401. +                                    {
  2402. +                                        SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "EGUIET_EDIT_BOX unhandled %d", event.GUIEvent.EventType);
  2403. +                                    }
  2404. +                                    break;
  2405. +                            }
  2406. +                        }
  2407. +                        #endif // _IRR_COMPILE_WITH_GUI_
  2408. +                        return false;
  2409. +                    }
  2410. +
  2411. +                    IEventReceiver* actual;
  2412. +            };
  2413. +
  2414. +        private:
  2415. +            //! create the driver
  2416. +            void createDriver();
  2417. +
  2418. +            bool createWindow();
  2419. +
  2420. +            bool createRenderer();
  2421. +
  2422. +            void createKeyMap();
  2423. +
  2424. +            void updateWindowSize();
  2425. +
  2426. +            #if defined(_IRR_COMPILE_WITH_JOYSTICK_EVENTS_)
  2427. +            core::array<SDL_Joystick*> Joysticks;
  2428. +            core::array<SJoystickInfo>* joyinfo;
  2429. +            #endif
  2430. +
  2431. +            s32 MouseX, MouseY;
  2432. +            u32 MouseButtonStates;
  2433. +
  2434. +            u32 Width, Height;
  2435. +
  2436. +            bool Resizable;
  2437. +            bool WindowHasFocus;
  2438. +            bool WindowMinimized;
  2439. +
  2440. +            struct SKeyMap
  2441. +            {
  2442. +                SKeyMap() : SDLKey(SDLK_UNKNOWN), IrrKey(KEY_OEM_8) {}
  2443. +                SKeyMap(s32 sdlk, s32 irrk) : SDLKey(sdlk), IrrKey(irrk) {}
  2444. +
  2445. +                s32 SDLKey;
  2446. +                s32 IrrKey;
  2447. +
  2448. +                bool operator< (const SKeyMap &o) const
  2449. +                {
  2450. +                    return SDLKey < o.SDLKey;
  2451. +                }
  2452. +            };
  2453. +
  2454. +            core::array<SKeyMap> KeyMap;
  2455. +            SDL_SysWMinfo Info;
  2456. +            SDL_Window* window;
  2457. +            SDL_GLContext glContext;
  2458. +            SDL_Renderer* renderer;
  2459. +            int rendFlags, winFlags;
  2460. +
  2461. +            video::SExposedVideoData filler;
  2462. +
  2463. +            SDL2EventReceiver* sdlEventReceiver;
  2464. +   };
  2465. +
  2466. +} // end namespace irr
  2467. +
  2468. +#endif // _IRR_COMPILE_WITH_SDL2_DEVICE_
  2469. +#endif // __C_IRR_DEVICE_SDL2_H_INCLUDED__
  2470. +
  2471. Index: source/Irrlicht/CLogger.cpp
  2472. ===================================================================
  2473. --- source/Irrlicht/CLogger.cpp (revision 4940)
  2474. +++ source/Irrlicht/CLogger.cpp (working copy)
  2475. @@ -4,6 +4,10 @@
  2476.  
  2477.  #include "CLogger.h"
  2478.  
  2479. +#if defined(_IRR_COMPILE_WITH_SDL2_DEVICE_)
  2480. +#include <SDL2/SDL_log.h>
  2481. +#endif // defined
  2482. +
  2483.  namespace irr
  2484.  {
  2485.  
  2486. @@ -25,13 +29,32 @@
  2487.     void CLogger::setLogLevel(ELOG_LEVEL ll)
  2488.     {
  2489.         LogLevel = ll;
  2490. +       #if defined(_IRR_COMPILE_WITH_SDL2_DEVICE_)
  2491. +        switch (ll)
  2492. +        {
  2493. +            case ELL_DEBUG:
  2494. +                SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG);
  2495. +                break;
  2496. +            case ELL_INFORMATION:
  2497. +                SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
  2498. +                break;
  2499. +            case ELL_WARNING:
  2500. +                SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN);
  2501. +                break;
  2502. +            case ELL_ERROR:
  2503. +                SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_ERROR);
  2504. +                break;
  2505. +            default: // ELL_NONE
  2506. +                SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_CRITICAL);
  2507. +                break;
  2508. +        }
  2509. +        #endif // defined
  2510.     }
  2511.  
  2512.     //! Prints out a text into the log
  2513.     void CLogger::log(const c8* text, ELOG_LEVEL ll)
  2514.     {
  2515. -       if (ll < LogLevel)
  2516. -           return;
  2517. +       if(ll < LogLevel) return;
  2518.  
  2519.         if (Receiver)
  2520.         {
  2521. Index: source/Irrlicht/COGLES2Driver.cpp
  2522. ===================================================================
  2523. --- source/Irrlicht/COGLES2Driver.cpp   (revision 4940)
  2524. +++ source/Irrlicht/COGLES2Driver.cpp   (working copy)
  2525. @@ -1,6 +1,10 @@
  2526.  // Copyright (C) 2014 Patryk Nadrowski
  2527.  // This file is part of the "Irrlicht Engine".
  2528. -// For conditions of distribution and use, see copyright notice in Irrlicht.h
  2529. +// For conditions of distribution and use, see copyright notice in Irrlicht.h
  2530. +//
  2531. +// SDL2 upgrade
  2532. +// Jonathan Frisch
  2533. +// Sep 15, 2014
  2534.  
  2535.  #include "COGLES2Driver.h"
  2536.  // needed here also because of the create methods' parameters
  2537. @@ -34,22 +38,11 @@
  2538.  {
  2539.  
  2540.  COGLES2Driver::COGLES2Driver(const SIrrlichtCreationParameters& params,
  2541. -           io::IFileSystem* io
  2542. -#if defined(_IRR_COMPILE_WITH_X11_DEVICE_) || defined(_IRR_WINDOWS_API_) || defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_) || defined(_IRR_COMPILE_WITH_FB_DEVICE_)
  2543. -            , IContextManager* contextManager
  2544. -#elif defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_)
  2545. -            , CIrrDeviceIPhone* device
  2546. -#endif
  2547. -            ) : CNullDriver(io, params.WindowSize), COGLES2ExtensionHandler(),
  2548. -   CurrentRenderMode(ERM_NONE), ResetRenderStates(true),
  2549. -   Transformation3DChanged(true), AntiAlias(params.AntiAlias), OGLES2ShaderPath(params.OGLES2ShaderPath),
  2550. -   RenderTargetTexture(0), CurrentRendertargetSize(0, 0), ColorFormat(ECF_R8G8B8), BridgeCalls(0)
  2551. -#if defined(_IRR_COMPILE_WITH_X11_DEVICE_) || defined(_IRR_WINDOWS_API_) || defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_) || defined(_IRR_COMPILE_WITH_FB_DEVICE_)
  2552. -    , ContextManager(contextManager)
  2553. -#elif defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_)
  2554. -    , Device(device), ViewFramebuffer(0),
  2555. -   ViewRenderbuffer(0), ViewDepthRenderbuffer(0)
  2556. -#endif
  2557. +           io::IFileSystem* io, IContextManager* contextManager) :
  2558. +        CNullDriver(io, params.WindowSize), COGLES2ExtensionHandler(), CurrentRenderMode(ERM_NONE),
  2559. +        ResetRenderStates(true), Transformation3DChanged(true), AntiAlias(params.AntiAlias),
  2560. +        OGLES2ShaderPath(params.OGLES2ShaderPath), RenderTargetTexture(0), CurrentRendertargetSize(0, 0),
  2561. +        ColorFormat(ECF_R8G8B8), BridgeCalls(0), ContextManager(contextManager)
  2562.     {
  2563.  #ifdef _DEBUG
  2564.     setDebugName("COGLES2Driver");
  2565. @@ -56,9 +49,8 @@
  2566.  #endif
  2567.  
  2568.      core::dimension2d<u32> WindowSize(0, 0);
  2569. -
  2570. -#if defined(_IRR_COMPILE_WITH_X11_DEVICE_) || defined(_IRR_WINDOWS_API_) || defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_) || defined(_IRR_COMPILE_WITH_FB_DEVICE_)
  2571. -   if (!ContextManager)
  2572. +
  2573. +    if (!ContextManager)
  2574.         return;
  2575.  
  2576.     ContextManager->grab();
  2577. @@ -68,7 +60,25 @@
  2578.     ContextManager->activateContext(ExposedData);
  2579.  
  2580.     WindowSize = params.WindowSize;
  2581. -#elif defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_)
  2582. +
  2583. +   genericDriverInit(WindowSize, params.Stencilbuffer);
  2584. +}
  2585. +
  2586. +#if defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_)
  2587. +COGLES2Driver::COGLES2Driver(const SIrrlichtCreationParameters& params,
  2588. +           io::IFileSystem* io, CIrrDeviceIPhone* device) : CNullDriver(io, params.WindowSize), COGLES2ExtensionHandler(),
  2589. +   CurrentRenderMode(ERM_NONE), ResetRenderStates(true),
  2590. +   Transformation3DChanged(true), AntiAlias(params.AntiAlias), OGLES2ShaderPath(params.OGLES2ShaderPath),
  2591. +   RenderTargetTexture(0), CurrentRendertargetSize(0, 0), ColorFormat(ECF_R8G8B8), BridgeCalls(0)
  2592. +    , Device(device), ViewFramebuffer(0),
  2593. +   ViewRenderbuffer(0), ViewDepthRenderbuffer(0)
  2594. +   {
  2595. +#ifdef _DEBUG
  2596. +   setDebugName("COGLES2Driver");
  2597. +#endif
  2598. +
  2599. +    core::dimension2d<u32> WindowSize(0, 0);
  2600. +
  2601.     glGenFramebuffers(1, &ViewFramebuffer);
  2602.     glGenRenderbuffers(1, &ViewRenderbuffer);
  2603.     glBindRenderbuffer(GL_RENDERBUFFER, ViewRenderbuffer);
  2604. @@ -98,10 +108,10 @@
  2605.     WindowSize = core::dimension2d<u32>(backingWidth, backingHeight);
  2606.     CNullDriver::ScreenSize = WindowSize;
  2607.     CNullDriver::ViewPort = core::rect<s32>(core::position2d<s32>(0,0), core::dimension2di(WindowSize));
  2608. -#endif
  2609.  
  2610.     genericDriverInit(WindowSize, params.Stencilbuffer);
  2611. -}
  2612. +}
  2613. +#endif
  2614.  
  2615.  COGLES2Driver::~COGLES2Driver()
  2616.  {
  2617. @@ -113,7 +123,7 @@
  2618.  
  2619.     delete BridgeCalls;
  2620.  
  2621. -#if defined(_IRR_COMPILE_WITH_X11_DEVICE_) || defined(_IRR_WINDOWS_API_) || defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_) || defined(_IRR_COMPILE_WITH_FB_DEVICE_)
  2622. +#if !defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_)
  2623.     if (ContextManager)
  2624.     {
  2625.         ContextManager->destroyContext();
  2626. @@ -120,7 +130,7 @@
  2627.         ContextManager->destroySurface();
  2628.         ContextManager->drop();
  2629.     }
  2630. -#elif defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_)
  2631. +#else
  2632.     if (0 != ViewFramebuffer)
  2633.     {
  2634.         glDeleteFramebuffers(1,&ViewFramebuffer);
  2635. @@ -454,10 +464,9 @@
  2636.  {
  2637.     CNullDriver::endScene();
  2638.  
  2639. -#if defined(_IRR_COMPILE_WITH_X11_DEVICE_) || defined(_IRR_WINDOWS_API_) || defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_) || defined(_IRR_COMPILE_WITH_FB_DEVICE_)
  2640. -    if (ContextManager)
  2641. -       ContextManager->swapBuffers();
  2642. -#elif defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_)
  2643. +#if !defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_)
  2644. +    if(ContextManager) ContextManager->swapBuffers();
  2645. +#else
  2646.      glFlush();
  2647.     glBindRenderbuffer(GL_RENDERBUFFER, ViewRenderbuffer);
  2648.      Device->displayEnd();
  2649. @@ -3004,29 +3013,27 @@
  2650.  
  2651.  #ifndef _IRR_COMPILE_WITH_OGLES2_
  2652.  class IContextManager;
  2653. -#endif
  2654. +#endif
  2655. +
  2656. +IVideoDriver* createOGLES2Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager)
  2657. +{
  2658. +    #ifdef _IRR_COMPILE_WITH_OGLES2_
  2659. +    return new COGLES2Driver(params, io, contextManager);
  2660. +    #else
  2661. +    return NULL;
  2662. +    #endif
  2663. +}
  2664. +
  2665. +#if defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_)
  2666. +IVideoDriver* createOGLES2Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, CIrrDeviceIPhone* device)
  2667. +{
  2668. +    #ifdef _IRR_COMPILE_WITH_OGLES2_
  2669. +    return new COGLES2Driver(params, io, device);
  2670. +    #else
  2671. +    return NULL;
  2672. +    #endif
  2673. +}
  2674. +#endif // defined
  2675.  
  2676. -IVideoDriver* createOGLES2Driver(const SIrrlichtCreationParameters& params,
  2677. -       io::IFileSystem* io
  2678. -#if defined(_IRR_COMPILE_WITH_X11_DEVICE_) || defined(_IRR_WINDOWS_API_) || defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_) || defined(_IRR_COMPILE_WITH_FB_DEVICE_)
  2679. -        , IContextManager* contextManager
  2680. -#elif defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_)
  2681. -        , CIrrDeviceIPhone* device
  2682. -#endif
  2683. -    )
  2684. -{
  2685. -#ifdef _IRR_COMPILE_WITH_OGLES2_
  2686. -   return new COGLES2Driver(params, io
  2687. -#if defined(_IRR_COMPILE_WITH_X11_DEVICE_) || defined(_IRR_WINDOWS_API_) || defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_) || defined(_IRR_COMPILE_WITH_FB_DEVICE_)
  2688. -        , contextManager
  2689. -#elif defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_)
  2690. -        , device
  2691. -#endif
  2692. -    );
  2693. -#else
  2694. -   return 0;
  2695. -#endif //  _IRR_COMPILE_WITH_OGLES2_
  2696. -}
  2697. -
  2698.  } // end namespace
  2699.  } // end namespace
  2700. Index: source/Irrlicht/COGLES2Driver.h
  2701. ===================================================================
  2702. --- source/Irrlicht/COGLES2Driver.h (revision 4940)
  2703. +++ source/Irrlicht/COGLES2Driver.h (working copy)
  2704. @@ -1,6 +1,10 @@
  2705.  // Copyright (C) 2014 Patryk Nadrowski
  2706.  // This file is part of the "Irrlicht Engine".
  2707. -// For conditions of distribution and use, see copyright notice in Irrlicht.h
  2708. +// For conditions of distribution and use, see copyright notice in Irrlicht.h
  2709. +//
  2710. +// SDL2 upgrade
  2711. +// Jonathan Frisch
  2712. +// Sep 15, 2014
  2713.  
  2714.  #ifndef __C_OGLES2_DRIVER_H_INCLUDED__
  2715.  #define __C_OGLES2_DRIVER_H_INCLUDED__
  2716. @@ -50,14 +54,11 @@
  2717.  
  2718.     public:
  2719.         //! constructor
  2720. -       COGLES2Driver(const SIrrlichtCreationParameters& params,
  2721. -               io::IFileSystem* io
  2722. -#if defined(_IRR_COMPILE_WITH_X11_DEVICE_) || defined(_IRR_WINDOWS_API_) || defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_) || defined(_IRR_COMPILE_WITH_FB_DEVICE_)
  2723. -       , IContextManager* contextManager
  2724. -#elif defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_)
  2725. -       , CIrrDeviceIPhone* device
  2726. +       COGLES2Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager);
  2727. +#if defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_)
  2728. +        //! IPhone constructor
  2729. +       COGLES2Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, CIrrDeviceIPhone* device);
  2730.  #endif
  2731. -       );
  2732.  
  2733.         //! destructor
  2734.         virtual ~COGLES2Driver();
  2735. @@ -516,7 +517,7 @@
  2736.         GLuint ViewFramebuffer;
  2737.         GLuint ViewRenderbuffer;
  2738.         GLuint ViewDepthRenderbuffer;
  2739. -#elif defined(_IRR_COMPILE_WITH_X11_DEVICE_) || defined(_IRR_WINDOWS_API_) || defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_) || defined(_IRR_COMPILE_WITH_FB_DEVICE_)
  2740. +#else
  2741.         IContextManager* ContextManager;
  2742.  #endif
  2743.     };
  2744. Index: source/Irrlicht/COGLES2ExtensionHandler.h
  2745. ===================================================================
  2746. --- source/Irrlicht/COGLES2ExtensionHandler.h   (revision 4940)
  2747. +++ source/Irrlicht/COGLES2ExtensionHandler.h   (working copy)
  2748. @@ -2,7 +2,11 @@
  2749.  // Heavily based on the OpenGL driver implemented by Nikolaus Gebhardt
  2750.  // and OpenGL ES driver implemented by Christian Stehno
  2751.  // This file is part of the "Irrlicht Engine".
  2752. -// For conditions of distribution and use, see copyright notice in Irrlicht.h
  2753. +// For conditions of distribution and use, see copyright notice in Irrlicht.h
  2754. +//
  2755. +// SDL2 upgrade
  2756. +// Jonathan Frisch
  2757. +// Sep 15, 2014
  2758.  
  2759.  #ifndef __C_OGLES2_EXTENSION_HANDLER_H_INCLUDED__
  2760.  #define __C_OGLES2_EXTENSION_HANDLER_H_INCLUDED__
  2761. @@ -11,25 +15,19 @@
  2762.  
  2763.  #ifdef _IRR_COMPILE_WITH_OGLES2_
  2764.  
  2765. -#if defined(_IRR_COMPILE_WITH_X11_DEVICE_) || defined(_IRR_WINDOWS_API_) || defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_)
  2766. +#if !defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_)
  2767.  #include "CEGLManager.h"
  2768. -#elif defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_)
  2769. +#else
  2770.  #include "iOS/CIrrDeviceiOS.h"
  2771. -#endif
  2772. +#endif
  2773.  
  2774.  #if defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_)
  2775.  #include <OpenGLES/ES2/gl.h>
  2776.  #include <OpenGLES/ES2/glext.h>
  2777. -#elif defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_)
  2778. +#else
  2779.  #include <GLES2/gl2.h>
  2780.  #include <GLES2/gl2ext.h>
  2781. -#else
  2782. -#include <GLES2/gl2.h>
  2783. -typedef char GLchar;
  2784. -#if defined(_IRR_OGLES2_USE_EXTPOINTER_)
  2785. -#include "gles2-ext.h"
  2786.  #endif
  2787. -#endif
  2788.  
  2789.  #include "os.h"
  2790.  #include "EDriverFeatures.h"
  2791. Index: source/Irrlicht/COGLES2MaterialRenderer.h
  2792. ===================================================================
  2793. --- source/Irrlicht/COGLES2MaterialRenderer.h   (revision 4940)
  2794. +++ source/Irrlicht/COGLES2MaterialRenderer.h   (working copy)
  2795. @@ -28,7 +28,7 @@
  2796.  
  2797.  namespace irr
  2798.  {
  2799. -namespace video  
  2800. +namespace video
  2801.  {
  2802.  
  2803.  class COGLES2Driver;
  2804. @@ -38,8 +38,8 @@
  2805.  public:
  2806.  
  2807.     COGLES2MaterialRenderer(
  2808. -       COGLES2Driver* driver,
  2809. -       s32& outMaterialTypeNr,
  2810. +       COGLES2Driver* driver,
  2811. +       s32& outMaterialTypeNr,
  2812.         const c8* vertexShaderProgram = 0,
  2813.         const c8* pixelShaderProgram = 0,
  2814.         IShaderConstantSetCallBack* callback = 0,
  2815. @@ -62,7 +62,7 @@
  2816.     virtual s32 getRenderCapability() const;
  2817.  
  2818.     virtual void setBasicRenderStates(const SMaterial& material, const SMaterial& lastMaterial, bool resetAllRenderstates);
  2819. -  
  2820. +
  2821.     virtual s32 getVertexShaderConstantID(const c8* name);
  2822.     virtual s32 getPixelShaderConstantID(const c8* name);
  2823.     virtual void setVertexShaderConstant(const f32* data, s32 startRegister, s32 constantAmount=1);
  2824. @@ -85,7 +85,7 @@
  2825.  
  2826.     bool createShader(GLenum shaderType, const char* shader);
  2827.     bool linkProgram();
  2828. -  
  2829. +
  2830.     COGLES2Driver* Driver;
  2831.     IShaderConstantSetCallBack* CallBack;
  2832.  
  2833. Index: source/Irrlicht/COGLES2Texture.h
  2834. ===================================================================
  2835. --- source/Irrlicht/COGLES2Texture.h    (revision 4940)
  2836. +++ source/Irrlicht/COGLES2Texture.h    (working copy)
  2837. @@ -7,7 +7,7 @@
  2838.  
  2839.  #include "IrrCompileConfig.h"
  2840.  
  2841. -#ifdef _IRR_COMPILE_WITH_OGLES2_
  2842. +#ifdef _IRR_COMPILE_WITH_OGLES2_
  2843.  
  2844.  #if defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_)
  2845.  #include <OpenGLES/ES2/gl.h>
  2846. Index: source/Irrlicht/COGLESDriver.cpp
  2847. ===================================================================
  2848. --- source/Irrlicht/COGLESDriver.cpp    (revision 4940)
  2849. +++ source/Irrlicht/COGLESDriver.cpp    (working copy)
  2850. @@ -1,6 +1,10 @@
  2851.  // Copyright (C) 2002-2008 Nikolaus Gebhardt
  2852.  // This file is part of the "Irrlicht Engine".
  2853. -// For conditions of distribution and use, see copyright notice in irrlicht.h
  2854. +// For conditions of distribution and use, see copyright notice in irrlicht.h
  2855. +//
  2856. +// SDL2 upgrade
  2857. +// Jonathan Frisch
  2858. +// Sep 15, 2014
  2859.  
  2860.  #include "COGLESDriver.h"
  2861.  #include "SIrrCreationParameters.h" // for createDriver function
  2862. @@ -14,10 +18,6 @@
  2863.  #include "CImage.h"
  2864.  #include "os.h"
  2865.  
  2866. -#ifdef _IRR_COMPILE_WITH_SDL_DEVICE_
  2867. -#include <SDL/SDL.h>
  2868. -#endif
  2869. -
  2870.  namespace irr
  2871.  {
  2872.  namespace video
  2873. @@ -24,22 +24,10 @@
  2874.  {
  2875.  
  2876.  COGLES1Driver::COGLES1Driver(const SIrrlichtCreationParameters& params,
  2877. -            io::IFileSystem* io
  2878. -#if defined(_IRR_COMPILE_WITH_X11_DEVICE_) || defined(_IRR_WINDOWS_API_) || defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_) || defined(_IRR_COMPILE_WITH_FB_DEVICE_)
  2879. -            , IContextManager* contextManager
  2880. -#elif defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_)
  2881. -            , CIrrDeviceIPhone* device
  2882. -#endif
  2883. -            ) : CNullDriver(io, params.WindowSize), COGLES1ExtensionHandler(),
  2884. +            io::IFileSystem* io, IContextManager* contextManager) : CNullDriver(io, params.WindowSize), COGLES1ExtensionHandler(),
  2885.     CurrentRenderMode(ERM_NONE), ResetRenderStates(true),
  2886.     Transformation3DChanged(true), AntiAlias(params.AntiAlias),
  2887. -   RenderTargetTexture(0), CurrentRendertargetSize(0,0), ColorFormat(ECF_R8G8B8), BridgeCalls(0)
  2888. -#if defined(_IRR_COMPILE_WITH_X11_DEVICE_) || defined(_IRR_WINDOWS_API_) || defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_) || defined(_IRR_COMPILE_WITH_FB_DEVICE_)
  2889. -    , ContextManager(contextManager)
  2890. -#elif defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_)
  2891. -    , Device(device), ViewFramebuffer(0),
  2892. -   ViewRenderbuffer(0), ViewDepthRenderbuffer(0)
  2893. -#endif
  2894. +   RenderTargetTexture(0), CurrentRendertargetSize(0,0), ColorFormat(ECF_R8G8B8), BridgeCalls(0), ContextManager(contextManager)
  2895.  {
  2896.  #ifdef _DEBUG
  2897.     setDebugName("COGLESDriver");
  2898. @@ -46,9 +34,7 @@
  2899.  #endif
  2900.  
  2901.      core::dimension2d<u32> WindowSize(0, 0);
  2902. -
  2903. -#if defined(_IRR_COMPILE_WITH_X11_DEVICE_) || defined(_IRR_WINDOWS_API_) || defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_) || defined(_IRR_COMPILE_WITH_FB_DEVICE_)
  2904. -   if (!ContextManager)
  2905. +    if (!ContextManager)
  2906.         return;
  2907.  
  2908.     ContextManager->grab();
  2909. @@ -58,7 +44,24 @@
  2910.     ContextManager->activateContext(ExposedData);
  2911.  
  2912.     WindowSize = params.WindowSize;
  2913. -#elif defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_)
  2914. +
  2915. +    genericDriverInit(WindowSize, params.Stencilbuffer);
  2916. +}
  2917. +
  2918. +#if defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_)
  2919. +COGLES1Driver::COGLES1Driver(const SIrrlichtCreationParameters& params,
  2920. +            io::IFileSystem* io, CIrrDeviceIPhone* device) : CNullDriver(io, params.WindowSize), COGLES1ExtensionHandler(),
  2921. +   CurrentRenderMode(ERM_NONE), ResetRenderStates(true),
  2922. +   Transformation3DChanged(true), AntiAlias(params.AntiAlias),
  2923. +   RenderTargetTexture(0), CurrentRendertargetSize(0,0), ColorFormat(ECF_R8G8B8), BridgeCalls(0), Device(device), ViewFramebuffer(0),
  2924. +   ViewRenderbuffer(0), ViewDepthRenderbuffer(0)
  2925. +{
  2926. +#ifdef _DEBUG
  2927. +   setDebugName("COGLESDriver");
  2928. +#endif
  2929. +
  2930. +    core::dimension2d<u32> WindowSize(0, 0);
  2931. +
  2932.     glGenFramebuffersOES(1, &ViewFramebuffer);
  2933.     glGenRenderbuffersOES(1, &ViewRenderbuffer);
  2934.     glBindRenderbufferOES(GL_RENDERBUFFER_OES, ViewRenderbuffer);
  2935. @@ -88,10 +91,10 @@
  2936.      WindowSize = core::dimension2d<u32>(backingWidth, backingHeight);
  2937.      CNullDriver::ScreenSize = WindowSize;
  2938.      CNullDriver::ViewPort = core::rect<s32>(core::position2d<s32>(0,0), core::dimension2di(WindowSize));
  2939. -#endif
  2940.  
  2941.      genericDriverInit(WindowSize, params.Stencilbuffer);
  2942. -}
  2943. +}
  2944. +#endif // defined
  2945.  
  2946.  COGLES1Driver::~COGLES1Driver()
  2947.  {
  2948. @@ -102,7 +105,7 @@
  2949.  
  2950.     delete BridgeCalls;
  2951.  
  2952. -#if defined(_IRR_COMPILE_WITH_X11_DEVICE_) || defined(_IRR_WINDOWS_API_) || defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_) || defined(_IRR_COMPILE_WITH_FB_DEVICE_)
  2953. +#if !defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_)
  2954.     if (ContextManager)
  2955.     {
  2956.         ContextManager->destroyContext();
  2957. @@ -109,7 +112,7 @@
  2958.         ContextManager->destroySurface();
  2959.         ContextManager->drop();
  2960.     }
  2961. -#elif defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_)
  2962. +#else
  2963.     if (0 != ViewFramebuffer)
  2964.     {
  2965.         extGlDeleteFramebuffers(1,&ViewFramebuffer);
  2966. @@ -265,9 +268,9 @@
  2967.  {
  2968.     CNullDriver::endScene();
  2969.  
  2970. -#if defined(_IRR_COMPILE_WITH_X11_DEVICE_) || defined(_IRR_WINDOWS_API_) || defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_) || defined(_IRR_COMPILE_WITH_FB_DEVICE_)
  2971. -    ContextManager->swapBuffers();
  2972. -#elif defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_)
  2973. +#if !defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_)
  2974. +    if(ContextManager) ContextManager->swapBuffers();
  2975. +#else
  2976.      glFlush();
  2977.     glBindRenderbufferOES(GL_RENDERBUFFER_OES, ViewRenderbuffer);
  2978.      Device->displayEnd();
  2979. @@ -3234,27 +3237,25 @@
  2980.  class IContextManager;
  2981.  #endif
  2982.  
  2983. -IVideoDriver* createOGLES1Driver(const SIrrlichtCreationParameters& params,
  2984. -       io::IFileSystem* io
  2985. -#if defined(_IRR_COMPILE_WITH_X11_DEVICE_) || defined(_IRR_WINDOWS_API_) || defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_) || defined(_IRR_COMPILE_WITH_FB_DEVICE_)
  2986. -        , IContextManager* contextManager
  2987. -#elif defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_)
  2988. -        , CIrrDeviceIPhone* device
  2989. -#endif
  2990. -    )
  2991. +IVideoDriver* createOGLES1Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager)
  2992.  {
  2993. -#ifdef _IRR_COMPILE_WITH_OGLES1_
  2994. -   return new COGLES1Driver(params, io
  2995. -#if defined(_IRR_COMPILE_WITH_X11_DEVICE_) || defined(_IRR_WINDOWS_API_) || defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_) || defined(_IRR_COMPILE_WITH_FB_DEVICE_)
  2996. -        , contextManager
  2997. -#elif defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_)
  2998. -        , device
  2999. -#endif
  3000. -    );
  3001. -#else
  3002. +    #ifdef _IRR_COMPILE_WITH_OGLES1_
  3003. +   return new COGLES1Driver(params, io, contextManager);
  3004. +    #else
  3005.     return 0;
  3006. -#endif //  _IRR_COMPILE_WITH_OGLES1_
  3007. +    #endif //  _IRR_COMPILE_WITH_OGLES1_
  3008.  }
  3009. +
  3010. +#if defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_)
  3011. +IVideoDriver* createOGLES1Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, CIrrDeviceIPhone* device)
  3012. +{
  3013. +    #ifdef _IRR_COMPILE_WITH_OGLES1_
  3014. +   return new COGLES1Driver(params, io, device);
  3015. +    #else
  3016. +   return 0;
  3017. +    #endif //  _IRR_COMPILE_WITH_OGLES1_
  3018. +}
  3019. +#endif // defined
  3020.  
  3021.  } // end namespace
  3022.  } // end namespace
  3023. Index: source/Irrlicht/COGLESDriver.h
  3024. ===================================================================
  3025. --- source/Irrlicht/COGLESDriver.h  (revision 4940)
  3026. +++ source/Irrlicht/COGLESDriver.h  (working copy)
  3027. @@ -1,6 +1,10 @@
  3028.  // Copyright (C) 2002-2008 Nikolaus Gebhardt
  3029.  // This file is part of the "Irrlicht Engine".
  3030. -// For conditions of distribution and use, see copyright notice in Irrlicht.h
  3031. +// For conditions of distribution and use, see copyright notice in Irrlicht.h
  3032. +//
  3033. +// SDL2 upgrade
  3034. +// Jonathan Frisch
  3035. +// Sep 15, 2014
  3036.  
  3037.  #ifndef __C_OGLES_DRIVER_H_INCLUDED__
  3038.  #define __C_OGLES_DRIVER_H_INCLUDED__
  3039. @@ -35,14 +39,11 @@
  3040.         friend class COGLES1Texture;
  3041.     public:
  3042.         //! constructor
  3043. -       COGLES1Driver(const SIrrlichtCreationParameters& params,
  3044. -               io::IFileSystem* io
  3045. -#if defined(_IRR_COMPILE_WITH_X11_DEVICE_) || defined(_IRR_WINDOWS_API_) || defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_) || defined(_IRR_COMPILE_WITH_FB_DEVICE_)
  3046. -                , IContextManager* contextManager
  3047. -#elif defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_)
  3048. -                , CIrrDeviceIPhone* device
  3049. +       COGLES1Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager);
  3050. +#if defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_)
  3051. +        //! IPhone constructor
  3052. +        COGLES1Driver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, CIrrDeviceIPhone* device);
  3053.  #endif
  3054. -                );
  3055.  
  3056.         //! destructor
  3057.         virtual ~COGLES1Driver();
  3058. @@ -449,7 +450,7 @@
  3059.         GLuint ViewFramebuffer;
  3060.         GLuint ViewRenderbuffer;
  3061.         GLuint ViewDepthRenderbuffer;
  3062. -#elif defined(_IRR_COMPILE_WITH_X11_DEVICE_) || defined(_IRR_WINDOWS_API_) || defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_) || defined(_IRR_COMPILE_WITH_FB_DEVICE_)
  3063. +#else
  3064.          IContextManager* ContextManager;
  3065.  #endif
  3066.     };
  3067. Index: source/Irrlicht/COGLESExtensionHandler.h
  3068. ===================================================================
  3069. --- source/Irrlicht/COGLESExtensionHandler.h    (revision 4940)
  3070. +++ source/Irrlicht/COGLESExtensionHandler.h    (working copy)
  3071. @@ -1,7 +1,11 @@
  3072.  // Copyright (C) 2008 Christian Stehno
  3073.  // Heavily based on the OpenGL driver implemented by Nikolaus Gebhardt
  3074.  // This file is part of the "Irrlicht Engine".
  3075. -// For conditions of distribution and use, see copyright notice in Irrlicht.h
  3076. +// For conditions of distribution and use, see copyright notice in Irrlicht.h
  3077. +//
  3078. +// SDL2 upgrade
  3079. +// Jonathan Frisch
  3080. +// Sep 15, 2014
  3081.  
  3082.  #ifndef __C_OGLES_EXTENSION_HANDLER_H_INCLUDED__
  3083.  #define __C_OGLES_EXTENSION_HANDLER_H_INCLUDED__
  3084. @@ -10,25 +14,25 @@
  3085.  
  3086.  #ifdef _IRR_COMPILE_WITH_OGLES1_
  3087.  
  3088. -#if defined(_IRR_COMPILE_WITH_X11_DEVICE_) || defined(_IRR_WINDOWS_API_) || defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_)
  3089. +#if !defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_)
  3090.  #include "CEGLManager.h"
  3091. -#elif defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_)
  3092. +#else
  3093.  #include "iOS/CIrrDeviceiOS.h"
  3094. -#endif
  3095. +#endif
  3096.  
  3097.  #if defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_)
  3098.  #include <OpenGLES/ES1/gl.h>
  3099.  #include <OpenGLES/ES1/glext.h>
  3100. -#elif defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_)
  3101. +#else
  3102.  #include <GLES/gl.h>
  3103.  #include <GLES/glext.h>
  3104. -#else
  3105. -#include <GLES/gl.h>
  3106. -typedef char GLchar;
  3107. -#if defined(_IRR_OGLES1_USE_EXTPOINTER_)
  3108. -#include "gles-ext.h"
  3109. +//#else
  3110. +//#include <GLES/gl.h>
  3111. +//typedef char GLchar;
  3112. +//#if defined(_IRR_OGLES1_USE_EXTPOINTER_)
  3113. +//#include "gles-ext.h"
  3114. +//#endif
  3115.  #endif
  3116. -#endif
  3117.  
  3118.  #include "os.h"
  3119.  #include "EDriverFeatures.h"
  3120. Index: source/Irrlicht/COGLESTexture.h
  3121. ===================================================================
  3122. --- source/Irrlicht/COGLESTexture.h (revision 4940)
  3123. +++ source/Irrlicht/COGLESTexture.h (working copy)
  3124. @@ -1,6 +1,10 @@
  3125.  // Copyright (C) 2002-2008 Nikolaus Gebhardt
  3126.  // This file is part of the "Irrlicht Engine".
  3127. -// For conditions of distribution and use, see copyright notice in irrlicht.h
  3128. +// For conditions of distribution and use, see copyright notice in irrlicht.h
  3129. +//
  3130. +// SDL2 upgrade
  3131. +// Jonathan Frisch
  3132. +// Sep 15, 2014
  3133.  
  3134.  #ifndef __C_OGLES1_TEXTURE_H_INCLUDED__
  3135.  #define __C_OGLES1_TEXTURE_H_INCLUDED__
  3136. @@ -9,16 +13,16 @@
  3137.  #include "IImage.h"
  3138.  
  3139.  #include "IrrCompileConfig.h"
  3140. -#if defined(_IRR_COMPILE_WITH_OGLES1_)
  3141. +#if defined(_IRR_COMPILE_WITH_OGLES1_)
  3142.  
  3143.  #if defined(_IRR_COMPILE_WITH_IPHONE_DEVICE_)
  3144.  #include <OpenGLES/ES1/gl.h>
  3145.  #include <OpenGLES/ES1/glext.h>
  3146. -#elif defined(_IRR_ANDROID_PLATFORM_)
  3147. +#else
  3148.  #include <GLES/gl.h>
  3149.  #include <GLES/glext.h>
  3150. -#else
  3151. -#include <GLES/egl.h>
  3152. +//#else
  3153. +//#include <GLES/egl.h>
  3154.  #endif
  3155.  
  3156.  namespace irr
  3157. @@ -90,7 +94,7 @@
  3158.  
  3159.     //! get the desired color format based on texture creation flags and the input format.
  3160.     ECOLOR_FORMAT getBestColorFormat(ECOLOR_FORMAT format);
  3161. -    
  3162. +
  3163.      //! Get the OpenGL color format parameters based on the given Irrlicht color format
  3164.     void getFormatParameters(ECOLOR_FORMAT format, GLint& internalFormat, GLint& filtering,
  3165.         GLenum& pixelFormat, GLenum& type, void(*&convert)(const void*, s32, void*));
  3166. Index: source/Irrlicht/COSOperator.cpp
  3167. ===================================================================
  3168. --- source/Irrlicht/COSOperator.cpp (revision 4940)
  3169. +++ source/Irrlicht/COSOperator.cpp (working copy)
  3170. @@ -1,23 +1,27 @@
  3171.  // Copyright (C) 2002-2012 Nikolaus Gebhardt
  3172.  // This file is part of the "Irrlicht Engine".
  3173.  // For conditions of distribution and use, see copyright notice in irrlicht.h
  3174. +//
  3175. +// SDL2 upgrade
  3176. +// Jonathan Frisch
  3177. +// Sep 15, 2014
  3178.  
  3179.  #include "COSOperator.h"
  3180.  
  3181.  #ifdef _IRR_WINDOWS_API_
  3182. -#ifndef _IRR_XBOX_PLATFORM_
  3183. -#include <windows.h>
  3184. -#endif
  3185. +    #ifndef _IRR_XBOX_PLATFORM_
  3186. +        #include <windows.h>
  3187. +    #endif
  3188.  #else
  3189. -#include <string.h>
  3190. -#include <unistd.h>
  3191. -#ifndef _IRR_SOLARIS_PLATFORM_
  3192. -#ifndef _IRR_ANDROID_PLATFORM_
  3193. -#include <sys/types.h>
  3194. -#include <sys/sysctl.h>
  3195. +    #include <string.h>
  3196. +    #include <unistd.h>
  3197. +    #ifndef _IRR_SOLARIS_PLATFORM_
  3198. +        #ifndef _IRR_ANDROID_PLATFORM_
  3199. +            #include <sys/types.h>
  3200. +            #include <linux/sysctl.h>
  3201. +        #endif
  3202. +    #endif
  3203.  #endif
  3204. -#endif
  3205. -#endif
  3206.  
  3207.  #if defined(_IRR_COMPILE_WITH_X11_DEVICE_)
  3208.  #include "CIrrDeviceLinux.h"
  3209. Index: source/Irrlicht/COpenGLDriver.cpp
  3210. ===================================================================
  3211. --- source/Irrlicht/COpenGLDriver.cpp   (revision 4940)
  3212. +++ source/Irrlicht/COpenGLDriver.cpp   (working copy)
  3213. @@ -1,6 +1,10 @@
  3214.  // Copyright (C) 2002-2012 Nikolaus Gebhardt
  3215.  // This file is part of the "Irrlicht Engine".
  3216.  // For conditions of distribution and use, see copyright notice in irrlicht.h
  3217. +//
  3218. +// SDL2 upgrade
  3219. +// Jonathan Frisch
  3220. +// Sep 15, 2014
  3221.  
  3222.  #include "COpenGLDriver.h"
  3223.  // needed here also because of the create methods' parameters
  3224. @@ -22,6 +26,9 @@
  3225.  #ifdef _IRR_COMPILE_WITH_SDL_DEVICE_
  3226.  #include <SDL/SDL.h>
  3227.  #endif
  3228. +#ifdef _IRR_COMPILE_WITH_SDL2_DEVICE_
  3229. +#include <SDL2/SDL.h>
  3230. +#endif // _IRR_COMPILE_WITH_SDL2_DEVICE_
  3231.  
  3232.  namespace irr
  3233.  {
  3234. @@ -155,6 +162,35 @@
  3235.  
  3236.  
  3237.  // -----------------------------------------------------------------------
  3238. +// SDL2 CONSTRUCTOR
  3239. +// -----------------------------------------------------------------------
  3240. +#ifdef _IRR_COMPILE_WITH_SDL2_DEVICE_
  3241. +//! SDL2 constructor and init code
  3242. +COpenGLDriver::COpenGLDriver(const SIrrlichtCreationParameters& params,
  3243. +       io::IFileSystem* io, CIrrDeviceSDL2* device)
  3244. +    : CNullDriver(io, params.WindowSize), COpenGLExtensionHandler(),
  3245. +   CurrentRenderMode(ERM_NONE), ResetRenderStates(true),
  3246. +   Transformation3DChanged(true), AntiAlias(params.AntiAlias),
  3247. +   RenderTargetTexture(0), CurrentRendertargetSize(0,0),
  3248. +   ColorFormat(ECF_R8G8B8), FixedPipelineState(EOFPS_ENABLE),
  3249. +   CurrentTarget(ERT_FRAME_BUFFER), Params(params), ContextManager(0),
  3250. +   BridgeCalls(0), SDL2Device(device), DeviceType(EIDT_SDL2)
  3251. +{
  3252. +   #ifdef _DEBUG
  3253. +   setDebugName("COpenGLDriver");
  3254. +   #endif
  3255. +
  3256. +   #ifdef _IRR_COMPILE_WITH_CG_
  3257. +   CgContext = 0;
  3258. +   #endif
  3259. +
  3260. +   genericDriverInit();
  3261. +}
  3262. +
  3263. +#endif // _IRR_COMPILE_WITH_SDL2_DEVICE_
  3264. +
  3265. +
  3266. +// -----------------------------------------------------------------------
  3267.  // SDL CONSTRUCTOR
  3268.  // -----------------------------------------------------------------------
  3269.  #ifdef _IRR_COMPILE_WITH_SDL_DEVICE_
  3270. @@ -397,38 +433,33 @@
  3271.  
  3272.     glFlush();
  3273.  
  3274. -#ifdef _IRR_COMPILE_WITH_WINDOWS_DEVICE_
  3275. -   if (DeviceType == EIDT_WIN32)
  3276. +   switch(DeviceType)
  3277.     {
  3278. -       return ContextManager->swapBuffers();
  3279. +       #ifdef _IRR_COMPILE_WITH_SDL2_DEVICE_
  3280. +        case EIDT_SDL2:
  3281. +            SDL_GL_SwapWindow((SDL_Window*)Params.WindowId);
  3282. +            return true;
  3283. +        #endif // _IRR_COMPILE_WITH_SDL2_DEVICE_
  3284. +        #ifdef _IRR_COMPILE_WITH_SDL_DEVICE_
  3285. +        case EIDT_SDL:
  3286. +            SDL_GL_SwapBuffers();
  3287. +            return true;
  3288. +        #endif // _IRR_COMPILE_WITH_SDL_DEVICE_
  3289. +        #ifdef _IRR_COMPILE_WITH_WINDOWS_DEVICE_
  3290. +        case EIDT_WIN32:
  3291. +            return ContextManager->swapBuffers();
  3292. +        #endif // _IRR_COMPILE_WITH_WINDOWS_DEVICE_
  3293. +        #ifdef _IRR_COMPILE_WITH_X11_DEVICE_
  3294. +        case EIDT_X11:
  3295. +            return ContextManager->swapBuffers();
  3296. +        #endif // _IRR_COMPILE_WITH_X11_DEVICE_
  3297. +        #ifdef _IRR_COMPILE_WITH_OSX_DEVICE_
  3298. +        case EIDT_OSX:
  3299. +            return ContextManager->swapBuffers();
  3300. +        #endif // _IRR_COMPILE_WITH_OSX_DEVICE_
  3301. +        default: // todo: console device present
  3302. +            return false;
  3303.     }
  3304. -#endif
  3305. -
  3306. -#ifdef _IRR_COMPILE_WITH_X11_DEVICE_
  3307. -   if (DeviceType == EIDT_X11)
  3308. -   {
  3309. -       return ContextManager->swapBuffers();
  3310. -   }
  3311. -#endif
  3312. -
  3313. -#ifdef _IRR_COMPILE_WITH_OSX_DEVICE_
  3314. -   if (DeviceType == EIDT_OSX)
  3315. -   {
  3316. -       return ContextManager->swapBuffers();
  3317. -   }
  3318. -#endif
  3319. -
  3320. -#ifdef _IRR_COMPILE_WITH_SDL_DEVICE_
  3321. -   if (DeviceType == EIDT_SDL)
  3322. -   {
  3323. -       SDL_GL_SwapBuffers();
  3324. -       return true;
  3325. -   }
  3326. -#endif
  3327. -
  3328. -   // todo: console device present
  3329. -
  3330. -   return false;
  3331.  }
  3332.  
  3333.  
  3334. @@ -469,9 +500,8 @@
  3335.         const SExposedVideoData& videoData, core::rect<s32>* sourceRect)
  3336.  {
  3337.     CNullDriver::beginScene(backBuffer, zBuffer, color, videoData, sourceRect);
  3338. -   ContextManager->activateContext(videoData);
  3339. -
  3340. -#if defined(_IRR_COMPILE_WITH_SDL_DEVICE_)
  3341. +   if(DeviceType != EIDT_SDL2) ContextManager->activateContext(videoData);
  3342. +    #if defined(_IRR_COMPILE_WITH_SDL_DEVICE_)
  3343.     if (DeviceType == EIDT_SDL)
  3344.     {
  3345.         // todo: SDL sets glFrontFace(GL_CCW) after driver creation,
  3346. @@ -478,7 +508,7 @@
  3347.         // it would be better if this was fixed elsewhere.
  3348.         glFrontFace(GL_CW);
  3349.     }
  3350. -#endif
  3351. +    #endif
  3352.  
  3353.     clearBuffers(backBuffer, zBuffer, false, color);
  3354.     return true;
  3355. @@ -3374,7 +3404,7 @@
  3356.  
  3357.     if (vp.getHeight() > 0 && vp.getWidth() > 0)
  3358.         BridgeCalls->setViewport(vp.UpperLeftCorner.X, getCurrentRenderTargetSize().Height - vp.UpperLeftCorner.Y - vp.getHeight(), vp.getWidth(), vp.getHeight());
  3359. -  
  3360. +
  3361.     ViewPort = vp;
  3362.  }
  3363.  
  3364. @@ -4692,11 +4722,11 @@
  3365.     glDisableClientState(GL_NORMAL_ARRAY);
  3366.     glDisableClientState(GL_COLOR_ARRAY);
  3367.     glDisableClientState(GL_TEXTURE_COORD_ARRAY);
  3368. -  
  3369. +
  3370.     const core::dimension2d<u32> ScreenSize = Driver->getScreenSize();
  3371.     ViewportWidth = ScreenSize.Width;
  3372.     ViewportHeight = ScreenSize.Height;
  3373. -   glViewport(ViewportX, ViewportY, ViewportWidth, ViewportHeight);   
  3374. +   glViewport(ViewportX, ViewportY, ViewportWidth, ViewportHeight);
  3375.  }
  3376.  
  3377.  COpenGLCallBridge::~COpenGLCallBridge()
  3378. @@ -5130,6 +5160,22 @@
  3379.  
  3380.  
  3381.  // -----------------------------------
  3382. +// SDL2 VERSION
  3383. +// -----------------------------------
  3384. +#ifdef _IRR_COMPILE_WITH_SDL2_DEVICE_
  3385. +IVideoDriver* createOpenGLDriver(const SIrrlichtCreationParameters& params,
  3386. +       io::IFileSystem* io, CIrrDeviceSDL2* device)
  3387. +{
  3388. +#ifdef _IRR_COMPILE_WITH_OPENGL_
  3389. +   return new COpenGLDriver(params, io, device);
  3390. +#else
  3391. +   return 0;
  3392. +#endif //  _IRR_COMPILE_WITH_OPENGL_
  3393. +}
  3394. +#endif // _IRR_COMPILE_WITH_SDL_DEVICE_
  3395. +
  3396. +
  3397. +// -----------------------------------
  3398.  // SDL VERSION
  3399.  // -----------------------------------
  3400.  #ifdef _IRR_COMPILE_WITH_SDL_DEVICE_
  3401. Index: source/Irrlicht/COpenGLDriver.h
  3402. ===================================================================
  3403. --- source/Irrlicht/COpenGLDriver.h (revision 4940)
  3404. +++ source/Irrlicht/COpenGLDriver.h (working copy)
  3405. @@ -1,6 +1,10 @@
  3406.  // Copyright (C) 2002-2012 Nikolaus Gebhardt
  3407.  // This file is part of the "Irrlicht Engine".
  3408.  // For conditions of distribution and use, see copyright notice in Irrlicht.h
  3409. +//
  3410. +// SDL2 upgrade
  3411. +// Jonathan Frisch
  3412. +// Sep 15, 2014
  3413.  
  3414.  #ifndef __C_VIDEO_OPEN_GL_H_INCLUDED__
  3415.  #define __C_VIDEO_OPEN_GL_H_INCLUDED__
  3416. @@ -13,6 +17,7 @@
  3417.  {
  3418.     class CIrrDeviceWin32;
  3419.     class CIrrDeviceLinux;
  3420. +   class CIrrDeviceSDL2;
  3421.     class CIrrDeviceSDL;
  3422.     class CIrrDeviceMacOSX;
  3423.  }
  3424. @@ -63,6 +68,10 @@
  3425.         bool initDriver(CIrrDeviceLinux* device);
  3426.         #endif
  3427.  
  3428. +       #ifdef _IRR_COMPILE_WITH_SDL2_DEVICE_
  3429. +       COpenGLDriver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, CIrrDeviceSDL2* device);
  3430. +       #endif
  3431. +
  3432.         #ifdef _IRR_COMPILE_WITH_SDL_DEVICE_
  3433.         COpenGLDriver(const SIrrlichtCreationParameters& params, io::IFileSystem* io, CIrrDeviceSDL* device);
  3434.         #endif
  3435. @@ -615,6 +624,9 @@
  3436.         S3DVertex Quad2DVertices[4];
  3437.         static const u16 Quad2DIndices[4];
  3438.  
  3439. +       #ifdef _IRR_COMPILE_WITH_SDL2_DEVICE_
  3440. +           CIrrDeviceSDL2* SDL2Device;
  3441. +       #endif
  3442.         #ifdef _IRR_COMPILE_WITH_SDL_DEVICE_
  3443.             CIrrDeviceSDL *SDLDevice;
  3444.         #endif
  3445. Index: source/Irrlicht/CReadFile.cpp
  3446. ===================================================================
  3447. --- source/Irrlicht/CReadFile.cpp   (revision 4940)
  3448. +++ source/Irrlicht/CReadFile.cpp   (working copy)
  3449. @@ -1,113 +1,125 @@
  3450.  // Copyright (C) 2002-2012 Nikolaus Gebhardt
  3451.  // This file is part of the "Irrlicht Engine".
  3452.  // For conditions of distribution and use, see copyright notice in irrlicht.h
  3453. +//
  3454. +// SDL2 upgrade
  3455. +// Jonathan Frisch
  3456. +// Sep 15, 2014
  3457.  
  3458.  #include "CReadFile.h"
  3459.  
  3460.  namespace irr
  3461.  {
  3462. -namespace io
  3463. -{
  3464. +    namespace io
  3465. +    {
  3466. +        CReadFile::CReadFile(const io::path& fileName) : File(NULL), FileSize(0), Filename(fileName)
  3467. +        {
  3468. +            #ifdef _DEBUG
  3469. +            setDebugName("CReadFile");
  3470. +            #endif
  3471. +            openFile();
  3472. +        }
  3473.  
  3474. +        CReadFile::~CReadFile()
  3475. +        {
  3476. +            if(File)
  3477. +            {
  3478. +                #ifdef _IRR_COMPILE_WITH_SDL2_DEVICE_
  3479. +                SDL_RWclose(File);
  3480. +                #else
  3481. +                fclose(File);
  3482. +                #endif // _IRR_COMPILE_WITH_SDL2_DEVICE_
  3483. +            }
  3484. +        }
  3485.  
  3486. -CReadFile::CReadFile(const io::path& fileName)
  3487. -: File(0), FileSize(0), Filename(fileName)
  3488. -{
  3489. -   #ifdef _DEBUG
  3490. -   setDebugName("CReadFile");
  3491. -   #endif
  3492. +        //! returns how much was read
  3493. +        s32 CReadFile::read(void* buffer, u32 sizeToRead)
  3494. +        {
  3495. +            if(!isOpen()) return 0;
  3496.  
  3497. -   openFile();
  3498. -}
  3499. +            #ifdef _IRR_COMPILE_WITH_SDL2_DEVICE_
  3500. +            return (s32)SDL_RWread(File, buffer, 1, sizeToRead);
  3501. +            #else
  3502. +            return (s32)fread(buffer, 1, sizeToRead, File);
  3503. +            #endif // _IRR_COMPILE_WITH_SDL2_DEVICE_
  3504. +        }
  3505.  
  3506. +        //! changes position in file, returns true if successful
  3507. +        //! if relativeMovement==true, the pos is changed relative to current pos,
  3508. +        //! otherwise from begin of file
  3509. +        bool CReadFile::seek(long finalPos, bool relativeMovement)
  3510. +        {
  3511. +            if(!isOpen()) return false;
  3512.  
  3513. -CReadFile::~CReadFile()
  3514. -{
  3515. -   if (File)
  3516. -       fclose(File);
  3517. -}
  3518. +            #ifdef _IRR_COMPILE_WITH_SDL2_DEVICE_
  3519. +            return SDL_RWseek(File, finalPos, relativeMovement ? RW_SEEK_CUR : RW_SEEK_SET) >= 0;
  3520. +            #else
  3521. +            return fseek(File, finalPos, relativeMovement ? SEEK_CUR : SEEK_SET) == 0;
  3522. +            #endif // _IRR_COMPILE_WITH_SDL2_DEVICE_
  3523. +        }
  3524.  
  3525. +        //! returns size of file
  3526. +        long CReadFile::getSize() const
  3527. +        {
  3528. +            return FileSize;
  3529. +        }
  3530.  
  3531. -//! returns how much was read
  3532. -s32 CReadFile::read(void* buffer, u32 sizeToRead)
  3533. -{
  3534. -   if (!isOpen())
  3535. -       return 0;
  3536. +        //! returns where in the file we are.
  3537. +        long CReadFile::getPos() const
  3538. +        {
  3539. +            #ifdef _IRR_COMPILE_WITH_SDL2_DEVICE_
  3540. +            return (long)SDL_RWtell(File);
  3541. +            #else
  3542. +            return ftell(File);
  3543. +            #endif
  3544. +        }
  3545.  
  3546. -   return (s32)fread(buffer, 1, sizeToRead, File);
  3547. -}
  3548. +        //! opens the file
  3549. +        void CReadFile::openFile()
  3550. +        {
  3551. +            // bugfix posted by rt
  3552. +            if(Filename.size() == 0) return;
  3553.  
  3554. +            #if defined(_IRR_WCHAR_FILESYSTEM)
  3555. +                #ifdef _IRR_COMPILE_WITH_SDL2_DEVICE_
  3556. +                File = SDL_RWFromFile(Filename.c_str(), L"rb");
  3557. +                #else
  3558. +                File = _wfopen(Filename.c_str(), L"rb");
  3559. +                #endif // _IRR_COMPILE_WITH_SDL2_DEVICE_
  3560. +            #else
  3561. +                #ifdef _IRR_COMPILE_WITH_SDL2_DEVICE_
  3562. +                File = SDL_RWFromFile(Filename.c_str(), "rb");
  3563. +                #else
  3564. +                File = fopen(Filename.c_str(), "rb");
  3565. +                #endif // _IRR_COMPILE_WITH_SDL2_DEVICE_
  3566. +            #endif
  3567.  
  3568. -//! changes position in file, returns true if successful
  3569. -//! if relativeMovement==true, the pos is changed relative to current pos,
  3570. -//! otherwise from begin of file
  3571. -bool CReadFile::seek(long finalPos, bool relativeMovement)
  3572. -{
  3573. -   if (!isOpen())
  3574. -       return false;
  3575. +            if(File)
  3576. +            {
  3577. +                // get FileSize
  3578. +                #ifdef _IRR_COMPILE_WITH_SDL2_DEVICE_
  3579. +                SDL_RWseek(File, 0, RW_SEEK_END);
  3580. +                #else
  3581. +                fseek(File, 0, SEEK_END);
  3582. +                #endif
  3583. +                FileSize = getPos();
  3584. +                seek(0, false);
  3585. +            }
  3586. +        }
  3587.  
  3588. -   return fseek(File, finalPos, relativeMovement ? SEEK_CUR : SEEK_SET) == 0;
  3589. -}
  3590. +        //! returns name of file
  3591. +        const io::path& CReadFile::getFileName() const
  3592. +        {
  3593. +            return Filename;
  3594. +        }
  3595.  
  3596. +        IReadFile* CReadFile::createReadFile(const io::path& fileName)
  3597. +        {
  3598. +            CReadFile* file = new CReadFile(fileName);
  3599. +            if(file->isOpen()) return file;
  3600.  
  3601. -//! returns size of file
  3602. -long CReadFile::getSize() const
  3603. -{
  3604. -   return FileSize;
  3605. -}
  3606. -
  3607. -
  3608. -//! returns where in the file we are.
  3609. -long CReadFile::getPos() const
  3610. -{
  3611. -   return ftell(File);
  3612. -}
  3613. -
  3614. -
  3615. -//! opens the file
  3616. -void CReadFile::openFile()
  3617. -{
  3618. -   if (Filename.size() == 0) // bugfix posted by rt
  3619. -   {
  3620. -       File = 0;
  3621. -       return;
  3622. -   }
  3623. -
  3624. -#if defined ( _IRR_WCHAR_FILESYSTEM )
  3625. -   File = _wfopen(Filename.c_str(), L"rb");
  3626. -#else
  3627. -   File = fopen(Filename.c_str(), "rb");
  3628. -#endif
  3629. -
  3630. -   if (File)
  3631. -   {
  3632. -       // get FileSize
  3633. -
  3634. -       fseek(File, 0, SEEK_END);
  3635. -       FileSize = getPos();
  3636. -       fseek(File, 0, SEEK_SET);
  3637. -   }
  3638. -}
  3639. -
  3640. -
  3641. -//! returns name of file
  3642. -const io::path& CReadFile::getFileName() const
  3643. -{
  3644. -   return Filename;
  3645. -}
  3646. -
  3647. -
  3648. -IReadFile* CReadFile::createReadFile(const io::path& fileName)
  3649. -{
  3650. -   CReadFile* file = new CReadFile(fileName);
  3651. -   if (file->isOpen())
  3652. -       return file;
  3653. -
  3654. -   file->drop();
  3655. -   return 0;
  3656. -}
  3657. -
  3658. -
  3659. -} // end namespace io
  3660. +            file->drop();
  3661. +            return NULL;
  3662. +        }
  3663. +    } // end namespace io
  3664.  } // end namespace irr
  3665. -
  3666. Index: source/Irrlicht/CReadFile.h
  3667. ===================================================================
  3668. --- source/Irrlicht/CReadFile.h (revision 4940)
  3669. +++ source/Irrlicht/CReadFile.h (working copy)
  3670. @@ -1,11 +1,20 @@
  3671.  // Copyright (C) 2002-2012 Nikolaus Gebhardt
  3672.  // This file is part of the "Irrlicht Engine".
  3673.  // For conditions of distribution and use, see copyright notice in irrlicht.h
  3674. +//
  3675. +// SDL2 upgrade
  3676. +// Jonathan Frisch
  3677. +// Sep 15, 2014
  3678.  
  3679.  #ifndef __C_READ_FILE_H_INCLUDED__
  3680.  #define __C_READ_FILE_H_INCLUDED__
  3681.  
  3682. +#ifdef _IRR_COMPILE_WITH_SDL2_DEVICE_
  3683. +#include <SDL2/SDL.h>
  3684. +#include <SDL2/SDL_rwops.h>
  3685. +#else
  3686.  #include <stdio.h>
  3687. +#endif // _IRR_COMPILE_WITH_SDL2_DEVICE_
  3688.  #include "IReadFile.h"
  3689.  #include "irrString.h"
  3690.  
  3691. @@ -55,7 +64,11 @@
  3692.         //! opens the file
  3693.         void openFile();
  3694.  
  3695. +       #ifdef _IRR_COMPILE_WITH_SDL2_DEVICE_
  3696. +       SDL_RWops* File;
  3697. +       #else
  3698.         FILE* File;
  3699. +       #endif // _IRR_COMPILE_WITH_SDL2_DEVICE_
  3700.         long FileSize;
  3701.         io::path Filename;
  3702.     };
  3703. Index: source/Irrlicht/CWriteFile.cpp
  3704. ===================================================================
  3705. --- source/Irrlicht/CWriteFile.cpp  (revision 4940)
  3706. +++ source/Irrlicht/CWriteFile.cpp  (working copy)
  3707. @@ -1,123 +1,126 @@
  3708.  // Copyright (C) 2002-2012 Nikolaus Gebhardt
  3709.  // This file is part of the "Irrlicht Engine".
  3710.  // For conditions of distribution and use, see copyright notice in irrlicht.h
  3711. +//
  3712. +// SDL2 upgrade
  3713. +// Jonathan Frisch
  3714. +// Sep 15, 2014
  3715.  
  3716.  #include "CWriteFile.h"
  3717. -#include <stdio.h>
  3718.  
  3719.  namespace irr
  3720.  {
  3721. -namespace io
  3722. -{
  3723. +    namespace io
  3724. +    {
  3725. +        CWriteFile::CWriteFile(const io::path& fileName, bool append) : File(NULL), FileSize(0)
  3726. +        {
  3727. +            #ifdef _DEBUG
  3728. +            setDebugName("CWriteFile");
  3729. +            #endif
  3730.  
  3731. +            Filename = fileName;
  3732. +            openFile(append);
  3733. +        }
  3734.  
  3735. -CWriteFile::CWriteFile(const io::path& fileName, bool append)
  3736. -: FileSize(0)
  3737. -{
  3738. -   #ifdef _DEBUG
  3739. -   setDebugName("CWriteFile");
  3740. -   #endif
  3741. +        CWriteFile::~CWriteFile()
  3742. +        {
  3743. +            if(File)
  3744. +            {
  3745. +                #ifdef _IRR_COMPILE_WITH_SDL2_DEVICE_
  3746. +                SDL_RWclose(File);
  3747. +                #else
  3748. +                fclose(File);
  3749. +                #endif
  3750. +            }
  3751. +        }
  3752.  
  3753. -   Filename = fileName;
  3754. -   openFile(append);
  3755. -}
  3756. +        //! returns if file is open
  3757. +        inline bool CWriteFile::isOpen() const
  3758. +        {
  3759. +            return File != NULL;
  3760. +        }
  3761.  
  3762. +        //! returns how much was read
  3763. +        s32 CWriteFile::write(const void* buffer, u32 sizeToWrite)
  3764. +        {
  3765. +            if(!isOpen()) return NULL;
  3766. +            #ifdef _IRR_COMPILE_WITH_SDL2_DEVICE_
  3767. +            return (s32)SDL_RWwrite(File, buffer, 1, sizeToWrite);
  3768. +            #else
  3769. +            return (s32)fwrite(buffer, 1, sizeToWrite, File);
  3770. +            #endif // _IRR_COMPILE_WITH_SDL2_DEVICE_
  3771. +        }
  3772.  
  3773. +        //! changes position in file, returns true if successful
  3774. +        //! if relativeMovement==true, the pos is changed relative to current pos,
  3775. +        //! otherwise from begin of file
  3776. +        bool CWriteFile::seek(long finalPos, bool relativeMovement)
  3777. +        {
  3778. +            if(!isOpen()) return false;
  3779.  
  3780. -CWriteFile::~CWriteFile()
  3781. -{
  3782. -   if (File)
  3783. -       fclose(File);
  3784. -}
  3785. +            #ifdef _IRR_COMPILE_WITH_SDL2_DEVICE_
  3786. +            return SDL_RWseek(File, finalPos, relativeMovement ? RW_SEEK_CUR : RW_SEEK_SET) == 0;
  3787. +            #else
  3788. +            return fseek(File, finalPos, relativeMovement ? SEEK_CUR : SEEK_SET) == 0;
  3789. +            #endif // _IRR_COMPILE_WITH_SDL2_DEVICE_
  3790. +        }
  3791.  
  3792. +        //! returns where in the file we are.
  3793. +        long CWriteFile::getPos() const
  3794. +        {
  3795. +            #ifdef _IRR_COMPILE_WITH_SDL2_DEVICE_
  3796. +            return (long)SDL_RWtell(File);
  3797. +            #else
  3798. +            return ftell(File);
  3799. +            #endif // _IRR_COMPILE_WITH_SDL2_DEVICE_
  3800. +        }
  3801.  
  3802. +        //! opens the file
  3803. +        void CWriteFile::openFile(bool append)
  3804. +        {
  3805. +            // bugfix posted by rt
  3806. +            if(Filename.size() == 0) return;
  3807.  
  3808. -//! returns if file is open
  3809. -inline bool CWriteFile::isOpen() const
  3810. -{
  3811. -   return File != 0;
  3812. -}
  3813. +            #if defined(_IRR_WCHAR_FILESYSTEM)
  3814. +                #ifdef _IRR_COMPILE_WITH_SDL2_DEVICE_
  3815. +                File = SDL_RWFromFile(Filename.c_str(), append ? L"ab" : L"wb");
  3816. +                #else
  3817. +                File = _wfopen(Filename.c_str(), append ? L"ab" : L"wb");
  3818. +                #endif // _IRR_COMPILE_WITH_SDL2_DEVICE_
  3819. +            #else
  3820. +                #ifdef _IRR_COMPILE_WITH_SDL2_DEVICE_
  3821. +                File = SDL_RWFromFile(Filename.c_str(), append ? "ab" : "wb");
  3822. +                #else
  3823. +                File = fopen(Filename.c_str(), append ? "ab" : "wb");
  3824. +                #endif // _IRR_COMPILE_WITH_SDL2_DEVICE_
  3825. +            #endif
  3826.  
  3827. +            if(File)
  3828. +            {
  3829. +                // get FileSize
  3830. +                #ifdef _IRR_COMPILE_WITH_SDL2_DEVICE_
  3831. +                SDL_RWseek(File, 0, RW_SEEK_END);
  3832. +                #else
  3833. +                fseek(File, 0, SEEK_END);
  3834. +                #endif // _IRR_COMPILE_WITH_SDL2_DEVICE_
  3835. +                FileSize = getPos();
  3836. +                seek(0, false);
  3837. +            }
  3838. +        }
  3839.  
  3840. +        //! returns name of file
  3841. +        const io::path& CWriteFile::getFileName() const
  3842. +        {
  3843. +            return Filename;
  3844. +        }
  3845.  
  3846. -//! returns how much was read
  3847. -s32 CWriteFile::write(const void* buffer, u32 sizeToWrite)
  3848. -{
  3849. -   if (!isOpen())
  3850. -       return 0;
  3851. +        IWriteFile* CWriteFile::createWriteFile(const io::path& fileName, bool append)
  3852. +        {
  3853. +            CWriteFile* file = new CWriteFile(fileName, append);
  3854. +            if(file->isOpen()) return file;
  3855.  
  3856. -   return (s32)fwrite(buffer, 1, sizeToWrite, File);
  3857. -}
  3858. -
  3859. -
  3860. -
  3861. -//! changes position in file, returns true if successful
  3862. -//! if relativeMovement==true, the pos is changed relative to current pos,
  3863. -//! otherwise from begin of file
  3864. -bool CWriteFile::seek(long finalPos, bool relativeMovement)
  3865. -{
  3866. -   if (!isOpen())
  3867. -       return false;
  3868. -
  3869. -   return fseek(File, finalPos, relativeMovement ? SEEK_CUR : SEEK_SET) == 0;
  3870. -}
  3871. -
  3872. -
  3873. -
  3874. -//! returns where in the file we are.
  3875. -long CWriteFile::getPos() const
  3876. -{
  3877. -   return ftell(File);
  3878. -}
  3879. -
  3880. -
  3881. -
  3882. -//! opens the file
  3883. -void CWriteFile::openFile(bool append)
  3884. -{
  3885. -   if (Filename.size() == 0)
  3886. -   {
  3887. -       File = 0;
  3888. -       return;
  3889. -   }
  3890. -
  3891. -#if defined(_IRR_WCHAR_FILESYSTEM)
  3892. -   File = _wfopen(Filename.c_str(), append ? L"ab" : L"wb");
  3893. -#else
  3894. -   File = fopen(Filename.c_str(), append ? "ab" : "wb");
  3895. -#endif
  3896. -
  3897. -   if (File)
  3898. -   {
  3899. -       // get FileSize
  3900. -
  3901. -       fseek(File, 0, SEEK_END);
  3902. -       FileSize = ftell(File);
  3903. -       fseek(File, 0, SEEK_SET);
  3904. -   }
  3905. -}
  3906. -
  3907. -
  3908. -
  3909. -//! returns name of file
  3910. -const io::path& CWriteFile::getFileName() const
  3911. -{
  3912. -   return Filename;
  3913. -}
  3914. -
  3915. -
  3916. -
  3917. -IWriteFile* CWriteFile::createWriteFile(const io::path& fileName, bool append)
  3918. -{
  3919. -   CWriteFile* file = new CWriteFile(fileName, append);
  3920. -   if (file->isOpen())
  3921. -       return file;
  3922. -
  3923. -   file->drop();
  3924. -   return 0;
  3925. -}
  3926. -
  3927. -
  3928. -} // end namespace io
  3929. +            file->drop();
  3930. +            return NULL;
  3931. +        }
  3932. +    } // end namespace io
  3933.  } // end namespace irr
  3934. -
  3935. Index: source/Irrlicht/CWriteFile.h
  3936. ===================================================================
  3937. --- source/Irrlicht/CWriteFile.h    (revision 4940)
  3938. +++ source/Irrlicht/CWriteFile.h    (working copy)
  3939. @@ -1,61 +1,68 @@
  3940.  // Copyright (C) 2002-2012 Nikolaus Gebhardt
  3941.  // This file is part of the "Irrlicht Engine".
  3942.  // For conditions of distribution and use, see copyright notice in irrlicht.h
  3943. +//
  3944. +// SDL2 upgrade
  3945. +// Jonathan Frisch
  3946. +// Sep 15, 2014
  3947.  
  3948.  #ifndef __C_WRITE_FILE_H_INCLUDED__
  3949.  #define __C_WRITE_FILE_H_INCLUDED__
  3950.  
  3951. +#ifdef _IRR_COMPILE_WITH_SDL2_DEVICE_
  3952. +#include <SDL2/SDL.h>
  3953. +#include <SDL2/SDL_rwops.h>
  3954. +#else
  3955.  #include <stdio.h>
  3956. +#endif // __C_WRITE_FILE_H_INCLUDED__
  3957.  #include "IWriteFile.h"
  3958.  #include "irrString.h"
  3959.  
  3960.  namespace irr
  3961.  {
  3962. +    namespace io
  3963. +    {
  3964. +        /*!
  3965. +            Class for writing a real file to disk.
  3966. +        */
  3967. +        class CWriteFile : public IWriteFile
  3968. +        {
  3969. +            public:
  3970. +                CWriteFile(const io::path& fileName, bool append);
  3971.  
  3972. -namespace io
  3973. -{
  3974. +                virtual ~CWriteFile();
  3975.  
  3976. -   /*!
  3977. -       Class for writing a real file to disk.
  3978. -   */
  3979. -   class CWriteFile : public IWriteFile
  3980. -   {
  3981. -   public:
  3982. +                //! Reads an amount of bytes from the file.
  3983. +                virtual s32 write(const void* buffer, u32 sizeToWrite) _IRR_OVERRIDE_;
  3984.  
  3985. -       CWriteFile(const io::path& fileName, bool append);
  3986. +                //! Changes position in file, returns true if successful.
  3987. +                virtual bool seek(long finalPos, bool relativeMovement = false) _IRR_OVERRIDE_;
  3988.  
  3989. -       virtual ~CWriteFile();
  3990. +                //! Returns the current position in the file.
  3991. +                virtual long getPos() const _IRR_OVERRIDE_;
  3992.  
  3993. -       //! Reads an amount of bytes from the file.
  3994. -       virtual s32 write(const void* buffer, u32 sizeToWrite) _IRR_OVERRIDE_;
  3995. +                //! Returns name of file.
  3996. +                virtual const io::path& getFileName() const _IRR_OVERRIDE_;
  3997.  
  3998. -       //! Changes position in file, returns true if successful.
  3999. -       virtual bool seek(long finalPos, bool relativeMovement = false) _IRR_OVERRIDE_;
  4000. +                //! returns if file is open
  4001. +                bool isOpen() const;
  4002.  
  4003. -       //! Returns the current position in the file.
  4004. -       virtual long getPos() const _IRR_OVERRIDE_;
  4005. +                //! creator method
  4006. +                static IWriteFile* createWriteFile(const io::path& fileName, bool append);
  4007.  
  4008. -       //! Returns name of file.
  4009. -       virtual const io::path& getFileName() const _IRR_OVERRIDE_;
  4010. +            private:
  4011. +                //! opens the file
  4012. +                void openFile(bool append);
  4013.  
  4014. -       //! returns if file is open
  4015. -       bool isOpen() const;
  4016. -
  4017. -       //! creator method
  4018. -       static IWriteFile* createWriteFile(const io::path& fileName, bool append);
  4019. -
  4020. -   private:
  4021. -
  4022. -       //! opens the file
  4023. -       void openFile(bool append);
  4024. -
  4025. -       io::path Filename;
  4026. -       FILE* File;
  4027. -       long FileSize;
  4028. -   };
  4029. -
  4030. -} // end namespace io
  4031. +                io::path Filename;
  4032. +                #ifdef _IRR_COMPILE_WITH_SDL2_DEVICE_
  4033. +                SDL_RWops* File;
  4034. +                #else
  4035. +                FILE* File;
  4036. +                #endif
  4037. +                long FileSize;
  4038. +        };
  4039. +    } // end namespace io
  4040.  } // end namespace irr
  4041.  
  4042.  #endif
  4043. -
  4044. Index: source/Irrlicht/Irrlicht.cpp
  4045. ===================================================================
  4046. --- source/Irrlicht/Irrlicht.cpp    (revision 4940)
  4047. +++ source/Irrlicht/Irrlicht.cpp    (working copy)
  4048. @@ -1,6 +1,10 @@
  4049.  // Copyright (C) 2002-2012 Nikolaus Gebhardt
  4050.  // This file is part of the "Irrlicht Engine".
  4051.  // For conditions of distribution and use, see copyright notice in irrlicht.h
  4052. +//
  4053. +// SDL2 upgrade
  4054. +// Jonathan Frisch
  4055. +// Sep 15, 2014
  4056.  
  4057.  #include "IrrCompileConfig.h"
  4058.  
  4059. @@ -38,6 +42,10 @@
  4060.  #include "Android/CIrrDeviceAndroid.h"
  4061.  #endif
  4062.  
  4063. +#ifdef _IRR_COMPILE_WITH_SDL2_DEVICE_
  4064. +#include "CIrrDeviceSDL2.h"
  4065. +#endif
  4066. +
  4067.  #ifdef _IRR_COMPILE_WITH_SDL_DEVICE_
  4068.  #include "CIrrDeviceSDL.h"
  4069.  #endif
  4070. @@ -75,6 +83,11 @@
  4071.  
  4072.         IrrlichtDevice* dev = 0;
  4073.  
  4074. +#ifdef _IRR_COMPILE_WITH_SDL2_DEVICE_
  4075. +       if (params.DeviceType == EIDT_SDL2 || (!dev && params.DeviceType == EIDT_BEST))
  4076. +           dev = new CIrrDeviceSDL2(params);
  4077. +#endif
  4078. +
  4079.  #ifdef _IRR_COMPILE_WITH_WINDOWS_DEVICE_
  4080.         if (params.DeviceType == EIDT_WIN32 || (!dev && params.DeviceType == EIDT_BEST))
  4081.             dev = new CIrrDeviceWin32(params);
  4082. @@ -94,7 +107,7 @@
  4083.         if (params.DeviceType == EIDT_X11 || (!dev && params.DeviceType == EIDT_BEST))
  4084.             dev = new CIrrDeviceLinux(params);
  4085.  #endif
  4086. -        
  4087. +
  4088.  #ifdef _IRR_COMPILE_WITH_IPHONE_DEVICE_
  4089.         if (params.DeviceType == EIDT_IPHONE || (!dev && params.DeviceType == EIDT_BEST))
  4090.             dev = new CIrrDeviceIPhone(params);
  4091. Index: source/Irrlicht/os.cpp
  4092. ===================================================================
  4093. --- source/Irrlicht/os.cpp  (revision 4940)
  4094. +++ source/Irrlicht/os.cpp  (working copy)
  4095. @@ -1,6 +1,10 @@
  4096.  // Copyright (C) 2002-2012 Nikolaus Gebhardt
  4097.  // This file is part of the "Irrlicht Engine".
  4098.  // For conditions of distribution and use, see copyright notice in irrlicht.h
  4099. +//
  4100. +// SDL2 upgrade
  4101. +// Jonathan Frisch
  4102. +// Sep 15, 2014
  4103.  
  4104.  #include "os.h"
  4105.  #include "irrString.h"
  4106. @@ -12,6 +16,11 @@
  4107.     #define bswap_16(X) SDL_Swap16(X)
  4108.     #define bswap_32(X) SDL_Swap32(X)
  4109.     #define bswap_64(X) SDL_Swap64(X)
  4110. +#elif defined(_IRR_COMPILE_WITH_SDL2_DEVICE_)
  4111. +   #include <SDL2/SDL_endian.h>
  4112. +   #define bswap_16(X) SDL_Swap16(X)
  4113. +   #define bswap_32(X) SDL_Swap32(X)
  4114. +   #define bswap_64(X) SDL_Swap64(X)
  4115.  #elif defined(_IRR_WINDOWS_API_) && defined(_MSC_VER) && (_MSC_VER > 1298)
  4116.     #include <stdlib.h>
  4117.     #define bswap_16(X) _byteswap_ushort(X)
  4118. @@ -134,8 +143,8 @@
  4119.     }
  4120.  
  4121.  } // end namespace os
  4122. +} // end namespace irr
  4123.  
  4124. -
  4125.  #elif defined( _IRR_ANDROID_PLATFORM_ )
  4126.  
  4127.  // ----------------------------------------------------------------
  4128. @@ -188,7 +197,59 @@
  4129.         return (u32)(tv.tv_sec * 1000) + (tv.tv_usec / 1000);
  4130.     }
  4131.  } // end namespace os
  4132. +} // end namespace irr
  4133.  
  4134. +#elif defined(_IRR_COMPILE_WITH_SDL2_DEVICE_)
  4135. +
  4136. +// ----------------------------------------------------------------
  4137. +// SDL2 version
  4138. +// ----------------------------------------------------------------
  4139. +
  4140. +#include <time.h>
  4141. +#include <sys/time.h>
  4142. +#include <SDL2/SDL_log.h>
  4143. +
  4144. +namespace irr
  4145. +{
  4146. +    namespace os
  4147. +    {
  4148. +        //! prints a debuginfo string
  4149. +        void Printer::print(const c8* message, ELOG_LEVEL ll)
  4150. +        {
  4151. +            switch(ll)
  4152. +            {
  4153. +                case ELL_DEBUG:
  4154. +                    SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Irrlicht://%s\n", message);
  4155. +                    break;
  4156. +                case ELL_INFORMATION:
  4157. +                    SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Irrlicht://%s\n", message);
  4158. +                    break;
  4159. +                case ELL_WARNING:
  4160. +                    SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "Irrlicht://%s\n", message);
  4161. +                    break;
  4162. +                case ELL_ERROR:
  4163. +                    SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Irrlicht://%s\n", message);
  4164. +                    break;
  4165. +                default: // ELL_NONE
  4166. +                    SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION, "Irrlicht://%s\n", message);
  4167. +                    break;
  4168. +            }
  4169. +        }
  4170. +
  4171. +        void Timer::initTimer(bool usePerformanceTimer)
  4172. +        {
  4173. +            initVirtualTimer();
  4174. +        }
  4175. +
  4176. +        u32 Timer::getRealTime()
  4177. +        {
  4178. +            timeval tv;
  4179. +            gettimeofday(&tv, 0);
  4180. +            return (u32)(tv.tv_sec * 1000) + (tv.tv_usec / 1000);
  4181. +        }
  4182. +    } // end namespace os
  4183. +} // end namespace irr
  4184. +
  4185.  #else
  4186.  
  4187.  // ----------------------------------------------------------------
  4188. @@ -222,9 +283,12 @@
  4189.         return (u32)(tv.tv_sec * 1000) + (tv.tv_usec / 1000);
  4190.     }
  4191.  } // end namespace os
  4192. +} // end namespace irr
  4193.  
  4194.  #endif // end linux / android / windows
  4195.  
  4196. +namespace irr
  4197. +{
  4198.  namespace os
  4199.  {
  4200.     // The platform independent implementation of the printer
  4201. @@ -232,26 +296,22 @@
  4202.  
  4203.     void Printer::log(const c8* message, ELOG_LEVEL ll)
  4204.     {
  4205. -       if (Logger)
  4206. -           Logger->log(message, ll);
  4207. +       if(Logger) Logger->log(message, ll);
  4208.     }
  4209.  
  4210.     void Printer::log(const wchar_t* message, ELOG_LEVEL ll)
  4211.     {
  4212. -       if (Logger)
  4213. -           Logger->log(message, ll);
  4214. +       if(Logger) Logger->log(message, ll);
  4215.     }
  4216.  
  4217.     void Printer::log(const c8* message, const c8* hint, ELOG_LEVEL ll)
  4218.     {
  4219. -       if (Logger)
  4220. -           Logger->log(message, hint, ll);
  4221. +       if(Logger) Logger->log(message, hint, ll);
  4222.     }
  4223.  
  4224.     void Printer::log(const c8* message, const io::path& hint, ELOG_LEVEL ll)
  4225.     {
  4226. -       if (Logger)
  4227. -           Logger->log(message, hint.c_str(), ll);
  4228. +       if(Logger) Logger->log(message, hint.c_str(), ll);
  4229.     }
  4230.  
  4231.     // our Randomizer is not really os specific, so we
  4232. @@ -264,8 +324,8 @@
  4233.     s32 Randomizer::rand()
  4234.     {
  4235.         // (a*seed)%m with Schrage's method
  4236. -       seed = a * (seed%q) - r* (seed/q);
  4237. -       if (seed<0)
  4238. +       seed = a * (seed % q) - r* (seed / q);
  4239. +       if(seed < 0)
  4240.             seed += m;
  4241.  
  4242.         return seed;
  4243. @@ -274,7 +334,7 @@
  4244.     //! generates a pseudo random number
  4245.     f32 Randomizer::frand()
  4246.     {
  4247. -       return rand()*(1.f/rMax);
  4248. +       return rand() * (1.f / rMax);
  4249.     }
  4250.  
  4251.     s32 Randomizer::randMax()
  4252. @@ -329,8 +389,7 @@
  4253.     //! returns current virtual time
  4254.     u32 Timer::getTime()
  4255.     {
  4256. -       if (isStopped())
  4257. -           return LastVirtualTime;
  4258. +       if(isStopped()) return LastVirtualTime;
  4259.  
  4260.         return LastVirtualTime + (u32)((StaticTime - StartRealTime) * VirtualTimerSpeed);
  4261.     }
  4262. @@ -352,7 +411,7 @@
  4263.     //! stops the virtual timer
  4264.     void Timer::stopTimer()
  4265.     {
  4266. -       if (!isStopped())
  4267. +       if(!isStopped())
  4268.         {
  4269.             // stop the virtual timer
  4270.             LastVirtualTime = getTime();
  4271. @@ -366,7 +425,7 @@
  4272.     {
  4273.         ++VirtualTimerStopCounter;
  4274.  
  4275. -       if (!isStopped())
  4276. +       if(!isStopped())
  4277.         {
  4278.             // restart virtual timer
  4279.             setTime(LastVirtualTime);
  4280. @@ -379,8 +438,7 @@
  4281.         setTime(getTime());
  4282.  
  4283.         VirtualTimerSpeed = speed;
  4284. -       if (VirtualTimerSpeed < 0.0f)
  4285. -           VirtualTimerSpeed = 0.0f;
  4286. +       if(VirtualTimerSpeed < 0.0f) VirtualTimerSpeed = 0.0f;
  4287.     }
  4288.  
  4289.     //! gets the speed of the virtual timer
  4290. @@ -403,5 +461,3 @@
  4291.  
  4292.  } // end namespace os
  4293.  } // end namespace irr
  4294. -
  4295. -
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement