From 90d33abe0b4b8c13b28e259fdd18f6bf3cffeab4 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Tue, 16 Apr 2019 02:23:03 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=96=B0=E7=9A=84VertexInput?= =?UTF-8?q?=E7=B1=BB=EF=BC=8C=E7=94=A8=E4=BA=8E=E5=AD=98=E5=82=A8vbo?= =?UTF-8?q?=E8=BE=93=E5=85=A5=E6=95=B0=E6=8D=AE=E5=B8=83=E5=B1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example/Vulkan/CMakeLists.txt | 3 ++ example/Vulkan/RenderSurfaceAttribute.h | 2 +- example/Vulkan/VKCommandBuffer.h | 10 ++++++ example/Vulkan/VKVertexInput.cpp | 38 ++++++++++++++++++++++ example/Vulkan/VKVertexInput.h | 43 +++++++++++++++++++++++++ 5 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 example/Vulkan/VKVertexInput.cpp create mode 100644 example/Vulkan/VKVertexInput.h diff --git a/example/Vulkan/CMakeLists.txt b/example/Vulkan/CMakeLists.txt index 70e7f243..e9e5851f 100644 --- a/example/Vulkan/CMakeLists.txt +++ b/example/Vulkan/CMakeLists.txt @@ -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 diff --git a/example/Vulkan/RenderSurfaceAttribute.h b/example/Vulkan/RenderSurfaceAttribute.h index 4db0e2a2..3772e77d 100644 --- a/example/Vulkan/RenderSurfaceAttribute.h +++ b/example/Vulkan/RenderSurfaceAttribute.h @@ -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); } diff --git a/example/Vulkan/VKCommandBuffer.h b/example/Vulkan/VKCommandBuffer.h index 37bba7f6..37c8bff8 100644 --- a/example/Vulkan/VKCommandBuffer.h +++ b/example/Vulkan/VKCommandBuffer.h @@ -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 diff --git a/example/Vulkan/VKVertexInput.cpp b/example/Vulkan/VKVertexInput.cpp new file mode 100644 index 00000000..442b53af --- /dev/null +++ b/example/Vulkan/VKVertexInput.cpp @@ -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 diff --git a/example/Vulkan/VKVertexInput.h b/example/Vulkan/VKVertexInput.h new file mode 100644 index 00000000..7fb4e9a9 --- /dev/null +++ b/example/Vulkan/VKVertexInput.h @@ -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
+ * 注:本引擎不支持一个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 vib_list; + List buf_list; + +public: + + bool Add(VertexBuffer *); + +public: + + List &GetBufferList(){return buf_list;} +};//class VertexInput +VK_NAMESPACE_END +#endif//HGL_GRAPH_VULKAN_VERTEX_INPUT_INCLUDE