CmGpuProgramManager.cpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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-2011 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 "CmGpuProgramManager.h"
  25. //#include "CmHighLevelGpuProgramManager.h"
  26. #include "CmRenderSystem.h"
  27. #include "CmRenderSystemManager.h"
  28. namespace CamelotEngine {
  29. //---------------------------------------------------------------------------
  30. GpuProgramManager::GpuProgramManager()
  31. {
  32. // subclasses should register with resource group manager
  33. }
  34. //---------------------------------------------------------------------------
  35. GpuProgramManager::~GpuProgramManager()
  36. {
  37. // subclasses should unregister with resource group manager
  38. }
  39. //---------------------------------------------------------------------------
  40. GpuProgramPtr GpuProgramManager::load(const String& code,
  41. GpuProgramType gptype, const String& syntaxCode)
  42. {
  43. GpuProgramPtr prg;
  44. {
  45. CM_LOCK_AUTO_MUTEX
  46. prg = createProgram( code, gptype, syntaxCode);
  47. }
  48. prg->load();
  49. return prg;
  50. }
  51. //---------------------------------------------------------------------------
  52. GpuProgramPtr GpuProgramManager::createProgram(const String& code, GpuProgramType gptype,
  53. const String& syntaxCode)
  54. {
  55. GpuProgramPtr prg = GpuProgramPtr(create(gptype, syntaxCode));
  56. // Set all prarmeters (create does not set, just determines factory)
  57. prg->setType(gptype);
  58. prg->setSyntaxCode(syntaxCode);
  59. prg->setSource(code);
  60. return prg;
  61. }
  62. //---------------------------------------------------------------------------
  63. const GpuProgramManager::SyntaxCodes& GpuProgramManager::getSupportedSyntax(void) const
  64. {
  65. // Use the current render system
  66. RenderSystem* rs = CamelotEngine::RenderSystemManager::getActive();
  67. // Get the supported syntaxed from RenderSystemCapabilities
  68. return rs->getCapabilities()->getSupportedShaderProfiles();
  69. }
  70. //---------------------------------------------------------------------------
  71. bool GpuProgramManager::isSyntaxSupported(const String& syntaxCode) const
  72. {
  73. // Use the current render system
  74. RenderSystem* rs = CamelotEngine::RenderSystemManager::getActive();
  75. // Get the supported syntaxed from RenderSystemCapabilities
  76. return rs->getCapabilities()->isShaderProfileSupported(syntaxCode);
  77. }
  78. //---------------------------------------------------------------------------
  79. String GpuProgramManager::gpuProgProfileToRSSpecificProfile(GpuProgramProfile gpuProgProfile) const
  80. {
  81. // Use the current render system
  82. RenderSystem* rs = CamelotEngine::RenderSystemManager::getActive();
  83. return rs->getCapabilities()->gpuProgProfileToRSSpecificProfile(gpuProgProfile);
  84. }
  85. //-----------------------------------------------------------------------------
  86. GpuProgramParametersSharedPtr GpuProgramManager::createParameters(void)
  87. {
  88. return GpuProgramParametersSharedPtr(new GpuProgramParameters());
  89. }
  90. //---------------------------------------------------------------------
  91. GpuSharedParametersPtr GpuProgramManager::createSharedParameters(const String& name)
  92. {
  93. if (mSharedParametersMap.find(name) != mSharedParametersMap.end())
  94. {
  95. CM_EXCEPT(InvalidParametersException,
  96. "The shared parameter set '" + name + "' already exists!");
  97. }
  98. GpuSharedParametersPtr ret(new GpuSharedParameters(name));
  99. mSharedParametersMap[name] = ret;
  100. return ret;
  101. }
  102. //---------------------------------------------------------------------
  103. GpuSharedParametersPtr GpuProgramManager::getSharedParameters(const String& name) const
  104. {
  105. SharedParametersMap::const_iterator i = mSharedParametersMap.find(name);
  106. if (i == mSharedParametersMap.end())
  107. {
  108. CM_EXCEPT(InvalidParametersException,
  109. "No shared parameter set with name '" + name + "'!");
  110. }
  111. return i->second;
  112. }
  113. //---------------------------------------------------------------------
  114. const GpuProgramManager::SharedParametersMap&
  115. GpuProgramManager::getAvailableSharedParameters() const
  116. {
  117. return mSharedParametersMap;
  118. }
  119. //---------------------------------------------------------------------
  120. }