Luanti 5.15.0-dev
 
Loading...
Searching...
No Matches
TextureSource Class Referencefinal
+ Inheritance diagram for TextureSource:
+ Collaboration diagram for TextureSource:

Public Member Functions

 TextureSource ()
 
virtual ~TextureSource ()
 
u32 getTextureId (const std::string &name)
 Generates a texture string into a standard texture.
 
std::string getTextureName (u32 id)
 Returns name of existing texture by ID.
 
video::ITexture * getTexture (u32 id)
 Returns existing texture by ID.
 
video::ITexture * getTexture (const std::string &name, u32 *id=nullptr)
 Generates a texture string into a standard texture.
 
video::ITexture * addArrayTexture (const std::vector< std::string > &images, u32 *id=nullptr)
 Generates texture string(s) into an array texture.
 
bool needFilterForMesh () const
 
PalettegetPalette (const std::string &name)
 Returns a palette from the given texture string.
 
bool isKnownSourceImage (const std::string &name)
 Check if given image name exists.
 
void processQueue ()
 Fulfil texture requests from other threads.
 
void insertSourceImage (const std::string &name, video::IImage *img)
 Inserts a source image.
 
void rebuildImagesAndTextures ()
 Rebuilds all textures (in case-source images have changed)
 
video::SColor getTextureAverageColor (const std::string &name)
 Return average color of a texture string.
 
core::dimension2du getTextureDimensions (const std::string &image)
 Return dimensions of a texture string (will avoid actually creating the texture)
 
void setImageCaching (bool enabled)
 Enables or disables the caching of finished texture images.
 
- Public Member Functions inherited from IWritableTextureSource
 IWritableTextureSource ()=default
 
virtual ~IWritableTextureSource ()=default
 
- Public Member Functions inherited from ITextureSource
 ITextureSource ()=default
 
virtual ~ITextureSource ()=default
 
video::ITexture * getTextureForMesh (const std::string &image, u32 *id=nullptr)
 Generates a texture string into a standard texture Filters will be applied to make the texture suitable for mipmapping and linear filtering during rendering.
 
- Public Member Functions inherited from ISimpleTextureSource
 ISimpleTextureSource ()=default
 
virtual ~ISimpleTextureSource ()=default
 

Private Member Functions

video::IImage * getOrGenerateImage (const std::string &name, std::set< std::string > &source_image_names)
 
void rebuildTexture (video::IVideoDriver *driver, TextureInfo &ti)
 
u32 processRequestQueued (const TextureRequest &req)
 
u32 processRequest (const TextureRequest &req)
 
u32 generateTexture (const std::string &name)
 
u32 generateArrayTexture (const std::vector< std::string > &names)
 

Private Attributes

std::thread::id m_main_thread
 
ImageSource m_imagesource
 
bool m_image_cache_enabled = false
 
std::unordered_map< std::string, ImageInfom_image_cache
 
MutexedMap< std::string, bool > m_source_image_existence
 
std::vector< TextureInfom_textureinfo_cache
 
std::unordered_map< std::string, u32 > m_name_to_id
 
std::mutex m_textureinfo_cache_mutex
 
RequestQueue< TextureRequest, u32, std::thread::id, char > m_get_texture_queue
 
std::vector< video::ITexture * > m_texture_trash
 
std::unordered_map< std::string, Palettem_palettes
 
bool mesh_filter_needed
 

Additional Inherited Members

- Static Public Attributes inherited from ITextureSource
static constexpr const char * FILTER_FOR_MESH = "^[applyfiltersformesh"
 Filter needed for mesh-suitable textures, including leading ^.
 

Constructor & Destructor Documentation

◆ TextureSource()

TextureSource::TextureSource ( )

References g_settings, Settings::getBool(), m_main_thread, m_name_to_id, m_textureinfo_cache, and mesh_filter_needed.

+ Here is the call graph for this function:

◆ ~TextureSource()

TextureSource::~TextureSource ( )
virtual

References RenderingEngine::get_video_driver(), infostream, m_image_cache, m_texture_trash, and m_textureinfo_cache.

+ Here is the call graph for this function:

Member Function Documentation

◆ addArrayTexture()

