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