source: OGRE/trunk/ogrenew/OgreMain/src/OgreCompositorManager.cpp @ 692

Revision 692, 7.5 KB checked in by mattausch, 19 years ago (diff)

adding ogre 1.2 and dependencies

Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2005 The OGRE Team
8Also see acknowledgements in Readme.html
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://www.gnu.org/copyleft/lesser.txt.
23-----------------------------------------------------------------------------
24*/
25#include "OgreStableHeaders.h"
26#include "OgreCompositorManager.h"
27#include "OgreCompositor.h"
28#include "OgreCompositorChain.h"
29#include "OgreCompositionPass.h"
30#include "OgreCompositionTargetPass.h"
31#include "OgreCompositionTechnique.h"
32#include "OgreRoot.h"
33
34namespace Ogre {
35
36template<> CompositorManager* Singleton<CompositorManager>::ms_Singleton = 0;
37//-----------------------------------------------------------------------
38CompositorManager::CompositorManager():
39        mRectangle(0)
40{
41        initialise();
42
43        // Loading order (just after materials)
44        mLoadOrder = 110.0f;
45        // Scripting is supported by this manager
46        mScriptPatterns.push_back("*.compositor");
47        ResourceGroupManager::getSingleton()._registerScriptLoader(this);
48
49        // Resource type
50        mResourceType = "Compositor";
51
52        // Register with resource group manager
53        ResourceGroupManager::getSingleton()._registerResourceManager(mResourceType, this);
54
55}
56//-----------------------------------------------------------------------
57CompositorManager::~CompositorManager()
58{
59    freeChains();
60        delete mRectangle;
61        // Resources cleared by superclass
62        // Unregister with resource group manager
63        ResourceGroupManager::getSingleton()._unregisterResourceManager(mResourceType);
64        ResourceGroupManager::getSingleton()._unregisterScriptLoader(this);
65}
66//-----------------------------------------------------------------------
67Resource* CompositorManager::createImpl(const String& name, ResourceHandle handle,
68    const String& group, bool isManual, ManualResourceLoader* loader,
69    const NameValuePairList* params)
70{
71    return new Compositor(this, name, handle, group, isManual, loader);
72}
73//-----------------------------------------------------------------------
74void CompositorManager::initialise(void)
75{
76    /// Create "default" compositor
77    /** Compositor that is used to implicitly represent the original
78        render in the chain. This is an identity compositor with only an output pass:
79    compositor Ogre/Scene
80    {
81        technique
82        {
83            target_output
84            {
85                                pass clear
86                                {
87                                        /// Clear frame
88                                }
89                pass render_scene
90                {
91                                        visibility_mask FFFFFFFF
92                                        render_queues SKIES_EARLY SKIES_LATE
93                }
94            }
95        }
96    };
97    */
98    CompositorPtr scene = create("Ogre/Scene", ResourceGroupManager::INTERNAL_RESOURCE_GROUP_NAME);
99    CompositionTechnique *t = scene->createTechnique();
100    CompositionTargetPass *tp = t->getOutputTargetPass();
101    tp->setVisibilityMask(0xFFFFFFFF);
102        {
103                CompositionPass *pass = tp->createPass();
104                pass->setType(CompositionPass::PT_CLEAR);
105        }
106        {
107                CompositionPass *pass = tp->createPass();
108                pass->setType(CompositionPass::PT_RENDERSCENE);
109                /// Render everything, including skies
110                pass->setFirstRenderQueue(RENDER_QUEUE_SKIES_EARLY);
111                pass->setLastRenderQueue(RENDER_QUEUE_SKIES_LATE);
112        }
113
114}
115//-----------------------------------------------------------------------
116void CompositorManager::parseScript(DataStreamPtr& stream, const String& groupName)
117{
118    mSerializer.parseScript(stream, groupName);
119}
120//-----------------------------------------------------------------------
121CompositorChain *CompositorManager::getCompositorChain(Viewport *vp)
122{
123    Chains::iterator i=mChains.find(vp);
124    if(i != mChains.end())
125    {
126        return i->second;
127    }
128    else
129    {
130        CompositorChain *chain = new CompositorChain(vp);
131        mChains[vp] = chain;
132        return chain;
133    }
134}
135//-----------------------------------------------------------------------
136bool CompositorManager::hasCompositorChain(Viewport *vp) const
137{
138    return mChains.find(vp) != mChains.end();
139}
140//-----------------------------------------------------------------------
141void CompositorManager::removeCompositorChain(Viewport *vp)
142{
143    Chains::iterator i = mChains.find(vp);
144    if (i != mChains.end())
145    {
146        delete i->second;
147        mChains.erase(i);
148    }
149}
150//-----------------------------------------------------------------------
151void CompositorManager::removeAll(void)
152{
153        freeChains();
154        ResourceManager::removeAll();
155}
156//-----------------------------------------------------------------------
157void CompositorManager::freeChains()
158{
159    Chains::iterator i, iend=mChains.end();
160    for(i=mChains.begin(); i!=iend;++i)
161    {
162        delete i->second;
163    }
164    mChains.clear();
165}
166//-----------------------------------------------------------------------
167Renderable *CompositorManager::_getTexturedRectangle2D()
168{
169        if(!mRectangle)
170        {
171                /// 2D rectangle, to use for render_quad passes
172                mRectangle = new Rectangle2D(true);
173        }
174        RenderSystem* rs = Root::getSingleton().getRenderSystem();
175        Viewport* vp = rs->_getViewport();
176        Real hOffset = rs->getHorizontalTexelOffset() / (0.5 * vp->getActualWidth());
177        Real vOffset = rs->getVerticalTexelOffset() / (0.5 * vp->getActualHeight());
178        mRectangle->setCorners(-1 + hOffset, 1 - vOffset, 1 + hOffset, -1 - vOffset);
179        return mRectangle;
180}
181//-----------------------------------------------------------------------
182CompositorInstance *CompositorManager::addCompositor(Viewport *vp, const String &compositor, int addPosition)
183{
184        CompositorPtr comp = getByName(compositor);
185        if(comp.isNull())
186                return 0;
187        CompositorChain *chain = getCompositorChain(vp);
188        return chain->addCompositor(comp, addPosition==-1 ? CompositorChain::LAST : (size_t)addPosition);
189}
190//-----------------------------------------------------------------------
191void CompositorManager::removeCompositor(Viewport *vp, const String &compositor)
192{
193        CompositorChain *chain = getCompositorChain(vp);
194        CompositorChain::InstanceIterator it = chain->getCompositors();
195        for(size_t pos=0; pos < chain->getNumCompositors(); ++pos)
196        {
197                CompositorInstance *instance = chain->getCompositor(pos);
198                if(instance->getCompositor()->getName() == compositor)
199                {
200                        chain->removeCompositor(pos);
201                        break;
202                }
203        }
204}
205//-----------------------------------------------------------------------
206void CompositorManager::setCompositorEnabled(Viewport *vp, const String &compositor, bool value)
207{
208        CompositorChain *chain = getCompositorChain(vp);
209        CompositorChain::InstanceIterator it = chain->getCompositors();
210        for(size_t pos=0; pos < chain->getNumCompositors(); ++pos)
211        {
212                CompositorInstance *instance = chain->getCompositor(pos);
213                if(instance->getCompositor()->getName() == compositor)
214                {
215                        chain->setCompositorEnabled(pos, value);
216                        break;
217                }
218        }
219}
220
221}
Note: See TracBrowser for help on using the repository browser.