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>
|
2023-07-28 20:17:46 +08:00
|
|
|
|
#include<hgl/log/LogInfo.h>
|
2020-09-21 19:05:25 +08:00
|
|
|
|
|
|
|
|
|
VK_NAMESPACE_BEGIN
|
2023-05-05 21:11:39 +08:00
|
|
|
|
VertexInputData::VertexInputData(const uint32_t c,const uint32_t vc,const IndexBufferData *ibd)
|
2023-04-28 11:09:22 +08:00
|
|
|
|
{
|
2023-05-05 21:11:39 +08:00
|
|
|
|
binding_count=c;
|
2023-05-04 19:11:18 +08:00
|
|
|
|
|
2023-05-05 21:11:39 +08:00
|
|
|
|
buffer_list=new VkBuffer[binding_count];
|
|
|
|
|
buffer_offset=new VkDeviceSize[binding_count];
|
2023-04-28 11:09:22 +08:00
|
|
|
|
|
2023-05-05 21:11:39 +08:00
|
|
|
|
vertex_count=vc;
|
2023-05-04 19:11:18 +08:00
|
|
|
|
|
2023-05-05 21:11:39 +08:00
|
|
|
|
index_buffer=ibd;
|
2023-04-28 11:09:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-05-05 21:11:39 +08:00
|
|
|
|
VertexInputData::~VertexInputData()
|
2023-04-28 11:09:22 +08:00
|
|
|
|
{
|
2023-05-05 21:11:39 +08:00
|
|
|
|
delete[] buffer_list;
|
|
|
|
|
delete[] buffer_offset;
|
2023-04-28 11:09:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-05-05 21:11:39 +08:00
|
|
|
|
Renderable::Renderable(Primitive *r,MaterialInstance *mi,Pipeline *p,VertexInputData *vi)
|
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-05 21:11:39 +08:00
|
|
|
|
vertex_input=vi;
|
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-05 21:11:39 +08:00
|
|
|
|
delete vertex_input;
|
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-05 21:11:39 +08:00
|
|
|
|
const uint32_t 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-06 19:28:42 +08:00
|
|
|
|
VertexInputData *vid=new VertexInputData(input_count,prim->GetVertexCount(),prim->GetIndexBufferData());
|
2023-05-04 19:11:18 +08:00
|
|
|
|
|
2024-04-04 01:57:51 +08:00
|
|
|
|
const VertexInputFormat *vif=vil->GetVIFList(VertexInputGroup::Basic);
|
2024-04-03 00:12:03 +08:00
|
|
|
|
VBOAccessData vad;
|
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-03 19:26:22 +08:00
|
|
|
|
//注: VIF来自于材质,但VBO来自于Primitive。
|
|
|
|
|
// 两个并不一定一样,排序也不一定一样。所以不能让PRIMTIVE直接提供BUFFER_LIST/OFFSET来搞一次性绑定。
|
|
|
|
|
|
2024-04-03 00:12:03 +08:00
|
|
|
|
if(!prim->GetVBOAccessData(vif->name,&vad))
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-03 00:12:03 +08:00
|
|
|
|
vbo=vad.vbo;
|
|
|
|
|
|
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
|
|
|
|
|
2024-04-03 00:12:03 +08:00
|
|
|
|
vid->buffer_offset[i]=vad.offset;
|
2023-05-05 21:11:39 +08:00
|
|
|
|
vid->buffer_list[i]=vbo->GetBuffer();
|
2023-05-04 19:11:18 +08:00
|
|
|
|
++vif;
|
2020-09-21 19:05:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-05-05 21:11:39 +08:00
|
|
|
|
return(new Renderable(prim,mi,p,vid));
|
2020-09-21 19:05:25 +08:00
|
|
|
|
}
|
2020-11-03 22:29:32 +08:00
|
|
|
|
VK_NAMESPACE_END
|