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-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 __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 #include "OgreHeaderPrefix.h"
00038 
00039 namespace Ogre {
00059     class _OgreExport CompositorManager : public ResourceManager, public Singleton<CompositorManager>
00060     {
00061     public:
00062         CompositorManager();
00063         virtual ~CompositorManager();
00064 
00066         Resource* createImpl(const String& name, ResourceHandle handle,
00067             const String& group, bool isManual, ManualResourceLoader* loader,
00068             const NameValuePairList* params);
00069 
00072         void initialise(void);
00073 
00078         CompositorPtr create (const String& name, const String& group,
00079                             bool isManual = false, ManualResourceLoader* loader = 0,
00080                             const NameValuePairList* createParams = 0);
00081 
00084         CompositorPtr getByName(const String& name, const String& groupName = ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME);
00085 
00086 
00089         void parseScript(DataStreamPtr& stream, const String& groupName);
00090 
00096         CompositorChain *getCompositorChain(Viewport *vp);
00097 
00100         bool hasCompositorChain(Viewport *vp) const;
00101 
00104         void removeCompositorChain(Viewport *vp);
00105 
00113         CompositorInstance *addCompositor(Viewport *vp, const String &compositor, int addPosition=-1);
00114 
00117         void removeCompositor(Viewport *vp, const String &compositor);
00118 
00124         void setCompositorEnabled(Viewport *vp, const String &compositor, bool value);
00125 
00128         Renderable *_getTexturedRectangle2D();
00129 
00131         void removeAll(void);
00132 
00134         void _reconstructAllCompositorResources();
00135 
00136         typedef set<Texture*>::type UniqueTextureSet;
00137 
00145         TexturePtr getPooledTexture(const String& name, const String& localName, 
00146             size_t w, size_t h, 
00147             PixelFormat f, uint aa, const String& aaHint, bool srgb, UniqueTextureSet& texturesAlreadyAssigned, 
00148             CompositorInstance* inst, CompositionTechnique::TextureScope scope);
00149 
00153         void freePooledTextures(bool onlyIfUnreferenced = true);
00154 
00158         void registerCompositorLogic(const String& name, CompositorLogic* logic);
00159 
00162         void unregisterCompositorLogic(const String& name);
00163         
00166         CompositorLogic* getCompositorLogic(const String& name);
00167 
00170         void registerCustomCompositionPass(const String& name, CustomCompositionPass* customPass);
00171         
00174         CustomCompositionPass* getCustomCompositionPass(const String& name);
00175 
00191         static CompositorManager& getSingleton(void);
00207         static CompositorManager* getSingletonPtr(void);
00208 
00209     
00210     private:
00211         typedef map<Viewport*, CompositorChain*>::type Chains;
00212         Chains mChains;
00213 
00216         void freeChains();
00217 
00218         Rectangle2D *mRectangle;
00219 
00221         typedef vector<CompositorInstance *>::type Instances;
00222         Instances mInstances;
00223 
00225         typedef map<String, CompositorLogic*>::type CompositorLogicMap;
00226         CompositorLogicMap mCompositorLogics;
00227 
00229         typedef map<String, CustomCompositionPass*>::type CustomCompositionPassMap;
00230         CustomCompositionPassMap mCustomCompositionPasses;
00231 
00232         typedef vector<TexturePtr>::type TextureList;
00233         typedef VectorIterator<TextureList> TextureIterator;
00234 
00235         struct TextureDef
00236         {
00237             size_t width, height;
00238             PixelFormat format;
00239             uint fsaa;
00240             String fsaaHint;
00241             bool sRGBwrite;
00242 
00243             TextureDef(size_t w, size_t h, PixelFormat f, uint aa, const String& aaHint, bool srgb)
00244                 : width(w), height(h), format(f), fsaa(aa), fsaaHint(aaHint), sRGBwrite(srgb)
00245             {
00246 
00247             }
00248         };
00249         struct TextureDefLess
00250         {
00251             bool _OgreExport operator()(const TextureDef& x, const TextureDef& y) const
00252             {
00253                 if (x.format < y.format)
00254                     return true;
00255                 else if (x.format == y.format)
00256                 {
00257                     if (x.width < y.width)
00258                         return true;
00259                     else if (x.width == y.width)
00260                     {
00261                         if (x.height < y.height)
00262                             return true;
00263                         else if (x.height == y.height)
00264                         {
00265                             if (x.fsaa < y.fsaa)
00266                                 return true;
00267                             else if (x.fsaa == y.fsaa)
00268                             {
00269                                 if (x.fsaaHint < y.fsaaHint)
00270                                     return true;
00271                                 else if (x.fsaaHint == y.fsaaHint)
00272                                 {
00273                                     if (!x.sRGBwrite && y.sRGBwrite)
00274                                         return true;
00275                                 }
00276 
00277                             }
00278                         }
00279                     }
00280                 }
00281                 return false;
00282             }
00283             virtual ~TextureDefLess() {}
00284         };
00285         typedef map<TextureDef, TextureList*, TextureDefLess>::type TexturesByDef;
00286         TexturesByDef mTexturesByDef;
00287 
00288         typedef std::pair<String, String> StringPair;
00289         typedef map<TextureDef, TexturePtr, TextureDefLess>::type TextureDefMap;
00290         typedef map<StringPair, TextureDefMap>::type ChainTexturesByDef;
00291         
00292         ChainTexturesByDef mChainTexturesByDef;
00293 
00294         bool isInputPreviousTarget(CompositorInstance* inst, const Ogre::String& localName);
00295         bool isInputPreviousTarget(CompositorInstance* inst, TexturePtr tex);
00296         bool isInputToOutputTarget(CompositorInstance* inst, const Ogre::String& localName);
00297         bool isInputToOutputTarget(CompositorInstance* inst, TexturePtr tex);
00298 
00299     };
00303 }
00304 
00305 #include "OgreHeaderSuffix.h"
00306 
00307 #endif

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Mon Jul 27 2020 13:40:41