Просмотр исходного кода

REVIEWED: `GenImageFontAtlas()`, no need for the conservative approach flag

pull/5574/head
Ray 2 дней назад
Родитель
Сommit
90dd9aef72
1 измененных файлов: 3 добавлений и 18 удалений
  1. +3
    -18
      src/rtext.c

+ 3
- 18
src/rtext.c Просмотреть файл

@ -818,25 +818,11 @@ Image GenImageFontAtlas(const GlyphInfo *glyphs, Rectangle **glyphRecs, int glyp
totalWidth += glyphs[i].image.width + 2*padding; totalWidth += glyphs[i].image.width + 2*padding;
} }
//#define SUPPORT_FONT_ATLAS_SIZE_CONSERVATIVE
#if defined(SUPPORT_FONT_ATLAS_SIZE_CONSERVATIVE)
int rowCount = 0;
int imageSize = 64; // Define minimum starting value to avoid unnecessary calculation steps for very small images
// NOTE: maxGlyphWidth is maximum possible space left at the end of row
while (totalWidth > (imageSize - maxGlyphWidth)*rowCount)
{
imageSize *= 2; // Double the size of image (to keep POT)
rowCount = imageSize/(fontSize + 2*padding); // Calculate new row count for the new image size
}
atlas.width = imageSize; // Atlas bitmap width
atlas.height = imageSize; // Atlas bitmap height
#else
int paddedFontSize = fontSize + 2*padding; int paddedFontSize = fontSize + 2*padding;
// No need for a so-conservative atlas generation
// NOTE: Multiplying total expected are by 1.2f scale factor
// Estimate image atlas size from available data
// NOTE: Multiplying total expected area by 1.2f scale factor but in case
// some glyphs do not fit, the atlas height is scaled x2 to fit them
float totalArea = totalWidth*paddedFontSize*1.2f; float totalArea = totalWidth*paddedFontSize*1.2f;
float imageMinSize = sqrtf(totalArea); float imageMinSize = sqrtf(totalArea);
int imageSize = (int)powf(2, ceilf(logf(imageMinSize)/logf(2))); int imageSize = (int)powf(2, ceilf(logf(imageMinSize)/logf(2)));
@ -851,7 +837,6 @@ Image GenImageFontAtlas(const GlyphInfo *glyphs, Rectangle **glyphRecs, int glyp
atlas.width = imageSize; // Atlas bitmap width atlas.width = imageSize; // Atlas bitmap width
atlas.height = imageSize; // Atlas bitmap height atlas.height = imageSize; // Atlas bitmap height
} }
#endif
int atlasDataSize = atlas.width*atlas.height; // Save total size for bounds checking int atlasDataSize = atlas.width*atlas.height; // Save total size for bounds checking
atlas.data = (unsigned char *)RL_CALLOC(atlasDataSize, 1); // Create a bitmap to store characters (8 bpp) atlas.data = (unsigned char *)RL_CALLOC(atlasDataSize, 1); // Create a bitmap to store characters (8 bpp)

Загрузка…
Отмена
Сохранить