From c78954d80d27c2fac7fe24e3c4e7766408706c48 Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Sat, 17 Feb 2024 13:16:11 -0800 Subject: Asset cache returns const Texture. --- CMakeLists.txt | 2 ++ game/src/plugins/texture_view.c | 14 +++++++------- game/src/plugins/viewer.c | 4 ++-- gfx/include/gfx/asset.h | 2 +- gfx/src/asset/asset_cache.c | 4 ++-- gfx/src/asset/asset_cache.h | 4 ++-- 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 @@ cmake_minimum_required(VERSION 3.0) +project(gfx-all) + add_subdirectory(gfx) add_subdirectory(gfx-app) add_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) { RenderBackend* render_backend = gfx_get_render_backend(game->gfx); - Texture* texture = gfx_load_texture( - render_backend, &(LoadTextureCmd){ - .origin = TextureFromFile, - .type = LoadTexture, - .filtering = LinearFiltering, - .mipmaps = false, - .data.texture.filepath = mstring_make(texture_file)}); + const Texture* texture = gfx_load_texture( + game->gfx, &(LoadTextureCmd){ + .origin = AssetFromFile, + .type = LoadTexture, + .filtering = LinearFiltering, + .mipmaps = false, + .data.texture.filepath = mstring_make(texture_file)}); if (!texture) { goto cleanup; } 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 { }; /// Load the skyquad texture. -static Texture* load_environment_map(Gfx* gfx) { +static const Texture* load_environment_map(Gfx* gfx) { assert(gfx); return gfx_load_texture( gfx, &(LoadTextureCmd){ @@ -56,7 +56,7 @@ static SceneNode* load_skyquad(Gfx* gfx, SceneNode* root) { RenderBackend* render_backend = gfx_get_render_backend(gfx); - Texture* environment_map = load_environment_map(gfx); + const Texture* environment_map = load_environment_map(gfx); if (!environment_map) { return 0; } 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 { Model* gfx_load_model(Gfx*, const LoadModelCmd*); /// Load a texture. -Texture* gfx_load_texture(Gfx*, const LoadTextureCmd*); +const 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) { return model; } -Texture* gfx_load_texture(Gfx* gfx, const LoadTextureCmd* cmd) { +const Texture* gfx_load_texture(Gfx* gfx, const LoadTextureCmd* cmd) { assert(gfx); assert(cmd); @@ -155,7 +155,7 @@ Texture* gfx_load_texture(Gfx* gfx, const LoadTextureCmd* cmd) { // Asset not found in the cache. // Load it, insert it into the cache, and return it. RenderBackend* render_backend = gfx_get_render_backend(gfx); - Texture* texture = gfx_texture_load(render_backend, cmd); + const Texture* texture = gfx_texture_load(render_backend, cmd); if (texture) { *(Asset*)mempool_alloc(&cache->assets) = (Asset){ .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 { AssetType type; Hash hash; union { - Model* model; - Texture* texture; + Model* model; + const Texture* texture; }; } Asset; -- cgit v1.2.3