Commit c98e3648 authored by chili's avatar chili
Browse files

static vertex constant buffer + protected:tion

parent 7fa7828c
...@@ -14,9 +14,10 @@ public: ...@@ -14,9 +14,10 @@ public:
virtual DirectX::XMMATRIX GetTransformXM() const noexcept = 0; virtual DirectX::XMMATRIX GetTransformXM() const noexcept = 0;
void Draw( Graphics& gfx ) const noexcept(!IS_DEBUG); void Draw( Graphics& gfx ) const noexcept(!IS_DEBUG);
virtual void Update( float dt ) noexcept = 0; virtual void Update( float dt ) noexcept = 0;
virtual ~Drawable() = default;
protected:
void AddBind( std::unique_ptr<Bindable> bind ) noexcept(!IS_DEBUG); void AddBind( std::unique_ptr<Bindable> bind ) noexcept(!IS_DEBUG);
void AddIndexBuffer( std::unique_ptr<class IndexBuffer> ibuf ) noexcept(!IS_DEBUG); void AddIndexBuffer( std::unique_ptr<class IndexBuffer> ibuf ) noexcept(!IS_DEBUG);
virtual ~Drawable() = default;
private: private:
virtual const std::vector<std::unique_ptr<Bindable>>& GetStaticBinds() const noexcept = 0; virtual const std::vector<std::unique_ptr<Bindable>>& GetStaticBinds() const noexcept = 0;
private: private:
......
...@@ -5,14 +5,14 @@ ...@@ -5,14 +5,14 @@
template<class T> template<class T>
class DrawableBase : public Drawable class DrawableBase : public Drawable
{ {
public: protected:
bool IsStaticInitialized() const noexcept static bool IsStaticInitialized() noexcept
{ {
return !staticBinds.empty(); return !staticBinds.empty();
} }
void AddStaticBind( std::unique_ptr<Bindable> bind ) noexcept(!IS_DEBUG) static void AddStaticBind( std::unique_ptr<Bindable> bind ) noexcept(!IS_DEBUG)
{ {
assert( "*Must* use AddIndexBuffer to bind index buffer" && typeid(*bind) != typeid(IndexBuffer) ); assert( "*Must* use AddStaticIndexBuffer to bind index buffer" && typeid(*bind) != typeid(IndexBuffer) );
staticBinds.push_back( std::move( bind ) ); staticBinds.push_back( std::move( bind ) );
} }
void AddStaticIndexBuffer( std::unique_ptr<IndexBuffer> ibuf ) noexcept(!IS_DEBUG) void AddStaticIndexBuffer( std::unique_ptr<IndexBuffer> ibuf ) noexcept(!IS_DEBUG)
...@@ -38,7 +38,7 @@ private: ...@@ -38,7 +38,7 @@ private:
const std::vector<std::unique_ptr<Bindable>>& GetStaticBinds() const noexcept override const std::vector<std::unique_ptr<Bindable>>& GetStaticBinds() const noexcept override
{ {
return staticBinds; return staticBinds;
} }
private: private:
static std::vector<std::unique_ptr<Bindable>> staticBinds; static std::vector<std::unique_ptr<Bindable>> staticBinds;
}; };
......
...@@ -2,16 +2,22 @@ ...@@ -2,16 +2,22 @@
TransformCbuf::TransformCbuf( Graphics& gfx,const Drawable& parent ) TransformCbuf::TransformCbuf( Graphics& gfx,const Drawable& parent )
: :
vcbuf( gfx ),
parent( parent ) parent( parent )
{} {
if( !pVcbuf )
{
pVcbuf = std::make_unique<VertexConstantBuffer<DirectX::XMMATRIX>>( gfx );
}
}
void TransformCbuf::Bind( Graphics& gfx ) noexcept void TransformCbuf::Bind( Graphics& gfx ) noexcept
{ {
vcbuf.Update( gfx, pVcbuf->Update( gfx,
DirectX::XMMatrixTranspose( DirectX::XMMatrixTranspose(
parent.GetTransformXM() * gfx.GetProjection() parent.GetTransformXM() * gfx.GetProjection()
) )
); );
vcbuf.Bind( gfx ); pVcbuf->Bind( gfx );
} }
std::unique_ptr<VertexConstantBuffer<DirectX::XMMATRIX>> TransformCbuf::pVcbuf;
\ No newline at end of file
...@@ -9,6 +9,6 @@ public: ...@@ -9,6 +9,6 @@ public:
TransformCbuf( Graphics& gfx,const Drawable& parent ); TransformCbuf( Graphics& gfx,const Drawable& parent );
void Bind( Graphics& gfx ) noexcept override; void Bind( Graphics& gfx ) noexcept override;
private: private:
VertexConstantBuffer<DirectX::XMMATRIX> vcbuf; static std::unique_ptr<VertexConstantBuffer<DirectX::XMMATRIX>> pVcbuf;
const Drawable& parent; const Drawable& parent;
}; };
\ No newline at end of file
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