diff options
| author | Pokechu22 <Pokechu022@gmail.com> | 2021-03-11 12:55:25 -0800 |
|---|---|---|
| committer | Pokechu22 <Pokechu022@gmail.com> | 2021-05-07 15:42:17 -0700 |
| commit | 0a906f553fe7699d1c863a464211f74b6c306a0f (patch) | |
| tree | 6cdb16eb84765bec99bf418c75b753b7324844ce /Source/Core/VideoCommon/VertexLoaderBase.cpp | |
| parent | fa7077763f91980e372d502b4357f3dda971ffbe (diff) | |
Move vertex size and component calculation to VertexLoaderBase
Diffstat (limited to 'Source/Core/VideoCommon/VertexLoaderBase.cpp')
| -rw-r--r-- | Source/Core/VideoCommon/VertexLoaderBase.cpp | 78 |
1 files changed, 70 insertions, 8 deletions
diff --git a/Source/Core/VideoCommon/VertexLoaderBase.cpp b/Source/Core/VideoCommon/VertexLoaderBase.cpp index 84d7eb43c0..51f9fda359 100644 --- a/Source/Core/VideoCommon/VertexLoaderBase.cpp +++ b/Source/Core/VideoCommon/VertexLoaderBase.cpp @@ -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) { |
