mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2024-11-14 13:27:45 -07:00
VideoBackends/D3D11: Simplify vertex attribute code
This commit is contained in:
parent
cc5640245c
commit
f5d11c1e38
@ -103,69 +103,18 @@ D3DVertexFormat::D3DVertexFormat(const PortableVertexDeclaration& vtx_decl)
|
||||
: NativeVertexFormat(vtx_decl)
|
||||
|
||||
{
|
||||
const AttributeFormat* format = &vtx_decl.position;
|
||||
if (format->enable)
|
||||
{
|
||||
m_elems[m_num_elems].SemanticName = "TEXCOORD";
|
||||
m_elems[m_num_elems].SemanticIndex = static_cast<u32>(ShaderAttrib::Position);
|
||||
m_elems[m_num_elems].AlignedByteOffset = format->offset;
|
||||
m_elems[m_num_elems].Format = VarToD3D(format->type, format->components, format->integer);
|
||||
m_elems[m_num_elems].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
|
||||
++m_num_elems;
|
||||
}
|
||||
AddAttribute(vtx_decl.position, ShaderAttrib::Position);
|
||||
|
||||
for (u32 i = 0; i < 3; i++)
|
||||
{
|
||||
format = &vtx_decl.normals[i];
|
||||
if (format->enable)
|
||||
{
|
||||
m_elems[m_num_elems].SemanticName = "TEXCOORD";
|
||||
m_elems[m_num_elems].SemanticIndex = static_cast<u32>(ShaderAttrib::Normal + i);
|
||||
m_elems[m_num_elems].AlignedByteOffset = format->offset;
|
||||
m_elems[m_num_elems].Format = VarToD3D(format->type, format->components, format->integer);
|
||||
m_elems[m_num_elems].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
|
||||
++m_num_elems;
|
||||
}
|
||||
}
|
||||
AddAttribute(vtx_decl.normals[i], ShaderAttrib::Normal + i);
|
||||
|
||||
for (u32 i = 0; i < 2; i++)
|
||||
{
|
||||
format = &vtx_decl.colors[i];
|
||||
if (format->enable)
|
||||
{
|
||||
m_elems[m_num_elems].SemanticName = "TEXCOORD";
|
||||
m_elems[m_num_elems].SemanticIndex = static_cast<u32>(ShaderAttrib::Color0 + i);
|
||||
m_elems[m_num_elems].AlignedByteOffset = format->offset;
|
||||
m_elems[m_num_elems].Format = VarToD3D(format->type, format->components, format->integer);
|
||||
m_elems[m_num_elems].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
|
||||
++m_num_elems;
|
||||
}
|
||||
}
|
||||
AddAttribute(vtx_decl.colors[i], ShaderAttrib::Color0 + i);
|
||||
|
||||
for (u32 i = 0; i < 8; i++)
|
||||
{
|
||||
format = &vtx_decl.texcoords[i];
|
||||
if (format->enable)
|
||||
{
|
||||
m_elems[m_num_elems].SemanticName = "TEXCOORD";
|
||||
m_elems[m_num_elems].SemanticIndex = static_cast<u32>(ShaderAttrib::TexCoord0 + i);
|
||||
m_elems[m_num_elems].AlignedByteOffset = format->offset;
|
||||
m_elems[m_num_elems].Format = VarToD3D(format->type, format->components, format->integer);
|
||||
m_elems[m_num_elems].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
|
||||
++m_num_elems;
|
||||
}
|
||||
}
|
||||
AddAttribute(vtx_decl.texcoords[i], ShaderAttrib::TexCoord0 + i);
|
||||
|
||||
format = &vtx_decl.posmtx;
|
||||
if (format->enable)
|
||||
{
|
||||
m_elems[m_num_elems].SemanticName = "TEXCOORD";
|
||||
m_elems[m_num_elems].SemanticIndex = static_cast<u32>(ShaderAttrib::PositionMatrix);
|
||||
m_elems[m_num_elems].AlignedByteOffset = format->offset;
|
||||
m_elems[m_num_elems].Format = VarToD3D(format->type, format->components, format->integer);
|
||||
m_elems[m_num_elems].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
|
||||
++m_num_elems;
|
||||
}
|
||||
AddAttribute(vtx_decl.posmtx, ShaderAttrib::PositionMatrix);
|
||||
}
|
||||
|
||||
D3DVertexFormat::~D3DVertexFormat()
|
||||
@ -201,4 +150,17 @@ ID3D11InputLayout* D3DVertexFormat::GetInputLayout(const void* vs_bytecode, size
|
||||
return layout;
|
||||
}
|
||||
|
||||
void D3DVertexFormat::AddAttribute(const AttributeFormat& format, ShaderAttrib semantic_index)
|
||||
{
|
||||
if (format.enable)
|
||||
{
|
||||
m_elems[m_num_elems].SemanticName = "TEXCOORD";
|
||||
m_elems[m_num_elems].SemanticIndex = static_cast<u32>(semantic_index);
|
||||
m_elems[m_num_elems].AlignedByteOffset = format.offset;
|
||||
m_elems[m_num_elems].Format = VarToD3D(format.type, format.components, format.integer);
|
||||
m_elems[m_num_elems].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
|
||||
++m_num_elems;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace DX11
|
||||
|
@ -12,6 +12,8 @@
|
||||
#include "VideoCommon/NativeVertexFormat.h"
|
||||
#include "VideoCommon/VertexManagerBase.h"
|
||||
|
||||
enum class ShaderAttrib : u32;
|
||||
|
||||
namespace DX11
|
||||
{
|
||||
class D3DVertexFormat : public NativeVertexFormat
|
||||
@ -22,6 +24,8 @@ public:
|
||||
ID3D11InputLayout* GetInputLayout(const void* vs_bytecode, size_t vs_bytecode_size);
|
||||
|
||||
private:
|
||||
void AddAttribute(const AttributeFormat& format, ShaderAttrib semantic_index);
|
||||
|
||||
std::array<D3D11_INPUT_ELEMENT_DESC, 32> m_elems{};
|
||||
UINT m_num_elems = 0;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user