video::ITexture * TextureSource::addArrayTexture ( const std::vector< std::string > & images,
u32 * id = nullptr )
virtual

Generates texture string(s) into an array texture.

Note
Unlike the other getters this will always add a new texture.
Returns
its ID

Implements ITextureSource.

References getTexture(), and processRequestQueued().

+ Here is the call graph for this function:

◆ generateArrayTexture()

u32 TextureSource::generateArrayTexture ( const std::vector< std::string > & names)
private

References errorstream, RenderingEngine::get_video_driver(), getOrGenerateImage(), m_name_to_id, m_textureinfo_cache, m_textureinfo_cache_mutex, porting::mt_snprintf(), sanity_check, and warningstream.

Referenced by processRequest().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ generateTexture()

u32 TextureSource::generateTexture ( const std::string & name)
private

References RenderingEngine::get_video_driver(), getOrGenerateImage(), guiScalingCache(), infostream, m_main_thread, m_name_to_id, m_textureinfo_cache, m_textureinfo_cache_mutex, sanity_check, and warningstream.

Referenced by processRequest().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getOrGenerateImage()

video::IImage * TextureSource::getOrGenerateImage ( const std::string & name,
std::set< std::string > & source_image_names )
private

References ImageSource::generateImage(), m_image_cache, m_image_cache_enabled, and m_imagesource.

Referenced by generateArrayTexture(), generateTexture(), getPalette(), getTextureAverageColor(), getTextureDimensions(), and rebuildTexture().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getPalette()

Palette * TextureSource::getPalette ( const std::string & image)
virtual

Returns a palette from the given texture string.

The pointer is valid until the texture source is destructed. Must be called from the main thread.

Implements ITextureSource.

References getOrGenerateImage(), m_main_thread, m_palettes, sanity_check, and warningstream.

+ Here is the call graph for this function:

◆ getTexture() [1/2]

video::ITexture * TextureSource::getTexture ( const std::string & name,
u32 * id = nullptr )
virtual

Generates a texture string into a standard texture.

Reimplemented from ITextureSource.

References getTexture(), and getTextureId().

+ Here is the call graph for this function:

◆ getTexture() [2/2]

video::ITexture * TextureSource::getTexture ( u32 id)
virtual

Returns existing texture by ID.

Implements ITextureSource.

References m_textureinfo_cache, and m_textureinfo_cache_mutex.

Referenced by addArrayTexture(), and getTexture().

+ Here is the caller graph for this function:

◆ getTextureAverageColor()

video::SColor TextureSource::getTextureAverageColor ( const std::string & image)
virtual

Return average color of a texture string.

Implements ITextureSource.

References getOrGenerateImage(), imageAverageColor(), and m_main_thread.

+ Here is the call graph for this function:

◆ getTextureDimensions()

core::dimension2du TextureSource::getTextureDimensions ( const std::string & image)
virtual

Return dimensions of a texture string (will avoid actually creating the texture)

Implements ITextureSource.

References getOrGenerateImage(), and m_main_thread.

+ Here is the call graph for this function:

◆ getTextureId()

u32 TextureSource::getTextureId ( const std::string & image)
virtual

Generates a texture string into a standard texture.

Returns
its ID

Implements ITextureSource.

References m_name_to_id, m_textureinfo_cache_mutex, and processRequestQueued().

Referenced by getTexture().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getTextureName()

std::string TextureSource::getTextureName ( u32 id)
virtual

Returns name of existing texture by ID.

Warning
Use sparingly. Mostly useful for debugging.

Implements ITextureSource.

References errorstream, m_textureinfo_cache, and m_textureinfo_cache_mutex.

◆ insertSourceImage()

void TextureSource::insertSourceImage ( const std::string & name,
video::IImage * img )
virtual

Inserts a source image.

Must be called from the main thread. Takes ownership of img

Implements IWritableTextureSource.

References RenderingEngine::get_video_driver(), ImageSource::insertSourceImage(), m_imagesource, m_main_thread, m_source_image_existence, m_textureinfo_cache, m_textureinfo_cache_mutex, rebuildTexture(), sanity_check, MutexedMap< Key, Value >::set(), and verbosestream.

+ Here is the call graph for this function:

