增加新的VertexInput类,用于存储vbo输入数据布局

This commit is contained in:
hyzboy 2019-04-16 02:23:03 +08:00
parent 276d179186
commit 90d33abe0b
5 changed files with 95 additions and 1 deletions

View File

@ -18,11 +18,13 @@ SET(VULKAN_TEST_SOURCE_FILES main.cpp
# VKDescriptorSet.cpp # VKDescriptorSet.cpp
VKRenderPass.cpp VKRenderPass.cpp
VKShader.cpp VKShader.cpp
VKVertexInput.cpp
) )
SET(VULKAN_TEST_HEADER_FILES VK.h SET(VULKAN_TEST_HEADER_FILES VK.h
VKInstance.h VKInstance.h
VKPhysicalDevice.h VKPhysicalDevice.h
VKCommandBuffer.h
VKSurfaceExtensionName.h VKSurfaceExtensionName.h
RenderSurfaceAttribute.h RenderSurfaceAttribute.h
RenderSurface.h RenderSurface.h
@ -31,6 +33,7 @@ SET(VULKAN_TEST_HEADER_FILES VK.h
# VKDescriptorSet.h # VKDescriptorSet.h
VKRenderPass.h VKRenderPass.h
VKShader.h VKShader.h
VKVertexInput.h
Window.h) Window.h)
SET(SHADER_FILES shader_compile.bat SET(SHADER_FILES shader_compile.bat

View File

@ -52,7 +52,7 @@ public:
RenderSurfaceAttribute(VkInstance inst,const PhysicalDevice *pd,VkSurfaceKHR s); RenderSurfaceAttribute(VkInstance inst,const PhysicalDevice *pd,VkSurfaceKHR s);
~RenderSurfaceAttribute(); ~RenderSurfaceAttribute();
bool CheckMemoryType(uint32_t typeBits,VkFlags requirements_mask,uint32_t *typeIndex) bool CheckMemoryType(uint32_t typeBits,VkFlags requirements_mask,uint32_t *typeIndex) const
{ {
return physical_device->CheckMemoryType(typeBits,requirements_mask,typeIndex); return physical_device->CheckMemoryType(typeBits,requirements_mask,typeIndex);
} }

View File

@ -2,6 +2,7 @@
#define HGL_GRAPH_VULKAN_COMMAND_BUFFER_INCLUDE #define HGL_GRAPH_VULKAN_COMMAND_BUFFER_INCLUDE
#include"VK.h" #include"VK.h"
#include"VKVertexInput.h"
VK_NAMESPACE_BEGIN VK_NAMESPACE_BEGIN
class CommandBuffer class CommandBuffer
@ -14,6 +15,15 @@ VK_NAMESPACE_BEGIN
CommandBuffer(VkDevice dev,VkCommandPool cp,VkCommandBuffer cb){device=dev;pool=cp;buf=cb;} CommandBuffer(VkDevice dev,VkCommandPool cp,VkCommandBuffer cb){device=dev;pool=cp;buf=cb;}
~CommandBuffer(); ~CommandBuffer();
void Bind(VertexInput *vi)
{
auto &buf_list=vi->GetBufferList();
constexpr VkDeviceSize offsets[1]={0};
vkCmdBindVertexBuffers(buf,0,buf_list.GetCount(),buf_list.GetData(),offsets);
}
};//class CommandBuffer };//class CommandBuffer
VK_NAMESPACE_END VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_COMMAND_BUFFER_INCLUDE #endif//HGL_GRAPH_VULKAN_COMMAND_BUFFER_INCLUDE

View File

@ -0,0 +1,38 @@
#include"VKVertexInput.h"
VK_NAMESPACE_BEGIN
//struct VertexInputBuffer
//{
// //按API可以一个binding绑多个attrib但我们仅支持1v1
//
// VkVertexInputBindingDescription binding;
// VkVertexInputAttributeDescription attrib;
// Buffer *buf;
//};
bool VertexInput::Add(VertexBuffer *buf)
{
if(!buf)
return(false);
const int binding_index=vib_list.GetCount(); //参考opengl vab,binding_index必须从0开始紧密排列但是否必须这样待以后测试
VkVertexInputBindingDescription binding;
VkVertexInputAttributeDescription attrib;
binding.binding=binding_index;
binding.stride=buf->GetStride();
binding.inputRate=VK_VERTEX_INPUT_RATE_VERTEX; //还有一种是INSTANCE暂时未知
attrib.binding=binding_index;
attrib.location=0;
attrib.format=buf->GetFormat();
attrib.offset=0;
vib_list.Add(new VertexInputBuffer(binding,attrib,buf));
buf_list.Add(buf->GetBuffer());
return(true);
}
VK_NAMESPACE_END

View File

@ -0,0 +1,43 @@
#ifndef HGL_GRAPH_VULKAN_VERTEX_INPUT_INCLUDE
#define HGL_GRAPH_VULKAN_VERTEX_INPUT_INCLUDE
#include"VK.h"
#include"VKBuffer.h"
VK_NAMESPACE_BEGIN
/**
* OpenGL的VAB<br>
* BUFFER中包括多种数据
*/
class VertexInput
{
struct VertexInputBuffer
{
//按API可以一个binding绑多个attrib但我们仅支持1v1
VkVertexInputBindingDescription binding;
VkVertexInputAttributeDescription attrib;
VertexBuffer *buffer;
public:
VertexInputBuffer(VkVertexInputBindingDescription bind,VkVertexInputAttributeDescription attr,VertexBuffer *buf)
{
binding=bind;
attrib=attr;
buffer=buf;
}
};
ObjectList<VertexInputBuffer> vib_list;
List<VkBuffer> buf_list;
public:
bool Add(VertexBuffer *);
public:
List<VkBuffer> &GetBufferList(){return buf_list;}
};//class VertexInput
VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_VERTEX_INPUT_INCLUDE