diff options
author | Kae <80987908+Novaenia@users.noreply.github.com> | 2023-06-20 14:33:09 +1000 |
---|---|---|
committer | Kae <80987908+Novaenia@users.noreply.github.com> | 2023-06-20 14:33:09 +1000 |
commit | 6352e8e3196f78388b6c771073f9e03eaa612673 (patch) | |
tree | e23772f79a7fbc41bc9108951e9e136857484bf4 /source/rendering/StarAssetTextureGroup.hpp | |
parent | 6741a057e5639280d85d0f88ba26f000baa58f61 (diff) |
everything everywhere
all at once
Diffstat (limited to 'source/rendering/StarAssetTextureGroup.hpp')
-rw-r--r-- | source/rendering/StarAssetTextureGroup.hpp | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/source/rendering/StarAssetTextureGroup.hpp b/source/rendering/StarAssetTextureGroup.hpp new file mode 100644 index 0000000..0941ad0 --- /dev/null +++ b/source/rendering/StarAssetTextureGroup.hpp @@ -0,0 +1,50 @@ +#ifndef STAR_ASSET_TEXTURE_GROUP_HPP +#define STAR_ASSET_TEXTURE_GROUP_HPP + +#include "StarMaybe.hpp" +#include "StarString.hpp" +#include "StarBiMap.hpp" +#include "StarListener.hpp" +#include "StarRenderer.hpp" + +namespace Star { + +STAR_CLASS(AssetTextureGroup); + +// Creates a renderer texture group for textures loaded directly from Assets. +class AssetTextureGroup { +public: + // Creates a texture group using the given renderer and textureFiltering for + // the managed textures. + AssetTextureGroup(TextureGroupPtr textureGroup); + + // Load the given texture into the texture group if it is not loaded, and + // return the texture pointer. + TexturePtr loadTexture(String const& imageName); + + // If the texture is loaded and ready, returns the texture pointer, otherwise + // queues the texture using Assets::tryImage and returns nullptr. + TexturePtr tryTexture(String const& imageName); + + // Has the texture been loaded? + bool textureLoaded(String const& imageName) const; + + // Frees textures that haven't been used in more than 'textureTimeout' time. + // If Root has been reloaded, will simply clear the texture group. + void cleanup(int64_t textureTimeout); + +private: + // Returns the texture parameters. If tryTexture is true, then returns none + // if the texture is not loaded, and queues it, otherwise loads texture + // immediately + TexturePtr loadTexture(String const& imageName, bool tryTexture); + + TextureGroupPtr m_textureGroup; + StringMap<pair<TexturePtr, int64_t>> m_textureMap; + HashMap<ImageConstPtr, TexturePtr> m_textureDeduplicationMap; + TrackerListenerPtr m_reloadTracker; +}; + +} + +#endif |