/src/ogre/OgreMain/src/OgreCompositionTechnique.cpp
Line | Count | Source |
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-2014 Torus Knot Software Ltd |
8 | | |
9 | | Permission is hereby granted, free of charge, to any person obtaining a copy |
10 | | of this software and associated documentation files (the "Software"), to deal |
11 | | in the Software without restriction, including without limitation the rights |
12 | | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
13 | | copies of the Software, and to permit persons to whom the Software is |
14 | | furnished to do so, subject to the following conditions: |
15 | | |
16 | | The above copyright notice and this permission notice shall be included in |
17 | | all copies or substantial portions of the Software. |
18 | | |
19 | | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
20 | | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
21 | | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
22 | | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
23 | | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
24 | | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
25 | | THE SOFTWARE. |
26 | | ----------------------------------------------------------------------------- |
27 | | */ |
28 | | #include "OgreStableHeaders.h" |
29 | | #include "OgreCompositionTargetPass.h" |
30 | | |
31 | | namespace Ogre { |
32 | | |
33 | | CompositionTechnique::CompositionTechnique(Compositor *parent): |
34 | 0 | mParent(parent) |
35 | 0 | { |
36 | 0 | mOutputTarget = OGRE_NEW CompositionTargetPass(this); |
37 | 0 | } |
38 | | //----------------------------------------------------------------------- |
39 | | CompositionTechnique::~CompositionTechnique() |
40 | 0 | { |
41 | 0 | removeAllTextureDefinitions(); |
42 | 0 | removeAllTargetPasses(); |
43 | 0 | OGRE_DELETE mOutputTarget; |
44 | 0 | } |
45 | | //----------------------------------------------------------------------- |
46 | | CompositionTechnique::TextureDefinition *CompositionTechnique::createTextureDefinition(const String &name) |
47 | 0 | { |
48 | 0 | if(getTextureDefinition(name)) |
49 | 0 | OGRE_EXCEPT(Exception::ERR_DUPLICATE_ITEM, "Texture '"+name+"' already exists"); |
50 | | |
51 | 0 | TextureDefinition *t = OGRE_NEW TextureDefinition(); |
52 | 0 | t->name = name; |
53 | 0 | mTextureDefinitions.push_back(t); |
54 | 0 | return t; |
55 | 0 | } |
56 | | //----------------------------------------------------------------------- |
57 | | |
58 | | void CompositionTechnique::removeTextureDefinition(size_t index) |
59 | 0 | { |
60 | 0 | assert (index < mTextureDefinitions.size() && "Index out of bounds."); |
61 | 0 | TextureDefinitions::iterator i = mTextureDefinitions.begin() + index; |
62 | 0 | OGRE_DELETE (*i); |
63 | 0 | mTextureDefinitions.erase(i); |
64 | 0 | } |
65 | | //--------------------------------------------------------------------- |
66 | | CompositionTechnique::TextureDefinition *CompositionTechnique::getTextureDefinition(const String& name) const |
67 | 0 | { |
68 | 0 | for (auto *t : mTextureDefinitions) |
69 | 0 | { |
70 | 0 | if (t->name == name) |
71 | 0 | return t; |
72 | 0 | } |
73 | 0 | return 0; |
74 | |
|
75 | 0 | } |
76 | | //----------------------------------------------------------------------- |
77 | | void CompositionTechnique::removeAllTextureDefinitions() |
78 | 0 | { |
79 | 0 | for (auto *t : mTextureDefinitions) |
80 | 0 | { |
81 | 0 | OGRE_DELETE t; |
82 | 0 | } |
83 | 0 | mTextureDefinitions.clear(); |
84 | 0 | } |
85 | | //----------------------------------------------------------------------- |
86 | | CompositionTechnique::TextureDefinitionIterator CompositionTechnique::getTextureDefinitionIterator(void) |
87 | 0 | { |
88 | 0 | return TextureDefinitionIterator(mTextureDefinitions.begin(), mTextureDefinitions.end()); |
89 | 0 | } |
90 | | |
91 | | //----------------------------------------------------------------------- |
92 | | CompositionTargetPass *CompositionTechnique::createTargetPass() |
93 | 0 | { |
94 | 0 | CompositionTargetPass *t = OGRE_NEW CompositionTargetPass(this); |
95 | 0 | mTargetPasses.push_back(t); |
96 | 0 | return t; |
97 | 0 | } |
98 | | //----------------------------------------------------------------------- |
99 | | |
100 | | void CompositionTechnique::removeTargetPass(size_t index) |
101 | 0 | { |
102 | 0 | assert (index < mTargetPasses.size() && "Index out of bounds."); |
103 | 0 | TargetPasses::iterator i = mTargetPasses.begin() + index; |
104 | 0 | OGRE_DELETE (*i); |
105 | 0 | mTargetPasses.erase(i); |
106 | 0 | } |
107 | | //----------------------------------------------------------------------- |
108 | | void CompositionTechnique::removeAllTargetPasses() |
109 | 0 | { |
110 | 0 | for (auto *t : mTargetPasses) |
111 | 0 | { |
112 | 0 | OGRE_DELETE t; |
113 | 0 | } |
114 | 0 | mTargetPasses.clear(); |
115 | 0 | } |
116 | | //----------------------------------------------------------------------- |
117 | | CompositionTechnique::TargetPassIterator CompositionTechnique::getTargetPassIterator(void) |
118 | 0 | { |
119 | 0 | return TargetPassIterator(mTargetPasses.begin(), mTargetPasses.end()); |
120 | 0 | } |
121 | | //----------------------------------------------------------------------- |
122 | | bool CompositionTechnique::isSupported(bool acceptTextureDegradation) |
123 | 0 | { |
124 | | // A technique is supported if all materials referenced have a supported |
125 | | // technique, and the intermediate texture formats requested are supported |
126 | | // Material support is a cast-iron requirement, but if no texture formats |
127 | | // are directly supported we can let the rendersystem create the closest |
128 | | // match for the least demanding technique |
129 | | |
130 | | |
131 | | // Check output target pass is supported |
132 | 0 | if (!mOutputTarget->_isSupported()) |
133 | 0 | { |
134 | 0 | return false; |
135 | 0 | } |
136 | | |
137 | | // Check all target passes is supported |
138 | 0 | for (auto *p : mTargetPasses) |
139 | 0 | { |
140 | 0 | if (!p->_isSupported()) |
141 | 0 | { |
142 | 0 | return false; |
143 | 0 | } |
144 | 0 | } |
145 | | |
146 | 0 | TextureManager& texMgr = TextureManager::getSingleton(); |
147 | 0 | for (auto *td : mTextureDefinitions) |
148 | 0 | { |
149 | | // Firstly check MRTs |
150 | 0 | if (td->formatList.size() > |
151 | 0 | Root::getSingleton().getRenderSystem()->getCapabilities()->getNumMultiRenderTargets()) |
152 | 0 | { |
153 | 0 | return false; |
154 | 0 | } |
155 | | |
156 | | |
157 | 0 | for (auto& pfi : td->formatList) |
158 | 0 | { |
159 | | // Check whether equivalent supported |
160 | | // Need a format which is the same number of bits to pass |
161 | 0 | bool accepted = texMgr.isEquivalentFormatSupported(td->type, pfi, TU_RENDERTARGET); |
162 | 0 | if(!accepted && acceptTextureDegradation) |
163 | 0 | { |
164 | | // Don't care about exact format so long as something is supported |
165 | 0 | accepted = texMgr.getNativeFormat(td->type, pfi, TU_RENDERTARGET) != PF_UNKNOWN; |
166 | 0 | } |
167 | |
|
168 | 0 | if(!accepted) |
169 | 0 | return false; |
170 | 0 | } |
171 | | |
172 | | //Check all render targets have same number of bits |
173 | 0 | if( Root::getSingleton().getRenderSystem()->getCapabilities()-> |
174 | 0 | hasCapability( RSC_MRT_SAME_BIT_DEPTHS ) && !td->formatList.empty() ) |
175 | 0 | { |
176 | 0 | PixelFormat nativeFormat = texMgr.getNativeFormat( td->type, td->formatList.front(), |
177 | 0 | TU_RENDERTARGET ); |
178 | 0 | size_t nativeBits = PixelUtil::getNumElemBits( nativeFormat ); |
179 | 0 | for( PixelFormatList::iterator pfi = td->formatList.begin()+1; |
180 | 0 | pfi != td->formatList.end(); ++pfi ) |
181 | 0 | { |
182 | 0 | PixelFormat nativeTmp = texMgr.getNativeFormat( td->type, *pfi, TU_RENDERTARGET ); |
183 | 0 | if( PixelUtil::getNumElemBits( nativeTmp ) != nativeBits ) |
184 | 0 | { |
185 | 0 | return false; |
186 | 0 | } |
187 | 0 | } |
188 | 0 | } |
189 | 0 | } |
190 | | |
191 | | // Must be ok |
192 | 0 | return true; |
193 | 0 | } |
194 | | //----------------------------------------------------------------------- |
195 | | Compositor *CompositionTechnique::getParent() |
196 | 0 | { |
197 | 0 | return mParent; |
198 | 0 | } |
199 | | //--------------------------------------------------------------------- |
200 | | void CompositionTechnique::setSchemeName(const String& schemeName) |
201 | 0 | { |
202 | 0 | mSchemeName = schemeName; |
203 | 0 | } |
204 | | |
205 | | } |