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

Revision 692, 8.1 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 "OgreCompositionTechnique.h"
27#include "OgreCompositionTargetPass.h"
28#include "OgreCompositorInstance.h"
29#include "OgreCompositorChain.h"
30#include "OgreCompositionPass.h"
31#include "OgreTextureManager.h"
32
33namespace Ogre {
34
35CompositionTechnique::CompositionTechnique(Compositor *parent):
36    mParent(parent)
37{
38    mOutputTarget = new CompositionTargetPass(this);
39}
40//-----------------------------------------------------------------------
41CompositionTechnique::~CompositionTechnique()
42{
43        /// Destroy all instances by removing them from their chain
44        /// CompositorChain::removeInstance also calls destroyInstance
45        Instances copy = mInstances;
46        for(Instances::iterator i=copy.begin(); i!=copy.end(); ++i)
47                (*i)->getChain()->_removeInstance(*i);
48
49    removeAllTextureDefinitions();
50    removeAllTargetPasses();
51    delete mOutputTarget;
52}
53//-----------------------------------------------------------------------
54CompositionTechnique::TextureDefinition *CompositionTechnique::createTextureDefinition(const String &name)
55{
56    TextureDefinition *t = new TextureDefinition();
57    t->name = name;
58    mTextureDefinitions.push_back(t);
59    return t;
60}
61//-----------------------------------------------------------------------
62
63void CompositionTechnique::removeTextureDefinition(size_t index)
64{
65    assert (index < mTextureDefinitions.size() && "Index out of bounds.");
66    TextureDefinitions::iterator i = mTextureDefinitions.begin() + index;
67    delete(*i);
68    mTextureDefinitions.erase(i);
69}
70//-----------------------------------------------------------------------
71
72CompositionTechnique::TextureDefinition *CompositionTechnique::getTextureDefinition(size_t index)
73{
74    assert (index < mTextureDefinitions.size() && "Index out of bounds.");
75    return mTextureDefinitions[index];
76}
77//-----------------------------------------------------------------------
78
79size_t CompositionTechnique::getNumTextureDefinitions()
80{
81    return mTextureDefinitions.size();
82}
83//-----------------------------------------------------------------------
84void CompositionTechnique::removeAllTextureDefinitions()
85{
86    TextureDefinitions::iterator i, iend;
87    iend = mTextureDefinitions.end();
88    for (i = mTextureDefinitions.begin(); i != iend; ++i)
89    {
90        delete(*i);
91    }
92    mTextureDefinitions.clear();
93}
94//-----------------------------------------------------------------------
95CompositionTechnique::TextureDefinitionIterator CompositionTechnique::getTextureDefinitionIterator(void)
96{
97    return TextureDefinitionIterator(mTextureDefinitions.begin(), mTextureDefinitions.end());
98}
99
100//-----------------------------------------------------------------------
101CompositionTargetPass *CompositionTechnique::createTargetPass()
102{
103    CompositionTargetPass *t = new CompositionTargetPass(this);
104    mTargetPasses.push_back(t);
105    return t;
106}
107//-----------------------------------------------------------------------
108
109void CompositionTechnique::removeTargetPass(size_t index)
110{
111    assert (index < mTargetPasses.size() && "Index out of bounds.");
112    TargetPasses::iterator i = mTargetPasses.begin() + index;
113    delete(*i);
114    mTargetPasses.erase(i);
115}
116//-----------------------------------------------------------------------
117
118CompositionTargetPass *CompositionTechnique::getTargetPass(size_t index)
119{
120    assert (index < mTargetPasses.size() && "Index out of bounds.");
121    return mTargetPasses[index];
122}
123//-----------------------------------------------------------------------
124
125size_t CompositionTechnique::getNumTargetPasses()
126{
127    return mTargetPasses.size();
128}
129//-----------------------------------------------------------------------
130void CompositionTechnique::removeAllTargetPasses()
131{
132    TargetPasses::iterator i, iend;
133    iend = mTargetPasses.end();
134    for (i = mTargetPasses.begin(); i != iend; ++i)
135    {
136        delete(*i);
137    }
138    mTargetPasses.clear();
139}
140//-----------------------------------------------------------------------
141CompositionTechnique::TargetPassIterator CompositionTechnique::getTargetPassIterator(void)
142{
143    return TargetPassIterator(mTargetPasses.begin(), mTargetPasses.end());
144}
145//-----------------------------------------------------------------------
146CompositionTargetPass *CompositionTechnique::getOutputTargetPass()
147{
148    return mOutputTarget;
149}
150//-----------------------------------------------------------------------
151bool CompositionTechnique::isSupported(bool acceptTextureDegradation)
152{
153        // A technique is supported if all materials referenced have a supported
154        // technique, and the intermediate texture formats requested are supported
155        // Material support is a cast-iron requirement, but if no texture formats
156        // are directly supported we can let the rendersystem create the closest
157        // match for the least demanding technique
158       
159
160    TargetPasses::iterator pi, piend;
161    piend = mTargetPasses.end();
162    for (pi = mTargetPasses.begin(); pi != piend; ++pi)
163    {
164                CompositionTargetPass* targetPass = *pi;
165                CompositionTargetPass::PassIterator passi = targetPass->getPassIterator();
166
167                while (passi.hasMoreElements())
168                {
169                        CompositionPass* pass = passi.getNext();
170                        if (pass->getType() == CompositionPass::PT_RENDERQUAD)
171                        {
172                                MaterialPtr mat = pass->getMaterial();
173                                if (mat.isNull())
174                                {
175                                        return false;
176                                }
177                                else
178                                {
179                                        mat->compile();
180                                        if (mat->getNumSupportedTechniques() == 0)
181                                        {
182                                                return false;
183                                        }
184                                }
185                        }
186
187                }
188
189
190        }
191       
192    TextureDefinitions::iterator i, iend;
193    iend = mTextureDefinitions.end();
194        TextureManager& texMgr = TextureManager::getSingleton();
195    for (i = mTextureDefinitions.begin(); i != iend; ++i)
196    {
197                TextureDefinition* td = *i;
198
199                // Check whether equivalent supported
200                if(acceptTextureDegradation)
201                {
202                        // Don't care about exact format so long as something is supported
203                        if(texMgr.getNativeFormat(TEX_TYPE_2D, td->format, TU_RENDERTARGET) == PF_UNKNOWN)
204                        {
205                                return false;
206                        }
207                }
208                else
209                {
210                        // Need a format which is the same number of bits to pass
211                        if (!texMgr.isEquivalentFormatSupported(TEX_TYPE_2D, td->format, TU_RENDERTARGET))
212                        {
213                                return false;
214                        }       
215                }
216        }
217       
218        // Must be ok
219        return true;
220}
221//-----------------------------------------------------------------------
222CompositorInstance *CompositionTechnique::createInstance(CompositorChain *chain)
223{
224        CompositorInstance *mew = new CompositorInstance(mParent, this, chain);
225        mInstances.push_back(mew);
226    return mew;
227}
228//-----------------------------------------------------------------------
229void CompositionTechnique::destroyInstance(CompositorInstance *instance)
230{
231    assert(instance->getTechnique() == this);
232        /// Erase from list of instances
233        mInstances.erase(std::find(mInstances.begin(), mInstances.end(), instance));
234    delete instance;
235}
236//-----------------------------------------------------------------------
237Compositor *CompositionTechnique::getParent()
238{
239    return mParent;
240}
241
242}
Note: See TracBrowser for help on using the repository browser.