Page MenuHomePhorge

Material.cpp
No OneTemporary

Size
1 KB
Referenced Files
None
Subscribers
None

Material.cpp

#include <echo/Platforms/GL/GLSupport.h>
#ifdef ECHO_RENDERER_GL
#include <echo/Graphics/Material.h>
#include <echo/Graphics/RenderPass.h>
#include <echo/Graphics/MultipassRenderable.h>
#include <echo/Graphics/Texture.h>
namespace Echo
{
Material::Material() : mCurrentPass(0)
{
}
Material::Material(const Material& other)
:
mPasses(other.mPasses),
mCurrentPass(other.mCurrentPass)
{
}
Material::~Material()
{
}
shared_ptr< Material > Material::Clone() const
{
return make_shared<Material>(*this);
}
void Material::SetToDefaultMaterial()
{
mPasses.clear();
mPasses.push_back(RenderPass());
}
void Material::SetTexture(shared_ptr<Texture> surface)
{
if(mPasses.empty())
AddPass(RenderPass());
mPasses[0].SetTexture(surface);
}
shared_ptr<Texture> Material::GetTexture() const
{
if(mPasses.empty())
return shared_ptr<Texture>();
return mPasses[0].GetTexture();
}
RenderPass* Material::GetPass(u32 passIndex)
{
if(passIndex < mPasses.size())
return &(mPasses[passIndex]);
return 0;
}
void Material::AddPass(const RenderPass& pass)
{
mPasses.push_back(pass);
}
void Material::SetPass(const RenderPass& pass, u32 passIndex)
{
if(passIndex < mPasses.size())
{
mPasses[passIndex] = pass;
return;
}
AddPass(pass);
}
void Material::ApplyAndRender(MultipassRenderable& renderable, const Matrix4& viewWorldMatrix, RenderTarget& renderTarget)
{
//Loop through the passes and apply each material followed by executing the render
size_t numPasses = mPasses.size();
for(size_t p = 0; p < numPasses; ++p)
{
RenderPass& pass = mPasses[p];
if(!pass.GetActive())
{
continue;
}
mCurrentPass = &pass;
pass.Apply(viewWorldMatrix,renderTarget);
renderable.Render(pass,renderTarget);
mCurrentPass = 0;
}
}
size_t Material::GetNumberOfPasses() const
{
return mPasses.size();
}
}
#endif

File Metadata

Mime Type
text/x-c++
Expires
Wed, Jan 15, 11:04 PM (11 h, 23 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
72085
Default Alt Text
Material.cpp (1 KB)

Event Timeline