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-2013 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 #if OGRE_PLATFORM == OGRE_PLATFORM_ANDROID 00042 #include "Android/OgreAndroidLogListener.h" 00043 #endif 00044 00045 #include <exception> 00046 00047 namespace Ogre 00048 { 00056 typedef vector<RenderSystem*>::type RenderSystemList; 00057 00071 class _OgreExport Root : public Singleton<Root>, public RootAlloc 00072 { 00073 // To allow update of active renderer if 00074 // RenderSystem::initialise is used directly 00075 friend class RenderSystem; 00076 protected: 00077 RenderSystemList mRenderers; 00078 RenderSystem* mActiveRenderer; 00079 String mVersion; 00080 String mConfigFileName; 00081 bool mQueuedEnd; 00083 bool mFirstTimePostWindowInit; 00084 00085 // Singletons 00086 LogManager* mLogManager; 00087 ControllerManager* mControllerManager; 00088 SceneManagerEnumerator* mSceneManagerEnum; 00089 typedef deque<SceneManager*>::type SceneManagerStack; 00090 SceneManagerStack mSceneManagerStack; 00091 DynLibManager* mDynLibManager; 00092 ArchiveManager* mArchiveManager; 00093 MaterialManager* mMaterialManager; 00094 MeshManager* mMeshManager; 00095 ParticleSystemManager* mParticleManager; 00096 SkeletonManager* mSkeletonManager; 00097 00098 ArchiveFactory *mZipArchiveFactory; 00099 ArchiveFactory *mEmbeddedZipArchiveFactory; 00100 ArchiveFactory *mFileSystemArchiveFactory; 00101 00102 #if OGRE_PLATFORM == OGRE_PLATFORM_ANDROID 00103 AndroidLogListener* mAndroidLogger; 00104 #endif 00105 00106 ResourceGroupManager* mResourceGroupManager; 00107 ResourceBackgroundQueue* mResourceBackgroundQueue; 00108 ShadowTextureManager* mShadowTextureManager; 00109 RenderSystemCapabilitiesManager* mRenderSystemCapabilitiesManager; 00110 ScriptCompilerManager *mCompilerManager; 00111 LodStrategyManager *mLodStrategyManager; 00112 PMWorker* mPMWorker; 00113 PMInjector* mPMInjector; 00114 00115 Timer* mTimer; 00116 RenderWindow* mAutoWindow; 00117 Profiler* mProfiler; 00118 HighLevelGpuProgramManager* mHighLevelGpuProgramManager; 00119 ExternalTextureSourceManager* mExternalTextureSourceManager; 00120 CompositorManager* mCompositorManager; 00121 unsigned long mNextFrame; 00122 Real mFrameSmoothingTime; 00123 bool mRemoveQueueStructuresOnClear; 00124 Real mDefaultMinPixelSize; 00125 00126 public: 00127 typedef vector<DynLib*>::type PluginLibList; 00128 typedef vector<Plugin*>::type PluginInstanceList; 00129 protected: 00131 PluginLibList mPluginLibs; 00133 PluginInstanceList mPlugins; 00134 00135 typedef map<String, MovableObjectFactory*>::type MovableObjectFactoryMap; 00136 MovableObjectFactoryMap mMovableObjectFactoryMap; 00137 uint32 mNextMovableObjectTypeFlag; 00138 // stock movable factories 00139 MovableObjectFactory* mEntityFactory; 00140 MovableObjectFactory* mLightFactory; 00141 MovableObjectFactory* mBillboardSetFactory; 00142 MovableObjectFactory* mManualObjectFactory; 00143 MovableObjectFactory* mBillboardChainFactory; 00144 MovableObjectFactory* mRibbonTrailFactory; 00145 00146 typedef map<String, RenderQueueInvocationSequence*>::type RenderQueueInvocationSequenceMap; 00147 RenderQueueInvocationSequenceMap mRQSequenceMap; 00148 00150 bool mIsInitialised; 00151 00152 WorkQueue* mWorkQueue; 00153 00155 bool mIsBlendIndicesGpuRedundant; 00157 bool mIsBlendWeightsGpuRedundant; 00158 00166 void loadPlugins(const String& pluginsfile = "plugins" OGRE_BUILD_SUFFIX ".cfg"); 00170 void initialisePlugins(); 00174 void shutdownPlugins(); 00175 00178 void unloadPlugins(); 00179 00181 void oneTimePostWindowInit(void); 00182 00184 set<FrameListener*>::type mFrameListeners; 00185 00187 set<FrameListener*>::type mRemovedFrameListeners; 00188 set<FrameListener*>::type mAddedFrameListeners; 00189 void _syncAddedRemovedFrameListeners(); 00190 00192 enum FrameEventTimeType { 00193 FETT_ANY = 0, 00194 FETT_STARTED = 1, 00195 FETT_QUEUED = 2, 00196 FETT_ENDED = 3, 00197 FETT_COUNT = 4 00198 }; 00199 00201 typedef deque<unsigned long>::type EventTimesQueue; 00202 EventTimesQueue mEventTimes[FETT_COUNT]; 00203 00208 Real calculateEventTime(unsigned long now, FrameEventTimeType type); 00209 00211 void populateFrameEvent(FrameEventTimeType type, FrameEvent& evtToUpdate); 00212 00213 public: 00214 00224 Root(const String& pluginFileName = "plugins" OGRE_BUILD_SUFFIX ".cfg", 00225 const String& configFileName = "ogre.cfg", 00226 const String& logFileName = "Ogre.log"); 00227 ~Root(); 00228 00234 void saveConfig(void); 00235 00248 bool restoreConfig(void); 00249 00266 bool showConfigDialog(void); 00267 00279 void addRenderSystem(RenderSystem* newRend); 00280 00287 const RenderSystemList& getAvailableRenderers(void); 00288 00295 RenderSystem* getRenderSystemByName(const String& name); 00296 00314 void setRenderSystem(RenderSystem* system); 00315 00318 RenderSystem* getRenderSystem(void); 00319 00335 RenderWindow* initialise(bool autoCreateWindow, const String& windowTitle = "OGRE Render Window", 00336 const String& customCapabilitiesConfig = StringUtil::BLANK); 00337 00339 bool isInitialised(void) const { return mIsInitialised; } 00340 00346 void useCustomRenderSystemCapabilities(RenderSystemCapabilities* capabilities); 00347 00351 bool getRemoveRenderQueueStructuresOnClear() const { return mRemoveQueueStructuresOnClear; } 00352 00356 void setRemoveRenderQueueStructuresOnClear(bool r) { mRemoveQueueStructuresOnClear = r; } 00357 00363 void addSceneManagerFactory(SceneManagerFactory* fact); 00364 00367 void removeSceneManagerFactory(SceneManagerFactory* fact); 00368 00378 const SceneManagerMetaData* getSceneManagerMetaData(const String& typeName) const; 00379 00383 SceneManagerEnumerator::MetaDataIterator getSceneManagerMetaDataIterator(void) const; 00384 00396 SceneManager* createSceneManager(const String& typeName, 00397 const String& instanceName = StringUtil::BLANK); 00398 00411 SceneManager* createSceneManager(SceneTypeMask typeMask, 00412 const String& instanceName = StringUtil::BLANK); 00413 00415 void destroySceneManager(SceneManager* sm); 00416 00421 SceneManager* getSceneManager(const String& instanceName) const; 00422 00426 bool hasSceneManager(const String& instanceName) const; 00428 SceneManagerEnumerator::SceneManagerIterator getSceneManagerIterator(void); 00429 00445 TextureManager* getTextureManager(void); 00446 00452 MeshManager* getMeshManager(void); 00453 00457 String getErrorDescription(long errorNumber); 00458 00475 void addFrameListener(FrameListener* newListener); 00476 00481 void removeFrameListener(FrameListener* oldListener); 00482 00491 void queueEndRendering(bool state = true); 00492 00499 bool endRenderingQueued(void); 00500 00528 void startRendering(void); 00529 00535 bool renderOneFrame(void); 00536 00543 bool renderOneFrame(Real timeSinceLastFrame); 00544 00552 void shutdown(void); 00553 00600 void addResourceLocation(const String& name, const String& locType, 00601 const String& groupName = ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, 00602 bool recursive = false); 00603 00610 void removeResourceLocation(const String& name, 00611 const String& groupName = ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); 00612 00634 DataStreamPtr createFileStream(const String& filename, const String& groupName = ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, 00635 bool overwrite = false, const String& locationPattern = StringUtil::BLANK); 00636 00651 DataStreamPtr openFileStream(const String& filename, const String& groupName = ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, 00652 const String& locationPattern = StringUtil::BLANK); 00653 00662 void convertColourValue(const ColourValue& colour, uint32* pDest); 00663 00672 RenderWindow* getAutoCreatedWindow(void); 00673 00676 RenderWindow* createRenderWindow(const String &name, unsigned int width, unsigned int height, 00677 bool fullScreen, const NameValuePairList *miscParams = 0) ; 00678 00681 bool createRenderWindows(const RenderWindowDescriptionList& renderWindowDescriptions, 00682 RenderWindowList& createdWindows); 00683 00689 RenderTarget* detachRenderTarget( RenderTarget* pWin ); 00690 00696 RenderTarget* detachRenderTarget( const String & name ); 00697 00700 void destroyRenderTarget(RenderTarget* target); 00701 00704 void destroyRenderTarget(const String &name); 00705 00708 RenderTarget * getRenderTarget(const String &name); 00709 00720 void loadPlugin(const String& pluginName); 00721 00731 void unloadPlugin(const String& pluginName); 00732 00743 void installPlugin(Plugin* plugin); 00744 00753 void uninstallPlugin(Plugin* plugin); 00754 00756 const PluginInstanceList& getInstalledPlugins() const { return mPlugins; } 00757 00759 Timer* getTimer(void); 00760 00780 bool _fireFrameStarted(FrameEvent& evt); 00790 bool _fireFrameRenderingQueued(FrameEvent& evt); 00791 00808 bool _fireFrameEnded(FrameEvent& evt); 00826 bool _fireFrameStarted(); 00837 bool _fireFrameRenderingQueued(); 00852 bool _fireFrameEnded(); 00853 00862 unsigned long getNextFrameNumber(void) const { return mNextFrame; } 00863 00869 SceneManager* _getCurrentSceneManager(void) const; 00874 void _pushCurrentSceneManager(SceneManager* sm); 00879 void _popCurrentSceneManager(SceneManager* sm); 00880 00891 bool _updateAllRenderTargets(void); 00892 00904 bool _updateAllRenderTargets(FrameEvent& evt); 00905 00910 RenderQueueInvocationSequence* createRenderQueueInvocationSequence( 00911 const String& name); 00912 00916 RenderQueueInvocationSequence* getRenderQueueInvocationSequence( 00917 const String& name); 00918 00924 void destroyRenderQueueInvocationSequence( 00925 const String& name); 00926 00931 void destroyAllRenderQueueInvocationSequences(void); 00932 00948 static Root& getSingleton(void); 00964 static Root* getSingletonPtr(void); 00965 00974 void clearEventTimes(void); 00975 00988 void setFrameSmoothingPeriod(Real period) { mFrameSmoothingTime = period; } 00990 Real getFrameSmoothingPeriod(void) const { return mFrameSmoothingTime; } 00991 01004 void addMovableObjectFactory(MovableObjectFactory* fact, 01005 bool overrideExisting = false); 01013 void removeMovableObjectFactory(MovableObjectFactory* fact); 01015 bool hasMovableObjectFactory(const String& typeName) const; 01017 MovableObjectFactory* getMovableObjectFactory(const String& typeName); 01023 uint32 _allocateNextMovableObjectTypeFlag(void); 01024 01025 typedef ConstMapIterator<MovableObjectFactoryMap> MovableObjectFactoryIterator; 01029 MovableObjectFactoryIterator getMovableObjectFactoryIterator(void) const; 01030 01034 unsigned int getDisplayMonitorCount() const; 01035 01042 WorkQueue* getWorkQueue() const { return mWorkQueue; } 01043 01052 void setWorkQueue(WorkQueue* queue); 01053 01060 void setBlendIndicesGpuRedundant(bool redundant) { mIsBlendIndicesGpuRedundant = redundant; } 01064 bool isBlendIndicesGpuRedundant() const { return mIsBlendIndicesGpuRedundant; } 01065 01072 void setBlendWeightsGpuRedundant(bool redundant) { mIsBlendWeightsGpuRedundant = redundant; } 01076 bool isBlendWeightsGpuRedundant() const { return mIsBlendWeightsGpuRedundant; } 01077 01082 void setDefaultMinPixelSize(Real pixelSize) { mDefaultMinPixelSize = pixelSize; } 01083 01086 Real getDefaultMinPixelSize() { return mDefaultMinPixelSize; } 01087 01088 01089 }; 01092 } // Namespace Ogre 01093 #endif
Copyright © 2012 Torus Knot Software Ltd

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Mon Jul 27 2020 13:40:45