Adding map context to simplify parameter passing

This commit is contained in:
Dan Paulat 2021-11-27 19:00:49 -06:00
parent afb174a8fe
commit f7f86ec24a
12 changed files with 140 additions and 124 deletions

View file

@ -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);