techkaczynski.dev / code

summaryrefslogtreecommitdiff
path: root/res.c
diff options
context:
space:
mode:
authortech kaczynski <tk@techkaczynski.dev>2026-10-22 06:17:20 +1000
committertech kaczynski <tk@techkaczynski.dev>2026-10-22 06:17:20 +1000
commitf5259b6c44b5902a0ca35de113fe16b9275ea13e (patch)
treede42321bd5148bf8c87fc288a8bfd6c26e812bbc /res.c
parent6bdb9fa5f2214f816b4195922b0b2b85f667e364 (diff)
added scene stats to default layout.
Diffstat (limited to 'res.c')
-rw-r--r--res.c32
1 files changed, 26 insertions, 6 deletions
diff --git a/res.c b/res.c
index ef4f2c2..f48ef86 100644
--- a/res.c
+++ b/res.c
@@ -8,6 +8,21 @@ typedef struct {
static Resources res = {0};
+static void
+asset_set_tag(Asset *asset, cstr path) {
+ cstr ext = GetFileExtension(path);
+ if (strcmp(ext, ".glb") == 0) {
+ asset->tag = ASSET_TAG_MODEL;
+ } else if (strcmp(ext, ".png") == 0) {
+ asset->tag = ASSET_TAG_TEXTURE;
+ } else if (strcmp(ext, ".ttf") == 0 ||
+ strcmp(ext, ".otf") == 0) {
+ asset->tag = ASSET_TAG_FONT;
+ } else if (strcmp(ext, ".ogg") == 0) {
+ asset->tag = ASSET_TAG_SOUND;
+ }
+}
+
static bool
asset_load_data(cstr key) {
Asset *asset = map_get(&res.assets, key);
@@ -122,6 +137,7 @@ asset_unload(cstr key) {
}
}
+
void
res_init(void) {
map_init(&res.sdr);
@@ -131,6 +147,10 @@ res_init(void) {
"res/sdr/mdl_vtx_lit.vs",
"res/sdr/mdl_vtx_lit.fs");
+ fun_shader_create("model_cutoff",
+ "res/sdr/mdl_vtx_lit.vs",
+ "res/sdr/mdl_vtx_lit_cutoff.fs");
+
fun_shader_create("sky", NULL, "res/sdr/sky.fs");
cstr filter = ".glb;.png;.ttf;.otf;.ogg";
@@ -139,6 +159,7 @@ res_init(void) {
for (int i = 0; i < res_list.count; ++i) {
cstr path = res_list.paths[i];
Asset asset = {0};
+ asset_set_tag(&asset, path);
asset.path_strlen = strlen(path);
asset.path = strdup(path); // freed in asset_unload
map_set(&res.assets, asset.path, asset);
@@ -175,7 +196,7 @@ res_update(void) {
}
char**
-asset_mdl_keys(int *count) {
+asset_type_keys(AssetTag tag, int *count) {
*count = 0;
if (!res.assets.base.nnodes) {
@@ -184,7 +205,7 @@ asset_mdl_keys(int *count) {
char **keys = malloc(res.assets.base.nnodes * sizeof(*keys));
if (!keys) {
- perror("asset_mdl_keys: mem allocation failed.");
+ perror("asset_type_keys: mem allocation failed.");
exit(1);
}
@@ -192,11 +213,10 @@ asset_mdl_keys(int *count) {
cstr key;
while ((key = map_next(&res.assets, &iter))) {
- if (strcmp(GetFileExtension(key), ".glb") != 0) {
- continue;
+ Asset *asset = map_get(&res.assets, key);
+ if (asset->tag == tag) {
+ keys[(*count)++] = asset->path;
}
-
- keys[(*count)++] = map_get(&res.assets, key)->path;
}
return keys;