OgreRoot.h

Go to the documentation of this file.
00001 /*
00002 -----------------------------------------------------------------------------
00003 This source file is part of OGRE
00004     (Object-oriented Graphics Rendering Engine)
00005 For the latest info, see http://www.ogre3d.org/
00006 
00007 Copyright (c) 2000-2009 Torus Knot Software Ltd
00008 
00009 Permission is hereby granted, free of charge, to any person obtaining a copy
00010 of this software and associated documentation files (the "Software"), to deal
00011 in the Software without restriction, including without limitation the rights
00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00013 copies of the Software, and to permit persons to whom the Software is
00014 furnished to do so, subject to the following conditions:
00015 
00016 The above copyright notice and this permission notice shall be included in
00017 all copies or substantial portions of the Software.
00018 
00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00025 THE SOFTWARE.
00026 -----------------------------------------------------------------------------
00027 */
00028 #ifndef __ROOT__
00029 #define __ROOT__
00030 
00031 // Precompiler options
00032 #include "OgrePrerequisites.h"
00033 
00034 #include "OgreSingleton.h"
00035 #include "OgreString.h"
00036 #include "OgreSceneManagerEnumerator.h"
00037 #include "OgreResourceGroupManager.h"
00038 #include "OgreLodStrategyManager.h"
00039 #include "OgreWorkQueue.h"
00040 
00041 #include <exception>
00042 
00043 namespace Ogre
00044 {
00052     typedef vector<RenderSystem*>::type RenderSystemList;
00053     
00067     class _OgreExport Root : public Singleton<Root>, public RootAlloc
00068     {
00069         // To allow update of active renderer if
00070         // RenderSystem::initialise is used directly
00071         friend class RenderSystem;
00072     protected:
00073         RenderSystemList mRenderers;
00074         RenderSystem* mActiveRenderer;
00075         String mVersion;
00076         String mConfigFileName;
00077         bool mQueuedEnd;
00078         // In case multiple render windows are created, only once are the resources loaded.
00079         bool mFirstTimePostWindowInit;
00080 
00081         // Singletons
00082         LogManager* mLogManager;
00083         ControllerManager* mControllerManager;
00084         SceneManagerEnumerator* mSceneManagerEnum;
00085         typedef deque<SceneManager*>::type SceneManagerStack;
00086         SceneManagerStack mSceneManagerStack;
00087         DynLibManager* mDynLibManager;
00088         ArchiveManager* mArchiveManager;
00089         MaterialManager* mMaterialManager;
00090         MeshManager* mMeshManager;
00091         ParticleSystemManager* mParticleManager;
00092         SkeletonManager* mSkeletonManager;
00093         OverlayElementFactory* mPanelFactory;
00094         OverlayElementFactory* mBorderPanelFactory;
00095         OverlayElementFactory* mTextAreaFactory;
00096         OverlayManager* mOverlayManager;
00097         FontManager* mFontManager;
00098         ArchiveFactory *mZipArchiveFactory;
00099         ArchiveFactory *mFileSystemArchiveFactory;
00100         ResourceGroupManager* mResourceGroupManager;
00101         ResourceBackgroundQueue* mResourceBackgroundQueue;
00102         ShadowTextureManager* mShadowTextureManager;
00103         RenderSystemCapabilitiesManager* mRenderSystemCapabilitiesManager;
00104         ScriptCompilerManager *mCompilerManager;
00105         LodStrategyManager *mLodStrategyManager;
00106 
00107         Timer* mTimer;
00108         RenderWindow* mAutoWindow;
00109         Profiler* mProfiler;
00110         HighLevelGpuProgramManager* mHighLevelGpuProgramManager;
00111         ExternalTextureSourceManager* mExternalTextureSourceManager;
00112         CompositorManager* mCompositorManager;      
00113         unsigned long mNextFrame;
00114         Real mFrameSmoothingTime;
00115         bool mRemoveQueueStructuresOnClear;
00116 
00117     public:
00118         typedef vector<DynLib*>::type PluginLibList;
00119         typedef vector<Plugin*>::type PluginInstanceList;
00120     protected:
00122         PluginLibList mPluginLibs;
00124         PluginInstanceList mPlugins;
00125 
00126         typedef map<String, MovableObjectFactory*>::type MovableObjectFactoryMap;
00127         MovableObjectFactoryMap mMovableObjectFactoryMap;
00128         uint32 mNextMovableObjectTypeFlag;
00129         // stock movable factories
00130         MovableObjectFactory* mEntityFactory;
00131         MovableObjectFactory* mLightFactory;
00132         MovableObjectFactory* mBillboardSetFactory;
00133         MovableObjectFactory* mManualObjectFactory;
00134         MovableObjectFactory* mBillboardChainFactory;
00135         MovableObjectFactory* mRibbonTrailFactory;
00136 
00137         typedef map<String, RenderQueueInvocationSequence*>::type RenderQueueInvocationSequenceMap;
00138         RenderQueueInvocationSequenceMap mRQSequenceMap;
00139 
00141         bool mIsInitialised;
00142 
00143         WorkQueue* mWorkQueue;
00144 
00151         void loadPlugins( const String& pluginsfile = "plugins.cfg" );
00155         void initialisePlugins();
00159         void shutdownPlugins();
00160 
00163         void unloadPlugins();
00164 
00165         // Internal method for one-time tasks after first window creation
00166         void oneTimePostWindowInit(void);
00167 
00169         set<FrameListener*>::type mFrameListeners;
00170 
00172         set<FrameListener*>::type mRemovedFrameListeners;
00173 
00175         enum FrameEventTimeType {
00176             FETT_ANY = 0, 
00177             FETT_STARTED = 1, 
00178             FETT_QUEUED = 2, 
00179             FETT_ENDED = 3, 
00180             FETT_COUNT = 4
00181         };
00182 
00184         typedef deque<unsigned long>::type EventTimesQueue;
00185         EventTimesQueue mEventTimes[FETT_COUNT];
00186 
00191         Real calculateEventTime(unsigned long now, FrameEventTimeType type);
00192 
00194         void populateFrameEvent(FrameEventTimeType type, FrameEvent& evtToUpdate);
00195 
00196     public:
00197 
00206         Root(const String& pluginFileName = "plugins.cfg", 
00207             const String& configFileName = "ogre.cfg", 
00208             const String& logFileName = "Ogre.log");
00209         ~Root();
00210 
00216         void saveConfig(void);
00217 
00230         bool restoreConfig(void);
00231 
00248         bool showConfigDialog(void);
00249 
00261         void addRenderSystem(RenderSystem* newRend);
00262 
00269         const RenderSystemList& getAvailableRenderers(void);
00270 
00277         RenderSystem* getRenderSystemByName(const String& name);
00278 
00296         void setRenderSystem(RenderSystem* system);
00297 
00300         RenderSystem* getRenderSystem(void);
00301 
00317         RenderWindow* initialise(bool autoCreateWindow, const String& windowTitle = "OGRE Render Window",
00318                                     const String& customCapabilitiesConfig = StringUtil::BLANK);
00319 
00321         bool isInitialised(void) const { return mIsInitialised; }
00322 
00328         void useCustomRenderSystemCapabilities(RenderSystemCapabilities* capabilities);
00329 
00333         bool getRemoveRenderQueueStructuresOnClear() const { return mRemoveQueueStructuresOnClear; }
00334 
00338         void setRemoveRenderQueueStructuresOnClear(bool r) { mRemoveQueueStructuresOnClear = r; }
00339 
00345         void addSceneManagerFactory(SceneManagerFactory* fact);
00346 
00349         void removeSceneManagerFactory(SceneManagerFactory* fact);
00350 
00360         const SceneManagerMetaData* getSceneManagerMetaData(const String& typeName) const;
00361 
00365         SceneManagerEnumerator::MetaDataIterator getSceneManagerMetaDataIterator(void) const;
00366 
00378         SceneManager* createSceneManager(const String& typeName, 
00379             const String& instanceName = StringUtil::BLANK);
00380 
00393         SceneManager* createSceneManager(SceneTypeMask typeMask, 
00394             const String& instanceName = StringUtil::BLANK);
00395 
00397         void destroySceneManager(SceneManager* sm);
00398 
00403         SceneManager* getSceneManager(const String& instanceName) const;
00404 
00408         bool hasSceneManager(const String& instanceName) const;
00410         SceneManagerEnumerator::SceneManagerIterator getSceneManagerIterator(void);
00411 
00427         TextureManager* getTextureManager(void);
00428 
00434         MeshManager* getMeshManager(void);
00435 
00439         String getErrorDescription(long errorNumber);
00440 
00457         void addFrameListener(FrameListener* newListener);
00458 
00463         void removeFrameListener(FrameListener* oldListener);
00464 
00473         void queueEndRendering(void);
00474 
00502         void startRendering(void);
00503 
00509         bool renderOneFrame(void);
00510 
00517         bool renderOneFrame(Real timeSinceLastFrame);
00518 
00526         void shutdown(void);
00527 
00574         void addResourceLocation(const String& name, const String& locType, 
00575             const String& groupName = ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, 
00576             bool recursive = false);
00577 
00584         void removeResourceLocation(const String& name, 
00585             const String& groupName = ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
00586 
00608         DataStreamPtr createFileStream(const String& filename, const String& groupName = ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, 
00609             bool overwrite = false, const String& locationPattern = StringUtil::BLANK);
00610 
00625         DataStreamPtr openFileStream(const String& filename, const String& groupName = ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, 
00626             const String& locationPattern = StringUtil::BLANK);
00627 
00636         void convertColourValue(const ColourValue& colour, uint32* pDest);
00637 
00646         RenderWindow* getAutoCreatedWindow(void);
00647 
00650         RenderWindow* createRenderWindow(const String &name, unsigned int width, unsigned int height, 
00651             bool fullScreen, const NameValuePairList *miscParams = 0) ;
00652 
00655         bool createRenderWindows(const RenderWindowDescriptionList& renderWindowDescriptions,
00656             RenderWindowList& createdWindows);
00657     
00660         void detachRenderTarget( RenderTarget* pWin );
00661 
00664         void detachRenderTarget( const String & name );
00665 
00668         RenderTarget * getRenderTarget(const String &name);
00669 
00680         void loadPlugin(const String& pluginName);
00681 
00691         void unloadPlugin(const String& pluginName);
00692 
00703         void installPlugin(Plugin* plugin);
00704 
00713         void uninstallPlugin(Plugin* plugin);
00714 
00716         const PluginInstanceList& getInstalledPlugins() const { return mPlugins; }
00717 
00719         Timer* getTimer(void);
00720 
00740         bool _fireFrameStarted(FrameEvent& evt);
00750         bool _fireFrameRenderingQueued(FrameEvent& evt);
00751 
00768         bool _fireFrameEnded(FrameEvent& evt);
00786         bool _fireFrameStarted();
00797         bool _fireFrameRenderingQueued();
00812         bool _fireFrameEnded();
00813 
00822         unsigned long getNextFrameNumber(void) const { return mNextFrame; }
00823 
00829         SceneManager* _getCurrentSceneManager(void) const;
00834         void _pushCurrentSceneManager(SceneManager* sm);
00839         void _popCurrentSceneManager(SceneManager* sm);
00840 
00851         bool _updateAllRenderTargets(void);
00852 
00864         bool _updateAllRenderTargets(FrameEvent& evt);
00865 
00870         RenderQueueInvocationSequence* createRenderQueueInvocationSequence(
00871             const String& name);
00872 
00876         RenderQueueInvocationSequence* getRenderQueueInvocationSequence(
00877             const String& name);
00878 
00884         void destroyRenderQueueInvocationSequence(
00885             const String& name);
00886 
00892         void destroyAllRenderQueueInvocationSequences(void);
00893 
00909         static Root& getSingleton(void);
00925         static Root* getSingletonPtr(void);
00926 
00935         void clearEventTimes(void);
00936 
00949         void setFrameSmoothingPeriod(Real period) { mFrameSmoothingTime = period; }
00951         Real getFrameSmoothingPeriod(void) const { return mFrameSmoothingTime; }
00952 
00965         void addMovableObjectFactory(MovableObjectFactory* fact, 
00966             bool overrideExisting = false);
00974         void removeMovableObjectFactory(MovableObjectFactory* fact);
00976         bool hasMovableObjectFactory(const String& typeName) const;
00978         MovableObjectFactory* getMovableObjectFactory(const String& typeName);
00984         uint32 _allocateNextMovableObjectTypeFlag(void);
00985 
00986         typedef ConstMapIterator<MovableObjectFactoryMap> MovableObjectFactoryIterator;
00990         MovableObjectFactoryIterator getMovableObjectFactoryIterator(void) const;
00991 
00995         unsigned int getDisplayMonitorCount() const;
00996 
01003         WorkQueue* getWorkQueue() const { return mWorkQueue; }
01004 
01013         void setWorkQueue(WorkQueue* queue);
01014             
01015     };
01018 } // Namespace Ogre
01019 #endif

Copyright © 2008 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Wed Nov 3 2010 19:24:52