SpiecsEngine
 
Loading...
Searching...
No Matches
WorldPickRenderer.cpp
Go to the documentation of this file.
1/**
2* @file WorldPickRenderer.cpp.
3* @brief The WorldPickRenderer Class Implementation.
4* @author Spices.
5*/
6
7#include "Pchheader.h"
9#include "World/Components/EntityComponent.h"
10
11namespace Spices {
12
14 {
16
17 RendererPassBuilder{ "WorldPick", this }
18 .AddSubPass("WorldPick")
19 .AddColorAttachment("SelectBuffer", TextureType::Texture2D, [](bool& isEnableBlend, VkAttachmentDescription& description) {
20 description.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
21 description.finalLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
22 description.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
23 description.format = VK_FORMAT_R32_SFLOAT;
24 })
27 }
28
30 {
32
33 DescriptorSetBuilder{ "WorldPick", this }
34 .AddPushConstant(sizeof(uint64_t))
35 .Build();
36 }
37
39 std::shared_ptr<Material> material ,
40 VkPipelineLayout& layout ,
41 std::shared_ptr<RendererSubPass> subPass
42 )
43 {
45
46 PipelineBuilder{ subPass, material, this }
47 .SetDefault()
48 .SetRenderPass()
49 .SetSubPassIndex()
50 .SetPipelineLayout(layout)
51 .SetCullMode(VK_CULL_MODE_NONE)
52 .SetColorAttachments()
53 .Build();
54 }
55
57 {
59
60 RenderBehaveBuilder builder{ this ,frameInfo.m_FrameIndex, frameInfo.m_ImageIndex };
61
62 builder.BeginRenderPass();
63
64 builder.BindDescriptorSet(DescriptorSetManager::GetByName("PreRenderer"));
65
66 builder.BindDescriptorSet(DescriptorSetManager::GetByName({ m_Pass->GetName(), "WorldPick" }));
67
68 static std::function<void(Entity)> drawSelected = [&](Entity e) {
69
70 if (e.HasComponent<MeshComponent>())
71 {
72 MeshComponent& meshComp = e.GetComponent<MeshComponent>();
73
74 meshComp.GetMesh()->Draw(m_VulkanState.m_GraphicCommandBuffer[frameInfo.m_FrameIndex], [&](uint32_t meshpackId, auto meshPack) {
75 builder.BindPipeline("WorldPickRenderer.WorldPick.Default");
76
77 builder.UpdatePushConstant<uint64_t>([&](auto& push) {
78 push = meshPack->GetMeshDesc().GetBufferAddress();
79 });
80 });
81 }
82
83 if (e.HasComponent<SpriteComponent>())
84 {
85 SpriteComponent& meshComp = e.GetComponent<SpriteComponent>();
86
87 meshComp.GetMesh()->Draw(m_VulkanState.m_GraphicCommandBuffer[frameInfo.m_FrameIndex], [&](uint32_t meshpackId, auto meshPack) {
88 builder.BindPipeline("WorldPickRenderer.WorldPick.Default");
89
90 builder.UpdatePushConstant<uint64_t>([&](auto& push) {
91 push = meshPack->GetMeshDesc().GetBufferAddress();
92 });
93 });
94 }
95 };
96
97 frameInfo.m_PickEntityID.for_each([&](const auto& k, const auto& v) {
98
99 Entity e = frameInfo.m_World->QueryEntitybyID(k);
100
101 drawSelected(e);
102
103 if (e.HasComponent<EntityComponent>())
104 {
105 EntityComponent& entityComp = e.GetComponent<EntityComponent>();
106
107 for (auto& entity : entityComp.GetEntities())
108 {
109 Entity child = frameInfo.m_World->QueryEntitybyID(entity);
110 drawSelected(child);
111 }
112 }
113
114 return false;
115 });
116
117 builder.EndRenderPass();
118 }
119}
#define SPICES_PROFILE_ZONE
EntityComponent Class. This class defines the specific behaves of EntityComponent.
Entity Class. This class defines the specific behaves of Entity.
Definition Entity.h:20
uint32_t m_FrameIndex
FrameIndex, varying during 0 - (MaxFrameInFlight - 1). Used almost anywhere.
Definition FrameInfo.h:69
uint32_t m_ImageIndex
ImageIndex, varying during 0 - (MaxFrameInFlight - 1). Used in swapchain index and framebuffer index.
Definition FrameInfo.h:75
FrameInfo Class. This class defines the FrameInfo data.
Definition FrameInfo.h:32
Material Class. This class contains a branch of parameter and shader, also descriptor.
Definition Material.h:62
This Class Combines some data relative to sub pass. Usually as a member variable of RendererPass.
DescriptorSetBuilder & AddPushConstant(uint32_t size)
Set VkPushConstantRange by a specific push constant struct.
virtual void BeginRenderPass()
Begin this Renderer's RenderPass.
Definition Renderer.cpp:840
virtual void EndRenderPass()
End this Renderer's RenderPass.
Definition Renderer.cpp:981
This class helps to bind pipeline and bind buffer. Only instanced during Render().
Definition Renderer.h:985
RendererPassBuilder & EndSubPass()
End recording a sub pass.
void Build() const
Build the RendererPass.
RendererPassBuilder & AddSubPass(const std::string &subPassName, Querier::StatisticsFlags flags=Querier::ALL)
Add a new SubPass to Renderer Pass.
This Class handles our engine time step during frames. Global Unique.
Definition TimeStep.h:22
virtual void CreateDescriptorSet() override
The interface is inherited from Renderer. Create specific descriptor set for sub pass.
virtual void Render(TimeStep &ts, FrameInfo &frameInfo) override
The interface is inherited from Renderer.
virtual void CreatePipeline(std::shared_ptr< Material > material, VkPipelineLayout &layout, std::shared_ptr< RendererSubPass > subPass) override
The interface is inherited from Renderer. Create Material Specific Pipeline.
virtual void CreateRendererPass() override
The interface is inherited from Renderer. Create specific render pass.
WorldPickRenderer Class. This class defines the picked entity render behaves.
TextureType
The enum of all Texture Type.
Definition Texture.h:20