Crimson Engine 1.0.0
A high-performance C++20 game engine prototype showcasing a custom ECS, Vulkan renderer, and ImGui editor.
Loading...
Searching...
No Matches
PipelineBuilder.hpp
Go to the documentation of this file.
1#pragma once
2#include <vector>
3#include <cstdint>
4#include <vulkan/vulkan.h>
5
11public:
15 PipelineBuilder() = default;
19 ~PipelineBuilder() = default;
20
21 // Basic setters
27 PipelineBuilder& setLayout(VkPipelineLayout l) { layout = l; return *this; }
33 PipelineBuilder& setRenderPass(VkRenderPass rp) { renderPass = rp; return *this; }
40 PipelineBuilder& setShaders(VkShaderModule vs, VkShaderModule fs) { vertShader = vs; fragShader = fs; return *this; }
41
42 // Provide full vertex input descriptions (overwrites previously set bindings/attributes)
50 const std::vector<VkVertexInputBindingDescription>& bindings,
51 const std::vector<VkVertexInputAttributeDescription>& attributes)
52 {
53 vertexBindings = bindings;
54 vertexAttributes = attributes;
55 return *this;
56 }
57
58 // Convenience: add instance matrix binding at `binding` (mat4 -> 4 vec4 attributes)
59 // `locationStart` is the first attribute location that will be used (uses locationStart..locationStart+3)
66 PipelineBuilder& addInstanceMatrixBinding(uint32_t binding, uint32_t locationStart);
67
68 // Build pipeline
74 VkPipeline build(VkDevice device);
75
76private:
78 VkPipelineLayout layout = VK_NULL_HANDLE;
80 VkRenderPass renderPass = VK_NULL_HANDLE;
82 VkShaderModule vertShader = VK_NULL_HANDLE;
84 VkShaderModule fragShader = VK_NULL_HANDLE;
85
87 std::vector<VkVertexInputBindingDescription> vertexBindings;
89 std::vector<VkVertexInputAttributeDescription> vertexAttributes;
90};
Builder utility facilitating the creation of Vulkan graphics pipelines.
Definition PipelineBuilder.hpp:10
VkShaderModule vertShader
Vertex shader handle.
Definition PipelineBuilder.hpp:82
PipelineBuilder & setLayout(VkPipelineLayout l)
Configures the pipeline layout.
Definition PipelineBuilder.hpp:27
VkRenderPass renderPass
Target render pass index.
Definition PipelineBuilder.hpp:80
~PipelineBuilder()=default
Destroy the Pipeline Builder object.
std::vector< VkVertexInputAttributeDescription > vertexAttributes
Cached input attributes.
Definition PipelineBuilder.hpp:89
PipelineBuilder & addInstanceMatrixBinding(uint32_t binding, uint32_t locationStart)
Adds input descriptions mapping to an instance model matrix.
Definition PipelineBuilder.cpp:13
VkShaderModule fragShader
Fragment shader handle.
Definition PipelineBuilder.hpp:84
VkPipelineLayout layout
Reference to pipeline layout.
Definition PipelineBuilder.hpp:78
VkPipeline build(VkDevice device)
Compiles and constructs the graphics pipeline.
Definition PipelineBuilder.cpp:61
PipelineBuilder & setVertexInput(const std::vector< VkVertexInputBindingDescription > &bindings, const std::vector< VkVertexInputAttributeDescription > &attributes)
Configures vertex input binding and attribute descriptions.
Definition PipelineBuilder.hpp:49
PipelineBuilder()=default
Construct a new Pipeline Builder object.
PipelineBuilder & setShaders(VkShaderModule vs, VkShaderModule fs)
Configures the shader stages.
Definition PipelineBuilder.hpp:40
std::vector< VkVertexInputBindingDescription > vertexBindings
Cached input bindings.
Definition PipelineBuilder.hpp:87
PipelineBuilder & setRenderPass(VkRenderPass rp)
Configures the target render pass.
Definition PipelineBuilder.hpp:33