diff options
author | nathan <nathansmith@disroot.org> | 2025-08-08 18:48:10 +0000 |
---|---|---|
committer | nathan <nathansmith@disroot.org> | 2025-08-08 18:48:10 +0000 |
commit | e5acfb329827802fe2259f91701dc8762c2573b6 (patch) | |
tree | 8d461b2d0e1864633341d066f783172790c62dc9 /src | |
parent | 94ca30b13bffe1f02313b7fd32b2320e5c490fa5 (diff) | |
download | FindThings-e5acfb329827802fe2259f91701dc8762c2573b6.tar.gz FindThings-e5acfb329827802fe2259f91701dc8762c2573b6.tar.bz2 FindThings-e5acfb329827802fe2259f91701dc8762c2573b6.zip |
Mesh instancing test working
Diffstat (limited to 'src')
-rw-r--r-- | src/assets.c | 3 | ||||
-rw-r--r-- | src/assets.h | 7 | ||||
-rw-r--r-- | src/entity.c | 2 | ||||
-rw-r--r-- | src/game.c | 2 | ||||
-rw-r--r-- | src/world.c | 27 | ||||
-rw-r--r-- | src/world.h | 4 |
6 files changed, 35 insertions, 10 deletions
diff --git a/src/assets.c b/src/assets.c index 09388b8..1da7197 100644 --- a/src/assets.c +++ b/src/assets.c @@ -13,7 +13,8 @@ const char imageAssetPaths[IMAGE_ASSET_COUNT][FT_NAMEMAX] = { }; const char shaderAssetNames[SHADER_ASSET_COUNT][FT_NAMEMAX] = { - "skybox" + "skybox", + "instancing" }; const char modelAssetPaths[MODEL_ASSET_COUNT][FT_NAMEMAX] = { diff --git a/src/assets.h b/src/assets.h index 2457115..de849b0 100644 --- a/src/assets.h +++ b/src/assets.h @@ -5,7 +5,7 @@ #define TEXTURE_ASSET_COUNT 5 #define IMAGE_ASSET_COUNT 1 -#define SHADER_ASSET_COUNT 1 +#define SHADER_ASSET_COUNT 2 #define MODEL_ASSET_COUNT 1 extern const char textureAssetPaths[TEXTURE_ASSET_COUNT][FT_NAMEMAX]; @@ -26,12 +26,13 @@ enum { // Image asset ids. enum { - SKYBOX_IMAGE + SKYBOX_IMAGE, }; // Shader asset ids. enum { - SKYBOX_SHADER + SKYBOX_SHADER, + INSTANCING_SHADER }; // Model asset ids. diff --git a/src/entity.c b/src/entity.c index c63acf4..0fb784e 100644 --- a/src/entity.c +++ b/src/entity.c @@ -95,6 +95,8 @@ void updateEntity(Entity* entity, Game* game) /* (Vector3){0.0, UTILITY_POLE_HEIGHT}), */ /* UTILITY_POLE_RADIUS, UTILITY_POLE_RADIUS, */ /* UTILITY_POLE_HEIGHT * 2.0, 6, BROWN); */ + /* DrawModel(game->assets.models[UTILITY_POLE_MODEL], entity->position, 1.0, */ + /* BROWN); */ break; default: break; @@ -30,7 +30,7 @@ void initGame(Game* game) CUBEMAP_LAYOUT_AUTO_DETECT); // World. - game->world = createWorld(345893); + game->world = createWorld(345893, &game->assets); // Player. game->player = createPlayer(); diff --git a/src/world.c b/src/world.c index 828aaa3..a5af6e7 100644 --- a/src/world.c +++ b/src/world.c @@ -473,8 +473,28 @@ Seed generateWorldPlants(World* world, Seed seed, int start, int end) return seed; } -Seed generateWorldUtilityPoles(World* world, Seed seed, int start, int end) +Seed generateWorldUtilityPoles(World* world, const Assets* assets, Seed seed, + int start, int end) { + world->utilityPoleTransforms = (Matrix*)FT_CALLOC(WORLD_UTILITY_POLE_COUNT, + sizeof(Matrix)); + + if (world->utilityPoleTransforms == NULL) + { + ALLOCATION_ERROR; + return seed; + } + + // Instancing shader. + Shader shader = assets->shaders[INSTANCING_SHADER]; + shader.locs[SHADER_LOC_MATRIX_MVP] = GetShaderLocation(shader, "mvp"); + shader.locs[SHADER_LOC_MATRIX_MODEL] = GetShaderLocationAttrib(shader, + "instance"); + shader.locs[SHADER_LOC_MATRIX_VIEW] = GetShaderLocation(shader, "view"); + shader.locs[SHADER_LOC_MATRIX_PROJECTION] = GetShaderLocation(shader, + "projection"); + assets->models[UTILITY_POLE_MODEL].materials[0].shader = shader; + for (int index = start; index < end; ++index) { FT_RANDOM16(seed); @@ -523,7 +543,7 @@ Texture generateGroundTexture() return texture; } -World createWorld(Seed seed) +World createWorld(Seed seed, const Assets* assets) { World world; world.size = WORLD_SIZE; @@ -573,7 +593,7 @@ World createWorld(Seed seed) // Utility poles. start = end; end = WORLD_UTILITY_POLE_COUNT + start; - seed = generateWorldUtilityPoles(&world, seed, start, end); + seed = generateWorldUtilityPoles(&world, assets, seed, start, end); // Items. start = end; @@ -655,6 +675,7 @@ void freeWorld(World world) UnloadTexture( world.heightmap.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture); UnloadModel(world.heightmap); + FT_FREE(world.utilityPoleTransforms); freeWorldBVH(world.bvh); } diff --git a/src/world.h b/src/world.h index fc84ca3..21e4c4c 100644 --- a/src/world.h +++ b/src/world.h @@ -58,12 +58,12 @@ struct World { BVHNode bvh; // Transforms for mesh instancing. - Matrix utilityPoleTransforms[WORLD_UTILITY_POLE_COUNT]; + Matrix* utilityPoleTransforms; int bvhDebugSelect; }; -World createWorld(Seed seed); +World createWorld(Seed seed, const Assets* assets); void updateWorld(World* world, Game* game); void freeWorld(World world); // Dam, I wanta live in a free world ): |