[3] | 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 "OgreUnifiedHighLevelGpuProgram.h" |
---|
| 31 | #include "OgreString.h" |
---|
| 32 | #include "OgreException.h" |
---|
| 33 | #include "OgreGpuProgramManager.h" |
---|
| 34 | |
---|
| 35 | namespace Ogre |
---|
| 36 | { |
---|
| 37 | //----------------------------------------------------------------------- |
---|
| 38 | UnifiedHighLevelGpuProgram::CmdDelegate UnifiedHighLevelGpuProgram::msCmdDelegate; |
---|
| 39 | static const String sLanguage = "unified"; |
---|
| 40 | //----------------------------------------------------------------------- |
---|
| 41 | //----------------------------------------------------------------------- |
---|
| 42 | UnifiedHighLevelGpuProgram::UnifiedHighLevelGpuProgram( |
---|
| 43 | ResourceManager* creator, const String& name, ResourceHandle handle, |
---|
| 44 | const String& group, bool isManual, ManualResourceLoader* loader) |
---|
| 45 | :HighLevelGpuProgram(creator, name, handle, group, isManual, loader) |
---|
| 46 | { |
---|
| 47 | if (createParamDictionary("UnifiedHighLevelGpuProgram")) |
---|
| 48 | { |
---|
| 49 | setupBaseParamDictionary(); |
---|
| 50 | |
---|
| 51 | ParamDictionary* dict = getParamDictionary(); |
---|
| 52 | |
---|
| 53 | dict->addParameter(ParameterDef("delegate", |
---|
| 54 | "Additional delegate programs containing implementations.", |
---|
| 55 | PT_STRING),&msCmdDelegate); |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | } |
---|
| 59 | //----------------------------------------------------------------------- |
---|
| 60 | UnifiedHighLevelGpuProgram::~UnifiedHighLevelGpuProgram() |
---|
| 61 | { |
---|
| 62 | |
---|
| 63 | } |
---|
| 64 | //----------------------------------------------------------------------- |
---|
| 65 | void UnifiedHighLevelGpuProgram::chooseDelegate() const |
---|
| 66 | { |
---|
| 67 | OGRE_LOCK_AUTO_MUTEX |
---|
| 68 | |
---|
| 69 | mChosenDelegate.setNull(); |
---|
| 70 | |
---|
| 71 | for (StringVector::const_iterator i = mDelegateNames.begin(); |
---|
| 72 | i != mDelegateNames.end(); ++i) |
---|
| 73 | { |
---|
| 74 | HighLevelGpuProgramPtr deleg = |
---|
| 75 | HighLevelGpuProgramManager::getSingleton().getByName(*i); |
---|
| 76 | |
---|
| 77 | // Silently ignore missing links |
---|
| 78 | if(!deleg.isNull() |
---|
| 79 | && deleg->isSupported()) |
---|
| 80 | { |
---|
| 81 | mChosenDelegate = deleg; |
---|
| 82 | break; |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | } |
---|
| 88 | //----------------------------------------------------------------------- |
---|
| 89 | const HighLevelGpuProgramPtr& UnifiedHighLevelGpuProgram::_getDelegate() const |
---|
| 90 | { |
---|
| 91 | if (mChosenDelegate.isNull()) |
---|
| 92 | { |
---|
| 93 | chooseDelegate(); |
---|
| 94 | } |
---|
| 95 | return mChosenDelegate; |
---|
| 96 | } |
---|
| 97 | //----------------------------------------------------------------------- |
---|
| 98 | void UnifiedHighLevelGpuProgram::addDelegateProgram(const String& name) |
---|
| 99 | { |
---|
| 100 | OGRE_LOCK_AUTO_MUTEX |
---|
| 101 | |
---|
| 102 | mDelegateNames.push_back(name); |
---|
| 103 | |
---|
| 104 | // reset chosen delegate |
---|
| 105 | mChosenDelegate.setNull(); |
---|
| 106 | |
---|
| 107 | } |
---|
| 108 | //----------------------------------------------------------------------- |
---|
| 109 | void UnifiedHighLevelGpuProgram::clearDelegatePrograms() |
---|
| 110 | { |
---|
| 111 | OGRE_LOCK_AUTO_MUTEX |
---|
| 112 | |
---|
| 113 | mDelegateNames.clear(); |
---|
| 114 | mChosenDelegate.setNull(); |
---|
| 115 | |
---|
| 116 | } |
---|
| 117 | //----------------------------------------------------------------------- |
---|
| 118 | const String& UnifiedHighLevelGpuProgram::getLanguage(void) const |
---|
| 119 | { |
---|
| 120 | return sLanguage; |
---|
| 121 | } |
---|
| 122 | //----------------------------------------------------------------------- |
---|
| 123 | GpuProgramParametersSharedPtr UnifiedHighLevelGpuProgram::createParameters(void) |
---|
| 124 | { |
---|
| 125 | if (isSupported()) |
---|
| 126 | { |
---|
| 127 | return _getDelegate()->createParameters(); |
---|
| 128 | } |
---|
| 129 | else |
---|
| 130 | { |
---|
| 131 | // return a default set |
---|
| 132 | GpuProgramParametersSharedPtr params = GpuProgramManager::getSingleton().createParameters(); |
---|
| 133 | // avoid any errors on parameter names that don't exist |
---|
| 134 | params->setIgnoreMissingParams(true); |
---|
| 135 | return params; |
---|
| 136 | } |
---|
| 137 | } |
---|
| 138 | //----------------------------------------------------------------------- |
---|
| 139 | GpuProgram* UnifiedHighLevelGpuProgram::_getBindingDelegate(void) |
---|
| 140 | { |
---|
| 141 | if (!_getDelegate().isNull()) |
---|
| 142 | return _getDelegate()->_getBindingDelegate(); |
---|
| 143 | else |
---|
| 144 | return 0; |
---|
| 145 | } |
---|
| 146 | //----------------------------------------------------------------------- |
---|
| 147 | bool UnifiedHighLevelGpuProgram::isSupported(void) const |
---|
| 148 | { |
---|
| 149 | // Supported if one of the delegates is |
---|
| 150 | return !(_getDelegate().isNull()); |
---|
| 151 | } |
---|
| 152 | //----------------------------------------------------------------------- |
---|
| 153 | bool UnifiedHighLevelGpuProgram::isSkeletalAnimationIncluded(void) const |
---|
| 154 | { |
---|
| 155 | if (!_getDelegate().isNull()) |
---|
| 156 | return _getDelegate()->isSkeletalAnimationIncluded(); |
---|
| 157 | else |
---|
| 158 | return false; |
---|
| 159 | } |
---|
| 160 | //----------------------------------------------------------------------- |
---|
| 161 | bool UnifiedHighLevelGpuProgram::isMorphAnimationIncluded(void) const |
---|
| 162 | { |
---|
| 163 | if (!_getDelegate().isNull()) |
---|
| 164 | return _getDelegate()->isMorphAnimationIncluded(); |
---|
| 165 | else |
---|
| 166 | return false; |
---|
| 167 | } |
---|
| 168 | //----------------------------------------------------------------------- |
---|
| 169 | bool UnifiedHighLevelGpuProgram::isPoseAnimationIncluded(void) const |
---|
| 170 | { |
---|
| 171 | if (!_getDelegate().isNull()) |
---|
| 172 | return _getDelegate()->isPoseAnimationIncluded(); |
---|
| 173 | else |
---|
| 174 | return false; |
---|
| 175 | } |
---|
| 176 | //----------------------------------------------------------------------- |
---|
| 177 | bool UnifiedHighLevelGpuProgram::isVertexTextureFetchRequired(void) const |
---|
| 178 | { |
---|
| 179 | if (!_getDelegate().isNull()) |
---|
| 180 | return _getDelegate()->isVertexTextureFetchRequired(); |
---|
| 181 | else |
---|
| 182 | return false; |
---|
| 183 | } |
---|
| 184 | //----------------------------------------------------------------------- |
---|
| 185 | GpuProgramParametersSharedPtr UnifiedHighLevelGpuProgram::getDefaultParameters(void) |
---|
| 186 | { |
---|
| 187 | if (!_getDelegate().isNull()) |
---|
| 188 | return _getDelegate()->getDefaultParameters(); |
---|
| 189 | else |
---|
| 190 | return GpuProgramParametersSharedPtr(); |
---|
| 191 | } |
---|
| 192 | //----------------------------------------------------------------------- |
---|
| 193 | bool UnifiedHighLevelGpuProgram::hasDefaultParameters(void) const |
---|
| 194 | { |
---|
| 195 | if (!_getDelegate().isNull()) |
---|
| 196 | return _getDelegate()->hasDefaultParameters(); |
---|
| 197 | else |
---|
| 198 | return false; |
---|
| 199 | } |
---|
| 200 | //----------------------------------------------------------------------- |
---|
| 201 | bool UnifiedHighLevelGpuProgram::getPassSurfaceAndLightStates(void) const |
---|
| 202 | { |
---|
| 203 | if (!_getDelegate().isNull()) |
---|
| 204 | return _getDelegate()->getPassSurfaceAndLightStates(); |
---|
| 205 | else |
---|
| 206 | return false; |
---|
| 207 | } |
---|
| 208 | //----------------------------------------------------------------------- |
---|
| 209 | bool UnifiedHighLevelGpuProgram::hasCompileError(void) const |
---|
| 210 | { |
---|
| 211 | if (_getDelegate().isNull()) |
---|
| 212 | { |
---|
| 213 | return false; |
---|
| 214 | } |
---|
| 215 | else |
---|
| 216 | { |
---|
| 217 | return _getDelegate()->hasCompileError(); |
---|
| 218 | } |
---|
| 219 | } |
---|
| 220 | //----------------------------------------------------------------------- |
---|
| 221 | void UnifiedHighLevelGpuProgram::resetCompileError(void) |
---|
| 222 | { |
---|
| 223 | if (!_getDelegate().isNull()) |
---|
| 224 | _getDelegate()->resetCompileError(); |
---|
| 225 | } |
---|
| 226 | //----------------------------------------------------------------------- |
---|
| 227 | void UnifiedHighLevelGpuProgram::load(bool backgroundThread) |
---|
| 228 | { |
---|
| 229 | if (!_getDelegate().isNull()) |
---|
| 230 | _getDelegate()->load(backgroundThread); |
---|
| 231 | } |
---|
| 232 | //----------------------------------------------------------------------- |
---|
| 233 | void UnifiedHighLevelGpuProgram::reload(void) |
---|
| 234 | { |
---|
| 235 | if (!_getDelegate().isNull()) |
---|
| 236 | _getDelegate()->reload(); |
---|
| 237 | } |
---|
| 238 | //----------------------------------------------------------------------- |
---|
| 239 | bool UnifiedHighLevelGpuProgram::isReloadable(void) const |
---|
| 240 | { |
---|
| 241 | if (!_getDelegate().isNull()) |
---|
| 242 | return _getDelegate()->isReloadable(); |
---|
| 243 | else |
---|
| 244 | return true; |
---|
| 245 | } |
---|
| 246 | //----------------------------------------------------------------------- |
---|
| 247 | void UnifiedHighLevelGpuProgram::unload(void) |
---|
| 248 | { |
---|
| 249 | if (!_getDelegate().isNull()) |
---|
| 250 | _getDelegate()->unload(); |
---|
| 251 | } |
---|
| 252 | //----------------------------------------------------------------------- |
---|
| 253 | bool UnifiedHighLevelGpuProgram::isLoaded(void) const |
---|
| 254 | { |
---|
| 255 | if (!_getDelegate().isNull()) |
---|
| 256 | return _getDelegate()->isLoaded(); |
---|
| 257 | else |
---|
| 258 | return false; |
---|
| 259 | } |
---|
| 260 | //----------------------------------------------------------------------- |
---|
| 261 | Resource::LoadingState UnifiedHighLevelGpuProgram::isLoading() const |
---|
| 262 | { |
---|
| 263 | if (!_getDelegate().isNull()) |
---|
| 264 | return _getDelegate()->isLoading(); |
---|
| 265 | else |
---|
| 266 | return Resource::LOADSTATE_UNLOADED; |
---|
| 267 | } |
---|
| 268 | //----------------------------------------------------------------------- |
---|
| 269 | Resource::LoadingState UnifiedHighLevelGpuProgram::getLoadingState() const |
---|
| 270 | { |
---|
| 271 | if (!_getDelegate().isNull()) |
---|
| 272 | return _getDelegate()->getLoadingState(); |
---|
| 273 | else |
---|
| 274 | return Resource::LOADSTATE_UNLOADED; |
---|
| 275 | } |
---|
| 276 | //----------------------------------------------------------------------- |
---|
| 277 | size_t UnifiedHighLevelGpuProgram::getSize(void) const |
---|
| 278 | { |
---|
| 279 | if (!_getDelegate().isNull()) |
---|
| 280 | return _getDelegate()->getSize(); |
---|
| 281 | else |
---|
| 282 | return 0; |
---|
| 283 | } |
---|
| 284 | //----------------------------------------------------------------------- |
---|
| 285 | void UnifiedHighLevelGpuProgram::touch(void) |
---|
| 286 | { |
---|
| 287 | if (!_getDelegate().isNull()) |
---|
| 288 | _getDelegate()->touch(); |
---|
| 289 | } |
---|
| 290 | //----------------------------------------------------------------------- |
---|
| 291 | bool UnifiedHighLevelGpuProgram::isBackgroundLoaded(void) const |
---|
| 292 | { |
---|
| 293 | if (!_getDelegate().isNull()) |
---|
| 294 | return _getDelegate()->isBackgroundLoaded(); |
---|
| 295 | else |
---|
| 296 | return false; |
---|
| 297 | } |
---|
| 298 | //----------------------------------------------------------------------- |
---|
| 299 | void UnifiedHighLevelGpuProgram::setBackgroundLoaded(bool bl) |
---|
| 300 | { |
---|
| 301 | if (!_getDelegate().isNull()) |
---|
| 302 | _getDelegate()->setBackgroundLoaded(bl); |
---|
| 303 | } |
---|
| 304 | //----------------------------------------------------------------------- |
---|
| 305 | void UnifiedHighLevelGpuProgram::escalateLoading() |
---|
| 306 | { |
---|
| 307 | if (!_getDelegate().isNull()) |
---|
| 308 | _getDelegate()->escalateLoading(); |
---|
| 309 | } |
---|
| 310 | //----------------------------------------------------------------------- |
---|
| 311 | void UnifiedHighLevelGpuProgram::addListener(Resource::Listener* lis) |
---|
| 312 | { |
---|
| 313 | if (!_getDelegate().isNull()) |
---|
| 314 | _getDelegate()->addListener(lis); |
---|
| 315 | } |
---|
| 316 | //----------------------------------------------------------------------- |
---|
| 317 | void UnifiedHighLevelGpuProgram::removeListener(Resource::Listener* lis) |
---|
| 318 | { |
---|
| 319 | if (!_getDelegate().isNull()) |
---|
| 320 | _getDelegate()->removeListener(lis); |
---|
| 321 | } |
---|
| 322 | //----------------------------------------------------------------------- |
---|
| 323 | void UnifiedHighLevelGpuProgram::createLowLevelImpl(void) |
---|
| 324 | { |
---|
| 325 | OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, |
---|
| 326 | "This method should never get called!", |
---|
| 327 | "UnifiedHighLevelGpuProgram::createLowLevelImpl"); |
---|
| 328 | } |
---|
| 329 | //----------------------------------------------------------------------- |
---|
| 330 | void UnifiedHighLevelGpuProgram::unloadHighLevelImpl(void) |
---|
| 331 | { |
---|
| 332 | OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, |
---|
| 333 | "This method should never get called!", |
---|
| 334 | "UnifiedHighLevelGpuProgram::unloadHighLevelImpl"); |
---|
| 335 | } |
---|
| 336 | //----------------------------------------------------------------------- |
---|
| 337 | void UnifiedHighLevelGpuProgram::buildConstantDefinitions() const |
---|
| 338 | { |
---|
| 339 | OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, |
---|
| 340 | "This method should never get called!", |
---|
| 341 | "UnifiedHighLevelGpuProgram::buildConstantDefinitions"); |
---|
| 342 | } |
---|
| 343 | //----------------------------------------------------------------------- |
---|
| 344 | void UnifiedHighLevelGpuProgram::loadFromSource(void) |
---|
| 345 | { |
---|
| 346 | OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, |
---|
| 347 | "This method should never get called!", |
---|
| 348 | "UnifiedHighLevelGpuProgram::loadFromSource"); |
---|
| 349 | } |
---|
| 350 | //----------------------------------------------------------------------- |
---|
| 351 | //----------------------------------------------------------------------- |
---|
| 352 | String UnifiedHighLevelGpuProgram::CmdDelegate::doGet(const void* target) const |
---|
| 353 | { |
---|
| 354 | // Can't do this (not one delegate), shouldn't matter |
---|
| 355 | return StringUtil::BLANK; |
---|
| 356 | } |
---|
| 357 | //----------------------------------------------------------------------- |
---|
| 358 | void UnifiedHighLevelGpuProgram::CmdDelegate::doSet(void* target, const String& val) |
---|
| 359 | { |
---|
| 360 | static_cast<UnifiedHighLevelGpuProgram*>(target)->addDelegateProgram(val); |
---|
| 361 | } |
---|
| 362 | //----------------------------------------------------------------------- |
---|
| 363 | //----------------------------------------------------------------------- |
---|
| 364 | UnifiedHighLevelGpuProgramFactory::UnifiedHighLevelGpuProgramFactory() |
---|
| 365 | { |
---|
| 366 | } |
---|
| 367 | //----------------------------------------------------------------------- |
---|
| 368 | UnifiedHighLevelGpuProgramFactory::~UnifiedHighLevelGpuProgramFactory() |
---|
| 369 | { |
---|
| 370 | } |
---|
| 371 | //----------------------------------------------------------------------- |
---|
| 372 | const String& UnifiedHighLevelGpuProgramFactory::getLanguage(void) const |
---|
| 373 | { |
---|
| 374 | return sLanguage; |
---|
| 375 | } |
---|
| 376 | //----------------------------------------------------------------------- |
---|
| 377 | HighLevelGpuProgram* UnifiedHighLevelGpuProgramFactory::create(ResourceManager* creator, |
---|
| 378 | const String& name, ResourceHandle handle, |
---|
| 379 | const String& group, bool isManual, ManualResourceLoader* loader) |
---|
| 380 | { |
---|
| 381 | return new UnifiedHighLevelGpuProgram(creator, name, handle, group, isManual, loader); |
---|
| 382 | } |
---|
| 383 | //----------------------------------------------------------------------- |
---|
| 384 | void UnifiedHighLevelGpuProgramFactory::destroy(HighLevelGpuProgram* prog) |
---|
| 385 | { |
---|
| 386 | delete prog; |
---|
| 387 | } |
---|
| 388 | //----------------------------------------------------------------------- |
---|
| 389 | |
---|
| 390 | } |
---|
| 391 | |
---|