Commit b4c37cb8 authored by chili's avatar chili
Browse files

refactor Cbuf for increased extensibility

parent bf379f2a
...@@ -13,18 +13,26 @@ namespace Bind ...@@ -13,18 +13,26 @@ namespace Bind
} }
void TransformCbuf::Bind( Graphics& gfx ) noexcept void TransformCbuf::Bind( Graphics& gfx ) noexcept
{
UpdateBindImpl( gfx,GetTransforms( gfx ) );
}
void TransformCbuf::UpdateBindImpl( Graphics& gfx,const Transforms& tf ) noexcept
{
pVcbuf->Update( gfx,tf );
pVcbuf->Bind( gfx );
}
TransformCbuf::Transforms TransformCbuf::GetTransforms( Graphics& gfx ) noexcept
{ {
const auto modelView = parent.GetTransformXM() * gfx.GetCamera(); const auto modelView = parent.GetTransformXM() * gfx.GetCamera();
const Transforms tf = return {
{
DirectX::XMMatrixTranspose( modelView ), DirectX::XMMatrixTranspose( modelView ),
DirectX::XMMatrixTranspose( DirectX::XMMatrixTranspose(
modelView * modelView *
gfx.GetProjection() gfx.GetProjection()
) )
}; };
pVcbuf->Update( gfx,tf );
pVcbuf->Bind( gfx );
} }
std::unique_ptr<VertexConstantBuffer<TransformCbuf::Transforms>> TransformCbuf::pVcbuf; std::unique_ptr<VertexConstantBuffer<TransformCbuf::Transforms>> TransformCbuf::pVcbuf;
......
...@@ -7,15 +7,18 @@ namespace Bind ...@@ -7,15 +7,18 @@ namespace Bind
{ {
class TransformCbuf : public Bindable class TransformCbuf : public Bindable
{ {
private: protected:
struct Transforms struct Transforms
{ {
DirectX::XMMATRIX modelView;
DirectX::XMMATRIX modelViewProj; DirectX::XMMATRIX modelViewProj;
DirectX::XMMATRIX model;
}; };
public: public:
TransformCbuf( Graphics& gfx,const Drawable& parent,UINT slot = 0u ); TransformCbuf( Graphics& gfx,const Drawable& parent,UINT slot = 0u );
void Bind( Graphics& gfx ) noexcept override; void Bind( Graphics& gfx ) noexcept override;
protected:
void UpdateBindImpl( Graphics& gfx,const Transforms& tf ) noexcept;
Transforms GetTransforms( Graphics& gfx ) noexcept;
private: private:
static std::unique_ptr<VertexConstantBuffer<Transforms>> pVcbuf; static std::unique_ptr<VertexConstantBuffer<Transforms>> pVcbuf;
const Drawable& parent; const Drawable& parent;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment