CommonLibSSE (powerof3)
VertexDesc.h
Go to the documentation of this file.
1 #pragma once
2 
3 namespace RE
4 {
5  //https://github.com/hexabits/nifskope/blob/develop/src/data/niftypes.h
6 
7  namespace BSGraphics
8  {
9  struct Vertex
10  {
11  enum Attribute : std::uint8_t
12  {
13  VA_POSITION = 0x0,
14  VA_TEXCOORD0 = 0x1,
15  VA_TEXCOORD1 = 0x2,
16  VA_NORMAL = 0x3,
17  VA_BINORMAL = 0x4,
18  VA_COLOR = 0x5,
19  VA_SKINNING = 0x6,
20  VA_LANDDATA = 0x7,
21  VA_EYEDATA = 0x8,
22 
23  VA_COUNT = 9
24  };
25 
26  enum Flags : std::uint16_t
27  {
37  VF_FULLPREC = 0x400
38  };
39 
40  enum Masks : std::uint64_t
41  {
42  DESC_MASK_VERT = 0xFFFFFFFFFFFFFFF0,
43  DESC_MASK_UVS = 0xFFFFFFFFFFFFFF0F,
44  DESC_MASK_NBT = 0xFFFFFFFFFFFFF0FF,
45  DESC_MASK_SKCOL = 0xFFFFFFFFFFFF0FFF,
46  DESC_MASK_DATA = 0xFFFFFFFFFFF0FFFF,
47  DESC_MASK_OFFSET = 0xFFFFFF0000000000,
49  };
50  };
51 
52  class VertexDesc
53  {
54  public:
55  [[nodiscard]] bool HasFlag(Vertex::Flags a_flag) const
56  {
57  return ((desc >> 44) & a_flag) != 0;
58  }
59  void SetFlag(Vertex::Flags a_flag)
60  {
61  desc |= (static_cast<uint64_t>(a_flag) << 44);
62  }
63  void ClearFlag(Vertex::Flags a_flag)
64  {
65  desc &= ~(static_cast<uint64_t>(a_flag) << 44);
66  }
67 
68  [[nodiscard]] std::uint32_t GetAttributeOffset(Vertex::Attribute a_attribute) const
69  {
70  return (desc >> (4 * static_cast<uint8_t>(a_attribute) + 2)) & 0x3C;
71  }
72  void SetAttributeOffset(Vertex::Attribute a_attribute, std::uint32_t a_offset)
73  {
74  if (a_attribute != Vertex::Attribute::VA_POSITION) {
75  const uint64_t lhs = static_cast<uint64_t>(a_offset) << (4 * static_cast<uint8_t>(a_attribute) + 2);
76  const uint64_t rhs = desc & ~static_cast<uint64_t>(15 << (4 * static_cast<uint8_t>(a_attribute) + 4));
77 
78  desc = lhs | rhs;
79  }
80  }
82  {
83  desc &= Vertex::Masks::DESC_MASK_OFFSET;
84  }
85 
86  [[nodiscard]] Vertex::Flags GetFlags() const
87  {
88  return static_cast<Vertex::Flags>((desc & Vertex::Masks::DESC_MASK_OFFSET) >> 44);
89  }
90  void SetFlags(Vertex::Flags a_flags)
91  {
92  desc |= (static_cast<uint64_t>(a_flags) << 44) | (desc & Vertex::Masks::DESC_MASK_FLAGS);
93  }
94 
95  [[nodiscard]] std::uint32_t GetSize()
96  {
97  std::uint32_t vertexSize = 0;
98  auto flags = GetFlags();
99 
100  if (flags & Vertex::VF_VERTEX) {
101  vertexSize += sizeof(float) * 4;
102  }
103  if (flags & Vertex::VF_UV) {
104  vertexSize += sizeof(std::uint16_t) * 2;
105  }
106  if (flags & Vertex::VF_UV_2) {
107  vertexSize += sizeof(std::uint16_t) * 2;
108  }
109  if (flags & Vertex::VF_NORMAL) {
110  vertexSize += sizeof(std::uint16_t) * 2;
111  if (flags & Vertex::VF_TANGENT) {
112  vertexSize += sizeof(std::uint16_t) * 2;
113  }
114  }
115  if (flags & Vertex::VF_COLORS) {
116  vertexSize += sizeof(std::uint8_t) * 4;
117  }
118  if (flags & Vertex::VF_SKINNED) {
119  vertexSize += sizeof(std::uint16_t) * 4 + sizeof(std::uint8_t) * 4;
120  }
121  if (flags & Vertex::VF_EYEDATA) {
122  vertexSize += sizeof(float);
123  }
124 
125  return vertexSize;
126  }
127 
128  private:
129  // members
130  std::uint64_t desc; // 00
131  };
132  static_assert(sizeof(VertexDesc) == 0x8);
133  }
134 }
Definition: VertexDesc.h:53
void SetAttributeOffset(Vertex::Attribute a_attribute, std::uint32_t a_offset)
Definition: VertexDesc.h:72
void SetFlags(Vertex::Flags a_flags)
Definition: VertexDesc.h:90
void ClearAttributeOffsets()
Definition: VertexDesc.h:81
void ClearFlag(Vertex::Flags a_flag)
Definition: VertexDesc.h:63
std::uint32_t GetAttributeOffset(Vertex::Attribute a_attribute) const
Definition: VertexDesc.h:68
void SetFlag(Vertex::Flags a_flag)
Definition: VertexDesc.h:59
bool HasFlag(Vertex::Flags a_flag) const
Definition: VertexDesc.h:55
Vertex::Flags GetFlags() const
Definition: VertexDesc.h:86
std::uint32_t GetSize()
Definition: VertexDesc.h:95
Definition: AbsorbEffect.h:6
Definition: VertexDesc.h:10
Attribute
Definition: VertexDesc.h:12
@ VA_SKINNING
Definition: VertexDesc.h:19
@ VA_POSITION
Definition: VertexDesc.h:13
@ VA_COUNT
Definition: VertexDesc.h:23
@ VA_NORMAL
Definition: VertexDesc.h:16
@ VA_BINORMAL
Definition: VertexDesc.h:17
@ VA_LANDDATA
Definition: VertexDesc.h:20
@ VA_EYEDATA
Definition: VertexDesc.h:21
@ VA_TEXCOORD0
Definition: VertexDesc.h:14
@ VA_COLOR
Definition: VertexDesc.h:18
@ VA_TEXCOORD1
Definition: VertexDesc.h:15
Masks
Definition: VertexDesc.h:41
@ DESC_MASK_VERT
Definition: VertexDesc.h:42
@ DESC_MASK_UVS
Definition: VertexDesc.h:43
@ DESC_MASK_SKCOL
Definition: VertexDesc.h:45
@ DESC_MASK_DATA
Definition: VertexDesc.h:46
@ DESC_MASK_FLAGS
Definition: VertexDesc.h:48
@ DESC_MASK_OFFSET
Definition: VertexDesc.h:47
@ DESC_MASK_NBT
Definition: VertexDesc.h:44
Flags
Definition: VertexDesc.h:27
@ VF_EYEDATA
Definition: VertexDesc.h:36
@ VF_UV_2
Definition: VertexDesc.h:30
@ VF_FULLPREC
Definition: VertexDesc.h:37
@ VF_TANGENT
Definition: VertexDesc.h:32
@ VF_VERTEX
Definition: VertexDesc.h:28
@ VF_UV
Definition: VertexDesc.h:29
@ VF_SKINNED
Definition: VertexDesc.h:34
@ VF_LANDDATA
Definition: VertexDesc.h:35
@ VF_COLORS
Definition: VertexDesc.h:33
@ VF_NORMAL
Definition: VertexDesc.h:31