to upgrade the VertexAttributeBinding codes.

This commit is contained in:
hyzboy 2020-09-05 17:53:48 +08:00
parent 3fd9d1535d
commit 2a1a79c736
3 changed files with 22 additions and 26 deletions

View File

@ -14,9 +14,9 @@ Material *CreateMaterial(Device *dev,ShaderModuleMap *shader_maps)
if(shader_count<2)
return(nullptr);
const ShaderModule *vsm;
const ShaderModule *sm;
if(!shader_maps->Get(VK_SHADER_STAGE_VERTEX_BIT,vsm))
if(!shader_maps->Get(VK_SHADER_STAGE_VERTEX_BIT,sm))
return(nullptr);
DescriptorSetLayoutCreater *dsl_creater=new DescriptorSetLayoutCreater(dev);
@ -29,16 +29,20 @@ Material *CreateMaterial(Device *dev,ShaderModuleMap *shader_maps)
auto **itp=shader_maps->GetDataList();
for(int i=0;i<shader_count;i++)
{
vsm=(*itp)->right;
memcpy(p,vsm->GetCreateInfo(),sizeof(VkPipelineShaderStageCreateInfo));
sm=(*itp)->right;
memcpy(p,sm->GetCreateInfo(),sizeof(VkPipelineShaderStageCreateInfo));
dsl_creater->Bind(vsm->GetDescriptorList(),vsm->GetStage());
dsl_creater->Bind(sm->GetDescriptorList(),sm->GetStage());
++p;
++itp;
}
dsl_creater->CreatePipelineLayout();
if(!dsl_creater->CreatePipelineLayout())
{
delete shader_maps;
return(nullptr);
}
return(new Material(dev,shader_maps,shader_stage_list,dsl_creater));
}
@ -68,8 +72,11 @@ Material::~Material()
{
delete dsl_creater;
vertex_sm->Release(vab);
delete vab;
if(vab)
{
vertex_sm->Release(vab);
delete vab;
}
delete shader_stage_list;
delete shader_maps;

View File

@ -69,7 +69,7 @@ VertexShaderModule::~VertexShaderModule()
VertexAttributeBinding *VertexShaderModule::CreateVertexAttributeBinding()
{
VertexAttributeBinding *vab=new VertexAttributeBinding(this);
VertexAttributeBinding *vab=new VertexAttributeBinding(attr_count,binding_list,attribute_list);
vab_sets.Add(vab);

View File

@ -2,11 +2,9 @@
#include<hgl/graph/vulkan/VKShaderModule.h>
VK_NAMESPACE_BEGIN
VertexAttributeBinding::VertexAttributeBinding(VertexShaderModule *s)
VertexAttributeBinding::VertexAttributeBinding(const uint32_t count,const VkVertexInputBindingDescription *bind_list,const VkVertexInputAttributeDescription *attr_list)
{
vsm=s;
attr_count=vsm->GetAttrCount();
attr_count=count;
if(attr_count<=0)
{
@ -15,21 +13,14 @@ VertexAttributeBinding::VertexAttributeBinding(VertexShaderModule *s)
return;
}
binding_list=hgl_copy_new(attr_count,vsm->GetDescList());
attribute_list=hgl_copy_new(attr_count,vsm->GetAttrList());
binding_list=hgl_copy_new(attr_count,bind_list);
attribute_list=hgl_copy_new(attr_count,attr_list);
}
VertexAttributeBinding::~VertexAttributeBinding()
{
delete[] attribute_list;
delete[] binding_list;
vsm->Release(this);
}
const uint VertexAttributeBinding::GetStageInputBinding(const AnsiString &name)
{
return vsm->GetStageInputBinding(name);
}
bool VertexAttributeBinding::SetInstance(const uint index,bool instance)
@ -70,12 +61,10 @@ bool VertexAttributeBinding::SetOffset(const uint index,const uint32_t offset)
void VertexAttributeBinding::Write(VkPipelineVertexInputStateCreateInfo &vis_create_info) const
{
const uint32_t count=vsm->GetAttrCount();
vis_create_info.vertexBindingDescriptionCount = count;
vis_create_info.vertexBindingDescriptionCount = attr_count;
vis_create_info.pVertexBindingDescriptions = binding_list;
vis_create_info.vertexAttributeDescriptionCount = count;
vis_create_info.vertexAttributeDescriptionCount = attr_count;
vis_create_info.pVertexAttributeDescriptions = attribute_list;
}
VK_NAMESPACE_END