Maria GDK 5.0.0.738
Documentation of native code in develop branch
Loading...
Searching...
No Matches
STK::TextureManager Class Reference

#include <StkTextureManager.h>

Classes

struct  TextureKey
 
struct  TextureKeyHasher
 

Public Member Functions

std::shared_ptr< Texture2DgetTexture2D (const std::string &filename, GLenum wrap_horiz=GL_REPEAT, GLenum wrap_vert=GL_REPEAT, GLenum min_filter=GL_LINEAR, GLenum mag_filter=GL_NEAREST, int unit=0)
 
std::shared_ptr< Texture2DgetTexture2D (const std::vector< uint8_t > &imageBuffer, const std::string &id, GLenum wrap_horiz=GL_REPEAT, GLenum wrap_vert=GL_REPEAT, GLenum min_filter=GL_LINEAR, GLenum mag_filter=GL_NEAREST, int unit=0)
 
std::shared_ptr< Texture2DgetTexture2D (const std::shared_ptr< STK::AssetDataProvider > &asset_provider, const std::string &asset_id, const std::string &url, GLenum wrap_horiz=GL_REPEAT, GLenum wrap_vert=GL_REPEAT, GLenum min_filter=GL_LINEAR, GLenum mag_filter=GL_NEAREST, int unit=0)
 
std::shared_ptr< CubeMapgetCubeMap (const std::string *filename, GLenum wrap_horiz=GL_REPEAT, GLenum wrap_vert=GL_REPEAT, GLenum min_filter=GL_LINEAR, GLenum mag_filter=GL_NEAREST, int unit=0)
 
void addLoadRequest (Texture *tex)
 
bool startTextureLoader (bool separate_context=true)
 
void stopTextureLoader ()
 
void clearTextures ()
 
int64_t getTimestamp () const
 
void incMemsize (int memsize)
 Increase size of tracked memory usage.
 
void decMemsize (int memsize)
 Decrease size of tracked memory usage.
 
int64_t getMemsize () const
 Get current memory usage.
 
void setMaxMemsize (int64_t max_memsize)
 Set max memory usage. If set to 0, no cleanup is done.
 
int64_t getMaxMemsize () const
 Get max memory usage.
 
int64_t cleanupCache (double target_f=0.5, int min_age=500)
 
std::shared_ptr< STK::AssetDataProvidergetAssetProvider (const std::string &asset_id) const
 
bool needsRedraw () const
 
void redrawFinished ()
 This should be called after each frame to keep track of rendering flags.
 

Protected Attributes

TextureLoader tex_loader_
 
std::mutex tex_mutex_
 
std::unordered_map< TextureKey, std::shared_ptr< Texture >, TextureKeyHashertextures_
 
std::atomic< int64_t > memsize_
 
int64_t max_memsize_
 
std::mutex asset_provider_mutex_
 
std::map< std::string, std::shared_ptr< STK::AssetDataProvider > > asset_providers_
 
std::chrono::steady_clock::time_point _start
 

Detailed Description

TextureManager - Short description. Detailed description.

Member Function Documentation

◆ cleanupCache()

int64_t TextureManager::cleanupCache ( double  target_f = 0.5,
int  min_age = 500 
)

Clean up memory cache. This method will delete textures based on last used time, oldest first. It will delete textures until we have reached a memory usage of target_f * getMaxMemsize(), or the oldest texture is newer than min_age (in miliseconds).

Returns
Number of bytes cleared.

◆ clearTextures()

void TextureManager::clearTextures ( )

Cleanup all textures. Should be done before deleting the last GL context

◆ getTexture2D() [1/2]

std::shared_ptr< Texture2D > STK::TextureManager::getTexture2D ( const std::string &  filename,
GLenum  wrap_horiz = GL_REPEAT,
GLenum  wrap_vert = GL_REPEAT,
GLenum  min_filter = GL_LINEAR,
GLenum  mag_filter = GL_NEAREST,
int  unit = 0 
)
inline

Get or create a 2D texture. This method will check if there exists a texture with the given specifications and return it if possible. If not, a new texture will be created and returned.

◆ getTexture2D() [2/2]

std::shared_ptr< Texture2D > STK::TextureManager::getTexture2D ( const std::vector< uint8_t > &  imageBuffer,
const std::string &  id,
GLenum  wrap_horiz = GL_REPEAT,
GLenum  wrap_vert = GL_REPEAT,
GLenum  min_filter = GL_LINEAR,
GLenum  mag_filter = GL_NEAREST,
int  unit = 0 
)
inline

Get or create a 2D texture from image buffer. This method will check if there exists a texture with the given specifications and return it if possible. If not, a new texture will be created and returned.

◆ needsRedraw()

bool STK::TextureManager::needsRedraw ( ) const
inline

Check if we need to redraw the frame. This will typically happen when a texture has finished asynchronous loading.

◆ startTextureLoader()

bool TextureManager::startTextureLoader ( bool  separate_context = true)

Start texture loader thread.

Note
This must be done after the main OpenGL context is valid, but before any other GL calls are made.
This must be done before attempting to load any textures.

The documentation for this class was generated from the following files: