VertexInput/CommandBuffer支持IBO

This commit is contained in:
HuYingzhuo 2019-04-25 14:10:18 +08:00
parent 34ae77c8fc
commit df149ee988
3 changed files with 34 additions and 1 deletions

View File

@ -3,6 +3,7 @@
#include"VKFramebuffer.h"
#include"VKPipeline.h"
#include"VKPipelineLayout.h"
#include"VKBuffer.h"
#include"VKVertexInput.h"
#include"VKDescriptorSets.h"
@ -94,6 +95,12 @@ bool CommandBuffer::Bind(VertexInput *vi)
return(false);
vkCmdBindVertexBuffers(cmd_buf,0,count,vi->GetBuffer(),vi->GetOffset());
IndexBuffer *indices_buffer=vi->GetIndexBuffer();
if(indices_buffer)
vkCmdBindIndexBuffer(cmd_buf,*indices_buffer,vi->GetIndexOffset(),indices_buffer->GetType());
return(true);
}
void CommandBuffer::SetDepthBias(float constant_factor,float clamp,float slope_factor)
@ -141,6 +148,16 @@ void CommandBuffer::Draw(const uint32_t vertex_count,const uint32_t instance_cou
vkCmdDraw(cmd_buf,vertex_count,instance_count,first_vertex,first_instance);
}
void CommandBuffer::DrawIndexed(const uint32_t index_count)
{
vkCmdDrawIndexed(cmd_buf,index_count,1,0,0,0);
}
void CommandBuffer::DrawIndexed(const uint32_t index_count,const uint32_t instance_count,const uint32_t first_index,const uint32_t vertex_offset,const uint32_t first_instance)
{
vkCmdDrawIndexed(cmd_buf,index_count,instance_count,first_index,vertex_offset,first_instance);
}
bool CommandBuffer::End()
{
vkCmdEndRenderPass(cmd_buf);

View File

@ -65,6 +65,8 @@ public:
void Draw(const uint32_t vertex_count);
void Draw(const uint32_t vertex_count,const uint32_t instance_count,const uint32_t first_vertex=0,const uint32_t first_instance=0);
void DrawIndexed(const uint32_t index_count);
void DrawIndexed(const uint32_t index_count,const uint32_t instance_count,const uint32_t first_index=0,const uint32_t vertex_offset=0,const uint32_t first_instance=0);
};//class CommandBuffer
VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_COMMAND_BUFFER_INCLUDE

View File

@ -4,6 +4,7 @@
#include"VK.h"
VK_NAMESPACE_BEGIN
class VertexBuffer;
class IndexBuffer;
/**
* OpenGL的VAB<br>
@ -29,19 +30,29 @@ class VertexInput
}
};
ObjectList<VertexInputBuffer> vib_list;
ObjectList<VertexInputBuffer> vib_list;
List<VkBuffer> buf_list;
List<VkDeviceSize> buf_offset;
List<VkVertexInputBindingDescription> binding_list;
List<VkVertexInputAttributeDescription> attribute_list;
IndexBuffer *indices_buffer=nullptr;
VkDeviceSize indices_offset=0;
public:
VertexInput()=default;
virtual ~VertexInput()=default;
bool Add(uint32_t location,VertexBuffer *,bool instance=false,VkDeviceSize offset=0);
bool AddIndices(IndexBuffer *ib,VkDeviceSize offset=0)
{
if(!ib)return(false);
indices_buffer=ib;
indices_offset=offset;
}
public:
@ -49,6 +60,9 @@ public:
const VkBuffer * GetBuffer ()const{return buf_list.GetData();}
const VkDeviceSize * GetOffset ()const{return buf_offset.GetData();}
IndexBuffer * GetIndexBuffer()const{return indices_buffer;}
const VkDeviceSize GetIndexOffset()const{return indices_offset;}
const VkPipelineVertexInputStateCreateInfo GetPipelineVertexInputStateCreateInfo()const;
};//class VertexInput
VK_NAMESPACE_END