ULRE/src/SceneGraph/RenderList.cpp

113 lines
2.9 KiB
C++
Raw Normal View History

2019-05-25 00:50:04 +08:00
#include<hgl/graph/RenderList.h>
#include<hgl/graph/Camera.h>
2019-05-21 21:28:33 +08:00
#include<hgl/graph/SceneNode.h>
#include<hgl/graph/VKRenderable.h>
#include<hgl/graph/VKCommandBuffer.h>
#include<hgl/graph/VertexAttribDataAccess.h>
#include<hgl/graph/VKMaterialInstance.h>
#include<hgl/graph/VKRenderableInstance.h>
2019-05-25 00:50:04 +08:00
2019-05-21 21:28:33 +08:00
namespace hgl
{
namespace graph
{
2019-05-24 21:43:59 +08:00
float CameraLengthComp(Camera *cam,SceneNode *obj_one,SceneNode *obj_two)
2019-05-21 21:28:33 +08:00
{
if(!cam||!obj_one||!obj_two)
return(0);
2019-05-24 21:43:59 +08:00
return( length_squared(obj_one->GetCenter(),cam->eye)-
2019-05-21 21:28:33 +08:00
length_squared(obj_two->GetCenter(),cam->eye));
}
2019-05-24 21:43:59 +08:00
//bool FrustumClipFilter(const SceneNode *node,void *fc)
//{
// if(!node||!fc)return(false);
2019-05-21 21:28:33 +08:00
2019-05-24 21:43:59 +08:00
// return (((Frustum *)fc)->BoxIn(node->GetWorldBoundingBox())!=Frustum::OUTSIDE);
//}
2019-05-21 21:28:33 +08:00
void RenderList::Render(SceneNode *node,vulkan::RenderableInstance *ri)
2019-05-21 21:28:33 +08:00
{
2019-05-25 00:50:04 +08:00
if(last_pipeline!=ri->GetPipeline())
{
last_pipeline=ri->GetPipeline();
cmd_buf->BindPipeline(last_pipeline);
last_mat_inst=nullptr;
2019-05-25 00:50:04 +08:00
}
if(last_mat_inst!=ri->GetMaterialInstance())
2019-05-25 00:50:04 +08:00
{
last_mat_inst=ri->GetMaterialInstance();
cmd_buf->BindDescriptorSets(last_mat_inst->GetDescriptorSets());
}
if(last_pc!=node->GetPushConstant())
{
last_pc=node->GetPushConstant();
cmd_buf->PushConstants(last_pc,sizeof(vulkan::PushConstant));
2019-05-25 00:50:04 +08:00
}
//更新fin_mvp
if(ri!=last_ri)
2019-05-25 00:50:04 +08:00
{
cmd_buf->BindVAB(ri);
2019-05-25 00:50:04 +08:00
last_ri=ri;
2019-05-25 00:50:04 +08:00
}
const vulkan::IndexBuffer *ib=ri->GetIndexBuffer();
2019-05-25 00:50:04 +08:00
if(ib)
{
cmd_buf->DrawIndexed(ib->GetCount());
}
else
{
cmd_buf->Draw(ri->GetDrawCount());
2019-05-25 00:50:04 +08:00
}
}
void RenderList::Render(SceneNode *node,List<vulkan::RenderableInstance *> &ri_list)
2019-05-25 00:50:04 +08:00
{
const int count=ri_list.GetCount();
vulkan::RenderableInstance **ri=ri_list.GetData();
for(int i=0;i<count;i++)
{
Render(node,*ri);
++ri;
}
}
2020-10-21 12:39:22 +08:00
bool RenderList::Render(vulkan::GPUCmdBuffer *cb)
{
if(!cb)
2019-05-21 21:28:33 +08:00
return(false);
cmd_buf=cb;
2019-05-25 00:50:04 +08:00
last_pipeline=nullptr;
last_mat_inst=nullptr;
last_ri=nullptr;
last_pc=nullptr;
2019-05-25 00:50:04 +08:00
const int count=scene_node_list.GetCount();
SceneNode **node=scene_node_list.GetData();
2019-05-21 21:28:33 +08:00
for(int i=0;i<count;i++)
{
Render(*node,(*node)->renderable_instances);
++node;
2019-05-21 21:28:33 +08:00
}
return(true);
}
}//namespace graph
}//namespace hgl