1 #pragma once 2 #include "triangle.hpp" 3 #include "util/gl_inc.h" 4 #include <map> 5 #include <vector> 6 #include <tuple> 7 #include "util/vector_pair.hpp" 8 9 namespace horizon { 10 class TriangleRenderer { 11 friend class CanvasGL; 12 13 public: 14 TriangleRenderer(const class CanvasGL &c, const std::map<int, vector_pair<Triangle, TriangleInfo>> &tris); 15 void realize(); 16 void render(); 17 void push(); 18 19 private: 20 const CanvasGL &ca; 21 enum class Type { TRIANGLE, LINE, LINE0, LINE_BUTT, GLYPH, CIRCLE, ARC, ARC0 }; 22 const std::map<int, vector_pair<Triangle, TriangleInfo>> &triangles; 23 24 struct BatchKey { 25 Type type; 26 bool highlight; 27 bool stencil; 28 29 private: tiehorizon::TriangleRenderer::BatchKey30 auto tie() const 31 { 32 return std::tie(type, highlight, stencil); 33 } 34 35 public: operator <horizon::TriangleRenderer::BatchKey36 bool operator<(const BatchKey &other) const 37 { 38 return tie() < other.tie(); 39 } operator ==horizon::TriangleRenderer::BatchKey40 bool operator==(const BatchKey &other) const 41 { 42 return tie() == other.tie(); 43 } 44 }; 45 46 struct Span { 47 size_t offset; 48 size_t count; 49 }; 50 51 std::map<int, std::map<BatchKey, Span>> layer_offsets; 52 size_t n_tris = 0; 53 54 GLuint program_line0; 55 GLuint program_line; 56 GLuint program_line_butt; 57 GLuint program_triangle; 58 GLuint program_circle; 59 GLuint program_glyph; 60 GLuint program_arc; 61 GLuint program_arc0; 62 GLuint vao; 63 GLuint vbo; 64 GLuint ubo; 65 GLuint ebo; 66 GLuint texture_glyph; 67 68 enum class HighlightMode { SKIP, ONLY }; 69 void render_layer(int layer, HighlightMode highlight_mode, bool ignore_flip = false); 70 using Batch = std::vector<decltype(layer_offsets)::mapped_type::value_type>; 71 void render_layer_batch(int layer, HighlightMode highlight_mode, bool ignore_flip, const Batch &batch, 72 bool use_stencil, bool stencil_mode); 73 void render_annotations(bool top); 74 std::array<float, 4> apply_highlight(const class Color &color, HighlightMode mode, int layer) const; 75 int stencil = 0; 76 }; 77 } // namespace horizon 78