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>
|
2022-06-24 21:06:38 +08:00
|
|
|
|
#include<hgl/graph/VKRenderable.h>
|
2021-06-19 20:31:07 +08:00
|
|
|
|
|
2019-05-21 21:28:33 +08:00
|
|
|
|
namespace hgl
|
|
|
|
|
{
|
|
|
|
|
namespace graph
|
|
|
|
|
{
|
2021-06-19 20:31:07 +08:00
|
|
|
|
RenderList::RenderList(GPUDevice *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);
|
|
|
|
|
|
2022-06-24 21:06:38 +08:00
|
|
|
|
Renderable *ri=sn->GetRenderable();
|
2021-06-19 20:31:07 +08:00
|
|
|
|
|
|
|
|
|
if(ri)
|
|
|
|
|
{
|
2023-05-07 01:07:26 +08:00
|
|
|
|
Material *mtl=ri->GetMaterial();
|
|
|
|
|
MaterialRenderList *mrl;
|
2021-06-19 20:31:07 +08:00
|
|
|
|
|
2023-05-07 01:07:26 +08:00
|
|
|
|
if(!mrl_map.Get(mtl,mrl))
|
|
|
|
|
{
|
2024-03-26 01:20:20 +08:00
|
|
|
|
mrl=new MaterialRenderList(device,true,mtl);
|
2021-06-19 20:31:07 +08:00
|
|
|
|
|
2023-05-07 01:07:26 +08:00
|
|
|
|
mrl_map.Add(mtl,mrl);
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-20 13:15:12 +08:00
|
|
|
|
mrl->Add(sn);
|
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
|
|
|
|
|
|
|
|
|
void RenderList::UpdateMaterialInstance(SceneNode *sn)
|
|
|
|
|
{
|
|
|
|
|
if(!sn)return;
|
|
|
|
|
|
|
|
|
|
Renderable *ri=sn->GetRenderable();
|
|
|
|
|
|
|
|
|
|
if(!ri)return;
|
|
|
|
|
|
|
|
|
|
Material *mtl=ri->GetMaterial();
|
|
|
|
|
MaterialRenderList *mrl;
|
|
|
|
|
|
|
|
|
|
if(!mrl_map.Get(mtl,mrl)) //找到对应的
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
mrl->UpdateMaterialInstance(sn);
|
|
|
|
|
}
|
2019-05-21 21:28:33 +08:00
|
|
|
|
}//namespace graph
|
|
|
|
|
}//namespace hgl
|