Horizon
triangle.hpp
1 #pragma once
2 #include "common/common.hpp"
3 #include "util/uuid.hpp"
4 #include <epoxy/gl.h>
5 #include <unordered_map>
6 
7 namespace horizon {
8 
9 enum class ColorP {
10  FROM_LAYER,
11  RED,
12  GREEN,
13  YELLOW,
14  WHITE,
15  ERROR,
16  NET,
17  BUS,
18  SYMBOL,
19  FRAME,
20  AIRWIRE,
21  PIN,
22  PIN_HIDDEN,
23  DIFFPAIR,
24  N_COLORS
25 };
26 
27 class ObjectRef {
28 public:
29  ObjectRef(ObjectType ty, const UUID &uu, const UUID &uu2 = UUID()) : type(ty), uuid(uu), uuid2(uu2)
30  {
31  }
32  ObjectRef() : type(ObjectType::INVALID)
33  {
34  }
35  ObjectType type;
36  UUID uuid;
37  UUID uuid2;
38  bool operator<(const ObjectRef &other) const
39  {
40  if (type < other.type) {
41  return true;
42  }
43  if (type > other.type) {
44  return false;
45  }
46  if (uuid < other.uuid) {
47  return true;
48  }
49  else if (uuid > other.uuid) {
50  return false;
51  }
52  return uuid2 < other.uuid2;
53  }
54  bool operator==(const ObjectRef &other) const
55  {
56  return (type == other.type) && (uuid == other.uuid) && (uuid2 == other.uuid2);
57  }
58  bool operator!=(const ObjectRef &other) const
59  {
60  return !(*this == other);
61  }
62 };
63 
64 class Triangle {
65 public:
66  float x0;
67  float y0;
68  float x1;
69  float y1;
70  float x2;
71  float y2;
72  enum class Type { NONE, TRACK_PREVIEW, TEXT, GRAPHICS, PLANE, POLYGON };
73 
74  uint8_t type;
75  uint8_t color;
76  uint8_t lod;
77  uint8_t flags;
78 
79  static const int FLAG_HIDDEN = 1 << 0;
80  static const int FLAG_HIGHLIGHT = 1 << 1;
81  static const int FLAG_BUTT = 1 << 2;
82 
83  Triangle(const Coordf &p0, const Coordf &p1, const Coordf &p2, ColorP co, Type ty, uint8_t flg = 0,
84  uint8_t ilod = 0)
85  : x0(p0.x), y0(p0.y), x1(p1.x), y1(p1.y), x2(p2.x), y2(p2.y), type(static_cast<uint8_t>(ty)),
86  color(static_cast<uint8_t>(co)), lod(ilod), flags(flg)
87  {
88  }
89 } __attribute__((packed));
90 
92  friend class CanvasGL;
93 
94 public:
95  TriangleRenderer(class CanvasGL *c, std::unordered_map<int, std::vector<Triangle>> &tris);
96  void realize();
97  void render();
98  void push();
99 
100 private:
101  CanvasGL *ca;
102  std::unordered_map<int, std::vector<Triangle>> &triangles;
103  std::unordered_map<int, size_t> layer_offsets;
104  size_t n_tris = 0;
105 
106  GLuint program;
107  GLuint vao;
108  GLuint vbo;
109  GLuint ubo;
110 
111  GLuint screenmat_loc;
112  GLuint scale_loc;
113  GLuint offset_loc;
114  GLuint alpha_loc;
115  GLuint layer_color_loc;
116  GLuint layer_flags_loc;
117  GLuint types_visible_loc;
118  GLuint types_force_outline_loc;
119  GLuint highlight_mode_loc;
120  GLuint highlight_dim_loc;
121  GLuint highlight_shadow_loc;
122  GLuint highlight_lighten_loc;
123 
124  void render_layer(int layer);
125  void render_layer_with_overlay(int layer);
126  int stencil = 0;
127 };
128 } // namespace horizon
Definition: triangle.hpp:64
Definition: canvas_gl.hpp:10
This class encapsulates a UUID and allows it to be uses as a value type.
Definition: uuid.hpp:16
Definition: block.cpp:7
Definition: triangle.hpp:91
Definition: triangle.hpp:27