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>
|
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>
|
2021-06-16 11:43:19 +08:00
|
|
|
|
#include<hgl/graph/VKMaterialParameters.h>
|
2020-10-21 11:43:18 +08:00
|
|
|
|
#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-06-15 19:03:34 +08:00
|
|
|
|
RenderList::RenderList()
|
2020-11-26 17:51:59 +08:00
|
|
|
|
{
|
|
|
|
|
cmd_buf =nullptr;
|
|
|
|
|
|
2021-06-15 15:36:30 +08:00
|
|
|
|
mvp_buffer =nullptr;
|
|
|
|
|
ri_list =nullptr;
|
2020-12-18 16:52:45 +08:00
|
|
|
|
|
2021-06-15 15:36:30 +08:00
|
|
|
|
ubo_offset =0;
|
|
|
|
|
ubo_align =0;
|
2021-04-26 20:36:56 +08:00
|
|
|
|
|
2020-11-26 17:51:59 +08:00
|
|
|
|
last_pipeline =nullptr;
|
2021-06-15 15:36:30 +08:00
|
|
|
|
last_mi =nullptr;
|
|
|
|
|
last_vbo =0;
|
2020-11-26 17:51:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-06-15 15:36:30 +08:00
|
|
|
|
void RenderList::Set(List<RenderableInstance *> *ril,GPUBuffer *buf,const uint32_t align)
|
2020-11-26 17:51:59 +08:00
|
|
|
|
{
|
2021-06-15 15:36:30 +08:00
|
|
|
|
ri_list=ril;
|
|
|
|
|
mvp_buffer=buf;
|
|
|
|
|
ubo_align=align;
|
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
|
|
|
|
{
|
2021-06-16 10:41:04 +08:00
|
|
|
|
MaterialParameters *mi=ri->GetMaterialInstance();
|
2019-05-29 21:48:56 +08:00
|
|
|
|
|
2021-06-15 15:36:30 +08:00
|
|
|
|
if(mi!=last_mi)
|
|
|
|
|
{
|
|
|
|
|
last_mi=mi;
|
|
|
|
|
cmd_buf->BindDescriptorSets(mi->GetDescriptorSets());
|
|
|
|
|
}
|
2019-05-29 21:48:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-06-15 15:36:30 +08:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
2019-05-25 00:50:04 +08:00
|
|
|
|
|
2021-06-15 15:36:30 +08:00
|
|
|
|
if(last_vbo!=ri->GetBufferHash())
|
2019-05-25 00:50:04 +08:00
|
|
|
|
{
|
2021-06-15 15:36:30 +08:00
|
|
|
|
last_vbo=ri->GetBufferHash();
|
|
|
|
|
|
2020-09-21 19:05:25 +08:00
|
|
|
|
cmd_buf->BindVAB(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);
|
|
|
|
|
|
2021-06-15 15:36:30 +08:00
|
|
|
|
if(!mvp_buffer
|
|
|
|
|
||!ri_list)
|
|
|
|
|
return(false);
|
|
|
|
|
|
|
|
|
|
if(ri_list->GetCount()<=0)
|
|
|
|
|
return(true);
|
|
|
|
|
|
2019-05-27 16:54:08 +08:00
|
|
|
|
cmd_buf=cb;
|
|
|
|
|
|
2019-05-25 00:50:04 +08:00
|
|
|
|
last_pipeline=nullptr;
|
2021-06-15 15:36:30 +08:00
|
|
|
|
last_mi=nullptr;
|
|
|
|
|
last_vbo=0;
|
|
|
|
|
ubo_offset=0;
|
2019-05-25 00:50:04 +08:00
|
|
|
|
|
2021-06-15 15:36:30 +08:00
|
|
|
|
for(RenderableInstance *ri:*ri_list)
|
|
|
|
|
Render(ri);
|
2019-05-21 21:28:33 +08:00
|
|
|
|
|
|
|
|
|
return(true);
|
|
|
|
|
}
|
|
|
|
|
}//namespace graph
|
|
|
|
|
}//namespace hgl
|