osb/source/rendering/StarAssetTextureGroup.hpp

49 lines
1.6 KiB
C++
Raw Normal View History

#pragma once
2023-06-20 04:33:09 +00:00
#include "StarMaybe.hpp"
#include "StarString.hpp"
#include "StarBiMap.hpp"
#include "StarListener.hpp"
#include "StarRenderer.hpp"
2023-06-24 12:49:47 +00:00
#include "StarAssetPath.hpp"
2023-06-20 04:33:09 +00:00
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.
2023-06-24 12:49:47 +00:00
TexturePtr loadTexture(AssetPath const& imagePath);
2023-06-20 04:33:09 +00:00
// If the texture is loaded and ready, returns the texture pointer, otherwise
// queues the texture using Assets::tryImage and returns nullptr.
2023-06-24 12:49:47 +00:00
TexturePtr tryTexture(AssetPath const& imagePath);
2023-06-20 04:33:09 +00:00
// Has the texture been loaded?
2023-06-24 12:49:47 +00:00
bool textureLoaded(AssetPath const& imagePath) const;
2023-06-20 04:33:09 +00:00
// 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
2023-06-24 12:49:47 +00:00
TexturePtr loadTexture(AssetPath const& imagePath, bool tryTexture);
2023-06-20 04:33:09 +00:00
TextureGroupPtr m_textureGroup;
2023-06-24 12:49:47 +00:00
HashMap<AssetPath, pair<TexturePtr, int64_t>> m_textureMap;
2023-06-20 04:33:09 +00:00
HashMap<ImageConstPtr, TexturePtr> m_textureDeduplicationMap;
TrackerListenerPtr m_reloadTracker;
};
}