Vulkan Engine 0.0
A simple Vulkan engine demo
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
offscreen_render_system.hpp
Go to the documentation of this file.
1#pragma once
2
4#include "engine_pipeline.hpp"
5
6#include <memory>
7
8
16private:
17 EngineDevice &device;
19 std::unique_ptr<EnginePipeline> pipeline;
20 VkPipelineLayout pipeline_layout;
21 std::string frag_path;
22
23 void create_pipeline_layout() {
24 VkPipelineLayoutCreateInfo pipeline_layout_info{};
25 pipeline_layout_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
26 std::vector<VkDescriptorSetLayout> descriptor_sets_layouts{};
27 descman.get_fullscreen_layouts(descriptor_sets_layouts);
28 pipeline_layout_info.setLayoutCount = descriptor_sets_layouts.size();
29 pipeline_layout_info.pSetLayouts = descriptor_sets_layouts.data();
30 pipeline_layout_info.pushConstantRangeCount = 0;
31 pipeline_layout_info.pPushConstantRanges = nullptr;
32
33 if (vkCreatePipelineLayout(
34 device.device(), &pipeline_layout_info, nullptr, &pipeline_layout
35 ) != VK_SUCCESS) {
36 throw std::runtime_error("failed to create pipeline layout");
37 }
38 }
39
40 void create_pipeline(VkRenderPass render_pass, uint32_t subpass=0) {
41 assert(pipeline_layout != nullptr && "Cannot create pipeline before pipeline layout");
42
43 PipelineConfigInfo pipeline_config{};
45 pipeline_config.render_pass = render_pass;
46 pipeline_config.pipeline_layout = pipeline_layout;
47 pipeline_config.subpass = subpass;
48 std::vector<PipelineShaderData> shaders_data = {
49 {
50 SHADERS_DIR+"/fullscreen.vert.spv",
51 VK_SHADER_STAGE_VERTEX_BIT
52 },
53 {
54 frag_path,
55 VK_SHADER_STAGE_FRAGMENT_BIT
56 }
57 };
58
59 VkPipelineVertexInputStateCreateInfo emptyInputState;
60 emptyInputState.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
61 emptyInputState.vertexAttributeDescriptionCount = 0;
62 emptyInputState.pVertexAttributeDescriptions = nullptr;
63 emptyInputState.vertexBindingDescriptionCount = 0;
64 emptyInputState.pVertexBindingDescriptions = nullptr;
65
66 pipeline = std::make_unique<EnginePipeline>(
67 device,
68 shaders_data,
69 pipeline_config,
70 emptyInputState
71 );
72 }
73
74public:
75
77 EngineDevice &device,
79 VkRenderPass render_pass,
80 std::string frag_path,
81 uint32_t subpass=0
82 ) : device{device}, descman{descman}, frag_path{frag_path} {
83 create_pipeline_layout();
84 create_pipeline(render_pass, subpass);
85 }
86
88 vkDestroyPipelineLayout(device.device(), pipeline_layout, nullptr);
89 }
90
91 // RAII
94
95 void render(
96 VkCommandBuffer command_buffer, Offscreen &source_offscreen
97 ) {
98 pipeline->bind(command_buffer);
99 descman.bind_fullscreen_descriptor_set(command_buffer, pipeline_layout, source_offscreen);
100 vkCmdDraw(command_buffer, 3, 1, 0, 0);
101 }
102};
Mega-class responsible for handling everything to do with descriptors.
Definition: engine_descriptors.hpp:23
void bind_fullscreen_descriptor_set(VkCommandBuffer command_buffer, VkPipelineLayout pipeline_layout, Offscreen &offscreen)
Definition: engine_descriptors.hpp:454
void get_fullscreen_layouts(std::vector< VkDescriptorSetLayout > &layouts)
Definition: engine_descriptors.hpp:402
Abstraction around VkDevice, managing everything to do with the physical and logical device,...
Definition: engine_device.hpp:109
VkDevice device()
Definition: engine_device.hpp:482
static void default_pipeline_config_info(PipelineConfigInfo &config_info)
Definition: engine_pipeline.hpp:207
Render System used to run render passes that require data from off screen render targets,...
Definition: offscreen_render_system.hpp:15
void render(VkCommandBuffer command_buffer, Offscreen &source_offscreen)
Definition: offscreen_render_system.hpp:95
OffscreenRenderSystem & operator=(const OffscreenRenderSystem &)=delete
~OffscreenRenderSystem()
Definition: offscreen_render_system.hpp:87
OffscreenRenderSystem(EngineDevice &device, EngineDescriptorManager &descman, VkRenderPass render_pass, std::string frag_path, uint32_t subpass=0)
Definition: offscreen_render_system.hpp:76
OffscreenRenderSystem(const OffscreenRenderSystem &)=delete
Off screen render target.
Definition: offscreen.hpp:15
Definition: engine_pipeline.hpp:13