diff --git a/example/Vulkan/VKMaterial.cpp b/example/Vulkan/VKMaterial.cpp index a3a0ea21..968238b5 100644 --- a/example/Vulkan/VKMaterial.cpp +++ b/example/Vulkan/VKMaterial.cpp @@ -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 diff --git a/example/Vulkan/VKMaterial.h b/example/Vulkan/VKMaterial.h index 10ec4d38..875e9e9c 100644 --- a/example/Vulkan/VKMaterial.h +++ b/example/Vulkan/VKMaterial.h @@ -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(); diff --git a/example/Vulkan/VKPipeline.cpp b/example/Vulkan/VKPipeline.cpp index 1cdefadc..d578a231 100644 --- a/example/Vulkan/VKPipeline.cpp +++ b/example/Vulkan/VKPipeline.cpp @@ -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 diff --git a/example/Vulkan/VKShader.cpp b/example/Vulkan/VKShader.cpp index 418c1e47..8d70ea1e 100644 --- a/example/Vulkan/VKShader.cpp +++ b/example/Vulkan/VKShader.cpp @@ -1,5 +1,5 @@ #include"VKShader.h" -#include"VKVertexInput.h" +#include"VKVertexAttributeBinding.h" #include"spirv_cross.hpp" VK_NAMESPACE_BEGIN diff --git a/example/Vulkan/VKVertexAttributeBinding.cpp b/example/Vulkan/VKVertexAttributeBinding.cpp index f26a5ef8..544d1b35 100644 --- a/example/Vulkan/VKVertexAttributeBinding.cpp +++ b/example/Vulkan/VKVertexAttributeBinding.cpp @@ -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 diff --git a/example/Vulkan/VKVertexAttributeBinding.h b/example/Vulkan/VKVertexAttributeBinding.h index bd8f5d04..2d0cc5d1 100644 --- a/example/Vulkan/VKVertexAttributeBinding.h +++ b/example/Vulkan/VKVertexAttributeBinding.h @@ -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