Created VertexInputData at VKRenderable.h
This commit is contained in:
@@ -138,12 +138,12 @@ bool RenderCmdBuffer::BindVBO(Renderable *ri)
|
||||
if(!ri)
|
||||
return(false);
|
||||
|
||||
const uint count=ri->GetBufferCount();
|
||||
const VertexInputData *vid=ri->GetVertexInputData();
|
||||
|
||||
if(count<=0)
|
||||
if(vid->count<=0)
|
||||
return(false);
|
||||
|
||||
vkCmdBindVertexBuffers(cmd_buf,0,count,ri->GetBuffer(),ri->GetBufferSize());
|
||||
vkCmdBindVertexBuffers(cmd_buf,0,vid->count,vid->buffer_list,vid->buffer_offset);
|
||||
|
||||
IndexBuffer *indices_buffer=ri->GetIndexBuffer();
|
||||
|
||||
|
@@ -8,18 +8,34 @@
|
||||
VK_NAMESPACE_BEGIN
|
||||
using namespace util;
|
||||
|
||||
Renderable::Renderable(Primitive *r,MaterialInstance *mi,Pipeline *p,const uint32_t count,VkBuffer *bl,VkDeviceSize *bs)
|
||||
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)
|
||||
{
|
||||
primitive=r;
|
||||
pipeline=p;
|
||||
mat_inst=mi;
|
||||
|
||||
buffer_count=count;
|
||||
buffer_list=bl;
|
||||
buffer_size=bs;
|
||||
vertex_input_data=vid;
|
||||
|
||||
if(buffer_count>0)
|
||||
CountHash<HASH::Adler32>(buffer_list,buffer_count*sizeof(VkBuffer),(void *)&buffer_hash);
|
||||
if(vertex_input_data->count>0)
|
||||
CountHash<HASH::Adler32>(vertex_input_data->buffer_list,vertex_input_data->count*sizeof(VkBuffer),(void *)&buffer_hash);
|
||||
else
|
||||
buffer_hash=0;
|
||||
}
|
||||
@@ -28,8 +44,7 @@ Renderable::~Renderable()
|
||||
{
|
||||
//需要在这里添加删除pipeline/desc_sets/primitive引用计数的代码
|
||||
|
||||
delete[] buffer_list;
|
||||
delete[] buffer_size;
|
||||
delete vertex_input_data;
|
||||
}
|
||||
|
||||
Renderable *CreateRenderable(Primitive *r,MaterialInstance *mi,Pipeline *p)
|
||||
@@ -47,54 +62,48 @@ Renderable *CreateRenderable(Primitive *r,MaterialInstance *mi,Pipeline *p)
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
AutoDeleteArray<VkBuffer> buffer_list(input_count);
|
||||
AutoDeleteArray<VkDeviceSize> buffer_size(input_count);
|
||||
|
||||
VBO *vbo;
|
||||
const char ** name_list=vil->GetNameList();
|
||||
const VkVertexInputBindingDescription * bind_list=vil->GetBindingList();
|
||||
const VkVertexInputAttributeDescription * attr_list=vil->GetAttributeList();
|
||||
const char *name;
|
||||
|
||||
VertexInputData *vid=new VertexInputData(vil);
|
||||
|
||||
for(int i=0;i<input_count;i++)
|
||||
{
|
||||
vbo=r->GetVBO(*name_list,buffer_size+i);
|
||||
vbo=r->GetVBO(vid->name_list[i],vid->buffer_offset+i);
|
||||
|
||||
name=vid->name_list[i];
|
||||
|
||||
if(!vbo)
|
||||
{
|
||||
LOG_ERROR("[FATAL ERROR] not found VBO \""+AnsiString(*name_list)+"\" in Material: "+mtl_name);
|
||||
LOG_ERROR("[FATAL ERROR] not found VBO \""+AnsiString(vid->name_list[i])+"\" in Material: "+mtl_name);
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
if(vbo->GetFormat()!=attr_list->format)
|
||||
if(vbo->GetFormat()!=vid->attr_list[i].format)
|
||||
{
|
||||
LOG_ERROR( "[FATAL ERROR] VBO \""+**name_list+
|
||||
LOG_ERROR( "[FATAL ERROR] VBO \""+UTF8String(name)+
|
||||
UTF8String("\" format can't match Renderable, Material(")+mtl_name+
|
||||
UTF8String(") Format(")+GetVulkanFormatName(attr_list->format)+
|
||||
UTF8String(") Format(")+GetVulkanFormatName(vid->attr_list[i].format)+
|
||||
UTF8String("), VBO Format(")+GetVulkanFormatName(vbo->GetFormat())+
|
||||
")");
|
||||
delete vid;
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
if(vbo->GetStride()!=bind_list->stride)
|
||||
if(vbo->GetStride()!=vid->bind_list[i].stride)
|
||||
{
|
||||
LOG_ERROR( "[FATAL ERROR] VBO \""+**name_list+
|
||||
LOG_ERROR( "[FATAL ERROR] VBO \""+UTF8String(name)+
|
||||
UTF8String("\" stride can't match Renderable, Material(")+mtl_name+
|
||||
UTF8String(") stride(")+UTF8String::numberOf(bind_list->stride)+
|
||||
UTF8String(") stride(")+UTF8String::numberOf(vid->bind_list[i].stride)+
|
||||
UTF8String("), VBO stride(")+UTF8String::numberOf(vbo->GetStride())+
|
||||
")");
|
||||
delete vid;
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
buffer_list[i]=vbo->GetBuffer();
|
||||
|
||||
++name_list;
|
||||
++bind_list;
|
||||
++attr_list;
|
||||
vid->buffer_list[i]=vbo->GetBuffer();
|
||||
}
|
||||
|
||||
Renderable *ri=new Renderable(r,mi,p,input_count,buffer_list,buffer_size);
|
||||
buffer_list.Discard();
|
||||
buffer_size.Discard();
|
||||
return ri;
|
||||
return(new Renderable(r,mi,p,vid));
|
||||
}
|
||||
VK_NAMESPACE_END
|
||||
|
Reference in New Issue
Block a user