Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement ability to release arbitrary textures from memory #543

Merged
merged 1 commit into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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