VAB改为同时备份Attribute属性,虽然大部分情况下无需修改

This commit is contained in:
hyzboy 2019-04-27 01:09:27 +08:00
parent 1e26f9e482
commit 6a313c9e25
6 changed files with 50 additions and 27 deletions

View File

@ -1,7 +1,7 @@
#include"VKMaterial.h"
#include"VKDescriptorSets.h"
#include"VKShader.h"
#include"VKVertexInput.h"
#include"VKVertexAttributeBinding.h"
VK_NAMESPACE_BEGIN
Material::~Material()
{
@ -11,13 +11,13 @@ Material::~Material()
MaterialInstance *Material::CreateInstance()
{
VertexAttributeBinding *vis_instance=shader->CreateVertexAttributeBinding();
VertexAttributeBinding *vab=shader->CreateVertexAttributeBinding();
return(new MaterialInstance(this,vis_instance));
return(new MaterialInstance(this,vab));
}
MaterialInstance::~MaterialInstance()
{
delete vis_instance;
delete vab;
}
VK_NAMESPACE_END

View File

@ -6,7 +6,6 @@ VK_NAMESPACE_BEGIN
class Shader;
class DescriptorSetLayoutCreater;
class MaterialInstance;
class VertexInputState;
class VertexAttributeBinding;
/**
@ -37,14 +36,14 @@ public:
class MaterialInstance
{
const Material *mat; ///<这里的是对material的完全引用不做任何修改
VertexAttributeBinding *vis_instance; ///<这里的vis是Material中vis的复制体
VertexAttributeBinding *vab; ///<这里的vis是Material中vis的复制体
public:
MaterialInstance(Material *m,VertexAttributeBinding *vi)
{
mat=m;
vis_instance=vi;
vab=vi;
}
~MaterialInstance();

View File

@ -1,7 +1,7 @@
#include"VKPipeline.h"
#include"VKDevice.h"
#include"VKShader.h"
#include"VKVertexInput.h"
#include"VKVertexAttributeBinding.h"
#include"VKRenderPass.h"
VK_NAMESPACE_BEGIN

View File

@ -1,5 +1,5 @@
#include"VKShader.h"
#include"VKVertexInput.h"
#include"VKVertexAttributeBinding.h"
#include"spirv_cross.hpp"
VK_NAMESPACE_BEGIN

View File

@ -6,50 +6,66 @@ VertexAttributeBinding::VertexAttributeBinding(Shader *s)
{
shader=s;
const int count=shader->GetAttrCount();
attr_count=shader->GetAttrCount();
if(count<=0)
if(attr_count<=0)
{
binding_list=nullptr;
attribute_list=nullptr;
return;
}
binding_list=hgl_copy_new(count,shader->GetDescList());
binding_list=hgl_copy_new(attr_count,shader->GetDescList());
attribute_list=hgl_copy_new(attr_count,shader->GetAttrList());
}
VertexAttributeBinding::~VertexAttributeBinding()
{
delete[] attribute_list;
delete[] binding_list;
shader->Release(this);
}
const uint VertexAttributeBinding::GetIndex(const UTF8String &name)
{
return shader->GetBinding(name);
}
bool VertexAttributeBinding::SetInstance(const uint index,bool instance)
{
if(index>=shader->GetAttrCount())return(false);
if(index>=attr_count)return(false);
binding_list[index].inputRate=instance?VK_VERTEX_INPUT_RATE_INSTANCE:VK_VERTEX_INPUT_RATE_VERTEX;
return(true);
}
bool VertexAttributeBinding::SetInstance(const UTF8String &name,bool instance)
bool VertexAttributeBinding::SetStride(const uint index,const uint32_t &stride)
{
return SetInstance(shader->GetBinding(name),instance);
}
bool VertexAttributeBinding::SetStride(const uint index,uint32_t stride)
{
if(index>=shader->GetAttrCount())return(false);
if(index>=attr_count)return(false);
binding_list[index].stride=stride;
return(true);
}
bool VertexAttributeBinding::SetStride(const UTF8String &name,uint32_t stride)
bool VertexAttributeBinding::SetFormat(const uint index,const VkFormat &format)
{
return SetStride(shader->GetBinding(name),stride);
if(index>=attr_count)return(false);
attribute_list[index].format=format;
return(true);
}
bool VertexAttributeBinding::SetOffset(const uint index,const uint32_t offset)
{
if(index>=attr_count)return(false);
attribute_list[index].offset=offset;
return(true);
}
void VertexAttributeBinding::Write(VkPipelineVertexInputStateCreateInfo &vis_create_info) const
@ -62,6 +78,6 @@ void VertexAttributeBinding::Write(VkPipelineVertexInputStateCreateInfo &vis_cre
vis_create_info.pVertexBindingDescriptions = binding_list;
vis_create_info.vertexAttributeDescriptionCount = count;
vis_create_info.pVertexAttributeDescriptions = shader->GetAttrList();
vis_create_info.pVertexAttributeDescriptions = attribute_list;
}
VK_NAMESPACE_END

View File

@ -15,7 +15,9 @@ class Shader;
class VertexAttributeBinding
{
Shader *shader;
uint32_t attr_count;
VkVertexInputBindingDescription *binding_list;
VkVertexInputAttributeDescription *attribute_list;
private:
@ -27,11 +29,17 @@ public:
~VertexAttributeBinding();
bool SetInstance(const uint index,bool instance);
bool SetInstance(const UTF8String &name,bool instance);
const uint GetIndex(const UTF8String &name);
bool SetStride(const uint index,uint32_t stride);
bool SetStride(const UTF8String &name,uint32_t stride);
bool SetInstance(const uint index,bool instance);
bool SetStride (const uint index,const uint32_t & stride);
bool SetFormat (const uint index,const VkFormat & format);
bool SetOffset (const uint index,const uint32_t offset);
bool SetInstance(const UTF8String &name,bool instance){return SetInstance(GetIndex(name),instance);}
bool SetStride (const UTF8String &name,const uint32_t &stride ){return SetStride (GetIndex(name),stride);}
bool SetFormat (const UTF8String &name,const VkFormat &format ){return SetFormat (GetIndex(name),format);}
bool SetOffset (const UTF8String &name,const uint32_t offset ){return SetOffset (GetIndex(name),offset);}
void Write(VkPipelineVertexInputStateCreateInfo &vis)const;
};//class VertexAttributeBinding