diff options
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 |