NativeVertexFormat.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. // Copyright 2008 Dolphin Emulator Project
  2. // Licensed under GPLv2+
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <functional> // for hash
  6. #include "Common/Common.h"
  7. #include "Common/Hash.h"
  8. // m_components
  9. enum
  10. {
  11. VB_HAS_POSMTXIDX =(1<<1),
  12. VB_HAS_TEXMTXIDX0=(1<<2),
  13. VB_HAS_TEXMTXIDX1=(1<<3),
  14. VB_HAS_TEXMTXIDX2=(1<<4),
  15. VB_HAS_TEXMTXIDX3=(1<<5),
  16. VB_HAS_TEXMTXIDX4=(1<<6),
  17. VB_HAS_TEXMTXIDX5=(1<<7),
  18. VB_HAS_TEXMTXIDX6=(1<<8),
  19. VB_HAS_TEXMTXIDX7=(1<<9),
  20. VB_HAS_TEXMTXIDXALL=(0xff<<2),
  21. //VB_HAS_POS=0, // Implied, it always has pos! don't bother testing
  22. VB_HAS_NRM0=(1<<10),
  23. VB_HAS_NRM1=(1<<11),
  24. VB_HAS_NRM2=(1<<12),
  25. VB_HAS_NRMALL=(7<<10),
  26. VB_HAS_COL0=(1<<13),
  27. VB_HAS_COL1=(1<<14),
  28. VB_HAS_UV0=(1<<15),
  29. VB_HAS_UV1=(1<<16),
  30. VB_HAS_UV2=(1<<17),
  31. VB_HAS_UV3=(1<<18),
  32. VB_HAS_UV4=(1<<19),
  33. VB_HAS_UV5=(1<<20),
  34. VB_HAS_UV6=(1<<21),
  35. VB_HAS_UV7=(1<<22),
  36. VB_HAS_UVALL=(0xff<<15),
  37. VB_HAS_UVTEXMTXSHIFT=13,
  38. };
  39. enum VarType
  40. {
  41. VAR_UNSIGNED_BYTE, // GX_U8 = 0
  42. VAR_BYTE, // GX_S8 = 1
  43. VAR_UNSIGNED_SHORT, // GX_U16 = 2
  44. VAR_SHORT, // GX_S16 = 3
  45. VAR_FLOAT, // GX_F32 = 4
  46. };
  47. struct AttributeFormat
  48. {
  49. VarType type;
  50. int components;
  51. int offset;
  52. bool enable;
  53. bool integer;
  54. };
  55. struct PortableVertexDeclaration
  56. {
  57. int stride;
  58. AttributeFormat position;
  59. AttributeFormat normals[3];
  60. AttributeFormat colors[2];
  61. AttributeFormat texcoords[8];
  62. AttributeFormat posmtx;
  63. inline bool operator<(const PortableVertexDeclaration& b) const
  64. {
  65. return memcmp(this, &b, sizeof(PortableVertexDeclaration)) < 0;
  66. }
  67. inline bool operator==(const PortableVertexDeclaration& b) const
  68. {
  69. return memcmp(this, &b, sizeof(PortableVertexDeclaration)) == 0;
  70. }
  71. };
  72. namespace std
  73. {
  74. template <>
  75. struct hash<PortableVertexDeclaration>
  76. {
  77. size_t operator()(const PortableVertexDeclaration& decl) const
  78. {
  79. return HashFletcher((u8 *) &decl, sizeof(decl));
  80. }
  81. };
  82. }
  83. // The implementation of this class is specific for GL/DX, so NativeVertexFormat.cpp
  84. // is in the respective backend, not here in VideoCommon.
  85. // Note that this class can't just invent arbitrary vertex formats out of its input -
  86. // all the data loading code must always be made compatible.
  87. class NativeVertexFormat : NonCopyable
  88. {
  89. public:
  90. virtual ~NativeVertexFormat() {}
  91. virtual void Initialize(const PortableVertexDeclaration &vtx_decl) = 0;
  92. virtual void SetupVertexPointers() = 0;
  93. u32 GetVertexStride() const { return vtx_decl.stride; }
  94. const PortableVertexDeclaration& GetVertexDeclaration() const { return vtx_decl; }
  95. // TODO: move this under private:
  96. u32 m_components; // VB_HAS_X. Bitmask telling what vertex components are present.
  97. protected:
  98. // Let subclasses construct.
  99. NativeVertexFormat() {}
  100. PortableVertexDeclaration vtx_decl;
  101. };