Commit c526e295 authored by chili's avatar chili
Browse files

vertex layout template system working

parent 114a7d6b
......@@ -21,12 +21,27 @@ GDIPlusManager gdipm;
void f()
{
VertexLayout vl;
vl.Append<VertexLayout::Position3D>()
.Append<VertexLayout::Normal>();
VertexBuffer vb( std::move( vl ) );
vb.EmplaceBack( dx::XMFLOAT3{1.0f,1.0f,5.0f},dx::XMFLOAT3{ 2.0f,1.0f,4.0f } );
VertexBuffer vb( std::move(
VertexLayout{}
.Append<VertexLayout::Position3D>()
.Append<VertexLayout::Normal>()
.Append<VertexLayout::Texture2D>()
) );
vb.EmplaceBack(
dx::XMFLOAT3{1.0f,1.0f,5.0f},
dx::XMFLOAT3{ 2.0f,1.0f,4.0f },
dx::XMFLOAT2{ 6.0f,9.0f }
);
vb.EmplaceBack(
dx::XMFLOAT3{ 6.0f,9.0f,6.0f },
dx::XMFLOAT3{ 9.0f,6.0f,9.0f },
dx::XMFLOAT2{ 4.2f,0.0f }
);
auto pos = vb[0].Attr<VertexLayout::Position3D>();
auto nor = vb[0].Attr<VertexLayout::Normal>();
auto tex = vb[1].Attr<VertexLayout::Texture2D>();
vb.Back().Attr<VertexLayout::Position3D>().z = 420.0f;
pos = vb.Back().Attr<VertexLayout::Position3D>();
}
App::App()
......
......@@ -103,6 +103,10 @@ public:
{
return elements.empty() ? 0u : elements.back().GetOffsetAfter();
}
size_t GetElementCount() const noexcept
{
return elements.size();
}
private:
std::vector<Element> elements;
};
......@@ -197,7 +201,7 @@ private:
void SetAttributeByIndex( size_t i,First&& first,Rest&&... rest ) noexcept(!IS_DEBUG)
{
SetAttributeByIndex( i,std::forward<First>( first ) );
SetAttributeByIndex( i,std::forward<Rest>( rest )... );
SetAttributeByIndex( i + 1,std::forward<Rest>( rest )... );
}
// helper to reduce code duplication in SetAttributeByIndex
template<typename Dest,typename Src>
......@@ -235,6 +239,7 @@ public:
template<typename ...Params>
void EmplaceBack( Params&&... params ) noexcept(!IS_DEBUG)
{
assert( sizeof...(params) == layout.GetElementCount() && "Param count doesn't match number of vertex elements" );
buffer.resize( buffer.size() + layout.Size() );
Back().SetAttributeByIndex( 0u,std::forward<Params>( params )... );
}
......
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