vengine  0.1.0
3D graphics engine made with Vulkan
Loading...
Searching...
No Matches
renderSystem.cpp
Go to the documentation of this file.
3
4
5ven::RenderSystem::RenderSystem(Device& device, const VkRenderPass renderPass,const VkDescriptorSetLayout globalSetLayout) : m_device{device}
6{
7 createPipelineLayout(globalSetLayout);
8 createPipeline(renderPass);
9}
10
11void ven::RenderSystem::createPipelineLayout(const VkDescriptorSetLayout globalSetLayout)
12{
13 VkPushConstantRange pushConstantRange{};
14 pushConstantRange.stageFlags = VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT;
15 pushConstantRange.offset = 0;
16 pushConstantRange.size = sizeof(SimplePushConstantData);
17
18 const std::vector<VkDescriptorSetLayout> descriptorSetLayouts{globalSetLayout};
19
20 VkPipelineLayoutCreateInfo pipelineLayoutInfo{};
21 pipelineLayoutInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
22 pipelineLayoutInfo.setLayoutCount = static_cast<uint32_t>(descriptorSetLayouts.size());
23 pipelineLayoutInfo.pSetLayouts = descriptorSetLayouts.data();
24 pipelineLayoutInfo.pushConstantRangeCount = 1;
25 pipelineLayoutInfo.pPushConstantRanges = &pushConstantRange;
26 if (vkCreatePipelineLayout(m_device.device(), &pipelineLayoutInfo, nullptr, &m_pipelineLayout) != VK_SUCCESS)
27 {
28 throw std::runtime_error("Failed to create pipeline layout");
29 }
30}
31
32void ven::RenderSystem::createPipeline(const VkRenderPass renderPass)
33{
34 PipelineConfigInfo pipelineConfig{};
36 pipelineConfig.renderPass = renderPass;
37 pipelineConfig.pipelineLayout = m_pipelineLayout;
38 m_shaders = std::make_unique<Shaders>(m_device, std::string(SHADERS_BIN_PATH) + "shader_vert.spv", std::string(SHADERS_BIN_PATH) + "shader_frag.spv", pipelineConfig);
39}
40
41void ven::RenderSystem::renderObjects(const FrameInfo &frameInfo) const
42{
43 m_shaders->bind(frameInfo.commandBuffer);
44
45 vkCmdBindDescriptorSets(frameInfo.commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, m_pipelineLayout, 0, 1, &frameInfo.globalDescriptorSet, 0, nullptr);
46
47 for (auto &kv : frameInfo.objects)
48 {
49 Object &object = kv.second;
50 if (object.model == nullptr) continue;
52 push.modelMatrix = object.transform3D.mat4();
53 push.normalMatrix = object.transform3D.normalMatrix();
54 vkCmdPushConstants(frameInfo.commandBuffer, m_pipelineLayout, VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT, 0, sizeof(SimplePushConstantData), &push);
55 object.model->bind(frameInfo.commandBuffer);
56 object.model->draw(frameInfo.commandBuffer);
57 }
58}
This file contains the constant values used in the project.
This file contains the RenderSystem class.
void createPipelineLayout(VkDescriptorSetLayout globalSetLayout)
void renderObjects(const FrameInfo &frameInfo) const
RenderSystem(Device &device, VkRenderPass renderPass, VkDescriptorSetLayout globalSetLayout)
void createPipeline(VkRenderPass renderPass)
static void defaultPipelineConfigInfo(PipelineConfigInfo &configInfo)
Definition shaders.cpp:112
static constexpr std::string_view SHADERS_BIN_PATH
Definition Constant.hpp:15
Object::Map & objects
Definition FrameInfo.hpp:41
VkCommandBuffer commandBuffer
Definition FrameInfo.hpp:38
VkDescriptorSet globalDescriptorSet
Definition FrameInfo.hpp:40