Skip to content

Commit d91f763

Browse files
committed
Simplify systems by inheriting from i_system
Add initial pbr system
1 parent 78bd081 commit d91f763

15 files changed

+171
-90
lines changed

VulkanTutorial.vcxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
</ItemGroup>
2121
<ItemGroup>
2222
<ClCompile Include="src\app.cpp" />
23+
<ClCompile Include="src\systems\i_system.cpp" />
24+
<ClCompile Include="src\systems\pbr_system.cpp" />
2325
<ClCompile Include="src\texture.cpp" />
2426
<ClCompile Include="src\movement_controller.cpp" />
2527
<ClCompile Include="src\buffer.cpp" />
@@ -114,6 +116,8 @@
114116
</ItemGroup>
115117
<ItemGroup>
116118
<ClInclude Include="src\app.h" />
119+
<ClInclude Include="src\systems\i_system.h" />
120+
<ClInclude Include="src\systems\pbr_system.h" />
117121
<ClInclude Include="src\texture.h" />
118122
<ClInclude Include="src\movement_controller.h" />
119123
<ClInclude Include="src\buffer.h" />
@@ -136,6 +140,8 @@
136140
<Content Include="CMakeLists.txt" />
137141
<Content Include="compile.bat" />
138142
<Content Include=".env.cmake" />
143+
<Content Include="shaders\pbr.frag" />
144+
<Content Include="shaders\pbr.vert" />
139145
<Content Include="shaders\shader_2d.frag" />
140146
<Content Include="shaders\shader_2d.vert" />
141147
<Content Include="shaders\point_light.frag" />

compile.bat

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ C:\VulkanSDK\1.3.261.1\Bin\glslc.exe shaders\shader_3d.vert -o shaders\shader_3d
44
C:\VulkanSDK\1.3.261.1\Bin\glslc.exe shaders\shader_3d.frag -o shaders\shader_3d.frag.spv
55
C:\VulkanSDK\1.3.261.1\Bin\glslc.exe shaders\point_light.vert -o shaders\point_light.vert.spv
66
C:\VulkanSDK\1.3.261.1\Bin\glslc.exe shaders\point_light.frag -o shaders\point_light.frag.spv
7+
C:\VulkanSDK\1.3.261.1\Bin\glslc.exe shaders\pbr.vert -o shaders\pbr.vert.spv
8+
C:\VulkanSDK\1.3.261.1\Bin\glslc.exe shaders\pbr.frag -o shaders\pbr.frag.spv
79
pause

shaders/pbr.frag

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#version 450
2+
3+
void main()
4+
{
5+
6+
}

shaders/pbr.vert

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#version 450
2+
3+
void main()
4+
{
5+
6+
}

src/pipeline.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#include <vector>
66
#include <vulkan/vulkan_core.h>
77

8-
98
namespace dae
109
{
1110
// Forward declarations

src/systems/i_system.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include "i_system.h"
2+
3+
namespace dae
4+
{
5+
i_system::i_system(device &device)
6+
: device_(device)
7+
{
8+
}
9+
10+
i_system::~i_system()
11+
{
12+
vkDestroyPipelineLayout(device_.get_logical_device(), pipeline_layout_, nullptr);
13+
}
14+
}

src/systems/i_system.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#pragma once
2+
3+
// Project includes
4+
#include "../frame_info.h"
5+
#include "../pipeline.h"
6+
7+
// Standard includes
8+
#include <memory>
9+
10+
namespace dae
11+
{
12+
class i_system
13+
{
14+
public:
15+
explicit i_system(device &device);
16+
virtual ~i_system();
17+
18+
i_system(i_system const &other) = delete;
19+
i_system(i_system &&other) = delete;
20+
i_system &operator=(i_system const &other) = delete;
21+
i_system &operator=(i_system &&other) = delete;
22+
23+
protected:
24+
virtual void create_pipeline_layout(VkDescriptorSetLayout global_set_layout) = 0;
25+
virtual void create_pipeline(VkRenderPass render_pass) = 0;
26+
27+
protected:
28+
device &device_;
29+
30+
std::unique_ptr<pipeline> pipeline_;
31+
VkPipelineLayout pipeline_layout_ = VK_NULL_HANDLE;
32+
};
33+
}

src/systems/pbr_system.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
}

src/systems/pbr_system.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#pragma once
2+
3+
// Project includes
4+
#include "i_system.h"
5+
6+
namespace dae
7+
{
8+
class pbr_system final : public i_system
9+
{
10+
public:
11+
pbr_system(device &device, VkRenderPass render_pass, VkDescriptorSetLayout global_set_layout);
12+
~pbr_system() override = default;
13+
14+
pbr_system(pbr_system const &other) = delete;
15+
pbr_system(pbr_system &&other) = delete;
16+
pbr_system &operator=(pbr_system const &other) = delete;
17+
pbr_system &operator=(pbr_system &&other) = delete;
18+
19+
protected:
20+
void create_pipeline_layout(VkDescriptorSetLayout global_set_layout) override;
21+
void create_pipeline(VkRenderPass render_pass) override;
22+
};
23+
}

src/systems/point_light_system.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,12 @@ namespace dae
2222
};
2323

2424
point_light_system::point_light_system(device& device, VkRenderPass render_pass, VkDescriptorSetLayout global_set_layout)
25-
: device_{device}
25+
: i_system{device}
2626
{
2727
create_pipeline_layout(global_set_layout);
2828
create_pipeline(render_pass);
2929
}
3030

31-
point_light_system::~point_light_system()
32-
{
33-
vkDestroyPipelineLayout(device_.get_logical_device(), pipeline_layout_, nullptr);
34-
}
35-
3631
void point_light_system::update(frame_info &frame_info, global_ubo &ubo)
3732
{
3833
auto rotate_light = glm::rotate(

0 commit comments

Comments
 (0)