Commit d219ca73 authored by chili's avatar chili
Browse files

generate d3d layout desc from dynamic vertex layout

parent af8779e6
...@@ -63,12 +63,7 @@ AssTest::AssTest( Graphics& gfx,std::mt19937& rng, ...@@ -63,12 +63,7 @@ AssTest::AssTest( Graphics& gfx,std::mt19937& rng,
AddStaticBind( std::make_unique<PixelShader>( gfx,L"PhongPS.cso" ) ); AddStaticBind( std::make_unique<PixelShader>( gfx,L"PhongPS.cso" ) );
const std::vector<D3D11_INPUT_ELEMENT_DESC> ied = AddStaticBind( std::make_unique<InputLayout>( gfx,vbuf.GetLayout().GetD3DLayout(),pvsbc ) );
{
{ "Position",0,DXGI_FORMAT_R32G32B32_FLOAT,0,0,D3D11_INPUT_PER_VERTEX_DATA,0 },
{ "Normal",0,DXGI_FORMAT_R32G32B32_FLOAT,0,12,D3D11_INPUT_PER_VERTEX_DATA,0 },
};
AddStaticBind( std::make_unique<InputLayout>( gfx,ied,pvsbc ) );
AddStaticBind( std::make_unique<Topology>( gfx,D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST ) ); AddStaticBind( std::make_unique<Topology>( gfx,D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST ) );
......
...@@ -31,44 +31,44 @@ namespace hw3dexp ...@@ -31,44 +31,44 @@ namespace hw3dexp
template<> struct Map<Position2D> template<> struct Map<Position2D>
{ {
using SysType = DirectX::XMFLOAT2; using SysType = DirectX::XMFLOAT2;
DXGI_FORMAT dxgiFormat = DXGI_FORMAT_R32G32_FLOAT; static constexpr DXGI_FORMAT dxgiFormat = DXGI_FORMAT_R32G32_FLOAT;
const char* semantic = "Position"; static constexpr const char* semantic = "Position";
}; };
template<> struct Map<Position3D> template<> struct Map<Position3D>
{ {
using SysType = DirectX::XMFLOAT3; using SysType = DirectX::XMFLOAT3;
DXGI_FORMAT dxgiFormat = DXGI_FORMAT_R32G32B32_FLOAT; static constexpr DXGI_FORMAT dxgiFormat = DXGI_FORMAT_R32G32B32_FLOAT;
const char* semantic = "Position"; static constexpr const char* semantic = "Position";
}; };
template<> struct Map<Texture2D> template<> struct Map<Texture2D>
{ {
using SysType = DirectX::XMFLOAT2; using SysType = DirectX::XMFLOAT2;
DXGI_FORMAT dxgiFormat = DXGI_FORMAT_R32G32_FLOAT; static constexpr DXGI_FORMAT dxgiFormat = DXGI_FORMAT_R32G32_FLOAT;
const char* semantic = "Texcoord"; static constexpr const char* semantic = "Texcoord";
}; };
template<> struct Map<Normal> template<> struct Map<Normal>
{ {
using SysType = DirectX::XMFLOAT3; using SysType = DirectX::XMFLOAT3;
DXGI_FORMAT dxgiFormat = DXGI_FORMAT_R32G32B32_FLOAT; static constexpr DXGI_FORMAT dxgiFormat = DXGI_FORMAT_R32G32B32_FLOAT;
const char* semantic = "Normal"; static constexpr const char* semantic = "Normal";
}; };
template<> struct Map<Float3Color> template<> struct Map<Float3Color>
{ {
using SysType = DirectX::XMFLOAT3; using SysType = DirectX::XMFLOAT3;
DXGI_FORMAT dxgiFormat = DXGI_FORMAT_R32G32B32_FLOAT; static constexpr DXGI_FORMAT dxgiFormat = DXGI_FORMAT_R32G32B32_FLOAT;
const char* semantic = "Color"; static constexpr const char* semantic = "Color";
}; };
template<> struct Map<Float4Color> template<> struct Map<Float4Color>
{ {
using SysType = DirectX::XMFLOAT4; using SysType = DirectX::XMFLOAT4;
DXGI_FORMAT dxgiFormat = DXGI_FORMAT_R32G32B32A32_FLOAT; static constexpr DXGI_FORMAT dxgiFormat = DXGI_FORMAT_R32G32B32A32_FLOAT;
const char* semantic = "Color"; static constexpr const char* semantic = "Color";
}; };
template<> struct Map<BGRAColor> template<> struct Map<BGRAColor>
{ {
using SysType = hw3dexp::BGRAColor; using SysType = hw3dexp::BGRAColor;
DXGI_FORMAT dxgiFormat = DXGI_FORMAT_R8G8B8A8_UNORM; static constexpr DXGI_FORMAT dxgiFormat = DXGI_FORMAT_R8G8B8A8_UNORM;
const char* semantic = "Color"; static constexpr const char* semantic = "Color";
}; };
class Element class Element
...@@ -93,7 +93,6 @@ namespace hw3dexp ...@@ -93,7 +93,6 @@ namespace hw3dexp
} }
static constexpr size_t SizeOf( ElementType type ) noexcept(!IS_DEBUG) static constexpr size_t SizeOf( ElementType type ) noexcept(!IS_DEBUG)
{ {
using namespace DirectX;
switch( type ) switch( type )
{ {
case Position2D: case Position2D:
...@@ -118,6 +117,34 @@ namespace hw3dexp ...@@ -118,6 +117,34 @@ namespace hw3dexp
{ {
return type; return type;
} }
D3D11_INPUT_ELEMENT_DESC GetDesc() const noexcept(!IS_DEBUG)
{
switch( type )
{
case Position2D:
return GenerateDesc<Position2D>( GetOffset() );
case Position3D:
return GenerateDesc<Position3D>( GetOffset() );
case Texture2D:
return GenerateDesc<Texture2D>( GetOffset() );
case Normal:
return GenerateDesc<Normal>( GetOffset() );
case Float3Color:
return GenerateDesc<Float3Color>( GetOffset() );
case Float4Color:
return GenerateDesc<Float4Color>( GetOffset() );
case BGRAColor:
return GenerateDesc<BGRAColor>( GetOffset() );
}
assert( "Invalid element type" && false );
return { "INVALID",0,DXGI_FORMAT_UNKNOWN,0,0,D3D11_INPUT_PER_VERTEX_DATA,0 };
}
private:
template<ElementType type>
static constexpr D3D11_INPUT_ELEMENT_DESC GenerateDesc( size_t offset ) noexcept(!IS_DEBUG)
{
return { Map<type>::semantic,0,Map<type>::dxgiFormat,0,(UINT)offset,D3D11_INPUT_PER_VERTEX_DATA,0 };
}
private: private:
ElementType type; ElementType type;
size_t offset; size_t offset;
...@@ -153,6 +180,16 @@ namespace hw3dexp ...@@ -153,6 +180,16 @@ namespace hw3dexp
{ {
return elements.size(); return elements.size();
} }
std::vector<D3D11_INPUT_ELEMENT_DESC> GetD3DLayout() const noexcept(!IS_DEBUG)
{
std::vector<D3D11_INPUT_ELEMENT_DESC> desc;
desc.reserve( GetElementCount() );
for( const auto& e : elements )
{
desc.push_back( e.GetDesc() );
}
return desc;
}
private: private:
std::vector<Element> elements; std::vector<Element> elements;
}; };
......
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