CmShader.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #include "CmShader.h"
  2. #include "CmTechnique.h"
  3. #include "CmException.h"
  4. #include "CmDebug.h"
  5. #include "CmShaderRTTI.h"
  6. namespace CamelotEngine
  7. {
  8. Shader::Shader(const String& name)
  9. :mName(name)
  10. {
  11. }
  12. void Shader::initialize_internal()
  13. { }
  14. TechniquePtr Shader::addTechnique(const String& renderSystem, const String& renderer)
  15. {
  16. TechniquePtr technique = TechniquePtr(new Technique(renderSystem, renderer));
  17. mTechniques.push_back(technique);
  18. return technique;
  19. }
  20. void Shader::removeTechnique(UINT32 idx)
  21. {
  22. if(idx < 0 || idx >= mTechniques.size())
  23. CM_EXCEPT(InvalidParametersException, "Index out of range: " + toString(idx));
  24. int count = 0;
  25. auto iter = mTechniques.begin();
  26. while(count != idx)
  27. {
  28. ++count;
  29. ++iter;
  30. }
  31. mTechniques.erase(iter);
  32. }
  33. void Shader::removeTechnique(TechniquePtr technique)
  34. {
  35. auto iterFind = std::find(mTechniques.begin(), mTechniques.end(), technique);
  36. if(iterFind == mTechniques.end())
  37. CM_EXCEPT(InvalidParametersException, "Cannot remove specified technique because it wasn't found in this shader.");
  38. mTechniques.erase(iterFind);
  39. }
  40. TechniquePtr Shader::getBestTechnique() const
  41. {
  42. for(auto iter = mTechniques.begin(); iter != mTechniques.end(); ++iter)
  43. {
  44. if((*iter)->isSupported())
  45. {
  46. return *iter;
  47. }
  48. }
  49. CM_EXCEPT(InternalErrorException, "No techniques are supported!");
  50. // TODO - Low priority. Instead of throwing an exception use an extremely simple technique that will be supported almost everywhere as a fallback.
  51. }
  52. RTTITypeBase* Shader::getRTTIStatic()
  53. {
  54. return ShaderRTTI::instance();
  55. }
  56. RTTITypeBase* Shader::getRTTI() const
  57. {
  58. return Shader::getRTTIStatic();
  59. }
  60. }