Browse Source

Added Raspberry Pi port, currently only supported in GCC build either natively or cross compiling (if the CC tool is detected). Moved the gcc out-of-source build directory one more level up as it is better supported by cmake/eclipse generator this way. Enhanced shell scripts so they can be invoked in any directory. A few bug bug fixes on SDL library code.

Wei Tjong Yao 12 years ago
parent
commit
cc99a07a53
46 changed files with 1388 additions and 164 deletions
  1. 1 1
      Bin/Chat.sh
  2. 1 1
      Bin/ChatServer.sh
  3. 6 2
      Bin/CoreData/Shaders/GLSL/Uniforms.vert
  4. 1 1
      Bin/Editor.sh
  5. 1 1
      Bin/LightTest.sh
  6. 1 1
      Bin/Navigation.sh
  7. 1 1
      Bin/NinjaSnowWar.sh
  8. 1 1
      Bin/Physics.sh
  9. 1 1
      Bin/SpriteTest.sh
  10. 1 1
      Bin/Terrain.sh
  11. 1 1
      Bin/TestScene.sh
  12. 1 1
      Bin/TestSceneOld.sh
  13. 1 0
      Bin/UpdateDocument.sh
  14. 1 1
      Bin/Vehicle.sh
  15. 49 29
      CMakeLists.txt
  16. 1 1
      Doxyfile
  17. 1 1
      Engine/Core/CMakeLists.txt
  18. 8 6
      Engine/Core/ProcessUtils.cpp
  19. 2 2
      Engine/Engine/Engine.cpp
  20. 2 2
      Engine/Graphics/CMakeLists.txt
  21. 1 1
      Engine/Graphics/Light.h
  22. 4 4
      Engine/Graphics/OpenGL/OGLGraphicsImpl.h
  23. 5 0
      Engine/Graphics/ShaderParser.cpp
  24. 1 1
      Engine/Input/CMakeLists.txt
  25. 3 2
      Extras/LuaScript/CMakeLists.txt
  26. 1 1
      ThirdParty/AngelScript/CMakeLists.txt
  27. 44 36
      ThirdParty/SDL/CMakeLists.txt
  28. 17 1
      ThirdParty/SDL/include/SDL_config_linux.h
  29. 7 0
      ThirdParty/SDL/src/video/SDL_sysvideo.h
  30. 10 20
      ThirdParty/SDL/src/video/SDL_video.c
  31. 5 0
      ThirdParty/SDL/src/video/android/SDL_androidvideo.c
  32. 164 0
      ThirdParty/SDL/src/video/raspi/SDL_raspievents.c
  33. 35 0
      ThirdParty/SDL/src/video/raspi/SDL_raspievents.h
  34. 384 0
      ThirdParty/SDL/src/video/raspi/SDL_raspiopengles.c
  35. 98 0
      ThirdParty/SDL/src/video/raspi/SDL_raspiopengles.h
  36. 178 0
      ThirdParty/SDL/src/video/raspi/SDL_raspivideo.c
  37. 44 0
      ThirdParty/SDL/src/video/raspi/SDL_raspivideo.h
  38. 143 0
      ThirdParty/SDL/src/video/raspi/SDL_raspiwindow.c
  39. 34 0
      ThirdParty/SDL/src/video/raspi/SDL_raspiwindow.h
  40. 28 18
      ThirdParty/SDL/src/video/x11/SDL_x11opengles.c
  41. 3 2
      ThirdParty/tolua++/src/bin/CMakeLists.txt
  42. 0 0
      cmake/Toolchains/android.toolchain.cmake
  43. 49 0
      cmake/Toolchains/raspberrypi.toolchain.cmake
  44. 2 2
      cmake_android.bat
  45. 1 14
      cmake_eclipse.sh
  46. 45 7
      cmake_gcc.sh

+ 1 - 1
Bin/Chat.sh

@@ -1 +1 @@
-./Urho3D Scripts/Chat.as $@
+$( dirname $0 )/Urho3D Scripts/Chat.as $@

+ 1 - 1
Bin/ChatServer.sh

@@ -1 +1 @@
-./Urho3D Scripts/Chat.as server -headless $@
+$( dirname $0 )/Urho3D Scripts/Chat.as server -headless $@

+ 6 - 2
Bin/CoreData/Shaders/GLSL/Uniforms.vert

@@ -21,8 +21,12 @@ uniform mat4 cZone;
     uniform mat4 cLightMatrices[2];
 #endif
 #ifdef SKINNED
-    uniform vec4 cSkinMatrices[64*3];
+    #ifdef RASPI
+        uniform vec4 cSkinMatrices[32*3];
+    #else
+        uniform vec4 cSkinMatrices[64*3];
+    #endif
 #endif
 #ifdef NUMVERTEXLIGHTS
     uniform vec4 cVertexLights[4*3];
-#endif
+#endif

+ 1 - 1
Bin/Editor.sh

@@ -1 +1 @@
-./Urho3D Scripts/Editor.as $@
+$( dirname $0 )/Urho3D Scripts/Editor.as $@

+ 1 - 1
Bin/LightTest.sh

@@ -1 +1 @@
-./Urho3D Scripts/LightTest.as $@
+$( dirname $0 )/Urho3D Scripts/LightTest.as $@

+ 1 - 1
Bin/Navigation.sh

@@ -1 +1 @@
-./Urho3D Scripts/Navigation.as $@
+$( dirname $0 )/Urho3D Scripts/Navigation.as $@

+ 1 - 1
Bin/NinjaSnowWar.sh

@@ -9,4 +9,4 @@
 #   Start the server with "./NinjaSnowWar.sh -w server"
 #   Start the client on the same host with "./NinjaSnowWar.sh -w -nobgm `hostname`"
 #
-./Urho3D Scripts/NinjaSnowWar.as $@
+$( dirname $0 )/Urho3D Scripts/NinjaSnowWar.as $@

+ 1 - 1
Bin/Physics.sh

@@ -1 +1 @@
-./Urho3D Scripts/Physics.as $@
+$( dirname $0 )/Urho3D Scripts/Physics.as $@

+ 1 - 1
Bin/SpriteTest.sh

@@ -1 +1 @@
-./Urho3D Scripts/SpriteTest.as $@
+$( dirname $0 )/Urho3D Scripts/SpriteTest.as $@

+ 1 - 1
Bin/Terrain.sh

@@ -1 +1 @@
-./Urho3D Scripts/Terrain.as $@
+$( dirname $0 )/Urho3D Scripts/Terrain.as $@

+ 1 - 1
Bin/TestScene.sh

@@ -1 +1 @@
-./Urho3D Scripts/TestScene.as $@
+$( dirname $0 )/Urho3D Scripts/TestScene.as $@

+ 1 - 1
Bin/TestSceneOld.sh

@@ -1 +1 @@
-./Urho3D Scripts/TestSceneOld.as $@
+$( dirname $0 )/Urho3D Scripts/TestSceneOld.as $@

+ 1 - 0
Bin/UpdateDocument.sh

@@ -1,3 +1,4 @@
+cd $( dirname $0 )
 echo "Dumping Script API..."
 ./ScriptCompiler -dumpapi ../Docs/ScriptAPI.dox
 if [ $? -ne 0 ]; then exit 1; fi

+ 1 - 1
Bin/Vehicle.sh

@@ -1 +1 @@
-./Urho3D Scripts/Vehicle.as $@
+$( dirname $0 )/Urho3D Scripts/Vehicle.as $@

+ 49 - 29
CMakeLists.txt

@@ -69,7 +69,7 @@ if (HAVE_STDINT_H)
 endif ()
 
 # Add definitions for GLEW
-if (NOT IOS AND NOT ANDROID AND USE_OPENGL)
+if (NOT IOS AND NOT ANDROID AND NOT RASPI AND USE_OPENGL)
     add_definitions(-DGLEW_STATIC)
     add_definitions(-DGLEW_NO_GLU)
 endif ()
@@ -81,14 +81,14 @@ if (IOS)
     set (CMAKE_OSX_ARCHITECTURES $(ARCHS_STANDARD_32_BIT))
     set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphoneos;-iphonesimulator")
     set (MACOSX_BUNDLE_GUI_IDENTIFIER "com.googlecode.urho3d")
-    set (CMAKE_OSX_SYSROOT "iphoneos")	# Set to "Latest iOS"
+    set (CMAKE_OSX_SYSROOT "iphoneos")    # Set to "Latest iOS"
 elseif (CMAKE_GENERATOR STREQUAL "Xcode")
     # MacOSX-Xcode-specific setup
     if (NOT ENABLE_64BIT)
         set (CMAKE_OSX_ARCHITECTURES $(ARCHS_STANDARD_32_BIT))
     endif ()
-    set (CMAKE_OSX_SYSROOT "")		# Set to "Current OS X"
-    #set (CMAKE_OSX_SYSROOT "macosx")	# Set to "Latest OS X"
+    set (CMAKE_OSX_SYSROOT "")        # Set to "Current OS X"
+    #set (CMAKE_OSX_SYSROOT "macosx") # Set to "Latest OS X"
 endif ()
 if (MSVC)
     # Visual Studio-specific setup
@@ -113,7 +113,11 @@ else ()
     elseif (NOT IOS)
         set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2 -ffast-math")
         set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-invalid-offsetof -O2 -ffast-math")
-        if (ENABLE_64BIT)
+        if (RASPI)
+            add_definitions (-DRASPI)
+            set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pipe -mcpu=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard")
+            set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pipe -mcpu=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard")
+        elseif (ENABLE_64BIT)
             set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m64")
             set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m64")
         else ()
@@ -174,7 +178,15 @@ macro (setup_executable)
         set_target_properties (${TARGET_NAME} PROPERTIES XCODE_ATTRIBUTE_TARGETED_DEVICE_FAMILY "1,2")
     else ()
         get_target_property (EXECUTABLE_NAME ${TARGET_NAME} LOCATION)
