| 79 | } |
| 80 | |
| 81 | static void SetupCache(HFontMap font_map, uint32_t texture_width, uint32_t texture_height, |
| 82 | uint32_t cell_width, uint32_t cell_height, uint32_t max_ascent) |
| 83 | { |
| 84 | if (font_map->m_Cache) |
| 85 | { |
| 86 | free(font_map->m_Cache); |
| 87 | free(font_map->m_CellTempData); |
| 88 | free(font_map->m_CacheIndices); |
| 89 | font_map->m_GlyphCache.Clear(); |
| 90 | } |
| 91 | |
| 92 | font_map->m_CacheCellWidth = cell_width; |
| 93 | font_map->m_CacheCellHeight = cell_height; |
| 94 | font_map->m_CacheCellMaxAscent = max_ascent; |
| 95 | |
| 96 | font_map->m_CacheColumns = texture_width / cell_width; |
| 97 | font_map->m_CacheRows = texture_height / cell_height; |
| 98 | font_map->m_CacheCellCount = font_map->m_CacheColumns * font_map->m_CacheRows; |
| 99 | |
| 100 | font_map->m_CellTempData = (uint8_t*)malloc(font_map->m_CacheCellWidth*font_map->m_CacheCellHeight*4); |
| 101 | |
| 102 | font_map->m_CacheCursor = 0; |
| 103 | font_map->m_CacheIndices = (uint16_t*)malloc(sizeof(uint16_t) * font_map->m_CacheCellCount); |
| 104 | memset(font_map->m_CacheIndices, 0, sizeof(uint16_t) * font_map->m_CacheCellCount); |
| 105 | |
| 106 | font_map->m_Cache = (CacheGlyph*)malloc(sizeof(CacheGlyph) * font_map->m_CacheCellCount); |
| 107 | memset(font_map->m_Cache, 0, sizeof(CacheGlyph*) * font_map->m_CacheCellCount); |
| 108 | for (uint32_t i = 0; i < font_map->m_CacheCellCount; ++i) |
| 109 | { |
| 110 | font_map->m_CacheIndices[i] = i; |
| 111 | |
| 112 | CacheGlyph* glyph = &font_map->m_Cache[i]; |
| 113 | glyph->m_Glyph = 0; |
| 114 | glyph->m_Frame = 0; |
| 115 | |
| 116 | // We calculate these only once |
| 117 | uint32_t col = i % font_map->m_CacheColumns; |
| 118 | uint32_t row = i / font_map->m_CacheColumns; |
| 119 | glyph->m_X = col * font_map->m_CacheCellWidth; |
| 120 | glyph->m_Y = row * font_map->m_CacheCellHeight; |
| 121 | } |
| 122 | |
| 123 | uint32_t old_cap = font_map->m_GlyphCache.Capacity(); |
| 124 | int new_cap = font_map->m_CacheCellCount; |
| 125 | if (new_cap > old_cap) |
| 126 | { |
| 127 | font_map->m_GlyphCache.SetCapacity((new_cap*3)/2, new_cap); |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | static void ClearTexture(HFontMap font_map, uint32_t width, uint32_t height) |
| 132 | { |
no test coverage detected