#include "render/IMaterialProxy.h" #include "IObjectMesh.h" namespace LifeGraphics { IMaterial* IMaterialProxy::GetBaseMaterial() { return base; } bool IMaterialProxy::SelectTechnique(MaterialTechnique tech) { TechniqueCollectionItr it = technics.find(tech); if(it != technics.end()){ active_technique = it->second; return true; } else //try to request it from parent material { IMaterialTechnique* t = base->CreateTechnique(MT_RENDER_DEFERRED,this); if(t == nullptr) return false; active_technique = t; return AddTechnique(t); } return false; } IMaterialProxy::IMaterialProxy(IMaterial* source, IObjectMesh* _geom) :active_technique(nullptr) { base = source; geom = _geom; } bool IMaterialProxy::AddTechnique(IMaterialTechnique* tech) { TechniqueCollectionItr it = technics.find(tech->GetTechniqueType()); if(it != technics.end())//found return false; else { technics[tech->GetTechniqueType()] = tech; return true; } } IMaterialTechnique* IMaterialProxy::GetTechnique() { return active_technique; } bool IMaterialTechnique::SelectPass(MaterialPass pass) { if(active_pass != NULL && active_pass->GetPassType() == pass) return true; PassCollectionItr it = passes.find(pass); if(it != passes.end()) { active_pass = it->second; return true; } //pass not found -> try to create it! IMaterialPass* newpass = parent->GetBaseMaterial()->CreatePass(this, pass); if(newpass != nullptr) { active_pass = newpass; return true; } return false; } IMaterialPass* IMaterialTechnique::GetPass() { return active_pass; } bool IMaterialTechnique::AddPass(IMaterialPass* pass) { PassCollectionItr it = passes.find(pass->GetPassType()); if(it != passes.end()) //found return false; else { passes[pass->GetPassType()] = pass; return true; } } IMaterialTechnique::IMaterialTechnique(MaterialTechnique tech, IMaterialProxy* _parent) :active_pass(nullptr), tech_type(tech), parent(_parent) { } MaterialTechnique IMaterialTechnique::GetTechniqueType() { return tech_type; } }