summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author3gg <3gg@shellblade.net>2024-02-17 13:16:11 -0800
committer3gg <3gg@shellblade.net>2024-02-17 13:16:11 -0800
commitc78954d80d27c2fac7fe24e3c4e7766408706c48 (patch)
tree8a54daadd6e93ddd57e4075995a70b32926d4954
parent7b756cc336f076fe95deb59847492b4127f82132 (diff)
Asset cache returns const Texture.
-rw-r--r--CMakeLists.txt2
-rw-r--r--game/src/plugins/texture_view.c14
-rw-r--r--game/src/plugins/viewer.c4
-rw-r--r--gfx/include/gfx/asset.h2
-rw-r--r--gfx/src/asset/asset_cache.c4
-rw-r--r--gfx/src/asset/asset_cache.h4
6 files changed, 16 insertions, 14 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6ec4a34..27e4bd6 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,5 +1,7 @@
1cmake_minimum_required(VERSION 3.0) 1cmake_minimum_required(VERSION 3.0)
2 2
3project(gfx-all)
4
3add_subdirectory(gfx) 5add_subdirectory(gfx)
4add_subdirectory(gfx-app) 6add_subdirectory(gfx-app)
5add_subdirectory(gfx-iso) 7add_subdirectory(gfx-iso)
diff --git a/game/src/plugins/texture_view.c b/game/src/plugins/texture_view.c
index fda62db..b624f46 100644
--- a/game/src/plugins/texture_view.c
+++ b/game/src/plugins/texture_view.c
@@ -35,13 +35,13 @@ bool init(Game* game, State** pp_state) {
35 35
36 RenderBackend* render_backend = gfx_get_render_backend(game->gfx); 36 RenderBackend* render_backend = gfx_get_render_backend(game->gfx);
37 37
38 Texture* texture = gfx_load_texture( 38 const Texture* texture = gfx_load_texture(
39 render_backend, &(LoadTextureCmd){ 39 game->gfx, &(LoadTextureCmd){
40 .origin = TextureFromFile, 40 .origin = AssetFromFile,
41 .type = LoadTexture, 41 .type = LoadTexture,
42 .filtering = LinearFiltering, 42 .filtering = LinearFiltering,
43 .mipmaps = false, 43 .mipmaps = false,
44 .data.texture.filepath = mstring_make(texture_file)}); 44 .data.texture.filepath = mstring_make(texture_file)});
45 if (!texture) { 45 if (!texture) {
46 goto cleanup; 46 goto cleanup;
47 } 47 }
diff --git a/game/src/plugins/viewer.c b/game/src/plugins/viewer.c
index dd7f451..c58b0e0 100644
--- a/game/src/plugins/viewer.c
+++ b/game/src/plugins/viewer.c
@@ -30,7 +30,7 @@ struct State {
30}; 30};
31 31
32/// Load the skyquad texture. 32/// Load the skyquad texture.
33static Texture* load_environment_map(Gfx* gfx) { 33static const Texture* load_environment_map(Gfx* gfx) {
34 assert(gfx); 34 assert(gfx);
35 return gfx_load_texture( 35 return gfx_load_texture(
36 gfx, &(LoadTextureCmd){ 36 gfx, &(LoadTextureCmd){
@@ -56,7 +56,7 @@ static SceneNode* load_skyquad(Gfx* gfx, SceneNode* root) {
56 56
57 RenderBackend* render_backend = gfx_get_render_backend(gfx); 57 RenderBackend* render_backend = gfx_get_render_backend(gfx);
58 58
59 Texture* environment_map = load_environment_map(gfx); 59 const Texture* environment_map = load_environment_map(gfx);
60 if (!environment_map) { 60 if (!environment_map) {
61 return 0; 61 return 0;
62 } 62 }
diff --git a/gfx/include/gfx/asset.h b/gfx/include/gfx/asset.h
index c5cc5f8..9845b03 100644
--- a/gfx/include/gfx/asset.h
+++ b/gfx/include/gfx/asset.h
@@ -100,4 +100,4 @@ typedef struct LoadModelCmd {
100Model* gfx_load_model(Gfx*, const LoadModelCmd*); 100Model* gfx_load_model(Gfx*, const LoadModelCmd*);
101 101
102/// Load a texture. 102/// Load a texture.
103Texture* gfx_load_texture(Gfx*, const LoadTextureCmd*); 103const Texture* gfx_load_texture(Gfx*, const LoadTextureCmd*);
diff --git a/gfx/src/asset/asset_cache.c b/gfx/src/asset/asset_cache.c
index 037f62b..0320954 100644
--- a/gfx/src/asset/asset_cache.c
+++ b/gfx/src/asset/asset_cache.c
@@ -139,7 +139,7 @@ Model* gfx_load_model(Gfx* gfx, const LoadModelCmd* cmd) {
139 return model; 139 return model;
140} 140}
141 141
142Texture* gfx_load_texture(Gfx* gfx, const LoadTextureCmd* cmd) { 142const Texture* gfx_load_texture(Gfx* gfx, const LoadTextureCmd* cmd) {
143 assert(gfx); 143 assert(gfx);
144 assert(cmd); 144 assert(cmd);
145 145
@@ -155,7 +155,7 @@ Texture* gfx_load_texture(Gfx* gfx, const LoadTextureCmd* cmd) {
155 // Asset not found in the cache. 155 // Asset not found in the cache.
156 // Load it, insert it into the cache, and return it. 156 // Load it, insert it into the cache, and return it.
157 RenderBackend* render_backend = gfx_get_render_backend(gfx); 157 RenderBackend* render_backend = gfx_get_render_backend(gfx);
158 Texture* texture = gfx_texture_load(render_backend, cmd); 158 const Texture* texture = gfx_texture_load(render_backend, cmd);
159 if (texture) { 159 if (texture) {
160 *(Asset*)mempool_alloc(&cache->assets) = (Asset){ 160 *(Asset*)mempool_alloc(&cache->assets) = (Asset){
161 .type = TextureAsset, 161 .type = TextureAsset,
diff --git a/gfx/src/asset/asset_cache.h b/gfx/src/asset/asset_cache.h
index 22300fd..b2a35ed 100644
--- a/gfx/src/asset/asset_cache.h
+++ b/gfx/src/asset/asset_cache.h
@@ -19,8 +19,8 @@ typedef struct Asset {
19 AssetType type; 19 AssetType type;
20 Hash hash; 20 Hash hash;
21 union { 21 union {
22 Model* model; 22 Model* model;
23 Texture* texture; 23 const Texture* texture;
24 }; 24 };
25} Asset; 25} Asset;
26 26