2019-04-16 02:23:03 +08:00
|
|
|
|
#include"VKVertexInput.h"
|
2019-04-18 22:10:24 +08:00
|
|
|
|
#include"VKBuffer.h"
|
2019-04-16 02:23:03 +08:00
|
|
|
|
|
|
|
|
|
VK_NAMESPACE_BEGIN
|
2019-04-20 19:27:10 +08:00
|
|
|
|
bool VertexInput::Add(uint32_t location,VertexBuffer *buf,bool instance,VkDeviceSize offset)
|
2019-04-16 02:23:03 +08:00
|
|
|
|
{
|
|
|
|
|
if(!buf)
|
|
|
|
|
return(false);
|
|
|
|
|
|
2019-04-16 14:17:39 +08:00
|
|
|
|
const int binding_index=vib_list.GetCount(); //参考opengl vab,binding_index必须从0开始,紧密排列。对应在vkCmdBindVertexBuffer中的缓冲区索引
|
2019-04-16 02:23:03 +08:00
|
|
|
|
|
|
|
|
|
VkVertexInputBindingDescription binding;
|
|
|
|
|
VkVertexInputAttributeDescription attrib;
|
|
|
|
|
|
|
|
|
|
binding.binding=binding_index;
|
|
|
|
|
binding.stride=buf->GetStride();
|
2019-04-20 19:27:10 +08:00
|
|
|
|
binding.inputRate=instance?VK_VERTEX_INPUT_RATE_INSTANCE:VK_VERTEX_INPUT_RATE_VERTEX;
|
2019-04-16 02:23:03 +08:00
|
|
|
|
|
|
|
|
|
attrib.binding=binding_index;
|
2019-04-19 21:49:59 +08:00
|
|
|
|
attrib.location=location;
|
2019-04-16 02:23:03 +08:00
|
|
|
|
attrib.format=buf->GetFormat();
|
2019-04-20 19:27:10 +08:00
|
|
|
|
attrib.offset=offset;
|
2019-04-16 02:23:03 +08:00
|
|
|
|
|
|
|
|
|
vib_list.Add(new VertexInputBuffer(binding,attrib,buf));
|
|
|
|
|
buf_list.Add(buf->GetBuffer());
|
2019-04-20 19:27:10 +08:00
|
|
|
|
buf_offset.Add(offset);
|
2019-04-16 02:23:03 +08:00
|
|
|
|
|
2019-04-18 16:37:59 +08:00
|
|
|
|
binding_list.Add(binding);
|
|
|
|
|
attribute_list.Add(attrib);
|
|
|
|
|
|
2019-04-16 02:23:03 +08:00
|
|
|
|
return(true);
|
|
|
|
|
}
|
2019-04-18 16:37:59 +08:00
|
|
|
|
|
|
|
|
|
const VkPipelineVertexInputStateCreateInfo VertexInput::GetPipelineVertexInputStateCreateInfo()const
|
|
|
|
|
{
|
|
|
|
|
VkPipelineVertexInputStateCreateInfo vertexInputInfo = {};
|
|
|
|
|
vertexInputInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
|
|
|
|
|
|
|
|
|
|
vertexInputInfo.vertexBindingDescriptionCount = binding_list.GetCount();
|
|
|
|
|
vertexInputInfo.pVertexBindingDescriptions = binding_list.GetData();
|
|
|
|
|
|
|
|
|
|
vertexInputInfo.vertexAttributeDescriptionCount = attribute_list.GetCount();
|
|
|
|
|
vertexInputInfo.pVertexAttributeDescriptions = attribute_list.GetData();
|
|
|
|
|
|
|
|
|
|
return vertexInputInfo;
|
|
|
|
|
}
|
2019-04-16 02:23:03 +08:00
|
|
|
|
VK_NAMESPACE_END
|