asset_manager concept

This commit is contained in:
2026-09-09 11:36:07 -07:00
parent 9aef3f57fc
commit 4190ff847b
14 changed files with 525 additions and 12 deletions
+40 -1
View File
@@ -183,7 +183,16 @@ class Application::Impl {
commandBuffer.setViewport(0, viewport);
commandBuffer.setScissor(0, scissor);
modelRenderSystem.render(commandBuffer, this->meshes, frameInfo);
std::vector<ModelRenderSystem::MeshInstance> instances;
instances.reserve(this->meshes.size() + this->drawCalls.size());
for (const std::unique_ptr<Mesh>& mesh : this->meshes) {
instances.push_back({mesh.get(), glm::mat4{1.f}});
}
instances.insert(instances.end(), this->drawCalls.begin(),
this->drawCalls.end());
modelRenderSystem.render(commandBuffer, instances, frameInfo);
this->drawCalls.clear();
commandBuffer.endRendering();
@@ -224,6 +233,25 @@ class Application::Impl {
this->meshes.clear();
}
MeshHandle createMesh(std::vector<CanvasVertex> vertices,
std::vector<u32> indices) {
Mesh::Builder builder{};
builder.vertices.reserve(vertices.size());
for (const CanvasVertex& vertex : vertices) {
builder.vertices.push_back({vertex.position, vertex.color});
}
builder.indices = std::move(indices);
this->persistentMeshes.push_back(
std::make_unique<Mesh>(this->device, builder));
return static_cast<MeshHandle>(this->persistentMeshes.size() - 1);
}
void drawMesh(MeshHandle handle, const glm::mat4& transform) {
this->drawCalls.push_back(
{this->persistentMeshes[handle].get(), transform});
}
private:
Application& application;
const Application::Config config;
@@ -232,6 +260,8 @@ class Application::Impl {
RenderContext renderContext;
std::vector<std::unique_ptr<Mesh>> meshes;
std::vector<std::unique_ptr<Mesh>> persistentMeshes;
std::vector<ModelRenderSystem::MeshInstance> drawCalls;
};
void Application::setCommandLineArgs(int argc, const char* const* argv) {
@@ -254,4 +284,13 @@ void Application::pushMesh(std::vector<CanvasVertex> vertices,
void Application::clearMeshes() { impl->clearMeshes(); }
MeshHandle Application::createMesh(std::vector<CanvasVertex> vertices,
std::vector<u32> indices) {
return impl->createMesh(std::move(vertices), std::move(indices));
}
void Application::drawMesh(MeshHandle handle, const glm::mat4& transform) {
impl->drawMesh(handle, transform);
}
} // namespace sophia