Created VertexInputData at VKRenderable.h
This commit is contained in:
parent
b26e25df61
commit
db0a8ee256
@ -8,9 +8,25 @@
|
|||||||
#include<hgl/graph/VKMaterialParameters.h>
|
#include<hgl/graph/VKMaterialParameters.h>
|
||||||
#include<hgl/graph/VKMaterialInstance.h>
|
#include<hgl/graph/VKMaterialInstance.h>
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
|
|
||||||
|
struct VertexInputData
|
||||||
|
{
|
||||||
|
uint32_t count;
|
||||||
|
|
||||||
|
const char **name_list;
|
||||||
|
const VkVertexInputBindingDescription *bind_list;
|
||||||
|
const VkVertexInputAttributeDescription *attr_list;
|
||||||
|
VkBuffer *buffer_list;
|
||||||
|
VkDeviceSize *buffer_offset;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
VertexInputData(const VIL *vil);
|
||||||
|
~VertexInputData();
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 可渲染对象<br>
|
* 可渲染对象<br>
|
||||||
* RenderList会统一管理Shader中的LocalToWorld数据,使用DynamicUBO/DynamicSSBO实现。
|
|
||||||
*/
|
*/
|
||||||
class Renderable ///可渲染对象实例
|
class Renderable ///可渲染对象实例
|
||||||
{
|
{
|
||||||
@ -18,9 +34,7 @@ class Renderable
|
|||||||
MaterialInstance * mat_inst;
|
MaterialInstance * mat_inst;
|
||||||
Primitive * primitive;
|
Primitive * primitive;
|
||||||
|
|
||||||
uint32_t buffer_count;
|
VertexInputData * vertex_input_data;
|
||||||
VkBuffer * buffer_list;
|
|
||||||
VkDeviceSize * buffer_size;
|
|
||||||
|
|
||||||
uint32_t buffer_hash;
|
uint32_t buffer_hash;
|
||||||
|
|
||||||
@ -28,7 +42,7 @@ private:
|
|||||||
|
|
||||||
friend Renderable *CreateRenderable(Primitive *,MaterialInstance *,Pipeline *);
|
friend Renderable *CreateRenderable(Primitive *,MaterialInstance *,Pipeline *);
|
||||||
|
|
||||||
Renderable(Primitive *,MaterialInstance *,Pipeline *,const uint32_t,VkBuffer *,VkDeviceSize *);
|
Renderable(Primitive *,MaterialInstance *,Pipeline *,VertexInputData *);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -43,9 +57,8 @@ public:
|
|||||||
Primitive * GetPrimitive (){return primitive;}
|
Primitive * GetPrimitive (){return primitive;}
|
||||||
const AABB & GetBoundingBox ()const{return primitive->GetBoundingBox();}
|
const AABB & GetBoundingBox ()const{return primitive->GetBoundingBox();}
|
||||||
|
|
||||||
const uint32_t GetBufferCount ()const{return buffer_count;}
|
const VertexInputData * GetVertexInputData ()const{return vertex_input_data;}
|
||||||
VkBuffer * GetBuffer ()const{return buffer_list;}
|
|
||||||
VkDeviceSize * GetBufferSize ()const{return buffer_size;}
|
|
||||||
IndexBuffer * GetIndexBuffer ()const{return primitive->GetIndexBuffer();}
|
IndexBuffer * GetIndexBuffer ()const{return primitive->GetIndexBuffer();}
|
||||||
const uint32_t GetIndexBufferOffset()const{return primitive->GetIndexBufferOffset();}
|
const uint32_t GetIndexBufferOffset()const{return primitive->GetIndexBufferOffset();}
|
||||||
const uint32_t GetDrawCount ()const{return primitive->GetDrawCount();}
|
const uint32_t GetDrawCount ()const{return primitive->GetDrawCount();}
|
||||||
|
@ -138,12 +138,12 @@ bool RenderCmdBuffer::BindVBO(Renderable *ri)
|
|||||||
if(!ri)
|
if(!ri)
|
||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
const uint count=ri->GetBufferCount();
|
const VertexInputData *vid=ri->GetVertexInputData();
|
||||||
|
|
||||||
if(count<=0)
|
if(vid->count<=0)
|
||||||
return(false);
|
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();
|
IndexBuffer *indices_buffer=ri->GetIndexBuffer();
|
||||||
|
|
||||||
|
@ -8,18 +8,34 @@
|
|||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
using namespace util;
|
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;
|
primitive=r;
|
||||||
pipeline=p;
|
pipeline=p;
|
||||||
mat_inst=mi;
|
mat_inst=mi;
|
||||||
|
|
||||||
buffer_count=count;
|
vertex_input_data=vid;
|
||||||
buffer_list=bl;
|
|
||||||
buffer_size=bs;
|
|
||||||
|
|
||||||
if(buffer_count>0)
|
if(vertex_input_data->count>0)
|
||||||
CountHash<HASH::Adler32>(buffer_list,buffer_count*sizeof(VkBuffer),(void *)&buffer_hash);
|
CountHash<HASH::Adler32>(vertex_input_data->buffer_list,vertex_input_data->count*sizeof(VkBuffer),(void *)&buffer_hash);
|
||||||
else
|
else
|
||||||
buffer_hash=0;
|
buffer_hash=0;
|
||||||
}
|
}
|
||||||
@ -28,8 +44,7 @@ Renderable::~Renderable()
|
|||||||
{
|
{
|
||||||
//需要在这里添加删除pipeline/desc_sets/primitive引用计数的代码
|
//需要在这里添加删除pipeline/desc_sets/primitive引用计数的代码
|
||||||
|
|
||||||
delete[] buffer_list;
|
delete vertex_input_data;
|
||||||
delete[] buffer_size;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Renderable *CreateRenderable(Primitive *r,MaterialInstance *mi,Pipeline *p)
|
Renderable *CreateRenderable(Primitive *r,MaterialInstance *mi,Pipeline *p)
|
||||||
@ -47,54 +62,48 @@ Renderable *CreateRenderable(Primitive *r,MaterialInstance *mi,Pipeline *p)
|
|||||||
return(nullptr);
|
return(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
AutoDeleteArray<VkBuffer> buffer_list(input_count);
|
|
||||||
AutoDeleteArray<VkDeviceSize> buffer_size(input_count);
|
|
||||||
|
|
||||||
VBO *vbo;
|
VBO *vbo;
|
||||||
const char ** name_list=vil->GetNameList();
|
const char *name;
|
||||||
const VkVertexInputBindingDescription * bind_list=vil->GetBindingList();
|
|
||||||
const VkVertexInputAttributeDescription * attr_list=vil->GetAttributeList();
|
VertexInputData *vid=new VertexInputData(vil);
|
||||||
|
|
||||||
for(int i=0;i<input_count;i++)
|
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)
|
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);
|
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 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())+
|
UTF8String("), VBO Format(")+GetVulkanFormatName(vbo->GetFormat())+
|
||||||
")");
|
")");
|
||||||
|
delete vid;
|
||||||
return(nullptr);
|
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 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())+
|
UTF8String("), VBO stride(")+UTF8String::numberOf(vbo->GetStride())+
|
||||||
")");
|
")");
|
||||||
|
delete vid;
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer_list[i]=vbo->GetBuffer();
|
vid->buffer_list[i]=vbo->GetBuffer();
|
||||||
|
|
||||||
++name_list;
|
|
||||||
++bind_list;
|
|
||||||
++attr_list;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Renderable *ri=new Renderable(r,mi,p,input_count,buffer_list,buffer_size);
|
return(new Renderable(r,mi,p,vid));
|
||||||
buffer_list.Discard();
|
|
||||||
buffer_size.Discard();
|
|
||||||
return ri;
|
|
||||||
}
|
}
|
||||||
VK_NAMESPACE_END
|
VK_NAMESPACE_END
|
||||||
|
Loading…
x
Reference in New Issue
Block a user