diff --git a/Arrangement_on_surface_2/demo/earth/CMakeLists.txt b/Arrangement_on_surface_2/demo/earth/CMakeLists.txt index 3760a72aace..fbcb7351955 100644 --- a/Arrangement_on_surface_2/demo/earth/CMakeLists.txt +++ b/Arrangement_on_surface_2/demo/earth/CMakeLists.txt @@ -77,7 +77,7 @@ source_group( "Graphics" FILES ${source_files_graphics} ) # GRAPHICS-GEOMETRY (Graphics-related) file(GLOB source_files_graphics_geometry Line_strips.h Line_strips.cpp - SingleVertex.h SingleVertex.cpp + Single_vertex.h Single_vertex.cpp Sphere.h Sphere.cpp Triangles.h Triangles.cpp Vertices.h Vertices.cpp diff --git a/Arrangement_on_surface_2/demo/earth/Main_widget.cpp b/Arrangement_on_surface_2/demo/earth/Main_widget.cpp index ecbbd4b29c4..ddb44b76ef0 100644 --- a/Arrangement_on_surface_2/demo/earth/Main_widget.cpp +++ b/Arrangement_on_surface_2/demo/earth/Main_widget.cpp @@ -37,6 +37,10 @@ Main_widget::~Main_widget() doneCurrent(); } +void Main_widget::set_mouse_pos(const QVector3D mouse_pos) +{ + m_gr_mouse_vertex->set_pos(mouse_pos); +} void Main_widget::hightlight_country(const std::string& country_name) { static std::string prev_picked_country; @@ -102,8 +106,8 @@ void Main_widget::initializeGL() { m_pick_handler = std::make_unique(*this); - m_mouse_pos = QVector3D(0, -1, 0); - m_gr_mouse_vertex = std::make_unique(m_mouse_pos); + QVector3D initial_mouse_pos(0, -1, 0); + m_gr_mouse_vertex = std::make_unique(initial_mouse_pos); // triangulation { @@ -386,7 +390,7 @@ void Main_widget::paintGL() //auto pos = m_mouse_vertex->get_pos(); //pos.setX(pos.x() + 0.01); //m_mouse_vertex->set_pos(pos); - m_gr_mouse_vertex->set_pos(m_mouse_pos); + //m_gr_mouse_vertex->set_pos(m_mouse_pos); draw_safe(m_gr_mouse_vertex); } diff --git a/Arrangement_on_surface_2/demo/earth/Main_widget.h b/Arrangement_on_surface_2/demo/earth/Main_widget.h index e13aa5adfd9..3e958926813 100644 --- a/Arrangement_on_surface_2/demo/earth/Main_widget.h +++ b/Arrangement_on_surface_2/demo/earth/Main_widget.h @@ -29,7 +29,7 @@ #include "Kml_reader.h" #include "Line_strips.h" #include "Shader_program.h" -#include "SingleVertex.h" +#include "Single_vertex.h" #include "Sphere.h" #include "Triangles.h" #include "Vertices.h" @@ -49,7 +49,7 @@ class Main_widget : public QOpenGLWidget, protected OpenGLFunctionsBase auto& get_model_matrix() { return m_model; } auto& get_arr_handle() { return m_arrh; } - void set_mouse_pos(const QVector3D mouse_pos) { m_mouse_pos = mouse_pos; } + void set_mouse_pos(const QVector3D mouse_pos); void hightlight_country(const std::string& country_name); @@ -92,8 +92,7 @@ class Main_widget : public QOpenGLWidget, protected OpenGLFunctionsBase std::unique_ptr m_pick_handler; // These are used to highlight the picked position by right-mouse click - QVector3D m_mouse_pos; - std::unique_ptr m_gr_mouse_vertex; + std::unique_ptr m_gr_mouse_vertex; // TRIANGLES for rendering the countries in solid diff --git a/Arrangement_on_surface_2/demo/earth/SingleVertex.cpp b/Arrangement_on_surface_2/demo/earth/Single_vertex.cpp similarity index 67% rename from Arrangement_on_surface_2/demo/earth/SingleVertex.cpp rename to Arrangement_on_surface_2/demo/earth/Single_vertex.cpp index 439af35bc12..2793f175ae4 100644 --- a/Arrangement_on_surface_2/demo/earth/SingleVertex.cpp +++ b/Arrangement_on_surface_2/demo/earth/Single_vertex.cpp @@ -7,10 +7,10 @@ // // Author(s): Engin Deniz Diktas -#include "SingleVertex.h" +#include "Single_vertex.h" -SingleVertex::SingleVertex(const QVector3D& pos) +Single_vertex::Single_vertex(const QVector3D& pos) { initializeOpenGLFunctions(); @@ -47,35 +47,40 @@ SingleVertex::SingleVertex(const QVector3D& pos) } -void SingleVertex::set_visible(bool flag) +void Single_vertex::set_visible(bool flag) { m_visible = flag; } -void SingleVertex::set_pos(const QVector3D& pos) +void Single_vertex::set_pos(const QVector3D& pos) { m_pos = pos; - glBindBuffer(GL_ARRAY_BUFFER, m_vbo); - auto vertex_buffer_size = sizeof(m_pos); - auto vertex_buffer_data = reinterpret_cast(&m_pos); - auto offset = 0; - glBufferSubData(GL_ARRAY_BUFFER, - offset, - vertex_buffer_size, - vertex_buffer_data); + m_update = true; } -const QVector3D& SingleVertex::get_pos() const +const QVector3D& Single_vertex::get_pos() const { return m_pos; } -void SingleVertex::draw() +void Single_vertex::draw() { if (m_visible) { + if (m_update) + { + glBindBuffer(GL_ARRAY_BUFFER, m_vbo); + auto vertex_buffer_size = sizeof(m_pos); + auto vertex_buffer_data = reinterpret_cast(&m_pos); + auto offset = 0; + glBufferSubData(GL_ARRAY_BUFFER, + offset, + vertex_buffer_size, + vertex_buffer_data); + m_update = false; + } + glBindVertexArray(m_vao); glDrawArrays(GL_POINTS, 0, 1); glBindVertexArray(0); } } - diff --git a/Arrangement_on_surface_2/demo/earth/SingleVertex.h b/Arrangement_on_surface_2/demo/earth/Single_vertex.h similarity index 78% rename from Arrangement_on_surface_2/demo/earth/SingleVertex.h rename to Arrangement_on_surface_2/demo/earth/Single_vertex.h index c64e4167d63..5c6f7da576d 100644 --- a/Arrangement_on_surface_2/demo/earth/SingleVertex.h +++ b/Arrangement_on_surface_2/demo/earth/Single_vertex.h @@ -15,10 +15,10 @@ #include "Common_defs.h" -class SingleVertex : protected OpenGLFunctionsBase +class Single_vertex : protected OpenGLFunctionsBase { public: - SingleVertex(const QVector3D& pos); + Single_vertex(const QVector3D& pos); void set_visible(bool flag); void set_pos(const QVector3D& pos); @@ -28,6 +28,7 @@ class SingleVertex : protected OpenGLFunctionsBase private: bool m_visible; + bool m_update = true; // flag to update the VBO (set_pos sets this) GLuint m_vao, m_vbo; QVector3D m_pos; };