supported newly IBMap,can RUN OK!!!

This commit is contained in:
hyzboy 2024-05-23 14:00:23 +08:00
parent 419e0e2574
commit 8a0215aee6
4 changed files with 106 additions and 81 deletions

View File

@ -28,8 +28,7 @@ protected:
uint vab_proc_count; ///<操作的vab数量
VkDeviceSize index_number; ///<索引数量
IndexBuffer * ibo;
void * ibo_map;
IBAccess * iba;
protected:
@ -54,36 +53,13 @@ public:
return AcquirePVB(name,format,data,bytes);
}
const IndexType GetIndexType()const{return ibo?ibo->GetType():IndexType::ERR;} ///<取得索引数据类型
const IndexType GetIndexType()const{return iba->buffer->GetType();}
IBAccess * AcquireIBO(){return iba;}
template<typename T>
T * AccessIBO()
{
if(!ibo)return(nullptr);
if(ibo->GetStride()!=sizeof(T))return(nullptr);
bool WriteIBO(const void *data,const VkDeviceSize bytes);
if(!ibo_map)
ibo_map=ibo->Map();
return (T *)ibo_map;
}
template<typename T> bool WriteIBO(const T *data)
{
if(!ibo)return(false);
if(ibo->GetStride()!=sizeof(T))return(false);
if(ibo_map)
{
hgl_cpy<T>((T *)ibo_map,data,index_number);
ibo->Unmap();
ibo_map=nullptr;
}
else
ibo->Write(data);
return(true);
}
template<typename T>
bool WriteIBO(const T *data){return WriteIBO(data,index_number*sizeof(T));}
virtual Primitive * Finish(RenderResource *); ///<结束并创建可渲染对象
};//class PrimitiveCreater
@ -205,4 +181,41 @@ typedef VABMap<VB4u32> VABMap4u32,VABMap4ui;
typedef VABMap<VB4f> VABMap4f;
typedef VABMap<VB4d> VABMap4d;
/**
* 访
*/
template<typename T> class IBMap
{
IBAccess *iba;
T *map_ptr;
public:
IBMap(IBAccess *a)
{
iba=a;
if(iba)
map_ptr=(T *)(iba->buffer->Map(iba->start,iba->count));
else
map_ptr=nullptr;
}
IBMap(PrimitiveCreater *pc):IBMap(pc->AcquireIBO()){}
~IBMap()
{
if(iba)
iba->buffer->Unmap();
}
const bool IsValid()const{ return iba; }
operator T *(){ return map_ptr; }
};//template<typename T> class IBMap
using IBMapU8=IBMap<uint8>;
using IBMapU16=IBMap<uint16>;
using IBMapU32=IBMap<uint32>;
VK_NAMESPACE_END

View File

