From a0a68b7b3a5430fea5aaa2ad1da75fdda5cd5c7a Mon Sep 17 00:00:00 2001 From: Fabrice Date: Wed, 11 Feb 2026 22:50:21 +0100 Subject: packing corrections --- src/rendering.cc | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src/rendering.cc') diff --git a/src/rendering.cc b/src/rendering.cc index 89a64ac..65a89b1 100644 --- a/src/rendering.cc +++ b/src/rendering.cc @@ -4,6 +4,7 @@ #include +#include "cglm/types.h" #include "utils.h" bool wayc_image_init(texture_t* texture, image_type_e type, @@ -126,3 +127,30 @@ void wayc_atlas_deinit(atlas_s* atlas) { wayc_sampler_deinit(&atlas->sampler); wayc_image_deinit(&atlas->texture); } + +static inline void wayc_atlas_packer_wrap(struct atlas_packer_s* packer) { + WAYC_X(packer->cursor) = 0; + WAYC_Y(packer->cursor) += packer->row_height; + packer->row_height = 0; +} + +bool wayc_atlas_packer_allocate(struct atlas_packer_s* packer, u32 width, + u32 height, ivec2 out) { + wayc_notnull(packer); + + struct atlas_s* atlas = packer->atlas; + wayc_notnull(atlas); + + if (width > atlas->width || height > atlas->height) return false; + + if (WAYC_X(packer->cursor) + width > atlas->width) + wayc_atlas_packer_wrap(packer); + + if (WAYC_Y(packer->cursor) + height > atlas->height) return false; + + glm_ivec2_copy(packer->cursor, out); + WAYC_X(packer->cursor) += width; + packer->row_height = wayc_max(packer->row_height, height); + + return true; +} \ No newline at end of file -- cgit v1.2.3