◆ isKnownSourceImage()

bool TextureSource::isKnownSourceImage ( const std::string & name)
inlinevirtual

Check if given image name exists.

Implements ITextureSource.

References MutexedMap< Key, Value >::get(), getTexturePath(), m_source_image_existence, and MutexedMap< Key, Value >::set().

+ Here is the call graph for this function:

◆ needFilterForMesh()

bool TextureSource::needFilterForMesh ( ) const
inlinevirtual
Returns
true if getTextureForMesh will apply a filter

Implements ITextureSource.

References mesh_filter_needed.

◆ processQueue()

void TextureSource::processQueue ( )
virtual

Fulfil texture requests from other threads.

Implements IWritableTextureSource.

References RequestQueue< Key, T, Caller, CallerData >::empty(), m_get_texture_queue, RequestQueue< Key, T, Caller, CallerData >::pop(), processRequest(), and RequestQueue< Key, T, Caller, CallerData >::pushResult().

+ Here is the call graph for this function:

◆ processRequest()

u32 TextureSource::processRequest ( const TextureRequest & req)
private

References errorstream, generateArrayTexture(), generateTexture(), TextureRequest::images, and TextureRequest::type.

Referenced by processQueue(), and processRequestQueued().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ processRequestQueued()

u32 TextureSource::processRequestQueued ( const TextureRequest & req)
private

References RequestQueue< Key, T, Caller, CallerData >::add(), errorstream, infostream, m_get_texture_queue, m_main_thread, TextureRequest::print(), and processRequest().

Referenced by addArrayTexture(), and getTextureId().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ rebuildImagesAndTextures()

void TextureSource::rebuildImagesAndTextures ( )
virtual

Rebuilds all textures (in case-source images have changed)

Note
This won't invalidate old ITexture's, but may or may not reuse them. So you have to re-get all textures anyway.

Implements IWritableTextureSource.

References RenderingEngine::get_video_driver(), infostream, m_image_cache, m_image_cache_enabled, m_textureinfo_cache, m_textureinfo_cache_mutex, rebuildTexture(), and sanity_check.

+ Here is the call graph for this function:

◆ rebuildTexture()

void TextureSource::rebuildTexture ( video::IVideoDriver * driver,
TextureInfo & ti )
private

References getOrGenerateImage(), guiScalingCache(), infostream, m_main_thread, m_texture_trash, TextureInfo::name, sanity_check, TextureInfo::sourceImages, TextureInfo::texture, TextureInfo::type, and warningstream.

Referenced by insertSourceImage(), and rebuildImagesAndTextures().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setImageCaching()

void TextureSource::setImageCaching ( bool enabled)
virtual

Enables or disables the caching of finished texture images.

This can be useful if you want to call getTextureAverageColor without duplicating work.

Note
Disabling caching will flush the cache.

Reimplemented from ITextureSource.

References m_image_cache, and m_image_cache_enabled.

Member Data Documentation

◆ m_get_texture_queue

RequestQueue<TextureRequest, u32, std::thread::id, char> TextureSource::m_get_texture_queue
private

◆ m_image_cache

std::unordered_map<std::string, ImageInfo> TextureSource::m_image_cache
private

◆ m_image_cache_enabled

bool TextureSource::m_image_cache_enabled = false
private

◆ m_imagesource

ImageSource TextureSource::m_imagesource
private

◆ m_main_thread

◆ m_name_to_id

std::unordered_map<std::string, u32> TextureSource::m_name_to_id
private

◆ m_palettes

std::unordered_map<std::string, Palette> TextureSource::m_palettes
private

Referenced by getPalette().

◆ m_source_image_existence

MutexedMap<std::string, bool> TextureSource::m_source_image_existence
private

◆ m_texture_trash

std::vector<video::ITexture*> TextureSource::m_texture_trash
private

Referenced by ~TextureSource(), and rebuildTexture().

◆ m_textureinfo_cache

◆ m_textureinfo_cache_mutex

std::mutex TextureSource::m_textureinfo_cache_mutex
private

◆ mesh_filter_needed

bool TextureSource::mesh_filter_needed
private

Referenced by TextureSource(), and needFilterForMesh().


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