VAB拆分到独立的文件
This commit is contained in:
parent
c01f46df5c
commit
3bed2806bd
@ -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
|
||||
|
53
example/Vulkan/VKVertexAttributeBinding.cpp
Normal file
53
example/Vulkan/VKVertexAttributeBinding.cpp
Normal 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
|
36
example/Vulkan/VKVertexAttributeBinding.h
Normal file
36
example/Vulkan/VKVertexAttributeBinding.h
Normal 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
|
@ -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;
|
||||
|
@ -235,7 +235,7 @@ int main(int,char **)
|
||||
device->Wait();
|
||||
device->QueuePresent();
|
||||
|
||||
wait_seconds(3);
|
||||
wait_seconds(1);
|
||||
|
||||
delete vertex_buffer;
|
||||
delete color_buffer;
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user