Browse Source

Vk: Add GraphicsPipelineBuilder

Signed-off-by: Squareys <squareys@googlemail.com>
pull/202/head
Squareys 10 years ago committed by Squareys
parent
commit
ca6b6337e7
  1. 2
      src/Magnum/Vk/Pipeline.cpp
  2. 28
      src/Magnum/Vk/Pipeline.h

2
src/Magnum/Vk/Pipeline.cpp

@ -35,7 +35,7 @@ Pipeline::~Pipeline() {
vkDestroyPipelineCache(_device, _cache, nullptr); vkDestroyPipelineCache(_device, _cache, nullptr);
} }
std::unique_ptr<Pipeline> GraphicsPipelineFactory::create() { std::unique_ptr<Pipeline> GraphicsPipelineBuilder::build() {
VkPipeline pipeline; VkPipeline pipeline;
VkPipelineCache cache; VkPipelineCache cache;
VkPipelineLayout layout; VkPipelineLayout layout;

28
src/Magnum/Vk/Pipeline.h

@ -174,10 +174,10 @@ class MAGNUM_VK_EXPORT Pipeline {
VkPipelineLayout _layout; VkPipelineLayout _layout;
}; };
class MAGNUM_VK_EXPORT GraphicsPipelineFactory { class MAGNUM_VK_EXPORT GraphicsPipelineBuilder {
public: public:
GraphicsPipelineFactory(Device& device): GraphicsPipelineBuilder(Device& device):
_device{device} { _device{device} {
_inputAssemblyState = { _inputAssemblyState = {
@ -291,27 +291,27 @@ class MAGNUM_VK_EXPORT GraphicsPipelineFactory {
}; };
} }
/** @brief Copying is not allowed */ /** @brief Copying is not allowed */ // TODO(squareys) probably should be, though
GraphicsPipelineFactory(const GraphicsPipelineFactory&) = delete; GraphicsPipelineBuilder(const GraphicsPipelineBuilder&) = delete;
/** @brief Move constructor */ /** @brief Move constructor */
GraphicsPipelineFactory(GraphicsPipelineFactory&& other); GraphicsPipelineBuilder(GraphicsPipelineBuilder&& other);
/** /**
* @brief Destructor * @brief Destructor
* *
* @see @fn_vk{DestroyPipeline} * @see @fn_vk{DestroyPipeline}
*/ */
~GraphicsPipelineFactory() { ~GraphicsPipelineBuilder() {
} }
/** @brief Copying is not allowed */ /** @brief Copying is not allowed */
GraphicsPipelineFactory& operator=(const GraphicsPipelineFactory&) = delete; GraphicsPipelineBuilder& operator=(const GraphicsPipelineBuilder&) = delete;
/** @brief Move assignment is not allowed */ /** @brief Move assignment is not allowed */
GraphicsPipelineFactory& operator=(GraphicsPipelineFactory&&) = delete; GraphicsPipelineBuilder& operator=(GraphicsPipelineBuilder&&) = delete;
GraphicsPipelineFactory& addShader(ShaderStage stage, Shader& shader) { GraphicsPipelineBuilder& addShader(ShaderStage stage, Shader& shader) {
VkPipelineShaderStageCreateInfo shaderStage = { VkPipelineShaderStageCreateInfo shaderStage = {
VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
nullptr, nullptr,
@ -325,24 +325,24 @@ class MAGNUM_VK_EXPORT GraphicsPipelineFactory {
return *this; return *this;
} }
std::unique_ptr<Pipeline> create(); std::unique_ptr<Pipeline> build();
GraphicsPipelineFactory& setRenderPass(RenderPass& renderPass) { GraphicsPipelineBuilder& setRenderPass(RenderPass& renderPass) {
_renderPass = &renderPass; _renderPass = &renderPass;
return *this; return *this;
} }
GraphicsPipelineFactory& setTopology(Topology topology) { GraphicsPipelineBuilder& setTopology(Topology topology) {
_inputAssemblyState.topology = VkPrimitiveTopology(topology); _inputAssemblyState.topology = VkPrimitiveTopology(topology);
return *this; return *this;
} }
GraphicsPipelineFactory& setDynamicStates(std::initializer_list<DynamicState> states) { GraphicsPipelineBuilder& setDynamicStates(std::initializer_list<DynamicState> states) {
_dynamicStates = std::vector<DynamicState>(states); _dynamicStates = std::vector<DynamicState>(states);
return *this; return *this;
} }
GraphicsPipelineFactory& addDescriptorSetLayout(const DescriptorSetLayout& layout) { GraphicsPipelineBuilder& addDescriptorSetLayout(const DescriptorSetLayout& layout) {
_setLayouts.push_back(layout); _setLayouts.push_back(layout);
return *this; return *this;
} }

Loading…
Cancel
Save