summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFabrice <fabrice@schaub-dev.xyz>2026-02-11 21:44:49 +0100
committerFabrice <fabrice@schaub-dev.xyz>2026-02-11 21:44:49 +0100
commit952dc19e0eeec2b0ba695970ac3f5a2997e39c77 (patch)
tree10a484496fc9c8acf9b389c9d9a78c6637d803c8 /src
parent29805da671f7dd13f9e1b25800ac6a846391d355 (diff)
working on atlas
Diffstat (limited to 'src')
-rw-r--r--src/rendering.cc17
-rw-r--r--src/rendering.h7
-rw-r--r--src/text.cc4
-rw-r--r--src/text.h5
-rw-r--r--src/wayclock.cc3
5 files changed, 24 insertions, 12 deletions
diff --git a/src/rendering.cc b/src/rendering.cc
index 356c6b3..8044688 100644
--- a/src/rendering.cc
+++ b/src/rendering.cc
@@ -4,7 +4,6 @@
#include <cstring>
-#include "cglm/ivec2.h"
#include "utils.h"
bool wayc_image_init(texture_t* texture, image_type_e type,
@@ -74,15 +73,15 @@ void wayc_sampler_use(sampler_t sampler, u32 slot) {
void wayc_sampler_deinit(sampler_t* sampler) { glDeleteSamplers(1, sampler); }
-bool wayc_atlas_init(atlas_s* atlas, u32 width, u32 height) {
+bool wayc_atlas_init(atlas_s* atlas, image_format_e format, u32 width,
+ u32 height) {
wayc_notnull(atlas);
memset(atlas, 0, sizeof(*atlas));
bool success = false;
texture_t texture;
- bool ok = wayc_image_init(&texture, IMAGE_TYPE_2D, IMAGE_FORMAT_RGBA, width,
- height);
+ bool ok = wayc_image_init(&texture, IMAGE_TYPE_2D, format, width, height);
if (!ok) return false;
wayc_defer_cond(wayc_image_deinit(&texture);, success, true);
@@ -95,7 +94,6 @@ bool wayc_atlas_init(atlas_s* atlas, u32 width, u32 height) {
atlas->sampler = sampler;
atlas->width = width;
atlas->height = height;
- glm_ivec2_zero(atlas->cursor);
success = true;
return true;
@@ -106,6 +104,15 @@ void wayc_atlas_use(atlas_s* atlas, u32 slot) {
wayc_sampler_use(atlas->sampler, slot);
}
+void wayc_atlas_set(atlas_s* atlas, image_data_type_e data_type, ivec2 offset,
+ u32 width, u32 height, const u8* data) {
+ wayc_notnull(atlas);
+ wayc_notnull(data);
+
+ wayc_image_upload(atlas->texture, offset, width, height, IMAGE_TYPE_2D,
+ IMAGE_FORMAT_RGBA, data_type, data);
+}
+
void wayc_atlas_deinit(atlas_s* atlas) {
wayc_notnull(atlas);
wayc_sampler_deinit(&atlas->sampler);
diff --git a/src/rendering.h b/src/rendering.h
index b70d366..8927eff 100644
--- a/src/rendering.h
+++ b/src/rendering.h
@@ -55,10 +55,13 @@ void wayc_sampler_deinit(sampler_t* sampler);
struct atlas_s {
texture_t texture;
sampler_t sampler;
- ivec2 cursor;
u32 width, height;
+ image_format_e format;
};
-bool wayc_atlas_init(atlas_s* atlas, u32 width, u32 height);
+bool wayc_atlas_init(atlas_s* atlas, image_format_e format, u32 width,
+ u32 height);
void wayc_atlas_use(atlas_s* atlas, u32 slot);
+void wayc_atlas_set(atlas_s* atlas, image_data_type_e data_type, ivec2 offset,
+ u32 width, u32 height, const u8* data);
void wayc_atlas_deinit(atlas_s* atlas);
diff --git a/src/text.cc b/src/text.cc
index d209ed2..21cee19 100644
--- a/src/text.cc
+++ b/src/text.cc
@@ -70,8 +70,8 @@ enum font_error_e wayc_font_init(struct font_s* font,
return FONT_ERROR_NONE;
}
-enum font_error_e wayc_font_lookup(struct font_s* font, codepoint_t codepoint,
- struct glyph_s* out) {
+enum font_error_e wayc_font_lookup(struct font_s* font, struct atlas_s* atlas,
+ codepoint_t codepoint, struct glyph_s* out) {
wayc_notnull(font);
wayc_notnull(out);
diff --git a/src/text.h b/src/text.h
index e507221..a3ed9d1 100644
--- a/src/text.h
+++ b/src/text.h
@@ -2,6 +2,7 @@
#include "freetype/freetype.h"
#include "hash.h"
+#include "rendering.h"
#include "utils.h"
typedef u32 codepoint_t;
@@ -35,6 +36,6 @@ struct font_s {
enum font_error_e wayc_font_init(struct font_s* font,
struct font_context_s* ctx, const char* path);
-enum font_error_e wayc_font_lookup(struct font_s* font, codepoint_t codepoint,
- struct glyph_s* out);
+enum font_error_e wayc_font_lookup(struct font_s* font, struct atlas_s* atlas,
+ codepoint_t codepoint, struct glyph_s* out);
void wayc_font_deinit(struct font_s* font);
diff --git a/src/wayclock.cc b/src/wayclock.cc
index 43f07ab..a34a0b8 100644
--- a/src/wayclock.cc
+++ b/src/wayclock.cc
@@ -108,7 +108,8 @@ int main() {
glClearColor(0.1f, 0.2f, 0.2f, 1.0f);
struct atlas_s atlas;
- if (!wayc_atlas_init(&atlas, WAYC_ATLAS_WIDTH, WAYC_ATLAS_HEIGHT))
+ if (!wayc_atlas_init(&atlas, IMAGE_FORMAT_RGBA, WAYC_ATLAS_WIDTH,
+ WAYC_ATLAS_HEIGHT))
wayc_panic("Failed to initialize atlas");
wayc_defer(wayc_atlas_deinit(&atlas));