dolphin/Source/Core/VideoCommon/VertexLoaderBase.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

89 lines
2.2 KiB
C
Raw Normal View History

// Copyright 2014 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <array>
#include <memory>
#include <string>
2021-03-11 23:43:00 +00:00
#include <vector>
#include "Common/CommonTypes.h"
#include "VideoCommon/CPMemory.h"
#include "VideoCommon/NativeVertexFormat.h"
class VertexLoaderUID
{
std::array<u32, 5> vid{};
size_t hash = 0;
public:
VertexLoaderUID() {}
VertexLoaderUID(const TVtxDesc& vtx_desc, const VAT& vat)
{
2021-06-09 04:35:43 +00:00
vid[0] = vtx_desc.low.Hex;
vid[1] = vtx_desc.high.Hex;
vid[2] = vat.g0.Hex;
vid[3] = vat.g1.Hex;
vid[4] = vat.g2.Hex;
hash = CalculateHash();
}
bool operator==(const VertexLoaderUID& rh) const { return vid == rh.vid; }
size_t GetHash() const { return hash; }
2018-04-12 12:18:04 +00:00
private:
size_t CalculateHash() const
{
size_t h = SIZE_MAX;
for (auto word : vid)
{
h = h * 137 + word;
}
return h;
}
};
namespace std
{
template <>
struct hash<VertexLoaderUID>
{
size_t operator()(const VertexLoaderUID& uid) const { return uid.GetHash(); }
};
} // namespace std
class VertexLoaderBase
{
public:
static u32 GetVertexSize(const TVtxDesc& vtx_desc, const VAT& vtx_attr);
static u32 GetVertexComponents(const TVtxDesc& vtx_desc, const VAT& vtx_attr);
static std::unique_ptr<VertexLoaderBase> CreateVertexLoader(const TVtxDesc& vtx_desc,
const VAT& vtx_attr);
2015-01-11 15:20:44 +00:00
virtual ~VertexLoaderBase() {}
virtual int RunVertices(const u8* src, u8* dst, int count) = 0;
// per loader public state
PortableVertexDeclaration m_native_vtx_decl{};
const u32 m_vertex_size; // number of bytes of a raw GC vertex
const u32 m_native_components;
// used by VertexLoaderManager
NativeVertexFormat* m_native_vertex_format = nullptr;
int m_numLoadedVertices = 0;
protected:
2021-03-11 06:15:43 +00:00
VertexLoaderBase(const TVtxDesc& vtx_desc, const VAT& vtx_attr)
2021-05-30 16:10:20 +00:00
: m_vertex_size{GetVertexSize(vtx_desc, vtx_attr)}, m_native_components{GetVertexComponents(
vtx_desc, vtx_attr)},
m_VtxAttr{vtx_attr}, m_VtxDesc{vtx_desc}
{
}
// GC vertex format
2021-03-11 06:15:43 +00:00
const VAT m_VtxAttr;
const TVtxDesc m_VtxDesc;
};