mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-11-01 08:50:04 +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(DrawItem&&) noexcept = default;
|
||||||
DrawItem& DrawItem::operator=(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(
|
void DrawItem::UseDefaultProjection(
|
||||||
const QMapLibreGL::CustomLayerRenderParameters& params,
|
const QMapLibreGL::CustomLayerRenderParameters& params,
|
||||||
GLint uMVPMatrixLocation)
|
GLint uMVPMatrixLocation)
|
||||||
|
|
|
||||||
|
|
@ -28,9 +28,10 @@ public:
|
||||||
DrawItem& operator=(DrawItem&&) noexcept;
|
DrawItem& operator=(DrawItem&&) noexcept;
|
||||||
|
|
||||||
virtual void Initialize() = 0;
|
virtual void Initialize() = 0;
|
||||||
virtual void
|
virtual void Render(const QMapLibreGL::CustomLayerRenderParameters& params);
|
||||||
Render(const QMapLibreGL::CustomLayerRenderParameters& params) = 0;
|
virtual void Render(const QMapLibreGL::CustomLayerRenderParameters& params,
|
||||||
virtual void Deinitialize() = 0;
|
bool textureAtlasChanged);
|
||||||
|
virtual void Deinitialize() = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void
|
void
|
||||||
|
|
|
||||||
|
|
@ -37,8 +37,6 @@ struct PlacefileIconInfo
|
||||||
auto baseUrl = QUrl::fromUserInput(QString::fromStdString(baseUrlString));
|
auto baseUrl = QUrl::fromUserInput(QString::fromStdString(baseUrlString));
|
||||||
auto relativeUrl = QUrl(QString::fromStdString(iconFile->filename_));
|
auto relativeUrl = QUrl(QString::fromStdString(iconFile->filename_));
|
||||||
resolvedUrl_ = baseUrl.resolved(relativeUrl).toString().toStdString();
|
resolvedUrl_ = baseUrl.resolved(relativeUrl).toString().toStdString();
|
||||||
|
|
||||||
UpdateTextureInfo();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateTextureInfo();
|
void UpdateTextureInfo();
|
||||||
|
|
@ -78,10 +76,9 @@ public:
|
||||||
|
|
||||||
std::mutex iconMutex_;
|
std::mutex iconMutex_;
|
||||||
|
|
||||||
boost::unordered_flat_map<std::size_t, const PlacefileIconInfo>
|
boost::unordered_flat_map<std::size_t, PlacefileIconInfo>
|
||||||
currentIconFiles_ {};
|
currentIconFiles_ {};
|
||||||
boost::unordered_flat_map<std::size_t, const PlacefileIconInfo>
|
boost::unordered_flat_map<std::size_t, PlacefileIconInfo> newIconFiles_ {};
|
||||||
newIconFiles_ {};
|
|
||||||
|
|
||||||
std::vector<std::shared_ptr<const gr::Placefile::IconDrawItem>>
|
std::vector<std::shared_ptr<const gr::Placefile::IconDrawItem>>
|
||||||
currentIconList_ {};
|
currentIconList_ {};
|
||||||
|
|
@ -103,7 +100,7 @@ public:
|
||||||
GLsizei numVertices_;
|
GLsizei numVertices_;
|
||||||
|
|
||||||
void UpdateBuffers();
|
void UpdateBuffers();
|
||||||
void Update();
|
void Update(bool textureAtlasChanged);
|
||||||
};
|
};
|
||||||
|
|
||||||
PlacefileIcons::PlacefileIcons(std::shared_ptr<GlContext> context) :
|
PlacefileIcons::PlacefileIcons(std::shared_ptr<GlContext> context) :
|
||||||
|
|
@ -203,7 +200,8 @@ void PlacefileIcons::Initialize()
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlacefileIcons::Render(
|
void PlacefileIcons::Render(
|
||||||
const QMapLibreGL::CustomLayerRenderParameters& params)
|
const QMapLibreGL::CustomLayerRenderParameters& params,
|
||||||
|
bool textureAtlasChanged)
|
||||||
{
|
{
|
||||||
std::unique_lock lock {p->iconMutex_};
|
std::unique_lock lock {p->iconMutex_};
|
||||||
|
|
||||||
|
|
@ -213,7 +211,7 @@ void PlacefileIcons::Render(
|
||||||
|
|
||||||
gl.glBindVertexArray(p->vao_);
|
gl.glBindVertexArray(p->vao_);
|
||||||
|
|
||||||
p->Update();
|
p->Update(textureAtlasChanged);
|
||||||
p->shaderProgram_->Use();
|
p->shaderProgram_->Use();
|
||||||
UseRotationProjection(params, p->uMVPMatrixLocation_);
|
UseRotationProjection(params, p->uMVPMatrixLocation_);
|
||||||
UseMapProjection(
|
UseMapProjection(
|
||||||
|
|
@ -329,8 +327,6 @@ void PlacefileIcons::FinishIcons()
|
||||||
p->newIconList_.clear();
|
p->newIconList_.clear();
|
||||||
p->newIconFiles_.clear();
|
p->newIconFiles_.clear();
|
||||||
|
|
||||||
p->UpdateBuffers();
|
|
||||||
|
|
||||||
// Mark the draw item dirty
|
// Mark the draw item dirty
|
||||||
p->dirty_ = true;
|
p->dirty_ = true;
|
||||||
}
|
}
|
||||||
|
|
@ -434,8 +430,21 @@ void PlacefileIcons::Impl::UpdateBuffers()
|
||||||
dirty_ = true;
|
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_)
|
if (dirty_)
|
||||||
{
|
{
|
||||||
gl::OpenGLFunctions& gl = context_->gl();
|
gl::OpenGLFunctions& gl = context_->gl();
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,8 @@ public:
|
||||||
void set_thresholded(bool thresholded);
|
void set_thresholded(bool thresholded);
|
||||||
|
|
||||||
void Initialize() override;
|
void Initialize() override;
|
||||||
void Render(const QMapLibreGL::CustomLayerRenderParameters& params) override;
|
void Render(const QMapLibreGL::CustomLayerRenderParameters& params,
|
||||||
|
bool textureAtlasChanged) override;
|
||||||
void Deinitialize() override;
|
void Deinitialize() override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,11 @@ gl::OpenGLFunctions& GlContext::gl()
|
||||||
return p->gl_;
|
return p->gl_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::uint64_t GlContext::texture_buffer_count() const
|
||||||
|
{
|
||||||
|
return p->textureBufferCount_;
|
||||||
|
}
|
||||||
|
|
||||||
std::shared_ptr<gl::ShaderProgram>
|
std::shared_ptr<gl::ShaderProgram>
|
||||||
GlContext::GetShaderProgram(const std::string& vertexPath,
|
GlContext::GetShaderProgram(const std::string& vertexPath,
|
||||||
const std::string& fragmentPath)
|
const std::string& fragmentPath)
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,8 @@ public:
|
||||||
|
|
||||||
gl::OpenGLFunctions& gl();
|
gl::OpenGLFunctions& gl();
|
||||||
|
|
||||||
|
std::uint64_t texture_buffer_count() const;
|
||||||
|
|
||||||
std::shared_ptr<gl::ShaderProgram>
|
std::shared_ptr<gl::ShaderProgram>
|
||||||
GetShaderProgram(const std::string& vertexPath,
|
GetShaderProgram(const std::string& vertexPath,
|
||||||
const std::string& fragmentPath);
|
const std::string& fragmentPath);
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,8 @@ public:
|
||||||
std::shared_ptr<MapContext> context_;
|
std::shared_ptr<MapContext> context_;
|
||||||
std::vector<std::shared_ptr<gl::draw::DrawItem>> drawList_;
|
std::vector<std::shared_ptr<gl::draw::DrawItem>> drawList_;
|
||||||
GLuint textureAtlas_;
|
GLuint textureAtlas_;
|
||||||
|
|
||||||
|
std::uint64_t textureAtlasBuildCount_ {};
|
||||||
};
|
};
|
||||||
|
|
||||||
DrawLayer::DrawLayer(std::shared_ptr<MapContext> context) :
|
DrawLayer::DrawLayer(std::shared_ptr<MapContext> context) :
|
||||||
|
|
@ -47,13 +49,21 @@ void DrawLayer::Render(const QMapLibreGL::CustomLayerRenderParameters& params)
|
||||||
gl::OpenGLFunctions& gl = p->context_->gl();
|
gl::OpenGLFunctions& gl = p->context_->gl();
|
||||||
p->textureAtlas_ = p->context_->GetTextureAtlas();
|
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.glActiveTexture(GL_TEXTURE0);
|
||||||
gl.glBindTexture(GL_TEXTURE_2D, p->textureAtlas_);
|
gl.glBindTexture(GL_TEXTURE_2D, p->textureAtlas_);
|
||||||
|
|
||||||
for (auto& item : p->drawList_)
|
for (auto& item : p->drawList_)
|
||||||
{
|
{
|
||||||
item->Render(params);
|
item->Render(params, textureAtlasChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
p->textureAtlasBuildCount_ = newTextureAtlasBuildCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawLayer::Deinitialize()
|
void DrawLayer::Deinitialize()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue