summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/atlas.cc14
-rw-r--r--src/atlas.h1
2 files changed, 10 insertions, 5 deletions
diff --git a/src/atlas.cc b/src/atlas.cc
index 2494cd0..ad697f1 100644
--- a/src/atlas.cc
+++ b/src/atlas.cc
@@ -27,9 +27,9 @@ static void wayc_atlas_gpu_desc(struct sg_image_desc* desc, u32 width,
desc->usage = usage;
}
-static inline usize wayc_atlas_size(struct atlas_s* atlas) {
- wayc_notnull(atlas);
- return atlas->width * atlas->height;
+static inline usize wayc_atlas_size(u32 width, u32 height,
+ enum sg_pixel_format format) {
+ return sg_query_surface_pitch(format, width, height, 1);
}
enum atlas_error_e wayc_atlas_init(struct atlas_s* atlas, u32 width, u32 height,
@@ -38,9 +38,10 @@ enum atlas_error_e wayc_atlas_init(struct atlas_s* atlas, u32 width, u32 height,
memset(atlas, 0, sizeof(*atlas));
bool success = false;
- usize atlas_size = width * height;
+ usize atlas_size = wayc_atlas_size(width, height, format);
u8* cpu_atlas = (u8*)mi_malloc(atlas_size);
wayc_defer_cond(mi_free(cpu_atlas), success, true);
+ memset(cpu_atlas, 0, atlas_size);
struct sg_image_desc desc = {};
wayc_atlas_gpu_desc(&desc, width, height, format);
@@ -51,6 +52,7 @@ enum atlas_error_e wayc_atlas_init(struct atlas_s* atlas, u32 width, u32 height,
atlas->width = width;
atlas->height = height;
+ atlas->format = format;
atlas->cpu_atlas = cpu_atlas;
atlas->gpu_atlas = gpu_atlas;
atlas->cpu_dirty = false;
@@ -63,9 +65,11 @@ enum atlas_error_e wayc_atlas_flush(struct atlas_s* atlas) {
wayc_notnull(atlas);
if (!atlas->cpu_dirty) return ATLAS_ERROR_NONE;
+ usize size = wayc_atlas_size(atlas->width, atlas->height, atlas->format);
+
struct sg_range range = {};
range.ptr = atlas->cpu_atlas;
- range.size = wayc_atlas_size(atlas);
+ range.size = size;
struct sg_image_data data = {};
data.mip_levels[0] = range;
diff --git a/src/atlas.h b/src/atlas.h
index be10c3b..66813a8 100644
--- a/src/atlas.h
+++ b/src/atlas.h
@@ -12,6 +12,7 @@ enum atlas_error_e : u8 {
struct atlas_s {
u32 width, height;
+ enum sg_pixel_format format;
struct sg_image gpu_atlas;
u8* cpu_atlas;
bool cpu_dirty;