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 
7 namespace horizon {
8 class ObjectRef {
9 public:
10  ObjectRef(ObjectType ty, const UUID &uu, const UUID &uu2 = UUID()) : type(ty), uuid(uu), uuid2(uu2)
11  {
12  }
13  ObjectRef() : type(ObjectType::INVALID)
14  {
15  }
16  ObjectType type;
17  UUID uuid;
18  UUID uuid2;
19  bool operator<(const ObjectRef &other) const
20  {
21  if (type < other.type) {
22  return true;
23  }
24  if (type > other.type) {
25  return false;
26  }
27  if (uuid < other.uuid) {
28  return true;
29  }
30  else if (uuid > other.uuid) {
31  return false;
32  }
33  return uuid2 < other.uuid2;
34  }
35  bool operator==(const ObjectRef &other) const
36  {
37  return (type == other.type) && (uuid == other.uuid) && (uuid2 == other.uuid2);
38  }
39  bool operator!=(const ObjectRef &other) const
40  {
41  return !(*this == other);
42  }
43 };
44 
45 class Triangle {
46 public:
47  float x0;
48  float y0;
49  float x1;
50  float y1;
51  float x2;
52  float y2;
53  enum class Type { NONE, TRACK_PREVIEW, TEXT, GRAPHICS, PLANE, POLYGON };
54 
55  uint8_t type;
56  uint8_t color;
57  uint8_t lod;
58  uint8_t flags;
59 
60  static const int FLAG_HIDDEN = 1 << 0;
61  static const int FLAG_HIGHLIGHT = 1 << 1;
62  static const int FLAG_BUTT = 1 << 2;
63  static const int FLAG_GLYPH = 1 << 3;
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::map<int, std::vector<Triangle>> &tris);
78  void realize();
79  void render();
80  void push();
81  enum class HighlightMode { SKIP, ONLY, ALL };
82 
83 private:
84  CanvasGL *ca;
85  enum class Type { TRIANGLE, LINE, LINE0, LINE_BUTT, GLYPH };
86  std::map<int, std::vector<Triangle>> &triangles;
87  std::map<int, std::map<std::pair<Type, bool>, std::pair<size_t, size_t>>> layer_offsets;
88  size_t n_tris = 0;
89 
90  GLuint program_line0;
91  GLuint program_line;
92  GLuint program_line_butt;
93  GLuint program_triangle;
94  GLuint program_glyph;
95  GLuint vao;
96  GLuint vbo;
97  GLuint ubo;
98  GLuint ebo;
99  GLuint texture_glyph;
100 
101  void render_layer(int layer, HighlightMode highlight_mode = HighlightMode::ALL, bool ignore_flip = false);
102  void render_layer_with_overlay(int layer, HighlightMode highlight_mode = HighlightMode::ALL);
103  int stencil = 0;
104 };
105 } // namespace horizon
libzip::uint8_t
zip_uint8_t uint8_t
zip_uint8_t typedef.
Definition: zip.hpp:78
horizon::ObjectRef
Definition: triangle.hpp:8
horizon::CanvasGL
Definition: canvas_gl.hpp:15
horizon::Coord< float >
horizon::Triangle
Definition: triangle.hpp:45
horizon::UUID
This class encapsulates a UUID and allows it to be uses as a value type.
Definition: uuid.hpp:16
horizon::TriangleRenderer
Definition: triangle.hpp:73