diff options
Diffstat (limited to 'include/async_image.h')
-rw-r--r-- | include/async_image.h | 45 |
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 */ |