2019-04-16 02:23:03 +08:00
|
|
|
|
#include"VKVertexInput.h"
|
2019-04-18 22:10:24 +08:00
|
|
|
|
#include"VKBuffer.h"
|
2019-04-26 22:34:51 +08:00
|
|
|
|
#include"VKShader.h"
|
2019-04-16 02:23:03 +08:00
|
|
|
|
|
|
|
|
|
VK_NAMESPACE_BEGIN
|
2019-04-26 22:34:51 +08:00
|
|
|
|
VertexAttributeBinding::VertexAttributeBinding(Shader *s)
|
2019-04-26 21:43:22 +08:00
|
|
|
|
{
|
2019-04-26 22:34:51 +08:00
|
|
|
|
shader=s;
|
2019-04-26 03:03:21 +08:00
|
|
|
|
|
2019-04-26 22:34:51 +08:00
|
|
|
|
const int count=shader->GetAttrCount();
|
2019-04-26 21:43:22 +08:00
|
|
|
|
|
|
|
|
|
if(count<=0)
|
|
|
|
|
{
|
|
|
|
|
binding_list=nullptr;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-26 22:34:51 +08:00
|
|
|
|
binding_list=hgl_copy_new(count,shader->GetDescList());
|
2019-04-26 21:43:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-04-26 22:34:51 +08:00
|
|
|
|
VertexAttributeBinding::~VertexAttributeBinding()
|
2019-04-26 21:43:22 +08:00
|
|
|
|
{
|
|
|
|
|
delete[] binding_list;
|
|
|
|
|
|
2019-04-26 22:34:51 +08:00
|
|
|
|
shader->Release(this);
|
2019-04-26 21:43:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-04-26 22:34:51 +08:00
|
|
|
|
bool VertexAttributeBinding::SetInstance(const uint index,bool instance)
|
2019-04-26 21:43:22 +08:00
|
|
|
|
{
|
2019-04-26 22:34:51 +08:00
|
|
|
|
if(index>=shader->GetAttrCount())return(false);
|
2019-04-26 21:43:22 +08:00
|
|
|
|
|
|
|
|
|
binding_list[index].inputRate=instance?VK_VERTEX_INPUT_RATE_INSTANCE:VK_VERTEX_INPUT_RATE_VERTEX;
|
|
|
|
|
|
|
|
|
|
return(true);
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-26 22:34:51 +08:00
|
|
|
|
bool VertexAttributeBinding::SetInstance(const UTF8String &name,bool instance)
|
|
|
|
|
{
|
|
|
|
|
return SetInstance(shader->GetBinding(name),instance);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VertexAttributeBinding::Write(VkPipelineVertexInputStateCreateInfo &vis_create_info) const
|
2019-04-26 21:43:22 +08:00
|
|
|
|
{
|
|
|
|
|
vis_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
|
|
|
|
|
|
2019-04-26 22:34:51 +08:00
|
|
|
|
const uint32_t count=shader->GetAttrCount();
|
2019-04-16 02:23:03 +08:00
|
|
|
|
|
2019-04-26 21:43:22 +08:00
|
|
|
|
vis_create_info.vertexBindingDescriptionCount = count;
|
|
|
|
|
vis_create_info.pVertexBindingDescriptions = binding_list;
|
2019-04-18 16:37:59 +08:00
|
|
|
|
|
2019-04-26 21:43:22 +08:00
|
|
|
|
vis_create_info.vertexAttributeDescriptionCount = count;
|
2019-04-26 22:34:51 +08:00
|
|
|
|
vis_create_info.pVertexAttributeDescriptions = shader->GetAttrList();
|
2019-04-16 02:23:03 +08:00
|
|
|
|
}
|
2019-04-18 16:37:59 +08:00
|
|
|
|
|
2019-04-26 22:34:51 +08:00
|
|
|
|
VertexInput::VertexInput(const Shader *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)
|
|
|
|
|
{
|
|
|
|
|
return Set(shader->GetBinding(name),vb,offset);
|
|
|
|
|
}
|
2019-04-16 02:23:03 +08:00
|
|
|
|
VK_NAMESPACE_END
|