refactor: move all caches to RenderResources object

This commit is contained in:
2026-06-29 04:08:57 +02:00
parent 3bc8ba02e1
commit aa5c497f29
27 changed files with 1187 additions and 692 deletions
+25 -28
View File
@@ -24,7 +24,7 @@
#include "destrum/Util/ModelDocUtils.h"
LightKeeper::LightKeeper() : App(), renderer(meshCache, materialCache)
LightKeeper::LightKeeper() : App()
{
}
@@ -34,8 +34,8 @@ LightKeeper::~LightKeeper()
void LightKeeper::customInit()
{
materialCache.init(gfxDevice);
renderer.init(gfxDevice, m_params.renderSize);
resources.init(gfxDevice);
renderer.init(gfxDevice, resources, m_params.renderSize);
const float aspectRatio = static_cast<float>(m_params.renderSize.x) / static_cast<float>(m_params.renderSize.y);
camera.setAspectRatio(aspectRatio);
@@ -56,7 +56,7 @@ void LightKeeper::customInit()
auto testMesh = kittyPrimitive.mesh;
testMesh.name = "Test Mesh";
auto testMeshID = meshCache.addMesh(gfxDevice, testMesh);
auto testMeshID = resources.meshes().addMesh(gfxDevice, testMesh);
spdlog::info("TestMesh uploaded with id: {}", testMeshID);
const auto testTexturePath = ModelDocUtils::PickTexturePath(
@@ -65,10 +65,10 @@ void LightKeeper::customInit()
AssetFS::GetInstance().GetFullPath("game://kitty.png")
);
const auto testimgID = gfxDevice.loadImageFromFile(testTexturePath);
const auto testimgID = resources.loadImageFromFile(gfxDevice, testTexturePath);
spdlog::info("Test image loaded from '{}' with id: {}", testTexturePath.generic_string(), testimgID);
auto testMaterialID = materialCache.addMaterial(gfxDevice, {
auto testMaterialID = resources.materials().addMaterial({
.baseColor = ModelDocUtils::GetImportedBaseColor(
kittyModel, kittyPrimitive),
.diffuseTexture = testimgID,
@@ -93,9 +93,9 @@ void LightKeeper::customInit()
const auto fragShaderPath = AssetFS::GetInstance().GetCookedPathForFile("engine://shaders/cubemap.frag");
//
skyboxCubemap = std::make_unique<CubeMap>();
skyboxCubemap->LoadCubeMap(skyboxID.generic_string());
skyboxCubemap->InitCubemapPipeline(vertShaderPath.generic_string(), fragShaderPath.generic_string());
skyboxCubemap->CreateCubeMap();
skyboxCubemap->LoadCubeMap(gfxDevice, resources, skyboxID.generic_string());
skyboxCubemap->InitCubemapPipeline(gfxDevice, resources, vertShaderPath.generic_string(), fragShaderPath.generic_string());
skyboxCubemap->CreateCubeMap(gfxDevice, resources);
renderer.setSkyboxTexture(skyboxCubemap->GetCubeMapImageID());
@@ -109,7 +109,7 @@ void LightKeeper::customInit()
ModelDocUtils::LogModelDocSummary(planeModel, "plane.glb");
const auto& planePrimitive = ModelDocUtils::GetFirstPrimitiveOrThrow(planeModel, "game://plane.glb");
const auto planeMeshID = meshCache.addMesh(gfxDevice, planePrimitive.mesh);
const auto planeMeshID = resources.meshes().addMesh(gfxDevice, planePrimitive.mesh);
const auto planeTexturePath = ModelDocUtils::PickTexturePath(
planeModel,
@@ -117,8 +117,8 @@ void LightKeeper::customInit()
AssetFS::GetInstance().GetFullPath("game://grass.png")
);
const auto planeTextureID = gfxDevice.loadImageFromFile(planeTexturePath);
const auto planeMaterialID = materialCache.addMaterial(gfxDevice, {
const auto planeTextureID = resources.loadImageFromFile(gfxDevice, planeTexturePath);
const auto planeMaterialID = resources.materials().addMaterial({
.baseColor = ModelDocUtils::GetImportedBaseColor(
planeModel, planePrimitive),
.textureFilteringMode = TextureFilteringMode::Nearest,
@@ -157,7 +157,7 @@ void LightKeeper::customInit()
"engine://cotw-capybara-male/source/capybara.fbx"
);
const auto charMeshID = meshCache.addMesh(gfxDevice, charPrimitive.mesh);
const auto charMeshID = resources.meshes().addMesh(gfxDevice, charPrimitive.mesh);
const auto charTexturePath = ModelDocUtils::PickTexturePath(
charModel,
@@ -166,9 +166,9 @@ void LightKeeper::customInit()
"engine://cotw-capybara-male/textures/capybara_male_light_brown_dif.ddsc.DECA.RE.pngballs")
);
const auto charTextureID = gfxDevice.loadImageFromFile(charTexturePath);
const auto charTextureID = resources.loadImageFromFile(gfxDevice, charTexturePath);
// const auto charTextureID = gfxDevice.loadImageFromFile(AssetFS::GetInstance().GetFullPath("engine://char.jpg"));
const auto charMaterialID = materialCache.addMaterial(gfxDevice, {
const auto charMaterialID = resources.materials().addMaterial({
.baseColor = ModelDocUtils::GetImportedBaseColor(
charModel, charPrimitive),
.diffuseTexture = charTextureID,
@@ -282,13 +282,13 @@ void LightKeeper::customInit()
"engine://characterMedium.fbx"
);
const auto charMeshID = meshCache.addMesh(gfxDevice, charPrimitive.mesh);
const auto charMeshID = resources.meshes().addMesh(gfxDevice, charPrimitive.mesh);
const auto charTextureID = gfxDevice.loadImageFromFile(
const auto charTextureID = resources.loadImageFromFile(gfxDevice,
AssetFS::GetInstance().GetFullPath("engine://textures/criminalMaleA.png")
);
const auto charMaterialID = materialCache.addMaterial(gfxDevice, {
const auto charMaterialID = resources.materials().addMaterial({
.baseColor = ModelDocUtils::GetImportedBaseColor(
charModel, charPrimitive),
.diffuseTexture = charTextureID,
@@ -345,8 +345,8 @@ void LightKeeper::customInit()
AssetFS::GetInstance().GetFullPath("game://grass.png")
);
const auto eliasTextueID = gfxDevice.loadImageFromFile(eliasTextuerPath);
const auto eliasMaterialID = materialCache.addMaterial(gfxDevice, {
const auto eliasTextueID = resources.loadImageFromFile(gfxDevice, eliasTextuerPath);
const auto eliasMaterialID = resources.materials().addMaterial({
.baseColor = ModelDocUtils::GetImportedBaseColor(
planeModel, planePrimitive),
.textureFilteringMode =
@@ -356,7 +356,7 @@ void LightKeeper::customInit()
planeModel, planePrimitive, "GroundPlaneMaterial"),
});
const auto cubeMeshID = meshCache.addMesh(gfxDevice, cubePrimitive.mesh);
const auto cubeMeshID = resources.meshes().addMesh(gfxDevice, cubePrimitive.mesh);
//
// for (int i{0}; i < 100; i++)
// {
@@ -425,8 +425,8 @@ void LightKeeper::customInit()
AssetFS::GetInstance().GetFullPath("game://238882.png")
);
const auto sphereTextureID = gfxDevice.loadImageFromFile(sphereTexturePath);
sphereMaterial = materialCache.addMaterial(gfxDevice, {
const auto sphereTextureID = resources.loadImageFromFile(gfxDevice, sphereTexturePath);
sphereMaterial = resources.materials().addMaterial({
.baseColor = ModelDocUtils::GetImportedBaseColor(planeModel, planePrimitive),
.textureFilteringMode =TextureFilteringMode::Anisotropic,
.diffuseTexture = sphereTextureID,
@@ -435,7 +435,7 @@ void LightKeeper::customInit()
"GroundPlaneMaterial"),
});
sphereMesh = meshCache.addMesh(gfxDevice, spherePrimitive.mesh);
sphereMesh = resources.meshes().addMesh(gfxDevice, spherePrimitive.mesh);
}
}
@@ -491,7 +491,7 @@ void LightKeeper::customDraw()
renderer.endDrawing();
const auto cmd = gfxDevice.beginFrame();
const auto& drawImage = renderer.getDrawImage(gfxDevice);
const auto& drawImage = renderer.getDrawImage();
renderer.draw(
cmd, gfxDevice, camera, GameRenderer::SceneData{
@@ -520,9 +520,6 @@ void LightKeeper::customCleanup()
}
renderer.cleanup(gfxDevice);
materialCache.cleanup(gfxDevice);
meshCache.cleanup(gfxDevice);
}
void LightKeeper::customFixedUpdate(float dt)