2014-12-12 17:51:14 -07:00
|
|
|
// Copyright 2014 Dolphin Emulator Project
|
2015-05-17 17:08:10 -06:00
|
|
|
// Licensed under GPLv2+
|
2014-12-12 17:51:14 -07:00
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <array>
|
2015-12-22 17:59:32 -07:00
|
|
|
#include <memory>
|
2014-12-12 17:51:14 -07:00
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "Common/CommonTypes.h"
|
|
|
|
#include "VideoCommon/CPMemory.h"
|
|
|
|
#include "VideoCommon/NativeVertexFormat.h"
|
|
|
|
|
2016-01-31 12:51:55 -07:00
|
|
|
class DataReader;
|
|
|
|
|
2014-12-12 17:51:14 -07:00
|
|
|
class VertexLoaderUID
|
|
|
|
{
|
|
|
|
std::array<u32, 5> vid;
|
|
|
|
size_t hash;
|
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
public:
|
2014-12-12 17:51:14 -07:00
|
|
|
VertexLoaderUID() {}
|
|
|
|
VertexLoaderUID(const TVtxDesc& vtx_desc, const VAT& vat)
|
2016-06-24 02:43:46 -06:00
|
|
|
{
|
2021-02-08 16:22:10 -07:00
|
|
|
vid[0] = vtx_desc.GetLegacyHex0();
|
|
|
|
vid[1] = vtx_desc.GetLegacyHex1();
|
2014-12-12 17:51:14 -07:00
|
|
|
vid[2] = vat.g0.Hex;
|
|
|
|
vid[3] = vat.g1.Hex;
|
|
|
|
vid[4] = vat.g2.Hex;
|
|
|
|
hash = CalculateHash();
|
2016-06-24 02:43:46 -06:00
|
|
|
}
|
|
|
|
|
2014-12-12 17:51:14 -07:00
|
|
|
bool operator==(const VertexLoaderUID& rh) const { return vid == rh.vid; }
|
|
|
|
size_t GetHash() const { return hash; }
|
2018-04-12 06:18:04 -06:00
|
|
|
|
2014-12-12 17:51:14 -07:00
|
|
|
private:
|
|
|
|
size_t CalculateHash() const
|
2016-06-24 02:43:46 -06:00
|
|
|
{
|
2017-06-07 05:16:02 -06:00
|
|
|
size_t h = SIZE_MAX;
|
2014-12-12 17:51:14 -07:00
|
|
|
|
|
|
|
for (auto word : vid)
|
|
|
|
{
|
|
|
|
h = h * 137 + word;
|
2016-06-24 02:43:46 -06:00
|
|
|
}
|
2014-12-12 17:51:14 -07:00
|
|
|
|
|
|
|
return h;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
namespace std
|
|
|
|
{
|
|
|
|
template <>
|
|
|
|
struct hash<VertexLoaderUID>
|
|
|
|
{
|
|
|
|
size_t operator()(const VertexLoaderUID& uid) const { return uid.GetHash(); }
|
|
|
|
};
|
2019-05-05 17:48:12 -06:00
|
|
|
} // namespace std
|
2014-12-12 17:51:14 -07:00
|
|
|
|
|
|
|
class VertexLoaderBase
|
|
|
|
{
|
|
|
|
public:
|
2015-12-22 17:59:32 -07:00
|
|
|
static std::unique_ptr<VertexLoaderBase> CreateVertexLoader(const TVtxDesc& vtx_desc,
|
|
|
|
const VAT& vtx_attr);
|
2015-01-11 08:20:44 -07:00
|
|
|
virtual ~VertexLoaderBase() {}
|
2015-04-06 03:44:13 -06:00
|
|
|
virtual int RunVertices(DataReader src, DataReader dst, int count) = 0;
|
2014-12-12 17:51:14 -07:00
|
|
|
|
|
|
|
// per loader public state
|
2017-03-23 06:34:35 -06:00
|
|
|
int m_VertexSize = 0; // number of bytes of a raw GC vertex
|
|
|
|
PortableVertexDeclaration m_native_vtx_decl{};
|
|
|
|
u32 m_native_components = 0;
|
2014-12-12 17:51:14 -07:00
|
|
|
|
|
|
|
// used by VertexLoaderManager
|
2017-03-23 06:34:35 -06:00
|
|
|
NativeVertexFormat* m_native_vertex_format = nullptr;
|
|
|
|
int m_numLoadedVertices = 0;
|
2014-12-12 17:51:14 -07:00
|
|
|
|
|
|
|
protected:
|
2021-03-10 23:15:43 -07:00
|
|
|
VertexLoaderBase(const TVtxDesc& vtx_desc, const VAT& vtx_attr)
|
|
|
|
: m_VtxDesc{vtx_desc}, m_VtxAttr{vtx_attr} {};
|
2014-12-12 17:51:14 -07:00
|
|
|
|
|
|
|
// GC vertex format
|
2021-03-10 23:15:43 -07:00
|
|
|
const VAT m_VtxAttr;
|
|
|
|
const TVtxDesc m_VtxDesc;
|
2014-12-12 17:51:14 -07:00
|
|
|
};
|