mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 17:20:06 +00:00 
			
		
		
		
	Buffer texture atlas on more than the first context after change
- Icons now work on all maps
This commit is contained in:
		
							parent
							
								
									4ff95094a3
								
							
						
					
					
						commit
						0be94c4de3
					
				
					 3 changed files with 11 additions and 10 deletions
				
			
		|  | @ -35,6 +35,8 @@ public: | ||||||
| 
 | 
 | ||||||
|    GLuint     textureAtlas_; |    GLuint     textureAtlas_; | ||||||
|    std::mutex textureMutex_; |    std::mutex textureMutex_; | ||||||
|  | 
 | ||||||
|  |    std::uint64_t textureBufferCount_ {}; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| GlContext::GlContext() : p(std::make_unique<Impl>()) {} | GlContext::GlContext() : p(std::make_unique<Impl>()) {} | ||||||
|  | @ -79,8 +81,10 @@ GLuint GlContext::GetTextureAtlas() | ||||||
| 
 | 
 | ||||||
|    auto& textureAtlas = util::TextureAtlas::Instance(); |    auto& textureAtlas = util::TextureAtlas::Instance(); | ||||||
| 
 | 
 | ||||||
|    if (p->textureAtlas_ == GL_INVALID_INDEX || textureAtlas.NeedsBuffered()) |    if (p->textureAtlas_ == GL_INVALID_INDEX || | ||||||
|  |        p->textureBufferCount_ != textureAtlas.BuildCount()) | ||||||
|    { |    { | ||||||
|  |       p->textureBufferCount_ = textureAtlas.BuildCount(); | ||||||
|       p->textureAtlas_       = textureAtlas.BufferAtlas(p->gl_); |       p->textureAtlas_       = textureAtlas.BufferAtlas(p->gl_); | ||||||
|    } |    } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -54,7 +54,7 @@ public: | ||||||
|    std::unordered_map<std::string, TextureAttributes> atlasMap_ {}; |    std::unordered_map<std::string, TextureAttributes> atlasMap_ {}; | ||||||
|    std::shared_mutex                                  atlasMutex_ {}; |    std::shared_mutex                                  atlasMutex_ {}; | ||||||
| 
 | 
 | ||||||
|    bool needsBuffered_ {true}; |    std::uint64_t buildCount_ {0u}; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| TextureAtlas::TextureAtlas() : p(std::make_unique<Impl>()) {} | TextureAtlas::TextureAtlas() : p(std::make_unique<Impl>()) {} | ||||||
|  | @ -63,9 +63,9 @@ TextureAtlas::~TextureAtlas() = default; | ||||||
| TextureAtlas::TextureAtlas(TextureAtlas&&) noexcept            = default; | TextureAtlas::TextureAtlas(TextureAtlas&&) noexcept            = default; | ||||||
| TextureAtlas& TextureAtlas::operator=(TextureAtlas&&) noexcept = default; | TextureAtlas& TextureAtlas::operator=(TextureAtlas&&) noexcept = default; | ||||||
| 
 | 
 | ||||||
| bool TextureAtlas::NeedsBuffered() const | std::uint64_t TextureAtlas::BuildCount() const | ||||||
| { | { | ||||||
|    return p->needsBuffered_; |    return p->buildCount_; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void TextureAtlas::RegisterTexture(const std::string& name, | void TextureAtlas::RegisterTexture(const std::string& name, | ||||||
|  | @ -278,7 +278,7 @@ void TextureAtlas::BuildAtlas(size_t width, size_t height) | ||||||
|    } |    } | ||||||
| 
 | 
 | ||||||
|    // Mark the need to buffer the atlas
 |    // Mark the need to buffer the atlas
 | ||||||
|    p->needsBuffered_ = true; |    ++p->buildCount_; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| GLuint TextureAtlas::BufferAtlas(gl::OpenGLFunctions& gl) | GLuint TextureAtlas::BufferAtlas(gl::OpenGLFunctions& gl) | ||||||
|  | @ -322,9 +322,6 @@ GLuint TextureAtlas::BufferAtlas(gl::OpenGLFunctions& gl) | ||||||
|                       pixelData.data()); |                       pixelData.data()); | ||||||
|    } |    } | ||||||
| 
 | 
 | ||||||
|    // Atlas has been successfully buffered
 |  | ||||||
|    p->needsBuffered_ = false; |  | ||||||
| 
 |  | ||||||
|    return texture; |    return texture; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -66,7 +66,7 @@ public: | ||||||
| 
 | 
 | ||||||
|    static TextureAtlas& Instance(); |    static TextureAtlas& Instance(); | ||||||
| 
 | 
 | ||||||
|    bool NeedsBuffered() const; |    std::uint64_t BuildCount() const; | ||||||
| 
 | 
 | ||||||
|    void   RegisterTexture(const std::string& name, const std::string& path); |    void   RegisterTexture(const std::string& name, const std::string& path); | ||||||
|    bool   CacheTexture(const std::string& name, const std::string& path); |    bool   CacheTexture(const std::string& name, const std::string& path); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat