From 4ad064578d7d1db39cddc2981f34f11b0ca43e1b Mon Sep 17 00:00:00 2001 From: Riley King-Saunders Date: Thu, 10 Jul 2025 21:56:14 +1000 Subject: [PATCH] Renamed argument when providing array of vertex binding attributes to reflect that they are, in fact attributes and not the binding description Extended pipeline to support adding vertex bindings Vertex bindings can now be added via a template function that assumes that the type implements the following; - A function matching the signature of PFN_GetVertexInputBindingDescription and with the name get_binding_description - A function matching the signature of PFN_GetVertexAttributeDescriptions and with the name get_attribute_descriptions GetVertexAttributeDescriptions should set the num_attachments to the number of attachments if and only if the attachment output pointer is nullptr. If the output pointer is not nullptr, num_attachments should be treated as a size. Return VK_SUCCESS on success, or a different value otherwise. --- include/vulkan/basalt_pipeline.h | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/include/vulkan/basalt_pipeline.h b/include/vulkan/basalt_pipeline.h index 4e4bfcf..33b4e72 100644 --- a/include/vulkan/basalt_pipeline.h +++ b/include/vulkan/basalt_pipeline.h @@ -3,6 +3,10 @@ namespace basalt { + typedef VkVertexInputBindingDescription (*PFN_GetVertexInputBindingDescription)(void); + typedef VkResult(*PFN_GetVertexAttributeDescriptions)(VkVertexInputAttributeDescription* out_attachments, u32* num_attachments); + + class Pipeline { public: @@ -34,7 +38,10 @@ namespace basalt PipelineBuilder& add_dynamic_states(const basalt::darray& states); PipelineBuilder& set_render_pass(VkRenderPass render_pass); PipelineBuilder& add_colour_attachment(VkPipelineColorBlendAttachmentState attachment); - PipelineBuilder& add_vertex_binding(VkVertexInputBindingDescription binding, VkVertexInputAttributeDescription* attributes, u32 num_bindings); + PipelineBuilder& add_vertex_binding(VkVertexInputBindingDescription binding, VkVertexInputAttributeDescription* attributes, u32 num_attributes); + + template + PipelineBuilder& add_vertex_binding(void); Pipeline build(); @@ -70,4 +77,16 @@ namespace basalt /// Number of bytes read from the file static size_t read_file(const char* fpath, char*& outptr, size_t& outptr_size); }; + template + inline PipelineBuilder& PipelineBuilder::add_vertex_binding(void) + { + VkResult err = VK_SUCCESS; + this->vertex_binding_description.push_back(T::get_binding_description()); + u32 sz = 0; + VK_ASSERT(T::get_attribute_descriptions(nullptr, &sz), "Failed to get number of vertex attribute descriptions for object\n\tAt %s:%d\n\tError %s\n\tObject %s\n", typeid(T).name()); + this->vertex_input_attributes.expand(sz); + VK_ASSERT(T::get_attribute_descriptions(this->vertex_input_attributes.end(), &sz), "Failed to get vertex attribute descriptions for object\n\tAt %s:%d\n\tError %s\n\tObject %s\n", typeid(T).name()); + this->vertex_input_attributes.resize(this->vertex_input_attributes.m_nelements + sz); + return *this; + } } \ No newline at end of file