diff options
author | 3gg <3gg@shellblade.net> | 2025-06-27 10:18:39 -0700 |
---|---|---|
committer | 3gg <3gg@shellblade.net> | 2025-06-27 10:18:39 -0700 |
commit | bd57f345ed9dbed1d81683e48199626de2ea9044 (patch) | |
tree | 4221f2f2a7ad2244d2e93052bd68187ec91b8ea9 /include/gfx/asset.h | |
parent | 9a82ce0083437a4f9f58108b2c23b957d2249ad8 (diff) |
Restructure project
Diffstat (limited to 'include/gfx/asset.h')
-rw-r--r-- | include/gfx/asset.h | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/include/gfx/asset.h b/include/gfx/asset.h new file mode 100644 index 0000000..caf40c1 --- /dev/null +++ b/include/gfx/asset.h | |||
@@ -0,0 +1,99 @@ | |||
1 | /* Asset Management */ | ||
2 | #pragma once | ||
3 | |||
4 | #include <gfx/core.h> | ||
5 | |||
6 | #include <stddef.h> | ||
7 | |||
8 | typedef struct Gfx Gfx; | ||
9 | typedef struct Model Model; | ||
10 | typedef struct ShaderProgram ShaderProgram; | ||
11 | typedef struct Texture Texture; | ||
12 | |||
13 | /// Describes where the asset comes from. | ||
14 | typedef enum AssetOrigin { | ||
15 | AssetFromMemory, | ||
16 | AssetFromFile, | ||
17 | } AssetOrigin; | ||
18 | |||
19 | /// Describes a texture's colour space. | ||
20 | typedef enum TextureColourSpace { | ||
21 | sRGB, // The most likely default. | ||
22 | LinearColourSpace, | ||
23 | } TextureColourSpace; | ||
24 | |||
25 | /// Describes a command to load a texture. | ||
26 | typedef struct LoadTextureCmd { | ||
27 | AssetOrigin origin; | ||
28 | enum { LoadTexture, LoadCubemap } type; | ||
29 | TextureColourSpace colour_space; | ||
30 | TextureFiltering filtering; | ||
31 | TextureWrapping wrap; | ||
32 | bool mipmaps; | ||
33 | union { | ||
34 | // A single texture. | ||
35 | struct { | ||
36 | union { | ||
37 | struct { | ||
38 | mstring filepath; | ||
39 | }; | ||
40 | struct { | ||
41 | const void* data; | ||
42 | size_t size_bytes; | ||
43 | }; | ||
44 | }; | ||
45 | } texture; | ||
46 | // Cubemap texture. | ||
47 | struct { | ||
48 | union { | ||
49 | struct { | ||
50 | mstring filepath_pos_x; | ||
51 | mstring filepath_neg_x; | ||
52 | mstring filepath_pos_y; | ||
53 | mstring filepath_neg_y; | ||
54 | mstring filepath_pos_z; | ||
55 | mstring filepath_neg_z; | ||
56 | } filepaths; | ||
57 | struct { | ||
58 | const void* data_pos_x; | ||
59 | const void* data_neg_x; | ||
60 | const void* data_pos_y; | ||
61 | const void* data_neg_y; | ||
62 | const void* data_pos_z; | ||
63 | const void* data_neg_z; | ||
64 | } buffers; | ||
65 | }; | ||
66 | } cubemap; | ||
67 | } data; | ||
68 | } LoadTextureCmd; | ||
69 | |||
70 | /// Describes a command to load a model. | ||
71 | /// | ||
72 | /// |shader| is an optional shader program assigned to the loaded model objects. | ||
73 | /// If no shader is given, a Cook-Torrance shader based on the object's | ||
74 | /// characteristics (presence of normals, tangents, etc) is assigned. | ||
75 | typedef struct LoadModelCmd { | ||
76 | AssetOrigin origin; | ||
77 | union { | ||
78 | struct { | ||
79 | mstring filepath; | ||
80 | }; | ||
81 | struct { | ||
82 | const void* data; | ||
83 | size_t size_bytes; | ||
84 | }; | ||
85 | }; | ||
86 | ShaderProgram* shader; | ||
87 | } LoadModelCmd; | ||
88 | |||
89 | /// Load a model. | ||
90 | /// | ||
91 | /// For animated models, this function returns a (shallow) clone of the model | ||
92 | /// that is safe to mutate. For static models, this returns the original model | ||
93 | /// in the cache. | ||
94 | /// | ||
95 | /// Currently only supports the GLTF format. | ||
96 | Model* gfx_load_model(Gfx*, const LoadModelCmd*); | ||
97 | |||
98 | /// Load a texture. | ||
99 | const Texture* gfx_load_texture(Gfx*, const LoadTextureCmd*); | ||