perf: optimize text rendering performance

This commit is contained in:
2026-03-28 16:22:38 +08:00
parent c37c45ad19
commit a7c42f249d
6 changed files with 89 additions and 47 deletions

View File

@@ -8,7 +8,7 @@ constexpr int MAX_UI_NUM = 1;
constexpr int CHUCK_SIZE = 16;
constexpr int DISTANCE = 8;
constexpr int MAX_BLOCK_STATUS = 1;
constexpr int MAX_CHARACTER = 128;
constexpr float FOV = 70.0f;
constexpr float VERTICES_POS[6][6][3] = {

View File

@@ -9,7 +9,8 @@
#include <unordered_map>
struct Character {
GLuint texture_id;
glm::vec2 uv_min;
glm::vec2 uv_max;
glm::ivec2 size;
glm::ivec2 bearing;
GLuint advance;
@@ -20,12 +21,16 @@ public:
Font();
~Font();
static void render_text(GLuint program, GLuint vbo, const std::string& text, float x, float y, float scale, const glm::vec3& color);
static void render_text(GLuint program, const std::string& text, float x, float y, float scale, const glm::vec3& color);
private:
FT_Library m_ft;
FT_Face m_face;
float m_texture_width = 64;
float m_texture_height = 64;
GLuint m_text_texture;
std::unordered_map<char8_t, Character> m_characters;
void load_character(char8_t c);