@ -354,8 +354,12 @@ namespace hgl
return rc.Finish(db);
}
template<typename T> void CreateSphereIndices(T *tp,uint numberParallels,const uint numberSlices)
template<typename T>
void CreateSphereIndices(PrimitiveCreater *pc,uint numberParallels,const uint numberSlices)
{
IBMap<T> ib_map(pc);
T *tp=ib_map;
for (uint i = 0; i < numberParallels; i++)
{
for (uint j = 0; j < numberSlices; j++)
@ -524,9 +528,9 @@ namespace hgl
{
const IndexType index_type=rc.GetIndexType();
if(index_type==IndexType::U16)CreateSphereIndices<uint16>(rc.AccessIBO<uint16>(),numberParallels,numberSlices);else
if(index_type==IndexType::U32)CreateSphereIndices<uint32>(rc.AccessIBO<uint32>(),numberParallels,numberSlices);else
if(index_type==IndexType::U8 )CreateSphereIndices<uint8 >(rc.AccessIBO<uint8 >(),numberParallels,numberSlices);else
if(index_type==IndexType::U16)CreateSphereIndices<uint16>(&rc,numberParallels,numberSlices);else
if(index_type==IndexType::U32)CreateSphereIndices<uint32>(&rc,numberParallels,numberSlices);else
if(index_type==IndexType::U8 )CreateSphereIndices<uint8 >(&rc,numberParallels,numberSlices);else
return(nullptr);
}
@ -618,9 +622,9 @@ namespace hgl
{
const IndexType index_type=rc.GetIndexType();
if(index_type==IndexType::U16)CreateSphereIndices<uint16>(rc.AccessIBO<uint16>(),numberParallels,numberSlices);else
if(index_type==IndexType::U32)CreateSphereIndices<uint32>(rc.AccessIBO<uint32>(),numberParallels,numberSlices);else
if(index_type==IndexType::U8 )CreateSphereIndices<uint8 >(rc.AccessIBO<uint8 >(),numberParallels,numberSlices);else
if(index_type==IndexType::U16)CreateSphereIndices<uint16>(&rc,numberParallels,numberSlices);else
if(index_type==IndexType::U32)CreateSphereIndices<uint32>(&rc,numberParallels,numberSlices);else
if(index_type==IndexType::U8 )CreateSphereIndices<uint8 >(&rc,numberParallels,numberSlices);else
return(nullptr);
}
@ -630,8 +634,11 @@ namespace hgl
namespace
{
template<typename T>
void CreateTorusIndices(T *tp,uint numberSlices,uint numberStacks)
void CreateTorusIndices(PrimitiveCreater *pc,uint numberSlices,uint numberStacks)
{
IBMap<T> ib_map(pc);
T *tp=ib_map;
// loop counters
uint sideCount, faceCount;
@ -767,9 +774,9 @@ namespace hgl
{
const IndexType index_type=rc.GetIndexType();
if(index_type==IndexType::U16)CreateTorusIndices<uint16>(rc.AccessIBO<uint16>(),tci->numberSlices,tci->numberStacks);else
if(index_type==IndexType::U32)CreateTorusIndices<uint32>(rc.AccessIBO<uint32>(),tci->numberSlices,tci->numberStacks);else
if(index_type==IndexType::U8 )CreateTorusIndices<uint8 >(rc.AccessIBO<uint8 >(),tci->numberSlices,tci->numberStacks);else
if(index_type==IndexType::U16)CreateTorusIndices<uint16>(&rc,tci->numberSlices,tci->numberStacks);else
if(index_type==IndexType::U32)CreateTorusIndices<uint32>(&rc,tci->numberSlices,tci->numberStacks);else
if(index_type==IndexType::U8 )CreateTorusIndices<uint8 >(&rc,tci->numberSlices,tci->numberStacks);else
return(nullptr);
}
return rc.Finish(db);
@ -778,8 +785,10 @@ namespace hgl
namespace
{
template<typename T>
void CreateCylinderIndices(T *tp,const uint numberSlices)
void CreateCylinderIndices(PrimitiveCreater *pc,const uint numberSlices)
{
IBMap<T> ib_map(pc);
T *tp=ib_map;
uint i;
T centerIndex = 0;
@ -1003,9 +1012,9 @@ namespace hgl
{
const IndexType index_type=rc.GetIndexType();
if(index_type==IndexType::U16)CreateCylinderIndices<uint16>(rc.AccessIBO<uint16>(),cci->numberSlices);else
if(index_type==IndexType::U32)CreateCylinderIndices<uint32>(rc.AccessIBO<uint32>(),cci->numberSlices);else
if(index_type==IndexType::U8 )CreateCylinderIndices<uint8 >(rc.AccessIBO<uint8 >(),cci->numberSlices);else
if(index_type==IndexType::U16)CreateCylinderIndices<uint16>(&rc,cci->numberSlices);else
if(index_type==IndexType::U32)CreateCylinderIndices<uint32>(&rc,cci->numberSlices);else
if(index_type==IndexType::U8 )CreateCylinderIndices<uint8 >(&rc,cci->numberSlices);else
return(nullptr);
}
@ -1015,8 +1024,11 @@ namespace hgl
namespace
{
template<typename T>
void CreateConeIndices(T *tp,const uint numberSlices,const uint numberStacks)
void CreateConeIndices(PrimitiveCreater *pc,const uint numberSlices,const uint numberStacks)
{
IBMap<T> ib_map(pc);
T *tp=ib_map;
// Bottom
uint centerIndex = 0;
uint indexCounter = 1;
@ -1177,9 +1189,9 @@ namespace hgl
{
const IndexType index_type=rc.GetIndexType();
if(index_type==IndexType::U16)CreateConeIndices<uint16>(rc.AccessIBO<uint16>(),cci->numberSlices,cci->numberStacks);else
if(index_type==IndexType::U32)CreateConeIndices<uint32>(rc.AccessIBO<uint32>(),cci->numberSlices,cci->numberStacks);else
if(index_type==IndexType::U8 )CreateConeIndices<uint8 >(rc.AccessIBO<uint8 >(),cci->numberSlices,cci->numberStacks);else
if(index_type==IndexType::U16)CreateConeIndices<uint16>(&rc,cci->numberSlices,cci->numberStacks);else
if(index_type==IndexType::U32)CreateConeIndices<uint32>(&rc,cci->numberSlices,cci->numberStacks);else
if(index_type==IndexType::U8 )CreateConeIndices<uint8 >(&rc,cci->numberSlices,cci->numberStacks);else
return(nullptr);
}

View File

@ -7,6 +7,7 @@
VK_NAMESPACE_BEGIN
PrimitiveData *CreatePrimitiveData(const VIL *_vil,const VkDeviceSize vc);
IBAccess * GetIBAccess( PrimitiveData *pd);
void SetIndexBuffer( PrimitiveData *pd,IndexBuffer *ib,const VkDeviceSize ic);
VABAccess * GetVABAccess( PrimitiveData *pd,const int);
void Destory( PrimitiveData *pd);
@ -22,10 +23,9 @@ PrimitiveCreater::PrimitiveCreater(GPUDevice *dev,const VIL *v,const AnsiString
vertices_number =0;
vab_proc_count =0;
index_number =0;
ibo =nullptr;
ibo_map =nullptr;
index_number =0;
iba =nullptr;
}
//PrimitiveCreater::PrimitiveCreater(VertexDataManager *_vdm)
@ -67,21 +67,24 @@ bool PrimitiveCreater::Init(const VkDeviceSize vertex_count,const VkDeviceSize i
return(false);
}
ibo=device->CreateIBO(it,index_count);
iba=GetIBAccess(prim_data);
if(!ibo)return(false);
iba->buffer=device->CreateIBO(it,index_count);
if(!iba->buffer)return(false);
iba->start=0;
iba->count=index_count;
index_number=index_count;
SetIndexBuffer(prim_data,ibo,index_count);
#ifdef _DEBUG
DebugUtils *du=device->GetDebugUtils();
if(du)
{
du->SetBuffer( ibo->GetBuffer(), prim_name+":IndexBuffer:Buffer");
du->SetDeviceMemory(ibo->GetVkMemory(), prim_name+":IndexBuffer:Memory");
du->SetBuffer( iba->buffer->GetBuffer(), prim_name+":IndexBuffer:Buffer");
du->SetDeviceMemory(iba->buffer->GetVkMemory(), prim_name+":IndexBuffer:Memory");
}
#endif//_DEBUG
}
@ -141,15 +144,19 @@ VABAccess *PrimitiveCreater::AcquirePVB(const AnsiString &name,const VkFormat &a
return vab_access;
}
bool PrimitiveCreater::WriteIBO(const void *data,const VkDeviceSize bytes)
{
if(!data)return(false);
if(bytes>0)
if(iba->buffer->GetStride()*index_number<bytes)return(false);
return iba->buffer->Write(data,bytes);
}
void PrimitiveCreater::ClearAllData()
{
if(ibo_map)
{
ibo->Unmap();
ibo_map=nullptr;
}
ibo=nullptr;
iba=nullptr;
if(prim_data)
{
@ -165,12 +172,6 @@ Primitive *PrimitiveCreater::Finish(RenderResource *rr)
if(vab_proc_count!=si_count)
return(nullptr);
if(ibo_map)
{
ibo->Unmap();
ibo_map=nullptr;
}
Primitive *primitive=rr->CreatePrimitive(prim_name,prim_data);
if(!primitive)
@ -179,8 +180,7 @@ Primitive *PrimitiveCreater::Finish(RenderResource *rr)
return(nullptr);
}
ibo_map=nullptr;
ibo=nullptr;
iba=nullptr;
prim_data=nullptr;
return primitive;

View File

@ -144,14 +144,14 @@ VABAccess *GetVABAccess(PrimitiveData *pd,const AnsiString &name)
// return vaba;
//}
void SetIndexBuffer(PrimitiveData *pd,IndexBuffer *ib,const VkDeviceSize ic)
{
if(!pd)return;
pd->ib_access.buffer=ib;
pd->ib_access.start=0;
pd->ib_access.count=ic;
}
//void SetIndexBuffer(PrimitiveData *pd,IndexBuffer *ib,const VkDeviceSize ic)
//{
// if(!pd)return;
//
// pd->ib_access.buffer=ib;
// pd->ib_access.start=0;
// pd->ib_access.count=ic;
//}
IBAccess *GetIBAccess(PrimitiveData *pd)
{