mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 18:10:05 +00:00
Update placefile icon texture coordinates when the texture atlas changes
This commit is contained in:
parent
e021484bfb
commit
565734217b
7 changed files with 55 additions and 16 deletions
|
|
@ -41,6 +41,17 @@ DrawItem::~DrawItem() = default;
|
|||
DrawItem::DrawItem(DrawItem&&) noexcept = default;
|
||||
DrawItem& DrawItem::operator=(DrawItem&&) noexcept = default;
|
||||
|
||||
void DrawItem::Render(
|
||||
const QMapLibreGL::CustomLayerRenderParameters& /* params */)
|
||||
{
|
||||
}
|
||||
|
||||
void DrawItem::Render(const QMapLibreGL::CustomLayerRenderParameters& params,
|
||||
bool /* textureAtlasChanged */)
|
||||
{
|
||||
Render(params);
|
||||
}
|
||||
|
||||
void DrawItem::UseDefaultProjection(
|
||||
const QMapLibreGL::CustomLayerRenderParameters& params,
|
||||
GLint uMVPMatrixLocation)
|
||||
|
|
|
|||
|
|
@ -28,9 +28,10 @@ public:
|
|||
DrawItem& operator=(DrawItem&&) noexcept;
|
||||
|
||||
virtual void Initialize() = 0;
|
||||
virtual void
|
||||
Render(const QMapLibreGL::CustomLayerRenderParameters& params) = 0;
|
||||
virtual void Deinitialize() = 0;
|
||||
virtual void Render(const QMapLibreGL::CustomLayerRenderParameters& params);
|
||||
virtual void Render(const QMapLibreGL::CustomLayerRenderParameters& params,
|
||||
bool textureAtlasChanged);
|
||||
virtual void Deinitialize() = 0;
|
||||
|
||||
protected:
|
||||
void
|
||||
|
|
|
|||
|
|
@ -37,8 +37,6 @@ struct PlacefileIconInfo
|
|||
auto baseUrl = QUrl::fromUserInput(QString::fromStdString(baseUrlString));
|
||||
auto relativeUrl = QUrl(QString::fromStdString(iconFile->filename_));
|
||||
resolvedUrl_ = baseUrl.resolved(relativeUrl).toString().toStdString();
|
||||
|
||||
UpdateTextureInfo();
|
||||
}
|
||||
|
||||
void UpdateTextureInfo();
|
||||
|
|
@ -78,10 +76,9 @@ public:
|
|||
|
||||
std::mutex iconMutex_;
|
||||
|
||||
boost::unordered_flat_map<std::size_t, const PlacefileIconInfo>
|
||||
boost::unordered_flat_map<std::size_t, PlacefileIconInfo>
|
||||
currentIconFiles_ {};
|
||||
boost::unordered_flat_map<std::size_t, const PlacefileIconInfo>
|
||||
newIconFiles_ {};
|
||||
boost::unordered_flat_map<std::size_t, PlacefileIconInfo> newIconFiles_ {};
|
||||
|
||||
std::vector<std::shared_ptr<const gr::Placefile::IconDrawItem>>
|
||||
currentIconList_ {};
|
||||
|
|
@ -103,7 +100,7 @@ public:
|
|||
GLsizei numVertices_;
|
||||
|
||||
void UpdateBuffers();
|
||||
void Update();
|
||||
void Update(bool textureAtlasChanged);
|
||||
};
|
||||
|
||||
PlacefileIcons::PlacefileIcons(std::shared_ptr<GlContext> context) :
|
||||
|
|
@ -203,7 +200,8 @@ void PlacefileIcons::Initialize()
|
|||
}
|
||||
|
||||
void PlacefileIcons::Render(
|
||||
const QMapLibreGL::CustomLayerRenderParameters& params)
|
||||
const QMapLibreGL::CustomLayerRenderParameters& params,
|
||||
bool textureAtlasChanged)
|
||||
{
|
||||
std::unique_lock lock {p->iconMutex_};
|
||||
|
||||
|
|
@ -213,7 +211,7 @@ void PlacefileIcons::Render(
|
|||
|
||||
gl.glBindVertexArray(p->vao_);
|
||||
|
||||
p->Update();
|
||||
p->Update(textureAtlasChanged);
|
||||
p->shaderProgram_->Use();
|
||||
UseRotationProjection(params, p->uMVPMatrixLocation_);
|
||||
UseMapProjection(
|
||||
|
|
@ -329,8 +327,6 @@ void PlacefileIcons::FinishIcons()
|
|||
p->newIconList_.clear();
|
||||
p->newIconFiles_.clear();
|
||||
|
||||
p->UpdateBuffers();
|
||||
|
||||
// Mark the draw item dirty
|
||||
p->dirty_ = true;
|
||||
}
|
||||
|
|
@ -434,8 +430,21 @@ void PlacefileIcons::Impl::UpdateBuffers()
|
|||
dirty_ = true;
|
||||
}
|
||||
|
||||
void PlacefileIcons::Impl::Update()
|
||||
void PlacefileIcons::Impl::Update(bool textureAtlasChanged)
|
||||
{
|
||||
// If the texture atlas has changed
|
||||
if (textureAtlasChanged)
|
||||
{
|
||||
// Update texture coordinates
|
||||
for (auto& iconFile : currentIconFiles_)
|
||||
{
|
||||
iconFile.second.UpdateTextureInfo();
|
||||
}
|
||||
|
||||
// Update OpenGL buffer data
|
||||
UpdateBuffers();
|
||||
}
|
||||
|
||||
if (dirty_)
|
||||
{
|
||||
gl::OpenGLFunctions& gl = context_->gl();
|
||||
|
|
|
|||
|
|
@ -30,7 +30,8 @@ public:
|
|||
void set_thresholded(bool thresholded);
|
||||
|
||||
void Initialize() override;
|
||||
void Render(const QMapLibreGL::CustomLayerRenderParameters& params) override;
|
||||
void Render(const QMapLibreGL::CustomLayerRenderParameters& params,
|
||||
bool textureAtlasChanged) override;
|
||||
void Deinitialize() override;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -52,6 +52,11 @@ gl::OpenGLFunctions& GlContext::gl()
|
|||
return p->gl_;
|
||||
}
|
||||
|
||||
std::uint64_t GlContext::texture_buffer_count() const
|
||||
{
|
||||
return p->textureBufferCount_;
|
||||
}
|
||||
|
||||
std::shared_ptr<gl::ShaderProgram>
|
||||
GlContext::GetShaderProgram(const std::string& vertexPath,
|
||||
const std::string& fragmentPath)
|
||||
|
|
|
|||
|
|
@ -24,6 +24,8 @@ public:
|
|||
|
||||
gl::OpenGLFunctions& gl();
|
||||
|
||||
std::uint64_t texture_buffer_count() const;
|
||||
|
||||
std::shared_ptr<gl::ShaderProgram>
|
||||
GetShaderProgram(const std::string& vertexPath,
|
||||
const std::string& fragmentPath);
|
||||
|
|
|
|||
|
|
@ -24,6 +24,8 @@ public:
|
|||
std::shared_ptr<MapContext> context_;
|
||||
std::vector<std::shared_ptr<gl::draw::DrawItem>> drawList_;
|
||||
GLuint textureAtlas_;
|
||||
|
||||
std::uint64_t textureAtlasBuildCount_ {};
|
||||
};
|
||||
|
||||
DrawLayer::DrawLayer(std::shared_ptr<MapContext> context) :
|
||||
|
|
@ -47,13 +49,21 @@ void DrawLayer::Render(const QMapLibreGL::CustomLayerRenderParameters& params)
|
|||
gl::OpenGLFunctions& gl = p->context_->gl();
|
||||
p->textureAtlas_ = p->context_->GetTextureAtlas();
|
||||
|
||||
// Determine if the texture atlas changed since last render
|
||||
std::uint64_t newTextureAtlasBuildCount =
|
||||
p->context_->texture_buffer_count();
|
||||
bool textureAtlasChanged =
|
||||
newTextureAtlasBuildCount != p->textureAtlasBuildCount_;
|
||||
|
||||
gl.glActiveTexture(GL_TEXTURE0);
|
||||
gl.glBindTexture(GL_TEXTURE_2D, p->textureAtlas_);
|
||||
|
||||
for (auto& item : p->drawList_)
|
||||
{
|
||||
item->Render(params);
|
||||
item->Render(params, textureAtlasChanged);
|
||||
}
|
||||
|
||||
p->textureAtlasBuildCount_ = newTextureAtlasBuildCount;
|
||||
}
|
||||
|
||||
void DrawLayer::Deinitialize()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue