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>
|
2020-12-18 16:52:45 +08:00
|
|
|
|
#include<hgl/graph/VKDevice.h>
|
2021-04-26 20:36:56 +08:00
|
|
|
|
#include<hgl/graph/VKBuffer.h>
|
2020-10-21 11:43:18 +08:00
|
|
|
|
#include<hgl/graph/VKRenderable.h>
|
|
|
|
|
#include<hgl/graph/VKCommandBuffer.h>
|
2020-07-16 20:36:54 +08:00
|
|
|
|
#include<hgl/graph/VertexAttribDataAccess.h>
|
2020-10-21 11:43:18 +08:00
|
|
|
|
#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
|
|
|
|
|
{
|
2021-01-29 20:50:47 +08:00
|
|
|
|
constexpr size_t MVPMatrixBytes=sizeof(MVPMatrix);
|
2020-12-18 16:52:45 +08:00
|
|
|
|
|
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
|
|
|
|
|
2020-12-18 16:52:45 +08:00
|
|
|
|
RenderList::RenderList(GPUDevice *gd)
|
2020-11-26 17:51:59 +08:00
|
|
|
|
{
|
2020-12-18 16:52:45 +08:00
|
|
|
|
device =gd;
|
2020-11-26 17:51:59 +08:00
|
|
|
|
cmd_buf =nullptr;
|
|
|
|
|
|
|
|
|
|
last_pipeline =nullptr;
|
|
|
|
|
last_ri =nullptr;
|
2020-12-18 16:52:45 +08:00
|
|
|
|
|
2021-04-26 20:36:56 +08:00
|
|
|
|
mvp_array =new MVPArrayBuffer(gd,VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
|
2020-12-18 16:52:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RenderList::~RenderList()
|
|
|
|
|
{
|
2021-01-29 20:50:47 +08:00
|
|
|
|
delete mvp_array;
|
2020-11-26 17:51:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RenderList::Begin()
|
|
|
|
|
{
|
|
|
|
|
scene_node_list.ClearData();
|
|
|
|
|
|
2021-04-26 20:36:56 +08:00
|
|
|
|
mvp_array->Clear();
|
|
|
|
|
mvp_offset.ClearData();
|
|
|
|
|
|
2020-11-26 17:51:59 +08:00
|
|
|
|
last_pipeline =nullptr;
|
|
|
|
|
last_ri =nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RenderList::Add(SceneNode *node)
|
|
|
|
|
{
|
|
|
|
|
if(!node)return;
|
|
|
|
|
|
|
|
|
|
scene_node_list.Add(node);
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-11 20:45:00 +08:00
|
|
|
|
void RenderList::End(CameraInfo *camera_info)
|
2020-11-26 17:51:59 +08:00
|
|
|
|
{
|
2020-12-18 16:52:45 +08:00
|
|
|
|
//清0计数器
|
2021-01-29 20:50:47 +08:00
|
|
|
|
uint32_t mvp_count=0; //local to world矩阵总数量
|
2020-12-18 16:52:45 +08:00
|
|
|
|
|
|
|
|
|
//统计Render
|
2020-12-09 21:33:29 +08:00
|
|
|
|
const uint32_t count=scene_node_list.GetCount();
|
|
|
|
|
|
2021-04-26 20:36:56 +08:00
|
|
|
|
mvp_array->Alloc(count);
|
|
|
|
|
mvp_array->Clear();
|
2020-12-18 16:52:45 +08:00
|
|
|
|
|
2021-04-26 20:36:56 +08:00
|
|
|
|
mvp_offset.PreMalloc(count);
|
|
|
|
|
mvp_offset.ClearData();
|
|
|
|
|
|
|
|
|
|
MVPMatrix *mp=mvp_array->Map(0,count);
|
|
|
|
|
uint32_t *op=mvp_offset.GetData();
|
2020-12-18 16:52:45 +08:00
|
|
|
|
|
2020-12-09 21:33:29 +08:00
|
|
|
|
for(SceneNode *node:scene_node_list)
|
|
|
|
|
{
|
2021-01-29 20:50:47 +08:00
|
|
|
|
const Matrix4f &l2w=node->GetLocalToWorldMatrix();
|
2020-12-18 16:52:45 +08:00
|
|
|
|
|
2021-01-29 20:50:47 +08:00
|
|
|
|
if(!l2w.IsIdentity())
|
2020-12-18 16:52:45 +08:00
|
|
|
|
{
|
2021-05-11 20:45:00 +08:00
|
|
|
|
mp->Set(l2w,camera_info->vp);
|
2020-12-18 16:52:45 +08:00
|
|
|
|
++mp;
|
|
|
|
|
|
2021-04-26 20:36:56 +08:00
|
|
|
|
*op=mvp_count*MVPMatrixBytes;
|
2021-01-29 20:50:47 +08:00
|
|
|
|
++mvp_count;
|
2020-12-18 16:52:45 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-04-26 20:36:56 +08:00
|
|
|
|
*op=mvp_count*MVPMatrixBytes;
|
2020-12-18 16:52:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
++op;
|
2020-12-09 21:33:29 +08:00
|
|
|
|
}
|
2020-11-26 17:51:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-06-10 18:56:23 +08:00
|
|
|
|
void RenderList::Render(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();
|
|
|
|
|
|
2020-09-21 19:05:25 +08:00
|
|
|
|
cmd_buf->BindPipeline(last_pipeline);
|
2019-05-25 00:50:04 +08:00
|
|
|
|
}
|
2019-05-27 19:54:19 +08:00
|
|
|
|
|
2019-05-25 00:50:04 +08:00
|
|
|
|
{
|
2020-12-18 16:52:45 +08:00
|
|
|
|
MaterialInstance *mi=ri->GetMaterialInstance();
|
2019-05-29 21:48:56 +08:00
|
|
|
|
|
2020-12-18 16:52:45 +08:00
|
|
|
|
cmd_buf->BindDescriptorSets(mi->GetDescriptorSets());
|
2019-05-29 21:48:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-25 00:50:04 +08:00
|
|
|
|
//更新fin_mvp
|
|
|
|
|
|
2020-09-21 19:05:25 +08:00
|
|
|
|
if(ri!=last_ri)
|
2019-05-25 00:50:04 +08:00
|
|
|
|
{
|
2020-09-21 19:05:25 +08:00
|
|
|
|
cmd_buf->BindVAB(ri);
|
2019-05-25 00:50:04 +08:00
|
|
|
|
|
2020-09-21 19:05:25 +08:00
|
|
|
|
last_ri=ri;
|
2019-05-25 00:50:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-21 12:47:06 +08:00
|
|
|
|
const IndexBuffer *ib=ri->GetIndexBuffer();
|
2019-05-25 00:50:04 +08:00
|
|
|
|
|
|
|
|
|
if(ib)
|
|
|
|
|
{
|
|
|
|
|
cmd_buf->DrawIndexed(ib->GetCount());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-09-21 19:05:25 +08:00
|
|
|
|
cmd_buf->Draw(ri->GetDrawCount());
|
2019-05-25 00:50:04 +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);
|
|
|
|
|
|
2019-05-27 16:54:08 +08:00
|
|
|
|
cmd_buf=cb;
|
|
|
|
|
|
2019-05-25 00:50:04 +08:00
|
|
|
|
last_pipeline=nullptr;
|
2020-09-21 19:05:25 +08:00
|
|
|
|
last_ri=nullptr;
|
2019-05-25 00:50:04 +08:00
|
|
|
|
|
2021-05-31 19:10:17 +08:00
|
|
|
|
for(SceneNode *sn:scene_node_list)
|
2021-06-10 18:56:23 +08:00
|
|
|
|
Render(sn->render_obj);
|
2019-05-21 21:28:33 +08:00
|
|
|
|
|
|
|
|
|
return(true);
|
|
|
|
|
}
|
|
|
|
|
}//namespace graph
|
|
|
|
|
}//namespace hgl
|