diff options
Diffstat (limited to 'gfx/src/asset/asset_cache.c')
-rw-r--r-- | gfx/src/asset/asset_cache.c | 53 |
1 files changed, 52 insertions, 1 deletions
diff --git a/gfx/src/asset/asset_cache.c b/gfx/src/asset/asset_cache.c index 0a9b1f2..1d64d66 100644 --- a/gfx/src/asset/asset_cache.c +++ b/gfx/src/asset/asset_cache.c | |||
@@ -13,8 +13,54 @@ | |||
13 | #include <gfx_assert.h> | 13 | #include <gfx_assert.h> |
14 | 14 | ||
15 | #include <cstring.h> | 15 | #include <cstring.h> |
16 | #include <error.h> | ||
16 | #include <log/log.h> | 17 | #include <log/log.h> |
17 | 18 | ||
19 | static void log_model_load_failure(const LoadModelCmd* cmd) { | ||
20 | assert(cmd); | ||
21 | |||
22 | switch (cmd->origin) { | ||
23 | case AssetFromFile: | ||
24 | log_error("Failed to load model: %s", mstring_cstr(&cmd->filepath)); | ||
25 | break; | ||
26 | case AssetFromMemory: | ||
27 | log_error("Failed to load model: %p", cmd->data); | ||
28 | break; | ||
29 | } | ||
30 | } | ||
31 | |||
32 | static void log_texture_load_failure(const LoadTextureCmd* cmd) { | ||
33 | assert(cmd); | ||
34 | |||
35 | switch (cmd->origin) { | ||
36 | case AssetFromFile: | ||
37 | switch (cmd->type) { | ||
38 | case LoadTexture: | ||
39 | log_error( | ||
40 | "Failed to load texture: %s", | ||
41 | mstring_cstr(&cmd->data.texture.filepath)); | ||
42 | break; | ||
43 | case LoadCubemap: | ||
44 | log_error( | ||
45 | "Failed to load cubemap texture: %s", | ||
46 | mstring_cstr(&cmd->data.cubemap.filepaths.filepath_pos_x)); | ||
47 | break; | ||
48 | } | ||
49 | break; | ||
50 | case AssetFromMemory: | ||
51 | switch (cmd->type) { | ||
52 | case LoadTexture: | ||
53 | log_error("Failed to load texture: %p", cmd->data.texture.data); | ||
54 | break; | ||
55 | case LoadCubemap: | ||
56 | log_error( | ||
57 | "Failed to load texture: %p", cmd->data.cubemap.buffers.data_pos_x); | ||
58 | break; | ||
59 | } | ||
60 | break; | ||
61 | } | ||
62 | } | ||
63 | |||
18 | static Hash calc_model_hash(const LoadModelCmd* cmd) { | 64 | static Hash calc_model_hash(const LoadModelCmd* cmd) { |
19 | assert(cmd); | 65 | assert(cmd); |
20 | switch (cmd->origin) { | 66 | switch (cmd->origin) { |
@@ -166,8 +212,11 @@ Model* gfx_load_model(Gfx* gfx, const LoadModelCmd* cmd) { | |||
166 | .model = model, | 212 | .model = model, |
167 | }; | 213 | }; |
168 | log_model_loaded(cmd); | 214 | log_model_loaded(cmd); |
215 | return clone_model(model); | ||
216 | } else { | ||
217 | log_model_load_failure(cmd); | ||
218 | return 0; | ||
169 | } | 219 | } |
170 | return clone_model(model); | ||
171 | } | 220 | } |
172 | 221 | ||
173 | const Texture* gfx_load_texture(Gfx* gfx, const LoadTextureCmd* cmd) { | 222 | const Texture* gfx_load_texture(Gfx* gfx, const LoadTextureCmd* cmd) { |
@@ -193,6 +242,8 @@ const Texture* gfx_load_texture(Gfx* gfx, const LoadTextureCmd* cmd) { | |||
193 | .hash = hash, | 242 | .hash = hash, |
194 | .texture = texture, | 243 | .texture = texture, |
195 | }; | 244 | }; |
245 | } else { | ||
246 | log_texture_load_failure(cmd); | ||
196 | } | 247 | } |
197 | return texture; | 248 | return texture; |
198 | } | 249 | } |