PageRenderTime 753ms CodeModel.GetById 33ms RepoModel.GetById 0ms app.codeStats 0ms

/Core/Dependencies/OgreSource/OgreMain/src/OgreUnifiedHighLevelGpuProgram.cpp

https://bitbucket.org/barakianc/nvidia-physx-and-apex-in-gge
C++ | 407 lines | 305 code | 18 blank | 84 comment | 33 complexity | d080bfaa10e0d79f175cb0ef42dadf33 MD5 | raw file
  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. Copyright (c) 2000-2012 Torus Knot Software Ltd
  7. Permission is hereby granted, free of charge, to any person obtaining a copy
  8. of this software and associated documentation files (the "Software"), to deal
  9. in the Software without restriction, including without limitation the rights
  10. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. copies of the Software, and to permit persons to whom the Software is
  12. furnished to do so, subject to the following conditions:
  13. The above copyright notice and this permission notice shall be included in
  14. all copies or substantial portions of the Software.
  15. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. THE SOFTWARE.
  22. -----------------------------------------------------------------------------
  23. */
  24. #include "OgreStableHeaders.h"
  25. #include "OgreUnifiedHighLevelGpuProgram.h"
  26. #include "OgreString.h"
  27. #include "OgreException.h"
  28. #include "OgreGpuProgramManager.h"
  29. namespace Ogre
  30. {
  31. //-----------------------------------------------------------------------
  32. UnifiedHighLevelGpuProgram::CmdDelegate UnifiedHighLevelGpuProgram::msCmdDelegate;
  33. static const String sLanguage = "unified";
  34. //-----------------------------------------------------------------------
  35. //-----------------------------------------------------------------------
  36. UnifiedHighLevelGpuProgram::UnifiedHighLevelGpuProgram(
  37. ResourceManager* creator, const String& name, ResourceHandle handle,
  38. const String& group, bool isManual, ManualResourceLoader* loader)
  39. :HighLevelGpuProgram(creator, name, handle, group, isManual, loader)
  40. {
  41. if (createParamDictionary("UnifiedHighLevelGpuProgram"))
  42. {
  43. setupBaseParamDictionary();
  44. ParamDictionary* dict = getParamDictionary();
  45. dict->addParameter(ParameterDef("delegate",
  46. "Additional delegate programs containing implementations.",
  47. PT_STRING),&msCmdDelegate);
  48. }
  49. }
  50. //-----------------------------------------------------------------------
  51. UnifiedHighLevelGpuProgram::~UnifiedHighLevelGpuProgram()
  52. {
  53. }
  54. //-----------------------------------------------------------------------
  55. void UnifiedHighLevelGpuProgram::chooseDelegate() const
  56. {
  57. OGRE_LOCK_AUTO_MUTEX
  58. mChosenDelegate.setNull();
  59. for (StringVector::const_iterator i = mDelegateNames.begin();
  60. i != mDelegateNames.end(); ++i)
  61. {
  62. HighLevelGpuProgramPtr deleg =
  63. HighLevelGpuProgramManager::getSingleton().getByName(*i);
  64. // Silently ignore missing links
  65. if(!deleg.isNull()
  66. && deleg->isSupported())
  67. {
  68. mChosenDelegate = deleg;
  69. break;
  70. }
  71. }
  72. }
  73. //-----------------------------------------------------------------------
  74. const HighLevelGpuProgramPtr& UnifiedHighLevelGpuProgram::_getDelegate() const
  75. {
  76. if (mChosenDelegate.isNull())
  77. {
  78. chooseDelegate();
  79. }
  80. return mChosenDelegate;
  81. }
  82. //-----------------------------------------------------------------------
  83. void UnifiedHighLevelGpuProgram::addDelegateProgram(const String& name)
  84. {
  85. OGRE_LOCK_AUTO_MUTEX
  86. mDelegateNames.push_back(name);
  87. // reset chosen delegate
  88. mChosenDelegate.setNull();
  89. }
  90. //-----------------------------------------------------------------------
  91. void UnifiedHighLevelGpuProgram::clearDelegatePrograms()
  92. {
  93. OGRE_LOCK_AUTO_MUTEX
  94. mDelegateNames.clear();
  95. mChosenDelegate.setNull();
  96. }
  97. //-----------------------------------------------------------------------
  98. const String& UnifiedHighLevelGpuProgram::getLanguage(void) const
  99. {
  100. return sLanguage;
  101. }
  102. //-----------------------------------------------------------------------
  103. GpuProgramParametersSharedPtr UnifiedHighLevelGpuProgram::createParameters(void)
  104. {
  105. if (isSupported())
  106. {
  107. return _getDelegate()->createParameters();
  108. }
  109. else
  110. {
  111. // return a default set
  112. GpuProgramParametersSharedPtr params = GpuProgramManager::getSingleton().createParameters();
  113. // avoid any errors on parameter names that don't exist
  114. params->setIgnoreMissingParams(true);
  115. return params;
  116. }
  117. }
  118. //-----------------------------------------------------------------------
  119. GpuProgram* UnifiedHighLevelGpuProgram::_getBindingDelegate(void)
  120. {
  121. if (!_getDelegate().isNull())
  122. return _getDelegate()->_getBindingDelegate();
  123. else
  124. return 0;
  125. }
  126. //-----------------------------------------------------------------------
  127. bool UnifiedHighLevelGpuProgram::isSupported(void) const
  128. {
  129. // Supported if one of the delegates is
  130. return !(_getDelegate().isNull());
  131. }
  132. //-----------------------------------------------------------------------
  133. bool UnifiedHighLevelGpuProgram::isSkeletalAnimationIncluded(void) const
  134. {
  135. if (!_getDelegate().isNull())
  136. return _getDelegate()->isSkeletalAnimationIncluded();
  137. else
  138. return false;
  139. }
  140. //-----------------------------------------------------------------------
  141. bool UnifiedHighLevelGpuProgram::isMorphAnimationIncluded(void) const
  142. {
  143. if (!_getDelegate().isNull())
  144. return _getDelegate()->isMorphAnimationIncluded();
  145. else
  146. return false;
  147. }
  148. //-----------------------------------------------------------------------
  149. bool UnifiedHighLevelGpuProgram::isPoseAnimationIncluded(void) const
  150. {
  151. if (!_getDelegate().isNull())
  152. return _getDelegate()->isPoseAnimationIncluded();
  153. else
  154. return false;
  155. }
  156. //-----------------------------------------------------------------------
  157. bool UnifiedHighLevelGpuProgram::isVertexTextureFetchRequired(void) const
  158. {
  159. if (!_getDelegate().isNull())
  160. return _getDelegate()->isVertexTextureFetchRequired();
  161. else
  162. return false;
  163. }
  164. //-----------------------------------------------------------------------
  165. GpuProgramParametersSharedPtr UnifiedHighLevelGpuProgram::getDefaultParameters(void)
  166. {
  167. if (!_getDelegate().isNull())
  168. return _getDelegate()->getDefaultParameters();
  169. else
  170. return GpuProgramParametersSharedPtr();
  171. }
  172. //-----------------------------------------------------------------------
  173. bool UnifiedHighLevelGpuProgram::hasDefaultParameters(void) const
  174. {
  175. if (!_getDelegate().isNull())
  176. return _getDelegate()->hasDefaultParameters();
  177. else
  178. return false;
  179. }
  180. //-----------------------------------------------------------------------
  181. bool UnifiedHighLevelGpuProgram::getPassSurfaceAndLightStates(void) const
  182. {
  183. if (!_getDelegate().isNull())
  184. return _getDelegate()->getPassSurfaceAndLightStates();
  185. else
  186. return HighLevelGpuProgram::getPassSurfaceAndLightStates();
  187. }
  188. //---------------------------------------------------------------------
  189. bool UnifiedHighLevelGpuProgram::getPassFogStates(void) const
  190. {
  191. if (!_getDelegate().isNull())
  192. return _getDelegate()->getPassFogStates();
  193. else
  194. return HighLevelGpuProgram::getPassFogStates();
  195. }
  196. //---------------------------------------------------------------------
  197. bool UnifiedHighLevelGpuProgram::getPassTransformStates(void) const
  198. {
  199. if (!_getDelegate().isNull())
  200. return _getDelegate()->getPassTransformStates();
  201. else
  202. return HighLevelGpuProgram::getPassTransformStates();
  203. }
  204. //-----------------------------------------------------------------------
  205. bool UnifiedHighLevelGpuProgram::hasCompileError(void) const
  206. {
  207. if (_getDelegate().isNull())
  208. {
  209. return false;
  210. }
  211. else
  212. {
  213. return _getDelegate()->hasCompileError();
  214. }
  215. }
  216. //-----------------------------------------------------------------------
  217. void UnifiedHighLevelGpuProgram::resetCompileError(void)
  218. {
  219. if (!_getDelegate().isNull())
  220. _getDelegate()->resetCompileError();
  221. }
  222. //-----------------------------------------------------------------------
  223. void UnifiedHighLevelGpuProgram::load(bool backgroundThread)
  224. {
  225. if (!_getDelegate().isNull())
  226. _getDelegate()->load(backgroundThread);
  227. }
  228. //-----------------------------------------------------------------------
  229. void UnifiedHighLevelGpuProgram::reload(void)
  230. {
  231. if (!_getDelegate().isNull())
  232. _getDelegate()->reload();
  233. }
  234. //-----------------------------------------------------------------------
  235. bool UnifiedHighLevelGpuProgram::isReloadable(void) const
  236. {
  237. if (!_getDelegate().isNull())
  238. return _getDelegate()->isReloadable();
  239. else
  240. return true;
  241. }
  242. //-----------------------------------------------------------------------
  243. void UnifiedHighLevelGpuProgram::unload(void)
  244. {
  245. if (!_getDelegate().isNull())
  246. _getDelegate()->unload();
  247. }
  248. //-----------------------------------------------------------------------
  249. bool UnifiedHighLevelGpuProgram::isLoaded(void) const
  250. {
  251. if (!_getDelegate().isNull())
  252. return _getDelegate()->isLoaded();
  253. else
  254. return false;
  255. }
  256. //-----------------------------------------------------------------------
  257. bool UnifiedHighLevelGpuProgram::isLoading() const
  258. {
  259. if (!_getDelegate().isNull())
  260. return _getDelegate()->isLoading();
  261. else
  262. return false;
  263. }
  264. //-----------------------------------------------------------------------
  265. Resource::LoadingState UnifiedHighLevelGpuProgram::getLoadingState() const
  266. {
  267. if (!_getDelegate().isNull())
  268. return _getDelegate()->getLoadingState();
  269. else
  270. return Resource::LOADSTATE_UNLOADED;
  271. }
  272. //-----------------------------------------------------------------------
  273. size_t UnifiedHighLevelGpuProgram::getSize(void) const
  274. {
  275. if (!_getDelegate().isNull())
  276. return _getDelegate()->getSize();
  277. else
  278. return 0;
  279. }
  280. //-----------------------------------------------------------------------
  281. void UnifiedHighLevelGpuProgram::touch(void)
  282. {
  283. if (!_getDelegate().isNull())
  284. _getDelegate()->touch();
  285. }
  286. //-----------------------------------------------------------------------
  287. bool UnifiedHighLevelGpuProgram::isBackgroundLoaded(void) const
  288. {
  289. if (!_getDelegate().isNull())
  290. return _getDelegate()->isBackgroundLoaded();
  291. else
  292. return false;
  293. }
  294. //-----------------------------------------------------------------------
  295. void UnifiedHighLevelGpuProgram::setBackgroundLoaded(bool bl)
  296. {
  297. if (!_getDelegate().isNull())
  298. _getDelegate()->setBackgroundLoaded(bl);
  299. }
  300. //-----------------------------------------------------------------------
  301. void UnifiedHighLevelGpuProgram::escalateLoading()
  302. {
  303. if (!_getDelegate().isNull())
  304. _getDelegate()->escalateLoading();
  305. }
  306. //-----------------------------------------------------------------------
  307. void UnifiedHighLevelGpuProgram::addListener(Resource::Listener* lis)
  308. {
  309. if (!_getDelegate().isNull())
  310. _getDelegate()->addListener(lis);
  311. }
  312. //-----------------------------------------------------------------------
  313. void UnifiedHighLevelGpuProgram::removeListener(Resource::Listener* lis)
  314. {
  315. if (!_getDelegate().isNull())
  316. _getDelegate()->removeListener(lis);
  317. }
  318. //-----------------------------------------------------------------------
  319. void UnifiedHighLevelGpuProgram::createLowLevelImpl(void)
  320. {
  321. OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED,
  322. "This method should never get called!",
  323. "UnifiedHighLevelGpuProgram::createLowLevelImpl");
  324. }
  325. //-----------------------------------------------------------------------
  326. void UnifiedHighLevelGpuProgram::unloadHighLevelImpl(void)
  327. {
  328. OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED,
  329. "This method should never get called!",
  330. "UnifiedHighLevelGpuProgram::unloadHighLevelImpl");
  331. }
  332. //-----------------------------------------------------------------------
  333. void UnifiedHighLevelGpuProgram::buildConstantDefinitions() const
  334. {
  335. OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED,
  336. "This method should never get called!",
  337. "UnifiedHighLevelGpuProgram::buildConstantDefinitions");
  338. }
  339. //-----------------------------------------------------------------------
  340. void UnifiedHighLevelGpuProgram::loadFromSource(void)
  341. {
  342. OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED,
  343. "This method should never get called!",
  344. "UnifiedHighLevelGpuProgram::loadFromSource");
  345. }
  346. //-----------------------------------------------------------------------
  347. //-----------------------------------------------------------------------
  348. String UnifiedHighLevelGpuProgram::CmdDelegate::doGet(const void* target) const
  349. {
  350. // Can't do this (not one delegate), shouldn't matter
  351. return StringUtil::BLANK;
  352. }
  353. //-----------------------------------------------------------------------
  354. void UnifiedHighLevelGpuProgram::CmdDelegate::doSet(void* target, const String& val)
  355. {
  356. static_cast<UnifiedHighLevelGpuProgram*>(target)->addDelegateProgram(val);
  357. }
  358. //-----------------------------------------------------------------------
  359. //-----------------------------------------------------------------------
  360. UnifiedHighLevelGpuProgramFactory::UnifiedHighLevelGpuProgramFactory()
  361. {
  362. }
  363. //-----------------------------------------------------------------------
  364. UnifiedHighLevelGpuProgramFactory::~UnifiedHighLevelGpuProgramFactory()
  365. {
  366. }
  367. //-----------------------------------------------------------------------
  368. const String& UnifiedHighLevelGpuProgramFactory::getLanguage(void) const
  369. {
  370. return sLanguage;
  371. }
  372. //-----------------------------------------------------------------------
  373. HighLevelGpuProgram* UnifiedHighLevelGpuProgramFactory::create(ResourceManager* creator,
  374. const String& name, ResourceHandle handle,
  375. const String& group, bool isManual, ManualResourceLoader* loader)
  376. {
  377. return OGRE_NEW UnifiedHighLevelGpuProgram(creator, name, handle, group, isManual, loader);
  378. }
  379. //-----------------------------------------------------------------------
  380. void UnifiedHighLevelGpuProgramFactory::destroy(HighLevelGpuProgram* prog)
  381. {
  382. OGRE_DELETE prog;
  383. }
  384. //-----------------------------------------------------------------------
  385. }