From 44e987c8521a99519350a42292bcfcd28451dcbd Mon Sep 17 00:00:00 2001 From: dec05eba Date: Mon, 20 Dec 2021 10:26:12 +0100 Subject: Async load images --- include/async_image.h | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 include/async_image.h (limited to 'include/async_image.h') 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 +#include +#include + +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 */ -- cgit v1.2.3-70-g09d2