增加新的VertexInput类,用于存储vbo输入数据布局
This commit is contained in:
parent
276d179186
commit
90d33abe0b
@ -18,11 +18,13 @@ SET(VULKAN_TEST_SOURCE_FILES main.cpp
|
||||
# VKDescriptorSet.cpp
|
||||
VKRenderPass.cpp
|
||||
VKShader.cpp
|
||||
VKVertexInput.cpp
|
||||
)
|
||||
|
||||
SET(VULKAN_TEST_HEADER_FILES VK.h
|
||||
VKInstance.h
|
||||
VKPhysicalDevice.h
|
||||
VKCommandBuffer.h
|
||||
VKSurfaceExtensionName.h
|
||||
RenderSurfaceAttribute.h
|
||||
RenderSurface.h
|
||||
@ -31,6 +33,7 @@ SET(VULKAN_TEST_HEADER_FILES VK.h
|
||||
# VKDescriptorSet.h
|
||||
VKRenderPass.h
|
||||
VKShader.h
|
||||
VKVertexInput.h
|
||||
Window.h)
|
||||
|
||||
SET(SHADER_FILES shader_compile.bat
|
||||
|
@ -52,7 +52,7 @@ public:
|
||||
RenderSurfaceAttribute(VkInstance inst,const PhysicalDevice *pd,VkSurfaceKHR s);
|
||||
~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);
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
#define HGL_GRAPH_VULKAN_COMMAND_BUFFER_INCLUDE
|
||||
|
||||
#include"VK.h"
|
||||
#include"VKVertexInput.h"
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
class CommandBuffer
|
||||
@ -14,6 +15,15 @@ VK_NAMESPACE_BEGIN
|
||||
|
||||
CommandBuffer(VkDevice dev,VkCommandPool cp,VkCommandBuffer cb){device=dev;pool=cp;buf=cb;}
|
||||
~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
|
||||
VK_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_VULKAN_COMMAND_BUFFER_INCLUDE
|
||||
|
38
example/Vulkan/VKVertexInput.cpp
Normal file
38
example/Vulkan/VKVertexInput.cpp
Normal 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
|
43
example/Vulkan/VKVertexInput.h
Normal file
43
example/Vulkan/VKVertexInput.h
Normal 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
|
Loading…
x
Reference in New Issue
Block a user