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>
|
2021-06-10 18:54:53 +08:00
|
|
|
#include<hgl/util/hash/Hash.h>
|
2020-09-21 19:05:25 +08:00
|
|
|
|
|
|
|
VK_NAMESPACE_BEGIN
|
2021-06-10 18:54:53 +08:00
|
|
|
using namespace util;
|
|
|
|
|
2023-04-28 11:09:22 +08:00
|
|
|
VertexInputData::VertexInputData(const VIL *vil)
|
|
|
|
{
|
|
|
|
count=vil->GetAttrCount();
|
|
|
|
|
|
|
|
name_list=vil->GetNameList();
|
|
|
|
bind_list=vil->GetBindingList();
|
|
|
|
attr_list=vil->GetAttributeList();
|
|
|
|
|
|
|
|
buffer_list=new VkBuffer[count];
|
|
|
|
buffer_offset=new VkDeviceSize[count];
|
|
|
|
}
|
|
|
|
|
|
|
|
VertexInputData::~VertexInputData()
|
|
|
|
{
|
|
|
|
delete[] buffer_list;
|
|
|
|
delete[] buffer_offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
Renderable::Renderable(Primitive *r,MaterialInstance *mi,Pipeline *p,VertexInputData *vid)
|
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-04-28 11:09:22 +08:00
|
|
|
vertex_input_data=vid;
|
2020-09-21 19:05:25 +08:00
|
|
|
|
2023-04-28 11:09:22 +08:00
|
|
|
if(vertex_input_data->count>0)
|
|
|
|
CountHash<HASH::Adler32>(vertex_input_data->buffer_list,vertex_input_data->count*sizeof(VkBuffer),(void *)&buffer_hash);
|
2021-06-10 18:54:53 +08:00
|
|
|
else
|
|
|
|
buffer_hash=0;
|
|
|
|
}
|
|
|
|
|
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-04-28 11:09:22 +08:00
|
|
|
delete vertex_input_data;
|
2020-09-21 19:05:25 +08:00
|
|
|
}
|
|
|
|
|
2022-06-24 21:06:38 +08:00
|
|
|
Renderable *CreateRenderable(Primitive *r,MaterialInstance *mi,Pipeline *p)
|
2020-09-21 19:05:25 +08:00
|
|
|
{
|
2022-01-07 16:25:13 +08:00
|
|
|
if(!r||!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();
|
|
|
|
const int input_count=vil->GetAttrCount();
|
2021-11-29 20:12:10 +08:00
|
|
|
const UTF8String &mtl_name=mi->GetMaterial()->GetName();
|
2020-09-21 19:05:25 +08:00
|
|
|
|
|
|
|
if(r->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
|
|
|
const char *name;
|
|
|
|
|
|
|
|
VertexInputData *vid=new VertexInputData(vil);
|
2020-09-21 19:05:25 +08:00
|
|
|
|
2020-09-27 20:58:25 +08:00
|
|
|
for(int i=0;i<input_count;i++)
|
2020-09-21 19:05:25 +08:00
|
|
|
{
|
2023-04-28 11:09:22 +08:00
|
|
|
vbo=r->GetVBO(vid->name_list[i],vid->buffer_offset+i);
|
|
|
|
|
|
|
|
name=vid->name_list[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-04-28 11:09:22 +08:00
|
|
|
LOG_ERROR("[FATAL ERROR] not found VBO \""+AnsiString(vid->name_list[i])+"\" in Material: "+mtl_name);
|
2021-05-11 20:45:00 +08:00
|
|
|
return(nullptr);
|
|
|
|
}
|
|
|
|
|
2023-04-28 11:09:22 +08:00
|
|
|
if(vbo->GetFormat()!=vid->attr_list[i].format)
|
2021-05-11 20:45:00 +08:00
|
|
|
{
|
2023-04-28 11:09:22 +08:00
|
|
|
LOG_ERROR( "[FATAL ERROR] VBO \""+UTF8String(name)+
|
2021-11-29 20:12:10 +08:00
|
|
|
UTF8String("\" format can't match Renderable, Material(")+mtl_name+
|
2023-04-28 11:09:22 +08:00
|
|
|
UTF8String(") Format(")+GetVulkanFormatName(vid->attr_list[i].format)+
|
2021-11-29 15:58:48 +08:00
|
|
|
UTF8String("), VBO Format(")+GetVulkanFormatName(vbo->GetFormat())+
|
2021-05-11 20:45:00 +08:00
|
|
|
")");
|
2023-04-28 11:09:22 +08:00
|
|
|
delete vid;
|
2021-05-11 20:45:00 +08:00
|
|
|
return(nullptr);
|
|
|
|
}
|
|
|
|
|
2023-04-28 11:09:22 +08:00
|
|
|
if(vbo->GetStride()!=vid->bind_list[i].stride)
|
2021-05-11 20:45:00 +08:00
|
|
|
{
|
2023-04-28 11:09:22 +08:00
|
|
|
LOG_ERROR( "[FATAL ERROR] VBO \""+UTF8String(name)+
|
2021-11-29 20:12:10 +08:00
|
|
|
UTF8String("\" stride can't match Renderable, Material(")+mtl_name+
|
2023-04-28 11:09:22 +08:00
|
|
|
UTF8String(") stride(")+UTF8String::numberOf(vid->bind_list[i].stride)+
|
2023-02-19 19:28:47 +08:00
|
|
|
UTF8String("), VBO stride(")+UTF8String::numberOf(vbo->GetStride())+
|
2021-05-11 20:45:00 +08:00
|
|
|
")");
|
2023-04-28 11:09:22 +08:00
|
|
|
delete vid;
|
2021-05-11 20:45:00 +08:00
|
|
|
return(nullptr);
|
|
|
|
}
|
2020-09-21 19:05:25 +08:00
|
|
|
|
2023-04-28 11:09:22 +08:00
|
|
|
vid->buffer_list[i]=vbo->GetBuffer();
|
2020-09-21 19:05:25 +08:00
|
|
|
}
|
|
|
|
|
2023-04-28 11:09:22 +08:00
|
|
|
return(new Renderable(r,mi,p,vid));
|
2020-09-21 19:05:25 +08:00
|
|
|
}
|
2020-11-03 22:29:32 +08:00
|
|
|
VK_NAMESPACE_END
|