overlays: use thread local static vector in get_glyph_data

This commit is contained in:
Megamouse 2025-02-26 21:46:24 +01:00
parent 7fd1f5b5d3
commit 4aa25285a3
4 changed files with 13 additions and 14 deletions

View file

@ -303,7 +303,7 @@ namespace gl
}
// Create font file
const std::vector<u8> glyph_data = font->get_glyph_data();
const std::vector<u8>& glyph_data = font->get_glyph_data();
auto tex = std::make_unique<gl::texture>(GL_TEXTURE_2D_ARRAY, font_size.width, font_size.height, font_size.depth, 1, 1, GL_R8, RSX_FORMAT_CLASS_COLOR);
tex->copy_from(glyph_data.data(), gl::texture::format::r, gl::texture::type::ubyte, {});

View file

@ -417,13 +417,14 @@ namespace rsx
return {loc_x, loc_y};
}
std::vector<u8> font::get_glyph_data() const
const std::vector<u8>& font::get_glyph_data() const
{
std::vector<u8> bytes;
const u32 page_size = codepage::bitmap_width * codepage::bitmap_height;
constexpr u32 page_size = codepage::bitmap_width * codepage::bitmap_height;
const auto size = page_size * m_glyph_map.size();
static thread_local std::vector<u8> bytes;
bytes.resize(size);
u8* data = bytes.data();
for (const auto& e : m_glyph_map)

View file

@ -79,7 +79,7 @@ namespace rsx
std::pair<f32, f32> get_char_offset(const char32_t* text, usz max_length, u16 max_width = -1, bool wrap = false);
bool matches(const char* name, int size) const { return font_name == name && static_cast<int>(size_pt) == size; }
bool matches(const char* name, int size) const { return static_cast<int>(size_pt) == size && font_name == name; }
std::string_view get_name() const { return font_name; }
f32 get_size_pt() const { return size_pt; }
f32 get_size_px() const { return size_px; }
@ -87,7 +87,7 @@ namespace rsx
// Renderer info
size3u get_glyph_data_dimensions() const { return { codepage::bitmap_width, codepage::bitmap_height, ::size32(m_glyph_map) }; }
std::vector<u8> get_glyph_data() const;
const std::vector<u8>& get_glyph_data() const;
};
// TODO: Singletons are cancer
@ -99,7 +99,7 @@ namespace rsx
font* find(const char* name, int size)
{
for (auto& f : fonts)
for (const auto& f : fonts)
{
if (f->matches(name, size))
return f.get();

View file

@ -508,16 +508,14 @@ namespace vk
{
return found->second.get();
}
else
{
auto gc = vk::get_resource_manager();
gc->dispose(font_cache[key]);
gc->dispose(view_cache[key]);
}
auto gc = vk::get_resource_manager();
gc->dispose(font_cache[key]);
gc->dispose(view_cache[key]);
}
// Create font resource
const std::vector<u8> bytes = font->get_glyph_data();
const std::vector<u8>& bytes = font->get_glyph_data();
return upload_simple_texture(cmd.get_command_pool().get_owner(), cmd, upload_heap, key, image_size.width, image_size.height, image_size.depth,
true, false, bytes.data(), -1);