2022-06-24 21:06:38 +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>
|
2020-09-21 19:05:25 +08:00
|
|
|
|
|
|
|
VK_NAMESPACE_BEGIN
|
2023-05-04 19:11:18 +08:00
|
|
|
VertexInputDataGroup::VertexInputDataGroup(const VIL *vd)
|
2023-04-28 11:09:22 +08:00
|
|
|
{
|
2023-05-04 19:11:18 +08:00
|
|
|
vil=vd;
|
|
|
|
|
|
|
|
uint first_binding=0;
|
2023-04-28 11:09:22 +08:00
|
|
|
|
2023-05-04 19:11:18 +08:00
|
|
|
for(uint i=0;i<size_t(VertexInputGroup::RANGE_SIZE);i++)
|
|
|
|
{
|
|
|
|
vid[i].binding_count=vil->GetCount(VertexInputGroup(i));
|
2023-04-28 11:09:22 +08:00
|
|
|
|
2023-05-04 19:11:18 +08:00
|
|
|
if(vid[i].binding_count>0)
|
|
|
|
{
|
|
|
|
vid[i].first_binding=vil->GetFirstBinding(VertexInputGroup(i));
|
|
|
|
|
|
|
|
vid[i].buffer_list=new VkBuffer[vid[i].binding_count];
|
|
|
|
vid[i].buffer_offset=new VkDeviceSize[vid[i].binding_count];
|
|
|
|
}
|
|
|
|
}
|
2023-04-28 11:09:22 +08:00
|
|
|
}
|
|
|
|
|
2023-05-04 19:11:18 +08:00
|
|
|
VertexInputDataGroup::~VertexInputDataGroup()
|
2023-04-28 11:09:22 +08:00
|
|
|
{
|
2023-05-04 19:11:18 +08:00
|
|
|
for(uint i=0;i<size_t(VertexInputGroup::RANGE_SIZE);i++)
|
|
|
|
if(vid[i].binding_count>0)
|
|
|
|
{
|
|
|
|
delete[] vid[i].buffer_list;
|
|
|
|
delete[] vid[i].buffer_offset;
|
|
|
|
}
|
2023-04-28 11:09:22 +08:00
|
|
|
}
|
|
|
|
|
2023-05-04 19:11:18 +08:00
|
|
|
Renderable::Renderable(Primitive *r,MaterialInstance *mi,Pipeline *p,VertexInputDataGroup *vidg)
|
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
|
|
|
|
2023-05-04 19:11:18 +08:00
|
|
|
vid_group=vidg;
|
2021-06-10 18:54:53 +08:00
|
|
|
}
|
|
|
|
|
2022-06-24 21:06:38 +08:00
|
|
|
Renderable::~Renderable()
|
2020-09-21 19:05:25 +08:00
|
|
|
{
|
2022-06-24 18:00:22 +08:00
|
|
|
//需要在这里添加删除pipeline/desc_sets/primitive引用计数的代码
|
2020-09-21 19:05:25 +08:00
|
|
|
|
2023-05-04 19:11:18 +08:00
|
|
|
delete vid_group;
|
2020-09-21 19:05:25 +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();
|
2023-05-04 19:11:18 +08:00
|
|
|
const uint input_count=vil->GetCount(VertexInputGroup::Basic); //不统计Bone/LocalToWorld组的
|
2021-11-29 20:12:10 +08:00
|
|
|
const UTF8String &mtl_name=mi->GetMaterial()->GetName();
|
2020-09-21 19:05:25 +08:00
|
|
|
|
2023-05-02 18:56:55 +08:00
|
|
|
if(prim->GetBufferCount()<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
|
|
|
|
2021-11-29 15:58:48 +08:00
|
|
|
VBO *vbo;
|
2023-04-28 11:09:22 +08:00
|
|
|
|
2023-05-04 19:11:18 +08:00
|
|
|
VertexInputDataGroup *vid_group=new VertexInputDataGroup(vil);
|
2020-09-21 19:05:25 +08:00
|
|
|
|
2023-05-04 19:11:18 +08:00
|
|
|
VertexInputData &vid=vid_group->vid[size_t(VertexInputGroup::Basic)];
|
|
|
|
|
|
|
|
const VertexInputFormat *vif=vil->GetFormatList(VertexInputGroup::Basic);
|
2023-04-28 11:09:22 +08:00
|
|
|
|
2023-05-04 19:11:18 +08:00
|
|
|
for(uint i=0;i<input_count;i++)
|
|
|
|
{
|
|
|
|
vbo=prim->GetVBO(vif->name,vid.buffer_offset+i);
|
2020-09-21 19:05:25 +08:00
|
|
|
|
2021-11-29 15:58:48 +08:00
|
|
|
if(!vbo)
|
2021-05-11 20:45:00 +08:00
|
|
|
{
|
2023-05-04 19:11:18 +08:00
|
|
|
LOG_ERROR("[FATAL ERROR] not found VBO \""+AnsiString(vif->name)+"\" in Material: "+mtl_name);
|
2021-05-11 20:45:00 +08:00
|
|
|
return(nullptr);
|
|
|
|
}
|
|
|
|
|
2023-05-04 19:11:18 +08:00
|
|
|
if(vbo->GetFormat()!=vif->format)
|
2021-05-11 20:45:00 +08:00
|
|
|
{
|
2023-05-04 19:11:18 +08:00
|
|
|
LOG_ERROR( "[FATAL ERROR] VBO \""+UTF8String(vif->name)+
|
2021-11-29 20:12:10 +08:00
|
|
|
UTF8String("\" format can't match Renderable, Material(")+mtl_name+
|
2023-05-04 19:11:18 +08:00
|
|
|
UTF8String(") Format(")+GetVulkanFormatName(vif->format)+
|
2021-11-29 15:58:48 +08:00
|
|
|
UTF8String("), VBO Format(")+GetVulkanFormatName(vbo->GetFormat())+
|
2021-05-11 20:45:00 +08:00
|
|
|
")");
|
|
|
|
return(nullptr);
|
|
|
|
}
|
|
|
|
|
2023-05-04 19:11:18 +08:00
|
|
|
if(vbo->GetStride()!=vif->stride)
|
2021-05-11 20:45:00 +08:00
|
|
|
{
|
2023-05-04 19:11:18 +08:00
|
|
|
LOG_ERROR( "[FATAL ERROR] VBO \""+UTF8String(vif->name)+
|
2021-11-29 20:12:10 +08:00
|
|
|
UTF8String("\" stride can't match Renderable, Material(")+mtl_name+
|
2023-05-04 19:11:18 +08:00
|
|
|
UTF8String(") stride(")+UTF8String::numberOf(vif->stride)+
|
2023-02-19 19:28:47 +08:00
|
|
|
UTF8String("), VBO stride(")+UTF8String::numberOf(vbo->GetStride())+
|
2021-05-11 20:45:00 +08:00
|
|
|
")");
|
|
|
|
return(nullptr);
|
|
|
|
}
|
2020-09-21 19:05:25 +08:00
|
|
|
|
2023-05-04 19:11:18 +08:00
|
|
|
vid.buffer_list[i]=vbo->GetBuffer();
|
|
|
|
++vif;
|
2020-09-21 19:05:25 +08:00
|
|
|
}
|
|
|
|
|
2023-05-04 19:11:18 +08:00
|
|
|
return(new Renderable(prim,mi,p,vid_group));
|
2020-09-21 19:05:25 +08:00
|
|
|
}
|
2020-11-03 22:29:32 +08:00
|
|
|
VK_NAMESPACE_END
|