mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 04:50:06 +00:00 
			
		
		
		
	Adding map context to simplify parameter passing
This commit is contained in:
		
							parent
							
								
									afb174a8fe
								
							
						
					
					
						commit
						f7f86ec24a
					
				
					 12 changed files with 140 additions and 124 deletions
				
			
		|  | @ -5,7 +5,7 @@ | |||
| #define SCWX_GL_CHECK_ERROR()                                                  \ | ||||
|    {                                                                           \ | ||||
|       GLenum err;                                                              \ | ||||
|       while ((err = p->gl_.glGetError()) != GL_NO_ERROR)                       \ | ||||
|       while ((err = gl.glGetError()) != GL_NO_ERROR)                           \ | ||||
|       {                                                                        \ | ||||
|          BOOST_LOG_TRIVIAL(warning) << logPrefix_ << "GL Error: " << err       \ | ||||
|                                     << ", " __FILE__ << ":" << __LINE__;       \ | ||||
|  |  | |||
|  | @ -17,12 +17,8 @@ static const std::string logPrefix_ = "[scwx::qt::map::color_table_layer] "; | |||
| class ColorTableLayerImpl | ||||
| { | ||||
| public: | ||||
|    explicit ColorTableLayerImpl( | ||||
|       std::shared_ptr<view::RadarProductView> radarProductView, | ||||
|       gl::OpenGLFunctions&                    gl) : | ||||
|        radarProductView_(radarProductView), | ||||
|        gl_(gl), | ||||
|        shaderProgram_(gl), | ||||
|    explicit ColorTableLayerImpl(std::shared_ptr<MapContext> context) : | ||||
|        shaderProgram_(context->gl_), | ||||
|        uMVPMatrixLocation_(GL_INVALID_INDEX), | ||||
|        vbo_ {GL_INVALID_INDEX}, | ||||
|        vao_ {GL_INVALID_INDEX}, | ||||
|  | @ -32,9 +28,6 @@ public: | |||
|    } | ||||
|    ~ColorTableLayerImpl() = default; | ||||
| 
 | ||||
|    std::shared_ptr<view::RadarProductView> radarProductView_; | ||||
|    gl::OpenGLFunctions&                    gl_; | ||||
| 
 | ||||
|    gl::ShaderProgram     shaderProgram_; | ||||
|    GLint                 uMVPMatrixLocation_; | ||||
|    std::array<GLuint, 2> vbo_; | ||||
|  | @ -46,19 +39,17 @@ public: | |||
|    bool colorTableNeedsUpdate_; | ||||
| }; | ||||
| 
 | ||||
| ColorTableLayer::ColorTableLayer( | ||||
|    std::shared_ptr<view::RadarProductView> radarProductView, | ||||
|    gl::OpenGLFunctions&                    gl) : | ||||
|     p(std::make_unique<ColorTableLayerImpl>(radarProductView, gl)) | ||||
| ColorTableLayer::ColorTableLayer(std::shared_ptr<MapContext> context) : | ||||
|     GenericLayer(context), p(std::make_unique<ColorTableLayerImpl>(context)) | ||||
| { | ||||
| } | ||||
| ColorTableLayer::~ColorTableLayer() = default; | ||||
| 
 | ||||
| void ColorTableLayer::Initialize() | ||||
| { | ||||
|    BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "initialize()"; | ||||
|    BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Initialize()"; | ||||
| 
 | ||||
|    gl::OpenGLFunctions& gl = p->gl_; | ||||
|    gl::OpenGLFunctions& gl = context()->gl_; | ||||
| 
 | ||||
|    // Load and configure overlay shader
 | ||||
|    p->shaderProgram_.Load(":/gl/texture1d.vert", ":/gl/texture1d.frag"); | ||||
|  | @ -105,7 +96,7 @@ void ColorTableLayer::Initialize() | |||
|    gl.glVertexAttribPointer(1, 1, GL_FLOAT, GL_FALSE, 0, static_cast<void*>(0)); | ||||
|    gl.glEnableVertexAttribArray(1); | ||||
| 
 | ||||
|    connect(p->radarProductView_.get(), | ||||
|    connect(context()->radarProductView_.get(), | ||||
|            &view::RadarProductView::ColorTableUpdated, | ||||
|            this, | ||||
|            [=]() { p->colorTableNeedsUpdate_ = true; }); | ||||
|  | @ -113,7 +104,7 @@ void ColorTableLayer::Initialize() | |||
| 
 | ||||
| void ColorTableLayer::Render(const QMapbox::CustomLayerRenderParameters& params) | ||||
| { | ||||
|    gl::OpenGLFunctions& gl = p->gl_; | ||||
|    gl::OpenGLFunctions& gl = context()->gl_; | ||||
| 
 | ||||
|    glm::mat4 projection = glm::ortho(0.0f, | ||||
|                                      static_cast<float>(params.width), | ||||
|  | @ -127,7 +118,7 @@ void ColorTableLayer::Render(const QMapbox::CustomLayerRenderParameters& params) | |||
| 
 | ||||
|    if (p->colorTableNeedsUpdate_) | ||||
|    { | ||||
|       p->colorTable_ = p->radarProductView_->color_table(); | ||||
|       p->colorTable_ = context()->radarProductView_->color_table(); | ||||
| 
 | ||||
|       gl.glActiveTexture(GL_TEXTURE0); | ||||
|       gl.glBindTexture(GL_TEXTURE_1D, p->texture_); | ||||
|  | @ -144,8 +135,9 @@ void ColorTableLayer::Render(const QMapbox::CustomLayerRenderParameters& params) | |||
|       gl.glGenerateMipmap(GL_TEXTURE_1D); | ||||
|    } | ||||
| 
 | ||||
|    if (p->colorTable_.size() > 0 && p->radarProductView_->sweep_time() != | ||||
|                                        std::chrono::system_clock::time_point()) | ||||
|    if (p->colorTable_.size() > 0 && | ||||
|        context()->radarProductView_->sweep_time() != | ||||
|           std::chrono::system_clock::time_point()) | ||||
|    { | ||||
|       // Color table panel vertices
 | ||||
|       const float vertexLX       = 0.0f; | ||||
|  | @ -172,9 +164,9 @@ void ColorTableLayer::Render(const QMapbox::CustomLayerRenderParameters& params) | |||
| 
 | ||||
| void ColorTableLayer::Deinitialize() | ||||
| { | ||||
|    gl::OpenGLFunctions& gl = p->gl_; | ||||
|    BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Deinitialize()"; | ||||
| 
 | ||||
|    BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "deinitialize()"; | ||||
|    gl::OpenGLFunctions& gl = context()->gl_; | ||||
| 
 | ||||
|    gl.glDeleteVertexArrays(1, &p->vao_); | ||||
|    gl.glDeleteBuffers(2, p->vbo_.data()); | ||||
|  |  | |||
|  | @ -1,8 +1,6 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <scwx/qt/gl/gl.hpp> | ||||
| #include <scwx/qt/map/generic_layer.hpp> | ||||
| #include <scwx/qt/view/radar_product_view.hpp> | ||||
| 
 | ||||
| namespace scwx | ||||
| { | ||||
|  | @ -16,9 +14,7 @@ class ColorTableLayerImpl; | |||
| class ColorTableLayer : public GenericLayer | ||||
| { | ||||
| public: | ||||
|    explicit ColorTableLayer( | ||||
|       std::shared_ptr<view::RadarProductView> radarProductView, | ||||
|       gl::OpenGLFunctions&                    gl); | ||||
|    explicit ColorTableLayer(std::shared_ptr<MapContext> context); | ||||
|    ~ColorTableLayer(); | ||||
| 
 | ||||
|    void Initialize() override final; | ||||
|  |  | |||
|  | @ -10,14 +10,27 @@ namespace map | |||
| class GenericLayerImpl | ||||
| { | ||||
| public: | ||||
|    explicit GenericLayerImpl() {} | ||||
|    explicit GenericLayerImpl(std::shared_ptr<MapContext> context) : | ||||
|        context_ {context} | ||||
|    { | ||||
|    } | ||||
| 
 | ||||
|    ~GenericLayerImpl() {} | ||||
| 
 | ||||
|    std::shared_ptr<MapContext> context_; | ||||
| }; | ||||
| 
 | ||||
| GenericLayer::GenericLayer() : p(std::make_unique<GenericLayerImpl>()) {} | ||||
| GenericLayer::GenericLayer(std::shared_ptr<MapContext> context) : | ||||
|     p(std::make_unique<GenericLayerImpl>(context)) | ||||
| { | ||||
| } | ||||
| GenericLayer::~GenericLayer() = default; | ||||
| 
 | ||||
| std::shared_ptr<MapContext> GenericLayer::context() const | ||||
| { | ||||
|    return p->context_; | ||||
| } | ||||
| 
 | ||||
| } // namespace map
 | ||||
| } // namespace qt
 | ||||
| } // namespace scwx
 | ||||
|  |  | |||
|  | @ -1,5 +1,7 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <scwx/qt/map/map_context.hpp> | ||||
| 
 | ||||
| #include <memory> | ||||
| 
 | ||||
| #include <QObject> | ||||
|  | @ -19,12 +21,15 @@ class GenericLayer : public QObject | |||
|    Q_OBJECT | ||||
| 
 | ||||
| public: | ||||
|    explicit GenericLayer(); | ||||
|    explicit GenericLayer(std::shared_ptr<MapContext> context); | ||||
|    virtual ~GenericLayer(); | ||||
| 
 | ||||
|    virtual void Initialize() = 0; | ||||
|    virtual void Initialize()                                        = 0; | ||||
|    virtual void Render(const QMapbox::CustomLayerRenderParameters&) = 0; | ||||
|    virtual void Deinitialize() = 0; | ||||
|    virtual void Deinitialize()                                      = 0; | ||||
| 
 | ||||
| protected: | ||||
|    std::shared_ptr<MapContext> context() const; | ||||
| 
 | ||||
| private: | ||||
|    std::unique_ptr<GenericLayerImpl> p; | ||||
|  |  | |||
							
								
								
									
										34
									
								
								scwx-qt/source/scwx/qt/map/map_context.hpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								scwx-qt/source/scwx/qt/map/map_context.hpp
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,34 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <scwx/qt/gl/gl.hpp> | ||||
| #include <scwx/qt/view/radar_product_view.hpp> | ||||
| 
 | ||||
| namespace scwx | ||||
| { | ||||
| namespace qt | ||||
| { | ||||
| namespace map | ||||
| { | ||||
| 
 | ||||
| struct MapContext | ||||
| { | ||||
|    explicit MapContext( | ||||
|       std::shared_ptr<view::RadarProductView> radarProductView = nullptr) : | ||||
|        gl_ {}, radarProductView_ {radarProductView} | ||||
|    { | ||||
|    } | ||||
|    ~MapContext() = default; | ||||
| 
 | ||||
|    MapContext(const MapContext&) = delete; | ||||
|    MapContext& operator=(const MapContext&) = delete; | ||||
| 
 | ||||
|    MapContext(MapContext&&) noexcept = default; | ||||
|    MapContext& operator=(MapContext&&) noexcept = default; | ||||
| 
 | ||||
|    gl::OpenGLFunctions                     gl_; | ||||
|    std::shared_ptr<view::RadarProductView> radarProductView_; | ||||
| }; | ||||
| 
 | ||||
| } // namespace map
 | ||||
| } // namespace qt
 | ||||
| } // namespace scwx
 | ||||
|  | @ -50,13 +50,12 @@ class MapWidgetImpl : public QObject | |||
| public: | ||||
|    explicit MapWidgetImpl(MapWidget*               widget, | ||||
|                           const QMapboxGLSettings& settings) : | ||||
|        gl_(), | ||||
|        context_ {std::make_shared<MapContext>()}, | ||||
|        widget_ {widget}, | ||||
|        settings_(settings), | ||||
|        map_(), | ||||
|        radarProductManager_ {manager::RadarProductManager::Instance("KLSX")}, | ||||
|        radarProductLayer_ {nullptr}, | ||||
|        radarProductView_ {nullptr}, | ||||
|        overlayLayer_ {nullptr}, | ||||
|        colorTableLayer_ {nullptr}, | ||||
|        isActive_ {false}, | ||||
|  | @ -74,7 +73,7 @@ public: | |||
| 
 | ||||
|    bool UpdateStoredMapParameters(); | ||||
| 
 | ||||
|    gl::OpenGLFunctions gl_; | ||||
|    std::shared_ptr<MapContext> context_; | ||||
| 
 | ||||
|    MapWidget*                 widget_; | ||||
|    QMapboxGLSettings          settings_; | ||||
|  | @ -82,8 +81,7 @@ public: | |||
| 
 | ||||
|    std::shared_ptr<manager::RadarProductManager> radarProductManager_; | ||||
| 
 | ||||
|    std::shared_ptr<common::ColorTable>     colorTable_; | ||||
|    std::shared_ptr<view::RadarProductView> radarProductView_; | ||||
|    std::shared_ptr<common::ColorTable> colorTable_; | ||||
| 
 | ||||
|    std::shared_ptr<RadarProductLayer> radarProductLayer_; | ||||
|    std::shared_ptr<OverlayLayer>      overlayLayer_; | ||||
|  | @ -120,50 +118,53 @@ MapWidget::~MapWidget() | |||
| 
 | ||||
| float MapWidget::GetElevation() const | ||||
| { | ||||
|    return p->radarProductView_->elevation(); | ||||
|    return p->context_->radarProductView_->elevation(); | ||||
| } | ||||
| 
 | ||||
| std::vector<float> MapWidget::GetElevationCuts() const | ||||
| { | ||||
|    return p->radarProductView_->GetElevationCuts(); | ||||
|    return p->context_->radarProductView_->GetElevationCuts(); | ||||
| } | ||||
| 
 | ||||
| void MapWidget::SelectElevation(float elevation) | ||||
| { | ||||
|    p->radarProductView_->SelectElevation(elevation); | ||||
|    p->context_->radarProductView_->SelectElevation(elevation); | ||||
| } | ||||
| 
 | ||||
| void MapWidget::SelectRadarProduct(common::Level2Product product) | ||||
| { | ||||
|    float currentElevation = 0.0f; | ||||
| 
 | ||||
|    if (p->radarProductView_ != nullptr) | ||||
|    std::shared_ptr<view::RadarProductView>& radarProductView = | ||||
|       p->context_->radarProductView_; | ||||
| 
 | ||||
|    if (p->context_->radarProductView_ != nullptr) | ||||
|    { | ||||
|       currentElevation = p->radarProductView_->elevation(); | ||||
|       currentElevation = p->context_->radarProductView_->elevation(); | ||||
|    } | ||||
| 
 | ||||
|    p->radarProductView_ = view::RadarProductViewFactory::Create( | ||||
|    radarProductView = view::RadarProductViewFactory::Create( | ||||
|       product, currentElevation, p->radarProductManager_); | ||||
|    p->radarProductView_->SetActive(p->isActive_); | ||||
|    radarProductView->SetActive(p->isActive_); | ||||
| 
 | ||||
|    connect( | ||||
|       p->radarProductView_.get(), | ||||
|       radarProductView.get(), | ||||
|       &view::RadarProductView::ColorTableUpdated, | ||||
|       this, | ||||
|       [&]() { update(); }, | ||||
|       Qt::QueuedConnection); | ||||
|    connect( | ||||
|       p->radarProductView_.get(), | ||||
|       radarProductView.get(), | ||||
|       &view::RadarProductView::SweepComputed, | ||||
|       this, | ||||
|       [&]() { | ||||
|          RadarRangeLayer::Update(p->map_, p->radarProductView_->range()); | ||||
|          RadarRangeLayer::Update(p->map_, radarProductView->range()); | ||||
|          update(); | ||||
|          emit RadarSweepUpdated(); | ||||
|       }, | ||||
|       Qt::QueuedConnection); | ||||
| 
 | ||||
|    p->radarProductView_->Initialize(); | ||||
|    radarProductView->Initialize(); | ||||
| 
 | ||||
|    std::string colorTableFile = | ||||
|       manager::SettingsManager::palette_settings()->palette( | ||||
|  | @ -172,7 +173,7 @@ void MapWidget::SelectRadarProduct(common::Level2Product product) | |||
|    { | ||||
|       std::shared_ptr<common::ColorTable> colorTable = | ||||
|          common::ColorTable::Load(colorTableFile); | ||||
|       p->radarProductView_->LoadColorTable(colorTable); | ||||
|       radarProductView->LoadColorTable(colorTable); | ||||
|    } | ||||
| 
 | ||||
|    if (p->map_ != nullptr) | ||||
|  | @ -185,9 +186,9 @@ void MapWidget::SetActive(bool isActive) | |||
| { | ||||
|    p->isActive_ = isActive; | ||||
| 
 | ||||
|    if (p->radarProductView_ != nullptr) | ||||
|    if (p->context_->radarProductView_ != nullptr) | ||||
|    { | ||||
|       p->radarProductView_->SetActive(isActive); | ||||
|       p->context_->radarProductView_->SetActive(isActive); | ||||
|       update(); | ||||
|    } | ||||
| } | ||||
|  | @ -221,7 +222,7 @@ void MapWidget::changeStyle() | |||
| 
 | ||||
| void MapWidget::AddLayers() | ||||
| { | ||||
|    if (p->radarProductView_ == nullptr) | ||||
|    if (p->context_->radarProductView_ == nullptr) | ||||
|    { | ||||
|       return; | ||||
|    } | ||||
|  | @ -240,12 +241,9 @@ void MapWidget::AddLayers() | |||
|       p->map_->removeLayer("colorTable"); | ||||
|    } | ||||
| 
 | ||||
|    p->radarProductLayer_ = | ||||
|       std::make_shared<RadarProductLayer>(p->radarProductView_, p->gl_); | ||||
|    p->overlayLayer_ = | ||||
|       std::make_shared<OverlayLayer>(p->radarProductView_, p->gl_); | ||||
|    p->colorTableLayer_ = | ||||
|       std::make_shared<ColorTableLayer>(p->radarProductView_, p->gl_); | ||||
|    p->radarProductLayer_ = std::make_shared<RadarProductLayer>(p->context_); | ||||
|    p->overlayLayer_      = std::make_shared<OverlayLayer>(p->context_); | ||||
|    p->colorTableLayer_   = std::make_shared<ColorTableLayer>(p->context_); | ||||
| 
 | ||||
|    // QMapboxGL::addCustomLayer will take ownership of the QScopedPointer
 | ||||
|    QScopedPointer<QMapbox::CustomLayerHostInterface> pHost( | ||||
|  | @ -269,7 +267,8 @@ void MapWidget::AddLayers() | |||
|    } | ||||
| 
 | ||||
|    p->map_->addCustomLayer("radar", pHost, before); | ||||
|    RadarRangeLayer::Add(p->map_, p->radarProductView_->range(), before); | ||||
|    RadarRangeLayer::Add( | ||||
|       p->map_, p->context_->radarProductView_->range(), before); | ||||
|    p->map_->addCustomLayer("overlay", pOverlayHost); | ||||
|    p->map_->addCustomLayer("colorTable", pColorTableHost); | ||||
| } | ||||
|  | @ -366,7 +365,7 @@ void MapWidget::wheelEvent(QWheelEvent* ev) | |||
| void MapWidget::initializeGL() | ||||
| { | ||||
|    makeCurrent(); | ||||
|    p->gl_.initializeOpenGLFunctions(); | ||||
|    p->context_->gl_.initializeOpenGLFunctions(); | ||||
| 
 | ||||
|    p->map_.reset(new QMapboxGL(nullptr, p->settings_, size(), pixelRatio())); | ||||
|    connect(p->map_.get(), | ||||
|  |  | |||
|  | @ -28,14 +28,10 @@ static const std::string logPrefix_ = "[scwx::qt::map::overlay_layer] "; | |||
| class OverlayLayerImpl | ||||
| { | ||||
| public: | ||||
|    explicit OverlayLayerImpl( | ||||
|       std::shared_ptr<view::RadarProductView> radarProductView, | ||||
|       gl::OpenGLFunctions&                    gl) : | ||||
|        radarProductView_(radarProductView), | ||||
|        gl_(gl), | ||||
|        textShader_(gl), | ||||
|    explicit OverlayLayerImpl(std::shared_ptr<MapContext> context) : | ||||
|        textShader_(context->gl_), | ||||
|        font_(util::Font::Create(":/res/fonts/din1451alt.ttf")), | ||||
|        shaderProgram_(gl), | ||||
|        shaderProgram_(context->gl_), | ||||
|        uMVPMatrixLocation_(GL_INVALID_INDEX), | ||||
|        uColorLocation_(GL_INVALID_INDEX), | ||||
|        vbo_ {GL_INVALID_INDEX}, | ||||
|  | @ -48,9 +44,6 @@ public: | |||
|    } | ||||
|    ~OverlayLayerImpl() = default; | ||||
| 
 | ||||
|    std::shared_ptr<view::RadarProductView> radarProductView_; | ||||
|    gl::OpenGLFunctions&                    gl_; | ||||
| 
 | ||||
|    gl::TextShader              textShader_; | ||||
|    std::shared_ptr<util::Font> font_; | ||||
|    gl::ShaderProgram           shaderProgram_; | ||||
|  | @ -64,19 +57,17 @@ public: | |||
|    bool        sweepTimeNeedsUpdate_; | ||||
| }; | ||||
| 
 | ||||
| OverlayLayer::OverlayLayer( | ||||
|    std::shared_ptr<view::RadarProductView> radarProductView, | ||||
|    gl::OpenGLFunctions&                    gl) : | ||||
|     p(std::make_unique<OverlayLayerImpl>(radarProductView, gl)) | ||||
| OverlayLayer::OverlayLayer(std::shared_ptr<MapContext> context) : | ||||
|     GenericLayer(context), p(std::make_unique<OverlayLayerImpl>(context)) | ||||
| { | ||||
| } | ||||
| OverlayLayer::~OverlayLayer() = default; | ||||
| 
 | ||||
| void OverlayLayer::Initialize() | ||||
| { | ||||
|    BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "initialize()"; | ||||
|    BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Initialize()"; | ||||
| 
 | ||||
|    gl::OpenGLFunctions& gl = p->gl_; | ||||
|    gl::OpenGLFunctions& gl = context()->gl_; | ||||
| 
 | ||||
|    p->textShader_.Initialize(); | ||||
| 
 | ||||
|  | @ -131,7 +122,7 @@ void OverlayLayer::Initialize() | |||
|    // Upper right panel color
 | ||||
|    gl.glUniform4f(p->uColorLocation_, 0.0f, 0.0f, 0.0f, 0.75f); | ||||
| 
 | ||||
|    connect(p->radarProductView_.get(), | ||||
|    connect(context()->radarProductView_.get(), | ||||
|            &view::RadarProductView::SweepComputed, | ||||
|            this, | ||||
|            &OverlayLayer::UpdateSweepTimeNextFrame); | ||||
|  | @ -139,13 +130,13 @@ void OverlayLayer::Initialize() | |||
| 
 | ||||
| void OverlayLayer::Render(const QMapbox::CustomLayerRenderParameters& params) | ||||
| { | ||||
|    gl::OpenGLFunctions& gl = p->gl_; | ||||
|    gl::OpenGLFunctions& gl = context()->gl_; | ||||
| 
 | ||||
|    if (p->sweepTimeNeedsUpdate_) | ||||
|    { | ||||
|       using namespace std::chrono; | ||||
|       auto sweepTime = | ||||
|          time_point_cast<seconds>(p->radarProductView_->sweep_time()); | ||||
|          time_point_cast<seconds>(context()->radarProductView_->sweep_time()); | ||||
| 
 | ||||
|       if (sweepTime.time_since_epoch().count() != 0) | ||||
|       { | ||||
|  | @ -168,7 +159,7 @@ void OverlayLayer::Render(const QMapbox::CustomLayerRenderParameters& params) | |||
|    gl.glUniformMatrix4fv( | ||||
|       p->uMVPMatrixLocation_, 1, GL_FALSE, glm::value_ptr(projection)); | ||||
| 
 | ||||
|    if (p->radarProductView_->IsActive()) | ||||
|    if (context()->radarProductView_->IsActive()) | ||||
|    { | ||||
|       const float vertexLX       = 1.0f; | ||||
|       const float vertexRX       = static_cast<float>(params.width) - 1.0f; | ||||
|  | @ -220,8 +211,7 @@ void OverlayLayer::Render(const QMapbox::CustomLayerRenderParameters& params) | |||
|       // Render time
 | ||||
|       p->textShader_.RenderText(p->sweepTimeString_, | ||||
|                                 params.width - 7.0f, | ||||
|                                 static_cast<float>(params.height) - | ||||
|                                    16.0f, // 7.0f,
 | ||||
|                                 static_cast<float>(params.height) - 16.0f, | ||||
|                                 fontSize, | ||||
|                                 projection, | ||||
|                                 boost::gil::rgba8_pixel_t(255, 255, 255, 204), | ||||
|  | @ -235,9 +225,9 @@ void OverlayLayer::Render(const QMapbox::CustomLayerRenderParameters& params) | |||
| 
 | ||||
| void OverlayLayer::Deinitialize() | ||||
| { | ||||
|    gl::OpenGLFunctions& gl = p->gl_; | ||||
|    BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Deinitialize()"; | ||||
| 
 | ||||
|    BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "deinitialize()"; | ||||
|    gl::OpenGLFunctions& gl = context()->gl_; | ||||
| 
 | ||||
|    gl.glDeleteVertexArrays(1, &p->vao_); | ||||
|    gl.glDeleteBuffers(static_cast<GLsizei>(p->vbo_.size()), p->vbo_.data()); | ||||
|  | @ -249,7 +239,7 @@ void OverlayLayer::Deinitialize() | |||
|    p->vbo_                = {GL_INVALID_INDEX}; | ||||
|    p->texture_            = GL_INVALID_INDEX; | ||||
| 
 | ||||
|    disconnect(p->radarProductView_.get(), | ||||
|    disconnect(context()->radarProductView_.get(), | ||||
|               &view::RadarProductView::SweepComputed, | ||||
|               this, | ||||
|               &OverlayLayer::UpdateSweepTimeNextFrame); | ||||
|  |  | |||
|  | @ -1,8 +1,6 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <scwx/qt/gl/gl.hpp> | ||||
| #include <scwx/qt/map/generic_layer.hpp> | ||||
| #include <scwx/qt/view/radar_product_view.hpp> | ||||
| 
 | ||||
| namespace scwx | ||||
| { | ||||
|  | @ -16,9 +14,7 @@ class OverlayLayerImpl; | |||
| class OverlayLayer : public GenericLayer | ||||
| { | ||||
| public: | ||||
|    explicit OverlayLayer( | ||||
|       std::shared_ptr<view::RadarProductView> radarProductView, | ||||
|       gl::OpenGLFunctions&                    gl); | ||||
|    explicit OverlayLayer(std::shared_ptr<MapContext> context); | ||||
|    ~OverlayLayer(); | ||||
| 
 | ||||
|    void Initialize() override final; | ||||
|  |  | |||
|  | @ -29,12 +29,8 @@ LatLongToScreenCoordinate(const QMapbox::Coordinate& coordinate); | |||
| class RadarProductLayerImpl | ||||
| { | ||||
| public: | ||||
|    explicit RadarProductLayerImpl( | ||||
|       std::shared_ptr<view::RadarProductView> radarProductView, | ||||
|       gl::OpenGLFunctions&                    gl) : | ||||
|        radarProductView_(radarProductView), | ||||
|        gl_(gl), | ||||
|        shaderProgram_(gl), | ||||
|    explicit RadarProductLayerImpl(std::shared_ptr<MapContext> context) : | ||||
|        shaderProgram_(context->gl_), | ||||
|        uMVPMatrixLocation_(GL_INVALID_INDEX), | ||||
|        uMapScreenCoordLocation_(GL_INVALID_INDEX), | ||||
|        uDataMomentOffsetLocation_(GL_INVALID_INDEX), | ||||
|  | @ -51,9 +47,6 @@ public: | |||
|    } | ||||
|    ~RadarProductLayerImpl() = default; | ||||
| 
 | ||||
|    std::shared_ptr<view::RadarProductView> radarProductView_; | ||||
|    gl::OpenGLFunctions&                    gl_; | ||||
| 
 | ||||
|    gl::ShaderProgram     shaderProgram_; | ||||
|    GLint                 uMVPMatrixLocation_; | ||||
|    GLint                 uMapScreenCoordLocation_; | ||||
|  | @ -72,19 +65,17 @@ public: | |||
|    bool sweepNeedsUpdate_; | ||||
| }; | ||||
| 
 | ||||
| RadarProductLayer::RadarProductLayer( | ||||
|    std::shared_ptr<view::RadarProductView> radarProductView, | ||||
|    gl::OpenGLFunctions&                    gl) : | ||||
|     p(std::make_unique<RadarProductLayerImpl>(radarProductView, gl)) | ||||
| RadarProductLayer::RadarProductLayer(std::shared_ptr<MapContext> context) : | ||||
|     GenericLayer(context), p(std::make_unique<RadarProductLayerImpl>(context)) | ||||
| { | ||||
| } | ||||
| RadarProductLayer::~RadarProductLayer() = default; | ||||
| 
 | ||||
| void RadarProductLayer::Initialize() | ||||
| { | ||||
|    BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "initialize()"; | ||||
|    BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Initialize()"; | ||||
| 
 | ||||
|    gl::OpenGLFunctions& gl = p->gl_; | ||||
|    gl::OpenGLFunctions& gl = context()->gl_; | ||||
| 
 | ||||
|    // Load and configure radar shader
 | ||||
|    p->shaderProgram_.Load(":/gl/radar.vert", ":/gl/radar.frag"); | ||||
|  | @ -143,11 +134,11 @@ void RadarProductLayer::Initialize() | |||
|    UpdateColorTable(); | ||||
|    gl.glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | ||||
| 
 | ||||
|    connect(p->radarProductView_.get(), | ||||
|    connect(context()->radarProductView_.get(), | ||||
|            &view::RadarProductView::ColorTableUpdated, | ||||
|            this, | ||||
|            [=]() { p->colorTableNeedsUpdate_ = true; }); | ||||
|    connect(p->radarProductView_.get(), | ||||
|    connect(context()->radarProductView_.get(), | ||||
|            &view::RadarProductView::SweepComputed, | ||||
|            this, | ||||
|            [=]() { p->sweepNeedsUpdate_ = true; }); | ||||
|  | @ -159,11 +150,12 @@ void RadarProductLayer::UpdateSweep() | |||
| 
 | ||||
|    p->sweepNeedsUpdate_ = false; | ||||
| 
 | ||||
|    gl::OpenGLFunctions& gl = p->gl_; | ||||
|    gl::OpenGLFunctions& gl = context()->gl_; | ||||
| 
 | ||||
|    boost::timer::cpu_timer timer; | ||||
| 
 | ||||
|    const std::vector<float>& vertices = p->radarProductView_->vertices(); | ||||
|    const std::vector<float>& vertices = | ||||
|       context()->radarProductView_->vertices(); | ||||
| 
 | ||||
|    // Bind a vertex array object
 | ||||
|    gl.glBindVertexArray(p->vao_); | ||||
|  | @ -192,7 +184,7 @@ void RadarProductLayer::UpdateSweep() | |||
|    GLenum        type; | ||||
| 
 | ||||
|    std::tie(data, dataSize, componentSize) = | ||||
|       p->radarProductView_->GetMomentData(); | ||||
|       context()->radarProductView_->GetMomentData(); | ||||
| 
 | ||||
|    if (componentSize == 1) | ||||
|    { | ||||
|  | @ -220,7 +212,7 @@ void RadarProductLayer::UpdateSweep() | |||
|    GLenum        cfpType; | ||||
| 
 | ||||
|    std::tie(cfpData, cfpDataSize, cfpComponentSize) = | ||||
|       p->radarProductView_->GetCfpMomentData(); | ||||
|       context()->radarProductView_->GetCfpMomentData(); | ||||
| 
 | ||||
|    if (cfpData != nullptr) | ||||
|    { | ||||
|  | @ -254,7 +246,7 @@ void RadarProductLayer::UpdateSweep() | |||
| void RadarProductLayer::Render( | ||||
|    const QMapbox::CustomLayerRenderParameters& params) | ||||
| { | ||||
|    gl::OpenGLFunctions& gl = p->gl_; | ||||
|    gl::OpenGLFunctions& gl = context()->gl_; | ||||
| 
 | ||||
|    p->shaderProgram_.Use(); | ||||
| 
 | ||||
|  | @ -297,9 +289,9 @@ void RadarProductLayer::Render( | |||
| 
 | ||||
| void RadarProductLayer::Deinitialize() | ||||
| { | ||||
|    gl::OpenGLFunctions& gl = p->gl_; | ||||
|    BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Deinitialize()"; | ||||
| 
 | ||||
|    BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "deinitialize()"; | ||||
|    gl::OpenGLFunctions& gl = context()->gl_; | ||||
| 
 | ||||
|    gl.glDeleteVertexArrays(1, &p->vao_); | ||||
|    gl.glDeleteBuffers(3, p->vbo_.data()); | ||||
|  | @ -320,12 +312,14 @@ void RadarProductLayer::UpdateColorTable() | |||
| 
 | ||||
|    p->colorTableNeedsUpdate_ = false; | ||||
| 
 | ||||
|    gl::OpenGLFunctions& gl = p->gl_; | ||||
|    gl::OpenGLFunctions&                    gl = context()->gl_; | ||||
|    std::shared_ptr<view::RadarProductView> radarProductView = | ||||
|       context()->radarProductView_; | ||||
| 
 | ||||
|    const std::vector<boost::gil::rgba8_pixel_t>& colorTable = | ||||
|       p->radarProductView_->color_table(); | ||||
|    const uint16_t rangeMin = p->radarProductView_->color_table_min(); | ||||
|    const uint16_t rangeMax = p->radarProductView_->color_table_max(); | ||||
|       radarProductView->color_table(); | ||||
|    const uint16_t rangeMin = radarProductView->color_table_min(); | ||||
|    const uint16_t rangeMax = radarProductView->color_table_max(); | ||||
| 
 | ||||
|    const float scale = rangeMax - rangeMin; | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,8 +1,6 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <scwx/qt/gl/gl.hpp> | ||||
| #include <scwx/qt/map/generic_layer.hpp> | ||||
| #include <scwx/qt/view/radar_product_view.hpp> | ||||
| 
 | ||||
| namespace scwx | ||||
| { | ||||
|  | @ -16,9 +14,7 @@ class RadarProductLayerImpl; | |||
| class RadarProductLayer : public GenericLayer | ||||
| { | ||||
| public: | ||||
|    explicit RadarProductLayer( | ||||
|       std::shared_ptr<view::RadarProductView> radarProductView, | ||||
|       gl::OpenGLFunctions&                    gl); | ||||
|    explicit RadarProductLayer(std::shared_ptr<MapContext> context); | ||||
|    ~RadarProductLayer(); | ||||
| 
 | ||||
|    void Initialize() override final; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat