VAB拆分到独立的文件

This commit is contained in:
HuYingzhuo 2019-04-26 22:39:27 +08:00
parent c01f46df5c
commit 3bed2806bd
6 changed files with 106 additions and 54 deletions

View File

@ -20,6 +20,7 @@ SET(VULKAN_TEST_SOURCE_FILES main.cpp
VKPipelineLayout.cpp
VKRenderPass.cpp
VKShader.cpp
VKVertexAttributeBinding.cpp
VKVertexInput.cpp
VKPipeline.cpp
VKSemaphore.cpp
@ -44,6 +45,7 @@ SET(VULKAN_TEST_HEADER_FILES VK.h
VKRenderPass.h
VKShader.h
VKVertexInput.h
VKVertexAttributeBinding.h
VKSemaphore.h
VKPipeline.h
VKFramebuffer.h

View File

@ -0,0 +1,53 @@
#include"VKVertexAttributeBinding.h"
#include"VKShader.h"
VK_NAMESPACE_BEGIN
VertexAttributeBinding::VertexAttributeBinding(Shader *s)
{
shader=s;
const int count=shader->GetAttrCount();
if(count<=0)
{
binding_list=nullptr;
return;
}
binding_list=hgl_copy_new(count,shader->GetDescList());
}
VertexAttributeBinding::~VertexAttributeBinding()
{
delete[] binding_list;
shader->Release(this);
}
bool VertexAttributeBinding::SetInstance(const uint index,bool instance)
{
if(index>=shader->GetAttrCount())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)
{
return SetInstance(shader->GetBinding(name),instance);
}
void VertexAttributeBinding::Write(VkPipelineVertexInputStateCreateInfo &vis_create_info) const
{
vis_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
const uint32_t count=shader->GetAttrCount();
vis_create_info.vertexBindingDescriptionCount = count;
vis_create_info.pVertexBindingDescriptions = binding_list;
vis_create_info.vertexAttributeDescriptionCount = count;
vis_create_info.pVertexAttributeDescriptions = shader->GetAttrList();
}
VK_NAMESPACE_END

View File

@ -0,0 +1,36 @@
#ifndef HGL_GRAPH_VULKAN_VERTEX_ATTRIBUTE_BINDING_INCLUDE
#define HGL_GRAPH_VULKAN_VERTEX_ATTRIBUTE_BINDING_INCLUDE
#include"VK.h"
#include<hgl/type/BaseString.h>
VK_NAMESPACE_BEGIN
class VertexBuffer;
class IndexBuffer;
class Shader;
/**
* <br>
* MaterialInstance,(instance)
*/
class VertexAttributeBinding
{
Shader *shader;
VkVertexInputBindingDescription *binding_list;
private:
friend class Shader;
VertexAttributeBinding(Shader *);
public:
~VertexAttributeBinding();
bool SetInstance(const uint index,bool instance);
bool SetInstance(const UTF8String &name,bool instance);
void Write(VkPipelineVertexInputStateCreateInfo &vis)const;
};//class VertexAttributeBinding
VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_VERTEX_ATTRIBUTE_BINDING_INCLUDE

View File

@ -3,55 +3,6 @@
#include"VKShader.h"
VK_NAMESPACE_BEGIN
VertexAttributeBinding::VertexAttributeBinding(Shader *s)
{
shader=s;
const int count=shader->GetAttrCount();
if(count<=0)
{
binding_list=nullptr;
return;
}
binding_list=hgl_copy_new(count,shader->GetDescList());
}
VertexAttributeBinding::~VertexAttributeBinding()
{
delete[] binding_list;
shader->Release(this);
}
bool VertexAttributeBinding::SetInstance(const uint index,bool instance)
{
if(index>=shader->GetAttrCount())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)
{
return SetInstance(shader->GetBinding(name),instance);
}
void VertexAttributeBinding::Write(VkPipelineVertexInputStateCreateInfo &vis_create_info) const
{
vis_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
const uint32_t count=shader->GetAttrCount();
vis_create_info.vertexBindingDescriptionCount = count;
vis_create_info.pVertexBindingDescriptions = binding_list;
vis_create_info.vertexAttributeDescriptionCount = count;
vis_create_info.pVertexAttributeDescriptions = shader->GetAttrList();
}
VertexInput::VertexInput(const Shader *s)
{
shader=s;

View File

@ -235,7 +235,7 @@ int main(int,char **)
device->Wait();
device->QueuePresent();
wait_seconds(3);
wait_seconds(1);
delete vertex_buffer;
delete color_buffer;

View File

@ -534,15 +534,25 @@ namespace hgl
/**
* 0
*/
template<typename T>
inline T *hgl_zero_new(const size_t count)
{
template<typename T>
inline T *hgl_zero_new(const size_t count)
{
if(count<=0)return(nullptr);
T *data=new T[count];
memset(data,0,count*sizeof(T));
return data;
}
}
template<typename T>
inline T *hgl_copy_new(const size_t count,const T *src)
{
if(count<=0)return(nullptr);
T *data=new T[count];
memcpy(data,src,count*sizeof(T));
return data;
}
/**
* 0