1 | /*
|
---|
2 | -----------------------------------------------------------------------------
|
---|
3 | This source file is part of OGRE
|
---|
4 | (Object-oriented Graphics Rendering Engine)
|
---|
5 | For the latest info, see http://www.ogre3d.org/
|
---|
6 |
|
---|
7 | Copyright (c) 2000-2005 The OGRE Team
|
---|
8 | Also see acknowledgements in Readme.html
|
---|
9 |
|
---|
10 | This program is free software; you can redistribute it and/or modify it under
|
---|
11 | the terms of the GNU Lesser General Public License as published by the Free Software
|
---|
12 | Foundation; either version 2 of the License, or (at your option) any later
|
---|
13 | version.
|
---|
14 |
|
---|
15 | This program is distributed in the hope that it will be useful, but WITHOUT
|
---|
16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
---|
17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
---|
18 |
|
---|
19 | You should have received a copy of the GNU Lesser General Public License along with
|
---|
20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
---|
21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to
|
---|
22 | http://www.gnu.org/copyleft/lesser.txt.
|
---|
23 | -----------------------------------------------------------------------------
|
---|
24 | */
|
---|
25 | #include "OgreStableHeaders.h"
|
---|
26 | #include "OgreCompositor.h"
|
---|
27 | #include "OgreCompositionTechnique.h"
|
---|
28 |
|
---|
29 | namespace Ogre {
|
---|
30 |
|
---|
31 | //-----------------------------------------------------------------------
|
---|
32 | Compositor::Compositor(ResourceManager* creator, const String& name, ResourceHandle handle,
|
---|
33 | const String& group, bool isManual, ManualResourceLoader* loader):
|
---|
34 | Resource(creator, name, handle, group, isManual, loader),
|
---|
35 | mCompilationRequired(true)
|
---|
36 | {
|
---|
37 | }
|
---|
38 | //-----------------------------------------------------------------------
|
---|
39 |
|
---|
40 | Compositor::~Compositor()
|
---|
41 | {
|
---|
42 | removeAllTechniques();
|
---|
43 | // have to call this here reather than in Resource destructor
|
---|
44 | // since calling virtual methods in base destructors causes crash
|
---|
45 | unload();
|
---|
46 | }
|
---|
47 | //-----------------------------------------------------------------------
|
---|
48 | CompositionTechnique *Compositor::createTechnique()
|
---|
49 | {
|
---|
50 | CompositionTechnique *t = new CompositionTechnique(this);
|
---|
51 | mTechniques.push_back(t);
|
---|
52 | mCompilationRequired = true;
|
---|
53 | return t;
|
---|
54 | }
|
---|
55 | //-----------------------------------------------------------------------
|
---|
56 |
|
---|
57 | void Compositor::removeTechnique(size_t index)
|
---|
58 | {
|
---|
59 | assert (index < mTechniques.size() && "Index out of bounds.");
|
---|
60 | Techniques::iterator i = mTechniques.begin() + index;
|
---|
61 | delete(*i);
|
---|
62 | mTechniques.erase(i);
|
---|
63 | mSupportedTechniques.clear();
|
---|
64 | mCompilationRequired = true;
|
---|
65 | }
|
---|
66 | //-----------------------------------------------------------------------
|
---|
67 |
|
---|
68 | CompositionTechnique *Compositor::getTechnique(size_t index)
|
---|
69 | {
|
---|
70 | assert (index < mTechniques.size() && "Index out of bounds.");
|
---|
71 | return mTechniques[index];
|
---|
72 | }
|
---|
73 | //-----------------------------------------------------------------------
|
---|
74 |
|
---|
75 | size_t Compositor::getNumTechniques()
|
---|
76 | {
|
---|
77 | return mTechniques.size();
|
---|
78 | }
|
---|
79 | //-----------------------------------------------------------------------
|
---|
80 | void Compositor::removeAllTechniques()
|
---|
81 | {
|
---|
82 | Techniques::iterator i, iend;
|
---|
83 | iend = mTechniques.end();
|
---|
84 | for (i = mTechniques.begin(); i != iend; ++i)
|
---|
85 | {
|
---|
86 | delete(*i);
|
---|
87 | }
|
---|
88 | mTechniques.clear();
|
---|
89 | mSupportedTechniques.clear();
|
---|
90 | mCompilationRequired = true;
|
---|
91 | }
|
---|
92 | //-----------------------------------------------------------------------
|
---|
93 | Compositor::TechniqueIterator Compositor::getTechniqueIterator(void)
|
---|
94 | {
|
---|
95 | return TechniqueIterator(mTechniques.begin(), mTechniques.end());
|
---|
96 | }
|
---|
97 | //-----------------------------------------------------------------------
|
---|
98 |
|
---|
99 | CompositionTechnique *Compositor::getSupportedTechnique(size_t index)
|
---|
100 | {
|
---|
101 | assert (index < mSupportedTechniques.size() && "Index out of bounds.");
|
---|
102 | return mSupportedTechniques[index];
|
---|
103 | }
|
---|
104 | //-----------------------------------------------------------------------
|
---|
105 |
|
---|
106 | size_t Compositor::getNumSupportedTechniques()
|
---|
107 | {
|
---|
108 | return mSupportedTechniques.size();
|
---|
109 | }
|
---|
110 | //-----------------------------------------------------------------------
|
---|
111 |
|
---|
112 | Compositor::TechniqueIterator Compositor::getSupportedTechniqueIterator(void)
|
---|
113 | {
|
---|
114 | return TechniqueIterator(mSupportedTechniques.begin(), mSupportedTechniques.end());
|
---|
115 | }
|
---|
116 | //-----------------------------------------------------------------------
|
---|
117 | void Compositor::loadImpl(void)
|
---|
118 | {
|
---|
119 | // compile if required
|
---|
120 | if (mCompilationRequired)
|
---|
121 | compile();
|
---|
122 | }
|
---|
123 | //-----------------------------------------------------------------------
|
---|
124 | void Compositor::unloadImpl(void)
|
---|
125 | {
|
---|
126 | }
|
---|
127 | //-----------------------------------------------------------------------
|
---|
128 | size_t Compositor::calculateSize(void) const
|
---|
129 | {
|
---|
130 | return 0;
|
---|
131 | }
|
---|
132 |
|
---|
133 | //-----------------------------------------------------------------------
|
---|
134 | void Compositor::compile()
|
---|
135 | {
|
---|
136 | /// Sift out supported techniques
|
---|
137 | mSupportedTechniques.clear();
|
---|
138 | Techniques::iterator i, iend;
|
---|
139 | iend = mTechniques.end();
|
---|
140 |
|
---|
141 | // Try looking for exact technique support with no texture fallback
|
---|
142 | for (i = mTechniques.begin(); i != iend; ++i)
|
---|
143 | {
|
---|
144 | // Look for exact texture support first
|
---|
145 | if((*i)->isSupported(false))
|
---|
146 | {
|
---|
147 | mSupportedTechniques.push_back(*i);
|
---|
148 | }
|
---|
149 | }
|
---|
150 |
|
---|
151 | if (mSupportedTechniques.empty())
|
---|
152 | {
|
---|
153 | // Check again, being more lenient with textures
|
---|
154 | for (i = mTechniques.begin(); i != iend; ++i)
|
---|
155 | {
|
---|
156 | // Allow texture support with degraded pixel format
|
---|
157 | if((*i)->isSupported(true))
|
---|
158 | {
|
---|
159 | mSupportedTechniques.push_back(*i);
|
---|
160 | }
|
---|
161 | }
|
---|
162 | }
|
---|
163 | mCompilationRequired = false;
|
---|
164 | }
|
---|
165 |
|
---|
166 | }
|
---|