Horizon
triangle.hpp
1 #pragma once
2 #include "common/common.hpp"
3 #include "util/uuid.hpp"
4 #include "color_palette.hpp"
5 #include <epoxy/gl.h>
6 #include <unordered_map>
7 
8 namespace horizon {
9 class ObjectRef {
10 public:
11  ObjectRef(ObjectType ty, const UUID &uu, const UUID &uu2 = UUID()) : type(ty), uuid(uu), uuid2(uu2)
12  {
13  }
14  ObjectRef() : type(ObjectType::INVALID)
15  {
16  }
17  ObjectType type;
18  UUID uuid;
19  UUID uuid2;
20  bool operator<(const ObjectRef &other) const
21  {
22  if (type < other.type) {
23  return true;
24  }
25  if (type > other.type) {
26  return false;
27  }
28  if (uuid < other.uuid) {
29  return true;
30  }
31  else if (uuid > other.uuid) {
32  return false;
33  }
34  return uuid2 < other.uuid2;
35  }
36  bool operator==(const ObjectRef &other) const
37  {
38  return (type == other.type) && (uuid == other.uuid) && (uuid2 == other.uuid2);
39  }
40  bool operator!=(const ObjectRef &other) const
41  {
42  return !(*this == other);
43  }
44 };
45 
46 class Triangle {
47 public:
48  float x0;
49  float y0;
50  float x1;
51  float y1;
52  float x2;
53  float y2;
54  enum class Type { NONE, TRACK_PREVIEW, TEXT, GRAPHICS, PLANE, POLYGON };
55 
56  uint8_t type;
57  uint8_t color;
58  uint8_t lod;
59  uint8_t flags;
60 
61  static const int FLAG_HIDDEN = 1 << 0;
62  static const int FLAG_HIGHLIGHT = 1 << 1;
63  static const int FLAG_BUTT = 1 << 2;
64 
65  Triangle(const Coordf &p0, const Coordf &p1, const Coordf &p2, ColorP co, Type ty, uint8_t flg = 0,
66  uint8_t ilod = 0)
67  : x0(p0.x), y0(p0.y), x1(p1.x), y1(p1.y), x2(p2.x), y2(p2.y), type(static_cast<uint8_t>(ty)),
68  color(static_cast<uint8_t>(co)), lod(ilod), flags(flg)
69  {
70  }
71 } __attribute__((packed));
72 
74  friend class CanvasGL;
75 
76 public:
77  TriangleRenderer(class CanvasGL *c, std::unordered_map<int, std::vector<Triangle>> &tris);
78  void realize();
79  void render();
80  void push();
81 
82 private:
83  CanvasGL *ca;
84  enum class Type { TRIANGLE, LINE, LINE0, LINE_BUTT, GLYPH };
85  std::unordered_map<int, std::vector<Triangle>> &triangles;
86  std::unordered_map<int, std::unordered_map<Type, std::pair<size_t, size_t>>> layer_offsets;
87  size_t n_tris = 0;
88 
89  GLuint program_line0;
90  GLuint program_line;
91  GLuint program_line_butt;
92  GLuint program_triangle;
93  GLuint vao;
94  GLuint vbo;
95  GLuint ubo;
96  GLuint ebo;
97 
98  void render_layer(int layer);
99  void render_layer_with_overlay(int layer);
100  int stencil = 0;
101 };
102 } // namespace horizon
Definition: triangle.hpp:46
Definition: canvas_gl.hpp:13
This class encapsulates a UUID and allows it to be uses as a value type.
Definition: uuid.hpp:16
Definition: block.cpp:9
Definition: triangle.hpp:73
Definition: triangle.hpp:9