Page MenuHomePhorge

RenderPass.cpp
No OneTemporary

Size
4 KB
Referenced Files
None
Subscribers
None

RenderPass.cpp

#include <echo/Graphics/RenderPass.h>
#include <echo/Graphics/RenderTarget.h>
#include <echo/Graphics/ShaderProgram.h>
namespace Echo
{
RenderPass::RenderPass()
{
mBlendMode = RenderPass::BlendModes::TRANSPARENT;
mDepthFunction = RenderPass::DepthFunctions::LESS_OR_EQUAL;
mEnabledOptions = RenderPass::Options::DEPTH_CHECK | RenderPass::Options::DEPTH_WRITE;
mCullMode = RenderPass::CullModes::NONE;
mAmbient.Set(0.8f, 0.8f, 0.8f, 1.0f);
mDiffuse.Set(1.0f, 1.0f, 1.0f, 1.0f);
mSpecular.Set(1.0f, 1.0f, 1.0f, 1.0f);
mEmissive.Set(0.f, 0.f, 0.f, 0.f);
mActive = true;
mShininess = 0.0f;
}
RenderPass::~RenderPass()
{
}
void RenderPass::AddTextureUnit(const TextureUnit& u)
{
mTextureUnits.push_back(u);
}
void RenderPass::SetTextureUnit(const TextureUnit& u, u32 stage)
{
if(stage >= mTextureUnits.size())
{
AddTextureUnit(u);
return;
}
mTextureUnits[stage] = u;
}
const TextureUnit* RenderPass::GetTextureUnit(u32 i) const
{
if(i >= mTextureUnits.size())
{
return 0;
}
return &(mTextureUnits[i]);
}
void RenderPass::SetTexture(shared_ptr<Texture> texture)
{
if(GetNumTextureUnits() == 0)
{
TextureUnit u;
u.SetTexture(texture);
AddTextureUnit(u);
} else
{
mTextureUnits[0].SetTexture(texture);
}
}
shared_ptr<Texture> RenderPass::GetTexture() const
{
if(GetNumTextureUnits() != 0)
{
return mTextureUnits[0].GetTexture();
}
return shared_ptr<Texture>();
}
void RenderPass::Apply(const Matrix4& viewWorld, RenderTarget& renderTarget)
{
if(mEnabledOptions & RenderPass::Options::LIGHTING)
{
renderTarget.SetLightingEnabled(true);
renderTarget.SetMaterialColourEnabled(true);
renderTarget.SetMaterialColours(mAmbient, mDiffuse, mSpecular, mEmissive, mShininess);
} else
{
renderTarget.SetMaterialColourEnabled(false);
renderTarget.SetLightingEnabled(false);
renderTarget.SetDiffuse(mDiffuse);
}
if(mEnabledOptions & RenderPass::Options::DEPTH_CHECK)
{
renderTarget.SetDepthTestEnabled(true);
renderTarget.SetDepthFunction(mDepthFunction);
} else
{
renderTarget.SetDepthTestEnabled(false);
}
if(mEnabledOptions & RenderPass::Options::DEPTH_WRITE)
{
renderTarget.SetDepthWriteEnabled(true);
}else
{
renderTarget.SetDepthWriteEnabled(false);
}
renderTarget.SetBlendMode(mBlendMode);
size_t numTexUnits = mTextureUnits.size();
u32 stage = 0;
if(numTexUnits == 0)
{
renderTarget.SetTexture2DEnabled(false);
} else
{
renderTarget.SetTexture2DEnabled(true);
for(size_t tu = 0; tu < numTexUnits; ++tu)
{
TextureUnit& texUnit = mTextureUnits[tu];
// if(texUnit.mUScaleSpeed != 0.0f || texUnit.mVScaleSpeed != 0.0f)
// {
// Matrix4 t;
// t.setScale(Vector3(texUnit.mUScaleSpeed*lastFrameTime, texUnit.mVScaleSpeed*lastFrameTime, 0));
// texUnit.mTextureMatrix = texUnit.mTextureMatrix * t;
// }
// if(!texUnit.mRotationSpeed.IsZero())
// {
// Quaternion ori;
// ori.SetEular(texUnit.mRotationSpeed.x*lastFrameTime, texUnit.mRotationSpeed.y*lastFrameTime, texUnit.mRotationSpeed.z * lastFrameTime);
// Matrix3 t;
// ori.ToRotationMatrix(t);
// texUnit.mTextureMatrix = texUnit.mTextureMatrix * t;
// }
// if(texUnit.mUScrollSpeed != 0.0f || texUnit.mVScrollSpeed != 0.0f)
// {
// Matrix4 t;
// t.Translation(texUnit.mUScrollSpeed*lastFrameTime, texUnit.mVScrollSpeed*lastFrameTime, 0);
// texUnit.mTextureMatrix = texUnit.mTextureMatrix * t;
// }
renderTarget.SetTextureStageBlendMode(texUnit.mBlendMode, stage);
renderTarget.SetTextureStageBlendMode(texUnit.mAlphaBlendMode, stage);
if(texUnit.mTexture)
{
renderTarget.SetTexture(texUnit.mTexture.get(), stage);
renderTarget.SetTexGen(texUnit.mTexGenMode, stage);
renderTarget.SetTextureMatrix(texUnit.mTextureMatrix, stage);
++stage;
renderTarget.SetWrapModeU(texUnit.mWrapModeU);
renderTarget.SetWrapModeV(texUnit.mWrapModeV);
renderTarget.SetMinFilter(texUnit.mMinFilter);
renderTarget.SetMagFilter(texUnit.mMagFilter);
}
}
}
renderTarget.SetCullMode(mCullMode);
if(mProgram)
{
if(mProgramViewProjectionWorld)
{
*mProgramViewProjectionWorld = (renderTarget.GetProjectionMatrix() * viewWorld).transpose();
}
}
}
size_t RenderPass::GetNumTextureUnits() const
{
return mTextureUnits.size();
}
}

File Metadata

Mime Type
text/x-c++
Expires
Thu, Dec 5, 2:06 AM (6 h, 59 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
61995
Default Alt Text
RenderPass.cpp (4 KB)

Event Timeline