diff options
author | Clyne Sullivan <tullivan99@gmail.com> | 2016-10-20 08:58:57 -0400 |
---|---|---|
committer | Clyne Sullivan <tullivan99@gmail.com> | 2016-10-20 08:58:57 -0400 |
commit | dbed8f40b0c85a1d550d9c2557d57b192fc097ab (patch) | |
tree | d579b3bc2449aeccddcc148b02d1dd52462c990a /include/texture.hpp | |
parent | cb408a63a0f03ccb0b0ce7c338527a3b4964aff9 (diff) | |
parent | 87bc18a63541c6e325170fbfacde2d7610a3b852 (diff) |
cat is good
Diffstat (limited to 'include/texture.hpp')
-rw-r--r-- | include/texture.hpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/include/texture.hpp b/include/texture.hpp index 7f22a79..7426a46 100644 --- a/include/texture.hpp +++ b/include/texture.hpp @@ -35,6 +35,42 @@ namespace Texture { dim2 imageDim(std::string fileName); } +class SpriteLoader { +private: + std::unordered_map<uint64_t, GLuint> sprites; + std::unordered_map<std::string, uint64_t> spritesLoc; + + uint64_t freeID = 0; + uint64_t increaseID() { + uint64_t id_t = 0; + while (1) { + try { + sprites.at(id_t); + } catch (const std::out_of_range& oor) { + freeID = id_t; + return freeID; + } + id_t++; + } + } +public: + uint64_t loadSprite(std::string s) { + uint64_t tex_e; + try { + tex_e = spritesLoc.at(s); + } catch (const std::out_of_range& oor) { + sprites.emplace(increaseID(), Texture::loadTexture (s)); + spritesLoc.emplace(s, freeID); + return freeID; + } + return tex_e; + } + + GLuint getSprite(uint64_t id) { + return sprites.at(id); + } +}; + /** * DRAFT texture iterator? */ |