2024-10-06 02:30:59 +08:00
|
|
|
|
#include<hgl/graph/MaterialRenderList.h>
|
|
|
|
|
#include<hgl/graph/RenderList.h>
|
2019-05-21 21:28:33 +08:00
|
|
|
|
#include<hgl/graph/SceneNode.h>
|
2024-10-06 02:30:59 +08:00
|
|
|
|
#include<hgl/graph/VK.h>
|
2020-10-21 11:43:18 +08:00
|
|
|
|
#include<hgl/graph/VKCommandBuffer.h>
|
2024-10-06 02:30:59 +08:00
|
|
|
|
#include<hgl/graph/VKMaterial.h>
|
2025-05-18 02:15:33 +08:00
|
|
|
|
#include<hgl/graph/Mesh.h>
|
2025-06-15 17:53:15 +08:00
|
|
|
|
#include<hgl/component/MeshComponent.h>
|
2021-06-19 20:31:07 +08:00
|
|
|
|
|
2019-05-21 21:28:33 +08:00
|
|
|
|
namespace hgl
|
|
|
|
|
{
|
|
|
|
|
namespace graph
|
|
|
|
|
{
|
2025-05-17 20:26:36 +08:00
|
|
|
|
RenderList::RenderList(VulkanDevice *dev)
|
2020-11-26 17:51:59 +08:00
|
|
|
|
{
|
2021-06-19 20:31:07 +08:00
|
|
|
|
device =dev;
|
2023-05-07 01:07:26 +08:00
|
|
|
|
renderable_count=0;
|
2024-08-02 23:17:07 +08:00
|
|
|
|
|
|
|
|
|
camera_info=nullptr;
|
2020-11-26 17:51:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-05-07 01:07:26 +08:00
|
|
|
|
bool RenderList::ExpendNode(SceneNode *sn)
|
2021-06-19 20:31:07 +08:00
|
|
|
|
{
|
|
|
|
|
if(!sn)return(false);
|
|
|
|
|
|
2025-06-14 21:05:36 +08:00
|
|
|
|
for(auto component:sn->GetComponents())
|
2021-06-19 20:31:07 +08:00
|
|
|
|
{
|
2025-06-15 17:53:15 +08:00
|
|
|
|
if(component->GetHashCode()!=MeshComponent::StaticHashCode()) //暂时只支持MeshComponent
|
2025-06-14 21:05:36 +08:00
|
|
|
|
continue;
|
|
|
|
|
|
2025-06-15 17:53:15 +08:00
|
|
|
|
MeshComponent *smc=reinterpret_cast<MeshComponent *>(component);
|
2025-06-14 21:05:36 +08:00
|
|
|
|
|
|
|
|
|
Mesh *mesh=smc->GetMesh();
|
|
|
|
|
|
|
|
|
|
RenderPipelineIndex rpi(mesh->GetMaterial(),mesh->GetPipeline());
|
2025-01-15 02:42:04 +08:00
|
|
|
|
|
2023-05-07 01:07:26 +08:00
|
|
|
|
MaterialRenderList *mrl;
|
2021-06-19 20:31:07 +08:00
|
|
|
|
|
2025-01-15 02:42:04 +08:00
|
|
|
|
if(!mrl_map.Get(rpi,mrl))
|
2023-05-07 01:07:26 +08:00
|
|
|
|
{
|
2025-01-15 02:42:04 +08:00
|
|
|
|
mrl=new MaterialRenderList(device,true,rpi);
|
2021-06-19 20:31:07 +08:00
|
|
|
|
|
2025-01-15 02:42:04 +08:00
|
|
|
|
mrl_map.Add(rpi,mrl);
|
2023-05-07 01:07:26 +08:00
|
|
|
|
}
|
2025-06-14 21:05:36 +08:00
|
|
|
|
|
|
|
|
|
mrl->Add(smc);
|
2021-06-19 20:31:07 +08:00
|
|
|
|
|
2023-05-07 01:07:26 +08:00
|
|
|
|
++renderable_count;
|
2021-06-19 20:31:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-10-06 16:49:08 +08:00
|
|
|
|
for(SceneNode *sub:sn->GetChildNode())
|
2023-05-07 01:07:26 +08:00
|
|
|
|
ExpendNode(sub);
|
2021-06-19 20:31:07 +08:00
|
|
|
|
|
|
|
|
|
return(true);
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-07 01:07:26 +08:00
|
|
|
|
bool RenderList::Expend(SceneNode *sn)
|
2021-06-19 20:31:07 +08:00
|
|
|
|
{
|
|
|
|
|
if(!device|!sn)return(false);
|
|
|
|
|
|
2024-08-02 23:17:07 +08:00
|
|
|
|
mrl_map.Begin(camera_info);
|
2023-05-07 01:07:26 +08:00
|
|
|
|
ExpendNode(sn);
|
|
|
|
|
mrl_map.End();
|
2021-06-19 20:31:07 +08:00
|
|
|
|
|
|
|
|
|
return(true);
|
2020-11-26 17:51:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-11-09 15:37:00 +08:00
|
|
|
|
bool RenderList::Render(RenderCmdBuffer *cb)
|
2019-05-27 16:54:08 +08:00
|
|
|
|
{
|
|
|
|
|
if(!cb)
|
2019-05-21 21:28:33 +08:00
|
|
|
|
return(false);
|
|
|
|
|
|
2023-05-07 01:07:26 +08:00
|
|
|
|
if(renderable_count<=0)
|
2021-06-15 15:36:30 +08:00
|
|
|
|
return(true);
|
|
|
|
|
|
2023-05-07 01:07:26 +08:00
|
|
|
|
mrl_map.Render(cb);
|
2019-05-21 21:28:33 +08:00
|
|
|
|
|
|
|
|
|
return(true);
|
|
|
|
|
}
|
2023-05-07 01:07:26 +08:00
|
|
|
|
|
|
|
|
|
void RenderList::Clear()
|
|
|
|
|
{
|
|
|
|
|
mrl_map.Clear();
|
|
|
|
|
}
|
2024-08-04 22:35:31 +08:00
|
|
|
|
|
2024-08-27 01:27:53 +08:00
|
|
|
|
void RenderList::UpdateLocalToWorld()
|
2024-08-04 22:35:31 +08:00
|
|
|
|
{
|
|
|
|
|
if(renderable_count<=0)
|
|
|
|
|
return;
|
|
|
|
|
|
2024-08-27 01:27:53 +08:00
|
|
|
|
mrl_map.UpdateLocalToWorld();
|
2024-08-04 22:35:31 +08:00
|
|
|
|
}
|
2024-08-30 03:36:01 +08:00
|
|
|
|
|
2025-06-15 17:53:15 +08:00
|
|
|
|
void RenderList::UpdateMaterialInstance(MeshComponent *smc)
|
2024-08-30 03:36:01 +08:00
|
|
|
|
{
|
2025-06-14 21:05:36 +08:00
|
|
|
|
if(!smc)return;
|
2024-08-30 03:36:01 +08:00
|
|
|
|
|
2025-06-14 21:05:36 +08:00
|
|
|
|
Mesh *ri=smc->GetMesh();
|
2024-08-30 03:36:01 +08:00
|
|
|
|
|
|
|
|
|
if(!ri)return;
|
|
|
|
|
|
2025-01-15 02:42:04 +08:00
|
|
|
|
RenderPipelineIndex rli(ri->GetMaterial(),ri->GetPipeline());
|
2024-08-30 03:36:01 +08:00
|
|
|
|
MaterialRenderList *mrl;
|
|
|
|
|
|
2025-01-15 02:42:04 +08:00
|
|
|
|
if(!mrl_map.Get(rli,mrl)) //找到对应的
|
2024-08-30 03:36:01 +08:00
|
|
|
|
return;
|
|
|
|
|
|
2025-06-14 21:05:36 +08:00
|
|
|
|
mrl->UpdateMaterialInstance(smc);
|
2024-08-30 03:36:01 +08:00
|
|
|
|
}
|
2019-05-21 21:28:33 +08:00
|
|
|
|
}//namespace graph
|
|
|
|
|
}//namespace hgl
|