VAB拆分到独立的文件
This commit is contained in:
parent
c01f46df5c
commit
3bed2806bd
@ -20,6 +20,7 @@ SET(VULKAN_TEST_SOURCE_FILES main.cpp
|
|||||||
VKPipelineLayout.cpp
|
VKPipelineLayout.cpp
|
||||||
VKRenderPass.cpp
|
VKRenderPass.cpp
|
||||||
VKShader.cpp
|
VKShader.cpp
|
||||||
|
VKVertexAttributeBinding.cpp
|
||||||
VKVertexInput.cpp
|
VKVertexInput.cpp
|
||||||
VKPipeline.cpp
|
VKPipeline.cpp
|
||||||
VKSemaphore.cpp
|
VKSemaphore.cpp
|
||||||
@ -44,6 +45,7 @@ SET(VULKAN_TEST_HEADER_FILES VK.h
|
|||||||
VKRenderPass.h
|
VKRenderPass.h
|
||||||
VKShader.h
|
VKShader.h
|
||||||
VKVertexInput.h
|
VKVertexInput.h
|
||||||
|
VKVertexAttributeBinding.h
|
||||||
VKSemaphore.h
|
VKSemaphore.h
|
||||||
VKPipeline.h
|
VKPipeline.h
|
||||||
VKFramebuffer.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"
|
#include"VKShader.h"
|
||||||
|
|
||||||
VK_NAMESPACE_BEGIN
|
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)
|
VertexInput::VertexInput(const Shader *s)
|
||||||
{
|
{
|
||||||
shader=s;
|
shader=s;
|
||||||
|
@ -235,7 +235,7 @@ int main(int,char **)
|
|||||||
device->Wait();
|
device->Wait();
|
||||||
device->QueuePresent();
|
device->QueuePresent();
|
||||||
|
|
||||||
wait_seconds(3);
|
wait_seconds(1);
|
||||||
|
|
||||||
delete vertex_buffer;
|
delete vertex_buffer;
|
||||||
delete color_buffer;
|
delete color_buffer;
|
||||||
|
@ -544,6 +544,16 @@ namespace hgl
|
|||||||
return data;
|
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
|
* 指定类型数据清0
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user