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 "OgreCompositor.h" |
---|
31 | #include "OgreCompositionTechnique.h" |
---|
32 | |
---|
33 | namespace Ogre { |
---|
34 | |
---|
35 | //----------------------------------------------------------------------- |
---|
36 | Compositor::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 | |
---|
44 | Compositor::~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 | //----------------------------------------------------------------------- |
---|
52 | CompositionTechnique *Compositor::createTechnique() |
---|
53 | { |
---|
54 | CompositionTechnique *t = new CompositionTechnique(this); |
---|
55 | mTechniques.push_back(t); |
---|
56 | mCompilationRequired = true; |
---|
57 | return t; |
---|
58 | } |
---|
59 | //----------------------------------------------------------------------- |
---|
60 | |
---|
61 | void 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 | |
---|
72 | CompositionTechnique *Compositor::getTechnique(size_t index) |
---|
73 | { |
---|
74 | assert (index < mTechniques.size() && "Index out of bounds."); |
---|
75 | return mTechniques[index]; |
---|
76 | } |
---|
77 | //----------------------------------------------------------------------- |
---|
78 | |
---|
79 | size_t Compositor::getNumTechniques() |
---|
80 | { |
---|
81 | return mTechniques.size(); |
---|
82 | } |
---|
83 | //----------------------------------------------------------------------- |
---|
84 | void 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 | //----------------------------------------------------------------------- |
---|
97 | Compositor::TechniqueIterator Compositor::getTechniqueIterator(void) |
---|
98 | { |
---|
99 | return TechniqueIterator(mTechniques.begin(), mTechniques.end()); |
---|
100 | } |
---|
101 | //----------------------------------------------------------------------- |
---|
102 | |
---|
103 | CompositionTechnique *Compositor::getSupportedTechnique(size_t index) |
---|
104 | { |
---|
105 | assert (index < mSupportedTechniques.size() && "Index out of bounds."); |
---|
106 | return mSupportedTechniques[index]; |
---|
107 | } |
---|
108 | //----------------------------------------------------------------------- |
---|
109 | |
---|
110 | size_t Compositor::getNumSupportedTechniques() |
---|
111 | { |
---|
112 | return mSupportedTechniques.size(); |
---|
113 | } |
---|
114 | //----------------------------------------------------------------------- |
---|
115 | |
---|
116 | Compositor::TechniqueIterator Compositor::getSupportedTechniqueIterator(void) |
---|
117 | { |
---|
118 | return TechniqueIterator(mSupportedTechniques.begin(), mSupportedTechniques.end()); |
---|
119 | } |
---|
120 | //----------------------------------------------------------------------- |
---|
121 | void Compositor::loadImpl(void) |
---|
122 | { |
---|
123 | // compile if required |
---|
124 | if (mCompilationRequired) |
---|
125 | compile(); |
---|
126 | } |
---|
127 | //----------------------------------------------------------------------- |
---|
128 | void Compositor::unloadImpl(void) |
---|
129 | { |
---|
130 | } |
---|
131 | //----------------------------------------------------------------------- |
---|
132 | size_t Compositor::calculateSize(void) const |
---|
133 | { |
---|
134 | return 0; |
---|
135 | } |
---|
136 | |
---|
137 | //----------------------------------------------------------------------- |
---|
138 | void 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 | } |
---|