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,
AddStaticBind( std::make_unique<PixelShader>( gfx,L"PhongPS.cso" ) );
const std::vector<D3D11_INPUT_ELEMENT_DESC> ied =
{
{ "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<InputLayout>( gfx,vbuf.GetLayout().GetD3DLayout(),pvsbc ) );
AddStaticBind( std::make_unique<Topology>( gfx,D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST ) );
......
......@@ -31,44 +31,44 @@ namespace hw3dexp
template<> struct Map<Position2D>
{
using SysType = DirectX::XMFLOAT2;
DXGI_FORMAT dxgiFormat = DXGI_FORMAT_R32G32_FLOAT;
const char* semantic = "Position";
static constexpr DXGI_FORMAT dxgiFormat = DXGI_FORMAT_R32G32_FLOAT;
static constexpr const char* semantic = "Position";
};
template<> struct Map<Position3D>
{
using SysType = DirectX::XMFLOAT3;
DXGI_FORMAT dxgiFormat = DXGI_FORMAT_R32G32B32_FLOAT;
const char* semantic = "Position";
static constexpr DXGI_FORMAT dxgiFormat = DXGI_FORMAT_R32G32B32_FLOAT;
static constexpr const char* semantic = "Position";
};
template<> struct Map<Texture2D>
{
using SysType = DirectX::XMFLOAT2;
DXGI_FORMAT dxgiFormat = DXGI_FORMAT_R32G32_FLOAT;
const char* semantic = "Texcoord";
static constexpr DXGI_FORMAT dxgiFormat = DXGI_FORMAT_R32G32_FLOAT;
static constexpr const char* semantic = "Texcoord";
};
template<> struct Map<Normal>
{
using SysType = DirectX::XMFLOAT3;
DXGI_FORMAT dxgiFormat = DXGI_FORMAT_R32G32B32_FLOAT;
const char* semantic = "Normal";
static constexpr DXGI_FORMAT dxgiFormat = DXGI_FORMAT_R32G32B32_FLOAT;
static constexpr const char* semantic = "Normal";
};
template<> struct Map<Float3Color>
{
using SysType = DirectX::XMFLOAT3;
DXGI_FORMAT dxgiFormat = DXGI_FORMAT_R32G32B32_FLOAT;
const char* semantic = "Color";
static constexpr DXGI_FORMAT dxgiFormat = DXGI_FORMAT_R32G32B32_FLOAT;
static constexpr const char* semantic = "Color";
};
template<> struct Map<Float4Color>
{
using SysType = DirectX::XMFLOAT4;
DXGI_FORMAT dxgiFormat = DXGI_FORMAT_R32G32B32A32_FLOAT;
const char* semantic = "Color";
static constexpr DXGI_FORMAT dxgiFormat = DXGI_FORMAT_R32G32B32A32_FLOAT;
static constexpr const char* semantic = "Color";
};
template<> struct Map<BGRAColor>
{
using SysType = hw3dexp::BGRAColor;
DXGI_FORMAT dxgiFormat = DXGI_FORMAT_R8G8B8A8_UNORM;
const char* semantic = "Color";
static constexpr DXGI_FORMAT dxgiFormat = DXGI_FORMAT_R8G8B8A8_UNORM;
static constexpr const char* semantic = "Color";
};
class Element
......@@ -93,7 +93,6 @@ namespace hw3dexp
}
static constexpr size_t SizeOf( ElementType type ) noexcept(!IS_DEBUG)
{
using namespace DirectX;
switch( type )
{
case Position2D:
......@@ -118,6 +117,34 @@ namespace hw3dexp
{
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:
ElementType type;
size_t offset;
......@@ -153,6 +180,16 @@ namespace hw3dexp
{
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:
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