-        add_custom_command (TARGET ${TARGET_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${EXECUTABLE_NAME} ${PROJECT_SOURCE_DIR}/Bin)
+        if (CMAKE_CROSSCOMPILING)
+            file (MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/Bin-CC)
+            add_custom_command (TARGET ${TARGET_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${EXECUTABLE_NAME} ${CMAKE_BINARY_DIR}/Bin-CC)
+            if (SCP_TO_TARGET)
+                add_custom_command (TARGET ${TARGET_NAME} POST_BUILD COMMAND scp ${EXECUTABLE_NAME} ${SCP_TO_TARGET} || exit 0)
+            endif ()
+        else ()
+            add_custom_command (TARGET ${TARGET_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${EXECUTABLE_NAME} ${PROJECT_SOURCE_DIR}/Bin)
+        endif ()
     endif ()
 endmacro ()
 
@@ -286,8 +298,7 @@ add_subdirectory (ThirdParty/StanHull)
 add_subdirectory (ThirdParty/STB)
 add_subdirectory (ThirdParty/JO)
 
-# Alternative Lua bindings. Uncomment the following line to enable
-# set (ENABLE_LUA 1)
+# Alternative Lua bindings
 if (ENABLE_LUA)
     add_definitions (-DENABLE_LUA)
     add_subdirectory (ThirdParty/Lua)
@@ -295,42 +306,51 @@ if (ENABLE_LUA)
     add_subdirectory (Extras/LuaScript)
 endif ()
 
-if (NOT IOS AND NOT ANDROID)
-    if (USE_OPENGL)
-        add_subdirectory (ThirdParty/GLEW)
+# Assuming cross compiling is used to target embedded system, and hence it does not make sense to build the tools (except when it is explicitly enabled)
+if (NOT ENABLE_TOOLS)
+    if (CMAKE_CROSSCOMPILING)
+        set (ENABLE_TOOLS 0)
+    else ()
+        set (ENABLE_TOOLS 1)
     endif ()
-    add_subdirectory (ThirdParty/Assimp)
-    add_subdirectory (ThirdParty/LibCpuId)
+endif ()
+
+if (NOT IOS AND NOT ANDROID)
     if (ENABLE_LUA)
         add_subdirectory (ThirdParty/tolua++/src/bin)
     endif ()
-    add_subdirectory (Tools/AssetImporter)
-    add_subdirectory (Tools/OgreImporter)
-    add_subdirectory (Tools/PackageTool)
-    add_subdirectory (Tools/RampGenerator)
-    add_subdirectory (Tools/ScriptCompiler)
-    add_subdirectory (Tools/DocConverter)
+    if (NOT RASPI)
+        if (USE_OPENGL)
+            add_subdirectory (ThirdParty/GLEW)
+        endif ()
+        add_subdirectory (ThirdParty/LibCpuId)
+    endif ()
+    if (ENABLE_TOOLS)
+        add_subdirectory (ThirdParty/Assimp)
+        add_subdirectory (Tools/AssetImporter)
+        add_subdirectory (Tools/OgreImporter)
+        add_subdirectory (Tools/PackageTool)
+        add_subdirectory (Tools/RampGenerator)
+        add_subdirectory (Tools/ScriptCompiler)
+        add_subdirectory (Tools/DocConverter)
+    endif ()
 endif ()
 
-if (NOT USE_OPENGL)
+if (NOT USE_OPENGL AND ENABLE_TOOLS)
     add_subdirectory (ThirdParty/MojoShader)
     add_subdirectory (Tools/ShaderCompiler)
 endif ()
 
-# Urho3D samples. Uncomment to enable
-# set (ENABLE_SAMPLES 1)
+# Urho3D samples
 if (ENABLE_SAMPLES AND NOT IOS AND NOT ANDROID)
     add_subdirectory (Samples)
 endif ()   
 
-# Urho3D extras. Uncomment to enable
+# Urho3D extras
 # Todo: CharacterDemo will be moved to Samples
-# set (ENABLE_EXTRAS 1)
-if (ENABLE_EXTRAS)
-    if (NOT IOS AND NOT ANDROID)
-        add_subdirectory (Extras/OgreBatchConverter)
-        add_subdirectory (Extras/CharacterDemo)
-    endif ()
+if (ENABLE_EXTRAS AND NOT IOS AND NOT ANDROID)
+    add_subdirectory (Extras/OgreBatchConverter)
+    add_subdirectory (Extras/CharacterDemo)
 endif ()
 
 add_subdirectory (Urho3D)

+ 1 - 1
Doxyfile

@@ -716,7 +716,7 @@ EXCLUDE_SYMLINKS       = NO
 
 EXCLUDE_PATTERNS       = */*API*.cpp \
                          */*API*.h \
-                         */OpenGL/*
+                         */Direct3D9/*
 
 # The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names 
 # (namespaces, classes, functions, etc.) that should be excluded from the 

+ 1 - 1
Engine/Core/CMakeLists.txt

@@ -9,7 +9,7 @@ set (SOURCE_FILES ${CPP_FILES} ${H_FILES})
 # Define dependency libs
 set (LIBS ../Container ../Math)
 
-if (NOT IOS AND NOT ANDROID)
+if (NOT IOS AND NOT ANDROID AND NOT RASPI)
     set (INCLUDE_DIRS_ONLY ../../ThirdParty/LibCpuId/libcpuid)
     set (LINK_LIBS_ONLY LibCpuId)
 endif ()

+ 8 - 6
Engine/Core/ProcessUtils.cpp

@@ -34,7 +34,7 @@
 
 #if defined(IOS)
 #include <mach/mach_host.h>
-#elif !defined(ANDROID)
+#elif !defined(ANDROID) && !defined(RASPI)
 #include <libcpuid.h>
 #endif
 
@@ -47,7 +47,7 @@
 
 #if defined(_MSC_VER)
 #include <float.h>
-#elif !defined(ANDROID) && !defined(IOS)
+#elif !defined(ANDROID) && !defined(IOS) && !defined(RASPI)
 // From http://stereopsis.com/FPU.html
 
 #define FPU_CW_PREC_MASK        0x0300
@@ -91,7 +91,7 @@ void GetCPUData(host_basic_info_data_t* data)
     infoCount = HOST_BASIC_INFO_COUNT;
     host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)data, &infoCount);
 }
-#elif !defined(ANDROID)
+#elif !defined(ANDROID) && !defined(RASPI)
 void GetCPUData(struct cpu_id_t* data)
 {
     if (cpu_identify(0, data) < 0)
@@ -104,7 +104,7 @@ void GetCPUData(struct cpu_id_t* data)
 
 void InitFPU()
 {
-    #if !defined(ANDROID) && !defined(IOS) && !defined(__x86_64__) && !defined(_M_AMD64)
+    #if !defined(ANDROID) && !defined(IOS) && !defined(RASPI) && !defined(__x86_64__) && !defined(_M_AMD64)
     // Make sure FPU is in round-to-nearest, single precision mode
     // This ensures Direct3D and OpenGL behave similarly, and all threads behave similarly
     #ifdef _MSC_VER
@@ -345,6 +345,8 @@ String GetPlatform()
     return "Mac OS X";
     #elif defined(__linux__)
     return "Linux";
+    #elif defined(RASPI)
+    return "Raspberry Pi";
     #else
     return String::EMPTY;
     #endif
@@ -361,7 +363,7 @@ unsigned GetNumPhysicalCPUs()
     #else
     return data.physical_cpu;
     #endif
-    #elif !defined(ANDROID)
+    #elif !defined(ANDROID) && !defined(RASPI)
     struct cpu_id_t data;
     GetCPUData(&data);
     return data.num_cores;
@@ -381,7 +383,7 @@ unsigned GetNumLogicalCPUs()
     #else
     return data.logical_cpu;
     #endif
-    #elif !defined(ANDROID)
+    #elif !defined(ANDROID) && !defined(RASPI)
     struct cpu_id_t data;
     GetCPUData(&data);
     return data.num_logical_cpus;

+ 2 - 2
Engine/Engine/Engine.cpp

@@ -75,7 +75,7 @@ Engine::Engine(Context* context) :
     Object(context),
     timeStep_(0.0f),
     minFps_(10),
-    #if defined(ANDROID) || defined(IOS)
+    #if defined(ANDROID) || defined(IOS) || defined(RASPI)
     maxFps_(60),
     maxInactiveFps_(10),
     pauseMinimized_(true),
@@ -83,8 +83,8 @@ Engine::Engine(Context* context) :
     maxFps_(200),
     maxInactiveFps_(60),
     pauseMinimized_(false),
-    autoExit_(true),
     #endif
+    autoExit_(true),
     initialized_(false),
     exiting_(false),
     headless_(false),

+ 2 - 2
Engine/Graphics/CMakeLists.txt

@@ -21,12 +21,12 @@ set (INCLUDE_DIRS_ONLY .)
 set (LINK_LIBS_ONLY SDL)
 
 if (USE_OPENGL)
-    if (NOT IOS AND NOT ANDROID)
+    if (NOT IOS AND NOT ANDROID AND NOT RASPI)
         set (LIBS ${LIBS} ../../ThirdParty/GLEW)
     endif ()
     if (WIN32)
         set (LINK_LIBS_ONLY ${LINK_LIBS_ONLY} opengl32)
-    elseif (ANDROID)
+    elseif (ANDROID OR RASPI)
         set (LINK_LIBS_ONLY ${LINK_LIBS_ONLY} GLESv1_CM GLESv2)
     elseif (NOT APPLE)
         set (LINK_LIBS_ONLY ${LINK_LIBS_ONLY} GL)

+ 1 - 1
Engine/Graphics/Light.h

@@ -46,7 +46,7 @@ enum LightType
 static const float SHADOW_MIN_QUANTIZE = 0.1f;
 static const float SHADOW_MIN_VIEW = 1.0f;
 static const int MAX_LIGHT_SPLITS = 6;
-#if !defined(ANDROID) && !defined(IOS)
+#if !defined(ANDROID) && !defined(IOS) && !defined(RASPI)
 static const int MAX_CASCADE_SPLITS = 4;
 #else
 static const int MAX_CASCADE_SPLITS = 2;

+ 4 - 4
Engine/Graphics/OpenGL/OGLGraphicsImpl.h

@@ -26,7 +26,7 @@
 #include "HashMap.h"
 #include "Timer.h"
 
-#if defined(ANDROID)
+#if defined(ANDROID) || defined (RASPI)
 #include <GLES2/gl2.h>
 #include <GLES2/gl2ext.h>
 #elif defined(IOS)
@@ -74,7 +74,7 @@ struct FrameBufferObject
         for (unsigned i = 0; i < MAX_RENDERTARGETS; ++i)
             colorAttachments_[i] = 0;
     }
-    
+
     /// Frame buffer handle.
     unsigned fbo_;
     /// Bound color attachment textures.
@@ -93,13 +93,13 @@ struct FrameBufferObject
 class GraphicsImpl
 {
     friend class Graphics;
-    
+
 public:
     /// Construct.
     GraphicsImpl();
     /// Return the SDL window.
     SDL_Window* GetWindow() const { return window_; }
-    
+
 private:
     /// SDL window.
     SDL_Window* window_;

+ 5 - 0
Engine/Graphics/ShaderParser.cpp

@@ -175,6 +175,11 @@ bool ShaderParser::ParseOptions(const XMLElement& element)
                 require = require.GetNext("require");
             }
             
+            #ifdef RASPI
+            newOption.defines_.Push("RASPI");
+            newOption.defineValues_.Push("1");
+            #endif
+
             options_.Push(newOption);
             if (options_.Size() > 31)
             {

+ 1 - 1
Engine/Input/CMakeLists.txt

@@ -10,7 +10,7 @@ set (SOURCE_FILES ${CPP_FILES} ${H_FILES})
 set (LIBS ../Container ../Core ../Graphics ../IO ../Math ../Resource ../Scene)
 set (LINK_LIBS_ONLY SDL)
 
-if (USE_OPENGL)
+if (NOT IOS AND NOT ANDROID AND NOT RASPI AND USE_OPENGL)
     set (INCLUDE_DIRS_ONLY ${INCLUDE_DIRS_ONLY} ../../ThirdParty/GLEW)
 endif ()
 

+ 3 - 2
Extras/LuaScript/CMakeLists.txt

@@ -35,7 +35,8 @@ set (SOURCE_FILES ${SOURCE_FILES} generated/AudioLuaAPI.cpp generated/ContainerL
 
 # Define dependency libs
 set (LIBS ../../Engine/Audio ../../Engine/Container ../../Engine/Core ../../Engine/Engine ../../Engine/Graphics ../../Engine/Input ../../Engine/IO ../../Engine/Math ../../Engine/Navigation ../../Engine/Network
-    ../../Engine/Physics ../../Engine/Resource ../../Engine/Scene ../../Engine/UI ../../ThirdParty/Lua/src ../../ThirdParty/tolua++_static)
+    ../../Engine/Physics ../../Engine/Resource ../../Engine/Scene ../../Engine/UI ../../ThirdParty/Lua/src)
+set (LINK_LIBS_ONLY tolua++_static)
 set (INCLUDE_DIRS_ONLY . ../../ThirdParty/Bullet/src ../../ThirdParty/kNet/include ../../ThirdParty/tolua++/include)
 
 # Setup target
@@ -44,7 +45,7 @@ setup_library ()
 
 # For IOS and Android build to be successful, the "tolua++" tool must be present in the "Bin" folder.
 # One way to achieve this is to first do a desktop build where all the tools would be generated, then switch to IOS/Android build.
-if (NOT IOS AND NOT ANDROID)
+if (NOT IOS AND NOT ANDROID AND NOT RASPI)
     # Add dependency to the "tolua++" bin tool
     add_dependencies(${TARGET_NAME} tolua++)
 endif ()

+ 1 - 1
ThirdParty/AngelScript/CMakeLists.txt

@@ -9,7 +9,7 @@ file (GLOB H_FILES
     include/*.h source/*.h
 )
 
-if (IOS OR ANDROID)
+if (IOS OR ANDROID OR RASPI)
     enable_language (ASM)
     if (IOS)
         set (ASM_FILES source/as_callfunc_arm_xcode.S)

+ 44 - 36
ThirdParty/SDL/CMakeLists.txt

@@ -39,49 +39,57 @@ elseif (ANDROID)
         src/thread/pthread/*.c src/timer/unix/*.c src/video/android/*.c
     )
 else ()
-    include(CheckCSourceCompiles)
-
     # On Linux, make sure development libraries exist, and use their include file directories  
-    find_package (OpenGL REQUIRED)
-    find_package (X11 REQUIRED)
-    if (NOT X11_Xrandr_FOUND)
-        message (FATAL_ERROR "Could not find XRandR (libxrandr-dev)")
+    if (RASPI)
+        #TODO: find_package (BCM_VC REQUIRED)
+        set (LINK_LIBS_ONLY bcm_host)
+        file (GLOB VIDEO_DRIVER_C_FILES src/video/raspi/*.c)
+    else ()
+        find_package (OpenGL REQUIRED)
+        include_directories (${OpenGL_INCLUDE_DIRS})
+        
+        find_package (X11 REQUIRED)
+        if (NOT X11_Xrandr_FOUND)
+            message (FATAL_ERROR "Could not find XRandR (libxrandr-dev)")
+        endif ()
+        include_directories (${X11_INCLUDE_DIRS})  
+
+        message ("--")
+        message ("-- Following tests check whether X11 library installed in this system uses _Xconst in below functions")
+        message ("-- A failed test result simply means the installed X11 library does not use _Xconst")
+        message ("-- It is OK to proceed to build Urho3D regardless of the test result")
+        include (CheckCSourceCompiles)
+        set  (CMAKE_REQUIRED_LIBRARIES ${X11_LIB} ${X11_LIB})
+        check_c_source_compiles ("
+            #include <X11/Xlib.h>
+            #include <X11/Xproto.h>
+            #include <X11/extensions/Xext.h>
+            #include <X11/extensions/extutil.h>
+            extern XExtDisplayInfo* XextAddDisplay(XExtensionInfo* a,Display* b,_Xconst char* c,XExtensionHooks* d,int e,XPointer f);
+            int main(int argc, char **argv) {}" HAVE_CONST_XEXT_ADDDISPLAY)
+        if (HAVE_CONST_XEXT_ADDDISPLAY)
+            add_definitions (-DSDL_VIDEO_DRIVER_X11_CONST_PARAM_XEXTADDDISPLAY)
+        endif ()
+        check_c_source_compiles ("
+            #include <X11/Xlibint.h>
+            extern int _XData32(Display *dpy,register _Xconst long *data,unsigned len);
+            int main(int argc, char **argv) {}" HAVE_CONST_XDATA32)
+        if (HAVE_CONST_XDATA32)
+            add_definitions (-DSDL_VIDEO_DRIVER_X11_CONST_PARAM_XDATA32)
+        endif ()
+        set (CMAKE_REQUIRED_LIBRARIES)
+        message ("--")
+        
+        file (GLOB VIDEO_DRIVER_C_FILES src/video/x11/*.c)
     endif ()
     find_package (ALSA REQUIRED)
-
-    include_directories (${OpenGL_INCLUDE_DIRS})
-    include_directories (${X11_INCLUDE_DIRS})  
     include_directories (${ALSA_INCLUDE_DIRS})
 
-    set(CMAKE_REQUIRED_LIBRARIES ${X11_LIB} ${X11_LIB})
-    message ("--")
-    message ("-- Following tests check whether X11 library installed in this system uses _Xconst in below functions")
-    message ("-- A failed test result simply means the installed X11 library does not use _Xconst")
-    message ("-- It is OK to proceed to build Urho3D regardless of the test result")
-    check_c_source_compiles("
-        #include <X11/Xlib.h>
-        #include <X11/Xproto.h>
-        #include <X11/extensions/Xext.h>
-        #include <X11/extensions/extutil.h>
-        extern XExtDisplayInfo* XextAddDisplay(XExtensionInfo* a,Display* b,_Xconst char* c,XExtensionHooks* d,int e,XPointer f);
-        int main(int argc, char **argv) {}" HAVE_CONST_XEXT_ADDDISPLAY)
-    if (HAVE_CONST_XEXT_ADDDISPLAY)
-        add_definitions (-DSDL_VIDEO_DRIVER_X11_CONST_PARAM_XEXTADDDISPLAY)
-    endif ()
-    check_c_source_compiles("
-        #include <X11/Xlibint.h>
-        extern int _XData32(Display *dpy,register _Xconst long *data,unsigned len);
-        int main(int argc, char **argv) {}" HAVE_CONST_XDATA32)
-    if (HAVE_CONST_XDATA32)
-        add_definitions (-DSDL_VIDEO_DRIVER_X11_CONST_PARAM_XDATA32)
-    endif ()
-    message ("--")
-    set(CMAKE_REQUIRED_LIBRARIES)
-
     file (GLOB SYS_C_FILES
         src/audio/alsa/*.c src/audio/dma/*.c src/audio/dsp/*.c src/haptic/linux/*.c src/joystick/linux/*.c src/loadso/dlopen/*.c
-        src/power/linux/*.c src/thread/pthread/*.c src/timer/unix/*.c src/video/x11/*.c
+        src/power/linux/*.c src/thread/pthread/*.c src/timer/unix/*.c
     )
+    set (SYS_C_FILES ${SYS_C_FILES} ${VIDEO_DRIVER_C_FILES})
 endif ()
 
 file (GLOB H_FILES include/*.h)
@@ -100,5 +108,5 @@ elseif (APPLE)
 elseif (ANDROID)
     target_link_libraries (${TARGET_NAME} dl log)
 else ()
-    target_link_libraries (${TARGET_NAME} dl pthread rt)
+    target_link_libraries (${TARGET_NAME} dl pthread rt ${LINK_LIBS_ONLY})
 endif ()

+ 17 - 1
ThirdParty/SDL/include/SDL_config_linux.h

@@ -20,6 +20,8 @@
   3. This notice may not be removed or altered from any source distribution.
 */
 
+// Modified by Yao Wei Tjong for Urho3D
+
 #ifndef _SDL_config_linux_h
 #define _SDL_config_linux_h
 
@@ -127,7 +129,7 @@
 #define HAVE_SSCANF 1
 #define HAVE_SNPRINTF 1
 #define HAVE_VSNPRINTF 1
-#define HAVE_M_PI /**/
+#define HAVE_M_PI 1
 #define HAVE_ATAN 1
 #define HAVE_ATAN2 1
 #define HAVE_CEIL 1
@@ -272,6 +274,18 @@
 #define SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS 1
 #define SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM 1
 
+// Urho3D: Use OpenGL ES 2 implementation from Broadcom VideoCore for Raspberry Pi
+#ifdef RASPI
+#undef SDL_VIDEO_DRIVER_X11			/* No X */
+#define SDL_VIDEO_DRIVER_RASPI 1
+
+/* Enable OpenGL ES 2 */
+#define SDL_VIDEO_OPENGL_ES2 1
+#define SDL_VIDEO_RENDER_OGL_ES 1
+#define SDL_VIDEO_RENDER_OGL_ES2 1
+
+#else
+
 /* #undef SDL_VIDEO_RENDER_D3D */
 #define SDL_VIDEO_RENDER_OGL 1
 /* #undef SDL_VIDEO_RENDER_OGL_ES */
@@ -288,6 +302,8 @@
 /* #undef SDL_VIDEO_OPENGL_OSMESA */
 /* #undef SDL_VIDEO_OPENGL_OSMESA_DYNAMIC */
 
+#endif
+
 /* Enable system power support */
 #define SDL_POWER_LINUX 1
 /* #undef SDL_POWER_WINDOWS */

+ 7 - 0
ThirdParty/SDL/src/video/SDL_sysvideo.h

@@ -18,6 +18,9 @@
      misrepresented as being the original software.
   3. This notice may not be removed or altered from any source distribution.
 */
+
+// Modified by Yao Wei Tjong for Urho3D
+
 #include "SDL_config.h"
 
 #ifndef _SDL_sysvideo_h
@@ -351,6 +354,10 @@ extern VideoBootStrap Android_bootstrap;
 #if SDL_VIDEO_DRIVER_PSP
 extern VideoBootStrap PSP_bootstrap;
 #endif
+// Urho3D: add Raspberry Pi support
+#if SDL_VIDEO_DRIVER_RASPI
+extern VideoBootStrap RASPI_bootstrap;
+#endif
 #if SDL_VIDEO_DRIVER_DUMMY
 extern VideoBootStrap DUMMY_bootstrap;
 #endif

+ 10 - 20
ThirdParty/SDL/src/video/SDL_video.c

@@ -19,7 +19,7 @@
   3. This notice may not be removed or altered from any source distribution.
 */
 
-// Modified by Lasse Oorni for Urho3D
+// Modified by Lasse Oorni and Yao Wei Tjong for Urho3D
 
 #include "SDL_config.h"
 
@@ -82,6 +82,10 @@ static VideoBootStrap *bootstrap[] = {
 #if SDL_VIDEO_DRIVER_PSP
     &PSP_bootstrap,
 #endif
+// Urho3D: add Raspberry Pi support
+#if SDL_VIDEO_DRIVER_RASPI
+    &RASPI_bootstrap,
+#endif
 #if SDL_VIDEO_DRIVER_DUMMY
     &DUMMY_bootstrap,
 #endif
@@ -123,25 +127,22 @@ typedef struct {
     int bytes_per_pixel;
 } SDL_WindowTextureData;
 
+// Urho3D: renderer disabled
+/*
 static SDL_bool
 ShouldUseTextureFramebuffer()
 {
     const char *hint;
 
-    /* If there's no native framebuffer support then there's no option */
     if (!_this->CreateWindowFramebuffer) {
         return SDL_TRUE;
     }
 
-    /* If the user has specified a software renderer we can't use a
-       texture framebuffer, or renderer creation will go recursive.
-     */
     hint = SDL_GetHint(SDL_HINT_RENDER_DRIVER);
     if (hint && SDL_strcasecmp(hint, "software") == 0) {
         return SDL_FALSE;
     }
 
-    /* See if the user or application wants a specific behavior */
     hint = SDL_GetHint(SDL_HINT_FRAMEBUFFER_ACCELERATION);
     if (hint) {
         if (*hint == '0') {
@@ -151,20 +152,14 @@ ShouldUseTextureFramebuffer()
         }
     }
 
-    /* Each platform has different performance characteristics */
 #if defined(__WIN32__)
-    /* GDI BitBlt() is way faster than Direct3D dynamic textures right now.
-     */
     return SDL_FALSE;
 
 #elif defined(__MACOSX__)
-    /* Mac OS X uses OpenGL as the native fast path */
     return SDL_TRUE;
 
 #elif defined(__LINUX__)
-    /* Properly configured OpenGL drivers are faster than MIT-SHM */
 #if SDL_VIDEO_OPENGL
-    /* Ugh, find a way to cache this value! */
     {
         SDL_Window *window;
         SDL_GLContext context;
@@ -181,7 +176,6 @@ ShouldUseTextureFramebuffer()
                 if (glGetStringFunc) {
                     vendor = (const char *) glGetStringFunc(GL_VENDOR);
                 }
-                /* Add more vendors here at will... */
                 if (vendor &&
                     (SDL_strstr(vendor, "ATI Technologies") ||
                      SDL_strstr(vendor, "NVIDIA"))) {
@@ -194,22 +188,16 @@ ShouldUseTextureFramebuffer()
         return hasAcceleratedOpenGL;
     }
 #elif SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
-    /* Let's be optimistic about this! */
     return SDL_TRUE;
 #else
     return SDL_FALSE;
 #endif
 
 #else
-    /* Play it safe, assume that if there is a framebuffer driver that it's
-       optimized for the current platform.
-    */
     return SDL_FALSE;
 #endif
 }
 
-// Urho3D: renderer disabled
-/*
 static int
 SDL_CreateWindowTexture(_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch)
 {
@@ -1288,7 +1276,7 @@ SDL_CreateWindowFrom(const void *data, Uint32 flags)
         SDL_GL_LoadLibrary(NULL);
         window->flags |= SDL_WINDOW_OPENGL;
     }
-    
+
     if (!_this->CreateWindowFrom ||
         _this->CreateWindowFrom(_this, window, data) < 0) {
         SDL_DestroyWindow(window);
@@ -2127,6 +2115,7 @@ SDL_DestroyWindow(SDL_Window * window)
 
     CHECK_WINDOW_MAGIC(window, );
 
+#if !SDL_VIDEO_OPENGL_ES && !SDL_VIDEO_OPENGL_ES2
     // Urho3D: make context uncurrent first
     /* make no context current if this is the current context window. */
     if (window->flags & SDL_WINDOW_OPENGL) {
@@ -2134,6 +2123,7 @@ SDL_DestroyWindow(SDL_Window * window)
             SDL_GL_MakeCurrent(window, NULL);
         }
     }
+#endif
 
     /* Restore video mode, etc. */
     SDL_HideWindow(window);

+ 5 - 0
ThirdParty/SDL/src/video/android/SDL_androidvideo.c

@@ -18,6 +18,9 @@
      misrepresented as being the original software.
   3. This notice may not be removed or altered from any source distribution.
 */
+
+// Modified by Yao Wei Tjong for Urho3D
+
 #include "SDL_config.h"
 
 #if SDL_VIDEO_DRIVER_ANDROID
@@ -77,6 +80,8 @@ Android_Available(void)
 static void
 Android_DeleteDevice(SDL_VideoDevice * device)
 {
+	// Urho3D: bug fix
+	SDL_free(device->driverdata);
     SDL_free(device);
 }
 

+ 164 - 0
ThirdParty/SDL/src/video/raspi/SDL_raspievents.c

@@ -0,0 +1,164 @@
+/*
+  Simple DirectMedia Layer
+  Copyright (C) 1997-2013 Sam Lantinga <[email protected]>
+
+  This software is provided 'as-is', without any express or implied
+  warranty.  In no event will the authors be held liable for any damages
+  arising from the use of this software.
+
+  Permission is granted to anyone to use this software for any purpose,
+  including commercial applications, and to alter it and redistribute it
+  freely, subject to the following restrictions:
+
+  1. The origin of this software must not be misrepresented; you must not
+     claim that you wrote the original software. If you use this software
+     in a product, an acknowledgment in the product documentation would be
+     appreciated but is not required.
+  2. Altered source versions must be plainly marked as such, and must not be
+     misrepresented as being the original software.
+  3. This notice may not be removed or altered from any source distribution.
+*/
+
+// Created by Yao Wei Tjong for Urho3D
+
+#include "SDL_config.h"
+
+#if SDL_VIDEO_DRIVER_RASPI
+
+#include "../../events/SDL_events_c.h"
+#include "SDL_raspivideo.h"
+
+#include <linux/input.h>
+#include <fcntl.h>
+
+static int event_fd[] = { -1, -1 };        /* assume two USB HID input devices */
+struct input_event event[64];
+#define NUM_INPUT_DEVICE sizeof(event_fd) / sizeof(int)
+
+static SDL_Keycode keymap[] = {
+    0,
+    SDLK_ESCAPE,'1','2','3','4','5','6','7','8','9','0','-','=',SDLK_BACKSPACE,
+    SDLK_TAB,'q','w','e','r','t','y','u','i','o','p','[',']',SDLK_RETURN,
+    SDLK_LCTRL,'a','s','d','f','g','h','j','k','l',';','\'','`',
+    SDLK_LSHIFT,'\\','z','x','c','v','b','n','m',',','.','/',SDLK_RSHIFT,
+    SDLK_KP_MULTIPLY,SDLK_LALT,SDLK_SPACE,SDLK_CAPSLOCK,
+    SDLK_F1,SDLK_F2,SDLK_F3,SDLK_F4,SDLK_F5,SDLK_F6,SDLK_F7,SDLK_F8,SDLK_F9,SDLK_F10,
+    SDLK_NUMLOCKCLEAR,SDLK_SCROLLLOCK,
+    SDLK_KP_7,SDLK_KP_8,SDLK_KP_9,SDLK_KP_MINUS,SDLK_KP_4,SDLK_KP_5,SDLK_KP_6,
+    SDLK_KP_PLUS,SDLK_KP_1,SDLK_KP_2,SDLK_KP_3,SDLK_KP_0,SDLK_KP_PERIOD,
+    0,0,0,SDLK_F11,SDLK_F12,0,0,0,0,0,0,0,
+    SDLK_KP_ENTER,SDLK_RCTRL,SDLK_KP_DIVIDE,SDLK_PRINTSCREEN,SDLK_RALT,0,
+    SDLK_HOME,SDLK_UP,SDLK_PAGEUP,SDLK_LEFT,SDLK_RIGHT,SDLK_END,SDLK_DOWN,SDLK_PAGEDOWN,SDLK_INSERT,SDLK_DELETE,
+    0,0,0,0,0,0,0,SDL_SCANCODE_PAUSE,0,0,0,0,0,SDLK_LGUI,SDLK_RGUI,
+};
+
+static int
+TranslateMouseButton(__u16 code) {
+    switch (code) {
+    case 272:
+        return SDL_BUTTON_LEFT;
+    case 273:
+        return SDL_BUTTON_RIGHT;
+    case 274:
+        return SDL_BUTTON_MIDDLE;
+    default:
+        return -1;
+    }
+}
+
+static void
+PropagateEvents(_THIS, int index)
+{
+    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
+
+    int i, count, button, x, y, relevent;
+    if ((count = read(event_fd[index], event, sizeof(event))) < 0) {
+        return;
+    }
+    count = count / sizeof(struct input_event);
+    for (i = 0; i < count; ++i) {
+        switch (event[i].type) {
+        case EV_KEY:
+            if (event[i].code < sizeof(keymap) / sizeof(SDL_Keycode)) {
+                SDL_SendKeyboardKey(event[i].value, event[i].code);
+            }
+            else if ((button = TranslateMouseButton(event[i].code)) != -1) {
+                SDL_SendMouseButton(data->window, index, event[i].value, button);
+            }
+            break;
+
+        case EV_REL:
+            switch (event[i].code) {
+            case REL_X:
+            case REL_HWHEEL:
+                x = event[i].value;
+                relevent = event[i].code == REL_X ? 1 : 2;
+                break;
+            case REL_Y:
+            case REL_WHEEL:
+                y = event[i].value;
+                relevent = event[i].code == REL_Y ? 1 : 2;
+                break;
+            default:
+                relevent = 0;
+            }
+            break;
+
+        case EV_SYN:
+            switch (relevent) {
+            case 1:
+                SDL_SendMouseMotion(data->window, index, 1, x, y);
+                break;
+            case 2:
+                SDL_SendMouseWheel(data->window, index, x, y);
+                break;
+            default: ;
+            }
+            break;
+
+        default: ;
+        }
+    }
+}
+
+void
+RASPI_PumpEvents(_THIS)
+{
+    int i;
+    for (i = 0; i < NUM_INPUT_DEVICE; ++i) {
+        PropagateEvents(_this, i);
+    }
+}
+
+int
+RASPI_InitInput(_THIS)
+{
+    int i;
+    char device[32];
+    for (i = 0; i < NUM_INPUT_DEVICE; ++i) {
+        sprintf(device, "/dev/input/event%i", i);
+        event_fd[i] = open(device, O_RDONLY | O_NONBLOCK);
+        if (event_fd[i] < 0) {
+            return SDL_SetError("Couldn't open %s", device);
+        }
+    }
+
+    /* Set Linux scancode to SDL key mapping */
+    SDL_SetKeymap(0, keymap, sizeof(keymap));
+
+    return 0;
+}
+
+void
+RASPI_QuitInput(_THIS)
+{
+    int i;
+    for (i = 0; i < NUM_INPUT_DEVICE; ++i) {
+        close(event_fd[i]);
+        event_fd[i] = -1;
+    }
+}
+
+#endif /* SDL_VIDEO_DRIVER_RASPI */
+
+/* vi: set ts=4 sw=4 expandtab: */

+ 35 - 0
ThirdParty/SDL/src/video/raspi/SDL_raspievents.h

@@ -0,0 +1,35 @@
+/*
+  Simple DirectMedia Layer
+  Copyright (C) 1997-2013 Sam Lantinga <[email protected]>
+
+  This software is provided 'as-is', without any express or implied
+  warranty.  In no event will the authors be held liable for any damages
+  arising from the use of this software.
+
+  Permission is granted to anyone to use this software for any purpose,
+  including commercial applications, and to alter it and redistribute it
+  freely, subject to the following restrictions:
+
+  1. The origin of this software must not be misrepresented; you must not
+     claim that you wrote the original software. If you use this software
+     in a product, an acknowledgment in the product documentation would be
+     appreciated but is not required.
+  2. Altered source versions must be plainly marked as such, and must not be
+     misrepresented as being the original software.
+  3. This notice may not be removed or altered from any source distribution.
+*/
+
+// Created by Yao Wei Tjong for Urho3D
+
+#include "SDL_config.h"
+
+#ifndef _SDL_raspievents_h
+#define _SDL_raspievents_h
+
+extern void RASPI_PumpEvents(_THIS);
+extern int RASPI_InitInput(_THIS);
+extern void RASPI_QuitInput(_THIS);
+
+#endif /* _SDL_raspievents_h */
+
+/* vi: set ts=4 sw=4 expandtab: */

+ 384 - 0
ThirdParty/SDL/src/video/raspi/SDL_raspiopengles.c

@@ -0,0 +1,384 @@
+/*
+  Simple DirectMedia Layer
+  Copyright (C) 1997-2013 Sam Lantinga <[email protected]>
+
+  This software is provided 'as-is', without any express or implied
+  warranty.  In no event will the authors be held liable for any damages
+  arising from the use of this software.
+
+  Permission is granted to anyone to use this software for any purpose,
+  including commercial applications, and to alter it and redistribute it
+  freely, subject to the following restrictions:
+
+  1. The origin of this software must not be misrepresented; you must not
+     claim that you wrote the original software. If you use this software
+     in a product, an acknowledgment in the product documentation would be
+     appreciated but is not required.
+  2. Altered source versions must be plainly marked as such, and must not be
+     misrepresented as being the original software.
+  3. This notice may not be removed or altered from any source distribution.
+*/
+
+// Created by Yao Wei Tjong for Urho3D
+
+#include "SDL_config.h"
+
+#if SDL_VIDEO_DRIVER_RASPI
+
+#include "SDL_raspiopengles.h"
+#include "SDL_raspivideo.h"
+
+#include <dlfcn.h>
+
+#define DEFAULT_EGL "libEGL.so"
+#define DEFAULT_OGL_ES2 "libGLESv2.so"
+#define DEFAULT_OGL_ES_PVR "libGLES_CM.so"
+#define DEFAULT_OGL_ES "libGLESv1_CM.so"
+
+#define LOAD_FUNC(NAME) \
+    *((void**)&_this->gles_data->NAME) = dlsym(handle, #NAME); \
+    if (!_this->gles_data->NAME) \
+    { \
+        return SDL_SetError("Could not retrieve EGL function " #NAME); \
+    }
+
+/* GLES implementation of SDL OpenGL support */
+
+void *
+RASPI_GLES_GetProcAddress(_THIS, const char *proc)
+{
+    static char procname[1024];
+    void *handle;
+    void *retval;
+
+    handle = _this->gles_data->egl_dll_handle;
+    if (_this->gles_data->eglGetProcAddress) {
+        retval = _this->gles_data->eglGetProcAddress(proc);
+        if (retval) {
+            return retval;
+        }
+    }
+
+    handle = _this->gl_config.dll_handle;
+    retval = dlsym(handle, proc);
+    if (!retval && strlen(proc) <= 1022) {
+        procname[0] = '_';
+        strcpy(procname + 1, proc);
+        retval = dlsym(handle, procname);
+    }
+    return retval;
+}
+
+int
+RASPI_GLES_LoadLibrary(_THIS, const char *path)
+{
+    void *handle;
+    int dlopen_flags;
+
+    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
+
+    if (_this->gles_data) {
+        return SDL_SetError("OpenGL ES context already created");
+    }
+
+    if (_this->gl_config.use_egl == 0) {
+        return SDL_SetError("SDL not configured with OpenGL/GLX support");
+    }
+
+#ifdef RTLD_GLOBAL
+    dlopen_flags = RTLD_LAZY | RTLD_GLOBAL;
+#else
+    dlopen_flags = RTLD_LAZY;
+#endif
+    handle = dlopen(path, dlopen_flags);
+    /* Catch the case where the application isn't linked with EGL */
+    if ((dlsym(handle, "eglChooseConfig") == NULL) && (path == NULL)) {
+
+        dlclose(handle);
+        path = getenv("SDL_VIDEO_EGL_DRIVER");
+        if (path == NULL) {
+            path = DEFAULT_EGL;
+        }
+        handle = dlopen(path, dlopen_flags);
+    }
+
+    if (handle == NULL) {
+        return SDL_SetError("Could not load OpenGL ES/EGL library");
+    }
+
+    /* Unload the old driver and reset the pointers */
+    RASPI_GLES_UnloadLibrary(_this);
+
+    _this->gles_data = (struct SDL_PrivateGLESData *) SDL_calloc(1, sizeof(SDL_PrivateGLESData));
+    if (!_this->gles_data) {
+        return SDL_OutOfMemory();
+    }
+
+    /* Load new function pointers */
+    LOAD_FUNC(eglGetDisplay);
+    LOAD_FUNC(eglInitialize);
+    LOAD_FUNC(eglTerminate);
+    LOAD_FUNC(eglGetProcAddress);
+    LOAD_FUNC(eglChooseConfig);
+    LOAD_FUNC(eglGetConfigAttrib);
+    LOAD_FUNC(eglCreateContext);
+    LOAD_FUNC(eglDestroyContext);
+    LOAD_FUNC(eglCreateWindowSurface);
+    LOAD_FUNC(eglDestroySurface);
+    LOAD_FUNC(eglMakeCurrent);
+    LOAD_FUNC(eglSwapBuffers);
+    LOAD_FUNC(eglSwapInterval);
+
+    _this->gles_data->egl_display = _this->gles_data->eglGetDisplay(EGL_DEFAULT_DISPLAY);
+
+    if (!_this->gles_data->egl_display) {
+        return SDL_SetError("Could not get EGL display");
+    }
+
+    if (_this->gles_data->
+        eglInitialize(_this->gles_data->egl_display, NULL,
+                      NULL) != EGL_TRUE) {
+        return SDL_SetError("Could not initialize EGL");
+    }
+
+    _this->gles_data->egl_dll_handle = handle;
+
+    path = getenv("SDL_VIDEO_GL_DRIVER");
+    handle = dlopen(path, dlopen_flags);
+    if ((path == NULL) | (handle == NULL)) {
+        if (_this->gl_config.major_version > 1) {
+            path = DEFAULT_OGL_ES2;
+            handle = dlopen(path, dlopen_flags);
+        } else {
+            path = DEFAULT_OGL_ES;
+            handle = dlopen(path, dlopen_flags);
+            if (handle == NULL) {
+                path = DEFAULT_OGL_ES_PVR;
+                handle = dlopen(path, dlopen_flags);
+            }
+        }
+    }
+
+    if (handle == NULL) {
+        return SDL_SetError("Could not initialize OpenGL ES library");
+    }
+
+    _this->gl_config.dll_handle = handle;
+    _this->gl_config.driver_loaded = 1;
+
+    if (path) {
+        strncpy(_this->gl_config.driver_path, path,
+                sizeof(_this->gl_config.driver_path) - 1);
+    } else {
+        strcpy(_this->gl_config.driver_path, "");
+    }
+    return 0;
+}
+
+void
+RASPI_GLES_UnloadLibrary(_THIS)
+{
+    if ((_this->gles_data) && (_this->gl_config.driver_loaded)) {
+        _this->gles_data->eglTerminate(_this->gles_data->egl_display);
+
+        dlclose(_this->gl_config.dll_handle);
+        dlclose(_this->gles_data->egl_dll_handle);
+
+        SDL_free(_this->gles_data);
+        _this->gles_data = NULL;
+
+        _this->gl_config.dll_handle = NULL;
+        _this->gl_config.driver_loaded = 0;
+    }
+}
+
+int
+RASPI_GLES_ChooseConfig(_THIS)
+{
+    /* 64 seems nice. */
+    EGLint attribs[64];
+    EGLint found_configs = 0;
+    int i;
+
+    if (!_this->gles_data) {
+        /* The EGL library wasn't loaded, SDL_GetError() should have info */
+        return -1;
+    }
+
+    i = 0;
+    attribs[i++] = EGL_RED_SIZE;
+    attribs[i++] = _this->gl_config.red_size;
+    attribs[i++] = EGL_GREEN_SIZE;
+    attribs[i++] = _this->gl_config.green_size;
+    attribs[i++] = EGL_BLUE_SIZE;
+    attribs[i++] = _this->gl_config.blue_size;
+
+    if (_this->gl_config.alpha_size) {
+        attribs[i++] = EGL_ALPHA_SIZE;
+        attribs[i++] = _this->gl_config.alpha_size;
+    }
+
+    if (_this->gl_config.buffer_size) {
+        attribs[i++] = EGL_BUFFER_SIZE;
+        attribs[i++] = _this->gl_config.buffer_size;
+    }
+
+    attribs[i++] = EGL_DEPTH_SIZE;
+    attribs[i++] = _this->gl_config.depth_size;
+
+    if (_this->gl_config.stencil_size) {
+        attribs[i++] = EGL_STENCIL_SIZE;
+        attribs[i++] = _this->gl_config.stencil_size;
+    }
+
+    if (_this->gl_config.multisamplebuffers) {
+        attribs[i++] = EGL_SAMPLE_BUFFERS;
+        attribs[i++] = _this->gl_config.multisamplebuffers;
+    }
+
+    if (_this->gl_config.multisamplesamples) {
+        attribs[i++] = EGL_SAMPLES;
+        attribs[i++] = _this->gl_config.multisamplesamples;
+    }
+
+    attribs[i++] = EGL_RENDERABLE_TYPE;
+    if (_this->gl_config.major_version == 2) {
+        attribs[i++] = EGL_OPENGL_ES2_BIT;
+    } else {
+        attribs[i++] = EGL_OPENGL_ES_BIT;
+    }
+
+    attribs[i++] = EGL_NONE;
+
+    if (_this->gles_data->eglChooseConfig(_this->gles_data->egl_display,
+                                          attribs,
+                                          &_this->gles_data->egl_config, 1,
+                                          &found_configs) == EGL_FALSE ||
+        found_configs == 0) {
+        return SDL_SetError("Couldn't find matching EGL config");
+    }
+
+    return 0;
+}
+
+SDL_GLContext
+RASPI_GLES_CreateContext(_THIS, SDL_Window *window)
+{
+    EGLint context_attrib_list[] = {
+        EGL_CONTEXT_CLIENT_VERSION,
+        1,
+        EGL_NONE
+    };
+
+    if (_this->gl_config.major_version) {
+        context_attrib_list[1] = _this->gl_config.major_version;
+    }
+
+    _this->gles_data->egl_context =
+        _this->gles_data->eglCreateContext(_this->gles_data->egl_display,
+                                           _this->gles_data->egl_config,
+                                           EGL_NO_CONTEXT, context_attrib_list);
+
+    if (_this->gles_data->egl_context == EGL_NO_CONTEXT) {
+        SDL_SetError("Could not create EGL context");
+        return NULL;
+    }
+
+    _this->gles_data->egl_swapinterval = 0;
+
+    SDL_GLContext context = (SDL_GLContext)1;
+    if (RASPI_GLES_MakeCurrent(_this, window, context) < 0) {
+        RASPI_GLES_DeleteContext(_this, context);
+        return NULL;
+    }
+
+    return context;
+}
+
+int
+RASPI_GLES_MakeCurrent(_THIS, SDL_Window *window, SDL_GLContext context)
+{
+    if (!_this->gles_data) {
+        return SDL_SetError("OpenGL not initialized");
+    }
+
+    if (!_this->gles_data->eglMakeCurrent(_this->gles_data->egl_display,
+                                          _this->gles_data->egl_surface,
+                                          _this->gles_data->egl_surface,
+                                          _this->gles_data->egl_context)) {
+        return SDL_SetError("Unable to make EGL context current");
+    }
+
+    return 1;
+}
+
+int
+RASPI_GLES_SetSwapInterval(_THIS, int interval)
+{
+    if (!_this->gles_data) {
+        return SDL_SetError("OpenGL ES context not active");
+    }
+
+    EGLBoolean status;
+    status = _this->gles_data->eglSwapInterval(_this->gles_data->egl_display, interval);
+    if (status == EGL_TRUE) {
+        _this->gles_data->egl_swapinterval = interval;
+        return 0;
+    }
+
+    return SDL_SetError("Unable to set the EGL swap interval");
+}
+
+int
+RASPI_GLES_GetSwapInterval(_THIS)
+{
+    if (!_this->gles_data) {
+        return SDL_SetError("OpenGL ES context not active");
+    }
+
+    return _this->gles_data->egl_swapinterval;
+}
+
+void
+RASPI_GLES_SwapWindow(_THIS, SDL_Window * window)
+{
+    _this->gles_data->eglSwapBuffers(_this->gles_data->egl_display,
+                                     _this->gles_data->egl_surface);
+}
+
+void
+RASPI_GLES_DeleteContext(_THIS, SDL_GLContext context)
+{
+    /* Clean up GLES and EGL */
+    if (!_this->gles_data) {
+        return;
+    }
+
+    if (_this->gles_data->egl_context != EGL_NO_CONTEXT ||
+        _this->gles_data->egl_surface != EGL_NO_SURFACE) {
+        _this->gles_data->eglMakeCurrent(_this->gles_data->egl_display,
+                                         EGL_NO_SURFACE, EGL_NO_SURFACE,
+                                         EGL_NO_CONTEXT);
+
+        if (_this->gles_data->egl_context != EGL_NO_CONTEXT) {
+            _this->gles_data->eglDestroyContext(_this->gles_data->egl_display,
+                                                _this->gles_data->
+                                                egl_context);
+            _this->gles_data->egl_context = EGL_NO_CONTEXT;
+        }
+
+        if (_this->gles_data->egl_surface != EGL_NO_SURFACE) {
+            _this->gles_data->eglDestroySurface(_this->gles_data->egl_display,
+                                                _this->gles_data->
+                                                egl_surface);
+            _this->gles_data->egl_surface = EGL_NO_SURFACE;
+        }
+    }
+
+    /* Inherited the crappy fix from SDL_x11opengles.c */
+    RASPI_GLES_UnloadLibrary(_this);
+}
+
+#endif /* SDL_VIDEO_DRIVER_RASPI */
+
+/* vi: set ts=4 sw=4 expandtab: */

+ 98 - 0
ThirdParty/SDL/src/video/raspi/SDL_raspiopengles.h

@@ -0,0 +1,98 @@
+/*
+  Simple DirectMedia Layer
+  Copyright (C) 1997-2013 Sam Lantinga <[email protected]>
+
+  This software is provided 'as-is', without any express or implied
+  warranty.  In no event will the authors be held liable for any damages
+  arising from the use of this software.
+
+  Permission is granted to anyone to use this software for any purpose,
+  including commercial applications, and to alter it and redistribute it
+  freely, subject to the following restrictions:
+
+  1. The origin of this software must not be misrepresented; you must not
+     claim that you wrote the original software. If you use this software
+     in a product, an acknowledgment in the product documentation would be
+     appreciated but is not required.
+  2. Altered source versions must be plainly marked as such, and must not be
+     misrepresented as being the original software.
+  3. This notice may not be removed or altered from any source distribution.
+*/
+
+// Created by Yao Wei Tjong for Urho3D
+
+#include "SDL_config.h"
+
+#ifndef _SDL_raspiopengles_h
+#define _SDL_raspiopengles_h
+
+#include "../SDL_sysvideo.h"
+#include <GLES/gl.h>
+
+/* Broadcom VideoCore EGL */
+#include <EGL/egl.h>
+
+typedef struct SDL_PrivateGLESData
+{
+    void *egl_dll_handle;
+    EGLDisplay egl_display;
+    EGLContext egl_context;
+    EGLSurface egl_surface;
+    EGLConfig egl_config;
+    int egl_swapinterval;
+
+    EGLDisplay(*eglGetDisplay) (NativeDisplayType display);
+
+    EGLBoolean(*eglInitialize) (EGLDisplay dpy, EGLint *major,
+                                EGLint *minor);
+
+    EGLBoolean(*eglTerminate) (EGLDisplay dpy);
+
+    void *(*eglGetProcAddress) (const char *procName);
+
+    EGLBoolean(*eglChooseConfig) (EGLDisplay dpy,
+                                  const EGLint *attrib_list,
+                                  EGLConfig *configs,
+                                  EGLint config_size, EGLint *num_config);
+
+    EGLContext(*eglCreateContext) (EGLDisplay dpy,
+                                   EGLConfig config,
+                                   EGLContext share_list,
+                                   const EGLint *attrib_list);
+
+    EGLBoolean(*eglDestroyContext) (EGLDisplay dpy, EGLContext ctx);
+
+    EGLSurface(*eglCreateWindowSurface) (EGLDisplay dpy,
+                                         EGLConfig config,
+                                         NativeWindowType window,
+                                         const EGLint *attrib_list);
+
+    EGLBoolean(*eglDestroySurface) (EGLDisplay dpy, EGLSurface surface);
+
+    EGLBoolean(*eglMakeCurrent) (EGLDisplay dpy, EGLSurface draw,
+                                 EGLSurface read, EGLContext ctx);
+
+    EGLBoolean(*eglSwapBuffers) (EGLDisplay dpy, EGLSurface draw);
+
+    EGLBoolean(*eglSwapInterval) (EGLDisplay dpy, EGLint interval);
+
+    EGLBoolean(*eglGetConfigAttrib) (EGLDisplay dpy, EGLConfig config,
+                                     EGLint attribute, EGLint *value);
+} SDL_PrivateGLESData;
+
+/* OpenGLES functions */
+extern void *RASPI_GLES_GetProcAddress(_THIS, const char *proc);
+extern int RASPI_GLES_LoadLibrary(_THIS, const char *path);
+extern void RASPI_GLES_UnloadLibrary(_THIS);
+extern SDL_GLContext RASPI_GLES_CreateContext(_THIS, SDL_Window *window);
+extern int RASPI_GLES_MakeCurrent(_THIS, SDL_Window *window,
+                                  SDL_GLContext context);
+extern int RASPI_GLES_SetSwapInterval(_THIS, int interval);
+extern int RASPI_GLES_GetSwapInterval(_THIS);
+extern int RASPI_GLES_GetAttribute(_THIS, SDL_GLattr attrib, int *value);
+extern void RASPI_GLES_SwapWindow(_THIS, SDL_Window *window);
+extern void RASPI_GLES_DeleteContext(_THIS, SDL_GLContext context);
+extern int RASPI_GLES_ChooseConfig(_THIS);
+#endif /* _SDL_raspiopengles_h */
+
+/* vi: set ts=4 sw=4 expandtab: */

+ 178 - 0
ThirdParty/SDL/src/video/raspi/SDL_raspivideo.c

@@ -0,0 +1,178 @@
+/*
+  Simple DirectMedia Layer
+  Copyright (C) 1997-2013 Sam Lantinga <[email protected]>
+
+  This software is provided 'as-is', without any express or implied
+  warranty.  In no event will the authors be held liable for any damages
+  arising from the use of this software.
+
+  Permission is granted to anyone to use this software for any purpose,
+  including commercial applications, and to alter it and redistribute it
+  freely, subject to the following restrictions:
+
+  1. The origin of this software must not be misrepresented; you must not
+     claim that you wrote the original software. If you use this software
+     in a product, an acknowledgment in the product documentation would be
+     appreciated but is not required.
+  2. Altered source versions must be plainly marked as such, and must not be
+     misrepresented as being the original software.
+  3. This notice may not be removed or altered from any source distribution.
+*/
+
+// Created by Yao Wei Tjong for Urho3D
+
+#include "SDL_config.h"
+
+#if SDL_VIDEO_DRIVER_RASPI
+
+#include "SDL_video.h"
+#include "SDL_raspivideo.h"
+#include "SDL_raspiwindow.h"
+#include "SDL_raspiopengles.h"
+#include "SDL_raspievents.h"
+
+#include <GLES/gl.h>
+
+/* Broadcom VideoCore EGL */
+#include <EGL/egl.h>
+
+#define RASPI_VID_DRIVER_NAME "RASPI"
+
+/* Initialization/Termination functions */
+static int RASPI_VideoInit(_THIS);
+static void RASPI_VideoQuit(_THIS);
+
+/* RASPI driver bootstrap functions */
+
+static int
+RASPI_Available(void)
+{
+    return 1;
+}
+
+static void
+RASPI_DeleteDevice(SDL_VideoDevice * device)
+{
+    SDL_free(device->driverdata);
+    SDL_free(device);
+}
+
+static SDL_VideoDevice *
+RASPI_CreateDevice(int devindex)
+{
+    SDL_VideoDevice *device;
+    SDL_VideoData *data;
+
+    /* Initialize all variables that we clean on shutdown */
+    device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
+    if (!device) {
+        SDL_OutOfMemory();
+        return NULL;
+    }
+
+    data = (SDL_VideoData*) SDL_calloc(1, sizeof(SDL_VideoData));
+    if (!data) {
+        SDL_OutOfMemory();
+        SDL_free(device);
+        return NULL;
+    }
+
+    device->driverdata = data;
+
+    /* Set the function pointers */
+    device->free = RASPI_DeleteDevice;
+
+    device->VideoInit = RASPI_VideoInit;
+    device->VideoQuit = RASPI_VideoQuit;
+    device->PumpEvents = RASPI_PumpEvents;
+
+    device->CreateWindow = RASPI_CreateWindow;
+    device->DestroyWindow = RASPI_DestroyWindow;
+
+    /* OpenGLES functiion pointers */
+    device->GL_GetProcAddress = RASPI_GLES_GetProcAddress;
+    device->GL_LoadLibrary = RASPI_GLES_LoadLibrary;
+    device->GL_UnloadLibrary = RASPI_GLES_UnloadLibrary;
+    device->GL_CreateContext = RASPI_GLES_CreateContext;
+    device->GL_MakeCurrent = RASPI_GLES_MakeCurrent;
+    device->GL_SetSwapInterval = RASPI_GLES_SetSwapInterval;
+    device->GL_GetSwapInterval = RASPI_GLES_GetSwapInterval;
+    device->GL_SwapWindow = RASPI_GLES_SwapWindow;
+    device->GL_DeleteContext = RASPI_GLES_DeleteContext;
+
+    return device;
+}
+
+VideoBootStrap RASPI_bootstrap = {
+    RASPI_VID_DRIVER_NAME, "SDL Raspberry Pi video driver",
+    RASPI_Available, RASPI_CreateDevice
+};
+
+int
+RASPI_InitModes(_THIS)
+{
+    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
+
+    const uint32_t device = 0;  /* LCD */
+    DISPMANX_DISPLAY_HANDLE_T display_handle;
+    DISPMANX_MODEINFO_T mode_info;
+
+    display_handle = vc_dispmanx_display_open(device);
+    if (!display_handle) {
+        return SDL_SetError("Couldn't open vc_dispmanx for InitModes");
+    }
+    if (vc_dispmanx_display_get_info(display_handle, &mode_info) < 0) {
+        SDL_SetError("vc_dispmanx couldn't get display info");
+    }
+    if (vc_dispmanx_display_close(display_handle) < 0) {
+        return SDL_SetError("Couldn't close vc_dispmanx for InitModes");
+    }
+
+    SDL_DisplayMode mode;
+    SDL_zero(mode);
+    mode.w = mode_info.width;
+    mode.h = mode_info.height;
+
+    /* FIXME: this code does not seem to work as it always returns VCOS_DISPLAY_INPUT_FORMAT_INVALID
+    switch (mode_info.input_format) {
+    case VCOS_DISPLAY_INPUT_FORMAT_RGB888:
+        mode.format = SDL_PIXELFORMAT_RGB888;
+        break;
+    case VCOS_DISPLAY_INPUT_FORMAT_RGB565:
+        mode.format = SDL_PIXELFORMAT_RGB565;
+        break;
+    default:
+        mode.format = SDL_PIXELFORMAT_UNKNOWN;
+    }
+    */
+    mode.format = SDL_PIXELFORMAT_RGBA8888;
+
+    return SDL_AddBasicVideoDisplay(&mode);
+}
+
+int
+RASPI_VideoInit(_THIS)
+{
+    bcm_host_init();
+
+    if (RASPI_InitModes(_this) < 0) {
+        return -1;
+    }
+
+    if (RASPI_InitInput(_this) < 0) {
+        return -1;
+    }
+
+    return 0;
+}
+
+void
+RASPI_VideoQuit(_THIS)
+{
+    RASPI_QuitInput(_this);
+    bcm_host_deinit();
+}
+
+#endif /* SDL_VIDEO_DRIVER_RASPI */
+
+/* vi: set ts=4 sw=4 expandtab: */

+ 44 - 0
ThirdParty/SDL/src/video/raspi/SDL_raspivideo.h

@@ -0,0 +1,44 @@
+/*
+  Simple DirectMedia Layer
+  Copyright (C) 1997-2013 Sam Lantinga <[email protected]>
+
+  This software is provided 'as-is', without any express or implied
+  warranty.  In no event will the authors be held liable for any damages
+  arising from the use of this software.
+
+  Permission is granted to anyone to use this software for any purpose,
+  including commercial applications, and to alter it and redistribute it
+  freely, subject to the following restrictions:
+
+  1. The origin of this software must not be misrepresented; you must not
+     claim that you wrote the original software. If you use this software
+     in a product, an acknowledgment in the product documentation would be
+     appreciated but is not required.
+  2. Altered source versions must be plainly marked as such, and must not be
+     misrepresented as being the original software.
+  3. This notice may not be removed or altered from any source distribution.
+*/
+
+// Created by Yao Wei Tjong for Urho3D
+
+#include "SDL_config.h"
+
+#ifndef _SDL_raspivideo_h
+#define _SDL_raspivideo_h
+
+#include "../SDL_sysvideo.h"
+
+#include <EGL/egl.h>
+
+/* Private display data */
+
+typedef struct
+{
+    SDL_Window *window;
+    EGL_DISPMANX_WINDOW_T nativewindow;
+    DISPMANX_DISPLAY_HANDLE_T display;
+} SDL_VideoData;
+
+#endif /* _SDL_raspivideo_h */
+
+/* vi: set ts=4 sw=4 expandtab: */

+ 143 - 0
ThirdParty/SDL/src/video/raspi/SDL_raspiwindow.c

@@ -0,0 +1,143 @@
+/*
+  Simple DirectMedia Layer
+  Copyright (C) 1997-2013 Sam Lantinga <[email protected]>
+
+  This software is provided 'as-is', without any express or implied
+  warranty.  In no event will the authors be held liable for any damages
+  arising from the use of this software.
+
+  Permission is granted to anyone to use this software for any purpose,
+  including commercial applications, and to alter it and redistribute it
+  freely, subject to the following restrictions:
+
+  1. The origin of this software must not be misrepresented; you must not
+     claim that you wrote the original software. If you use this software
+     in a product, an acknowledgment in the product documentation would be
+     appreciated but is not required.
+  2. Altered source versions must be plainly marked as such, and must not be
+     misrepresented as being the original software.
+  3. This notice may not be removed or altered from any source distribution.
+*/
+
+// Created by Yao Wei Tjong for Urho3D
+
+#include "SDL_config.h"
+
+#if SDL_VIDEO_DRIVER_RASPI
+
+#include "SDL_raspivideo.h"
+#include "SDL_raspiwindow.h"
+#include "SDL_raspiopengles.h"
+
+int
+RASPI_CreateWindow(_THIS, SDL_Window *window)
+{
+    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
+    if (data->window) {
+        return SDL_SetError("Raspberry Pi video driver only supports one native window");
+    }
+    data->window = window;
+
+    /* Adjust the window data to match the current mode */
+    SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
+    SDL_DisplayMode mode = display->current_mode;
+
+    window->x = 0;
+    window->y = 0;
+    window->w = mode.w;
+    window->h = mode.h;
+
+    window->flags &= ~SDL_WINDOW_RESIZABLE;     /* window is NEVER resizeable */
+    window->flags |= SDL_WINDOW_FULLSCREEN;     /* window is always fullscreen */
+    window->flags &= ~SDL_WINDOW_HIDDEN;
+    window->flags |= SDL_WINDOW_SHOWN;          /* only support one window */
+    window->flags |= SDL_WINDOW_INPUT_FOCUS;    /* always has input focus */
+
+    display->fullscreen_window = window;
+
+    /* One window, it always has focus */
+    SDL_SetMouseFocus(window);
+    SDL_SetKeyboardFocus(window);
+
+    /* Broadcom VideoCore specific */
+    if (RASPI_GLES_ChooseConfig(_this) < 0) {
+        /* SDL_GetError() should have info */
+        return -1;
+    }
+
+    const uint32_t device = 0;  /* LCD */
+    DISPMANX_UPDATE_HANDLE_T update_handle;
+    DISPMANX_ELEMENT_HANDLE_T element_handle;
+    VC_RECT_T dst_rect;
+    VC_RECT_T src_rect;
+    VC_DISPMANX_ALPHA_T alpha;
+
+    dst_rect.x = 0;
+    dst_rect.y = 0;
+    dst_rect.width = mode.w;
+    dst_rect.height = mode.h;
+
+    src_rect.x = 0;
+    src_rect.y = 0;
+    src_rect.width = mode.w << 16;
+    src_rect.height = mode.h << 16;
+
+    /* Through trial and error, these combination seems to work well for Urho3D engine */
+    alpha.flags = DISPMANX_FLAGS_ALPHA_FIXED_ALL_PIXELS;
+    alpha.opacity = 255;
+    alpha.mask = 0;
+
+    data->display = vc_dispmanx_display_open(device);
+    if (!data->display) {
+        return SDL_SetError("Couldn't open vc_dispmanx");
+    }
+    update_handle = vc_dispmanx_update_start(0 /*priority*/);
+    if (!update_handle) {
+        return SDL_SetError("vc_dispmanx couldn't start update");
+    }
+    element_handle = vc_dispmanx_element_add (update_handle, data->display, 0/*layer*/,
+                                              &dst_rect, 0/*src*/, &src_rect, DISPMANX_PROTECTION_NONE,
+                                              &alpha, 0/*clamp*/, 0/*transform*/);
+    if (!element_handle) {
+        return SDL_SetError("vc_dispmanx couldn't add element");
+    }
+
+    data->nativewindow.element = element_handle;
+    data->nativewindow.width = mode.w;
+    data->nativewindow.height = mode.h;
+
+    if (vc_dispmanx_update_submit_sync(update_handle) < 0) {
+        return SDL_SetError("vc_dispmanx couldn't commit update");
+    }
+
+    /* Create the GLES window surface */
+    _this->gles_data->egl_surface =
+        _this->gles_data->eglCreateWindowSurface(_this->gles_data->egl_display,
+                                                 _this->gles_data->egl_config,
+                                                 (NativeWindowType) &data->nativewindow,
+                                                 NULL);
+
+    if (_this->gles_data->egl_surface == EGL_NO_SURFACE) {
+        return SDL_SetError("Couldn't create EGL window surface");
+    }
+
+    return 0;
+}
+
+void
+RASPI_DestroyWindow(_THIS, SDL_Window * window)
+{
+    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
+    if (data->window != window) {
+        SDL_SetError("Invalid window - Raspberry Pi video driver only supports one native window and it's not this one");
+        return;
+    }
+
+    if (vc_dispmanx_display_close(data->display) < 0) {
+        SDL_SetError("Couldn't close vc_dispmanx");
+    }
+}
+
+#endif /* SDL_VIDEO_DRIVER_RASPI */
+
+/* vi: set ts=4 sw=4 expandtab: */

+ 34 - 0
ThirdParty/SDL/src/video/raspi/SDL_raspiwindow.h

@@ -0,0 +1,34 @@
+/*
+  Simple DirectMedia Layer
+  Copyright (C) 1997-2013 Sam Lantinga <[email protected]>
+
+  This software is provided 'as-is', without any express or implied
+  warranty.  In no event will the authors be held liable for any damages
+  arising from the use of this software.
+
+  Permission is granted to anyone to use this software for any purpose,
+  including commercial applications, and to alter it and redistribute it
+  freely, subject to the following restrictions:
+
+  1. The origin of this software must not be misrepresented; you must not
+     claim that you wrote the original software. If you use this software
+     in a product, an acknowledgment in the product documentation would be
+     appreciated but is not required.
+  2. Altered source versions must be plainly marked as such, and must not be
+     misrepresented as being the original software.
+  3. This notice may not be removed or altered from any source distribution.
+*/
+
+// Created by Yao Wei Tjong for Urho3D
+
+#include "SDL_config.h"
+
+#ifndef _SDL_raspiwindow_h
+#define _SDL_raspiwindow_h
+
+extern int RASPI_CreateWindow(_THIS, SDL_Window * window);
+extern void RASPI_DestroyWindow(_THIS, SDL_Window * window);
+
+#endif /* _SDL_raspiwindow_h */
+
+/* vi: set ts=4 sw=4 expandtab: */

+ 28 - 18
ThirdParty/SDL/src/video/x11/SDL_x11opengles.c

@@ -18,9 +18,13 @@
      misrepresented as being the original software.
   3. This notice may not be removed or altered from any source distribution.
 */
+
+// Modified by Yao Wei Tjong for Urho3D
+
 #include "SDL_config.h"
 
-#if SDL_VIDEO_DRIVER_X11 && SDL_VIDEO_OPENGL_ES
+// Urho3D: fix compiler directive to include OpenGL ES 2
+#if SDL_VIDEO_DRIVER_X11 && (SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2)
 
 #include "SDL_x11video.h"
 #include "SDL_x11opengles.h"
@@ -274,32 +278,36 @@ X11_GLES_GetVisual(_THIS, Display * display, int screen)
         return NULL;
     }
 
+    // Urho3D: fix the fallback to handle case where visual id is available but vinfo still returns null
+    XVisualInfo *vinfo = 0;
     if (_this->gles_data->eglGetConfigAttrib(_this->gles_data->egl_display,
                                              _this->gles_data->egl_config,
                                              EGL_NATIVE_VISUAL_ID,
-                                             (EGLint *) & visual_id) ==
-        EGL_FALSE || !visual_id) {
-        /* Use the default visual when all else fails */
+                                             (EGLint *) &visual_id) ==
+        EGL_TRUE && visual_id) {
         XVisualInfo vi_in;
         int out_count;
+
         vi_in.screen = screen;
+        vi_in.visualid = visual_id;
+        vinfo = XGetVisualInfo(display,
+                               VisualScreenMask |
+                               VisualIDMask,
+                               &vi_in, &out_count);
+    }
 
-        _this->gles_data->egl_visualinfo = XGetVisualInfo(display,
-                                                          VisualScreenMask,
-                                                          &vi_in, &out_count);
-    } else {
+    if (!vinfo) {
+        /* Use the default visual when all else fails */
         XVisualInfo vi_in;
         int out_count;
-
         vi_in.screen = screen;
-        vi_in.visualid = visual_id;
-        _this->gles_data->egl_visualinfo = XGetVisualInfo(display,
-                                                          VisualScreenMask |
-                                                          VisualIDMask,
-                                                          &vi_in, &out_count);
+
+        vinfo = XGetVisualInfo(display,
+                               VisualScreenMask,
+                               &vi_in, &out_count);
     }
 
-    return _this->gles_data->egl_visualinfo;
+    return _this->gles_data->egl_visualinfo = vinfo;
 }
 
 SDL_GLContext
@@ -371,7 +379,8 @@ X11_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
 int
 X11_GLES_SetSwapInterval(_THIS, int interval)
 {
-    if (_this->gles_data) {
+    // Urho3D: bug fix on pointer check
+    if (!_this->gles_data) {
         return SDL_SetError("OpenGL ES context not active");
     }
 
@@ -388,7 +397,8 @@ X11_GLES_SetSwapInterval(_THIS, int interval)
 int
 X11_GLES_GetSwapInterval(_THIS)
 {
-    if (_this->gles_data) {
+    // Urho3D: bug fix on pointer check
+    if (!_this->gles_data) {
         return SDL_SetError("OpenGL ES context not active");
     }
 
@@ -435,6 +445,6 @@ X11_GLES_DeleteContext(_THIS, SDL_GLContext context)
     X11_GLES_UnloadLibrary(_this);
 }
 
-#endif /* SDL_VIDEO_DRIVER_X11 && SDL_VIDEO_OPENGL_ES */
+#endif /* SDL_VIDEO_DRIVER_X11 && (SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2) */
 
 /* vi: set ts=4 sw=4 expandtab: */

+ 3 - 2
ThirdParty/tolua++/src/bin/CMakeLists.txt

@@ -7,10 +7,11 @@ file (GLOB H_FILES *.h)
 set (SOURCE_FILES ${CPP_FILES} ${H_FILES})
 
 # Define dependency libs
-set (LIBS ../../../../ThirdParty/Lua/src ../tolua++_static)
+set (LIBS ../../../../ThirdParty/Lua/src)
+set (LINK_LIBS_ONLY tolua++_static)
 set (INCLUDE_DIRS_ONLY ../../include)
 if (NOT MSVC)
-    set (LINK_LIBS_ONLY m)
+    set (LINK_LIBS_ONLY ${LINK_LIBS_ONLY} m)
 endif ()
 
 # Setup target

+ 0 - 0
Android/android.toolchain.cmake → cmake/Toolchains/android.toolchain.cmake


+ 49 - 0
cmake/Toolchains/raspberrypi.toolchain.cmake

@@ -0,0 +1,49 @@
+#
+# Copyright (c) 2008-2013 the Urho3D project.
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# THE SOFTWARE.
+#
+
+cmake_minimum_required (VERSION 2.6.3)
+
+# this one is important
+set (CMAKE_SYSTEM_NAME Linux)
+#this one not so much
+set (CMAKE_SYSTEM_VERSION 1)
+
+# specify the cross compiler
+set (RASPI_TOOL $ENV{RASPI_TOOL})
+set (CMAKE_C_COMPILER   "${RASPI_TOOL}/arm-linux-gnueabihf-gcc"     CACHE PATH "C compiler")
+set (CMAKE_CXX_COMPILER "${RASPI_TOOL}/arm-linux-gnueabihf-c++"     CACHE PATH "C++ compiler")
+set (CMAKE_ASM_COMPILER "${RASPI_TOOL}/arm-linux-gnueabihf-gcc"     CACHE PATH "assembler")
+set (CMAKE_STRIP        "${RASPI_TOOL}/arm-linux-gnueabihf-strip"   CACHE PATH "strip")
+set (CMAKE_AR           "${RASPI_TOOL}/arm-linux-gnueabihf-ar"      CACHE PATH "archive")
+set (CMAKE_LINKER       "${RASPI_TOOL}/arm-linux-gnueabihf-ld"      CACHE PATH "linker")
+set (CMAKE_NM           "${RASPI_TOOL}/arm-linux-gnueabihf-nm"      CACHE PATH "nm")
+set (CMAKE_OBJCOPY      "${RASPI_TOOL}/arm-linux-gnueabihf-objcopy" CACHE PATH "objcopy")
+set (CMAKE_OBJDUMP      "${RASPI_TOOL}/arm-linux-gnueabihf-objdump" CACHE PATH "objdump")
+set (CMAKE_RANLIB       "${RASPI_TOOL}/arm-linux-gnueabihf-ranlib"  CACHE PATH "ranlib")
+
+# where is the target environment 
+set (CMAKE_FIND_ROOT_PATH "${RASPI_TOOL}/../arm-linux-gnueabihf/libc")
+
+# only search programs, libraries, and headers in the target directories
+set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY)
+set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
+set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

+ 2 - 2
cmake_android.bat

@@ -3,5 +3,5 @@
 @cd Android
 @del /F CMakeCache.txt
 @rd /S /Q CMakeFiles
-cmake -G "Unix Makefiles" -DANDROID=1 -DCMAKE_TOOLCHAIN_FILE=android.toolchain.cmake -DLIBRARY_OUTPUT_PATH_ROOT=. -DCMAKE_BUILD_TYPE=Release .. %*
-@cd ..
+cmake -G "Unix Makefiles" -DANDROID=1 -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchains/android.toolchain.cmake -DLIBRARY_OUTPUT_PATH_ROOT=. -DCMAKE_BUILD_TYPE=Release .. %*
+@cd ..

+ 1 - 14
cmake_eclipse.sh

@@ -1,14 +1 @@
-# Create out-of-source build directory
-cmake -E make_directory build
-# Remove existing CMake cache and rules
-rm -rf {.,build}/CMakeCache.txt CMakeFiles
-# Create the Cmake generators
-cmake -E chdir build cmake -G "Eclipse CDT4 - Unix Makefiles" .. $@
-[ $ANDROID_NDK ] && cmake -E chdir Android cmake -G "Eclipse CDT4 - Unix Makefiles" -DANDROID=1 -DCMAKE_TOOLCHAIN_FILE=android.toolchain.cmake -DLIBRARY_OUTPUT_PATH_ROOT=. .. $@
-# Assume Eclipse user uses OpenGL, comment out below sed if this is not true
-sed -i.bak 's/OpenGL/Direct3D9/g' Doxyfile
-# Create symbolic links in the build and Android directories
-for dir in CoreData Data; do
-    cmake -E create_symlink ../../Bin/$dir build/Urho3D/$dir
-    [ $ANDROID_NDK ] && cmake -E create_symlink ../../Bin/$dir Android/assets/$dir
-done
+./cmake_gcc.sh eclipse $@

+ 45 - 7
cmake_gcc.sh

@@ -1,11 +1,49 @@
+# Define helpers
+msg() {
+    echo -e "\n$1\n================================================================================================="
+}
+
+# Ensure we are in project source root directory
+cd $( dirname $0 )
+PROJ=`pwd`
+
 # Create out-of-source build directory
-cmake -E make_directory build
+cmake -E make_directory ../build
+[ $RASPI_TOOL ] && cmake -E make_directory ../raspi-build
+[ $ANDROID_NDK ] && cmake -E make_directory ../android-build
+
 # Remove existing CMake cache and rules
-rm -rf {.,build}/CMakeCache.txt CMakeFiles
-# Create the Cmake generators
-cmake -E chdir build cmake -G "Unix Makefiles" .. $@
-[ $ANDROID_NDK ] && cmake -E chdir Android cmake -G "Unix Makefiles" -DANDROID=1 -DCMAKE_TOOLCHAIN_FILE=android.toolchain.cmake -DLIBRARY_OUTPUT_PATH_ROOT=. .. $@
+rm -rf {../build,../raspi-build,../android-build}/CMakeCache.txt {../build,../raspi-build,../android-build}/CMakeFiles
+# Do cleanup one more time for old build directory created by previous version of cmake_gcc.sh, just in case
+rm -rf {.,build,Android}/CMakeCache.txt {.,build,Android}/CMakeFiles
+
+# Add support for Eclipse IDE
+IFS=#
+GENERATOR="Unix Makefiles"
+[[ $1 =~ ^eclipse$ ]] && GENERATOR="Eclipse CDT4 - Unix Makefiles" && ECLIPSE=1 && shift
+
+# Add support for both native and cross-compiling build for Raspberry Pi
+[[ $( uname -p ) =~ ^armv6 ]] && PLATFORM="-DRASPI=1"
+
+# Create project with the respective Cmake generators
+OPT=--no-warn-unused-cli
+msg "Native build" && cmake -E chdir ../build cmake $OPT -G $GENERATOR $PLATFORM $PROJ $@
+[ $RASPI_TOOL ] && msg "Raspberry Pi build" && cmake -E chdir ../raspi-build cmake $OPT -G $GENERATOR -DRASPI=1 -DCMAKE_TOOLCHAIN_FILE=$PROJ/cmake/Toolchains/raspberrypi.toolchain.cmake $PROJ $@
+[ $ANDROID_NDK ] && msg "Android build" && cmake -E chdir ../android-build cmake $OPT -G $GENERATOR -DANDROID=1 -DCMAKE_TOOLCHAIN_FILE=$PROJ/cmake/Toolchains/android.toolchain.cmake -DLIBRARY_OUTPUT_PATH_ROOT=. $PROJ $@
+unset IFS
+
 # Assume GCC user uses OpenGL, comment out below sed if this is not true
 sed -i.bak 's/OpenGL/Direct3D9/g' Doxyfile
-# Create symbolic links in the Android directory
-[ $ANDROID_NDK ] && for dir in CoreData Data; do cmake -E create_symlink ../../Bin/$dir Android/assets/$dir; done
+
+# Create symbolic links in the build directories
+for dir in CoreData Data; do
+    [ $ECLIPSE ] && cmake -E create_symlink $PROJ/Bin/$dir ../build/Urho3D/$dir
+    if [ $ANDROID_NDK ]; then
+        cmake -E create_symlink ../../Bin/$dir Android/assets/$dir
+        for f in AndroidManifest.xml build.xml project.properties src res assets; do
+            cmake -E create_symlink $PROJ/Android/$f ../android-build/$f
+        done
+    fi
+done
+
+# vi: set ts=4 sw=4 expandtab: