fix texture atlas bounds check

This commit is contained in:
jacob 2026-02-12 19:03:55 -06:00
parent fdd888cb32
commit f3ae9674f1
3 changed files with 15 additions and 23 deletions

View File

@ -324,22 +324,22 @@ void GC_TickAsync(WaveLaneCtx *lane, AsyncFrameLaneCtx *base_async_lane_frame)
SllStackPush(GC.first_atlas, atlas); SllStackPush(GC.first_atlas, atlas);
++GC.atlases_count; ++GC.atlases_count;
} }
// Determine pos in atlas if (atlas->cur_pos.x + image_dims.x > atlas->dims.x)
pos_in_atlas = atlas->cur_pos;
atlas->cur_row_height = MaxI32(atlas->cur_row_height, image_dims.y);
if (pos_in_atlas.x + image_dims.x > atlas->dims.x)
{ {
atlas->cur_pos.x = 0; atlas->cur_pos.x = 0;
atlas->cur_pos.y += atlas->cur_row_height; atlas->cur_pos.y += atlas->cur_row_height;
atlas->cur_row_height = image_dims.y; atlas->cur_row_height = 0;
} }
atlas->cur_pos.x += image_dims.x; if (atlas->cur_pos.x + image_dims.x < atlas->dims.x && atlas->cur_pos.y + image_dims.y < atlas->dims.y)
if (atlas->cur_pos.x < atlas->dims.x && atlas->cur_pos.y < atlas->dims.y)
{ {
pos_in_atlas = atlas->cur_pos;
atlas->cur_row_height = MaxI32(atlas->cur_row_height, image_dims.y);
atlas->cur_pos.x += image_dims.x;
can_use_atlas = 1; can_use_atlas = 1;
} }
else else
{ {
// New atlas required
atlas = 0; atlas = 0;
} }
} }

View File

@ -4960,17 +4960,9 @@ void V_TickForever(WaveLaneCtx *lane)
////////////////////////////// //////////////////////////////
//- End frame //- End frame
i32 vsync = !!TweakBool("Vsync", 1);
// {
// Arena *old_arena = sim_output->arena;
// ZeroStruct(sim_output);
// sim_output->arena = old_arena;
// ResetArena(sim_output->arena);
// }
G_CommitCommandList(frame->cl); G_CommitCommandList(frame->cl);
i32 vsync = !!TweakBool("Vsync", 1);
UI_EndFrame(ui_frame, vsync); UI_EndFrame(ui_frame, vsync);
} }

View File

@ -447,22 +447,22 @@ void SPR_TickAsync(WaveLaneCtx *lane, AsyncFrameLaneCtx *base_async_lane_frame)
SllStackPush(SPR.first_atlas, atlas); SllStackPush(SPR.first_atlas, atlas);
++SPR.atlases_count; ++SPR.atlases_count;
} }
// Determine pos in atlas if (atlas->cur_pos.x + slice_dims.x > atlas->dims.x)
atlas_pos = atlas->cur_pos;
atlas->cur_row_height = MaxI32(atlas->cur_row_height, slice_dims.y);
if (atlas_pos.x + slice_dims.x > atlas->dims.x)
{ {
atlas->cur_pos.x = 0; atlas->cur_pos.x = 0;
atlas->cur_pos.y += atlas->cur_row_height; atlas->cur_pos.y += atlas->cur_row_height;
atlas->cur_row_height = slice_dims.y; atlas->cur_row_height = 0;
} }
atlas->cur_pos.x += slice_dims.x; if (atlas->cur_pos.x + slice_dims.x < atlas->dims.x && atlas->cur_pos.y + slice_dims.y < atlas->dims.y)
if (atlas->cur_pos.x < atlas->dims.x && atlas->cur_pos.y < atlas->dims.y)
{ {
atlas_pos = atlas->cur_pos;
atlas->cur_row_height = MaxI32(atlas->cur_row_height, slice_dims.y);
atlas->cur_pos.x += slice_dims.x;
can_use_atlas = 1; can_use_atlas = 1;
} }
else else
{ {
// New atlas required
atlas = 0; atlas = 0;
} }
} }