From 50e5aa897648246c253b59313a288c294faf9f12 Mon Sep 17 00:00:00 2001 From: Nikolay Kasyanov Date: Sun, 16 Jun 2013 16:25:13 +0400 Subject: [PATCH] Custom rendering loop on OS X again. Prevents default Ogre message pump from stealing input events. --- libs/openengine/ogre/renderer.cpp | 34 ++++++++++++++++++++++++++++++- libs/openengine/ogre/renderer.hpp | 21 +++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/libs/openengine/ogre/renderer.cpp b/libs/openengine/ogre/renderer.cpp index e3bba8bfa2..72a02142f4 100644 --- a/libs/openengine/ogre/renderer.cpp +++ b/libs/openengine/ogre/renderer.cpp @@ -23,13 +23,29 @@ #include #include -#ifdef __MACOSX__ +#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE #include "osx_utils.h" #endif using namespace Ogre; using namespace OEngine::Render; + +#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE + +CustomRoot::CustomRoot(const Ogre::String& pluginFileName, + const Ogre::String& configFileName, + const Ogre::String& logFileName) +: Ogre::Root(pluginFileName, configFileName, logFileName) +{} + +bool CustomRoot::isQueuedEnd() const +{ + return mQueuedEnd; +} + +#endif + void OgreRenderer::cleanup() { delete mFader; @@ -52,7 +68,19 @@ void OgreRenderer::cleanup() void OgreRenderer::start() { +#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE + // we need this custom main loop because otherwise Ogre's Carbon message pump will + // steal input events even from our Cocoa window + // There's no way to disable Ogre's message pump other that comment pump code in Ogre's source + do { + if (!mRoot->renderOneFrame()) { + break; + } + + } while (!mRoot->isQueuedEnd()); +#else mRoot->startRendering(); +#endif } void OgreRenderer::loadPlugins() @@ -145,7 +173,11 @@ void OgreRenderer::configure(const std::string &logPath, // Disable logging log->setDebugOutputEnabled(false); +#if defined(__APPLE__) && !defined(__LP64__) + mRoot = new CustomRoot("", "", ""); +#else mRoot = new Root("", "", ""); +#endif #if defined(ENABLE_PLUGIN_GL) || defined(ENABLE_PLUGIN_Direct3D9) || defined(ENABLE_PLUGIN_CgProgramManager) || defined(ENABLE_PLUGIN_OctreeSceneManager) || defined(ENABLE_PLUGIN_ParticleFX) loadPlugins(); diff --git a/libs/openengine/ogre/renderer.hpp b/libs/openengine/ogre/renderer.hpp index 0cd0e74e83..a451490fbd 100644 --- a/libs/openengine/ogre/renderer.hpp +++ b/libs/openengine/ogre/renderer.hpp @@ -27,12 +27,18 @@ #include "OgreTexture.h" #include +#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE +#include +#endif + struct SDL_Window; struct SDL_Surface; namespace Ogre { +#if OGRE_PLATFORM != OGRE_PLATFORM_APPLE class Root; +#endif class RenderWindow; class SceneManager; class Camera; @@ -54,11 +60,26 @@ namespace OEngine std::string icon; }; +#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE + class CustomRoot : public Ogre::Root { + public: + bool isQueuedEnd() const; + + CustomRoot(const Ogre::String& pluginFileName = "plugins.cfg", + const Ogre::String& configFileName = "ogre.cfg", + const Ogre::String& logFileName = "Ogre.log"); + }; +#endif + class Fader; class OgreRenderer { +#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE + CustomRoot *mRoot; +#else Ogre::Root *mRoot; +#endif Ogre::RenderWindow *mWindow; SDL_Window *mSDLWindow; SDL_Surface *mWindowIconSurface;