From 942917fc4ea9f71a81415a4153391d0ac19f3e42 Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Wed, 1 Feb 2012 12:35:28 -0500 Subject: [PATCH 01/18] Add a missing include --- OgreMain/src/OgreImage.cpp | 1 + 1 file changed, 1 insertion(+) 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() { From f45d88cf68de0b06b2e8068acdf3e8c8cd444922 Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Wed, 1 Feb 2012 17:52:36 -0500 Subject: [PATCH 02/18] Include sys/time.h in a header which uses timeval --- OgreMain/include/GLX/OgreTimerImp.h | 2 ++ 1 file changed, 2 insertions(+) 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 */ From b10cee8977d8f232ce4c51ba3b20a7135f42bb57 Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Wed, 1 Feb 2012 20:12:03 -0500 Subject: [PATCH 03/18] Make the build system respect CMAKE_TOOLCHAIN_FILE --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index b260c63db..4861a7af1 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,6 +41,7 @@ set(CMAKE_MODULE_PATH "${OGRE_SOURCE_DIR}/CMake/Packages" ) +include(CMakeDetermineSystem) include(CMakeDependentOption) include(CheckCXXCompilerFlag) include(MacroLogFeature) From 437df036f49e42eef3d93f96ab144047f289f56d Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Wed, 1 Feb 2012 22:08:30 -0500 Subject: [PATCH 04/18] Fix the infinite cmake loop problem on Mac To fix this we need to move the code responsible for hardcoding Mac compilers to before the project command, so that a change in those variables would not force a reconfigure. --- CMakeLists.txt | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4861a7af1..41ca8cf50 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") + 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 () + project(OGRE) # Include necessary submodules @@ -52,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 ##################################################################### From f41922a8fa73f3f4264b8d3434046f8efbf7bafa Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Thu, 2 Feb 2012 17:31:05 -0500 Subject: [PATCH 05/18] Try to do parts of what the NaCl port does to build with Emscripten --- CMakeLists.txt | 3 +- OgreMain/CMakeLists.txt | 15 ++++ .../include/Emscripten/OgreConfigDialogImp.h | 75 +++++++++++++++++ .../include/Emscripten/OgreErrorDialogImp.h | 52 ++++++++++++ OgreMain/include/Emscripten/OgreTimerImp.h | 83 +++++++++++++++++++ OgreMain/include/OgreConfigDialog.h | 2 + OgreMain/include/OgreDynLib.h | 3 +- OgreMain/include/OgreErrorDialog.h | 2 + OgreMain/include/OgreLog.h | 4 +- OgreMain/include/OgrePlatform.h | 17 +++- OgreMain/include/OgrePlatformInformation.h | 5 +- OgreMain/include/OgreStringConverter.h | 3 +- OgreMain/include/OgreTimer.h | 2 + OgreMain/src/Emscripten/OgreConfigDialog.cpp | 43 ++++++++++ OgreMain/src/Emscripten/OgreErrorDialog.cpp | 42 ++++++++++ OgreMain/src/Emscripten/OgreTimer.cpp | 79 ++++++++++++++++++ OgreMain/src/OgreDynLib.cpp | 3 +- OgreMain/src/OgreFileSystem.cpp | 3 +- OgreMain/src/OgrePlatformInformation.cpp | 10 +-- OgreMain/src/OgreStringConverter.cpp | 3 +- 20 files changed, 433 insertions(+), 16 deletions(-) create mode 100644 OgreMain/include/Emscripten/OgreConfigDialogImp.h create mode 100644 OgreMain/include/Emscripten/OgreErrorDialogImp.h create mode 100644 OgreMain/include/Emscripten/OgreTimerImp.h create mode 100644 OgreMain/src/Emscripten/OgreConfigDialog.cpp create mode 100644 OgreMain/src/Emscripten/OgreErrorDialog.cpp create mode 100644 OgreMain/src/Emscripten/OgreTimer.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 41ca8cf50..69add1b63 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,7 +39,7 @@ if (APPLE) 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 () + 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) @@ -259,6 +259,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/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..731cb0dcb 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/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) { From b2d590994cd19a0b9b660af03a6d3fb42565db2e Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Thu, 2 Feb 2012 17:59:24 -0500 Subject: [PATCH 06/18] Fix a stupid mistake --- OgreMain/include/OgreStringConverter.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OgreMain/include/OgreStringConverter.h b/OgreMain/include/OgreStringConverter.h index 731cb0dcb..955344158 100644 --- a/OgreMain/include/OgreStringConverter.h +++ b/OgreMain/include/OgreStringConverter.h @@ -91,7 +91,7 @@ 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_PLATFORM != OGRE_EMSCRIPTEN && \ +#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, From 48378aa88e5713d4837fd2f022d86d7edbc19780 Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Fri, 3 Feb 2012 16:03:42 -0500 Subject: [PATCH 07/18] Don't use X11 for Emscripten builds --- CMake/Dependencies.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMake/Dependencies.cmake b/CMake/Dependencies.cmake index 8198e2d96..68e1fb923 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 "" "") From d2873aa8125ec7fe366dbaeb11270b6a7ecbb4f2 Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Fri, 3 Feb 2012 16:04:09 -0500 Subject: [PATCH 08/18] Don't use Boost and threads on Emscripten --- CMake/Dependencies.cmake | 54 +++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/CMake/Dependencies.cmake b/CMake/Dependencies.cmake index 68e1fb923..aa34b5e5b 100755 --- a/CMake/Dependencies.cmake +++ b/CMake/Dependencies.cmake @@ -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) From 367115bd3d56442f709ec2ad7032671dc5f1ba28 Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Fri, 3 Feb 2012 16:05:41 -0500 Subject: [PATCH 09/18] Force GLES2 and static builds for Emscripten --- CMakeLists.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 69add1b63..1a57d5a2b 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -237,6 +237,12 @@ 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_APPLE_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) + + remove_definitions(-msse) elseif (SYMBIAN) set(OGRE_BUILD_RENDERSYSTEM_GLES TRUE CACHE BOOL "Forcing OpenGL ES 1.x RenderSystem for Symbian" FORCE) endif () From 00a87661110fdc8297826e55087bd8aa0cb715bc Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Fri, 3 Feb 2012 18:12:11 -0500 Subject: [PATCH 10/18] Implement a simple SDL backend for Emscripten builds --- RenderSystems/GLES2/CMakeLists.txt | 14 ++ .../GLES2/include/OgreGLES2Prerequisites.h | 4 + .../GLES2/include/SDL/OgreGLES2Util.h | 41 +++++ .../GLES2/include/SDL/OgreSDLGLContext.h | 61 ++++++++ .../GLES2/include/SDL/OgreSDLGLSupport.h | 65 ++++++++ .../GLES2/include/SDL/OgreSDLWindow.h | 79 ++++++++++ .../GLES2/src/SDL/OgreSDLGLContext.cpp | 97 ++++++++++++ .../GLES2/src/SDL/OgreSDLGLSupport.cpp | 141 +++++++++++++++++ RenderSystems/GLES2/src/SDL/OgreSDLWindow.cpp | 143 ++++++++++++++++++ 9 files changed, 645 insertions(+) create mode 100644 RenderSystems/GLES2/include/SDL/OgreGLES2Util.h create mode 100644 RenderSystems/GLES2/include/SDL/OgreSDLGLContext.h create mode 100644 RenderSystems/GLES2/include/SDL/OgreSDLGLSupport.h create mode 100644 RenderSystems/GLES2/include/SDL/OgreSDLWindow.h create mode 100644 RenderSystems/GLES2/src/SDL/OgreSDLGLContext.cpp create mode 100644 RenderSystems/GLES2/src/SDL/OgreSDLGLSupport.cpp create mode 100644 RenderSystems/GLES2/src/SDL/OgreSDLWindow.cpp 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..76dd757ac --- /dev/null +++ b/RenderSystems/GLES2/include/SDL/OgreSDLGLSupport.h @@ -0,0 +1,65 @@ +/* +----------------------------------------------------------------------------- +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" + +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..fa01433ec --- /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 _OgrePrivate SDLWindow : public RenderWindow + { + protected: + SDLGLSupport* mGLSupport; + SDLGLContext* mContext; + bool mClosed; + + void getLeftAndTopFromNativeWindow(int & left, int & top, uint width, uint height); + void initNativeCreatedWindow(const NameValuePairList *miscParams); + void createNativeWindow( int &left, int &top, uint &width, uint &height, String &title ); + void reposition(int left, int top); + void resize(unsigned int width, unsigned int height); + void windowMovedOrResized(); + void switchFullScreen(bool fullscreen); + + + public: + 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; + + 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/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/GLES2/src/SDL/OgreSDLGLSupport.cpp b/RenderSystems/GLES2/src/SDL/OgreSDLGLSupport.cpp new file mode 100644 index 000000000..ed1e1c6c9 --- /dev/null +++ b/RenderSystems/GLES2/src/SDL/OgreSDLGLSupport.cpp @@ -0,0 +1,141 @@ +/* +----------------------------------------------------------------------------- +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 "OgreException.h" +#include "OgreLogManager.h" +#include "OgreStringConverter.h" +#include "OgreRoot.h" + +#include "OgreGLES2Prerequisites.h" +#include "OgreGLES2RenderSystem.h" + +#include "OgreSDLGLSupport.h" +#include "OgreSDLWindow.h" +#include "OgreSDLGLContext.h" + +namespace Ogre { + + SDLGLSupport::SDLGLSupport() + { + } + + SDLGLSupport::~SDLGLSupport() + { + } + + String SDLGLSupport::getDisplayName(void) + { + return "SDL GLES2 Support"; + } + + + void SDLGLSupport::switchMode(uint& width, uint& height, short& frequency) + { + } + + RenderWindow* SDLGLSupport::createWindow(bool autoCreateWindow, + GLES2RenderSystem *renderSystem, + const String& windowTitle) + { + LogManager::getSingleton().logMessage("\tGLSupport createWindow called"); + + RenderWindow *window = 0; + + if (autoCreateWindow) + { + ConfigOptionMap::iterator opt; + ConfigOptionMap::iterator end = mOptions.end(); + NameValuePairList miscParams; + + bool fullscreen = true; + unsigned int w = 1, h = 1; + + if ((opt = mOptions.find("Display Frequency")) != end) + { + miscParams["displayFrequency"] = opt->second.currentValue; + } + + window = renderSystem->_createRenderWindow(windowTitle, w, h, fullscreen, &miscParams); + } + + return window; + } + + RenderWindow* SDLGLSupport::newWindow(const String &name, + unsigned int width, unsigned int height, + bool fullScreen, + const NameValuePairList *miscParams) + { + LogManager::getSingleton().logMessage("\tGLSupport newWindow called"); + + SDLWindow* window = new SDLWindow(this); + window->create(name, width, height, fullScreen, miscParams); + String targetName = window->getName(); + + return window; + } + + void SDLGLSupport::start(void) + { + LogManager::getSingleton().logMessage("\tGLSupport start called"); + } + + void SDLGLSupport::stop(void) + { + LogManager::getSingleton().logMessage("\tGLSupport stop called"); + } + + void SDLGLSupport::addConfig(void) + { + LogManager::getSingleton().logMessage("\tGLSupport addConfig called"); + + // Currently no config options supported + refreshConfig(); + } + + void SDLGLSupport::refreshConfig(void) + { + } + + String SDLGLSupport::validateConfig(void) + { + return StringUtil::BLANK; + } + + void SDLGLSupport::setConfigOption(const String &name, const String &value) + { + GLES2Support::setConfigOption(name, value); + } + + void* SDLGLSupport::getProcAddress(const Ogre::String& name) + { + //return (void*)pglGetProcAddress((const char*) name.c_str()); - doesn't link + return 0; + } + +} diff --git a/RenderSystems/GLES2/src/SDL/OgreSDLWindow.cpp b/RenderSystems/GLES2/src/SDL/OgreSDLWindow.cpp new file mode 100644 index 000000000..052a1c6c2 --- /dev/null +++ b/RenderSystems/GLES2/src/SDL/OgreSDLWindow.cpp @@ -0,0 +1,143 @@ +/* +----------------------------------------------------------------------------- +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 "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 +#include +#include + +namespace Ogre { + SDLWindow::SDLWindow(SDLGLSupport *glsupport) + : mGLSupport(glsupport), mClosed(false), mContext(0) + { + } + + SDLWindow::~SDLWindow() + { + if(mContext) + delete mContext; + } + + void SDLWindow::getCustomAttribute( const String& name, void* pData ) + { + if(name == "GLCONTEXT") + { + *static_cast(pData) = mContext; + return; + } + } + + void SDLWindow::getLeftAndTopFromNativeWindow( int & left, int & top, uint width, uint height ) + { + } + + void SDLWindow::initNativeCreatedWindow(const NameValuePairList *miscParams) + { + mContext = new SDLGLContext(this, mGLSupport); + } + + void SDLWindow::createNativeWindow( int &left, int &top, uint &width, uint &height, String &title ) + { + } + + void SDLWindow::reposition( int left, int top ) + { + } + + void SDLWindow::resize(uint width, uint height) + { + mWidth = width; + mHeight = height; + + mContext->resize(); + } + + void SDLWindow::windowMovedOrResized() + { + } + + void SDLWindow::copyContentsToMemory(const PixelBox &dst, FrameBuffer buffer) + { + + } + + bool SDLWindow::requiresTextureFlipping() const + { + return false; + } + + void SDLWindow::destroy(void) + { + } + + bool SDLWindow::isClosed(void) const + { + return mClosed; + } + + void SDLWindow::create(const String& name, uint width, uint height, + bool fullScreen, const NameValuePairList *miscParams) + { + initNativeCreatedWindow(miscParams); + + mName = name; + mWidth = width; + mHeight = height; + mLeft = 0; + mTop = 0; + mActive = true; + //mVisible = true; + + mClosed = false; + } + + void SDLWindow::swapBuffers(bool waitForVSync) + { + if (mClosed) + { + return; + } + + mContext->swapBuffers(waitForVSync); + + } + + +} From 8775e3ae100f2345725191a59387d956e9dff590 Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Mon, 6 Feb 2012 19:29:57 -0500 Subject: [PATCH 11/18] Fix a typo --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1a57d5a2b..9d786857b 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -237,7 +237,7 @@ 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_APPLE_EMSCRIPTEN) +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) From c7f341ed1a2e1dcef0028b92a38ad2aa59fc9998 Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Mon, 6 Feb 2012 19:30:03 -0500 Subject: [PATCH 12/18] Hard code the paths to the library name for now THIS SUCKS, AND IT NEEDS TO BE FIXED ONCE WE FIGURE OUT WTF IS WRONG WITH CMAKE'S FIND_LIBRARY() MACRO! --- CMake/Packages/FindOIS.cmake | 4 ++++ 1 file changed, 4 insertions(+) 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}) From c682616f15575ea79d5991ac9fadc798d91068eb Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Mon, 6 Feb 2012 19:55:49 -0500 Subject: [PATCH 13/18] Force use of the internal allocator for Emscripten builds --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9d786857b..2fba5a3c5 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -241,6 +241,7 @@ 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) From 75a4d0ab99da7f6cde88823e53b6de358406d060 Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Thu, 9 Feb 2012 21:23:13 -0500 Subject: [PATCH 14/18] Move the SDL implementation files to the right place, fix missing include --- RenderSystems/GL/src/SDL/OgreSDLGLSupport.cpp | 181 ------------ RenderSystems/GL/src/SDL/OgreSDLWindow.cpp | 255 ----------------- .../GLES2/src/OgreGLES2RenderSystem.cpp | 2 + .../{GL => GLES2}/src/SDL/OgreGLUtil.h | 0 .../GLES2/src/SDL/OgreSDLGLSupport.cpp | 266 +++++++++-------- RenderSystems/GLES2/src/SDL/OgreSDLWindow.cpp | 268 +++++++++++++----- 6 files changed, 345 insertions(+), 627 deletions(-) delete mode 100644 RenderSystems/GL/src/SDL/OgreSDLGLSupport.cpp delete mode 100644 RenderSystems/GL/src/SDL/OgreSDLWindow.cpp rename RenderSystems/{GL => GLES2}/src/SDL/OgreGLUtil.h (100%) diff --git a/RenderSystems/GL/src/SDL/OgreSDLGLSupport.cpp b/RenderSystems/GL/src/SDL/OgreSDLGLSupport.cpp deleted file mode 100644 index 4fa0b643a..000000000 --- a/RenderSystems/GL/src/SDL/OgreSDLGLSupport.cpp +++ /dev/null @@ -1,181 +0,0 @@ -#include "OgreException.h" -#include "OgreLogManager.h" -#include "OgreStringConverter.h" - -#include "OgreSDLGLSupport.h" - -#include "OgreSDLWindow.h" - -using namespace Ogre; - -SDLGLSupport::SDLGLSupport() -{ - - SDL_Init(SDL_INIT_VIDEO); -} - -SDLGLSupport::~SDLGLSupport() -{ -} - -void SDLGLSupport::addConfig(void) -{ - mVideoModes = SDL_ListModes(NULL, SDL_FULLSCREEN | SDL_OPENGL); - - if (mVideoModes == (SDL_Rect **)0) - { - OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "Unable to load video modes", - "SDLRenderSystem::initConfigOptions"); - } - - ConfigOption optFullScreen; - ConfigOption optVideoMode; - ConfigOption optFSAA; - ConfigOption optRTTMode; -#ifdef RTSHADER_SYSTEM_BUILD_CORE_SHADERS - ConfigOption optEnableFixedPipeline; -#endif - - // FS setting possibilities - optFullScreen.name = "Full Screen"; - optFullScreen.possibleValues.push_back("Yes"); - optFullScreen.possibleValues.push_back("No"); - optFullScreen.currentValue = "Yes"; - optFullScreen.immutable = false; - - // 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; - } - } - - //FSAA possibilities - optFSAA.name = "FSAA"; - optFSAA.possibleValues.push_back("0"); - optFSAA.possibleValues.push_back("2"); - optFSAA.possibleValues.push_back("4"); - optFSAA.possibleValues.push_back("6"); - optFSAA.currentValue = "0"; - optFSAA.immutable = false; - - optRTTMode.name = "RTT Preferred Mode"; - optRTTMode.possibleValues.push_back("FBO"); - optRTTMode.possibleValues.push_back("PBuffer"); - optRTTMode.possibleValues.push_back("Copy"); - optRTTMode.currentValue = "FBO"; - optRTTMode.immutable = false; - -#ifdef RTSHADER_SYSTEM_BUILD_CORE_SHADERS - optEnableFixedPipeline.name = "Fixed Pipeline Enabled"; - optEnableFixedPipeline.possibleValues.push_back( "Yes" ); - optEnableFixedPipeline.possibleValues.push_back( "No" ); - optEnableFixedPipeline.currentValue = "Yes"; - optEnableFixedPipeline.immutable = false; -#endif - - mOptions[optFullScreen.name] = optFullScreen; - mOptions[optVideoMode.name] = optVideoMode; - mOptions[optFSAA.name] = optFSAA; - mOptions[optRTTMode.name] = optRTTMode; -#ifdef RTSHADER_SYSTEM_BUILD_CORE_SHADERS - mOptions[optEnableFixedPipeline.name] = optEnableFixedPipeline; -#endif - -} - -String SDLGLSupport::validateConfig(void) -{ - return String(""); -} - -RenderWindow* SDLGLSupport::createWindow(bool autoCreateWindow, GLRenderSystem* renderSystem, const String& windowTitle) -{ - if (autoCreateWindow) - { - ConfigOptionMap::iterator opt = mOptions.find("Full Screen"); - if (opt == mOptions.end()) - OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "Can't find full screen options!", "SDLGLSupport::createWindow"); - bool fullscreen = (opt->second.currentValue == "Yes"); - - opt = mOptions.find("Video Mode"); - if (opt == mOptions.end()) - OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "Can't find video mode options!", "SDLGLSupport::createWindow"); - String val = opt->second.currentValue; - String::size_type pos = val.find('x'); - if (pos == String::npos) - OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "Invalid Video Mode provided", "SDLGLSupport::createWindow"); - - // Parse FSAA config - NameValuePairList winOptions; - winOptions["title"] = windowTitle; - int fsaa_x_samples = 0; - opt = mOptions.find("FSAA"); - if(opt != mOptions.end()) - { - winOptions["FSAA"] = opt->second.currentValue; - } - -#ifdef RTSHADER_SYSTEM_BUILD_CORE_SHADERS - opt = mOptions.find("Fixed Pipeline Enabled"); - if (opt == mOptions.end()) - OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "Can't find Fixed Pipeline enabled options!", "Win32GLSupport::createWindow"); - bool enableFixedPipeline = (opt->second.currentValue == "Yes"); - renderSystem->setFixedPipelineEnabled(enableFixedPipeline); -#endif - - unsigned int w = StringConverter::parseUnsignedInt(val.substr(0, pos)); - unsigned int h = StringConverter::parseUnsignedInt(val.substr(pos + 1)); - - const SDL_VideoInfo* videoInfo = SDL_GetVideoInfo(); - return renderSystem->createRenderWindow(windowTitle, w, h, fullscreen, &winOptions); - } - else - { - // XXX What is the else? - return NULL; - } - -} - - -RenderWindow* SDLGLSupport::newWindow(const String &name, unsigned int width, unsigned int height, - bool fullScreen, const NameValuePairList *miscParams) -{ - SDLWindow* window = new SDLWindow(); - window->create(name, width, height, fullScreen, miscParams); - return window; -} - -void SDLGLSupport::start() -{ - LogManager::getSingleton().logMessage( - "******************************\n" - "*** Starting SDL Subsystem ***\n" - "******************************"); - - SDL_Init(SDL_INIT_VIDEO); -} - -void SDLGLSupport::stop() -{ - LogManager::getSingleton().logMessage( - "******************************\n" - "*** Stopping SDL Subsystem ***\n" - "******************************"); - - SDL_Quit(); -} - -void* SDLGLSupport::getProcAddress(const String& procname) -{ - return SDL_GL_GetProcAddress(procname.c_str()); -} diff --git a/RenderSystems/GL/src/SDL/OgreSDLWindow.cpp b/RenderSystems/GL/src/SDL/OgreSDLWindow.cpp deleted file mode 100644 index 721be1be0..000000000 --- a/RenderSystems/GL/src/SDL/OgreSDLWindow.cpp +++ /dev/null @@ -1,255 +0,0 @@ -/* ------------------------------------------------------------------------------ -This source file is part of OGRE - (Object-oriented Graphics Rendering Engine) -For the latest info, see http://www.ogre3d.org/ - -Copyright (c) 2000-2011 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 "OgreSDLWindow.h" -#include "OgreRoot.h" -#include "OgreRenderSystem.h" -#include "OgreImageCodec.h" -#include "OgreException.h" -#include "OgreLogManager.h" -#include "OgreStringConverter.h" - -#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 -# include -# include -# include -# define GL_GLEXT_PROTOTYPES -# include "glprocs.h" -# include -#elif OGRE_PLATFORM == OGRE_PLATFORM_LINUX -# include -# include -#elif OGRE_PLATFORM == OGRE_PLATFORM_APPLE -# include -# define GL_EXT_texture_env_combine 1 -# include -# include -#endif - -namespace Ogre { - - SDLWindow::SDLWindow() : - mScreen(NULL), mActive(false), mClosed(false) - { - } - - SDLWindow::~SDLWindow() - { - // according to http://www.libsdl.org/cgi/docwiki.cgi/SDL_5fSetVideoMode - // never free the surface returned from SDL_SetVideoMode - /*if (mScreen != NULL) - SDL_FreeSurface(mScreen);*/ - - } - - void SDLWindow::create(const String& name, unsigned int width, unsigned int height, - bool fullScreen, const NameValuePairList *miscParams) - { - int colourDepth = 32; - String title = name; - if(miscParams) - { - // Parse miscellenous parameters - NameValuePairList::const_iterator opt; - // Bit depth - opt = miscParams->find("colourDepth"); - if(opt != miscParams->end()) //check for FSAA parameter, if not ignore it... - colourDepth = StringConverter::parseUnsignedInt(opt->second); - // Full screen antialiasing - opt = miscParams->find("FSAA"); - if(opt != miscParams->end()) //check for FSAA parameter, if not ignore it... - { - size_t fsaa_x_samples = StringConverter::parseUnsignedInt(opt->second); - if(fsaa_x_samples>1) { - // If FSAA is enabled in the parameters, enable the MULTISAMPLEBUFFERS - // and set the number of samples before the render window is created. - SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS,1); - SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES,fsaa_x_samples); - } - } - // Window title - opt = miscParams->find("title"); - if(opt != miscParams->end()) //check for FSAA parameter, if not ignore it... - title = opt->second; - } - - LogManager::getSingleton().logMessage("SDLWindow::create", LML_TRIVIAL); - SDL_Surface* screen; - int flags = SDL_OPENGL | SDL_HWPALETTE | SDL_RESIZABLE; - - SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); - // request good stencil size if 32-bit colour - if (colourDepth == 32) - { - SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE, 8); - } - - if (fullScreen) - flags |= SDL_FULLSCREEN; - - LogManager::getSingleton().logMessage("Create window", LML_TRIVIAL); - screen = SDL_SetVideoMode(width, height, colourDepth, flags); - if (!screen) - { - LogManager::getSingleton().logMessage(LML_CRITICAL, - String("Could not make screen: ") + SDL_GetError()); - exit(1); - } - LogManager::getSingleton().logMessage("screen is valid", LML_TRIVIAL); - mScreen = screen; - - mName = name; - - mWidth = width; - mHeight = height; - - mActive = true; - - 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) - { - // according to http://www.libsdl.org/cgi/docwiki.cgi/SDL_5fSetVideoMode - // never free the surface returned from SDL_SetVideoMode - //SDL_FreeSurface(mScreen); - mScreen = NULL; - mActive = false; - - Root::getSingleton().getRenderSystem()->detachRenderTarget( this->getName() ); - } - - bool SDLWindow::isActive() const - { - return mActive; - } - - bool SDLWindow::isClosed() const - { - return mClosed; - } - - void SDLWindow::reposition(int left, int top) - { - // XXX FIXME - } - - void SDLWindow::resize(unsigned int width, unsigned int height) - { - SDL_Surface* screen; - int flags = SDL_OPENGL | SDL_HWPALETTE | SDL_RESIZABLE; - - LogManager::getSingleton().logMessage("Updating window", LML_TRIVIAL); - screen = SDL_SetVideoMode(width, height, mScreen->format->BitsPerPixel, flags); - if (!screen) - { - LogManager::getSingleton().logMessage(LML_CRITICAL, - String("Could not make screen: ") + SDL_GetError()); - exit(1); - } - LogManager::getSingleton().logMessage("screen is valid", LML_TRIVIAL); - mScreen = screen; - - - mWidth = width; - mHeight = height; - - for (ViewportList::iterator it = mViewportList.begin(); - it != mViewportList.end(); ++it) - { - (*it).second->_updateDimensions(); - } - } - - 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? - } - - void SDLWindow::copyContentsToMemory(const PixelBox &dst, FrameBuffer buffer) - { - if ((dst.left < 0) || (dst.right > mWidth) || - (dst.top < 0) || (dst.bottom > mHeight) || - (dst.front != 0) || (dst.back != 1)) - { - OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, - "Invalid box.", - "SDLWindow::copyContentsToMemory" ); - } - - if (buffer == FB_AUTO) - { - buffer = mIsFullScreen? FB_FRONT : FB_BACK; - } - - GLenum format = Ogre::GLPixelUtil::getGLOriginFormat(dst.format); - GLenum type = Ogre::GLPixelUtil::getGLOriginDataType(dst.format); - - if ((format == GL_NONE) || (type == 0)) - { - OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, - "Unsupported format.", - "SDLWindow::copyContentsToMemory" ); - } - - 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); - - //vertical flip - { - size_t rowSpan = dst.getWidth() * PixelUtil::getNumElemBytes(dst.format); - size_t height = dst.getHeight(); - uchar *tmpData = new uchar[rowSpan * height]; - uchar *srcRow = (uchar *)dst.data, *tmpRow = tmpData + (height - 1) * rowSpan; - - while (tmpRow >= tmpData) - { - memcpy(tmpRow, srcRow, rowSpan); - srcRow += rowSpan; - tmpRow -= rowSpan; - } - memcpy(dst.data, tmpData, rowSpan * height); - - delete [] tmpData; - } - } -} 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/OgreSDLGLSupport.cpp b/RenderSystems/GLES2/src/SDL/OgreSDLGLSupport.cpp index ed1e1c6c9..4fa0b643a 100644 --- a/RenderSystems/GLES2/src/SDL/OgreSDLGLSupport.cpp +++ b/RenderSystems/GLES2/src/SDL/OgreSDLGLSupport.cpp @@ -1,141 +1,181 @@ -/* ------------------------------------------------------------------------------ -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 "OgreException.h" #include "OgreLogManager.h" #include "OgreStringConverter.h" -#include "OgreRoot.h" - -#include "OgreGLES2Prerequisites.h" -#include "OgreGLES2RenderSystem.h" #include "OgreSDLGLSupport.h" + #include "OgreSDLWindow.h" -#include "OgreSDLGLContext.h" -namespace Ogre { +using namespace Ogre; - SDLGLSupport::SDLGLSupport() +SDLGLSupport::SDLGLSupport() +{ + + SDL_Init(SDL_INIT_VIDEO); +} + +SDLGLSupport::~SDLGLSupport() +{ +} + +void SDLGLSupport::addConfig(void) +{ + mVideoModes = SDL_ListModes(NULL, SDL_FULLSCREEN | SDL_OPENGL); + + if (mVideoModes == (SDL_Rect **)0) { + OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "Unable to load video modes", + "SDLRenderSystem::initConfigOptions"); } - SDLGLSupport::~SDLGLSupport() + ConfigOption optFullScreen; + ConfigOption optVideoMode; + ConfigOption optFSAA; + ConfigOption optRTTMode; +#ifdef RTSHADER_SYSTEM_BUILD_CORE_SHADERS + ConfigOption optEnableFixedPipeline; +#endif + + // FS setting possibilities + optFullScreen.name = "Full Screen"; + optFullScreen.possibleValues.push_back("Yes"); + optFullScreen.possibleValues.push_back("No"); + optFullScreen.currentValue = "Yes"; + optFullScreen.immutable = false; + + // 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; + } } + + //FSAA possibilities + optFSAA.name = "FSAA"; + optFSAA.possibleValues.push_back("0"); + optFSAA.possibleValues.push_back("2"); + optFSAA.possibleValues.push_back("4"); + optFSAA.possibleValues.push_back("6"); + optFSAA.currentValue = "0"; + optFSAA.immutable = false; + + optRTTMode.name = "RTT Preferred Mode"; + optRTTMode.possibleValues.push_back("FBO"); + optRTTMode.possibleValues.push_back("PBuffer"); + optRTTMode.possibleValues.push_back("Copy"); + optRTTMode.currentValue = "FBO"; + optRTTMode.immutable = false; + +#ifdef RTSHADER_SYSTEM_BUILD_CORE_SHADERS + optEnableFixedPipeline.name = "Fixed Pipeline Enabled"; + optEnableFixedPipeline.possibleValues.push_back( "Yes" ); + optEnableFixedPipeline.possibleValues.push_back( "No" ); + optEnableFixedPipeline.currentValue = "Yes"; + optEnableFixedPipeline.immutable = false; +#endif + + mOptions[optFullScreen.name] = optFullScreen; + mOptions[optVideoMode.name] = optVideoMode; + mOptions[optFSAA.name] = optFSAA; + mOptions[optRTTMode.name] = optRTTMode; +#ifdef RTSHADER_SYSTEM_BUILD_CORE_SHADERS + mOptions[optEnableFixedPipeline.name] = optEnableFixedPipeline; +#endif + +} + +String SDLGLSupport::validateConfig(void) +{ + return String(""); +} - String SDLGLSupport::getDisplayName(void) +RenderWindow* SDLGLSupport::createWindow(bool autoCreateWindow, GLRenderSystem* renderSystem, const String& windowTitle) +{ + if (autoCreateWindow) { - return "SDL GLES2 Support"; - } + ConfigOptionMap::iterator opt = mOptions.find("Full Screen"); + if (opt == mOptions.end()) + OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "Can't find full screen options!", "SDLGLSupport::createWindow"); + bool fullscreen = (opt->second.currentValue == "Yes"); + + opt = mOptions.find("Video Mode"); + if (opt == mOptions.end()) + OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "Can't find video mode options!", "SDLGLSupport::createWindow"); + String val = opt->second.currentValue; + String::size_type pos = val.find('x'); + if (pos == String::npos) + OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, "Invalid Video Mode provided", "SDLGLSupport::createWindow"); + + // Parse FSAA config + NameValuePairList winOptions; + winOptions["title"] = windowTitle; + int fsaa_x_samples = 0; + opt = mOptions.find("FSAA"); + if(opt != mOptions.end()) + { + winOptions["FSAA"] = opt->second.currentValue; + } + +#ifdef RTSHADER_SYSTEM_BUILD_CORE_SHADERS + opt = mOptions.find("Fixed Pipeline Enabled"); + if (opt == mOptions.end()) + OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "Can't find Fixed Pipeline enabled options!", "Win32GLSupport::createWindow"); + bool enableFixedPipeline = (opt->second.currentValue == "Yes"); + renderSystem->setFixedPipelineEnabled(enableFixedPipeline); +#endif + unsigned int w = StringConverter::parseUnsignedInt(val.substr(0, pos)); + unsigned int h = StringConverter::parseUnsignedInt(val.substr(pos + 1)); - void SDLGLSupport::switchMode(uint& width, uint& height, short& frequency) + const SDL_VideoInfo* videoInfo = SDL_GetVideoInfo(); + return renderSystem->createRenderWindow(windowTitle, w, h, fullscreen, &winOptions); + } + else { + // XXX What is the else? + return NULL; } - RenderWindow* SDLGLSupport::createWindow(bool autoCreateWindow, - GLES2RenderSystem *renderSystem, - const String& windowTitle) - { - LogManager::getSingleton().logMessage("\tGLSupport createWindow called"); - - RenderWindow *window = 0; +} - if (autoCreateWindow) - { - ConfigOptionMap::iterator opt; - ConfigOptionMap::iterator end = mOptions.end(); - NameValuePairList miscParams; - bool fullscreen = true; - unsigned int w = 1, h = 1; +RenderWindow* SDLGLSupport::newWindow(const String &name, unsigned int width, unsigned int height, + bool fullScreen, const NameValuePairList *miscParams) +{ + SDLWindow* window = new SDLWindow(); + window->create(name, width, height, fullScreen, miscParams); + return window; +} - if ((opt = mOptions.find("Display Frequency")) != end) - { - miscParams["displayFrequency"] = opt->second.currentValue; - } +void SDLGLSupport::start() +{ + LogManager::getSingleton().logMessage( + "******************************\n" + "*** Starting SDL Subsystem ***\n" + "******************************"); - window = renderSystem->_createRenderWindow(windowTitle, w, h, fullscreen, &miscParams); - } + SDL_Init(SDL_INIT_VIDEO); +} - return window; - } +void SDLGLSupport::stop() +{ + LogManager::getSingleton().logMessage( + "******************************\n" + "*** Stopping SDL Subsystem ***\n" + "******************************"); - RenderWindow* SDLGLSupport::newWindow(const String &name, - unsigned int width, unsigned int height, - bool fullScreen, - const NameValuePairList *miscParams) - { - LogManager::getSingleton().logMessage("\tGLSupport newWindow called"); - - SDLWindow* window = new SDLWindow(this); - window->create(name, width, height, fullScreen, miscParams); - String targetName = window->getName(); + SDL_Quit(); +} - return window; - } - - void SDLGLSupport::start(void) - { - LogManager::getSingleton().logMessage("\tGLSupport start called"); - } - - void SDLGLSupport::stop(void) - { - LogManager::getSingleton().logMessage("\tGLSupport stop called"); - } - - void SDLGLSupport::addConfig(void) - { - LogManager::getSingleton().logMessage("\tGLSupport addConfig called"); - - // Currently no config options supported - refreshConfig(); - } - - void SDLGLSupport::refreshConfig(void) - { - } - - String SDLGLSupport::validateConfig(void) - { - return StringUtil::BLANK; - } - - void SDLGLSupport::setConfigOption(const String &name, const String &value) - { - GLES2Support::setConfigOption(name, value); - } - - void* SDLGLSupport::getProcAddress(const Ogre::String& name) - { - //return (void*)pglGetProcAddress((const char*) name.c_str()); - doesn't link - return 0; - } - +void* SDLGLSupport::getProcAddress(const String& procname) +{ + return SDL_GL_GetProcAddress(procname.c_str()); } diff --git a/RenderSystems/GLES2/src/SDL/OgreSDLWindow.cpp b/RenderSystems/GLES2/src/SDL/OgreSDLWindow.cpp index 052a1c6c2..721be1be0 100644 --- a/RenderSystems/GLES2/src/SDL/OgreSDLWindow.cpp +++ b/RenderSystems/GLES2/src/SDL/OgreSDLWindow.cpp @@ -4,7 +4,7 @@ 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 +Copyright (c) 2000-2011 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 @@ -26,118 +26,230 @@ THE SOFTWARE. ----------------------------------------------------------------------------- */ +#include "OgreSDLWindow.h" #include "OgreRoot.h" +#include "OgreRenderSystem.h" +#include "OgreImageCodec.h" #include "OgreException.h" #include "OgreLogManager.h" #include "OgreStringConverter.h" -#include "OgreWindowEventUtilities.h" -#include "OgreGLES2Prerequisites.h" -#include "OgreGLES2RenderSystem.h" +#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 +# include +# include +# include +# define GL_GLEXT_PROTOTYPES +# include "glprocs.h" +# include +#elif OGRE_PLATFORM == OGRE_PLATFORM_LINUX +# include +# include +#elif OGRE_PLATFORM == OGRE_PLATFORM_APPLE +# include +# define GL_EXT_texture_env_combine 1 +# include +# include +#endif -#include "OgreSDLGLSupport.h" -#include "OgreSDLWindow.h" -#include "OgreSDLGLContext.h" +namespace Ogre { -#include -#include -#include + SDLWindow::SDLWindow() : + mScreen(NULL), mActive(false), mClosed(false) + { + } -namespace Ogre { - SDLWindow::SDLWindow(SDLGLSupport *glsupport) - : mGLSupport(glsupport), mClosed(false), mContext(0) - { - } + SDLWindow::~SDLWindow() + { + // according to http://www.libsdl.org/cgi/docwiki.cgi/SDL_5fSetVideoMode + // never free the surface returned from SDL_SetVideoMode + /*if (mScreen != NULL) + SDL_FreeSurface(mScreen);*/ - SDLWindow::~SDLWindow() - { - if(mContext) - delete mContext; - } + } - void SDLWindow::getCustomAttribute( const String& name, void* pData ) - { - if(name == "GLCONTEXT") + void SDLWindow::create(const String& name, unsigned int width, unsigned int height, + bool fullScreen, const NameValuePairList *miscParams) + { + int colourDepth = 32; + String title = name; + if(miscParams) + { + // Parse miscellenous parameters + NameValuePairList::const_iterator opt; + // Bit depth + opt = miscParams->find("colourDepth"); + if(opt != miscParams->end()) //check for FSAA parameter, if not ignore it... + colourDepth = StringConverter::parseUnsignedInt(opt->second); + // Full screen antialiasing + opt = miscParams->find("FSAA"); + if(opt != miscParams->end()) //check for FSAA parameter, if not ignore it... + { + size_t fsaa_x_samples = StringConverter::parseUnsignedInt(opt->second); + if(fsaa_x_samples>1) { + // If FSAA is enabled in the parameters, enable the MULTISAMPLEBUFFERS + // and set the number of samples before the render window is created. + SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS,1); + SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES,fsaa_x_samples); + } + } + // Window title + opt = miscParams->find("title"); + if(opt != miscParams->end()) //check for FSAA parameter, if not ignore it... + title = opt->second; + } + + LogManager::getSingleton().logMessage("SDLWindow::create", LML_TRIVIAL); + SDL_Surface* screen; + int flags = SDL_OPENGL | SDL_HWPALETTE | SDL_RESIZABLE; + + SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); + // request good stencil size if 32-bit colour + if (colourDepth == 32) { - *static_cast(pData) = mContext; - return; + SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE, 8); } - } + + if (fullScreen) + flags |= SDL_FULLSCREEN; - void SDLWindow::getLeftAndTopFromNativeWindow( int & left, int & top, uint width, uint height ) - { - } + LogManager::getSingleton().logMessage("Create window", LML_TRIVIAL); + screen = SDL_SetVideoMode(width, height, colourDepth, flags); + if (!screen) + { + LogManager::getSingleton().logMessage(LML_CRITICAL, + String("Could not make screen: ") + SDL_GetError()); + exit(1); + } + LogManager::getSingleton().logMessage("screen is valid", LML_TRIVIAL); + mScreen = screen; - void SDLWindow::initNativeCreatedWindow(const NameValuePairList *miscParams) - { - mContext = new SDLGLContext(this, mGLSupport); - } + mName = name; - void SDLWindow::createNativeWindow( int &left, int &top, uint &width, uint &height, String &title ) - { - } + mWidth = width; + mHeight = height; - void SDLWindow::reposition( int left, int top ) - { - } + mActive = true; - void SDLWindow::resize(uint width, uint height) - { - mWidth = width; - mHeight = height; + if (!fullScreen) + SDL_WM_SetCaption(title.c_str(), 0); - mContext->resize(); - } + glXGetVideoSyncSGI = (int (*)(unsigned int *))SDL_GL_GetProcAddress("glXGetVideoSyncSGI"); + glXWaitVideoSyncSGI = (int (*)(int, int, unsigned int *))SDL_GL_GetProcAddress("glXWaitVideoSyncSGI"); + } - void SDLWindow::windowMovedOrResized() - { - } + void SDLWindow::destroy(void) + { + // according to http://www.libsdl.org/cgi/docwiki.cgi/SDL_5fSetVideoMode + // never free the surface returned from SDL_SetVideoMode + //SDL_FreeSurface(mScreen); + mScreen = NULL; + mActive = false; - void SDLWindow::copyContentsToMemory(const PixelBox &dst, FrameBuffer buffer) - { - - } + Root::getSingleton().getRenderSystem()->detachRenderTarget( this->getName() ); + } - bool SDLWindow::requiresTextureFlipping() const - { - return false; - } + bool SDLWindow::isActive() const + { + return mActive; + } - void SDLWindow::destroy(void) - { - } + bool SDLWindow::isClosed() const + { + return mClosed; + } - bool SDLWindow::isClosed(void) const - { - return mClosed; - } + void SDLWindow::reposition(int left, int top) + { + // XXX FIXME + } - void SDLWindow::create(const String& name, uint width, uint height, - bool fullScreen, const NameValuePairList *miscParams) + void SDLWindow::resize(unsigned int width, unsigned int height) { - initNativeCreatedWindow(miscParams); + SDL_Surface* screen; + int flags = SDL_OPENGL | SDL_HWPALETTE | SDL_RESIZABLE; + + LogManager::getSingleton().logMessage("Updating window", LML_TRIVIAL); + screen = SDL_SetVideoMode(width, height, mScreen->format->BitsPerPixel, flags); + if (!screen) + { + LogManager::getSingleton().logMessage(LML_CRITICAL, + String("Could not make screen: ") + SDL_GetError()); + exit(1); + } + LogManager::getSingleton().logMessage("screen is valid", LML_TRIVIAL); + mScreen = screen; + - mName = name; mWidth = width; mHeight = height; - mLeft = 0; - mTop = 0; - mActive = true; - //mVisible = true; - mClosed = false; - } + for (ViewportList::iterator it = mViewportList.begin(); + it != mViewportList.end(); ++it) + { + (*it).second->_updateDimensions(); + } + } void SDLWindow::swapBuffers(bool waitForVSync) { - if (mClosed) + if ( waitForVSync && glXGetVideoSyncSGI && glXWaitVideoSyncSGI ) { - return; + unsigned int retraceCount; + glXGetVideoSyncSGI( &retraceCount ); + glXWaitVideoSyncSGI( 2, ( retraceCount + 1 ) & 1, &retraceCount); } - mContext->swapBuffers(waitForVSync); - + SDL_GL_SwapBuffers(); + // XXX More? } - + void SDLWindow::copyContentsToMemory(const PixelBox &dst, FrameBuffer buffer) + { + if ((dst.left < 0) || (dst.right > mWidth) || + (dst.top < 0) || (dst.bottom > mHeight) || + (dst.front != 0) || (dst.back != 1)) + { + OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, + "Invalid box.", + "SDLWindow::copyContentsToMemory" ); + } + + if (buffer == FB_AUTO) + { + buffer = mIsFullScreen? FB_FRONT : FB_BACK; + } + + GLenum format = Ogre::GLPixelUtil::getGLOriginFormat(dst.format); + GLenum type = Ogre::GLPixelUtil::getGLOriginDataType(dst.format); + + if ((format == GL_NONE) || (type == 0)) + { + OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, + "Unsupported format.", + "SDLWindow::copyContentsToMemory" ); + } + + 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); + + //vertical flip + { + size_t rowSpan = dst.getWidth() * PixelUtil::getNumElemBytes(dst.format); + size_t height = dst.getHeight(); + uchar *tmpData = new uchar[rowSpan * height]; + uchar *srcRow = (uchar *)dst.data, *tmpRow = tmpData + (height - 1) * rowSpan; + + while (tmpRow >= tmpData) + { + memcpy(tmpRow, srcRow, rowSpan); + srcRow += rowSpan; + tmpRow -= rowSpan; + } + memcpy(dst.data, tmpData, rowSpan * height); + + delete [] tmpData; + } + } } From 2de8e470432d78762586783eea948f13e987d837 Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Thu, 9 Feb 2012 22:18:19 -0500 Subject: [PATCH 15/18] Fix build problems --- .../GLES2/include/SDL/OgreSDLGLSupport.h | 1 + .../GLES2/include/SDL/OgreSDLWindow.h | 6 ++- .../GLES2/src/SDL/OgreSDLGLSupport.cpp | 44 +++++++++++-------- RenderSystems/GLES2/src/SDL/OgreSDLWindow.cpp | 22 +++------- 4 files changed, 39 insertions(+), 34 deletions(-) diff --git a/RenderSystems/GLES2/include/SDL/OgreSDLGLSupport.h b/RenderSystems/GLES2/include/SDL/OgreSDLGLSupport.h index 76dd757ac..a09b162ea 100644 --- a/RenderSystems/GLES2/include/SDL/OgreSDLGLSupport.h +++ b/RenderSystems/GLES2/include/SDL/OgreSDLGLSupport.h @@ -30,6 +30,7 @@ THE SOFTWARE. #define __SDLGLSupport_H__ #include "OgreGLES2Support.h" +#include "OgreSDLWindow.h" namespace Ogre { class GLES2PBuffer; diff --git a/RenderSystems/GLES2/include/SDL/OgreSDLWindow.h b/RenderSystems/GLES2/include/SDL/OgreSDLWindow.h index fa01433ec..9cd2defca 100644 --- a/RenderSystems/GLES2/include/SDL/OgreSDLWindow.h +++ b/RenderSystems/GLES2/include/SDL/OgreSDLWindow.h @@ -33,6 +33,7 @@ THE SOFTWARE. namespace Ogre { class SDLGLContext; + class SDLGLSupport; class _OgrePrivate SDLWindow : public RenderWindow @@ -41,6 +42,8 @@ namespace Ogre { SDLGLSupport* mGLSupport; SDLGLContext* mContext; bool mClosed; + bool mActive; + SDL_Surface* mScreen; void getLeftAndTopFromNativeWindow(int & left, int & top, uint width, uint height); void initNativeCreatedWindow(const NameValuePairList *miscParams); @@ -52,7 +55,7 @@ namespace Ogre { public: - SDLWindow(SDLGLSupport* glsupport); + explicit SDLWindow(SDLGLSupport* glsupport); virtual ~SDLWindow(); /** @@ -67,6 +70,7 @@ namespace Ogre { bool requiresTextureFlipping() const; void destroy(void); bool isClosed(void) const; + bool isActive(void) const; void swapBuffers(bool waitForVSync); diff --git a/RenderSystems/GLES2/src/SDL/OgreSDLGLSupport.cpp b/RenderSystems/GLES2/src/SDL/OgreSDLGLSupport.cpp index 4fa0b643a..55a15746f 100644 --- a/RenderSystems/GLES2/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"); @@ -44,18 +46,20 @@ void SDLGLSupport::addConfig(void) optFullScreen.immutable = false; // 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 + optVideoMode.name = "Video Mode"; + optVideoMode.immutable = false; + 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; + } + } } //FSAA possibilities @@ -83,7 +87,9 @@ void SDLGLSupport::addConfig(void) #endif mOptions[optFullScreen.name] = optFullScreen; - mOptions[optVideoMode.name] = optVideoMode; + if (videoModes != (SDL_Rect**)-1) { + mOptions[optVideoMode.name] = optVideoMode; + } mOptions[optFSAA.name] = optFSAA; mOptions[optRTTMode.name] = optRTTMode; #ifdef RTSHADER_SYSTEM_BUILD_CORE_SHADERS @@ -97,8 +103,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 +143,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 +157,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/GLES2/src/SDL/OgreSDLWindow.cpp b/RenderSystems/GLES2/src/SDL/OgreSDLWindow.cpp index 721be1be0..1bd49c0be 100644 --- a/RenderSystems/GLES2/src/SDL/OgreSDLWindow.cpp +++ b/RenderSystems/GLES2/src/SDL/OgreSDLWindow.cpp @@ -33,6 +33,7 @@ THE SOFTWARE. #include "OgreException.h" #include "OgreLogManager.h" #include "OgreStringConverter.h" +#include "OgreGLES2PixelFormat.h" #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 # include @@ -53,8 +54,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) { } @@ -132,9 +134,6 @@ namespace Ogre { 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) @@ -192,13 +191,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 +211,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 +221,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); From 9e4c68ccf568e73de9c64771fc65a3919c74be48 Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Thu, 9 Feb 2012 22:40:53 -0500 Subject: [PATCH 16/18] Make sure to default to a sane video mode --- RenderSystems/GLES2/src/SDL/OgreSDLGLSupport.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/RenderSystems/GLES2/src/SDL/OgreSDLGLSupport.cpp b/RenderSystems/GLES2/src/SDL/OgreSDLGLSupport.cpp index 55a15746f..8f1bef596 100644 --- a/RenderSystems/GLES2/src/SDL/OgreSDLGLSupport.cpp +++ b/RenderSystems/GLES2/src/SDL/OgreSDLGLSupport.cpp @@ -46,9 +46,9 @@ void SDLGLSupport::addConfig(void) optFullScreen.immutable = false; // Video mode possibilities + optVideoMode.name = "Video Mode"; + optVideoMode.immutable = false; if (videoModes != (SDL_Rect**)-1) { // All resolutions - optVideoMode.name = "Video Mode"; - optVideoMode.immutable = false; for (size_t i = 0; videoModes[i]; i++) { char szBuf[16]; @@ -60,6 +60,9 @@ void SDLGLSupport::addConfig(void) optVideoMode.currentValue = szBuf; } } + } else { + optVideoMode.possibleValues.push_back("640 x 480"); + optVideoMode.currentValue = "640 x 480"; } //FSAA possibilities @@ -87,9 +90,7 @@ void SDLGLSupport::addConfig(void) #endif mOptions[optFullScreen.name] = optFullScreen; - if (videoModes != (SDL_Rect**)-1) { - mOptions[optVideoMode.name] = optVideoMode; - } + mOptions[optVideoMode.name] = optVideoMode; mOptions[optFSAA.name] = optFSAA; mOptions[optRTTMode.name] = optRTTMode; #ifdef RTSHADER_SYSTEM_BUILD_CORE_SHADERS From 6727df7b3d22ceeee42660e3b623278e15a2dcc5 Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Fri, 10 Feb 2012 19:37:12 -0500 Subject: [PATCH 17/18] Fix build errors --- .../GLES2/include/SDL/OgreSDLWindow.h | 4 ---- RenderSystems/GLES2/src/SDL/OgreSDLWindow.cpp | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/RenderSystems/GLES2/include/SDL/OgreSDLWindow.h b/RenderSystems/GLES2/include/SDL/OgreSDLWindow.h index 9cd2defca..0d8b3f273 100644 --- a/RenderSystems/GLES2/include/SDL/OgreSDLWindow.h +++ b/RenderSystems/GLES2/include/SDL/OgreSDLWindow.h @@ -45,13 +45,9 @@ namespace Ogre { bool mActive; SDL_Surface* mScreen; - void getLeftAndTopFromNativeWindow(int & left, int & top, uint width, uint height); - void initNativeCreatedWindow(const NameValuePairList *miscParams); - void createNativeWindow( int &left, int &top, uint &width, uint &height, String &title ); void reposition(int left, int top); void resize(unsigned int width, unsigned int height); void windowMovedOrResized(); - void switchFullScreen(bool fullscreen); public: diff --git a/RenderSystems/GLES2/src/SDL/OgreSDLWindow.cpp b/RenderSystems/GLES2/src/SDL/OgreSDLWindow.cpp index 1bd49c0be..16241493b 100644 --- a/RenderSystems/GLES2/src/SDL/OgreSDLWindow.cpp +++ b/RenderSystems/GLES2/src/SDL/OgreSDLWindow.cpp @@ -69,6 +69,15 @@ namespace Ogre { } + 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) { @@ -162,6 +171,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; @@ -244,4 +258,9 @@ namespace Ogre { delete [] tmpData; } } + +bool SDLWindow::requiresTextureFlipping() const +{ + return false; +} } From e918ec2ef97f032e34e3f2bfc482cc0ddcb48abc Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Tue, 14 Feb 2012 11:44:00 -0500 Subject: [PATCH 18/18] Setup the context inside SDLWindow --- RenderSystems/GLES2/src/SDL/OgreSDLWindow.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/RenderSystems/GLES2/src/SDL/OgreSDLWindow.cpp b/RenderSystems/GLES2/src/SDL/OgreSDLWindow.cpp index 16241493b..022d9bb9f 100644 --- a/RenderSystems/GLES2/src/SDL/OgreSDLWindow.cpp +++ b/RenderSystems/GLES2/src/SDL/OgreSDLWindow.cpp @@ -34,6 +34,7 @@ THE SOFTWARE. #include "OgreLogManager.h" #include "OgreStringConverter.h" #include "OgreGLES2PixelFormat.h" +#include "OgreSDLGLContext.h" #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 # include @@ -56,7 +57,7 @@ namespace Ogre { SDLWindow::SDLWindow(SDLGLSupport* glSupport) : mScreen(NULL), mActive(false), mClosed(false), - mGLSupport(glSupport) + mGLSupport(glSupport), mContext(0) { } @@ -67,6 +68,8 @@ namespace Ogre { /*if (mScreen != NULL) SDL_FreeSurface(mScreen);*/ + if (mContext) + delete mContext; } void SDLWindow::getCustomAttribute( const String& name, void* pData ) @@ -141,6 +144,8 @@ namespace Ogre { mActive = true; + mContext = new SDLGLContext(this, mGLSupport); + if (!fullScreen) SDL_WM_SetCaption(title.c_str(), 0); }