assume constant dimensions for created textures, shaves a lot of time in uploading

This commit is contained in:
veclavtalica
2025-02-09 08:07:58 +03:00
parent 322fbf6bbd
commit d6aaef3f68
4 changed files with 57 additions and 21 deletions

View File

@ -193,7 +193,7 @@ static SDL_Surface *create_surface(int width, int height) {
static void add_new_atlas(TextureCache *cache) {
SDL_Surface *new_atlas = create_surface((int)ctx.texture_atlas_size, (int)ctx.texture_atlas_size);
arrput(cache->atlas_surfaces, new_atlas);
arrput(cache->atlas_textures, create_gpu_texture(TEXTURE_FILTER_NEAREAST, true));
arrput(cache->atlas_textures, create_gpu_texture(TEXTURE_FILTER_NEAREAST, true, 4, (int)ctx.texture_atlas_size, (int)ctx.texture_atlas_size));
}
@ -510,7 +510,7 @@ void textures_update_atlas(TextureCache *cache) {
if (!is_power_of_two(response.data->w) || !is_power_of_two(response.data->h))
log_warn("Unportable texture dimensions for %s, should be powers of 2", cache->hash[texture_load_queue[i].index].key);
}
response.loner_texture = create_gpu_texture(TEXTURE_FILTER_NEAREAST, true);
response.loner_texture = create_gpu_texture(TEXTURE_FILTER_NEAREAST, true, response.data->format->BytesPerPixel, response.data->w, response.data->h);
upload_texture_from_surface(response.loner_texture, response.data);
response.srcrect = (Rect) { .w = (float)response.data->w, .h = (float)response.data->h };
@ -642,7 +642,11 @@ void textures_bind_repeating(const TextureCache *cache, TextureKey key) {
const Texture texture = cache->hash[key.id].value;
const GPUTexture repeating_texture = create_gpu_texture(TEXTURE_FILTER_NEAREAST, false);
const GPUTexture repeating_texture = create_gpu_texture(TEXTURE_FILTER_NEAREAST,
false,
texture.data->format->BytesPerPixel,
texture.data->w,
texture.data->h);
SDL_LockSurface(texture.data);