mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-21 13:20:27 -06:00
Move vertex size and component calculation to VertexLoaderBase
This commit is contained in:
@ -79,13 +79,9 @@ VertexLoader::VertexLoader(const TVtxDesc& vtx_desc, const VAT& vtx_attr)
|
||||
|
||||
void VertexLoader::CompileVertexTranslator()
|
||||
{
|
||||
m_VertexSize = 0;
|
||||
|
||||
// Reset pipeline
|
||||
m_numPipelineStages = 0;
|
||||
|
||||
u32 components = 0;
|
||||
|
||||
// Position in pc vertex format.
|
||||
int nat_offset = 0;
|
||||
|
||||
@ -93,71 +89,24 @@ void VertexLoader::CompileVertexTranslator()
|
||||
if (m_VtxDesc.low.PosMatIdx)
|
||||
{
|
||||
WriteCall(PosMtx_ReadDirect_UByte);
|
||||
components |= VB_HAS_POSMTXIDX;
|
||||
m_native_vtx_decl.posmtx.components = 4;
|
||||
m_native_vtx_decl.posmtx.enable = true;
|
||||
m_native_vtx_decl.posmtx.offset = nat_offset;
|
||||
m_native_vtx_decl.posmtx.type = VAR_UNSIGNED_BYTE;
|
||||
m_native_vtx_decl.posmtx.integer = true;
|
||||
nat_offset += 4;
|
||||
m_VertexSize += 1;
|
||||
}
|
||||
|
||||
if (m_VtxDesc.low.Tex0MatIdx)
|
||||
for (auto texmtxidx : m_VtxDesc.low.TexMatIdx)
|
||||
{
|
||||
m_VertexSize += 1;
|
||||
components |= VB_HAS_TEXMTXIDX0;
|
||||
WriteCall(TexMtx_ReadDirect_UByte);
|
||||
}
|
||||
if (m_VtxDesc.low.Tex1MatIdx)
|
||||
{
|
||||
m_VertexSize += 1;
|
||||
components |= VB_HAS_TEXMTXIDX1;
|
||||
WriteCall(TexMtx_ReadDirect_UByte);
|
||||
}
|
||||
if (m_VtxDesc.low.Tex2MatIdx)
|
||||
{
|
||||
m_VertexSize += 1;
|
||||
components |= VB_HAS_TEXMTXIDX2;
|
||||
WriteCall(TexMtx_ReadDirect_UByte);
|
||||
}
|
||||
if (m_VtxDesc.low.Tex3MatIdx)
|
||||
{
|
||||
m_VertexSize += 1;
|
||||
components |= VB_HAS_TEXMTXIDX3;
|
||||
WriteCall(TexMtx_ReadDirect_UByte);
|
||||
}
|
||||
if (m_VtxDesc.low.Tex4MatIdx)
|
||||
{
|
||||
m_VertexSize += 1;
|
||||
components |= VB_HAS_TEXMTXIDX4;
|
||||
WriteCall(TexMtx_ReadDirect_UByte);
|
||||
}
|
||||
if (m_VtxDesc.low.Tex5MatIdx)
|
||||
{
|
||||
m_VertexSize += 1;
|
||||
components |= VB_HAS_TEXMTXIDX5;
|
||||
WriteCall(TexMtx_ReadDirect_UByte);
|
||||
}
|
||||
if (m_VtxDesc.low.Tex6MatIdx)
|
||||
{
|
||||
m_VertexSize += 1;
|
||||
components |= VB_HAS_TEXMTXIDX6;
|
||||
WriteCall(TexMtx_ReadDirect_UByte);
|
||||
}
|
||||
if (m_VtxDesc.low.Tex7MatIdx)
|
||||
{
|
||||
m_VertexSize += 1;
|
||||
components |= VB_HAS_TEXMTXIDX7;
|
||||
WriteCall(TexMtx_ReadDirect_UByte);
|
||||
if (texmtxidx)
|
||||
WriteCall(TexMtx_ReadDirect_UByte);
|
||||
}
|
||||
|
||||
// Write vertex position loader
|
||||
WriteCall(VertexLoader_Position::GetFunction(m_VtxDesc.low.Position, m_VtxAttr.g0.PosFormat,
|
||||
m_VtxAttr.g0.PosElements));
|
||||
|
||||
m_VertexSize += VertexLoader_Position::GetSize(m_VtxDesc.low.Position, m_VtxAttr.g0.PosFormat,
|
||||
m_VtxAttr.g0.PosElements);
|
||||
int pos_elements = m_VtxAttr.g0.PosElements == CoordComponentCount::XY ? 2 : 3;
|
||||
m_native_vtx_decl.position.components = pos_elements;
|
||||
m_native_vtx_decl.position.enable = true;
|
||||
@ -169,10 +118,6 @@ void VertexLoader::CompileVertexTranslator()
|
||||
// Normals
|
||||
if (m_VtxDesc.low.Normal != VertexComponentFormat::NotPresent)
|
||||
{
|
||||
m_VertexSize +=
|
||||
VertexLoader_Normal::GetSize(m_VtxDesc.low.Normal, m_VtxAttr.g0.NormalFormat,
|
||||
m_VtxAttr.g0.NormalElements, m_VtxAttr.g0.NormalIndex3);
|
||||
|
||||
TPipelineFunction pFunc =
|
||||
VertexLoader_Normal::GetFunction(m_VtxDesc.low.Normal, m_VtxAttr.g0.NormalFormat,
|
||||
m_VtxAttr.g0.NormalElements, m_VtxAttr.g0.NormalIndex3);
|
||||
@ -194,10 +139,6 @@ void VertexLoader::CompileVertexTranslator()
|
||||
m_native_vtx_decl.normals[i].integer = false;
|
||||
nat_offset += 12;
|
||||
}
|
||||
|
||||
components |= VB_HAS_NRM0;
|
||||
if (m_VtxAttr.g0.NormalElements == NormalComponentCount::NBT)
|
||||
components |= VB_HAS_NRM1 | VB_HAS_NRM2;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < m_VtxDesc.low.Color.Size(); i++)
|
||||
@ -206,8 +147,6 @@ void VertexLoader::CompileVertexTranslator()
|
||||
m_native_vtx_decl.colors[i].type = VAR_UNSIGNED_BYTE;
|
||||
m_native_vtx_decl.colors[i].integer = false;
|
||||
|
||||
m_VertexSize +=
|
||||
VertexLoader_Color::GetSize(m_VtxDesc.low.Color[i], m_VtxAttr.GetColorFormat(i));
|
||||
TPipelineFunction pFunc =
|
||||
VertexLoader_Color::GetFunction(m_VtxDesc.low.Color[i], m_VtxAttr.GetColorFormat(i));
|
||||
|
||||
@ -218,7 +157,6 @@ void VertexLoader::CompileVertexTranslator()
|
||||
|
||||
if (m_VtxDesc.low.Color[i] != VertexComponentFormat::NotPresent)
|
||||
{
|
||||
components |= VB_HAS_COL0 << i;
|
||||
m_native_vtx_decl.colors[i].offset = nat_offset;
|
||||
m_native_vtx_decl.colors[i].enable = true;
|
||||
nat_offset += 4;
|
||||
@ -245,25 +183,21 @@ void VertexLoader::CompileVertexTranslator()
|
||||
ASSERT_MSG(VIDEO, elements == TexComponentCount::S || elements == TexComponentCount::ST,
|
||||
"Invalid number of texture coordinates elements!\n(elements = %d)", (u32)elements);
|
||||
|
||||
components |= VB_HAS_UV0 << i;
|
||||
WriteCall(VertexLoader_TextCoord::GetFunction(tc, format, elements));
|
||||
m_VertexSize += VertexLoader_TextCoord::GetSize(tc, format, elements);
|
||||
}
|
||||
|
||||
if (components & (VB_HAS_TEXMTXIDX0 << i))
|
||||
if (m_VtxDesc.low.TexMatIdx[i])
|
||||
{
|
||||
m_native_vtx_decl.texcoords[i].enable = true;
|
||||
m_native_vtx_decl.texcoords[i].components = 3;
|
||||
nat_offset += 12;
|
||||
if (tc != VertexComponentFormat::NotPresent)
|
||||
{
|
||||
// if texmtx is included, texcoord will always be 3 floats, z will be the texmtx index
|
||||
m_native_vtx_decl.texcoords[i].components = 3;
|
||||
nat_offset += 12;
|
||||
WriteCall(elements == TexComponentCount::ST ? TexMtx_Write_Float : TexMtx_Write_Float2);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_native_vtx_decl.texcoords[i].components = 3;
|
||||
nat_offset += 12;
|
||||
WriteCall(TexMtx_Write_Float3);
|
||||
}
|
||||
}
|
||||
@ -280,17 +214,21 @@ void VertexLoader::CompileVertexTranslator()
|
||||
if (tc == VertexComponentFormat::NotPresent)
|
||||
{
|
||||
// if there's more tex coords later, have to write a dummy call
|
||||
size_t j = i + 1;
|
||||
for (; j < m_VtxDesc.high.TexCoord.Size(); ++j)
|
||||
bool has_more = false;
|
||||
for (size_t j = 0; j < m_VtxDesc.high.TexCoord.Size(); ++j)
|
||||
{
|
||||
if (m_VtxDesc.high.TexCoord[j] != VertexComponentFormat::NotPresent)
|
||||
{
|
||||
has_more = true;
|
||||
WriteCall(VertexLoader_TextCoord::GetDummyFunction()); // important to get indices right!
|
||||
break;
|
||||
}
|
||||
else if (m_VtxDesc.low.TexMatIdx[i])
|
||||
{
|
||||
has_more = true;
|
||||
}
|
||||
}
|
||||
// tricky!
|
||||
if (j == 8 && !((components & VB_HAS_TEXMTXIDXALL) & (VB_HAS_TEXMTXIDXALL << (i + 1))))
|
||||
if (!has_more)
|
||||
{
|
||||
// no more tex coords and tex matrices, so exit loop
|
||||
break;
|
||||
@ -304,7 +242,6 @@ void VertexLoader::CompileVertexTranslator()
|
||||
WriteCall(SkipVertex);
|
||||
}
|
||||
|
||||
m_native_components = components;
|
||||
m_native_vtx_decl.stride = nat_offset;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user