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