Skip to content

Commit

Permalink
Implement the ability to release specific textures from memory (#543)
Browse files Browse the repository at this point in the history
  • Loading branch information
viseztrance committed Nov 21, 2023
1 parent 6f793e2 commit d131274
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Include/RmlUi/Core/Core.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ RMLUICORE_API EventId RegisterEventType(const String& type, bool interruptible,
RMLUICORE_API StringList GetTextureSourceList();
/// Forces all texture handles loaded and generated by RmlUi to be released.
RMLUICORE_API void ReleaseTextures();
/// Releases a specified texture by name from memory, returning 'true' if successful and 'false' if not found.
RMLUICORE_API bool ReleaseTexture(const String& name);
/// Forces all compiled geometry handles generated by RmlUi to be released.
RMLUICORE_API void ReleaseCompiledGeometry();
/// Releases unused font textures and rendered glyphs to free up memory, and regenerates actively used fonts.
Expand Down
5 changes: 5 additions & 0 deletions Source/Core/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,11 @@ void ReleaseTextures()
TextureDatabase::ReleaseTextures();
}

bool ReleaseTexture(const String& source)
{
return TextureDatabase::ReleaseTexture(source);
}

void ReleaseCompiledGeometry()
{
return GeometryDatabase::ReleaseAll();
Expand Down
12 changes: 12 additions & 0 deletions Source/Core/TextureDatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,18 @@ void TextureDatabase::ReleaseTextures()
}
}

bool TextureDatabase::ReleaseTexture(const String& source)
{
auto it = texture_database->textures.find(source);
if (it != texture_database->textures.end())
{
it->second->Release();
return true;
}

return false;
}

bool TextureDatabase::AllTexturesReleased()
{
if (texture_database)
Expand Down
3 changes: 3 additions & 0 deletions Source/Core/TextureDatabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ class TextureDatabase {
/// Release all textures in the database.
static void ReleaseTextures();

/// Release a given texture from the database.
static bool ReleaseTexture(const String& source);

/// Adds a texture resource with a callback function and stores it as a weak (raw) pointer in the database.
static void AddCallbackTexture(TextureResource* texture);

Expand Down

0 comments on commit d131274

Please sign in to comment.