twn_textures.c: fix srcrect setting on atlas rebuild

This commit is contained in:
veclav talica 2024-09-23 11:51:18 +03:00
parent f705546644
commit 0ef8a6233f
2 changed files with 13 additions and 7 deletions

View File

@ -94,9 +94,9 @@ static void ingame_tick(struct state *state) {
(t_fvec3){ (float)x, d0, (float)y }, (t_fvec3){ (float)x, d0, (float)y },
(t_fvec3){ (float)x + 1, d1, (float)y }, (t_fvec3){ (float)x + 1, d1, (float)y },
(t_fvec3){ (float)x, d3, (float)y - 1 }, (t_fvec3){ (float)x, d3, (float)y - 1 },
(t_shvec2){ 0, 768 },
(t_shvec2){ 1024, 768 }, (t_shvec2){ 1024, 768 },
(t_shvec2){ 1024, 0 }); (t_shvec2){ 1024, 0 },
(t_shvec2){ 0, 768 });
unfurl_triangle("/assets/grass.gif", unfurl_triangle("/assets/grass.gif",
(t_fvec3){ (float)x + 1, d1, (float)y }, (t_fvec3){ (float)x + 1, d1, (float)y },

View File

@ -130,8 +130,8 @@ static void upload_texture_from_surface(gpu_texture texture, SDL_Surface *surfac
static void recreate_current_atlas_texture(struct texture_cache *cache) { static void recreate_current_atlas_texture(struct texture_cache *cache) {
/* TODO: figure out if SDL_UpdateTexture alone is faster than blitting */
/* TODO: should surfaces be freed after they cannot be referenced in atlas builing? */ /* TODO: should surfaces be freed after they cannot be referenced in atlas builing? */
/* for example, if full page of 64x64 tiles was already filled, there's no real reason to process them further */
SDL_Surface *atlas_surface = cache->atlas_surfaces[cache->atlas_index]; SDL_Surface *atlas_surface = cache->atlas_surfaces[cache->atlas_index];
/* clear */ /* clear */
@ -230,13 +230,19 @@ static bool update_rects(struct texture_cache *cache, stbrp_rect *rects, stbrp_r
/* updates the atlas location of every rect in the cache */ /* updates the atlas location of every rect in the cache */
static void update_texture_rects_in_atlas(struct texture_cache *cache, stbrp_rect *rects) { static void update_texture_rects_in_atlas(struct texture_cache *cache, stbrp_rect *rects) {
int r = 0;
for (size_t i = 0; i < arrlenu(rects); ++i) { for (size_t i = 0; i < arrlenu(rects); ++i) {
if (cache->hash[i].value.loner_texture != 0)
continue;
cache->hash[i].value.srcrect = (t_frect) { cache->hash[i].value.srcrect = (t_frect) {
.x = (float)rects[i].x, .x = (float)rects[r].x,
.y = (float)rects[i].y, .y = (float)rects[r].y,
.w = (float)rects[i].w, .w = (float)rects[r].w,
.h = (float)rects[i].h, .h = (float)rects[r].h,
}; };
r++;
} }
} }