1#pragma once
2
3#include <stddef.h>
4#include "taichi/common/platform_macros.h"
5
6#include <type_traits>
7
8namespace taichi {
9namespace ui {
10
11struct Vertex {
12 struct vec3 {
13 float x;
14 float y;
15 float z;
16 };
17 struct vec4 {
18 float x;
19 float y;
20 float z;
21 float w;
22 };
23 struct vec2 {
24 float x;
25 float y;
26 };
27 vec3 pos;
28 vec3 normal;
29 vec2 tex_coord;
30 vec4 color;
31};
32
33enum class VertexAttributes : char {
34 kPos = 0b0001,
35 kNormal = 0b0010,
36 kUv = 0b0100,
37 kColor = 0b1000,
38};
39
40constexpr inline VertexAttributes operator|(VertexAttributes src,
41 VertexAttributes a) {
42 using UT = std::underlying_type_t<VertexAttributes>;
43 return static_cast<VertexAttributes>(UT(src) | UT(a));
44}
45
46class TI_DLL_EXPORT VboHelpers {
47 public:
48 constexpr static VertexAttributes kOrderedAttrs[] = {
49 VertexAttributes::kPos,
50 VertexAttributes::kNormal,
51 VertexAttributes::kUv,
52 VertexAttributes::kColor,
53 };
54
55 constexpr static VertexAttributes empty() {
56 return static_cast<VertexAttributes>(0);
57 }
58 constexpr static VertexAttributes all() {
59 return VertexAttributes::kPos | VertexAttributes::kNormal |
60 VertexAttributes::kUv | VertexAttributes::kColor;
61 }
62
63 static bool has_attr(VertexAttributes src, VertexAttributes attr) {
64 using UT = std::underlying_type_t<VertexAttributes>;
65 return UT(src) & UT(attr);
66 }
67};
68
69} // namespace ui
70} // namespace taichi
71