supported newly IBMap,can RUN OK!!!
This commit is contained in:
parent
419e0e2574
commit
8a0215aee6
@ -28,8 +28,7 @@ protected:
|
|||||||
uint vab_proc_count; ///<操作的vab数量
|
uint vab_proc_count; ///<操作的vab数量
|
||||||
|
|
||||||
VkDeviceSize index_number; ///<索引数量
|
VkDeviceSize index_number; ///<索引数量
|
||||||
IndexBuffer * ibo;
|
IBAccess * iba;
|
||||||
void * ibo_map;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
@ -54,36 +53,13 @@ public:
|
|||||||
return AcquirePVB(name,format,data,bytes);
|
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;}
|
||||||
|
|
||||||
|
bool WriteIBO(const void *data,const VkDeviceSize bytes);
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
T * AccessIBO()
|
bool WriteIBO(const T *data){return WriteIBO(data,index_number*sizeof(T));}
|
||||||
{
|
|
||||||
if(!ibo)return(nullptr);
|
|
||||||
if(ibo->GetStride()!=sizeof(T))return(nullptr);
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual Primitive * Finish(RenderResource *); ///<结束并创建可渲染对象
|
virtual Primitive * Finish(RenderResource *); ///<结束并创建可渲染对象
|
||||||
};//class PrimitiveCreater
|
};//class PrimitiveCreater
|
||||||
@ -205,4 +181,41 @@ typedef VABMap<VB4u32> VABMap4u32,VABMap4ui;
|
|||||||
typedef VABMap<VB4f> VABMap4f;
|
typedef VABMap<VB4f> VABMap4f;
|
||||||
typedef VABMap<VB4d> VABMap4d;
|
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
|
VK_NAMESPACE_END
|
@ -354,8 +354,12 @@ namespace hgl
|
|||||||
return rc.Finish(db);
|
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 i = 0; i < numberParallels; i++)
|
||||||
{
|
{
|
||||||
for (uint j = 0; j < numberSlices; j++)
|
for (uint j = 0; j < numberSlices; j++)
|
||||||
@ -524,9 +528,9 @@ namespace hgl
|
|||||||
{
|
{
|
||||||
const IndexType index_type=rc.GetIndexType();
|
const IndexType index_type=rc.GetIndexType();
|
||||||
|
|
||||||
if(index_type==IndexType::U16)CreateSphereIndices<uint16>(rc.AccessIBO<uint16>(),numberParallels,numberSlices);else
|
if(index_type==IndexType::U16)CreateSphereIndices<uint16>(&rc,numberParallels,numberSlices);else
|
||||||
if(index_type==IndexType::U32)CreateSphereIndices<uint32>(rc.AccessIBO<uint32>(),numberParallels,numberSlices);else
|
if(index_type==IndexType::U32)CreateSphereIndices<uint32>(&rc,numberParallels,numberSlices);else
|
||||||
if(index_type==IndexType::U8 )CreateSphereIndices<uint8 >(rc.AccessIBO<uint8 >(),numberParallels,numberSlices);else
|
if(index_type==IndexType::U8 )CreateSphereIndices<uint8 >(&rc,numberParallels,numberSlices);else
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -618,9 +622,9 @@ namespace hgl
|
|||||||
{
|
{
|
||||||
const IndexType index_type=rc.GetIndexType();
|
const IndexType index_type=rc.GetIndexType();
|
||||||
|
|
||||||
if(index_type==IndexType::U16)CreateSphereIndices<uint16>(rc.AccessIBO<uint16>(),numberParallels,numberSlices);else
|
if(index_type==IndexType::U16)CreateSphereIndices<uint16>(&rc,numberParallels,numberSlices);else
|
||||||
if(index_type==IndexType::U32)CreateSphereIndices<uint32>(rc.AccessIBO<uint32>(),numberParallels,numberSlices);else
|
if(index_type==IndexType::U32)CreateSphereIndices<uint32>(&rc,numberParallels,numberSlices);else
|
||||||
if(index_type==IndexType::U8 )CreateSphereIndices<uint8 >(rc.AccessIBO<uint8 >(),numberParallels,numberSlices);else
|
if(index_type==IndexType::U8 )CreateSphereIndices<uint8 >(&rc,numberParallels,numberSlices);else
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -630,8 +634,11 @@ namespace hgl
|
|||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
template<typename T>
|
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
|
// loop counters
|
||||||
uint sideCount, faceCount;
|
uint sideCount, faceCount;
|
||||||
|
|
||||||
@ -767,9 +774,9 @@ namespace hgl
|
|||||||
{
|
{
|
||||||
const IndexType index_type=rc.GetIndexType();
|
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::U16)CreateTorusIndices<uint16>(&rc,tci->numberSlices,tci->numberStacks);else
|
||||||
if(index_type==IndexType::U32)CreateTorusIndices<uint32>(rc.AccessIBO<uint32>(),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.AccessIBO<uint8 >(),tci->numberSlices,tci->numberStacks);else
|
if(index_type==IndexType::U8 )CreateTorusIndices<uint8 >(&rc,tci->numberSlices,tci->numberStacks);else
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
}
|
}
|
||||||
return rc.Finish(db);
|
return rc.Finish(db);
|
||||||
@ -778,8 +785,10 @@ namespace hgl
|
|||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
template<typename T>
|
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;
|
uint i;
|
||||||
|
|
||||||
T centerIndex = 0;
|
T centerIndex = 0;
|
||||||
@ -1003,9 +1012,9 @@ namespace hgl
|
|||||||
{
|
{
|
||||||
const IndexType index_type=rc.GetIndexType();
|
const IndexType index_type=rc.GetIndexType();
|
||||||
|
|
||||||
if(index_type==IndexType::U16)CreateCylinderIndices<uint16>(rc.AccessIBO<uint16>(),cci->numberSlices);else
|
if(index_type==IndexType::U16)CreateCylinderIndices<uint16>(&rc,cci->numberSlices);else
|
||||||
if(index_type==IndexType::U32)CreateCylinderIndices<uint32>(rc.AccessIBO<uint32>(),cci->numberSlices);else
|
if(index_type==IndexType::U32)CreateCylinderIndices<uint32>(&rc,cci->numberSlices);else
|
||||||
if(index_type==IndexType::U8 )CreateCylinderIndices<uint8 >(rc.AccessIBO<uint8 >(),cci->numberSlices);else
|
if(index_type==IndexType::U8 )CreateCylinderIndices<uint8 >(&rc,cci->numberSlices);else
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1015,8 +1024,11 @@ namespace hgl
|
|||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
template<typename T>
|
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
|
// Bottom
|
||||||
uint centerIndex = 0;
|
uint centerIndex = 0;
|
||||||
uint indexCounter = 1;
|
uint indexCounter = 1;
|
||||||
@ -1177,9 +1189,9 @@ namespace hgl
|
|||||||
{
|
{
|
||||||
const IndexType index_type=rc.GetIndexType();
|
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::U16)CreateConeIndices<uint16>(&rc,cci->numberSlices,cci->numberStacks);else
|
||||||
if(index_type==IndexType::U32)CreateConeIndices<uint32>(rc.AccessIBO<uint32>(),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.AccessIBO<uint8 >(),cci->numberSlices,cci->numberStacks);else
|
if(index_type==IndexType::U8 )CreateConeIndices<uint8 >(&rc,cci->numberSlices,cci->numberStacks);else
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
|
|
||||||
PrimitiveData *CreatePrimitiveData(const VIL *_vil,const VkDeviceSize vc);
|
PrimitiveData *CreatePrimitiveData(const VIL *_vil,const VkDeviceSize vc);
|
||||||
|
IBAccess * GetIBAccess( PrimitiveData *pd);
|
||||||
void SetIndexBuffer( PrimitiveData *pd,IndexBuffer *ib,const VkDeviceSize ic);
|
void SetIndexBuffer( PrimitiveData *pd,IndexBuffer *ib,const VkDeviceSize ic);
|
||||||
VABAccess * GetVABAccess( PrimitiveData *pd,const int);
|
VABAccess * GetVABAccess( PrimitiveData *pd,const int);
|
||||||
void Destory( PrimitiveData *pd);
|
void Destory( PrimitiveData *pd);
|
||||||
@ -22,10 +23,9 @@ PrimitiveCreater::PrimitiveCreater(GPUDevice *dev,const VIL *v,const AnsiString
|
|||||||
|
|
||||||
vertices_number =0;
|
vertices_number =0;
|
||||||
vab_proc_count =0;
|
vab_proc_count =0;
|
||||||
index_number =0;
|
|
||||||
|
|
||||||
ibo =nullptr;
|
index_number =0;
|
||||||
ibo_map =nullptr;
|
iba =nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
//PrimitiveCreater::PrimitiveCreater(VertexDataManager *_vdm)
|
//PrimitiveCreater::PrimitiveCreater(VertexDataManager *_vdm)
|
||||||
@ -67,21 +67,24 @@ bool PrimitiveCreater::Init(const VkDeviceSize vertex_count,const VkDeviceSize i
|
|||||||
return(false);
|
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;
|
index_number=index_count;
|
||||||
|
|
||||||
SetIndexBuffer(prim_data,ibo,index_count);
|
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
DebugUtils *du=device->GetDebugUtils();
|
DebugUtils *du=device->GetDebugUtils();
|
||||||
|
|
||||||
if(du)
|
if(du)
|
||||||
{
|
{
|
||||||
du->SetBuffer( ibo->GetBuffer(), prim_name+":IndexBuffer:Buffer");
|
du->SetBuffer( iba->buffer->GetBuffer(), prim_name+":IndexBuffer:Buffer");
|
||||||
du->SetDeviceMemory(ibo->GetVkMemory(), prim_name+":IndexBuffer:Memory");
|
du->SetDeviceMemory(iba->buffer->GetVkMemory(), prim_name+":IndexBuffer:Memory");
|
||||||
}
|
}
|
||||||
#endif//_DEBUG
|
#endif//_DEBUG
|
||||||
}
|
}
|
||||||
@ -141,15 +144,19 @@ VABAccess *PrimitiveCreater::AcquirePVB(const AnsiString &name,const VkFormat &a
|
|||||||
return vab_access;
|
return vab_access;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrimitiveCreater::ClearAllData()
|
bool PrimitiveCreater::WriteIBO(const void *data,const VkDeviceSize bytes)
|
||||||
{
|
{
|
||||||
if(ibo_map)
|
if(!data)return(false);
|
||||||
{
|
|
||||||
ibo->Unmap();
|
if(bytes>0)
|
||||||
ibo_map=nullptr;
|
if(iba->buffer->GetStride()*index_number<bytes)return(false);
|
||||||
|
|
||||||
|
return iba->buffer->Write(data,bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
ibo=nullptr;
|
void PrimitiveCreater::ClearAllData()
|
||||||
|
{
|
||||||
|
iba=nullptr;
|
||||||
|
|
||||||
if(prim_data)
|
if(prim_data)
|
||||||
{
|
{
|
||||||
@ -165,12 +172,6 @@ Primitive *PrimitiveCreater::Finish(RenderResource *rr)
|
|||||||
if(vab_proc_count!=si_count)
|
if(vab_proc_count!=si_count)
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
|
|
||||||
if(ibo_map)
|
|
||||||
{
|
|
||||||
ibo->Unmap();
|
|
||||||
ibo_map=nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
Primitive *primitive=rr->CreatePrimitive(prim_name,prim_data);
|
Primitive *primitive=rr->CreatePrimitive(prim_name,prim_data);
|
||||||
|
|
||||||
if(!primitive)
|
if(!primitive)
|
||||||
@ -179,8 +180,7 @@ Primitive *PrimitiveCreater::Finish(RenderResource *rr)
|
|||||||
return(nullptr);
|
return(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
ibo_map=nullptr;
|
iba=nullptr;
|
||||||
ibo=nullptr;
|
|
||||||
prim_data=nullptr;
|
prim_data=nullptr;
|
||||||
|
|
||||||
return primitive;
|
return primitive;
|
||||||
|
@ -144,14 +144,14 @@ VABAccess *GetVABAccess(PrimitiveData *pd,const AnsiString &name)
|
|||||||
// return vaba;
|
// return vaba;
|
||||||
//}
|
//}
|
||||||
|
|
||||||
void SetIndexBuffer(PrimitiveData *pd,IndexBuffer *ib,const VkDeviceSize ic)
|
//void SetIndexBuffer(PrimitiveData *pd,IndexBuffer *ib,const VkDeviceSize ic)
|
||||||
{
|
//{
|
||||||
if(!pd)return;
|
// if(!pd)return;
|
||||||
|
//
|
||||||
pd->ib_access.buffer=ib;
|
// pd->ib_access.buffer=ib;
|
||||||
pd->ib_access.start=0;
|
// pd->ib_access.start=0;
|
||||||
pd->ib_access.count=ic;
|
// pd->ib_access.count=ic;
|
||||||
}
|
//}
|
||||||
|
|
||||||
IBAccess *GetIBAccess(PrimitiveData *pd)
|
IBAccess *GetIBAccess(PrimitiveData *pd)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user