Moved vab_map_list and ibo_map from PrimitiveCreater to PrimitiveData
This commit is contained in:
parent
0a025f0464
commit
7b0a185a45
@ -25,17 +25,13 @@ protected:
|
||||
|
||||
uint32_t vertices_number; ///<顶点数量
|
||||
|
||||
VABMap * vab_map_list;
|
||||
|
||||
uint32_t index_number; ///<索引数量
|
||||
IndexType index_type; ///<索引类型
|
||||
IndexBuffer * ibo; ///<索引缓冲区
|
||||
|
||||
IBMap ibo_map;
|
||||
|
||||
protected:
|
||||
|
||||
const int GetVABIndex (const AnsiString &name); ///<取得顶点属性索引
|
||||
const int InitVAB(const AnsiString &name,const VkFormat format,const void *data); ///<取得顶点属性索引
|
||||
|
||||
public:
|
||||
|
||||
@ -60,9 +56,9 @@ public: //顶点缓冲区
|
||||
|
||||
const uint32_t GetVertexCount()const{ return vertices_number; } ///<取得顶点数量
|
||||
|
||||
VABMap * MapVAB (const AnsiString &name);
|
||||
VABMap * MapVAB (const AnsiString &name,const VkFormat format=VK_FORMAT_UNDEFINED);
|
||||
|
||||
bool WriteVAB (const AnsiString &name,const VkFormat &format,const void *data); ///<直接写入顶点属性数据
|
||||
bool WriteVAB (const AnsiString &name,const VkFormat format,const void *data); ///<直接写入顶点属性数据
|
||||
|
||||
public: //索引缓冲区
|
||||
|
||||
|
@ -52,7 +52,7 @@ public:
|
||||
|
||||
const IndexType GetType()const{return buffer->GetType();}
|
||||
|
||||
void Set(IndexBuffer *ib,const int32_t index_offset,const uint32_t count)
|
||||
void SetIBO(IndexBuffer *ib,const int32_t index_offset,const uint32_t count)
|
||||
{
|
||||
VKBufferMap<IndexBuffer>::Set(ib,index_offset,ib->GetStride(),count);
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ public:
|
||||
|
||||
const VkFormat GetFormat()const { return buffer->GetFormat(); }
|
||||
|
||||
void Set(VAB *vab,const VkDeviceSize off,const uint32_t count)
|
||||
void SetVAB(VAB *vab,const VkDeviceSize off,const uint32_t count)
|
||||
{
|
||||
VKBufferMap<VAB>::Set(vab,off,vab->GetStride(),count);
|
||||
}
|
||||
|
@ -15,8 +15,6 @@ PrimitiveCreater::PrimitiveCreater(GPUDevice *dev,const VIL *v)
|
||||
|
||||
prim_data =nullptr;
|
||||
|
||||
vab_map_list =new VABMap[v->GetVertexAttribCount()];
|
||||
|
||||
Clear();
|
||||
}
|
||||
|
||||
@ -30,7 +28,6 @@ PrimitiveCreater::PrimitiveCreater(VertexDataManager *_vdm)
|
||||
|
||||
PrimitiveCreater::~PrimitiveCreater()
|
||||
{
|
||||
delete[] vab_map_list;
|
||||
SAFE_CLEAR(prim_data);
|
||||
}
|
||||
|
||||
@ -94,8 +91,6 @@ bool PrimitiveCreater::Init(const AnsiString &pname,const uint32_t vertex_count,
|
||||
delete prim_data;
|
||||
return(false);
|
||||
}
|
||||
|
||||
ibo_map.Set(ibo,prim_data->GetFirstIndex(),index_number);
|
||||
|
||||
#ifdef _DEBUG
|
||||
if(!vdm)
|
||||
@ -116,75 +111,72 @@ bool PrimitiveCreater::Init(const AnsiString &pname,const uint32_t vertex_count,
|
||||
return(true);
|
||||
}
|
||||
|
||||
const int PrimitiveCreater::GetVABIndex(const AnsiString &name)
|
||||
const int PrimitiveCreater::InitVAB(const AnsiString &name,const VkFormat format,const void *data)
|
||||
{
|
||||
if(!prim_data)return(-1);
|
||||
|
||||
const int vab_index=prim_data->GetVABIndex(name);
|
||||
|
||||
if(vab_index<0)
|
||||
if(vab_index<0||vab_index>=vil->GetVertexAttribCount())
|
||||
return(-1);
|
||||
|
||||
if(format!=VK_FORMAT_UNDEFINED)
|
||||
{
|
||||
const VIF *vif=vil->GetConfig(vab_index);
|
||||
|
||||
if(vif->format!=format)
|
||||
return(-2);
|
||||
}
|
||||
|
||||
VAB *vab=prim_data->GetVAB(vab_index);
|
||||
|
||||
if(!vab)
|
||||
{
|
||||
vab=prim_data->InitVAB(vab_index,nullptr);
|
||||
vab=prim_data->InitVAB(vab_index,data);
|
||||
|
||||
if(vab)
|
||||
vab_map_list[vab_index].Set(vab,
|
||||
prim_data->GetVertexOffset(),
|
||||
vertices_number);
|
||||
}
|
||||
if(!vab)
|
||||
return(-1);
|
||||
|
||||
if(!vab)
|
||||
return(-1);
|
||||
|
||||
#ifdef _DEBUG
|
||||
if (!vdm)
|
||||
{
|
||||
DebugUtils *du=device->GetDebugUtils();
|
||||
|
||||
if (du)
|
||||
#ifdef _DEBUG
|
||||
if (!vdm)
|
||||
{
|
||||
du->SetBuffer(vab->GetBuffer(), prim_name+":VAB:Buffer:"+name);
|
||||
du->SetDeviceMemory(vab->GetVkMemory(), prim_name+":VAB:Memory:"+name);
|
||||
DebugUtils *du=device->GetDebugUtils();
|
||||
|
||||
if (du)
|
||||
{
|
||||
du->SetBuffer(vab->GetBuffer(), prim_name+":VAB:Buffer:"+name);
|
||||
du->SetDeviceMemory(vab->GetVkMemory(), prim_name+":VAB:Memory:"+name);
|
||||
}
|
||||
}
|
||||
#endif//_DEBUG
|
||||
}
|
||||
#endif//_DEBUG
|
||||
|
||||
return(vab_index);
|
||||
}
|
||||
|
||||
VABMap *PrimitiveCreater::MapVAB(const AnsiString &name)
|
||||
VABMap *PrimitiveCreater::MapVAB(const AnsiString &name,const VkFormat format)
|
||||
{
|
||||
const int vab_index=GetVABIndex(name);
|
||||
const int vab_index=InitVAB(name,format,nullptr);
|
||||
|
||||
if(vab_index<0)return nullptr;
|
||||
|
||||
return vab_map_list+vab_index;
|
||||
return prim_data->GetVABMap(vab_index);
|
||||
}
|
||||
|
||||
bool PrimitiveCreater::WriteVAB(const AnsiString &name,const VkFormat &format, const void *data)
|
||||
bool PrimitiveCreater::WriteVAB(const AnsiString &name,const VkFormat format,const void *data)
|
||||
{
|
||||
if(!prim_data)return(false);
|
||||
if(!data)return(false);
|
||||
|
||||
const int vab_index=GetVABIndex(name);
|
||||
|
||||
VAB *vab=prim_data->GetVAB(vab_index);
|
||||
|
||||
if(!vab)
|
||||
return(false);
|
||||
|
||||
return vab->Write(data,prim_data->GetVertexOffset(),vertices_number);
|
||||
return InitVAB(name,format,data)>0;
|
||||
}
|
||||
|
||||
IBMap *PrimitiveCreater::MapIBO()
|
||||
{
|
||||
if(!ibo)
|
||||
if(!prim_data)
|
||||
return(nullptr);
|
||||
|
||||
return &ibo_map;
|
||||
return prim_data->MapIBO();
|
||||
}
|
||||
|
||||
bool PrimitiveCreater::WriteIBO(const void *data,const uint32_t count)
|
||||
@ -205,10 +197,7 @@ Primitive *PrimitiveCreater::Create()
|
||||
if(!prim_data)
|
||||
return(nullptr);
|
||||
|
||||
for(uint32_t i=0;i<vil->GetVertexAttribCount();i++)
|
||||
vab_map_list[i].Clear();
|
||||
|
||||
ibo_map.Clear();
|
||||
prim_data->UnmapAll();
|
||||
|
||||
Primitive *primitive=new Primitive(prim_name,prim_data);
|
||||
|
||||
|
@ -14,12 +14,14 @@ PrimitiveData::PrimitiveData(const VIL *_vil,const uint32_t vc)
|
||||
vertex_count=vc;
|
||||
|
||||
vab_list=hgl_zero_new<VAB *>(_vil->GetVertexAttribCount());
|
||||
vab_map_list=new VABMap[_vil->GetVertexAttribCount()];
|
||||
|
||||
ibo=nullptr;
|
||||
}
|
||||
|
||||
PrimitiveData::~PrimitiveData()
|
||||
{
|
||||
delete[] vab_map_list;
|
||||
delete[] vab_list; //注意:这里并不释放VAB,在派生类中释放
|
||||
}
|
||||
|
||||
@ -42,6 +44,73 @@ VAB *PrimitiveData::GetVAB(const int index)
|
||||
return vab_list[index];
|
||||
}
|
||||
|
||||
VAB *PrimitiveData::InitVAB(const int vab_index,const void *data)
|
||||
{
|
||||
if(!vil)return(nullptr);
|
||||
|
||||
if(vab_index<0||vab_index>=vil->GetVertexAttribCount())
|
||||
return(nullptr);
|
||||
|
||||
const VertexInputFormat *vif=vil->GetConfig(vab_index);
|
||||
|
||||
if(!vif)return(nullptr);
|
||||
|
||||
if(!vab_list[vab_index])
|
||||
{
|
||||
vab_list[vab_index]=CreateVAB(vab_index,vif->format,data);
|
||||
|
||||
if(!vab_list[vab_index])
|
||||
return(nullptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
vab_map_list[vab_index].Write(data,vertex_count);
|
||||
}
|
||||
|
||||
return vab_list[vab_index];
|
||||
}
|
||||
|
||||
VABMap *PrimitiveData::GetVABMap(const int vab_index)
|
||||
{
|
||||
if(vab_index<0||vab_index>=vil->GetVertexAttribCount())return nullptr;
|
||||
|
||||
VABMap *vab_map=vab_map_list+vab_index;
|
||||
|
||||
if(!vab_map->IsValid())
|
||||
{
|
||||
if(!vab_list[vab_index])
|
||||
return(nullptr);
|
||||
|
||||
vab_map->SetVAB(vab_list[vab_index],GetVertexOffset(),vertex_count);
|
||||
}
|
||||
|
||||
return vab_map;
|
||||
}
|
||||
|
||||
IndexBuffer *PrimitiveData::InitIBO(const uint32_t ic,IndexType it)
|
||||
{
|
||||
if(ibo)delete ibo;
|
||||
|
||||
ibo=CreateIBO(ic,it);
|
||||
|
||||
if(!ibo)
|
||||
return(nullptr);
|
||||
|
||||
index_count=ic;
|
||||
|
||||
ibo_map.SetIBO(ibo,GetFirstIndex(),index_count);
|
||||
|
||||
return(ibo);
|
||||
}
|
||||
|
||||
void PrimitiveData::UnmapAll()
|
||||
{
|
||||
for(int i=0;i<vil->GetVertexAttribCount();i++)
|
||||
vab_map_list[i].Unmap();
|
||||
|
||||
ibo_map.Unmap();
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
/**
|
||||
@ -81,48 +150,18 @@ namespace
|
||||
delete ibo;
|
||||
}
|
||||
|
||||
IndexBuffer *InitIBO(const uint32_t ic,IndexType it) override
|
||||
{
|
||||
IndexBuffer *CreateIBO(const uint32_t ic,const IndexType &it) override
|
||||
{
|
||||
if(!device)return(nullptr);
|
||||
|
||||
if(ibo)delete ibo;
|
||||
|
||||
ibo=device->CreateIBO(it,ic);
|
||||
|
||||
if(!ibo)
|
||||
return(nullptr);
|
||||
|
||||
index_count=ic;
|
||||
|
||||
return(ibo);
|
||||
return device->CreateIBO(it,ic);
|
||||
}
|
||||
|
||||
VAB *InitVAB(const int vab_index,const void *data)
|
||||
VAB *CreateVAB(const int vab_index,const VkFormat format,const void *data) override
|
||||
{
|
||||
if(!device)return(nullptr);
|
||||
if(!vil)return(nullptr);
|
||||
|
||||
if(vab_index<0||vab_index>=vil->GetVertexAttribCount())
|
||||
return(nullptr);
|
||||
|
||||
const VertexInputFormat *vif=vil->GetConfig(vab_index);
|
||||
|
||||
if(!vif)return(nullptr);
|
||||
|
||||
if(!vab_list[vab_index])
|
||||
{
|
||||
vab_list[vab_index]=device->CreateVAB(vif->format,vertex_count,data);
|
||||
|
||||
if(!vab_list[vab_index])
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
if(vab_list[vab_index]&&data)
|
||||
{
|
||||
vab_list[vab_index]->Write(data,vertex_count);
|
||||
}
|
||||
|
||||
return vab_list[vab_index];
|
||||
return device->CreateVAB(format,vertex_count,data);
|
||||
}
|
||||
};//class PrimitiveDataPrivateBuffer:public PrimitiveData
|
||||
|
||||
@ -161,10 +200,10 @@ namespace
|
||||
vdm->ReleaseVAB(vab_node);
|
||||
}
|
||||
|
||||
IndexBuffer *InitIBO(const uint32_t ic,IndexType it) override
|
||||
IndexBuffer *CreateIBO(const uint32_t ic,const IndexType &it) override
|
||||
{
|
||||
if(ic<=0)return(nullptr);
|
||||
if(!vdm)return(nullptr);
|
||||
if(!vdm)
|
||||
return(nullptr);
|
||||
|
||||
if(!ib_node)
|
||||
{
|
||||
@ -172,39 +211,21 @@ namespace
|
||||
|
||||
if(!ib_node)
|
||||
return(nullptr);
|
||||
|
||||
ibo=vdm->GetIBO();
|
||||
}
|
||||
|
||||
index_count=ic;
|
||||
|
||||
return ibo;
|
||||
return vdm->GetIBO();
|
||||
}
|
||||
|
||||
VAB *InitVAB(const int vab_index,const void *data)
|
||||
|
||||
VAB *CreateVAB(const int vab_index,const VkFormat format,const void *data) override
|
||||
{
|
||||
if(!vdm)return(nullptr);
|
||||
if(!vil)return(nullptr);
|
||||
VAB *vab=vdm->GetVAB(vab_index);
|
||||
|
||||
if (vab_index<0||vab_index>=vil->GetVertexAttribCount())
|
||||
return(nullptr);
|
||||
if(!vab)return(nullptr);
|
||||
|
||||
const VertexInputFormat *vif=vil->GetConfig(vab_index);
|
||||
if(data)
|
||||
vab->Write(data,vab_node->GetStart(),vertex_count);
|
||||
|
||||
if(!vif)return(nullptr);
|
||||
|
||||
if (!vab_list[vab_index])
|
||||
{
|
||||
vab_list[vab_index]=vdm->GetVAB(vab_index);
|
||||
|
||||
if(!vab_list[vab_index])
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
if(vab_list[vab_index]&&data)
|
||||
vab_list[vab_index]->Write(data,vab_node->GetStart(),vertex_count);
|
||||
|
||||
return vab_list[vab_index];
|
||||
return vab;
|
||||
}
|
||||
};//class PrimitiveDataVDM:public PrimitiveData
|
||||
}//namespace
|
||||
|
@ -1,4 +1,7 @@
|
||||
#include<hgl/graph/VK.h>
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/VKIndexBuffer.h>
|
||||
#include<hgl/graph/VKVertexAttribBuffer.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
/*
|
||||
@ -25,7 +28,16 @@ protected:
|
||||
uint32_t index_count;
|
||||
|
||||
VAB ** vab_list;
|
||||
IndexBuffer * ibo;
|
||||
VABMap * vab_map_list;
|
||||
|
||||
virtual VAB * CreateVAB(const int vab_index,const VkFormat format,const void *data)=0;
|
||||
|
||||
protected:
|
||||
|
||||
IndexBuffer * ibo;
|
||||
IBMap ibo_map;
|
||||
|
||||
virtual IndexBuffer *CreateIBO(const uint32_t ic,const IndexType &it)=0;
|
||||
|
||||
public:
|
||||
|
||||
@ -37,21 +49,23 @@ public:
|
||||
const uint32_t GetVertexCount ()const{return vertex_count;}
|
||||
const int GetVABCount ()const;
|
||||
const int GetVABIndex (const AnsiString &name)const;
|
||||
VAB * GetVAB (const int index);
|
||||
VAB * GetVAB (const AnsiString &name){return GetVAB(GetVABIndex(name));}
|
||||
|
||||
VAB * GetVAB (const int index);
|
||||
VAB * InitVAB (const int vab_index,const void *data);
|
||||
VABMap * GetVABMap (const int vab_index);
|
||||
|
||||
IndexBuffer * InitIBO(const uint32_t index_count,IndexType it);
|
||||
IndexBuffer * GetIBO (){return ibo;}
|
||||
IBMap * MapIBO (){return &ibo_map;}
|
||||
uint32_t GetIndexCount ()const{return index_count;}
|
||||
|
||||
virtual int32_t GetVertexOffset ()const=0; ///<取得顶点偏移(注意是顶点不是字节)
|
||||
virtual uint32_t GetFirstIndex ()const=0; ///<取得第一个索引
|
||||
|
||||
virtual VertexDataManager * GetVDM()const=0; ///<取得顶点数据管理器
|
||||
virtual VertexDataManager * GetVDM()const=0; ///<取得顶点数据管理器
|
||||
|
||||
public:
|
||||
void UnmapAll();
|
||||
|
||||
virtual IndexBuffer * InitIBO(const uint32_t index_count,IndexType it)=0;
|
||||
virtual VAB * InitVAB(const int vab_index,const void *data)=0;
|
||||
};//class PrimitiveData
|
||||
|
||||
PrimitiveData *CreatePrimitiveData(GPUDevice *dev,const VIL *_vil,const uint32_t vc);
|
||||
|
Loading…
x
Reference in New Issue
Block a user