twn_textures.c: little pieces

This commit is contained in:
veclav talica 2024-09-23 09:50:01 +03:00
parent 66678a27cf
commit 535d5d8d36

View File

@ -344,7 +344,7 @@ static t_texture_key textures_load(struct texture_cache *cache, const char *path
/* it's a "loner texture," it doesn't fit in an atlas so it's not in one */ /* it's a "loner texture," it doesn't fit in an atlas so it's not in one */
if (surface->w >= TEXTURE_ATLAS_SIZE || surface->h >= TEXTURE_ATLAS_SIZE) { if (surface->w >= TEXTURE_ATLAS_SIZE || surface->h >= TEXTURE_ATLAS_SIZE) {
if (ctx.game.debug) { if (ctx.game.debug) {
if (surface->w > TEXTURE_ATLAS_SIZE || surface->h > TEXTURE_ATLAS_SIZE) if (surface->w > 2048 || surface->h > 2048)
log_warn("Unportable texture dimensions for %s, use 2048x2048 at max", path); log_warn("Unportable texture dimensions for %s, use 2048x2048 at max", path);
if (!is_power_of_two(surface->w) || !is_power_of_two(surface->h)) if (!is_power_of_two(surface->w) || !is_power_of_two(surface->h))
log_warn("Unportable texture dimensions for %s, should be powers of 2", path); log_warn("Unportable texture dimensions for %s, should be powers of 2", path);
@ -352,14 +352,13 @@ static t_texture_key textures_load(struct texture_cache *cache, const char *path
new_texture.loner_texture = create_gpu_texture(TEXTURE_FILTER_NEAREAST, true); new_texture.loner_texture = create_gpu_texture(TEXTURE_FILTER_NEAREAST, true);
upload_texture_from_surface(new_texture.loner_texture, surface); upload_texture_from_surface(new_texture.loner_texture, surface);
new_texture.srcrect = (t_frect) { .w = (float)surface->w, .h = (float)surface->h }; new_texture.srcrect = (t_frect) { .w = (float)surface->w, .h = (float)surface->h };
shput(cache->hash, path, new_texture);
return (t_texture_key){ (uint16_t)shgeti(cache->hash, path) };
} else { } else {
/* will be fully populated as the atlas updates */
new_texture.atlas_index = cache->atlas_index; new_texture.atlas_index = cache->atlas_index;
shput(cache->hash, path, new_texture);
cache->is_dirty = true; cache->is_dirty = true;
return (t_texture_key){ (uint16_t)shgeti(cache->hash, path) };
} }
shput(cache->hash, path, new_texture);
return (t_texture_key){ (uint16_t)shgeti(cache->hash, path) };
} }
@ -544,6 +543,8 @@ void textures_bind_repeating(const struct texture_cache *cache, t_texture_key ke
cache->hash[key.id].value.repeating_texture = repeating_texture; cache->hash[key.id].value.repeating_texture = repeating_texture;
bind_gpu_texture(repeating_texture);
} else } else
bind_gpu_texture(cache->hash[key.id].value.loner_texture); bind_gpu_texture(cache->hash[key.id].value.loner_texture);