From 538d3a7dcb95a4d03dcb3cd55623923d8f39a4ba Mon Sep 17 00:00:00 2001 From: connellpaxton Date: Tue, 30 Jan 2024 08:50:11 -0500 Subject: [PATCH] made a model overload for cmd->bind(), added FPS counter to screen --- Model/Model.cpp | 1 - Renderer/CommandBuffer.cpp | 7 +++++++ Renderer/CommandBuffer.hpp | 2 ++ Renderer/Renderer.cpp | 5 +++-- UI/UI.cpp | 2 +- UI/UI.hpp | 4 ++++ pléascach.cpp | 3 ++- 7 files changed, 19 insertions(+), 5 deletions(-) diff --git a/Model/Model.cpp b/Model/Model.cpp index f3f0d88..ecf9a52 100644 --- a/Model/Model.cpp +++ b/Model/Model.cpp @@ -43,7 +43,6 @@ Model::Model(vk::PhysicalDevice phys_dev, vk::Device dev, const std::string& fna index_buffer = std::make_unique(phys_dev, dev, indices.size()*sizeof(uint16_t), vk::BufferUsageFlagBits::eIndexBuffer, vk::MemoryPropertyFlagBits::eHostCoherent | vk::MemoryPropertyFlagBits::eHostVisible); index_buffer->upload(reinterpret_cast(indices.data()), static_cast(indices.size()*sizeof(uint16_t))); - } void Model::initVertices(Node* node, const tinygltf::Primitive& prim) { diff --git a/Renderer/CommandBuffer.cpp b/Renderer/CommandBuffer.cpp index bf23414..9cc5754 100644 --- a/Renderer/CommandBuffer.cpp +++ b/Renderer/CommandBuffer.cpp @@ -2,6 +2,8 @@ #include #include +#include + #include #include @@ -73,6 +75,11 @@ void CommandBuffer::bind(const VertexBuffer& vertex_buffer, uint32_t binding) { command_buffer.bindVertexBuffers(binding, vertex_buffer.buffer->buffer, offsets); } +void CommandBuffer::bind(std::shared_ptr model) { + bind(*model->vertex_buffer); + command_buffer.bindIndexBuffer(*model->index_buffer, 0, vk::IndexType::eUint16); +} + void CommandBuffer::draw(uint32_t vertex_count, uint32_t instance_count, uint32_t first_vertex, uint32_t first_instance) { command_buffer.draw(vertex_count, instance_count, first_vertex, first_instance); } diff --git a/Renderer/CommandBuffer.hpp b/Renderer/CommandBuffer.hpp index 4a6ea1c..1106546 100644 --- a/Renderer/CommandBuffer.hpp +++ b/Renderer/CommandBuffer.hpp @@ -11,6 +11,7 @@ struct Image; struct GraphicsPipeline; struct ComputePipeline; struct VertexBuffer; +struct Model; struct CommandBuffer { CommandBuffer(vk::Device dev, u32 queue_family); @@ -28,6 +29,7 @@ struct CommandBuffer { void bind(const GraphicsPipeline& pipeline); void bind(vk::PipelineLayout layout, vk::ArrayProxy desc_sets); void bind(const VertexBuffer& vertex_buffer, uint32_t binding = 0); + void bind(std::shared_ptr model); void draw(uint32_t vertex_count, uint32_t instance_count, uint32_t first_vertex = 0, uint32_t first_instance = 0); diff --git a/Renderer/Renderer.cpp b/Renderer/Renderer.cpp index 5603479..a6c745a 100644 --- a/Renderer/Renderer.cpp +++ b/Renderer/Renderer.cpp @@ -313,8 +313,9 @@ void Renderer::draw() { command_buffer->command_buffer.setScissor(0, scissor); - command_buffer->bind(*models[0]->vertex_buffer); - command_buffer->command_buffer.bindIndexBuffer(*models[0]->index_buffer, 0, vk::IndexType::eUint16); + command_buffer->bind(models[0]); + + command_buffer->bind(pipeline->layout, pipeline->desc_set); auto sz = win.getDimensions(); diff --git a/UI/UI.cpp b/UI/UI.cpp index 4331de6..4e72235 100644 --- a/UI/UI.cpp +++ b/UI/UI.cpp @@ -87,7 +87,7 @@ void UI::newFrame() { ImGui::SetNextWindowBgAlpha(0.8f); ImGui::Begin("Rendering Info", nullptr); - ImGui::Text("ImGui Test"); + ImGui::Text("FPS: %f", info.fps); ImGui::End(); } diff --git a/UI/UI.hpp b/UI/UI.hpp index 1992d9b..630de33 100644 --- a/UI/UI.hpp +++ b/UI/UI.hpp @@ -8,6 +8,10 @@ struct Renderer; struct UI { + struct UI_Info { + float fps = 0.0; + } info; + vk::Device dev; vk::DescriptorPool desc_pool; diff --git a/pléascach.cpp b/pléascach.cpp index 75dc39d..32dd45a 100644 --- a/pléascach.cpp +++ b/pléascach.cpp @@ -42,7 +42,8 @@ int main(int argc, char* argv[]) { ren.draw(); ren.present(); - Log::debug("Frame: %.2lf milliseconds (60fps ~ 16.67)\r", frame_timer.read()); + const auto t = frame_timer.read(); + ren.ui->info.fps = 1000.0f / t; while (frame_timer.read() < 16.60) ;