diff options
author | LaG1924 <12997935+LaG1924@users.noreply.github.com> | 2017-07-21 16:49:56 +0200 |
---|---|---|
committer | LaG1924 <12997935+LaG1924@users.noreply.github.com> | 2017-07-21 16:49:56 +0200 |
commit | 9e56348975dbdaf1cce9dd688129208a61fd4eb5 (patch) | |
tree | 5a44a37cf0243c1ced14c222f35983eaaaa0185b /src/core/AssetManager.cpp | |
parent | 2017-06-21 (diff) | |
download | AltCraft-9e56348975dbdaf1cce9dd688129208a61fd4eb5.tar AltCraft-9e56348975dbdaf1cce9dd688129208a61fd4eb5.tar.gz AltCraft-9e56348975dbdaf1cce9dd688129208a61fd4eb5.tar.bz2 AltCraft-9e56348975dbdaf1cce9dd688129208a61fd4eb5.tar.lz AltCraft-9e56348975dbdaf1cce9dd688129208a61fd4eb5.tar.xz AltCraft-9e56348975dbdaf1cce9dd688129208a61fd4eb5.tar.zst AltCraft-9e56348975dbdaf1cce9dd688129208a61fd4eb5.zip |
Diffstat (limited to 'src/core/AssetManager.cpp')
-rw-r--r-- | src/core/AssetManager.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/core/AssetManager.cpp b/src/core/AssetManager.cpp index f4c0801..d263c4a 100644 --- a/src/core/AssetManager.cpp +++ b/src/core/AssetManager.cpp @@ -149,3 +149,33 @@ TextureCoordinates AssetManager::GetTextureByBlock(BlockTextureId block) { std::string assetName = this->GetTextureAssetNameByBlockId(block); return this->GetTextureByAssetName(assetName); } + +const std::map<BlockTextureId, glm::vec4> &AssetManager::GetTextureAtlasIndexes() { + if (!textureAtlasIndexes.empty()) + return textureAtlasIndexes; + + LOG(INFO) << "Initializing texture atlas..."; + for (int id = 1; id < 128; id++) { + for (int state = 0; state < 16; state++) { + BlockTextureId blockTextureId(id, state, 6); + if (!this->GetTextureByBlock(blockTextureId) && + !this->GetTextureByBlock(BlockTextureId(id, state, 0))) { + continue; + } + if (this->GetTextureByBlock(blockTextureId)) { + for (int i = 0; i < 6; i++) { + TextureCoordinates tc = this->GetTextureByBlock(BlockTextureId(id, state, 6)); + textureAtlasIndexes[BlockTextureId(id, state, i)] = glm::vec4(tc.x, tc.y, tc.w, tc.h); + } + } else { + for (int i = 0; i < 6; i++) { + TextureCoordinates tc = this->GetTextureByBlock(BlockTextureId(id, state, i)); + textureAtlasIndexes[BlockTextureId(id, state, i)] = glm::vec4(tc.x, tc.y, tc.w, tc.h); + } + } + } + } + LOG(INFO) << "Created " << textureAtlasIndexes.size() << " texture indexes"; + + return textureAtlasIndexes; +} |