OgreCompositorManager.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 __CompositorManager_H__
00029 #define __CompositorManager_H__
00030 
00031 #include "OgrePrerequisites.h"
00032 #include "OgreResourceManager.h"
00033 #include "OgreCompositor.h"
00034 #include "OgreRectangle2D.h"
00035 #include "OgreRenderSystem.h"
00036 #include "OgreCompositionTechnique.h"
00037 
00038 namespace Ogre {
00058     class _OgreExport CompositorManager : public ResourceManager, public Singleton<CompositorManager>
00059     {
00060     public:
00061         CompositorManager();
00062         virtual ~CompositorManager();
00063 
00065         Resource* createImpl(const String& name, ResourceHandle handle,
00066             const String& group, bool isManual, ManualResourceLoader* loader,
00067             const NameValuePairList* params);
00068 
00071         void initialise(void);
00072 
00075         void parseScript(DataStreamPtr& stream, const String& groupName);
00076 
00082         CompositorChain *getCompositorChain(Viewport *vp);
00083 
00086         bool hasCompositorChain(Viewport *vp) const;
00087 
00090         void removeCompositorChain(Viewport *vp);
00091 
00099         CompositorInstance *addCompositor(Viewport *vp, const String &compositor, int addPosition=-1);
00100 
00103         void removeCompositor(Viewport *vp, const String &compositor);
00104 
00110         void setCompositorEnabled(Viewport *vp, const String &compositor, bool value);
00111 
00114         Renderable *_getTexturedRectangle2D();
00115 
00117         void removeAll(void);
00118 
00120         void _reconstructAllCompositorResources();
00121 
00122         typedef set<Texture*>::type UniqueTextureSet;
00123 
00131         TexturePtr getPooledTexture(const String& name, const String& localName, 
00132             size_t w, size_t h, 
00133             PixelFormat f, uint aa, const String& aaHint, bool srgb, UniqueTextureSet& texturesAlreadyAssigned, 
00134             CompositorInstance* inst, CompositionTechnique::TextureScope scope);
00135 
00139         void freePooledTextures(bool onlyIfUnreferenced = true);
00140 
00144         void registerCompositorLogic(const String& name, CompositorLogic* logic);
00145         
00148         CompositorLogic* getCompositorLogic(const String& name);
00149 
00152         void registerCustomCompositionPass(const String& name, CustomCompositionPass* customPass);
00153         
00156         CustomCompositionPass* getCustomCompositionPass(const String& name);
00157 
00173         static CompositorManager& getSingleton(void);
00189         static CompositorManager* getSingletonPtr(void);
00190 
00191     
00192     private:
00193         typedef map<Viewport*, CompositorChain*>::type Chains;
00194         Chains mChains;
00195 
00198         void freeChains();
00199 
00200         Rectangle2D *mRectangle;
00201 
00203         typedef vector<CompositorInstance *>::type Instances;
00204         Instances mInstances;
00205 
00207         typedef map<String, CompositorLogic*>::type CompositorLogicMap;
00208         CompositorLogicMap mCompositorLogics;
00209 
00211         typedef map<String, CustomCompositionPass*>::type CustomCompositionPassMap;
00212         CustomCompositionPassMap mCustomCompositionPasses;
00213 
00214         typedef vector<TexturePtr>::type TextureList;
00215         typedef VectorIterator<TextureList> TextureIterator;
00216 
00217         struct TextureDef
00218         {
00219             size_t width, height;
00220             PixelFormat format;
00221             uint fsaa;
00222             String fsaaHint;
00223             bool sRGBwrite;
00224 
00225             TextureDef(size_t w, size_t h, PixelFormat f, uint aa, const String& aaHint, bool srgb)
00226                 : width(w), height(h), format(f), fsaa(aa), fsaaHint(aaHint), sRGBwrite(srgb)
00227             {
00228 
00229             }
00230         };
00231         struct TextureDefLess
00232         {
00233             bool _OgreExport operator()(const TextureDef& x, const TextureDef& y) const
00234             {
00235                 if (x.format < y.format)
00236                     return true;
00237                 else if (x.format == y.format)
00238                 {
00239                     if (x.width < y.width)
00240                         return true;
00241                     else if (x.width == y.width)
00242                     {
00243                         if (x.height < y.height)
00244                             return true;
00245                         else if (x.height == y.height)
00246                         {
00247                             if (x.fsaa < y.fsaa)
00248                                 return true;
00249                             else if (x.fsaa == y.fsaa)
00250                             {
00251                                 if (x.fsaaHint < y.fsaaHint)
00252                                     return true;
00253                                 else if (x.fsaaHint == y.fsaaHint)
00254                                 {
00255                                     if (!x.sRGBwrite && y.sRGBwrite)
00256                                         return true;
00257                                 }
00258 
00259                             }
00260                         }
00261                     }
00262                 }
00263                 return false;
00264             }
00265             virtual ~TextureDefLess() {}
00266         };
00267         typedef map<TextureDef, TextureList*, TextureDefLess>::type TexturesByDef;
00268         TexturesByDef mTexturesByDef;
00269 
00270         typedef std::pair<String, String> StringPair;
00271         typedef map<TextureDef, TexturePtr, TextureDefLess>::type TextureDefMap;
00272         typedef std::map<StringPair, TextureDefMap> ChainTexturesByDef;
00273         
00274         ChainTexturesByDef mChainTexturesByDef;
00275 
00276         bool isInputPreviousTarget(CompositorInstance* inst, const Ogre::String& localName);
00277         bool isInputPreviousTarget(CompositorInstance* inst, TexturePtr tex);
00278         bool isInputToOutputTarget(CompositorInstance* inst, const Ogre::String& localName);
00279         bool isInputToOutputTarget(CompositorInstance* inst, TexturePtr tex);
00280 
00281     };
00285 }
00286 
00287 #endif

Copyright © 2008 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Thu Dec 31 16:27:08 2009