VertexLoaderBase.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // Copyright 2014 Dolphin Emulator Project
  2. // Licensed under GPLv2+
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <array>
  6. #include <string>
  7. #include "Common/CommonTypes.h"
  8. #include "VideoCommon/CPMemory.h"
  9. #include "VideoCommon/DataReader.h"
  10. #include "VideoCommon/NativeVertexFormat.h"
  11. class VertexLoaderUID
  12. {
  13. std::array<u32, 5> vid;
  14. size_t hash;
  15. public:
  16. VertexLoaderUID()
  17. {
  18. }
  19. VertexLoaderUID(const TVtxDesc& vtx_desc, const VAT& vat)
  20. {
  21. vid[0] = vtx_desc.Hex & 0xFFFFFFFF;
  22. vid[1] = vtx_desc.Hex >> 32;
  23. vid[2] = vat.g0.Hex;
  24. vid[3] = vat.g1.Hex;
  25. vid[4] = vat.g2.Hex;
  26. hash = CalculateHash();
  27. }
  28. bool operator == (const VertexLoaderUID& rh) const
  29. {
  30. return vid == rh.vid;
  31. }
  32. size_t GetHash() const
  33. {
  34. return hash;
  35. }
  36. private:
  37. size_t CalculateHash() const
  38. {
  39. size_t h = -1;
  40. for (auto word : vid)
  41. {
  42. h = h * 137 + word;
  43. }
  44. return h;
  45. }
  46. };
  47. namespace std
  48. {
  49. template <> struct hash<VertexLoaderUID>
  50. {
  51. size_t operator()(const VertexLoaderUID& uid) const
  52. {
  53. return uid.GetHash();
  54. }
  55. };
  56. }
  57. class VertexLoaderBase
  58. {
  59. public:
  60. static VertexLoaderBase* CreateVertexLoader(const TVtxDesc &vtx_desc, const VAT &vtx_attr);
  61. virtual ~VertexLoaderBase() {}
  62. virtual int RunVertices(DataReader src, DataReader dst, int count) = 0;
  63. virtual bool IsInitialized() = 0;
  64. // For debugging / profiling
  65. void AppendToString(std::string *dest) const;
  66. virtual std::string GetName() const = 0;
  67. // per loader public state
  68. int m_VertexSize; // number of bytes of a raw GC vertex
  69. PortableVertexDeclaration m_native_vtx_decl;
  70. u32 m_native_components;
  71. // used by VertexLoaderManager
  72. NativeVertexFormat* m_native_vertex_format;
  73. int m_numLoadedVertices;
  74. protected:
  75. VertexLoaderBase(const TVtxDesc &vtx_desc, const VAT &vtx_attr);
  76. void SetVAT(const VAT& vat);
  77. // GC vertex format
  78. TVtxAttr m_VtxAttr; // VAT decoded into easy format
  79. TVtxDesc m_VtxDesc; // Not really used currently - or well it is, but could be easily avoided.
  80. VAT m_vat;
  81. };