From 12e64d7ce0518f9ee4ad7df9479153bb2846b085 Mon Sep 17 00:00:00 2001 From: "HuYingzhuo(hugo/hyzboy)" Date: Sat, 6 May 2023 19:29:38 +0800 Subject: [PATCH] added BindVBO and BindIBO functions at VKCommandBuffer.h/.cpp --- inc/hgl/graph/VKCommandBuffer.h | 7 +++++ .../Vulkan/VKCommandBufferRender.cpp | 30 +++++++++---------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/inc/hgl/graph/VKCommandBuffer.h b/inc/hgl/graph/VKCommandBuffer.h index 92e211e2..9ffa22e0 100644 --- a/inc/hgl/graph/VKCommandBuffer.h +++ b/inc/hgl/graph/VKCommandBuffer.h @@ -155,6 +155,13 @@ public: void PushConstants(const void *data,const uint32_t size) {vkCmdPushConstants(cmd_buf,pipeline_layout,VK_SHADER_STAGE_VERTEX_BIT,0, size,data);} void PushConstants(const void *data,const uint32_t offset,const uint32_t size) {vkCmdPushConstants(cmd_buf,pipeline_layout,VK_SHADER_STAGE_VERTEX_BIT,offset, size,data);} + void BindVBO(const uint32_t first,const uint32_t count,const VkBuffer *vbo,const VkDeviceSize *offsets) + { + vkCmdBindVertexBuffers(cmd_buf,first,count,vbo,offsets); + } + + void BindIBO(const IndexBufferData *); + bool BindVBO(Renderable *); void SetViewport (uint32_t first,uint32_t count,const VkViewport *vp) {vkCmdSetViewport(cmd_buf,first,count,vp);} diff --git a/src/SceneGraph/Vulkan/VKCommandBufferRender.cpp b/src/SceneGraph/Vulkan/VKCommandBufferRender.cpp index 4feff48e..91881065 100644 --- a/src/SceneGraph/Vulkan/VKCommandBufferRender.cpp +++ b/src/SceneGraph/Vulkan/VKCommandBufferRender.cpp @@ -133,32 +133,30 @@ bool RenderCmdBuffer::BindDescriptorSets(Renderable *ri) return(true); } +void RenderCmdBuffer::BindIBO(const IndexBufferData *ibd) +{ + vkCmdBindIndexBuffer( cmd_buf, + ibd->buffer->GetBuffer(), + ibd->offset, + VkIndexType(ibd->buffer->GetType())); +} + bool RenderCmdBuffer::BindVBO(Renderable *ri) { if(!ri) return(false); - uint count=0; + const VertexInputData *vid=ri->GetVertexInputData(); - ENUM_CLASS_FOR(VertexInputGroup,uint,i) - { - const VertexInputData *vid=ri->GetVertexInputData(VertexInputGroup(i)); - - if(vid->binding_count<=0) - continue; - - vkCmdBindVertexBuffers(cmd_buf,vid->first_binding,vid->binding_count,vid->buffer_list,vid->buffer_offset); - - count+=vid->binding_count; - } - - if(count==0) + if(vid->binding_count<=0) return(false); - IndexBuffer *indices_buffer=ri->GetIndexBuffer(); + vkCmdBindVertexBuffers(cmd_buf,0,vid->binding_count,vid->buffer_list,vid->buffer_offset); + + IndexBuffer *indices_buffer=vid->index_buffer->buffer; if(indices_buffer) - vkCmdBindIndexBuffer(cmd_buf,indices_buffer->GetBuffer(),ri->GetIndexBufferOffset(),VkIndexType(indices_buffer->GetType())); + vkCmdBindIndexBuffer(cmd_buf,indices_buffer->GetBuffer(),vid->index_buffer->offset,VkIndexType(indices_buffer->GetType())); return(true); }