From 5115eb592d1477b355770eee9d6b913481d4859f Mon Sep 17 00:00:00 2001 From: kartofen Date: Fri, 20 Oct 2023 19:31:31 +0300 Subject: graphics pipeline --- src/common.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src/common.h') diff --git a/src/common.h b/src/common.h index 1c80ab8..27d8404 100644 --- a/src/common.h +++ b/src/common.h @@ -27,4 +27,34 @@ void *xmalloc(size_t size); void *xcalloc(size_t nmemb, size_t size); void *xrealloc(void *ptr, size_t size); +#define F_LOAD_FILE_ALIGNED(T) \ + static int load_file_##T##_aligned( \ + char *path, size_t *size, u32 *buf) \ + { \ + int ret = 1; \ + \ + FILE *fp = fopen(path, "rb"); \ + if(!fp) { \ + err("fopen: %s: %s", path, strerror(errno)); \ + return 1; \ + } \ + \ + fseek(fp, 0, SEEK_END); \ + *size = (size_t)ftell(fp); \ + *size += (*size % sizeof(u32)); \ + \ + if(buf == NULL) { \ + ret = 0; \ + goto exit; \ + } \ + \ + fseek(fp, 0, SEEK_SET); \ + fread(buf, sizeof(u32), *size/sizeof(u32), fp); \ + \ + return 0; \ + exit: \ + fclose(fp); \ + return ret; \ + } + #endif -- cgit v1.2.3