diff options
| author | onelin <oscar@nelin.dk> | 2025-10-31 23:55:42 +0000 |
|---|---|---|
| committer | onelin <oscar@nelin.dk> | 2025-11-02 22:07:17 +0000 |
| commit | d38deeef3af2316a666f8fc0173940bd769b748e (patch) | |
| tree | 6e30d4a9eea18daa5705c894f28cd99ff047e8f9 /src/resources/include/engine/resources.h | |
| parent | 6c077751982ea2c7bd2d9262b01b9f8602f80dc8 (diff) | |
Flatten project structure
This will make it easier to break up the code into smaller chunks again
later.
One would think doing this seems fun to me at this point.
Diffstat (limited to 'src/resources/include/engine/resources.h')
| -rw-r--r-- | src/resources/include/engine/resources.h | 138 |
1 files changed, 0 insertions, 138 deletions
diff --git a/src/resources/include/engine/resources.h b/src/resources/include/engine/resources.h deleted file mode 100644 index d967403..0000000 --- a/src/resources/include/engine/resources.h +++ /dev/null @@ -1,138 +0,0 @@ -#ifndef ENGINE_RESOURCES_H -#define ENGINE_RESOURCES_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include <engine/core/types.h> -#include <engine/rendering/rendering.h> - -// TODO -/* We need some "global resources", available to all states. - * These are resources used throughout the applications lifetime, such as common - * fonts, GUI frames, button background images. - * - * We need to define state-specific resources as well. - * - Can both be defined alike? - * If we lazy-load all resources we can get away with a lot. - * Maybe use fall-back resources? like the missing source texture, and an ugly - * font? - * - Then declare to the engine, in the main function for the game, that these - * resources are to be made available throughout? - * - Shaders, oh boy oh shaders. - * We need to make some meta-shader declaration, so we can declare a set of - * shaders, that are used to link with other shaders, s.t. we can free up the - * shaders after compilation. - * - Make all resource specifications a union. - * */ - -enum Asset { - Asset_error, - Asset_audio, - Asset_font, - Asset_shader, - Asset_shaderprog, - Asset_texture, - Asset_model, -}; - -typedef struct { - enum Asset type; - const char* path; -} Asset_AudioSpec; - -typedef struct { - enum Asset type; - const char* path; -} Asset_FontSpec; - -// if a shader is declared GLOBALLY, we should not destroy it when done with the -// "main" shader compilations. -typedef struct { - enum Asset type; - // Assume shader type from filename - const char* path; -} Asset_ShaderSpec; - -// Use list of gluint shader program ids to link against. This translates to a -// call to compose_shader. -typedef struct { - enum Asset type; - const u32* shader; - const usize shader_len; -} Asset_ShaderProgramSpec; - -typedef struct { - enum Asset type; - const char* path; - /* Bits per component, set to zero if you don't want to change the format. */ - i32 bpc; -} Asset_TextureSpec; - -typedef struct { - enum Asset type; - const char* path; -} Asset_ModelSpec; - -typedef union { - enum Asset type; - Asset_AudioSpec audio; - Asset_FontSpec font; - Asset_ShaderSpec shader; - Asset_ShaderProgramSpec shaderprog; - Asset_TextureSpec texture; - Asset_ModelSpec model; -} asset_t; - -#include <engine/resources/model.h> - -// The resource spec -typedef struct { - /* Assorted asset specification, makes reloading them easier. */ - usize assets_len; - asset_t* assets; - - /* Translation from `assets`'s indices to type-specific loaded assets: */ - usize* get; // Let r=Resources, then use as: `r.shader[ r.get[ MyShader ] ]` - - /* Loaded assets */ - usize shader_len; - Shader* shader; - - usize texture_len; - Texture* texture; - - usize model_len; - Model* model; -} Resources; - -#define TextureDefinition(_path, ...) unimplemented -#define Resource_AudioDefinition(_path, ...) unimplemented -#define Declare_Shader(PATH) (const asset_t){.shader = {.type = Asset_shader, .path=PATH}} -#define Declare_ShaderProgram(SHADERS, NUMSHADERS) (const asset_t){.shaderprog = {.type = Asset_shaderprog, .shader=SHADERS, .shader_len=NUMSHADERS}} -#define Declare_Texture(PATH) (const asset_t){.texture = {.type = Asset_texture, .path=PATH, .bpc=0}} - -void* get_asset(Resources* r, u32 idx); - -/* Each of resource_load_font, resource_load_texture, and resource_load_audio - * loads a given resource into the engines memory and returns an identifier. - */ -//isize resource_load_font(Asset_FontSpec font_def); -//isize resource_load_texture(Asset_TextureSpec texture_def); -//isize resource_load_audio(Asset_AudioSpec audio_def); - -// Loads all resources specified in `assets` and populates corresponding -// resources members. -i32 resources_load(Resources *resources); - -/* Makes a resource globally available. This must be called **BEFORE** any call - * to `engine_run` */ -isize resource_make_global(isize resource_id); - -#include <engine/resources/texture.h> - -#ifdef __cplusplus -} -#endif -#endif |
