mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 01:20:06 +00:00 
			
		
		
		
	Fix rendering of placefile icons, now works on one map
This commit is contained in:
		
							parent
							
								
									f074e487de
								
							
						
					
					
						commit
						bc1bf8cef6
					
				
					 5 changed files with 32 additions and 21 deletions
				
			
		|  | @ -343,11 +343,11 @@ void PlacefileIcons::Impl::Update() | |||
|                        { | ||||
|                           // Icon
 | ||||
|                           lat, lon, lx, by, ls, bt, mc0, mc1, mc2, mc3, a, // BL
 | ||||
|                           lat, lon, lx, by, ls, tt, mc0, mc1, mc2, mc3, a, // TL
 | ||||
|                           lat, lon, rx, ty, rs, bt, mc0, mc1, mc2, mc3, a, // BR
 | ||||
|                           lat, lon, rx, ty, rs, bt, mc0, mc1, mc2, mc3, a, // BR
 | ||||
|                           lat, lon, lx, ty, ls, tt, mc0, mc1, mc2, mc3, a, // TL
 | ||||
|                           lat, lon, rx, by, rs, bt, mc0, mc1, mc2, mc3, a, // BR
 | ||||
|                           lat, lon, rx, by, rs, bt, mc0, mc1, mc2, mc3, a, // BR
 | ||||
|                           lat, lon, rx, ty, rs, tt, mc0, mc1, mc2, mc3, a, // TR
 | ||||
|                           lat, lon, lx, by, ls, tt, mc0, mc1, mc2, mc3, a  // TL
 | ||||
|                           lat, lon, lx, ty, ls, tt, mc0, mc1, mc2, mc3, a  // TL
 | ||||
|                        }); | ||||
| 
 | ||||
|          numVertices_ += 6; | ||||
|  |  | |||
|  | @ -77,9 +77,11 @@ GLuint GlContext::GetTextureAtlas() | |||
| { | ||||
|    std::unique_lock lock(p->textureMutex_); | ||||
| 
 | ||||
|    if (p->textureAtlas_ == GL_INVALID_INDEX) | ||||
|    auto& textureAtlas = util::TextureAtlas::Instance(); | ||||
| 
 | ||||
|    if (p->textureAtlas_ == GL_INVALID_INDEX || textureAtlas.NeedsBuffered()) | ||||
|    { | ||||
|       p->textureAtlas_ = util::TextureAtlas::Instance().BufferAtlas(p->gl_); | ||||
|       p->textureAtlas_ = textureAtlas.BufferAtlas(p->gl_); | ||||
|    } | ||||
| 
 | ||||
|    return p->textureAtlas_; | ||||
|  |  | |||
|  | @ -45,6 +45,7 @@ void DrawLayer::Initialize() | |||
| void DrawLayer::Render(const QMapLibreGL::CustomLayerRenderParameters& params) | ||||
| { | ||||
|    gl::OpenGLFunctions& gl = p->context_->gl(); | ||||
|    p->textureAtlas_        = p->context_->GetTextureAtlas(); | ||||
| 
 | ||||
|    gl.glActiveTexture(GL_TEXTURE0); | ||||
|    gl.glBindTexture(GL_TEXTURE_2D, p->textureAtlas_); | ||||
|  |  | |||
|  | @ -38,27 +38,22 @@ static const auto        logger_    = scwx::util::Logger::Create(logPrefix_); | |||
| class TextureAtlas::Impl | ||||
| { | ||||
| public: | ||||
|    explicit Impl() : | ||||
|        texturePathMap_ {}, | ||||
|        texturePathMutex_ {}, | ||||
|        atlas_ {}, | ||||
|        atlasMap_ {}, | ||||
|        atlasMutex_ {} | ||||
|    { | ||||
|    } | ||||
|    explicit Impl() {} | ||||
|    ~Impl() {} | ||||
| 
 | ||||
|    static boost::gil::rgba8_image_t LoadImage(const std::string& imagePath); | ||||
| 
 | ||||
|    std::unordered_map<std::string, std::string> texturePathMap_; | ||||
|    std::shared_mutex                            texturePathMutex_; | ||||
|    std::unordered_map<std::string, std::string> texturePathMap_ {}; | ||||
|    std::shared_mutex                            texturePathMutex_ {}; | ||||
| 
 | ||||
|    std::shared_mutex textureCacheMutex_; | ||||
|    std::unordered_map<std::string, boost::gil::rgba8_image_t> textureCache_; | ||||
|    std::shared_mutex textureCacheMutex_ {}; | ||||
|    std::unordered_map<std::string, boost::gil::rgba8_image_t> textureCache_ {}; | ||||
| 
 | ||||
|    boost::gil::rgba8_image_t                          atlas_; | ||||
|    std::unordered_map<std::string, TextureAttributes> atlasMap_; | ||||
|    std::shared_mutex                                  atlasMutex_; | ||||
|    boost::gil::rgba8_image_t                          atlas_ {}; | ||||
|    std::unordered_map<std::string, TextureAttributes> atlasMap_ {}; | ||||
|    std::shared_mutex                                  atlasMutex_ {}; | ||||
| 
 | ||||
|    bool needsBuffered_ {true}; | ||||
| }; | ||||
| 
 | ||||
| TextureAtlas::TextureAtlas() : p(std::make_unique<Impl>()) {} | ||||
|  | @ -67,6 +62,11 @@ TextureAtlas::~TextureAtlas() = default; | |||
| TextureAtlas::TextureAtlas(TextureAtlas&&) noexcept            = default; | ||||
| TextureAtlas& TextureAtlas::operator=(TextureAtlas&&) noexcept = default; | ||||
| 
 | ||||
| bool TextureAtlas::NeedsBuffered() const | ||||
| { | ||||
|    return p->needsBuffered_; | ||||
| } | ||||
| 
 | ||||
| void TextureAtlas::RegisterTexture(const std::string& name, | ||||
|                                    const std::string& path) | ||||
| { | ||||
|  | @ -275,6 +275,9 @@ void TextureAtlas::BuildAtlas(size_t width, size_t height) | |||
|          logger_->warn("Unable to pack texture: {}", images[i].first); | ||||
|       } | ||||
|    } | ||||
| 
 | ||||
|    // Mark the need to buffer the atlas
 | ||||
|    p->needsBuffered_ = true; | ||||
| } | ||||
| 
 | ||||
| GLuint TextureAtlas::BufferAtlas(gl::OpenGLFunctions& gl) | ||||
|  | @ -318,6 +321,9 @@ GLuint TextureAtlas::BufferAtlas(gl::OpenGLFunctions& gl) | |||
|                       pixelData.data()); | ||||
|    } | ||||
| 
 | ||||
|    // Atlas has been successfully buffered
 | ||||
|    p->needsBuffered_ = false; | ||||
| 
 | ||||
|    return texture; | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -66,6 +66,8 @@ public: | |||
| 
 | ||||
|    static TextureAtlas& Instance(); | ||||
| 
 | ||||
|    bool NeedsBuffered() const; | ||||
| 
 | ||||
|    void   RegisterTexture(const std::string& name, const std::string& path); | ||||
|    bool   CacheTexture(const std::string& name, const std::string& path); | ||||
|    void   BuildAtlas(size_t width, size_t height); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat