mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-21 05:09:34 -06:00
Move vertex size and component calculation to VertexLoaderBase
This commit is contained in:
@ -19,6 +19,10 @@
|
||||
|
||||
#include "VideoCommon/DataReader.h"
|
||||
#include "VideoCommon/VertexLoader.h"
|
||||
#include "VideoCommon/VertexLoader_Color.h"
|
||||
#include "VideoCommon/VertexLoader_Normal.h"
|
||||
#include "VideoCommon/VertexLoader_Position.h"
|
||||
#include "VideoCommon/VertexLoader_TextCoord.h"
|
||||
|
||||
#ifdef _M_X86_64
|
||||
#include "VideoCommon/VertexLoaderX64.h"
|
||||
@ -35,20 +39,22 @@ public:
|
||||
: VertexLoaderBase(vtx_desc, vtx_attr), a(std::move(a_)), b(std::move(b_))
|
||||
{
|
||||
ASSERT(a && b);
|
||||
if (a->m_VertexSize == b->m_VertexSize && a->m_native_components == b->m_native_components &&
|
||||
if (a->m_vertex_size == b->m_vertex_size && a->m_native_components == b->m_native_components &&
|
||||
a->m_native_vtx_decl.stride == b->m_native_vtx_decl.stride)
|
||||
{
|
||||
m_VertexSize = a->m_VertexSize;
|
||||
m_native_components = a->m_native_components;
|
||||
// These are generated from the VAT and vertex desc, so they should match.
|
||||
// m_native_vtx_decl.stride isn't set yet, though.
|
||||
ASSERT(m_vertex_size == a->m_vertex_size && m_native_components == a->m_native_components);
|
||||
|
||||
memcpy(&m_native_vtx_decl, &a->m_native_vtx_decl, sizeof(PortableVertexDeclaration));
|
||||
}
|
||||
else
|
||||
{
|
||||
ERROR_LOG_FMT(VIDEO, "Can't compare vertex loaders that expect different vertex formats!");
|
||||
ERROR_LOG_FMT(VIDEO, "a: m_VertexSize {}, m_native_components {:#010x}, stride {}",
|
||||
a->m_VertexSize, a->m_native_components, a->m_native_vtx_decl.stride);
|
||||
ERROR_LOG_FMT(VIDEO, "b: m_VertexSize {}, m_native_components {:#010x}, stride {}",
|
||||
b->m_VertexSize, b->m_native_components, b->m_native_vtx_decl.stride);
|
||||
PanicAlertFmt("Can't compare vertex loaders that expect different vertex formats!\n"
|
||||
"a: m_vertex_size {}, m_native_components {:#010x}, stride {}\n"
|
||||
"b: m_vertex_size {}, m_native_components {:#010x}, stride {}",
|
||||
a->m_vertex_size, a->m_native_components, a->m_native_vtx_decl.stride,
|
||||
b->m_vertex_size, b->m_native_components, b->m_native_vtx_decl.stride);
|
||||
}
|
||||
}
|
||||
int RunVertices(DataReader src, DataReader dst, int count) override
|
||||
@ -91,6 +97,62 @@ private:
|
||||
std::vector<u8> buffer_b;
|
||||
};
|
||||
|
||||
u32 VertexLoaderBase::GetVertexSize(const TVtxDesc& vtx_desc, const VAT& vtx_attr)
|
||||
{
|
||||
u32 size = 0;
|
||||
if (vtx_desc.low.PosMatIdx)
|
||||
size++;
|
||||
for (auto texmtxidx : vtx_desc.low.TexMatIdx)
|
||||
{
|
||||
if (texmtxidx)
|
||||
size++;
|
||||
}
|
||||
size += VertexLoader_Position::GetSize(vtx_desc.low.Position, vtx_attr.g0.PosFormat,
|
||||
vtx_attr.g0.PosElements);
|
||||
size += VertexLoader_Normal::GetSize(vtx_desc.low.Normal, vtx_attr.g0.NormalFormat,
|
||||
vtx_attr.g0.NormalElements, vtx_attr.g0.NormalIndex3);
|
||||
for (u32 i = 0; i < vtx_desc.low.Color.Size(); i++)
|
||||
{
|
||||
size += VertexLoader_Color::GetSize(vtx_desc.low.Color[i], vtx_attr.GetColorFormat(i));
|
||||
}
|
||||
for (u32 i = 0; i < vtx_desc.high.TexCoord.Size(); i++)
|
||||
{
|
||||
size += VertexLoader_TextCoord::GetSize(vtx_desc.high.TexCoord[i], vtx_attr.GetTexFormat(i),
|
||||
vtx_attr.GetTexElements(i));
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
u32 VertexLoaderBase::GetVertexComponents(const TVtxDesc& vtx_desc, const VAT& vtx_attr)
|
||||
{
|
||||
u32 components = 0;
|
||||
if (vtx_desc.low.PosMatIdx)
|
||||
components |= VB_HAS_POSMTXIDX;
|
||||
for (u32 i = 0; i < vtx_desc.low.TexMatIdx.Size(); i++)
|
||||
{
|
||||
if (vtx_desc.low.TexMatIdx[i])
|
||||
components |= VB_HAS_TEXMTXIDX0 << i;
|
||||
}
|
||||
// Vertices always have positions; thus there is no VB_HAS_POS as it would always be set
|
||||
if (vtx_desc.low.Normal != VertexComponentFormat::NotPresent)
|
||||
{
|
||||
components |= VB_HAS_NRM0;
|
||||
if (vtx_attr.g0.NormalElements == NormalComponentCount::NBT)
|
||||
components |= VB_HAS_NRM1 | VB_HAS_NRM2;
|
||||
}
|
||||
for (u32 i = 0; i < vtx_desc.low.Color.Size(); i++)
|
||||
{
|
||||
if (vtx_desc.low.Color[i] != VertexComponentFormat::NotPresent)
|
||||
components |= VB_HAS_COL0 << i;
|
||||
}
|
||||
for (u32 i = 0; i < vtx_desc.high.TexCoord.Size(); i++)
|
||||
{
|
||||
if (vtx_desc.high.TexCoord[i] != VertexComponentFormat::NotPresent)
|
||||
components |= VB_HAS_UV0 << i;
|
||||
}
|
||||
return components;
|
||||
}
|
||||
|
||||
std::unique_ptr<VertexLoaderBase> VertexLoaderBase::CreateVertexLoader(const TVtxDesc& vtx_desc,
|
||||
const VAT& vtx_attr)
|
||||
{
|
||||
|
Reference in New Issue
Block a user