2019-04-16 02:23:03 +08:00
|
|
|
|
#include"VKVertexInput.h"
|
2019-04-18 22:10:24 +08:00
|
|
|
|
#include"VKBuffer.h"
|
2019-04-28 16:06:53 +08:00
|
|
|
|
#include"VKShaderModule.h"
|
2019-04-16 02:23:03 +08:00
|
|
|
|
|
|
|
|
|
VK_NAMESPACE_BEGIN
|
2019-04-28 16:06:53 +08:00
|
|
|
|
VertexInput::VertexInput(const VertexShaderModule *s)
|
2019-04-18 16:37:59 +08:00
|
|
|
|
{
|
2019-04-26 22:34:51 +08:00
|
|
|
|
shader=s;
|
2019-04-18 16:37:59 +08:00
|
|
|
|
|
2019-04-26 22:34:51 +08:00
|
|
|
|
if(!shader)
|
2019-04-25 16:02:13 +08:00
|
|
|
|
return;
|
2019-04-18 16:37:59 +08:00
|
|
|
|
|
2019-04-26 22:34:51 +08:00
|
|
|
|
buf_count=shader->GetAttrCount();
|
2019-04-18 16:37:59 +08:00
|
|
|
|
|
2019-04-25 16:02:13 +08:00
|
|
|
|
buf_list=hgl_zero_new<VkBuffer>(buf_count);
|
|
|
|
|
buf_offset=hgl_zero_new<VkDeviceSize>(buf_count);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VertexInput::~VertexInput()
|
|
|
|
|
{
|
|
|
|
|
delete[] buf_offset;
|
|
|
|
|
delete[] buf_list;
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-26 21:43:22 +08:00
|
|
|
|
bool VertexInput::Set(const int index,VertexBuffer *buf,VkDeviceSize offset)
|
2019-04-25 16:02:13 +08:00
|
|
|
|
{
|
|
|
|
|
if(index<0||index>=buf_count)return(false);
|
|
|
|
|
|
2019-04-26 22:34:51 +08:00
|
|
|
|
const VkVertexInputBindingDescription *desc=shader->GetDesc(index);
|
|
|
|
|
const VkVertexInputAttributeDescription *attr=shader->GetAttr(index);
|
2019-04-25 16:02:13 +08:00
|
|
|
|
|
|
|
|
|
if(buf->GetFormat()!=attr->format)return(false);
|
|
|
|
|
if(buf->GetStride()!=desc->stride)return(false);
|
|
|
|
|
|
|
|
|
|
buf_list[index]=*buf;
|
|
|
|
|
buf_offset[index]=offset;
|
|
|
|
|
|
|
|
|
|
return(true);
|
2019-04-18 16:37:59 +08:00
|
|
|
|
}
|
2019-04-26 22:34:51 +08:00
|
|
|
|
|
|
|
|
|
bool VertexInput::Set(const UTF8String &name,VertexBuffer *vb,VkDeviceSize offset)
|
|
|
|
|
{
|
2019-04-28 16:06:53 +08:00
|
|
|
|
const int binding=shader->GetBinding(name);
|
|
|
|
|
|
|
|
|
|
return Set(binding,vb,offset);
|
2019-04-26 22:34:51 +08:00
|
|
|
|
}
|
2019-04-16 02:23:03 +08:00
|
|
|
|
VK_NAMESPACE_END
|