made a model overload for cmd->bind(), added FPS counter to screen

This commit is contained in:
connellpaxton 2024-01-30 08:50:11 -05:00
parent 384c393e16
commit 538d3a7dcb
7 changed files with 19 additions and 5 deletions

View File

@ -43,7 +43,6 @@ Model::Model(vk::PhysicalDevice phys_dev, vk::Device dev, const std::string& fna
index_buffer = std::make_unique<Buffer>(phys_dev, dev, indices.size()*sizeof(uint16_t),
vk::BufferUsageFlagBits::eIndexBuffer, vk::MemoryPropertyFlagBits::eHostCoherent | vk::MemoryPropertyFlagBits::eHostVisible);
index_buffer->upload(reinterpret_cast<uint8_t*>(indices.data()), static_cast<vk::DeviceSize>(indices.size()*sizeof(uint16_t)));
}
void Model::initVertices(Node* node, const tinygltf::Primitive& prim) {

View File

@ -2,6 +2,8 @@
#include <Renderer/Pipeline.hpp>
#include <Renderer/VertexBuffer.hpp>
#include <Model/Model.hpp>
#include <Memory/Buffer.hpp>
#include <Memory/Image.hpp>
@ -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> 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);
}

View File

@ -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<vk::DescriptorSet> desc_sets);
void bind(const VertexBuffer& vertex_buffer, uint32_t binding = 0);
void bind(std::shared_ptr<Model> model);
void draw(uint32_t vertex_count, uint32_t instance_count, uint32_t first_vertex = 0, uint32_t first_instance = 0);

View File

@ -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();

View File

@ -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();
}

View File

@ -8,6 +8,10 @@
struct Renderer;
struct UI {
struct UI_Info {
float fps = 0.0;
} info;
vk::Device dev;
vk::DescriptorPool desc_pool;

View File

@ -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)
;