OgreCompositorInstance.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 __CompositorInstance_H__
00029 #define __CompositorInstance_H__
00030 
00031 #include "OgrePrerequisites.h"
00032 #include "OgreMaterialManager.h"
00033 #include "OgreTexture.h"
00034 #include "OgreRenderQueue.h"
00035 #include "OgreCompositionTechnique.h"
00036 #include "OgreHeaderPrefix.h"
00037 
00038 namespace Ogre {
00045     const size_t RENDER_QUEUE_COUNT = RENDER_QUEUE_MAX+1;       
00046             
00050     class _OgreExport CompositorInstance : public CompositorInstAlloc
00051     {
00052     public:
00053         CompositorInstance(CompositionTechnique *technique, CompositorChain *chain);
00054         virtual ~CompositorInstance();
00058         class _OgreExport Listener
00059         {
00060         public:
00061             virtual ~Listener();
00062 
00074             virtual void notifyMaterialSetup(uint32 pass_id, MaterialPtr &mat);
00075 
00086             virtual void notifyMaterialRender(uint32 pass_id, MaterialPtr &mat);
00087 
00092             virtual void notifyResourcesCreated(bool forResizeOnly);
00093 
00094         };
00099         class _OgreExport RenderSystemOperation : public CompositorInstAlloc
00100         {
00101         public:
00102             virtual ~RenderSystemOperation();
00104             virtual void execute(SceneManager *sm, RenderSystem *rs) = 0;
00105         };
00106         typedef map<int, MaterialPtr>::type QuadMaterialMap;
00107         typedef std::pair<int, RenderSystemOperation*> RenderSystemOpPair;
00108         typedef vector<RenderSystemOpPair>::type RenderSystemOpPairs;
00111         class TargetOperation
00112         {
00113         public:
00114             TargetOperation()
00115             { 
00116             }
00117             TargetOperation(RenderTarget *inTarget):
00118                 target(inTarget), currentQueueGroupID(0), visibilityMask(0xFFFFFFFF),
00119                 lodBias(1.0f),
00120                 onlyInitial(false), hasBeenRendered(false), findVisibleObjects(false), 
00121                 materialScheme(MaterialManager::DEFAULT_SCHEME_NAME), shadowsEnabled(true)
00122             { 
00123             }
00125             RenderTarget *target;
00126 
00128             int currentQueueGroupID;
00129 
00132             RenderSystemOpPairs renderSystemOperations;
00133 
00136             uint32 visibilityMask;
00137             
00140             float lodBias;
00141             
00144             typedef std::bitset<RENDER_QUEUE_COUNT> RenderQueueBitSet;
00145 
00147             RenderQueueBitSet renderQueues;
00148             
00151             bool onlyInitial;
00155             bool hasBeenRendered;
00158             bool findVisibleObjects;
00160             String materialScheme;
00162             bool shadowsEnabled;
00163         };
00164         typedef vector<TargetOperation>::type CompiledState;
00165         
00170         void setEnabled(bool value);
00171         
00174         bool getEnabled() const { return mEnabled; }
00175 
00182         void setAlive(bool value);
00183 
00186         bool getAlive() const { return mAlive; }
00187 
00201         const String& getTextureInstanceName(const String& name, size_t mrtIndex);
00202 
00216         TexturePtr getTextureInstance(const String& name, size_t mrtIndex);
00217 
00224         RenderTarget* getRenderTarget(const String& name);
00225 
00226        
00231         virtual void _compileTargetOperations(CompiledState &compiledState);
00232         
00236         virtual void _compileOutputOperation(TargetOperation &finalState);
00237         
00240         Compositor *getCompositor();
00241         
00244         CompositionTechnique *getTechnique();
00245 
00253         void setTechnique(CompositionTechnique* tech, bool reuseTextures = true);
00254 
00268         void setScheme(const String& schemeName, bool reuseTextures = true);
00269 
00271         const String& getScheme() const { return mTechnique ? mTechnique->getSchemeName() : StringUtil::BLANK; }
00272 
00278         void notifyResized();
00279 
00282         CompositorChain *getChain();
00283 
00289         void addListener(Listener *l);
00290 
00294         void removeListener(Listener *l);
00295 
00298         void _fireNotifyMaterialSetup(uint32 pass_id, MaterialPtr &mat);
00299 
00302         void _fireNotifyMaterialRender(uint32 pass_id, MaterialPtr &mat);
00303 
00306         void _fireNotifyResourcesCreated(bool forResizeOnly);
00307     private:
00309         Compositor *mCompositor;
00311         CompositionTechnique *mTechnique;
00313         CompositorChain *mChain;
00315         bool mEnabled;
00317         bool mAlive;
00319         typedef map<String,TexturePtr>::type LocalTextureMap;
00320         LocalTextureMap mLocalTextures;
00322         typedef map<String,MultiRenderTarget*>::type LocalMRTMap;
00323         LocalMRTMap mLocalMRTs;
00324         typedef map<CompositionTechnique::TextureDefinition*, TexturePtr>::type ReserveTextureMap;
00329         ReserveTextureMap mReserveTextures;
00330 
00332         typedef vector<Listener*>::type Listeners;
00333         Listeners mListeners;
00334         
00336         CompositorInstance *mPreviousInstance;
00337         
00341         virtual void collectPasses(TargetOperation &finalState, CompositionTargetPass *target);
00342         
00347         MaterialPtr createLocalMaterial(const String& srcName);
00348         
00351         void createResources(bool forResizeOnly);
00352         
00355         void freeResources(bool forResizeOnly, bool clearReserveTextures);
00356 
00359         RenderTarget *getTargetForTex(const String &name);
00360         
00367         const String &getSourceForTex(const String &name, size_t mrtIndex = 0);
00368 
00371         void queueRenderSystemOp(TargetOperation &finalState, RenderSystemOperation *op);
00372 
00374         String getMRTTexLocalName(const String& baseName, size_t attachment);
00375 
00379         void deriveTextureRenderTargetOptions(const String& texname, 
00380             bool *hwGammaWrite, uint *fsaa, String* fsaaHint);
00381 
00383         void notifyCameraChanged(Camera* camera);
00384 
00385         friend class CompositorChain;
00386     };
00390 } // namespace Ogre
00391 
00392 #include "OgreHeaderSuffix.h"
00393 
00394 #endif // __CompositorInstance_H__

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