| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- #include "CmShader.h"
- #include "CmTechnique.h"
- #include "CmException.h"
- #include "CmDebug.h"
- #include "CmShaderRTTI.h"
- namespace CamelotEngine
- {
- Shader::Shader(const String& name)
- :mName(name)
- {
- }
- void Shader::initialize_internal()
- { }
- TechniquePtr Shader::addTechnique(const String& renderSystem, const String& renderer)
- {
- TechniquePtr technique = TechniquePtr(new Technique(renderSystem, renderer));
- mTechniques.push_back(technique);
- return technique;
- }
- void Shader::removeTechnique(UINT32 idx)
- {
- if(idx < 0 || idx >= mTechniques.size())
- CM_EXCEPT(InvalidParametersException, "Index out of range: " + toString(idx));
- int count = 0;
- auto iter = mTechniques.begin();
- while(count != idx)
- {
- ++count;
- ++iter;
- }
- mTechniques.erase(iter);
- }
- void Shader::removeTechnique(TechniquePtr technique)
- {
- auto iterFind = std::find(mTechniques.begin(), mTechniques.end(), technique);
- if(iterFind == mTechniques.end())
- CM_EXCEPT(InvalidParametersException, "Cannot remove specified technique because it wasn't found in this shader.");
- mTechniques.erase(iterFind);
- }
- TechniquePtr Shader::getBestTechnique() const
- {
- for(auto iter = mTechniques.begin(); iter != mTechniques.end(); ++iter)
- {
- if((*iter)->isSupported())
- {
- return *iter;
- }
- }
- CM_EXCEPT(InternalErrorException, "No techniques are supported!");
- // TODO - Low priority. Instead of throwing an exception use an extremely simple technique that will be supported almost everywhere as a fallback.
- }
- RTTITypeBase* Shader::getRTTIStatic()
- {
- return ShaderRTTI::instance();
- }
- RTTITypeBase* Shader::getRTTI() const
- {
- return Shader::getRTTIStatic();
- }
- }
|