Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/OgreMain/src/OgreCompositor.cpp @ 3

Last change on this file since 3 was 3, checked in by anonymous, 17 years ago

=update

File size: 5.5 KB
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-2006 Torus Knot Software Ltd
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
24You may alternatively use this source under the terms of a specific version of
25the OGRE Unrestricted License provided you have obtained such a license from
26Torus Knot Software Ltd.
27-----------------------------------------------------------------------------
28*/
29#include "OgreStableHeaders.h"
30#include "OgreCompositor.h"
31#include "OgreCompositionTechnique.h"
32
33namespace Ogre {
34
35//-----------------------------------------------------------------------
36Compositor::Compositor(ResourceManager* creator, const String& name, ResourceHandle handle,
37            const String& group, bool isManual, ManualResourceLoader* loader):
38    Resource(creator, name, handle, group, isManual, loader),
39    mCompilationRequired(true)
40{
41}
42//-----------------------------------------------------------------------
43
44Compositor::~Compositor()
45{
46    removeAllTechniques();
47    // have to call this here reather than in Resource destructor
48    // since calling virtual methods in base destructors causes crash
49    unload(); 
50}
51//-----------------------------------------------------------------------
52CompositionTechnique *Compositor::createTechnique()
53{
54    CompositionTechnique *t = new CompositionTechnique(this);
55    mTechniques.push_back(t);
56    mCompilationRequired = true;
57    return t;
58}
59//-----------------------------------------------------------------------
60
61void Compositor::removeTechnique(size_t index)
62{
63    assert (index < mTechniques.size() && "Index out of bounds.");
64    Techniques::iterator i = mTechniques.begin() + index;
65    delete(*i);
66    mTechniques.erase(i);
67    mSupportedTechniques.clear();
68    mCompilationRequired = true;
69}
70//-----------------------------------------------------------------------
71
72CompositionTechnique *Compositor::getTechnique(size_t index)
73{
74    assert (index < mTechniques.size() && "Index out of bounds.");
75    return mTechniques[index];
76}
77//-----------------------------------------------------------------------
78
79size_t Compositor::getNumTechniques()
80{
81    return mTechniques.size();
82}
83//-----------------------------------------------------------------------
84void Compositor::removeAllTechniques()
85{
86    Techniques::iterator i, iend;
87    iend = mTechniques.end();
88    for (i = mTechniques.begin(); i != iend; ++i)
89    {
90        delete(*i);
91    }
92    mTechniques.clear();
93    mSupportedTechniques.clear();
94    mCompilationRequired = true;
95}
96//-----------------------------------------------------------------------
97Compositor::TechniqueIterator Compositor::getTechniqueIterator(void)
98{
99    return TechniqueIterator(mTechniques.begin(), mTechniques.end());
100}
101//-----------------------------------------------------------------------
102
103CompositionTechnique *Compositor::getSupportedTechnique(size_t index)
104{
105    assert (index < mSupportedTechniques.size() && "Index out of bounds.");
106    return mSupportedTechniques[index];
107}
108//-----------------------------------------------------------------------
109
110size_t Compositor::getNumSupportedTechniques()
111{
112    return mSupportedTechniques.size();
113}
114//-----------------------------------------------------------------------
115
116Compositor::TechniqueIterator Compositor::getSupportedTechniqueIterator(void)
117{
118    return TechniqueIterator(mSupportedTechniques.begin(), mSupportedTechniques.end());
119}
120//-----------------------------------------------------------------------
121void Compositor::loadImpl(void)
122{
123    // compile if required
124    if (mCompilationRequired)
125        compile();
126}
127//-----------------------------------------------------------------------
128void Compositor::unloadImpl(void)
129{
130}
131//-----------------------------------------------------------------------
132size_t Compositor::calculateSize(void) const
133{
134    return 0;
135}
136
137//-----------------------------------------------------------------------
138void Compositor::compile()
139{
140    /// Sift out supported techniques
141    mSupportedTechniques.clear();
142    Techniques::iterator i, iend;
143    iend = mTechniques.end();
144
145        // Try looking for exact technique support with no texture fallback
146    for (i = mTechniques.begin(); i != iend; ++i)
147    {
148        // Look for exact texture support first
149        if((*i)->isSupported(false))
150        {
151            mSupportedTechniques.push_back(*i);
152        }
153    }
154
155        if (mSupportedTechniques.empty())
156        {
157                // Check again, being more lenient with textures
158                for (i = mTechniques.begin(); i != iend; ++i)
159                {
160                        // Allow texture support with degraded pixel format
161                        if((*i)->isSupported(true))
162                        {
163                                mSupportedTechniques.push_back(*i);
164                        }
165                }
166        }
167    mCompilationRequired = false;
168}
169
170}
Note: See TracBrowser for help on using the repository browser.