mirror of https://github.com/WerWolv/ImHex
impr: Drastically reduce font-related memory usage
This commit is contained in:
parent
e1580e51cf
commit
02b5df03ab
|
|
@ -334,6 +334,9 @@ namespace hex {
|
|||
}
|
||||
|
||||
void Window::frameBegin() {
|
||||
ImGui_ImplOpenGL3_NewFrame();
|
||||
ImGui_ImplGlfw_NewFrame();
|
||||
|
||||
// Create font textures if necessary
|
||||
{
|
||||
const auto &fontDefinitions = ImHexApi::Fonts::impl::getFontDefinitions();
|
||||
|
|
@ -345,6 +348,8 @@ namespace hex {
|
|||
|
||||
currentFont = font->ContainerAtlas;
|
||||
ImGui_ImplOpenGL3_CreateFontsTexture();
|
||||
currentFont->ClearInputData();
|
||||
currentFont->ClearTexData();
|
||||
}
|
||||
|
||||
{
|
||||
|
|
@ -359,6 +364,8 @@ namespace hex {
|
|||
cfg.SizePixels = ImHexApi::Fonts::DefaultFontSize;
|
||||
io.Fonts->AddFontDefault(&cfg);
|
||||
ImGui_ImplOpenGL3_CreateFontsTexture();
|
||||
io.Fonts->ClearInputData();
|
||||
io.Fonts->ClearTexData();
|
||||
} else {
|
||||
currentFont = font->ContainerAtlas;
|
||||
}
|
||||
|
|
@ -366,8 +373,7 @@ namespace hex {
|
|||
}
|
||||
|
||||
// Start new ImGui Frame
|
||||
ImGui_ImplOpenGL3_NewFrame();
|
||||
ImGui_ImplGlfw_NewFrame();
|
||||
|
||||
ImGui::NewFrame();
|
||||
|
||||
TutorialManager::drawTutorial();
|
||||
|
|
|
|||
|
|
@ -53,6 +53,36 @@ namespace hex::fonts {
|
|||
FontAtlas(const FontAtlas &) = delete;
|
||||
FontAtlas &operator=(const FontAtlas &) = delete;
|
||||
|
||||
FontAtlas(FontAtlas &&other) noexcept {
|
||||
m_fontAtlas = other.m_fontAtlas;
|
||||
other.m_fontAtlas = nullptr;
|
||||
|
||||
m_defaultConfig = other.m_defaultConfig;
|
||||
m_fontSizes = std::move(other.m_fontSizes);
|
||||
m_fontConfigs = std::move(other.m_fontConfigs);
|
||||
m_glyphRange = std::move(other.m_glyphRange);
|
||||
m_fontData = std::move(other.m_fontData);
|
||||
}
|
||||
|
||||
FontAtlas& operator=(FontAtlas &&other) noexcept {
|
||||
if (this != &other) {
|
||||
if (m_fontAtlas != nullptr) {
|
||||
IM_DELETE(m_fontAtlas);
|
||||
}
|
||||
|
||||
m_fontAtlas = other.m_fontAtlas;
|
||||
other.m_fontAtlas = nullptr;
|
||||
|
||||
m_defaultConfig = other.m_defaultConfig;
|
||||
m_fontSizes = std::move(other.m_fontSizes);
|
||||
m_fontConfigs = std::move(other.m_fontConfigs);
|
||||
m_glyphRange = std::move(other.m_glyphRange);
|
||||
m_fontData = std::move(other.m_fontData);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
~FontAtlas() {
|
||||
if (m_fontAtlas != nullptr) {
|
||||
m_fontAtlas->Locked = false;
|
||||
|
|
|
|||
|
|
@ -97,6 +97,7 @@ namespace hex::fonts {
|
|||
|
||||
// Build the font atlas
|
||||
if (fontAtlas->build()) {
|
||||
fontAtlas->reset();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ namespace hex::fonts {
|
|||
|
||||
bool buildFontAtlas(FontAtlas *fontAtlas, std::fs::path fontPath, bool pixelPerfectFont, float fontSize, bool loadUnicodeCharacters, bool bold, bool italic, bool antialias);
|
||||
|
||||
static AutoReset<std::map<ImFont*, std::unique_ptr<FontAtlas>>> s_fontAtlases;
|
||||
static AutoReset<std::map<UnlocalizedString, std::unique_ptr<FontAtlas>>> s_fontAtlases;
|
||||
|
||||
void loadFont(const ContentRegistry::Settings::Widgets::Widget &widget, const UnlocalizedString &name, ImFont **font, float scale) {
|
||||
const auto &settings = static_cast<const FontSelector&>(widget);
|
||||
|
|
@ -51,7 +51,7 @@ namespace hex::fonts {
|
|||
|
||||
*font = atlas->getAtlas()->Fonts[0];
|
||||
|
||||
(*s_fontAtlases)[*font] = std::move(atlas);
|
||||
(*s_fontAtlases)[name] = std::move(atlas);
|
||||
}
|
||||
|
||||
bool setupFonts() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue