2024-05-25 01:46:19 +08:00
|
|
|
|
#include<hgl/graph/VKRenderable.h>
|
2021-06-16 20:29:25 +08:00
|
|
|
|
#include<hgl/graph/VKMaterialInstance.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/VKMaterial.h>
|
2021-05-11 20:45:00 +08:00
|
|
|
|
#include<hgl/graph/VKVertexAttribBuffer.h>
|
2024-05-25 22:08:01 +08:00
|
|
|
|
#include<hgl/graph/VKIndexBuffer.h>
|
2023-07-28 20:17:46 +08:00
|
|
|
|
#include<hgl/log/LogInfo.h>
|
2020-09-21 19:05:25 +08:00
|
|
|
|
|
|
|
|
|
VK_NAMESPACE_BEGIN
|
2024-05-28 23:33:15 +08:00
|
|
|
|
PrimitiveDataBuffer::PrimitiveDataBuffer(const uint32_t c,IndexBuffer *ib,VertexDataManager *_vdm)
|
2023-04-28 11:09:22 +08:00
|
|
|
|
{
|
2024-05-25 22:08:01 +08:00
|
|
|
|
vab_count=c;
|
2023-05-04 19:11:18 +08:00
|
|
|
|
|
2024-05-25 22:08:01 +08:00
|
|
|
|
vab_list=hgl_zero_new<VkBuffer>(vab_count);
|
2024-05-31 22:04:02 +08:00
|
|
|
|
vab_offset=hgl_zero_new<VkDeviceSize>(vab_count);
|
2024-05-28 02:21:33 +08:00
|
|
|
|
ibo=ib;
|
2024-05-28 23:33:15 +08:00
|
|
|
|
|
|
|
|
|
vdm=_vdm;
|
2023-04-28 11:09:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-28 02:21:33 +08:00
|
|
|
|
PrimitiveDataBuffer::~PrimitiveDataBuffer()
|
2023-04-28 11:09:22 +08:00
|
|
|
|
{
|
2024-05-31 22:04:02 +08:00
|
|
|
|
delete[] vab_offset;
|
2024-05-25 22:08:01 +08:00
|
|
|
|
delete[] vab_list;
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-12 13:30:11 +08:00
|
|
|
|
const int PrimitiveDataBuffer::compare(const PrimitiveDataBuffer &pdb)const
|
2024-05-25 22:08:01 +08:00
|
|
|
|
{
|
2024-12-12 13:30:11 +08:00
|
|
|
|
ptrdiff_t off;
|
2024-05-25 22:08:01 +08:00
|
|
|
|
|
2024-12-12 13:30:11 +08:00
|
|
|
|
off=&vdm-&pdb.vdm;
|
|
|
|
|
if(off)
|
|
|
|
|
return off;
|
2024-05-29 00:55:12 +08:00
|
|
|
|
|
2024-12-12 13:30:11 +08:00
|
|
|
|
off=vab_count-pdb.vab_count;
|
|
|
|
|
if(off)
|
|
|
|
|
return off;
|
2024-05-25 22:08:01 +08:00
|
|
|
|
|
2024-12-12 13:30:11 +08:00
|
|
|
|
off=hgl_cmp(vab_list,pdb.vab_list,vab_count);
|
|
|
|
|
if(off)
|
|
|
|
|
return off;
|
2024-05-25 22:08:01 +08:00
|
|
|
|
|
2024-12-12 13:30:11 +08:00
|
|
|
|
off=hgl_cmp(vab_offset,pdb.vab_offset,vab_count);
|
|
|
|
|
if(off)
|
|
|
|
|
return off;
|
2024-05-25 22:08:01 +08:00
|
|
|
|
|
2024-12-12 13:30:11 +08:00
|
|
|
|
off=ibo-pdb.ibo;
|
|
|
|
|
|
|
|
|
|
return off;
|
2023-04-28 11:09:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-28 23:10:50 +08:00
|
|
|
|
Renderable::Renderable(Primitive *r,MaterialInstance *mi,Pipeline *p,PrimitiveDataBuffer *pdb,PrimitiveRenderData *prd)
|
2020-09-21 19:05:25 +08:00
|
|
|
|
{
|
2022-06-24 18:00:22 +08:00
|
|
|
|
primitive=r;
|
2020-09-21 19:05:25 +08:00
|
|
|
|
pipeline=p;
|
2021-06-16 20:29:25 +08:00
|
|
|
|
mat_inst=mi;
|
2020-09-21 19:05:25 +08:00
|
|
|
|
|
2024-05-28 23:10:50 +08:00
|
|
|
|
primitive_data_buffer=pdb;
|
2024-05-27 01:42:10 +08:00
|
|
|
|
primitive_render_data=prd;
|
2021-06-10 18:54:53 +08:00
|
|
|
|
}
|
2024-05-25 22:08:01 +08:00
|
|
|
|
|
2023-05-02 18:56:55 +08:00
|
|
|
|
Renderable *CreateRenderable(Primitive *prim,MaterialInstance *mi,Pipeline *p)
|
2020-09-21 19:05:25 +08:00
|
|
|
|
{
|
2023-05-02 18:56:55 +08:00
|
|
|
|
if(!prim||!mi||!p)return(nullptr);
|
2020-09-21 19:05:25 +08:00
|
|
|
|
|
2022-10-11 19:16:06 +08:00
|
|
|
|
const VIL *vil=mi->GetVIL();
|
2024-07-01 02:55:48 +08:00
|
|
|
|
|
2024-12-12 13:30:11 +08:00
|
|
|
|
if(*vil!=*p->GetVIL())
|
2024-07-01 02:55:48 +08:00
|
|
|
|
return(nullptr);
|
|
|
|
|
|
2024-05-28 23:10:50 +08:00
|
|
|
|
const uint32_t input_count=vil->GetVertexAttribCount(VertexInputGroup::Basic); //不统计Bone/LocalToWorld组的
|
2024-07-26 03:25:09 +08:00
|
|
|
|
const AnsiString &mtl_name=mi->GetMaterial()->GetName();
|
2020-09-21 19:05:25 +08:00
|
|
|
|
|
2024-05-25 01:46:19 +08:00
|
|
|
|
if(prim->GetVABCount()<input_count) //小于材质要求的数量?那自然是不行的
|
2021-05-11 20:45:00 +08:00
|
|
|
|
{
|
2021-11-29 20:12:10 +08:00
|
|
|
|
LOG_ERROR("[FATAL ERROR] input buffer count of Renderable lesser than Material, Material name: "+mtl_name);
|
2021-05-11 20:45:00 +08:00
|
|
|
|
|
2020-09-21 19:05:25 +08:00
|
|
|
|
return(nullptr);
|
2021-05-11 20:45:00 +08:00
|
|
|
|
}
|
2020-09-21 19:05:25 +08:00
|
|
|
|
|
2024-05-28 23:33:15 +08:00
|
|
|
|
PrimitiveDataBuffer *pdb=new PrimitiveDataBuffer(input_count,prim->GetIBO(),prim->GetVDM());
|
2024-05-28 23:10:50 +08:00
|
|
|
|
PrimitiveRenderData *prd=new PrimitiveRenderData(prim->GetVertexCount(),prim->GetIndexCount(),prim->GetVertexOffset(),prim->GetFirstIndex());
|
2023-05-04 19:11:18 +08:00
|
|
|
|
|
2024-04-04 01:57:51 +08:00
|
|
|
|
const VertexInputFormat *vif=vil->GetVIFList(VertexInputGroup::Basic);
|
2024-05-27 01:42:10 +08:00
|
|
|
|
|
2024-05-28 23:10:50 +08:00
|
|
|
|
VAB *vab;
|
2023-04-28 11:09:22 +08:00
|
|
|
|
|
2023-05-04 19:11:18 +08:00
|
|
|
|
for(uint i=0;i<input_count;i++)
|
|
|
|
|
{
|
2024-04-24 01:44:01 +08:00
|
|
|
|
//注: VIF来自于材质,但VAB来自于Primitive。
|
2024-04-03 19:26:22 +08:00
|
|
|
|
// 两个并不一定一样,排序也不一定一样。所以不能让PRIMTIVE直接提供BUFFER_LIST/OFFSET来搞一次性绑定。
|
|
|
|
|
|
2024-05-28 23:10:50 +08:00
|
|
|
|
vab=prim->GetVAB(vif->name);
|
2024-05-23 02:19:40 +08:00
|
|
|
|
|
2024-05-28 23:10:50 +08:00
|
|
|
|
if(!vab)
|
2021-05-11 20:45:00 +08:00
|
|
|
|
{
|
2024-04-24 01:44:01 +08:00
|
|
|
|
LOG_ERROR("[FATAL ERROR] not found VAB \""+AnsiString(vif->name)+"\" in Material: "+mtl_name);
|
2021-05-11 20:45:00 +08:00
|
|
|
|
return(nullptr);
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-28 23:10:50 +08:00
|
|
|
|
if(vab->GetFormat()!=vif->format)
|
2021-05-11 20:45:00 +08:00
|
|
|
|
{
|
2024-07-26 03:25:09 +08:00
|
|
|
|
LOG_ERROR( "[FATAL ERROR] VAB \""+AnsiString(vif->name)+
|
|
|
|
|
AnsiString("\" format can't match Renderable, Material(")+mtl_name+
|
|
|
|
|
AnsiString(") Format(")+GetVulkanFormatName(vif->format)+
|
|
|
|
|
AnsiString("), VAB Format(")+GetVulkanFormatName(vab->GetFormat())+
|
2021-05-11 20:45:00 +08:00
|
|
|
|
")");
|
|
|
|
|
return(nullptr);
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-28 23:10:50 +08:00
|
|
|
|
if(vab->GetStride()!=vif->stride)
|
2021-05-11 20:45:00 +08:00
|
|
|
|
{
|
2024-07-26 03:25:09 +08:00
|
|
|
|
LOG_ERROR( "[FATAL ERROR] VAB \""+AnsiString(vif->name)+
|
|
|
|
|
AnsiString("\" stride can't match Renderable, Material(")+mtl_name+
|
|
|
|
|
AnsiString(") stride(")+AnsiString::numberOf(vif->stride)+
|
|
|
|
|
AnsiString("), VAB stride(")+AnsiString::numberOf(vab->GetStride())+
|
2021-05-11 20:45:00 +08:00
|
|
|
|
")");
|
|
|
|
|
return(nullptr);
|
|
|
|
|
}
|
2020-09-21 19:05:25 +08:00
|
|
|
|
|
2024-05-28 23:10:50 +08:00
|
|
|
|
pdb->vab_list[i]=vab->GetBuffer();
|
2024-05-31 22:04:02 +08:00
|
|
|
|
pdb->vab_offset[i]=0;
|
2023-05-04 19:11:18 +08:00
|
|
|
|
++vif;
|
2020-09-21 19:05:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-28 23:10:50 +08:00
|
|
|
|
return(new Renderable(prim,mi,p,pdb,prd));
|
2020-09-21 19:05:25 +08:00
|
|
|
|
}
|
2020-11-03 22:29:32 +08:00
|
|
|
|
VK_NAMESPACE_END
|