18
18
namespace ts
19
19
{
20
20
class Renderer ;
21
- class LightRenderSystem ;
22
21
23
22
class RenderSystem : public System
24
23
{
@@ -28,32 +27,73 @@ class RenderSystem : public System
28
27
{
29
28
requireComponent<RendererComponentBase>();
30
29
31
- gRegistry .addSystem <LightRenderSystem >();
30
+ gRegistry .addSystem <Lights >();
32
31
}
33
32
34
33
void update (const VkCommandBuffer cmdBuf, const VkDescriptorSet descriptorSet)
35
34
{
36
- size_t entityIndexforUniformBufferOffset{};
37
- const auto uniformBufferOffset = static_cast <uint32_t >(
38
- khronos_utils::align (
39
- static_cast <VkDeviceSize>(sizeof (decltype (RenderProcess::mIndividualUniformData )::value_type)),
40
- mVkUniformBufferOffsetAlignment ) * static_cast <VkDeviceSize>(entityIndexforUniformBufferOffset));
41
-
42
35
for (const auto entity : getSystemEntities ())
43
36
{
44
- if (entity.hasComponent <MeshComponent>() && (!entity.hasComponent <RendererComponent<PipelineType::PBR>>()))
37
+ size_t entityIndexforUniformBufferOffset{};
38
+ const auto uniformBufferOffset = static_cast <uint32_t >(
39
+ khronos_utils::align (
40
+ static_cast <VkDeviceSize>(sizeof (decltype (RenderProcess::mIndividualUniformData )::value_type)),
41
+ mVkUniformBufferOffsetAlignment ) * static_cast <VkDeviceSize>(entityIndexforUniformBufferOffset));
42
+
43
+ vkCmdBindDescriptorSets (
44
+ cmdBuf,
45
+ VK_PIPELINE_BIND_POINT_GRAPHICS,
46
+ mpPipelineLayout,
47
+ 0 ,
48
+ 1 ,
49
+ &descriptorSet,
50
+ 1 ,
51
+ &uniformBufferOffset);
52
+
53
+ if (!entity.hasComponent <TransformComponent>())
54
+ {
55
+ vkCmdPushConstants (cmdBuf,
56
+ mpPipelineLayout,
57
+ VK_SHADER_STAGE_VERTEX_BIT,
58
+ 0 ,
59
+ sizeof (math::Vec3),
60
+ &entity.getComponent <TransformComponent>().pos );
61
+ }
62
+
63
+ if (entity.hasComponent <MeshComponent>())
45
64
{
46
65
TS_ASSERT (!entity.hasComponent <RendererComponent<PipelineType::COLOR>>(), " Not implemented yet" );
47
66
48
67
const auto & mesh = entity.getComponent <MeshComponent>();
49
68
50
- if (const auto pipe = mpNormalLightingPipeline. lock ())
69
+ if (entity. hasComponent <RendererComponent<PipelineType::NORMAL_LIGHTING>> ())
51
70
{
52
- pipe->bind (cmdBuf);
71
+ if (const auto pipe = mpNormalLightingPipeline.lock ())
72
+ {
73
+ pipe->bind (cmdBuf);
74
+ }
75
+ else
76
+ {
77
+ throw Exception{ " Invalid normal lighting pipeline" };
78
+ }
53
79
}
54
- else
80
+ else if (entity. hasComponent <RendererComponent<PipelineType::PBR>>())
55
81
{
56
- throw Exception{" Invalid normal lighting pipeline" };
82
+ if (const auto pipe = mpPbrPipeline.lock ())
83
+ {
84
+ pipe->bind (cmdBuf);
85
+ }
86
+ else
87
+ {
88
+ throw Exception{ " Invalid pbr pipeline" };
89
+ }
90
+
91
+ vkCmdPushConstants (cmdBuf,
92
+ mpPipelineLayout,
93
+ VK_SHADER_STAGE_FRAGMENT_BIT,
94
+ sizeof (math::Vec3),
95
+ sizeof (RendererComponent<PipelineType::PBR>::Material),
96
+ &entity.getComponent <RendererComponent<PipelineType::PBR>>().material );
57
97
}
58
98
59
99
vkCmdDrawIndexed (cmdBuf,
@@ -63,24 +103,6 @@ class RenderSystem : public System
63
103
0 ,
64
104
0 );
65
105
}
66
- else if (entity.hasComponent <RendererComponent<PipelineType::PBR>>())
67
- {
68
- if (const auto pipe = mpPbrPipeline.lock ())
69
- {
70
- pipe->bind (cmdBuf);
71
- }
72
- else
73
- {
74
- throw Exception{" Invalid pbr pipeline" };
75
- }
76
-
77
- vkCmdPushConstants (cmdBuf,
78
- mpPipelineLayout,
79
- VK_SHADER_STAGE_FRAGMENT_BIT,
80
- sizeof (math::Vec3),
81
- sizeof (RendererComponent<PipelineType::PBR>::Material),
82
- &entity.getComponent <RendererComponent<PipelineType::PBR>>().material );
83
- }
84
106
else if (entity.hasComponent <RendererComponent<PipelineType::LIGHT>>())
85
107
{
86
108
if (const auto pipe = mpLightCubePipeline.lock ())
@@ -111,47 +133,23 @@ class RenderSystem : public System
111
133
{
112
134
TS_ERR (" Unexpected rendering workflow" );
113
135
}
114
-
115
- if (!entity.hasComponent <RendererComponent<PipelineType::GRID>>())
116
- {
117
- TS_ASSERT (entity.hasComponent <TransformComponent>(), " TransformComponent is missing" );
118
-
119
- vkCmdPushConstants (cmdBuf,
120
- mpPipelineLayout,
121
- VK_SHADER_STAGE_VERTEX_BIT,
122
- 0 ,
123
- sizeof (math::Vec3),
124
- &entity.getComponent <TransformComponent>().pos );
125
- }
126
-
127
-
128
-
129
- vkCmdBindDescriptorSets (
130
- cmdBuf,
131
- VK_PIPELINE_BIND_POINT_GRAPHICS,
132
- mpPipelineLayout,
133
- 0 ,
134
- 1 ,
135
- &descriptorSet,
136
- 1 ,
137
- &uniformBufferOffset);
138
136
}
139
137
}
140
138
139
+ class Lights : public System
140
+ {
141
+ public:
142
+ Lights ()
143
+ {
144
+ requireComponent<RendererComponent<PipelineType::LIGHT>>();
145
+ }
146
+
147
+ };
148
+
141
149
private:
142
150
friend Renderer;
143
151
const VkDeviceSize& mVkUniformBufferOffsetAlignment ;
144
152
std::weak_ptr<Pipeline> mpGridPipeline, mpNormalLightingPipeline, mpPbrPipeline, mpLightCubePipeline;
145
153
VkPipelineLayout mpPipelineLayout{};
146
154
};
147
-
148
- class LightRenderSystem : public System
149
- {
150
- public:
151
- LightRenderSystem ()
152
- {
153
- requireComponent<RendererComponent<PipelineType::LIGHT>>();
154
- }
155
-
156
- };
157
155
}
0 commit comments