diff --git a/scwx-qt/source/scwx/qt/gl/draw/placefile_polygons.cpp b/scwx-qt/source/scwx/qt/gl/draw/placefile_polygons.cpp index 67d04a3d..11152a5a 100644 --- a/scwx-qt/source/scwx/qt/gl/draw/placefile_polygons.cpp +++ b/scwx-qt/source/scwx/qt/gl/draw/placefile_polygons.cpp @@ -233,11 +233,15 @@ void PlacefilePolygons::Deinitialize() gl.glDeleteVertexArrays(1, &p->vao_); gl.glDeleteBuffers(2, p->vbo_.data()); + + // Clear the current buffers + p->currentBuffer_.clear(); + p->currentThresholdBuffer_.clear(); } void PlacefilePolygons::StartPolygons() { - // Clear the new buffer + // Clear the new buffers p->newBuffer_.clear(); p->newThresholdBuffer_.clear(); } @@ -259,6 +263,10 @@ void PlacefilePolygons::FinishPolygons() p->currentBuffer_.swap(p->newBuffer_); p->currentThresholdBuffer_.swap(p->newThresholdBuffer_); + // Clear the new buffers + p->newBuffer_.clear(); + p->newThresholdBuffer_.clear(); + // Mark the draw item dirty p->dirty_ = true; } diff --git a/scwx-qt/source/scwx/qt/gl/draw/placefile_text.cpp b/scwx-qt/source/scwx/qt/gl/draw/placefile_text.cpp index ee28800a..e15d7fdc 100644 --- a/scwx-qt/source/scwx/qt/gl/draw/placefile_text.cpp +++ b/scwx-qt/source/scwx/qt/gl/draw/placefile_text.cpp @@ -45,7 +45,6 @@ public: std::string placefileName_; - bool dirty_ {false}; bool thresholded_ {false}; std::uint32_t textId_ {}; @@ -59,9 +58,9 @@ public: units::length::nautical_miles mapDistance_ {}; + std::mutex listMutex_ {}; std::vector> textList_ {}; - - void Update(); + std::vector> newList_ {}; }; PlacefileText::PlacefileText(std::shared_ptr context, @@ -84,18 +83,15 @@ void PlacefileText::set_thresholded(bool thresholded) p->thresholded_ = thresholded; } -void PlacefileText::Initialize() -{ - p->dirty_ = true; -} +void PlacefileText::Initialize() {} void PlacefileText::Render( const QMapLibreGL::CustomLayerRenderParameters& params) { + std::unique_lock lock {p->listMutex_}; + if (!p->textList_.empty()) { - p->Update(); - // Reset text ID per frame p->textId_ = 0; @@ -209,7 +205,14 @@ void PlacefileText::Impl::RenderText( void PlacefileText::Deinitialize() { - Reset(); + // Clear the text list + p->textList_.clear(); +} + +void PlacefileText::StartText() +{ + // Clear the new list + p->newList_.clear(); } void PlacefileText::AddText( @@ -217,21 +220,19 @@ void PlacefileText::AddText( { if (di != nullptr) { - p->textList_.emplace_back(di); - p->dirty_ = true; + p->newList_.emplace_back(di); } } -void PlacefileText::Reset() +void PlacefileText::FinishText() { - // Clear the icon list, and mark the draw item dirty - p->textList_.clear(); - p->dirty_ = true; -} + std::unique_lock lock {p->listMutex_}; -void PlacefileText::Impl::Update() -{ - dirty_ = false; + // Swap text lists + p->textList_.swap(p->newList_); + + // Clear the new list + p->newList_.clear(); } } // namespace draw diff --git a/scwx-qt/source/scwx/qt/gl/draw/placefile_text.hpp b/scwx-qt/source/scwx/qt/gl/draw/placefile_text.hpp index 04d78844..363164c7 100644 --- a/scwx-qt/source/scwx/qt/gl/draw/placefile_text.hpp +++ b/scwx-qt/source/scwx/qt/gl/draw/placefile_text.hpp @@ -33,6 +33,11 @@ public: void Render(const QMapLibreGL::CustomLayerRenderParameters& params) override; void Deinitialize() override; + /** + * Resets and prepares the draw item for adding a new set of text. + */ + void StartText(); + /** * Adds placefile text to the internal draw list. * @@ -41,9 +46,9 @@ public: void AddText(const std::shared_ptr& di); /** - * Resets the list of text in preparation for rendering a new frame. + * Finalizes the draw item after adding new text. */ - void Reset(); + void FinishText(); private: class Impl; diff --git a/scwx-qt/source/scwx/qt/map/map_widget.cpp b/scwx-qt/source/scwx/qt/map/map_widget.cpp index 406384db..61665a24 100644 --- a/scwx-qt/source/scwx/qt/map/map_widget.cpp +++ b/scwx-qt/source/scwx/qt/map/map_widget.cpp @@ -815,6 +815,12 @@ void MapWidgetImpl::UpdatePlacefileLayers() placefileLayers_.push_back(placefileLayer); AddLayer( GetPlacefileLayerName(placefileName), placefileLayer, "colorTable"); + + // When the layer updates, trigger a map widget update + connect(placefileLayer.get(), + &PlacefileLayer::DataReloaded, + widget_, + [this]() { widget_->update(); }); } } } diff --git a/scwx-qt/source/scwx/qt/map/placefile_layer.cpp b/scwx-qt/source/scwx/qt/map/placefile_layer.cpp index 3f5c880e..fc60cefa 100644 --- a/scwx-qt/source/scwx/qt/map/placefile_layer.cpp +++ b/scwx-qt/source/scwx/qt/map/placefile_layer.cpp @@ -59,6 +59,8 @@ PlacefileLayer::PlacefileLayer(std::shared_ptr context, AddDrawItem(p->placefileIcons_); AddDrawItem(p->placefilePolygons_); AddDrawItem(p->placefileText_); + + ReloadData(); } PlacefileLayer::~PlacefileLayer() = default; @@ -128,19 +130,10 @@ void PlacefileLayer::Render( p->placefileIcons_->SetIconFiles(placefile->icon_files(), placefile->name()); - // Reset Placefile Text - p->placefileText_->Reset(); - for (auto& drawItem : placefile->GetDrawItems()) { switch (drawItem->itemType_) { - case gr::Placefile::ItemType::Text: - p->placefileText_->AddText( - std::static_pointer_cast( - drawItem)); - break; - case gr::Placefile::ItemType::Icon: p->placefileIcons_->AddIcon( std::static_pointer_cast( @@ -168,7 +161,7 @@ void PlacefileLayer::Deinitialize() void PlacefileLayer::ReloadData() { - // TODO: No longer needed after moving Icon and Text Render items here + // TODO: No longer needed after moving Icon Render items here p->dirty_ = true; boost::asio::post( @@ -188,15 +181,18 @@ void PlacefileLayer::ReloadData() return; } - // Reset Placefile Polygons + // Start draw items p->placefilePolygons_->StartPolygons(); + p->placefileText_->StartText(); for (auto& drawItem : placefile->GetDrawItems()) { switch (drawItem->itemType_) { case gr::Placefile::ItemType::Text: - // TODO + p->placefileText_->AddText( + std::static_pointer_cast( + drawItem)); break; case gr::Placefile::ItemType::Icon: @@ -214,8 +210,11 @@ void PlacefileLayer::ReloadData() } } - // Finish Placefile Polygons + // Finish draw items p->placefilePolygons_->FinishPolygons(); + p->placefileText_->FinishText(); + + Q_EMIT DataReloaded(); }); } diff --git a/scwx-qt/source/scwx/qt/map/placefile_layer.hpp b/scwx-qt/source/scwx/qt/map/placefile_layer.hpp index 68fd38c5..9c08db10 100644 --- a/scwx-qt/source/scwx/qt/map/placefile_layer.hpp +++ b/scwx-qt/source/scwx/qt/map/placefile_layer.hpp @@ -13,6 +13,8 @@ namespace map class PlacefileLayer : public DrawLayer { + Q_OBJECT + public: explicit PlacefileLayer(std::shared_ptr context, const std::string& placefileName); @@ -28,6 +30,9 @@ public: void ReloadData(); +signals: + void DataReloaded(); + private: class Impl; std::unique_ptr p;