Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenfont/intern/blf_font.c
| Show First 20 Lines • Show All 181 Lines • ▼ Show 20 Lines | |||||
| static GPUTexture *blf_batch_cache_texture_load(void) | static GPUTexture *blf_batch_cache_texture_load(void) | ||||
| { | { | ||||
| GlyphCacheBLF *gc = g_batch.glyph_cache; | GlyphCacheBLF *gc = g_batch.glyph_cache; | ||||
| BLI_assert(gc); | BLI_assert(gc); | ||||
| BLI_assert(gc->bitmap_len > 0); | BLI_assert(gc->bitmap_len > 0); | ||||
| if (gc->bitmap_len > gc->bitmap_len_landed) { | if (gc->bitmap_len > gc->bitmap_len_landed) { | ||||
| const int tex_width = GPU_texture_width(gc->texture); | int bitmap_len = gc->bitmap_len; | ||||
| int tex_width = g_batch.font->tex_size_max; | |||||
| int tex_height = bitmap_len / tex_width + 1; | |||||
| if (tex_height == 1 && gc->texture && GPU_texture_height(gc->texture) == 1) { | |||||
| int bitmap_len_landed = gc->bitmap_len_landed; | int bitmap_len_landed = gc->bitmap_len_landed; | ||||
| int remain = gc->bitmap_len - bitmap_len_landed; | |||||
| int offset_x = bitmap_len_landed % tex_width; | |||||
| int offset_y = bitmap_len_landed / tex_width; | |||||
| /* TODO(germano): Update more than one row in a single call. */ | |||||
| while (remain) { | |||||
| int remain_row = tex_width - offset_x; | |||||
| int width = remain > remain_row ? remain_row : remain; | |||||
| GPU_texture_update_sub(gc->texture, | GPU_texture_update_sub(gc->texture, | ||||
| GPU_DATA_UNSIGNED_BYTE, | GPU_DATA_UNSIGNED_BYTE, | ||||
| &gc->bitmap_result[bitmap_len_landed], | &gc->bitmap_result[bitmap_len_landed], | ||||
| offset_x, | bitmap_len_landed, | ||||
| offset_y, | |||||
| 0, | 0, | ||||
| width, | 0, | ||||
| bitmap_len - bitmap_len_landed, | |||||
| 1, | 1, | ||||
| 0); | 0); | ||||
| } | |||||
| bitmap_len_landed += width; | else { | ||||
| remain -= width; | /* In some GPUs it is difficult to update a texture buffer with more than | ||||
| offset_x = 0; | * one row because the `GPU_texture_update_sub` behavior seems to vary. | ||||
| offset_y += 1; | * So, recreate the entire texture in this case. */ | ||||
| if (gc->texture) { | |||||
| GPU_texture_free(gc->texture); | |||||
| } | |||||
| gc->texture = GPU_texture_create_nD(tex_width, | |||||
| tex_height, | |||||
| 0, | |||||
| 1, | |||||
| gc->bitmap_result, | |||||
| GPU_R8, | |||||
| GPU_DATA_UNSIGNED_BYTE, | |||||
| 0, | |||||
| false, | |||||
| NULL); | |||||
| } | } | ||||
| gc->bitmap_len_landed = bitmap_len_landed; | gc->bitmap_len_landed = bitmap_len; | ||||
| } | } | ||||
| return gc->texture; | return gc->texture; | ||||
| } | } | ||||
| void blf_batch_draw(void) | void blf_batch_draw(void) | ||||
| { | { | ||||
| if (g_batch.glyph_len == 0) { | if (g_batch.glyph_len == 0) { | ||||
| ▲ Show 20 Lines • Show All 1,194 Lines • Show Last 20 Lines | |||||