summaryrefslogtreecommitdiff
path: root/src/rendering.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/rendering.cc')
-rw-r--r--src/rendering.cc28
1 files changed, 28 insertions, 0 deletions
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 <cstring>
+#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