Tatooine
edgeset2.h
Go to the documentation of this file.
1#ifndef TATOOINE_RENDERING_INTERACTIVE_EDGESET2_H
2#define TATOOINE_RENDERING_INTERACTIVE_EDGESET2_H
3//==============================================================================
10#include <tatooine/edgeset.h>
11//==============================================================================
13//==============================================================================
14template <floating_point Real>
17 //============================================================================
19 //============================================================================
20 private:
21 int line_width = 1;
22 Vec4<GLfloat> line_color = {0, 0, 0, 1};
23
26
27 public:
28 //============================================================================
30 if (grid.vertices().size() > 0) {
31 init_geometry(grid);
32 }
33 }
34 //----------------------------------------------------------------------------
36 m_geometry.resize(grid.vertices().size());
37 m_lines.resize(grid.simplices().size() * 2);
38 {
39 auto data = m_geometry.wmap();
40 auto k = std::size_t{};
41 for (auto const v : grid.vertices()) {
42 data[k++] = Vec2<GLfloat>{grid[v]};
43 }
44 }
45 {
46 auto data = m_lines.wmap();
47 auto k = std::size_t{};
48 for (auto const s : grid.simplices()) {
49 auto const [v0, v1] = grid[s];
50 data[k++] = v0.index();
51 data[k++] = v1.index();
52 }
53 }
54 }
55 //============================================================================
56 auto render() {
59
60 line_shader.set_color(line_color(0), line_color(1), line_color(2),
61 line_color(3));
62 gl::line_width(line_width);
63 auto vao = gl::vertexarray{};
64 vao.bind();
65 m_geometry.bind();
66 m_geometry.activate_attributes();
67 m_lines.bind();
68 vao.draw_lines(m_lines.size());
69 }
70 //----------------------------------------------------------------------------
71 auto properties(renderable_type const& /*grid*/) {
72 ImGui::PushID("##__");
73 ImGui::Text("Edgeset");
74 ImGui::DragInt("Line width", &line_width, 1, 1, 20);
75 ImGui::ColorEdit4("Wireframe Color", line_color.data());
76 ImGui::PopID();
77 }
78 //----------------------------------------------------------------------------
79 auto update(auto const /*dt*/, renderable_type const& /*grid*/,
80 camera auto const& cam) {
81 using CamReal = typename std::decay_t<decltype(cam)>::real_type;
82 static auto constexpr cam_is_float = is_same<GLfloat, CamReal>;
83 if constexpr (cam_is_float) {
84 line_shader::get().set_projection_matrix(cam.projection_matrix());
85 } else {
86 line_shader::get().set_projection_matrix(
87 Mat4<GLfloat>{cam.projection_matrix()});
88 }
89
90 if constexpr (cam_is_float) {
91 line_shader::get().set_model_view_matrix(cam.view_matrix());
92 } else {
93 line_shader::get().set_model_view_matrix(
94 Mat4<GLfloat>{cam.view_matrix()});
95 }
96 }
97};
98template <floating_point Real>
99struct renderer<tatooine::edgeset<Real, 2>>
100 : renderer<tatooine::unstructured_simplicial_grid<Real, 2, 1>> {
104};
105//==============================================================================
106} // namespace tatooine::rendering::interactive
107//==============================================================================
108#endif
auto size() const
Definition: buffer.h:460
auto resize(GLsizei size) -> void
Definition: buffer.h:640
auto wmap()
Definition: buffer.h:506
auto bind() const -> void
Definition: buffer.h:684
Definition: indexbuffer.h:13
DLL_API void bind() const
Definition: vertexarray.h:15
DLL_API void bind() const
Definition: vertexbuffer.h:22
static constexpr void activate_attributes()
Definition: vertexbuffer.h:76
Definition: grid_edge.h:16
constexpr auto data() -> ValueType *
Definition: static_multidim_array.h:260
Definition: camera.h:312
DLL_API auto line_width(GLfloat width) -> void
Definition: interactive.h:15
Definition: algorithm.h:6
typename get_impl< Container, I >::type get
Definition: get.h:11
Definition: edgeset.h:9
Definition: mat.h:14
auto update(auto const, renderable_type const &, camera auto const &cam)
Definition: edgeset2.h:79
gl::vertexbuffer< Vec2< GLfloat >, GLfloat > m_geometry
Definition: edgeset2.h:24
auto set_color(GLfloat r, GLfloat g, GLfloat b, GLfloat a=1) -> void
Definition: shaders.h:85
Definition: unstructured_simplicial_grid.h:52
Definition: vec.h:12