|
| 1 | +#include "pbr_system.h" |
| 2 | + |
| 3 | +// Standard includes |
| 4 | +#include <stdexcept> |
| 5 | + |
| 6 | +namespace dae |
| 7 | +{ |
| 8 | + pbr_system::pbr_system(device &device, VkRenderPass render_pass, VkDescriptorSetLayout global_set_layout) |
| 9 | + : i_system{device} |
| 10 | + { |
| 11 | + create_pipeline_layout(global_set_layout); |
| 12 | + create_pipeline(render_pass); |
| 13 | + } |
| 14 | + |
| 15 | + void pbr_system::create_pipeline_layout(VkDescriptorSetLayout global_set_layout) |
| 16 | + { |
| 17 | + std::vector<VkDescriptorSetLayout> descriptor_set_layouts{global_set_layout}; |
| 18 | + |
| 19 | + VkPipelineLayoutCreateInfo pipeline_layout_info{}; |
| 20 | + pipeline_layout_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; |
| 21 | + pipeline_layout_info.setLayoutCount = static_cast<uint32_t>(descriptor_set_layouts.size()); |
| 22 | + pipeline_layout_info.pSetLayouts = descriptor_set_layouts.data(); |
| 23 | + pipeline_layout_info.pushConstantRangeCount = 0; |
| 24 | + pipeline_layout_info.pPushConstantRanges = VK_NULL_HANDLE; |
| 25 | + |
| 26 | + if (vkCreatePipelineLayout(device_.get_logical_device(), &pipeline_layout_info, nullptr, &pipeline_layout_) != VK_SUCCESS) |
| 27 | + { |
| 28 | + throw std::runtime_error{"Failed to create pipeline layout!"}; |
| 29 | + } |
| 30 | + } |
| 31 | + |
| 32 | + void pbr_system::create_pipeline(VkRenderPass render_pass) |
| 33 | + { |
| 34 | + assert(pipeline_layout_ != nullptr and "Cannot create pipeline before pipeline layout"); |
| 35 | + |
| 36 | + pipeline_config_info pipeline_config{}; |
| 37 | + pipeline::default_pipeline_config_info(pipeline_config); |
| 38 | + pipeline_config.attribute_descriptions.clear(); |
| 39 | + pipeline_config.binding_descriptions.clear(); |
| 40 | + pipeline_config.render_pass = render_pass; |
| 41 | + pipeline_config.pipeline_layout = pipeline_layout_; |
| 42 | + pipeline_ = std::make_unique<pipeline>( |
| 43 | + device_, |
| 44 | + "shaders/pbr.vert.spv", |
| 45 | + "shaders/pbr.frag.spv", |
| 46 | + pipeline_config); |
| 47 | + } |
| 48 | +} |
0 commit comments