1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
#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,
};
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;
i32 width;
i32 height;
} Asset_TextureSpec;
typedef union {
enum Asset type;
Asset_AudioSpec audio;
Asset_FontSpec font;
Asset_ShaderSpec shader;
Asset_ShaderProgramSpec shaderprog;
Asset_TextureSpec texture;
} asset_t;
// 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;
} 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}}
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
|