aboutsummaryrefslogtreecommitdiff
path: root/include/async_image.h
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-12-20 10:26:12 +0100
committerdec05eba <dec05eba@protonmail.com>2021-12-21 20:22:33 +0100
commit44e987c8521a99519350a42292bcfcd28451dcbd (patch)
tree699015a5dd459e96e0b19f4836f7dcffc1e347de /include/async_image.h
parent6bb40bf0c5cd8ee8fb87640fd04b2c595f84c1d3 (diff)
Async load images
Diffstat (limited to 'include/async_image.h')
-rw-r--r--include/async_image.h45
1 files changed, 45 insertions, 0 deletions
diff --git a/include/async_image.h b/include/async_image.h
new file mode 100644
index 0000000..a108d5e
--- /dev/null
+++ b/include/async_image.h
@@ -0,0 +1,45 @@
+#ifndef MGUI_ASYNC_IMAGE_H
+#define MGUI_ASYNC_IMAGE_H
+
+#include <mgl/graphics/image.h>
+#include <mgl/graphics/texture.h>
+#include <stdint.h>
+
+typedef struct mgui_async_image mgui_async_image;
+
+typedef enum {
+ MGUI_ASYNC_IMAGE_NOT_LOADED,
+ MGUI_ASYNC_IMAGE_LOADING,
+ MGUI_ASYNC_IMAGE_LOADED,
+ MGUI_ASYNC_IMAGE_APPLIED,
+ MGUI_ASYNC_IMAGE_FAILED_TO_LOAD,
+ MGUI_ASYNC_IMAGE_UNLOADED
+} mgui_async_image_state;
+
+struct mgui_async_image {
+ mgl_image image;
+ mgl_texture texture;
+ uint64_t hash;
+ mgui_async_image_state state;
+ uint32_t updated;
+ uint32_t ref_count;
+ char *filepath;
+};
+
+/* Do not call this manually */
+void mgui_async_image_init();
+/* Do not call this manually */
+void mgui_async_image_deinit();
+/* Do not call this manually */
+void mgui_async_image_unload_unreferenced();
+
+/*
+ Increases reference count by 1 every time this is called.
+ Call |mgui_async_image_unref| when done with the image so it can be unloaded when all references are gone.
+*/
+mgui_async_image* mgui_async_image_get_by_path(const char *filepath);
+/* Needs to be called at least once a frame to keep the image from being unloaded */
+void mgui_async_image_update(mgui_async_image *self);
+void mgui_async_image_unref(mgui_async_image *self);
+
+#endif /* MGUI_ASYNC_IMAGE_H */