summaryrefslogtreecommitdiff
path: root/src/ui/text.c
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2020-09-03 13:43:05 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2020-09-03 13:43:05 +0300
commit66849901ab1fbacb97644a8635d6b3a3259cbc4c (patch)
tree9bd08bda3ebfb78595f8d1714c555401f81fd658 /src/ui/text.c
parenta54468a67c27dca0cae0b54ca32b67515e0e366e (diff)
Text: 16-bit glyph cache; check maximum texture size
Diffstat (limited to 'src/ui/text.c')
-rw-r--r--src/ui/text.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/ui/text.c b/src/ui/text.c
index 6f87a6d0..6c97a4ce 100644
--- a/src/ui/text.c
+++ b/src/ui/text.c
@@ -200,18 +200,25 @@ static void initCache_Text_(iText *d) {
200 iAssert(textSize > 0); 200 iAssert(textSize > 0);
201 const iInt2 cacheDims = init_I2(16, 80); 201 const iInt2 cacheDims = init_I2(16, 80);
202 d->cacheSize = mul_I2(cacheDims, init1_I2(iMax(textSize, fontSize_UI))); 202 d->cacheSize = mul_I2(cacheDims, init1_I2(iMax(textSize, fontSize_UI)));
203 SDL_RendererInfo renderInfo;
204 SDL_GetRendererInfo(d->render, &renderInfo);
205 if (renderInfo.max_texture_height > 0 && d->cacheSize.y > renderInfo.max_texture_height) {
206 d->cacheSize.y = renderInfo.max_texture_height;
207 d->cacheSize.x = renderInfo.max_texture_width;
208 }
203 d->cacheRowAllocStep = iMax(2, textSize / 6); 209 d->cacheRowAllocStep = iMax(2, textSize / 6);
204 /* Allocate initial (empty) rows. These will be assigned actual locations in the cache 210 /* Allocate initial (empty) rows. These will be assigned actual locations in the cache
205 once at least one glyph is stored. */ 211 once at least one glyph is stored. */
206 for (int h = d->cacheRowAllocStep; h <= 2 * textSize; h += d->cacheRowAllocStep) { 212 for (int h = d->cacheRowAllocStep; h <= 2 * textSize; h += d->cacheRowAllocStep) {
207 pushBack_Array(&d->cacheRows, &(iCacheRow){ .height = 0 }); 213 pushBack_Array(&d->cacheRows, &(iCacheRow){ .height = 0 }); }
208 }
209 d->cacheBottom = 0; 214 d->cacheBottom = 0;
210 d->cache = SDL_CreateTexture(d->render, 215 d->cache = SDL_CreateTexture(d->render,
211 SDL_PIXELFORMAT_RGBA8888, 216 SDL_PIXELFORMAT_RGBA4444,
212 SDL_TEXTUREACCESS_STATIC | SDL_TEXTUREACCESS_TARGET, 217 SDL_TEXTUREACCESS_STATIC | SDL_TEXTUREACCESS_TARGET,
213 d->cacheSize.x, 218 d->cacheSize.x,
214 d->cacheSize.y); 219 d->cacheSize.y);
220
221 printf("cache texture:%p size:%d x %d\n", d->cache, d->cacheSize.x, d->cacheSize.y);
215 SDL_SetTextureBlendMode(d->cache, SDL_BLENDMODE_BLEND); 222 SDL_SetTextureBlendMode(d->cache, SDL_BLENDMODE_BLEND);
216} 223}
217 224
@@ -280,7 +287,7 @@ static SDL_Surface *rasterizeGlyph_Font_(const iFont *d, iChar ch, float xShift)
280 SDL_Surface *surface8 = 287 SDL_Surface *surface8 =
281 SDL_CreateRGBSurfaceWithFormatFrom(bmp, w, h, 8, w, SDL_PIXELFORMAT_INDEX8); 288 SDL_CreateRGBSurfaceWithFormatFrom(bmp, w, h, 8, w, SDL_PIXELFORMAT_INDEX8);
282 SDL_SetSurfacePalette(surface8, text_.grayscale); 289 SDL_SetSurfacePalette(surface8, text_.grayscale);
283 SDL_PixelFormat *fmt = SDL_AllocFormat(SDL_PIXELFORMAT_RGBA8888); 290 SDL_PixelFormat *fmt = SDL_AllocFormat(SDL_PIXELFORMAT_RGBA4444);
284 SDL_Surface *surface = SDL_ConvertSurface(surface8, fmt, 0); 291 SDL_Surface *surface = SDL_ConvertSurface(surface8, fmt, 0);
285 SDL_FreeFormat(fmt); 292 SDL_FreeFormat(fmt);
286 SDL_FreeSurface(surface8); 293 SDL_FreeSurface(surface8);
@@ -817,7 +824,7 @@ void init_TextBuf(iTextBuf *d, int font, const char *text) {
817 SDL_Renderer *render = text_.render; 824 SDL_Renderer *render = text_.render;
818 d->size = advance_Text(font, text); 825 d->size = advance_Text(font, text);
819 d->texture = SDL_CreateTexture(render, 826 d->texture = SDL_CreateTexture(render,
820 SDL_PIXELFORMAT_RGBA8888, 827 SDL_PIXELFORMAT_RGBA4444,
821 SDL_TEXTUREACCESS_STATIC | SDL_TEXTUREACCESS_TARGET, 828 SDL_TEXTUREACCESS_STATIC | SDL_TEXTUREACCESS_TARGET,
822 d->size.x, 829 d->size.x,
823 d->size.y); 830 d->size.y);