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;
|
|
|
|
|
2022-06-24 21:06:38 +08:00
|
|
|
Renderable::Renderable(Primitive *r,MaterialInstance *mi,Pipeline *p,const uint32_t count,VkBuffer *bl,VkDeviceSize *bs)
|
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
|
|
|
|
|
|
|
buffer_count=count;
|
|
|
|
buffer_list=bl;
|
|
|
|
buffer_size=bs;
|
|
|
|
|
2021-06-10 18:54:53 +08:00
|
|
|
if(buffer_count>0)
|
|
|
|
CountHash<HASH::Adler32>(buffer_list,buffer_count*sizeof(VkBuffer),(void *)&buffer_hash);
|
|
|
|
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
|
|
|
|
|
|
|
delete[] buffer_list;
|
|
|
|
delete[] buffer_size;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2020-09-27 21:20:17 +08:00
|
|
|
AutoDeleteArray<VkBuffer> buffer_list(input_count);
|
|
|
|
AutoDeleteArray<VkDeviceSize> buffer_size(input_count);
|
2020-09-21 19:05:25 +08:00
|
|
|
|
2021-11-29 15:58:48 +08:00
|
|
|
VBO *vbo;
|
2022-10-11 19:16:06 +08:00
|
|
|
const AnsiString ** name_list=vil->GetNameList();
|
|
|
|
const VkVertexInputBindingDescription * bind_list=vil->GetBindingList();
|
|
|
|
const VkVertexInputAttributeDescription * attr_list=vil->GetAttributeList();
|
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
|
|
|
{
|
2021-11-29 20:12:10 +08:00
|
|
|
vbo=r->GetVBO(**name_list,buffer_size+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
|
|
|
{
|
2022-10-11 19:16:06 +08:00
|
|
|
LOG_ERROR("[FATAL ERROR] not found VBO \""+**name_list+"\" in Material: "+mtl_name);
|
2021-05-11 20:45:00 +08:00
|
|
|
return(nullptr);
|
|
|
|
}
|
|
|
|
|
2021-11-29 20:12:10 +08:00
|
|
|
if(vbo->GetFormat()!=attr_list->format)
|
2021-05-11 20:45:00 +08:00
|
|
|
{
|
2021-11-29 20:12:10 +08:00
|
|
|
LOG_ERROR( "[FATAL ERROR] VBO \""+**name_list+
|
|
|
|
UTF8String("\" format can't match Renderable, Material(")+mtl_name+
|
|
|
|
UTF8String(") Format(")+GetVulkanFormatName(attr_list->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);
|
|
|
|
}
|
|
|
|
|
2021-11-29 20:12:10 +08:00
|
|
|
if(vbo->GetStride()!=bind_list->stride)
|
2021-05-11 20:45:00 +08:00
|
|
|
{
|
2021-11-29 20:12:10 +08:00
|
|
|
LOG_ERROR( "[FATAL ERROR] VBO \""+**name_list+
|
|
|
|
UTF8String("\" stride can't match Renderable, Material(")+mtl_name+
|
|
|
|
UTF8String(") stride(")+UTF8String::valueOf(bind_list->stride)+
|
2021-11-29 15:58:48 +08:00
|
|
|
UTF8String("), VBO stride(")+UTF8String::valueOf(vbo->GetStride())+
|
2021-05-11 20:45:00 +08:00
|
|
|
")");
|
|
|
|
return(nullptr);
|
|
|
|
}
|
2020-09-21 19:05:25 +08:00
|
|
|
|
2021-11-29 15:58:48 +08:00
|
|
|
buffer_list[i]=vbo->GetBuffer();
|
2020-09-21 19:05:25 +08:00
|
|
|
|
2021-11-29 20:12:10 +08:00
|
|
|
++name_list;
|
|
|
|
++bind_list;
|
|
|
|
++attr_list;
|
2020-09-21 19:05:25 +08:00
|
|
|
}
|
|
|
|
|
2022-06-24 21:06:38 +08:00
|
|
|
Renderable *ri=new Renderable(r,mi,p,input_count,buffer_list,buffer_size);
|
2020-09-21 19:05:25 +08:00
|
|
|
buffer_list.Discard();
|
|
|
|
buffer_size.Discard();
|
|
|
|
return ri;
|
|
|
|
}
|
2020-11-03 22:29:32 +08:00
|
|
|
VK_NAMESPACE_END
|