diff --git a/CMake/Dependencies.cmake b/CMake/Dependencies.cmake index 8198e2d96..aa34b5e5b 100755 --- a/CMake/Dependencies.cmake +++ b/CMake/Dependencies.cmake @@ -72,7 +72,7 @@ find_package(Freetype) macro_log_feature(FREETYPE_FOUND "freetype" "Portable font engine" "http://www.freetype.org" TRUE "" "") # Find X11 -if (UNIX AND NOT OGRE_BUILD_PLATFORM_APPLE_IOS) +if (UNIX AND NOT OGRE_BUILD_PLATFORM_APPLE_IOS AND NOT OGRE_BUILD_PLATFORM_EMSCRIPTEN) find_package(X11) macro_log_feature(X11_FOUND "X11" "X Window system" "http://www.x.org" TRUE "" "") macro_log_feature(X11_Xt_FOUND "Xt" "X Toolkit" "http://www.x.org" TRUE "" "") @@ -116,33 +116,35 @@ endif (NOT OGRE_BUILD_PLATFORM_APPLE_IOS) # Find Boost # Prefer static linking in all cases -if (WIN32 OR APPLE) - set(Boost_USE_STATIC_LIBS TRUE) -else () - # Statically linking boost to a dynamic Ogre build doesn't work on Linux 64bit - set(Boost_USE_STATIC_LIBS ${OGRE_STATIC}) -endif () -if (APPLE AND OGRE_BUILD_PLATFORM_APPLE_IOS) - set(Boost_COMPILER "-xgcc42") -endif() -set(Boost_ADDITIONAL_VERSIONS "1.48" "1.48.0" "1.47" "1.47.0" "1.46" "1.46.0" "1.45" "1.45.0" "1.44" "1.44.0" "1.42" "1.42.0" "1.41.0" "1.41" "1.40.0" "1.40" "1.39.0" "1.39" "1.38.0" "1.38" "1.37.0" "1.37" ) -# Components that need linking (NB does not include header-only components like bind) -set(OGRE_BOOST_COMPONENTS thread date_time) -find_package(Boost COMPONENTS ${OGRE_BOOST_COMPONENTS} QUIET) -if (NOT Boost_FOUND) - # Try again with the other type of libs - if(Boost_USE_STATIC_LIBS) - set(Boost_USE_STATIC_LIBS) - else() - set(Boost_USE_STATIC_LIBS ON) - endif() - find_package(Boost COMPONENTS ${OGRE_BOOST_COMPONENTS} QUIET) +if (NOT OGRE_BUILD_PLATFORM_EMSCRIPTEN) + if (WIN32 OR APPLE) + set(Boost_USE_STATIC_LIBS TRUE) + else () + # Statically linking boost to a dynamic Ogre build doesn't work on Linux 64bit + set(Boost_USE_STATIC_LIBS ${OGRE_STATIC}) + endif () + if (APPLE AND OGRE_BUILD_PLATFORM_APPLE_IOS) + set(Boost_COMPILER "-xgcc42") + endif() + set(Boost_ADDITIONAL_VERSIONS "1.48" "1.48.0" "1.47" "1.47.0" "1.46" "1.46.0" "1.45" "1.45.0" "1.44" "1.44.0" "1.42" "1.42.0" "1.41.0" "1.41" "1.40.0" "1.40" "1.39.0" "1.39" "1.38.0" "1.38" "1.37.0" "1.37" ) + # Components that need linking (NB does not include header-only components like bind) + set(OGRE_BOOST_COMPONENTS thread date_time) + find_package(Boost COMPONENTS ${OGRE_BOOST_COMPONENTS} QUIET) + if (NOT Boost_FOUND) + # Try again with the other type of libs + if(Boost_USE_STATIC_LIBS) + set(Boost_USE_STATIC_LIBS) + else() + set(Boost_USE_STATIC_LIBS ON) + endif() + find_package(Boost COMPONENTS ${OGRE_BOOST_COMPONENTS} QUIET) + endif() + find_package(Boost QUIET) + # Optional Boost libs (Boost_${COMPONENT}_FOUND + macro_log_feature(Boost_FOUND "boost" "Boost (general)" "http://boost.org" FALSE "" "") + macro_log_feature(Boost_THREAD_FOUND "boost-thread" "Used for threading support" "http://boost.org" FALSE "" "") + macro_log_feature(Boost_DATE_TIME_FOUND "boost-date_time" "Used for threading support" "http://boost.org" FALSE "" "") endif() -find_package(Boost QUIET) -# Optional Boost libs (Boost_${COMPONENT}_FOUND -macro_log_feature(Boost_FOUND "boost" "Boost (general)" "http://boost.org" FALSE "" "") -macro_log_feature(Boost_THREAD_FOUND "boost-thread" "Used for threading support" "http://boost.org" FALSE "" "") -macro_log_feature(Boost_DATE_TIME_FOUND "boost-date_time" "Used for threading support" "http://boost.org" FALSE "" "") # POCO find_package(POCO) diff --git a/CMake/Packages/FindOIS.cmake b/CMake/Packages/FindOIS.cmake index fc8500b79..1ffb36a1e 100644 --- a/CMake/Packages/FindOIS.cmake +++ b/CMake/Packages/FindOIS.cmake @@ -67,6 +67,10 @@ message(STATUS "Lib will be searched in Symbian out dir: ${CMAKE_SYSYEM_OUT_DIR} endif (SYMBIAN) find_library(OIS_LIBRARY_REL NAMES ${OIS_LIBRARY_NAMES} HINTS ${OIS_LIB_SEARCH_PATH} ${OIS_PKGC_LIBRARY_DIRS} PATH_SUFFIXES "" release relwithdebinfo minsizerel) find_library(OIS_LIBRARY_DBG NAMES ${OIS_LIBRARY_NAMES_DBG} HINTS ${OIS_LIB_SEARCH_PATH} ${OIS_PKGC_LIBRARY_DIRS} PATH_SUFFIXES "" debug) +if (OGRE_BUILD_PLATFORM_EMSCRIPTEN) + set(OIS_LIBRARY_REL "libOIS.so") + set(OIS_LIBRARY_DBG "libOIS.so") +endif() if (SYMBIAN) set(OIS_LIBRARY_REL "${FreeImage_LIBRARY_REL} ois.lib touchfeedback.lib") set(CMAKE_PREFIX_PATH ${ORIGINAL_CMAKE_PREFIX_PATH}) diff --git a/CMakeLists.txt b/CMakeLists.txt index b260c63db..2fba5a3c5 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,6 +32,21 @@ if(WIN32) set(CMAKE_SUPPRESS_REGENERATION true) endif() +if (APPLE) + include(CMakeForceCompiler) + if (OGRE_BUILD_PLATFORM_APPLE_IOS) + CMAKE_FORCE_C_COMPILER(clang GNU) + CMAKE_FORCE_CXX_COMPILER(clang++ GNU) + SET(CMAKE_SIZEOF_VOID_P 4) + set(CMAKE_XCODE_ATTRIBUTE_GCC_VERSION "com.apple.compilers.llvm.clang.1_0") + elseif (NOT OGRE_BUILD_PLATFORM_EMSCRIPTEN) + CMAKE_FORCE_C_COMPILER(llvm-gcc-4.2 GNU) + CMAKE_FORCE_CXX_COMPILER(llvm-g++-4.2 GNU) + SET(CMAKE_SIZEOF_VOID_P 4) + set(CMAKE_XCODE_ATTRIBUTE_GCC_VERSION "com.apple.compilers.llvmgcc42") + endif () +endif () + project(OGRE) # Include necessary submodules @@ -41,6 +56,7 @@ set(CMAKE_MODULE_PATH "${OGRE_SOURCE_DIR}/CMake/Packages" ) +include(CMakeDetermineSystem) include(CMakeDependentOption) include(CheckCXXCompilerFlag) include(MacroLogFeature) @@ -51,21 +67,6 @@ set(OGRE_TEMPLATES_DIR "${OGRE_SOURCE_DIR}/CMake/Templates") set(OGRE_WORK_DIR ${OGRE_BINARY_DIR}) -if (APPLE) - include(CMakeForceCompiler) - if (OGRE_BUILD_PLATFORM_APPLE_IOS) - CMAKE_FORCE_C_COMPILER(clang GNU) - CMAKE_FORCE_CXX_COMPILER(clang++ GNU) - SET(CMAKE_SIZEOF_VOID_P 4) - set(CMAKE_XCODE_ATTRIBUTE_GCC_VERSION "com.apple.compilers.llvm.clang.1_0") - else () - CMAKE_FORCE_C_COMPILER(llvm-gcc-4.2 GNU) - CMAKE_FORCE_CXX_COMPILER(llvm-g++-4.2 GNU) - SET(CMAKE_SIZEOF_VOID_P 4) - set(CMAKE_XCODE_ATTRIBUTE_GCC_VERSION "com.apple.compilers.llvmgcc42") - endif () -endif () - ##################################################################### # Set up the basic build environment ##################################################################### @@ -236,6 +237,13 @@ elseif (APPLE AND NOT OGRE_BUILD_PLATFORM_APPLE_IOS) set(OGRE_BUILD_RENDERSYSTEM_GL TRUE) set(OGRE_BUILD_RENDERSYSTEM_GLES FALSE) set(OGRE_BUILD_RENDERSYSTEM_GLES2 FALSE) +elseif (OGRE_BUILD_PLATFORM_EMSCRIPTEN) + # Set build variables + set(OGRE_BUILD_RENDERSYSTEM_GLES2 TRUE CACHE BOOL "Forcing OpenGL ES 2 RenderSystem for Emscripten" FORCE) + set(OGRE_STATIC TRUE CACHE BOOL "Forcing static build for Emscripten" FORCE) + set(OGRE_CONFIG_ALLOCATOR 1 CACHE BOOL "Forcing internal allocator" FORCE) + + remove_definitions(-msse) elseif (SYMBIAN) set(OGRE_BUILD_RENDERSYSTEM_GLES TRUE CACHE BOOL "Forcing OpenGL ES 1.x RenderSystem for Symbian" FORCE) endif () @@ -258,6 +266,7 @@ cmake_dependent_option(OGRE_BUILD_RENDERSYSTEM_GLES "Build OpenGL ES 1.x RenderS cmake_dependent_option(OGRE_BUILD_RENDERSYSTEM_GLES2 "Build OpenGL ES 2.x RenderSystem" FALSE "OPENGLES2_FOUND" FALSE) cmake_dependent_option(OGRE_BUILD_PLATFORM_APPLE_IOS "Build Ogre for iOS" FALSE "iPhoneSDK_FOUND;OPENGLES_FOUND;OPENGLES2_FOUND" FALSE) cmake_dependent_option(OGRE_BUILD_PLATFORM_NACL "Build Ogre for Google's Native Client (NaCl)" FALSE "OPENGLES2_FOUND" FALSE) +cmake_dependent_option(OGRE_BUILD_PLATFORM_EMSCRIPTEN "Build Ogre for Emscripten" FALSE "OPENGLES2_FOUND" FALSE) option(OGRE_BUILD_PLUGIN_BSP "Build BSP SceneManager plugin" TRUE) option(OGRE_BUILD_PLUGIN_OCTREE "Build Octree SceneManager plugin" TRUE) option(OGRE_BUILD_PLUGIN_PFX "Build ParticleFX plugin" TRUE) diff --git a/OgreMain/CMakeLists.txt b/OgreMain/CMakeLists.txt index c28704edb..ae2fda7e7 100644 --- a/OgreMain/CMakeLists.txt +++ b/OgreMain/CMakeLists.txt @@ -481,6 +481,21 @@ if (OGRE_BUILD_PLATFORM_NACL) ) set(PLATFORM_LIBS nosys) set(PLATFORM_HEADER_INSTALL "NaCl") +elseif (OGRE_BUILD_PLATFORM_EMSCRIPTEN) + include_directories("include/Emscripten") + set(PLATFORM_HEADER_FILES + include/Emscripten/OgreConfigDialogImp.h + include/Emscripten/OgreErrorDialogImp.h + include/Emscripten/OgreTimerImp.h + ) + set(PLATFORM_SOURCE_FILES + src/Emscripten/OgreConfigDialog.cpp + src/Emscripten/OgreErrorDialog.cpp + src/Emscripten/OgreTimer.cpp + src/OgreSearchOps.cpp + ) + set(PLATFORM_LIBS nosys) + set(PLATFORM_HEADER_INSTALL "Emscripten") elseif (WIN32) include_directories("include/WIN32") set(PLATFORM_HEADER_FILES diff --git a/OgreMain/include/Emscripten/OgreConfigDialogImp.h b/OgreMain/include/Emscripten/OgreConfigDialogImp.h new file mode 100644 index 000000000..56c22194b --- /dev/null +++ b/OgreMain/include/Emscripten/OgreConfigDialogImp.h @@ -0,0 +1,75 @@ +/* +----------------------------------------------------------------------------- +This source file is part of OGRE +(Object-oriented Graphics Rendering Engine) +For the latest info, see http://www.ogre3d.org/ + +Copyright (c) 2000-2009 Torus Knot Software Ltd + +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. +----------------------------------------------------------------------------- +*/ + +#ifndef __OGRE_EMSCRIPTEN_CONFIG_DIALOG_H__ +#define __OGRE_EMSCRIPTEN_CONFIG_DIALOG_H__ + +#include "../OgrePrerequisites.h" +#include "../OgreRoot.h" +#include "../OgreRenderSystem.h" + +namespace Ogre +{ + /** Defines the behaviour of an automatic renderer configuration dialog. + @remarks + OGRE comes with it's own renderer configuration dialog, which + applications can use to easily allow the user to configure the + settings appropriate to their machine. This class defines the + interface to this standard dialog. Because dialogs are inherently + tied to a particular platform's windowing system, there will be a + different subclass for each platform. + @author + Steven J. Streeting + */ + class _OgreExport ConfigDialog : public UtilityAlloc + { + public: + ConfigDialog(); + + /** Displays the dialog. + @remarks + This method displays the dialog and from then on the dialog + interacts with the user independently. The dialog will be + calling the relevant OGRE rendering systems to query them for + options and to set the options the user selects. The method + returns when the user closes the dialog. + @returns + If the user accepted the dialog, true is returned. + @par + If the user cancelled the dialog (indicating the application + should probably terminate), false is returned. + @see + RenderSystem + */ + bool display(); + + protected: + RenderSystem* mSelectedRenderSystem; + }; +} +#endif diff --git a/OgreMain/include/Emscripten/OgreErrorDialogImp.h b/OgreMain/include/Emscripten/OgreErrorDialogImp.h new file mode 100644 index 000000000..20628d641 --- /dev/null +++ b/OgreMain/include/Emscripten/OgreErrorDialogImp.h @@ -0,0 +1,52 @@ +/* +----------------------------------------------------------------------------- +This source file is part of OGRE +(Object-oriented Graphics Rendering Engine) +For the latest info, see http://www.ogre3d.org/ + +Copyright (c) 2000-2009 Torus Knot Software Ltd + +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. +----------------------------------------------------------------------------- +*/ +#ifndef __OGRE_EMSCRIPTEN_ERROR_DIALOG_H__ +#define __OGRE_EMSCRIPTEN_ERROR_DIALOG_H__ + +#include "../OgrePrerequisites.h" + +namespace Ogre +{ + /** Class for displaying the error dialog if Ogre fails badly. */ + class _OgreExport ErrorDialog + { + public: + ErrorDialog(); + + /** + @remarks + Displays the error dialog. + @param + errorMessage The error message which has caused the failure. + @param + logName Optional name of the log to display in the detail pane. + */ + void display(const String& errorMessage, String logName = ""); + }; +} +#endif diff --git a/OgreMain/include/Emscripten/OgreTimerImp.h b/OgreMain/include/Emscripten/OgreTimerImp.h new file mode 100644 index 000000000..1396c4ce0 --- /dev/null +++ b/OgreMain/include/Emscripten/OgreTimerImp.h @@ -0,0 +1,83 @@ +/* +----------------------------------------------------------------------------- +This source file is part of OGRE +(Object-oriented Graphics Rendering Engine) +For the latest info, see http://www.ogre3d.org/ + +Copyright (c) 2000-2009 Torus Knot Software Ltd + +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. +----------------------------------------------------------------------------- +*/ + +#ifndef __OGRE_EMSCRIPTEN_TIMER_H__ +#define __OGRE_EMSCRIPTEN_TIMER_H__ + +#include "../OgrePrerequisites.h" + +#if OGRE_PLATFORM == OGRE_PLATFORM_EMSCRIPTEN + #include +#endif + +namespace Ogre +{ + /** Timer class */ + class _OgreExport Timer : public TimerAlloc + { + private: + struct timeval start; + clock_t zeroClock; + public: + Timer(); + ~Timer(); + + /** Method for setting a specific option of the Timer. These options are usually + specific for a certain implementation of the Timer class, and may (and probably + will) not exist across different implementations. reset() must be called after + all setOption() calls. + @param + strKey The name of the option to set + @param + pValue A pointer to the value - the size should be calculated by the timer + based on the key + @return + On success, true is returned. + @par + On failure, false is returned. + */ + bool setOption( const String& strKey, const void* pValue ) + { (void)strKey; (void)pValue; return false; } + + /** Resets timer */ + void reset(); + + /** Returns milliseconds since initialisation or last reset */ + unsigned long getMilliseconds(); + + /** Returns microseconds since initialisation or last reset */ + unsigned long getMicroseconds(); + + /** Returns milliseconds since initialisation or last reset, only CPU time measured */ + unsigned long getMillisecondsCPU(); + + /** Returns microseconds since initialisation or last reset, only CPU time measured */ + unsigned long getMicrosecondsCPU(); + }; +} +#endif diff --git a/OgreMain/include/GLX/OgreTimerImp.h b/OgreMain/include/GLX/OgreTimerImp.h index d8107866b..a84cf314c 100644 --- a/OgreMain/include/GLX/OgreTimerImp.h +++ b/OgreMain/include/GLX/OgreTimerImp.h @@ -31,6 +31,8 @@ THE SOFTWARE. #include "../OgrePrerequisites.h" +#include + namespace Ogre { /** Timer class */ diff --git a/OgreMain/include/OgreConfigDialog.h b/OgreMain/include/OgreConfigDialog.h index c1b050d8c..2f344ccf2 100644 --- a/OgreMain/include/OgreConfigDialog.h +++ b/OgreMain/include/OgreConfigDialog.h @@ -44,6 +44,8 @@ THE SOFTWARE. # include "GLX/OgreConfigDialogImp.h" #elif OGRE_PLATFORM == OGRE_PLATFORM_NACL # include "NaCl/OgreConfigDialogImp.h" +#elif OGRE_PLATFORM == OGRE_PLATFORM_EMSCRIPTEN +# include "Emscripten/OgreConfigDialogImp.h" #elif OGRE_PLATFORM == OGRE_PLATFORM_APPLE # include "OSX/OgreConfigDialogImp.h" #elif OGRE_PLATFORM == OGRE_PLATFORM_APPLE_IOS diff --git a/OgreMain/include/OgreDynLib.h b/OgreMain/include/OgreDynLib.h index 7e39e23c1..f274b7dde 100644 --- a/OgreMain/include/OgreDynLib.h +++ b/OgreMain/include/OgreDynLib.h @@ -51,7 +51,8 @@ typedef struct HINSTANCE__* hInstance; # define DYNLIB_GETSYM( a, b ) dlsym( a, b ) # define DYNLIB_UNLOAD( a ) dlclose( a ) -#elif OGRE_PLATFORM == OGRE_PLATFORM_SYMBIAN || OGRE_PLATFORM == OGRE_PLATFORM_NACL +#elif OGRE_PLATFORM == OGRE_PLATFORM_SYMBIAN || OGRE_PLATFORM == OGRE_PLATFORM_NACL || \ + OGRE_PLATFORM == OGRE_PLATFORM_EMSCRIPTEN # define DYNLIB_HANDLE void* # define DYNLIB_LOAD( a ) 0 # define DYNLIB_GETSYM( a, b ) 0 diff --git a/OgreMain/include/OgreErrorDialog.h b/OgreMain/include/OgreErrorDialog.h index ccbb1c8ca..177405b59 100644 --- a/OgreMain/include/OgreErrorDialog.h +++ b/OgreMain/include/OgreErrorDialog.h @@ -44,6 +44,8 @@ THE SOFTWARE. # include "GLX/OgreErrorDialogImp.h" #elif OGRE_PLATFORM == OGRE_PLATFORM_NACL # include "NaCl/OgreErrorDialogImp.h" +#elif OGRE_PLATFORM == OGRE_PLATFORM_EMSCRIPTEN +# include "Emscripten/OgreErrorDialogImp.h" #elif OGRE_PLATFORM == OGRE_PLATFORM_APPLE # include "OSX/OgreErrorDialogImp.h" #elif OGRE_PLATFORM == OGRE_PLATFORM_APPLE_IOS diff --git a/OgreMain/include/OgreLog.h b/OgreMain/include/OgreLog.h index d26ba6a50..014d50f5b 100644 --- a/OgreMain/include/OgreLog.h +++ b/OgreMain/include/OgreLog.h @@ -32,7 +32,7 @@ THE SOFTWARE. #include "OgrePrerequisites.h" #include "OgreString.h" -#if OGRE_PLATFORM == OGRE_PLATFORM_NACL +#if OGRE_PLATFORM == OGRE_PLATFORM_NACL || OGRE_PLATFORM == OGRE_PLATFORM_EMSCRIPTEN namespace pp { class Instance; @@ -248,7 +248,7 @@ namespace Ogre { }; -#if OGRE_PLATFORM == OGRE_PLATFORM_NACL +#if OGRE_PLATFORM == OGRE_PLATFORM_NACL || OGRE_PLATFORM == OGRE_PLATFORM_EMSCRIPTEN protected: static pp::Instance* mInstance; public: diff --git a/OgreMain/include/OgrePlatform.h b/OgreMain/include/OgrePlatform.h index a31e977f8..e54977dce 100644 --- a/OgreMain/include/OgrePlatform.h +++ b/OgreMain/include/OgrePlatform.h @@ -40,6 +40,7 @@ namespace Ogre { #define OGRE_PLATFORM_APPLE_IOS 5 #define OGRE_PLATFORM_ANDROID 6 #define OGRE_PLATFORM_NACL 7 +#define OGRE_PLATFORM_EMSCRIPTEN 8 #define OGRE_COMPILER_MSVC 1 #define OGRE_COMPILER_GNUC 2 @@ -123,6 +124,20 @@ namespace Ogre { # ifndef OGRE_BUILD_RENDERSYSTEM_GLES2 # error GLES2 render system is required for NaCl (OGRE_BUILD_RENDERSYSTEM_GLES2=false in CMake) # endif +#elif defined( EMSCRIPTEN ) +# define OGRE_PLATFORM OGRE_PLATFORM_EMSCRIPTEN +# ifndef OGRE_STATIC_LIB +# error OGRE must be built as static for Emscripten (OGRE_STATIC=true in CMake) +# endif +# ifdef OGRE_BUILD_RENDERSYSTEM_D3D9 +# error D3D9 is not supported on Emscripten (OGRE_BUILD_RENDERSYSTEM_D3D9 false in CMake) +# endif +# ifdef OGRE_BUILD_RENDERSYSTEM_GL +# error OpenGL is not supported on Emscripten (OGRE_BUILD_RENDERSYSTEM_GL=false in CMake) +# endif +# ifndef OGRE_BUILD_RENDERSYSTEM_GLES2 +# error GLES2 render system is required for Emscripten (OGRE_BUILD_RENDERSYSTEM_GLES2=false in CMake) +# endif #else # define OGRE_PLATFORM OGRE_PLATFORM_LINUX #endif @@ -241,7 +256,7 @@ namespace Ogre { //---------------------------------------------------------------------------- // Linux/Apple/iOs/Android/Symbian/NaCl Settings #if OGRE_PLATFORM == OGRE_PLATFORM_LINUX || OGRE_PLATFORM == OGRE_PLATFORM_APPLE || OGRE_PLATFORM == OGRE_PLATFORM_APPLE_IOS || \ - OGRE_PLATFORM == OGRE_PLATFORM_ANDROID || OGRE_PLATFORM == OGRE_PLATFORM_NACL + OGRE_PLATFORM == OGRE_PLATFORM_ANDROID || OGRE_PLATFORM == OGRE_PLATFORM_NACL || OGRE_PLATFORM == OGRE_PLATFORM_EMSCRIPTEN // Enable GCC symbol visibility # if defined( OGRE_GCC_VISIBILITY ) diff --git a/OgreMain/include/OgrePlatformInformation.h b/OgreMain/include/OgrePlatformInformation.h index f294925e8..333b584b3 100644 --- a/OgreMain/include/OgrePlatformInformation.h +++ b/OgreMain/include/OgrePlatformInformation.h @@ -88,10 +88,11 @@ namespace Ogre { /* Define whether or not Ogre compiled with SSE supports. */ #if OGRE_DOUBLE_PRECISION == 0 && OGRE_CPU == OGRE_CPU_X86 && OGRE_COMPILER == OGRE_COMPILER_MSVC && \ - OGRE_PLATFORM != OGRE_PLATFORM_NACL + OGRE_PLATFORM != OGRE_PLATFORM_NACL && OGRE_PLATFORM != OGRE_PLATFORM_EMSCRIPTEN # define __OGRE_HAVE_SSE 1 #elif OGRE_DOUBLE_PRECISION == 0 && OGRE_CPU == OGRE_CPU_X86 && OGRE_COMPILER == OGRE_COMPILER_GNUC && \ - OGRE_PLATFORM != OGRE_PLATFORM_APPLE_IOS && OGRE_PLATFORM != OGRE_PLATFORM_NACL + OGRE_PLATFORM != OGRE_PLATFORM_APPLE_IOS && OGRE_PLATFORM != OGRE_PLATFORM_NACL && \ + OGRE_PLATFORM != OGRE_PLATFORM_EMSCRIPTEN # define __OGRE_HAVE_SSE 1 #endif diff --git a/OgreMain/include/OgreStringConverter.h b/OgreMain/include/OgreStringConverter.h index a5f0ff4a3..955344158 100644 --- a/OgreMain/include/OgreStringConverter.h +++ b/OgreMain/include/OgreStringConverter.h @@ -91,7 +91,8 @@ namespace Ogre { static String toString(int val, unsigned short width = 0, char fill = ' ', std::ios::fmtflags flags = std::ios::fmtflags(0) ); -#if OGRE_PLATFORM != OGRE_PLATFORM_NACL && ( OGRE_ARCH_TYPE == OGRE_ARCHITECTURE_64 || OGRE_PLATFORM == OGRE_PLATFORM_APPLE || OGRE_PLATFORM == OGRE_PLATFORM_APPLE_IOS ) +#if OGRE_PLATFORM != OGRE_PLATFORM_NACL && OGRE_PLATFORM != OGRE_EMSCRIPTEN && \ + ( OGRE_ARCH_TYPE == OGRE_ARCHITECTURE_64 || OGRE_PLATFORM == OGRE_PLATFORM_APPLE || OGRE_PLATFORM == OGRE_PLATFORM_APPLE_IOS ) /** Converts an unsigned int to a String. */ static String toString(unsigned int val, unsigned short width = 0, char fill = ' ', diff --git a/OgreMain/include/OgreTimer.h b/OgreMain/include/OgreTimer.h index f8875eaa1..d04ad94ac 100644 --- a/OgreMain/include/OgreTimer.h +++ b/OgreMain/include/OgreTimer.h @@ -38,6 +38,8 @@ THE SOFTWARE. # include "GLX/OgreTimerImp.h" #elif OGRE_PLATFORM == OGRE_PLATFORM_NACL # include "NaCl/OgreTimerImp.h" +#elif OGRE_PLATFORM == OGRE_PLATFORM_EMSCRIPTEN +# include "Emscripten/OgreTimerImp.h" #elif OGRE_PLATFORM == OGRE_PLATFORM_APPLE # include "OSX/OgreTimerImp.h" #elif OGRE_PLATFORM == OGRE_PLATFORM_APPLE_IOS diff --git a/OgreMain/src/Emscripten/OgreConfigDialog.cpp b/OgreMain/src/Emscripten/OgreConfigDialog.cpp new file mode 100644 index 000000000..d3b6789b8 --- /dev/null +++ b/OgreMain/src/Emscripten/OgreConfigDialog.cpp @@ -0,0 +1,43 @@ +/* +----------------------------------------------------------------------------- +This source file is part of OGRE + (Object-oriented Graphics Rendering Engine) +For the latest info, see http://www.ogre3d.org/ + +Copyright (c) 2000-2009 Torus Knot Software Ltd + +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. +----------------------------------------------------------------------------- +*/ +#include "OgreConfigDialog.h" + +namespace Ogre { + +//------------------------------------------------------------------------------------// +ConfigDialog::ConfigDialog() : mSelectedRenderSystem(0) +{ +} + +//------------------------------------------------------------------------------------// +bool ConfigDialog::display() +{ + return true; +} +}; + diff --git a/OgreMain/src/Emscripten/OgreErrorDialog.cpp b/OgreMain/src/Emscripten/OgreErrorDialog.cpp new file mode 100644 index 000000000..3848bcfbb --- /dev/null +++ b/OgreMain/src/Emscripten/OgreErrorDialog.cpp @@ -0,0 +1,42 @@ +/* +----------------------------------------------------------------------------- +This source file is part of OGRE +(Object-oriented Graphics Rendering Engine) +For the latest info, see http://www.ogre3d.org/ + +Copyright (c) 2000-2009 Torus Knot Software Ltd + +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. +----------------------------------------------------------------------------- +*/ +#include "OgreErrorDialog.h" +#include + +using namespace Ogre; + +//---------------------------------------------------------------------------// +ErrorDialog::ErrorDialog() +{ +} + +//---------------------------------------------------------------------------// +void ErrorDialog::display(const String& errorMessage, String logName) +{ + std::cout << "*** ERROR: " << errorMessage << std::endl; +} diff --git a/OgreMain/src/Emscripten/OgreTimer.cpp b/OgreMain/src/Emscripten/OgreTimer.cpp new file mode 100644 index 000000000..f79fc7744 --- /dev/null +++ b/OgreMain/src/Emscripten/OgreTimer.cpp @@ -0,0 +1,79 @@ +/* +----------------------------------------------------------------------------- +This source file is part of OGRE +(Object-oriented Graphics Rendering Engine) +For the latest info, see http://www.ogre3d.org/ + +Copyright (c) 2000-2009 Torus Knot Software Ltd + +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. +----------------------------------------------------------------------------- +*/ +#include "OgreTimer.h" +#include + +using namespace Ogre; + +//--------------------------------------------------------------------------------// +Timer::Timer() +{ + reset(); +} + +//--------------------------------------------------------------------------------// +Timer::~Timer() +{ +} + +//--------------------------------------------------------------------------------// +void Timer::reset() +{ + zeroClock = clock(); + gettimeofday(&start, NULL); +} + +//--------------------------------------------------------------------------------// +unsigned long Timer::getMilliseconds() +{ + struct timeval now; + gettimeofday(&now, NULL); + return (now.tv_sec-start.tv_sec)*1000+(now.tv_usec-start.tv_usec)/1000; +} + +//--------------------------------------------------------------------------------// +unsigned long Timer::getMicroseconds() +{ + struct timeval now; + gettimeofday(&now, NULL); + return (now.tv_sec-start.tv_sec)*1000000+(now.tv_usec-start.tv_usec); +} + +//-- Common Across All Timers ----------------------------------------------------// +unsigned long Timer::getMillisecondsCPU() +{ + clock_t newClock = clock(); + return (unsigned long)((float)(newClock-zeroClock) / ((float)CLOCKS_PER_SEC/1000.0)) ; +} + +//-- Common Across All Timers ----------------------------------------------------// +unsigned long Timer::getMicrosecondsCPU() +{ + clock_t newClock = clock(); + return (unsigned long)((float)(newClock-zeroClock) / ((float)CLOCKS_PER_SEC/1000000.0)) ; +} diff --git a/OgreMain/src/OgreDynLib.cpp b/OgreMain/src/OgreDynLib.cpp index 0082f3958..ee6e837d4 100644 --- a/OgreMain/src/OgreDynLib.cpp +++ b/OgreMain/src/OgreDynLib.cpp @@ -67,7 +67,8 @@ namespace Ogre { LogManager::getSingleton().logMessage("Loading library " + mName); String name = mName; -#if OGRE_PLATFORM == OGRE_PLATFORM_LINUX || OGRE_PLATFORM == OGRE_PLATFORM_NACL +#if OGRE_PLATFORM == OGRE_PLATFORM_LINUX || OGRE_PLATFORM == OGRE_PLATFORM_NACL || \ + OGRE_PLATFORM == OGRE_PLATFORM_EMSCRIPTEN // dlopen() does not add .so to the filename, like windows does for .dll if (name.find(".so") == String::npos) name += ".so"; diff --git a/OgreMain/src/OgreFileSystem.cpp b/OgreMain/src/OgreFileSystem.cpp index 32b179ff4..45525c6c7 100644 --- a/OgreMain/src/OgreFileSystem.cpp +++ b/OgreMain/src/OgreFileSystem.cpp @@ -38,7 +38,8 @@ THE SOFTWARE. #if OGRE_PLATFORM == OGRE_PLATFORM_LINUX || OGRE_PLATFORM == OGRE_PLATFORM_APPLE || \ OGRE_PLATFORM == OGRE_PLATFORM_SYMBIAN || OGRE_PLATFORM == OGRE_PLATFORM_APPLE_IOS || \ OGRE_PLATFORM == OGRE_PLATFORM_ANDROID || \ - OGRE_PLATFORM == OGRE_PLATFORM_NACL + OGRE_PLATFORM == OGRE_PLATFORM_NACL || \ + OGRE_PLATFORM == OGRE_PLATFORM_EMSCRIPTEN # include "OgreSearchOps.h" # include # define MAX_PATH MAXPATHLEN diff --git a/OgreMain/src/OgreImage.cpp b/OgreMain/src/OgreImage.cpp index 5243e47be..ad0eafd18 100644 --- a/OgreMain/src/OgreImage.cpp +++ b/OgreMain/src/OgreImage.cpp @@ -33,6 +33,7 @@ THE SOFTWARE. #include "OgreColourValue.h" #include "OgreImageResampler.h" +#include "OgreMath.h" namespace Ogre { ImageCodec::~ImageCodec() { diff --git a/OgreMain/src/OgrePlatformInformation.cpp b/OgreMain/src/OgrePlatformInformation.cpp index 1196f26c7..3b258b8f7 100644 --- a/OgreMain/src/OgrePlatformInformation.cpp +++ b/OgreMain/src/OgrePlatformInformation.cpp @@ -36,7 +36,7 @@ THE SOFTWARE. #if _MSC_VER >= 1400 #include #endif -#elif OGRE_COMPILER == OGRE_COMPILER_GNUC && OGRE_PLATFORM != OGRE_PLATFORM_NACL +#elif OGRE_COMPILER == OGRE_COMPILER_GNUC && OGRE_PLATFORM != OGRE_PLATFORM_NACL && OGRE_COMPILER == OGRE_PLATFORM != OGRE_PLATFORM_EMSCRIPTEN #include #include @@ -115,7 +115,7 @@ namespace Ogre { // Return values in eax, no return statement requirement here for VC. } #endif -#elif OGRE_COMPILER == OGRE_COMPILER_GNUC && OGRE_PLATFORM != OGRE_PLATFORM_NACL +#elif OGRE_COMPILER == OGRE_COMPILER_GNUC && OGRE_PLATFORM != OGRE_PLATFORM_NACL && OGRE_PLATFORM != OGRE_PLATFORM_EMSCRIPTEN #if OGRE_ARCH_TYPE == OGRE_ARCHITECTURE_64 return true; #else @@ -169,7 +169,7 @@ namespace Ogre { // Return values in eax, no return statement requirement here for VC. } #endif -#elif OGRE_COMPILER == OGRE_COMPILER_GNUC && OGRE_PLATFORM != OGRE_PLATFORM_NACL +#elif OGRE_COMPILER == OGRE_COMPILER_GNUC && OGRE_PLATFORM != OGRE_PLATFORM_NACL && OGRE_PLATFORM != OGRE_PLATFORM_EMSCRIPTEN #if OGRE_ARCH_TYPE == OGRE_ARCHITECTURE_64 __asm__ ( @@ -200,7 +200,7 @@ namespace Ogre { //--------------------------------------------------------------------- // Detect whether or not os support Streaming SIMD Extension. -#if OGRE_COMPILER == OGRE_COMPILER_GNUC && OGRE_PLATFORM != OGRE_PLATFORM_NACL +#if OGRE_COMPILER == OGRE_COMPILER_GNUC && OGRE_PLATFORM != OGRE_PLATFORM_NACL && OGRE_PLATFORM != OGRE_PLATFORM_EMSCRIPTEN #if OGRE_ARCH_TYPE == OGRE_ARCHITECTURE_32 static jmp_buf sIllegalJmpBuf; static void _illegalHandler(int x) @@ -243,7 +243,7 @@ namespace Ogre { return false; } #endif -#elif OGRE_COMPILER == OGRE_COMPILER_GNUC && OGRE_PLATFORM != OGRE_PLATFORM_NACL +#elif OGRE_COMPILER == OGRE_COMPILER_GNUC && OGRE_PLATFORM != OGRE_PLATFORM_NACL && OGRE_PLATFORM != OGRE_PLATFORM_EMSCRIPTEN #if OGRE_ARCH_TYPE == OGRE_ARCHITECTURE_64 return true; #else diff --git a/OgreMain/src/OgreStringConverter.cpp b/OgreMain/src/OgreStringConverter.cpp index 5de85882e..ba74e98f0 100644 --- a/OgreMain/src/OgreStringConverter.cpp +++ b/OgreMain/src/OgreStringConverter.cpp @@ -62,7 +62,8 @@ namespace Ogre { return stream.str(); } //----------------------------------------------------------------------- -#if OGRE_PLATFORM != OGRE_PLATFORM_NACL && ( OGRE_ARCH_TYPE == OGRE_ARCHITECTURE_64 || OGRE_PLATFORM == OGRE_PLATFORM_APPLE || OGRE_PLATFORM == OGRE_PLATFORM_APPLE_IOS ) +#if OGRE_PLATFORM != OGRE_PLATFORM_NACL && OGRE_PLATFORM != OGRE_PLATFORM_EMSCRIPTEN && \ + ( OGRE_ARCH_TYPE == OGRE_ARCHITECTURE_64 || OGRE_PLATFORM == OGRE_PLATFORM_APPLE || OGRE_PLATFORM == OGRE_PLATFORM_APPLE_IOS ) String StringConverter::toString(unsigned int val, unsigned short width, char fill, std::ios::fmtflags flags) { diff --git a/RenderSystems/GLES2/CMakeLists.txt b/RenderSystems/GLES2/CMakeLists.txt index 694e6ccfb..00c8a5bf3 100644 --- a/RenderSystems/GLES2/CMakeLists.txt +++ b/RenderSystems/GLES2/CMakeLists.txt @@ -105,6 +105,20 @@ if (OGRE_BUILD_PLATFORM_NACL) ) include_directories(src/NaCl include/NaCl) set(PLATFORM_HEADER_INSTALL "NaCl") +elseif (OGRE_BUILD_PLATFORM_EMSCRIPTEN) + set(PLATFORM_HEADERS + include/SDL/OgreGLES2Util.h + include/SDL/OgreSDLGLContext.h + include/SDL/OgreSDLGLSupport.h + include/SDL/OgreSDLWindow.h + ) + set(PLATFORM_SOURCES + src/SDL/OgreSDLGLContext.cpp + src/SDL/OgreSDLGLSupport.cpp + src/SDL/OgreSDLWindow.cpp + ) + include_directories(src/SDL include/SDL) + set(PLATFORM_HEADER_INSTALL "SDL") elseif (WIN32) set(PLATFORM_HEADERS include/EGL/WIN32/OgreWin32EGLContext.h diff --git a/RenderSystems/GLES2/include/OgreGLES2Prerequisites.h b/RenderSystems/GLES2/include/OgreGLES2Prerequisites.h index b837cbd82..fc64ea688 100644 --- a/RenderSystems/GLES2/include/OgreGLES2Prerequisites.h +++ b/RenderSystems/GLES2/include/OgreGLES2Prerequisites.h @@ -82,6 +82,10 @@ THE SOFTWARE. # include # include +#if (OGRE_PLATFORM == OGRE_PLATFORM_EMSCRIPTEN) +# include +#endif + // Function pointers for FBO extension methods // Declare them here since we don't have GLEW to do it for us diff --git a/RenderSystems/GLES2/include/SDL/OgreGLES2Util.h b/RenderSystems/GLES2/include/SDL/OgreGLES2Util.h new file mode 100644 index 000000000..29306f909 --- /dev/null +++ b/RenderSystems/GLES2/include/SDL/OgreGLES2Util.h @@ -0,0 +1,41 @@ +/* +----------------------------------------------------------------------------- +This source file is part of OGRE +(Object-oriented Graphics Rendering Engine) +For the latest info, see http://www.ogre3d.org/ + +Copyright (c) 2000-2009 Torus Knot Software Ltd + +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. +----------------------------------------------------------------------------- +*/ + +#ifndef __GLES2Util_H__ +#define __GLES2Util_H__ + +#include "OgreSDLGLSupport.h" + +namespace Ogre { + inline GLES2Support* getGLSupport() + { + return new SDLGLSupport(); + } +}; + +#endif diff --git a/RenderSystems/GLES2/include/SDL/OgreSDLGLContext.h b/RenderSystems/GLES2/include/SDL/OgreSDLGLContext.h new file mode 100644 index 000000000..cc3cb3f6f --- /dev/null +++ b/RenderSystems/GLES2/include/SDL/OgreSDLGLContext.h @@ -0,0 +1,61 @@ +/* +----------------------------------------------------------------------------- +This source file is part of OGRE + (Object-oriented Graphics Rendering Engine) +For the latest info, see http://www.ogre3d.org/ + +Copyright (c) 2000-2009 Torus Knot Software Ltd + +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. +----------------------------------------------------------------------------- +*/ + +#ifndef __SDLGLContext_H__ +#define __SDLGLContext_H__ + +#include "OgreGLES2Context.h" +#include "OgreSDLWindow.h" + +namespace Ogre { + class SDLGLSupport; + + class _OgrePrivate SDLGLContext : public GLES2Context + { + private: + const SDLGLSupport *mGLSupport; + const SDLWindow* mWindow; + SDL_Surface* mContext; + unsigned int mWidth; + unsigned int mHeight; + public: + SDLGLContext(const SDLWindow * window, const SDLGLSupport *glsupport); + virtual ~SDLGLContext(); + + virtual void setCurrent(); + virtual void endCurrent(); + GLES2Context* clone() const; + + void swapBuffers(bool waitForVSync); + + void resize(); + + }; +} + +#endif diff --git a/RenderSystems/GLES2/include/SDL/OgreSDLGLSupport.h b/RenderSystems/GLES2/include/SDL/OgreSDLGLSupport.h new file mode 100644 index 000000000..a09b162ea --- /dev/null +++ b/RenderSystems/GLES2/include/SDL/OgreSDLGLSupport.h @@ -0,0 +1,66 @@ +/* +----------------------------------------------------------------------------- +This source file is part of OGRE + (Object-oriented Graphics Rendering Engine) +For the latest info, see http://www.ogre3d.org/ + +Copyright (c) 2000-2009 Torus Knot Software Ltd + +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. +----------------------------------------------------------------------------- +*/ + +#ifndef __SDLGLSupport_H__ +#define __SDLGLSupport_H__ + +#include "OgreGLES2Support.h" +#include "OgreSDLWindow.h" + +namespace Ogre { + class GLES2PBuffer; + + class _OgrePrivate SDLGLSupport : public GLES2Support + { + public: + SDLGLSupport(); + virtual ~SDLGLSupport(); + + void switchMode(uint& width, uint& height, short& frequency); + String getDisplayName(void); + + RenderWindow* createWindow(bool autoCreateWindow, + GLES2RenderSystem *renderSystem, + const String& windowTitle); + + RenderWindow* newWindow(const String& name, + unsigned int width, unsigned int height, + bool fullScreen, + const NameValuePairList *miscParams = 0); + + void start(void); + void stop(void); + void addConfig(void); + void refreshConfig(void); + String validateConfig(void); + void setConfigOption(const String &name, const String &value); + void* getProcAddress(const Ogre::String& name); + }; +} + +#endif diff --git a/RenderSystems/GLES2/include/SDL/OgreSDLWindow.h b/RenderSystems/GLES2/include/SDL/OgreSDLWindow.h new file mode 100644 index 000000000..0d8b3f273 --- /dev/null +++ b/RenderSystems/GLES2/include/SDL/OgreSDLWindow.h @@ -0,0 +1,79 @@ +/* +----------------------------------------------------------------------------- +This source file is part of OGRE + (Object-oriented Graphics Rendering Engine) +For the latest info, see http://www.ogre3d.org/ + +Copyright (c) 2000-2009 Torus Knot Software Ltd + +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. +----------------------------------------------------------------------------- +*/ + +#ifndef __SDLWindow_H__ +#define __SDLWindow_H__ + +#include "OgreSDLGLSupport.h" + +namespace Ogre { + class SDLGLContext; + class SDLGLSupport; + + + class _OgrePrivate SDLWindow : public RenderWindow + { + protected: + SDLGLSupport* mGLSupport; + SDLGLContext* mContext; + bool mClosed; + bool mActive; + SDL_Surface* mScreen; + + void reposition(int left, int top); + void resize(unsigned int width, unsigned int height); + void windowMovedOrResized(); + + + public: + explicit SDLWindow(SDLGLSupport* glsupport); + virtual ~SDLWindow(); + + /** + @remarks + * Get custom attribute; the following attributes are valid: + * HANDLE The integer id of the android window + * GLCONTEXT The Ogre GLContext used for rendering. + */ + void getCustomAttribute(const String& name, void* pData); + + void copyContentsToMemory(const PixelBox &dst, FrameBuffer buffer); + bool requiresTextureFlipping() const; + void destroy(void); + bool isClosed(void) const; + bool isActive(void) const; + + void swapBuffers(bool waitForVSync); + + //Moved this from EGLWindow because it has some native calls. + void create(const String& name, unsigned int width, unsigned int height, + bool fullScreen, const NameValuePairList *miscParams); + }; +} + +#endif diff --git a/RenderSystems/GLES2/src/OgreGLES2RenderSystem.cpp b/RenderSystems/GLES2/src/OgreGLES2RenderSystem.cpp index 7a1ffeb16..9bebfc626 100644 --- a/RenderSystems/GLES2/src/OgreGLES2RenderSystem.cpp +++ b/RenderSystems/GLES2/src/OgreGLES2RenderSystem.cpp @@ -53,6 +53,8 @@ THE SOFTWARE. # include "OgreAndroidWindow.h" #elif OGRE_PLATFORM == OGRE_PLATFORM_NACL # include "OgreNaClWindow.h" +#elif OGRE_PLATFORM == OGRE_PLATFORM_EMSCRIPTEN +# include "OgreSDLWindow.h" #else # include "OgreEGLWindow.h" # ifndef GL_GLEXT_PROTOTYPES diff --git a/RenderSystems/GL/src/SDL/OgreGLUtil.h b/RenderSystems/GLES2/src/SDL/OgreGLUtil.h similarity index 100% rename from RenderSystems/GL/src/SDL/OgreGLUtil.h rename to RenderSystems/GLES2/src/SDL/OgreGLUtil.h diff --git a/RenderSystems/GLES2/src/SDL/OgreSDLGLContext.cpp b/RenderSystems/GLES2/src/SDL/OgreSDLGLContext.cpp new file mode 100644 index 000000000..4f919e150 --- /dev/null +++ b/RenderSystems/GLES2/src/SDL/OgreSDLGLContext.cpp @@ -0,0 +1,97 @@ +/* +----------------------------------------------------------------------------- +This source file is part of OGRE + (Object-oriented Graphics Rendering Engine) +For the latest info, see http://www.ogre3d.org/ + +Copyright (c) 2000-2009 Torus Knot Software Ltd + +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. +----------------------------------------------------------------------------- +*/ + +#include "OgreSDLGLContext.h" +#include "OgreLog.h" +#include "OgreException.h" +#include "OgreRoot.h" +#include "OgreException.h" +#include "OgreLogManager.h" +#include "OgreStringConverter.h" +#include "OgreWindowEventUtilities.h" + +#include "OgreGLES2Prerequisites.h" +#include "OgreGLES2RenderSystem.h" + +#include "OgreSDLGLSupport.h" +#include "OgreSDLWindow.h" +#include "OgreSDLGLContext.h" + +#include + +namespace Ogre { + SDLGLContext::SDLGLContext(const SDLWindow * window, const SDLGLSupport *glsupport) + : mGLSupport(glsupport) + , mWindow(window) + , mWidth(mWindow->getWidth()) + , mHeight(mWindow->getHeight()) + { + } + + SDLGLContext::~SDLGLContext() + { + } + + void SDLGLContext::setCurrent() + { + unsigned int flags = SDL_OPENGL | SDL_RESIZABLE; + mContext = SDL_SetVideoMode(mWidth, mHeight, 0, flags); + } + + void SDLGLContext::endCurrent() + { + } + + GLES2Context* SDLGLContext::clone() const + { + SDLGLContext* res = new SDLGLContext(mWindow, mGLSupport); + return res; + } + + void SDLGLContext::swapBuffers( bool waitForVSync ) + { + SDL_GL_SwapBuffers(); + } + + void SDLGLContext::resize() + { + if(mWidth != mWindow->getWidth() || mHeight != mWindow->getHeight() ) + { + LogManager::getSingleton().logMessage("\tresizing"); + mWidth = mWindow->getWidth(); + mHeight = mWindow->getHeight(); + setCurrent(); // call SDL_SetVideoMode + LogManager::getSingleton().logMessage("\tdone resizing"); + } + + } + + + + +} // namespace diff --git a/RenderSystems/GL/src/SDL/OgreSDLGLSupport.cpp b/RenderSystems/GLES2/src/SDL/OgreSDLGLSupport.cpp similarity index 81% rename from RenderSystems/GL/src/SDL/OgreSDLGLSupport.cpp rename to RenderSystems/GLES2/src/SDL/OgreSDLGLSupport.cpp index 4fa0b643a..8f1bef596 100644 --- a/RenderSystems/GL/src/SDL/OgreSDLGLSupport.cpp +++ b/RenderSystems/GLES2/src/SDL/OgreSDLGLSupport.cpp @@ -1,6 +1,7 @@ #include "OgreException.h" #include "OgreLogManager.h" #include "OgreStringConverter.h" +#include "OgreGLES2RenderSystem.h" #include "OgreSDLGLSupport.h" @@ -11,6 +12,7 @@ using namespace Ogre; SDLGLSupport::SDLGLSupport() { + LogManager::getSingleton().logMessage("\tGLSupport ctor called"); SDL_Init(SDL_INIT_VIDEO); } @@ -20,9 +22,9 @@ SDLGLSupport::~SDLGLSupport() void SDLGLSupport::addConfig(void) { - mVideoModes = SDL_ListModes(NULL, SDL_FULLSCREEN | SDL_OPENGL); + SDL_Rect** videoModes = SDL_ListModes(NULL, SDL_FULLSCREEN | SDL_OPENGL); - if (mVideoModes == (SDL_Rect **)0) + if (videoModes == (SDL_Rect **)0) { OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "Unable to load video modes", "SDLRenderSystem::initConfigOptions"); @@ -46,16 +48,21 @@ void SDLGLSupport::addConfig(void) // Video mode possibilities optVideoMode.name = "Video Mode"; optVideoMode.immutable = false; - for (size_t i = 0; mVideoModes[i]; i++) - { - char szBuf[16]; - snprintf(szBuf, 16, "%d x %d", mVideoModes[i]->w, mVideoModes[i]->h); - optVideoMode.possibleValues.push_back(szBuf); - // Make the first one default - if (i == 0) - { - optVideoMode.currentValue = szBuf; - } + if (videoModes != (SDL_Rect**)-1) { // All resolutions + for (size_t i = 0; videoModes[i]; i++) + { + char szBuf[16]; + snprintf(szBuf, 16, "%d x %d", videoModes[i]->w, videoModes[i]->h); + optVideoMode.possibleValues.push_back(szBuf); + // Make the first one default + if (i == 0) + { + optVideoMode.currentValue = szBuf; + } + } + } else { + optVideoMode.possibleValues.push_back("640 x 480"); + optVideoMode.currentValue = "640 x 480"; } //FSAA possibilities @@ -97,8 +104,9 @@ String SDLGLSupport::validateConfig(void) return String(""); } -RenderWindow* SDLGLSupport::createWindow(bool autoCreateWindow, GLRenderSystem* renderSystem, const String& windowTitle) +RenderWindow* SDLGLSupport::createWindow(bool autoCreateWindow, GLES2RenderSystem* renderSystem, const String& windowTitle) { + LogManager::getSingleton().logMessage("\tGLSupport createWindow called"); if (autoCreateWindow) { ConfigOptionMap::iterator opt = mOptions.find("Full Screen"); @@ -136,7 +144,7 @@ RenderWindow* SDLGLSupport::createWindow(bool autoCreateWindow, GLRenderSystem* unsigned int h = StringConverter::parseUnsignedInt(val.substr(pos + 1)); const SDL_VideoInfo* videoInfo = SDL_GetVideoInfo(); - return renderSystem->createRenderWindow(windowTitle, w, h, fullscreen, &winOptions); + return renderSystem->_createRenderWindow(windowTitle, w, h, fullscreen, &winOptions); } else { @@ -150,7 +158,8 @@ RenderWindow* SDLGLSupport::createWindow(bool autoCreateWindow, GLRenderSystem* RenderWindow* SDLGLSupport::newWindow(const String &name, unsigned int width, unsigned int height, bool fullScreen, const NameValuePairList *miscParams) { - SDLWindow* window = new SDLWindow(); + LogManager::getSingleton().logMessage("\tGLSupport newWindow called"); + SDLWindow* window = new SDLWindow(this); window->create(name, width, height, fullScreen, miscParams); return window; } diff --git a/RenderSystems/GL/src/SDL/OgreSDLWindow.cpp b/RenderSystems/GLES2/src/SDL/OgreSDLWindow.cpp similarity index 89% rename from RenderSystems/GL/src/SDL/OgreSDLWindow.cpp rename to RenderSystems/GLES2/src/SDL/OgreSDLWindow.cpp index 721be1be0..022d9bb9f 100644 --- a/RenderSystems/GL/src/SDL/OgreSDLWindow.cpp +++ b/RenderSystems/GLES2/src/SDL/OgreSDLWindow.cpp @@ -33,6 +33,8 @@ THE SOFTWARE. #include "OgreException.h" #include "OgreLogManager.h" #include "OgreStringConverter.h" +#include "OgreGLES2PixelFormat.h" +#include "OgreSDLGLContext.h" #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 # include @@ -53,8 +55,9 @@ THE SOFTWARE. namespace Ogre { - SDLWindow::SDLWindow() : - mScreen(NULL), mActive(false), mClosed(false) + SDLWindow::SDLWindow(SDLGLSupport* glSupport) : + mScreen(NULL), mActive(false), mClosed(false), + mGLSupport(glSupport), mContext(0) { } @@ -65,8 +68,19 @@ namespace Ogre { /*if (mScreen != NULL) SDL_FreeSurface(mScreen);*/ + if (mContext) + delete mContext; } + void SDLWindow::getCustomAttribute( const String& name, void* pData ) + { + if(name == "GLCONTEXT") + { + *static_cast(pData) = mContext; + return; + } + } + void SDLWindow::create(const String& name, unsigned int width, unsigned int height, bool fullScreen, const NameValuePairList *miscParams) { @@ -130,11 +144,10 @@ namespace Ogre { mActive = true; + mContext = new SDLGLContext(this, mGLSupport); + if (!fullScreen) SDL_WM_SetCaption(title.c_str(), 0); - - glXGetVideoSyncSGI = (int (*)(unsigned int *))SDL_GL_GetProcAddress("glXGetVideoSyncSGI"); - glXWaitVideoSyncSGI = (int (*)(int, int, unsigned int *))SDL_GL_GetProcAddress("glXWaitVideoSyncSGI"); } void SDLWindow::destroy(void) @@ -163,6 +176,11 @@ namespace Ogre { // XXX FIXME } + void SDLWindow::windowMovedOrResized() + { + LogManager::getSingleton().logMessage("\twindowMovedOrResized called"); + } + void SDLWindow::resize(unsigned int width, unsigned int height) { SDL_Surface* screen; @@ -192,13 +210,6 @@ namespace Ogre { void SDLWindow::swapBuffers(bool waitForVSync) { - if ( waitForVSync && glXGetVideoSyncSGI && glXWaitVideoSyncSGI ) - { - unsigned int retraceCount; - glXGetVideoSyncSGI( &retraceCount ); - glXWaitVideoSyncSGI( 2, ( retraceCount + 1 ) & 1, &retraceCount); - } - SDL_GL_SwapBuffers(); // XXX More? } @@ -219,8 +230,8 @@ namespace Ogre { buffer = mIsFullScreen? FB_FRONT : FB_BACK; } - GLenum format = Ogre::GLPixelUtil::getGLOriginFormat(dst.format); - GLenum type = Ogre::GLPixelUtil::getGLOriginDataType(dst.format); + GLenum format = Ogre::GLES2PixelUtil::getGLOriginFormat(dst.format); + GLenum type = Ogre::GLES2PixelUtil::getGLOriginDataType(dst.format); if ((format == GL_NONE) || (type == 0)) { @@ -229,7 +240,7 @@ namespace Ogre { "SDLWindow::copyContentsToMemory" ); } - glReadBuffer((buffer == FB_FRONT)? GL_FRONT : GL_BACK); + //glReadBuffer((buffer == FB_FRONT)? GL_FRONT : GL_BACK); glReadPixels((GLint)dst.left, (GLint)dst.top, (GLsizei)dst.getWidth(), (GLsizei)dst.getHeight(), format, type, dst.data); @@ -252,4 +263,9 @@ namespace Ogre { delete [] tmpData; } } + +bool SDLWindow::requiresTextureFlipping() const +{ + return false; +} }