[WIP] update PrimitiveCreater/PrimitiveData, CAN'T RUN.
This commit is contained in:
parent
ecb47dae4d
commit
e27442a0b4
@ -1 +1 @@
|
||||
Subproject commit 481d6a7924f373b8d0b40f25199eb987d4512fa8
|
||||
Subproject commit f220bd8370781f791b3c3a27bd7daa4dc96817e6
|
@ -4,7 +4,7 @@
|
||||
#include<hgl/graph/VertexAttribDataAccess.h>
|
||||
#include<hgl/graph/VKShaderModule.h>
|
||||
#include<hgl/graph/VKIndexBuffer.h>
|
||||
#include<hgl/graph/VKPrimitiveData.h>
|
||||
#include<hgl/graph/VKVertexAttribBuffer.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
class VertexDataManager;
|
||||
@ -20,59 +20,43 @@ protected:
|
||||
GPUDevice *device;
|
||||
const GPUPhysicalDevice *phy_device;
|
||||
|
||||
const VIL *vil;
|
||||
const VIL * vil;
|
||||
|
||||
protected:
|
||||
|
||||
PrimitiveData * prim_data;
|
||||
|
||||
void_pointer vab_map_ptr[HGL_MAX_VERTEX_ATTRIB_COUNT];
|
||||
|
||||
VkDeviceSize vertices_number;
|
||||
VkDeviceSize index_number;
|
||||
|
||||
IndexBuffer * ibo;
|
||||
void * ibo_map;
|
||||
VABAccessMap vab_map;
|
||||
|
||||
protected:
|
||||
|
||||
bool AcquirePVB(VABAccess *,const AnsiString &,const void *data); ///<请求一个顶点属性数据区
|
||||
template<typename T> friend class VABRawMap;
|
||||
template<typename T> friend class VABMap;
|
||||
|
||||
VABAccess *AcquirePVB(const AnsiString &,const VkFormat &,const void *data); ///<请求一个顶点属性数据区
|
||||
|
||||
void ClearAllData();
|
||||
|
||||
public:
|
||||
|
||||
PrimitiveCreater(GPUDevice *,const VIL *);
|
||||
PrimitiveCreater(VertexDataManager *);
|
||||
//PrimitiveCreater(VertexDataManager *);
|
||||
virtual ~PrimitiveCreater();
|
||||
|
||||
virtual bool Init(const uint32 vertices_count,const uint32 index_count,IndexType it=IndexType::AUTO); ///<初始化,参数为顶点数量
|
||||
virtual bool Init(const VkDeviceSize vertices_count,const VkDeviceSize index_count,IndexType it=IndexType::AUTO); ///<初始化,参数为顶点数量
|
||||
|
||||
template<typename T>
|
||||
T * AccessVAB(const AnsiString &name) ///<创建一个顶点属性数据缓冲区以及访问器
|
||||
{
|
||||
const VkFormat format=vil->GetVulkanFormat(name);
|
||||
|
||||
if(format!=T::GetVulkanFormat())
|
||||
return(nullptr);
|
||||
|
||||
VABAccess vad;
|
||||
|
||||
if(!this->AcquirePVB(&vad,name,nullptr))
|
||||
return(nullptr);
|
||||
|
||||
T *access=T::Create(vertices_number,vad.map_ptr);
|
||||
|
||||
access->Begin();
|
||||
|
||||
return access;
|
||||
}
|
||||
const VkDeviceSize GetVertexCount()const{ return vertices_number; } ///<取得顶点数量
|
||||
|
||||
bool WriteVAB(const AnsiString &name,const void *data,const uint32_t bytes); ///<直接写入顶点属性数据
|
||||
|
||||
const IndexType GetIndexType()const{return ibo?ibo->GetType():IndexType::ERR;} ///<取得索引数据类型
|
||||
|
||||
template<typename T> T *AccessIBO()
|
||||
template<typename T>
|
||||
T * AccessIBO()
|
||||
{
|
||||
if(!ibo)return(nullptr);
|
||||
if(ibo->GetStride()!=sizeof(T))return(nullptr);
|
||||
@ -92,4 +76,105 @@ public:
|
||||
|
||||
virtual Primitive * Finish(RenderResource *,const AnsiString &); ///<结束并创建可渲染对象
|
||||
};//class PrimitiveCreater
|
||||
|
||||
/**
|
||||
* VAB原生数据访问映射
|
||||
*/
|
||||
template<typename T> class VABRawMap
|
||||
{
|
||||
VABAccess *vaba;
|
||||
T *map_ptr;
|
||||
|
||||
public:
|
||||
|
||||
VABRawMap(PrimitiveCreater *pc,const AnsiString &name)
|
||||
{
|
||||
vaba=pc->AcquirePVB(name,T::GetVulkanFormat(),nullptr);
|
||||
|
||||
map_ptr=(T *)(vaba->vab->Map(vaba->start,vaba->count));
|
||||
}
|
||||
|
||||
~VABRawMap()
|
||||
{
|
||||
vaba->vab->Unmap();
|
||||
}
|
||||
|
||||
T *operator->(){ return map_ptr; }
|
||||
};//template<typename T> class VABRawMap
|
||||
|
||||
typedef VABRawMap<int8> VABRawMapi8, VABRawMapByte;
|
||||
typedef VABRawMap<int16> VABRawMapi16,VABRawMapShort;
|
||||
typedef VABRawMap<int32> VABRawMapi32,VABRawMapInt;
|
||||
typedef VABRawMap<uint8> VABRawMapu8, VABRawMapUByte;
|
||||
typedef VABRawMap<uint16> VABRawMapu16,VABRawMapUShort;
|
||||
typedef VABRawMap<uint32> VABRawMapu32,VABRawMapUInt;
|
||||
typedef VABRawMap<float> VABRawMapFloat;
|
||||
typedef VABRawMap<double> VABRawMapDouble;
|
||||
|
||||
/**
|
||||
* VAB VertexAttribDataAccess数据访问映射
|
||||
*/
|
||||
template<typename T> class VABMap
|
||||
{
|
||||
VABAccess *vaba;
|
||||
T *vb;
|
||||
|
||||
public:
|
||||
|
||||
VABMap(PrimitiveCreater *pc,const AnsiString &name)
|
||||
{
|
||||
vaba=pc->AcquirePVB(name,T::GetVulkanFormat(),nullptr);
|
||||
|
||||
void *map_ptr=vaba->vab->Map(vaba->start,vaba->count);
|
||||
|
||||
vb=T::Create(pc->GetVertexCount(),map_ptr);
|
||||
|
||||
vb->Begin();
|
||||
}
|
||||
|
||||
~VABMap()
|
||||
{
|
||||
vaba->vab->Unmap();
|
||||
}
|
||||
|
||||
void Restart()
|
||||
{
|
||||
vb->Begin();
|
||||
}
|
||||
|
||||
T *operator->(){ return vb; }
|
||||
};//template<typename T> class VABMap
|
||||
|
||||
typedef VABMap<VB1i8> VABMap1i8 ,VABMap1b;
|
||||
typedef VABMap<VB1i16> VABMap1i16,VABMap1s;
|
||||
typedef VABMap<VB1i32> VABMap1i32,VABMap1i;
|
||||
typedef VABMap<VB1u8> VABMap1u8 ,VABMap1ub;
|
||||
typedef VABMap<VB1u16> VABMap1u16,VABMap1us;
|
||||
typedef VABMap<VB1u32> VABMap1u32,VABMap1ui;
|
||||
typedef VABMap<VB1f> VABMap1f;
|
||||
typedef VABMap<VB1d> VABMap1d;
|
||||
|
||||
typedef VABMap<VB2i8> VABMap2i8 ,VABMap2b;
|
||||
typedef VABMap<VB2i16> VABMap2i16,VABMap2s;
|
||||
typedef VABMap<VB2i32> VABMap2i32,VABMap2i;
|
||||
typedef VABMap<VB2u8> VABMap2u8 ,VABMap2ub;
|
||||
typedef VABMap<VB2u16> VABMap2u16,VABMap2us;
|
||||
typedef VABMap<VB2u32> VABMap2u32,VABMap2ui;
|
||||
typedef VABMap<VB2f> VABMap2f;
|
||||
typedef VABMap<VB2d> VABMap2d;
|
||||
|
||||
typedef VABMap<VB3i32> VABMap3i32,VABMap3i;
|
||||
typedef VABMap<VB3u32> VABMap3u32,VABMap3ui;
|
||||
typedef VABMap<VB3f> VABMap3f;
|
||||
typedef VABMap<VB3d> VABMap3d;
|
||||
|
||||
typedef VABMap<VB4i8> VABMap4i8 ,VABMap4b;
|
||||
typedef VABMap<VB4i16> VABMap4i16,VABMap4s;
|
||||
typedef VABMap<VB4i32> VABMap4i32,VABMap4i;
|
||||
typedef VABMap<VB4u8> VABMap4u8, VABMap4ub;
|
||||
typedef VABMap<VB4u16> VABMap4u16,VABMap4us;
|
||||
typedef VABMap<VB4u32> VABMap4u32,VABMap4ui;
|
||||
typedef VABMap<VB4f> VABMap4f;
|
||||
typedef VABMap<VB4d> VABMap4d;
|
||||
|
||||
VK_NAMESPACE_END
|
@ -63,23 +63,20 @@ struct VABAccess
|
||||
{
|
||||
VAB *vab;
|
||||
VkDeviceSize start;
|
||||
|
||||
void *map_ptr;
|
||||
VkDeviceSize count;
|
||||
|
||||
public:
|
||||
|
||||
CompOperatorMemcmp(const VABAccess &);
|
||||
};//class VABAccess
|
||||
|
||||
using VABAccessMap=Map<AnsiString,VABAccess>;
|
||||
|
||||
class IndexBuffer;
|
||||
|
||||
struct IndexBufferAccess
|
||||
{
|
||||
IndexBuffer *buffer=nullptr;
|
||||
VkDeviceSize start=0;
|
||||
VkDeviceSize count=0;
|
||||
IndexBuffer *buffer;
|
||||
VkDeviceSize start;
|
||||
VkDeviceSize count;
|
||||
};
|
||||
|
||||
using IBAccess=IndexBufferAccess;
|
||||
@ -121,6 +118,7 @@ using VIF=VertexInputFormat;
|
||||
class VertexInputLayout;
|
||||
using VIL=VertexInputLayout;
|
||||
|
||||
struct PrimitiveData;
|
||||
class Primitive;
|
||||
class Renderable;
|
||||
|
||||
|
@ -27,6 +27,8 @@ protected:
|
||||
|
||||
AnsiString prim_name;
|
||||
|
||||
PrimitiveData *prim_data;
|
||||
|
||||
protected:
|
||||
|
||||
AABB BoundingBox;
|
||||
|
@ -21,8 +21,6 @@ VK_NAMESPACE_BEGIN
|
||||
就是为了必避动态分配内存,以及可以直接memcpy处理,所以此处这样定义。
|
||||
*/
|
||||
|
||||
constexpr const uint HGL_MAX_VERTEX_ATTRIB_COUNT=16; ///<最大顶点属性数量
|
||||
|
||||
struct PrimitiveData
|
||||
{
|
||||
const VIL * vil;
|
||||
@ -33,9 +31,10 @@ struct PrimitiveData
|
||||
IBAccess ib_access;
|
||||
};//struct PrimitiveData
|
||||
|
||||
bool Init( PrimitiveData *pd,const VIL *_vil,const VkDeviceSize vc,const VkDeviceSize ic=0);
|
||||
int GetVABIndex(const PrimitiveData *pd,const AnsiString &name);
|
||||
const VABAccess * GetVAB(const PrimitiveData *pd,const AnsiString &name);
|
||||
VABAccess * SetVAB( PrimitiveData *pd,const AnsiString &name,VAB *vab,VkDeviceSize start=0);
|
||||
bool InitPrimitiveData( PrimitiveData *pd,const VIL *_vil,const VkDeviceSize vc);
|
||||
int GetVABIndex(const PrimitiveData *pd,const AnsiString &name);
|
||||
VABAccess * GetVAB( PrimitiveData *pd,const int);
|
||||
VABAccess * SetVAB( PrimitiveData *pd,const int,VAB *vab,VkDeviceSize start,VkDeviceSize count);
|
||||
void SetIndexBuffer( PrimitiveData *pd,IndexBuffer *ib,const VkDeviceSize ic);
|
||||
|
||||
VK_NAMESPACE_END
|
||||
|
@ -9,53 +9,51 @@ PrimitiveCreater::PrimitiveCreater(GPUDevice *dev,const VIL *v)
|
||||
{
|
||||
device =dev;
|
||||
phy_device =device->GetPhysicalDevice();
|
||||
|
||||
vdm =nullptr;
|
||||
vil =v;
|
||||
|
||||
vertices_number =0;
|
||||
index_number =0;
|
||||
prim_data =hgl_zero_new<PrimitiveData>();
|
||||
|
||||
vertices_number=0;
|
||||
hgl_zero(vab_ptr);
|
||||
|
||||
ibo =nullptr;
|
||||
ibo_map =nullptr;
|
||||
}
|
||||
|
||||
PrimitiveCreater::PrimitiveCreater(VertexDataManager *_vdm)
|
||||
{
|
||||
device =_vdm->GetDevice();
|
||||
phy_device =device->GetPhysicalDevice();
|
||||
|
||||
vdm =_vdm;
|
||||
vil =vdm->GetVIL();
|
||||
|
||||
vertices_number =0;
|
||||
index_number =0;
|
||||
ibo =nullptr;
|
||||
ibo_map =nullptr;
|
||||
}
|
||||
//PrimitiveCreater::PrimitiveCreater(VertexDataManager *_vdm)
|
||||
//{
|
||||
// device =_vdm->GetDevice();
|
||||
// phy_device =device->GetPhysicalDevice();
|
||||
//
|
||||
// vdm =_vdm;
|
||||
// vil =vdm->GetVIL();
|
||||
//
|
||||
// vertices_number =0;
|
||||
// index_number =0;
|
||||
// ibo =nullptr;
|
||||
// ibo_map =nullptr;
|
||||
//}
|
||||
|
||||
PrimitiveCreater::~PrimitiveCreater()
|
||||
{
|
||||
if(ibo)
|
||||
if(prim_data)
|
||||
{
|
||||
if(ibo_map)
|
||||
ibo->Unmap();
|
||||
delete ibo;
|
||||
|
||||
delete prim_data;
|
||||
}
|
||||
}
|
||||
|
||||
bool PrimitiveCreater::Init(const uint32 vertex_count,const uint32 index_count,IndexType it)
|
||||
bool PrimitiveCreater::Init(const VkDeviceSize vertex_count,const VkDeviceSize index_count,IndexType it)
|
||||
{
|
||||
if(vertex_count<=0)return(false);
|
||||
|
||||
vertices_number=vertex_count;
|
||||
|
||||
if(index_count>0)
|
||||
{
|
||||
index_number=index_count;
|
||||
InitPrimitiveData(prim_data,vil,vertex_count);
|
||||
|
||||
if(vdm)
|
||||
{
|
||||
}
|
||||
else
|
||||
if(index_count>0)
|
||||
{
|
||||
if(it==IndexType::AUTO)
|
||||
{
|
||||
@ -73,7 +71,8 @@ bool PrimitiveCreater::Init(const uint32 vertex_count,const uint32 index_count,I
|
||||
ibo=device->CreateIBO(it,index_count);
|
||||
|
||||
if(!ibo)return(false);
|
||||
}
|
||||
|
||||
SetIndexBuffer(prim_data,ibo,index_count);
|
||||
|
||||
ibo_map=ibo->Map();
|
||||
}
|
||||
@ -81,19 +80,28 @@ bool PrimitiveCreater::Init(const uint32 vertex_count,const uint32 index_count,I
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool PrimitiveCreater::AcquirePVB(VABAccess *vad,const AnsiString &name,const void *data)
|
||||
VABAccess *PrimitiveCreater::AcquirePVB(const AnsiString &name,const VkFormat &acquire_format,const void *data)
|
||||
{
|
||||
if(!vad)return(false);
|
||||
if(!vil)return(false);
|
||||
if(name.IsEmpty())return(false);
|
||||
if(!vil)return(nullptr);
|
||||
if(name.IsEmpty())return(nullptr);
|
||||
|
||||
const VertexInputFormat *vif=vil->GetConfig(name);
|
||||
const int index=vil->GetIndex(name);
|
||||
|
||||
if(index<0||index>=vil->GetCount())
|
||||
return(nullptr);
|
||||
|
||||
const VertexInputFormat *vif=vil->GetConfig(index);
|
||||
|
||||
if(!vif)
|
||||
return(false);
|
||||
return(nullptr);
|
||||
|
||||
if(vab_map.Get(name,*vad))
|
||||
return true;
|
||||
if(vif->format!=acquire_format)
|
||||
return(nullptr);
|
||||
|
||||
VABAccess *vab=GetVAB(prim_data,index);
|
||||
|
||||
if(vab)
|
||||
return vab;
|
||||
|
||||
vad->vab =device->CreateVAB(vif->format,vertices_number,data);
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include<hgl/graph/VKPrimitiveData.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
bool Init(PrimitiveData *pd,const VIL *_vil,const VkDeviceSize vc,const VkDeviceSize ic=0)
|
||||
bool InitPrimitiveData(PrimitiveData *pd,const VIL *_vil,const VkDeviceSize vc)
|
||||
{
|
||||
if(!pd)return(false);
|
||||
if(!_vil)return(false);
|
||||
@ -11,7 +11,6 @@ bool Init(PrimitiveData *pd,const VIL *_vil,const VkDeviceSize vc,const VkDevice
|
||||
|
||||
pd->vil=_vil;
|
||||
pd->vertex_count=vc;
|
||||
pd->ib_access.count=ic;
|
||||
|
||||
return(true);
|
||||
}
|
||||
@ -25,33 +24,26 @@ int GetVABIndex(const PrimitiveData *pd,const AnsiString &name)
|
||||
return pd->vil->GetIndex(name);
|
||||
}
|
||||
|
||||
const VABAccess *GetVAB(const PrimitiveData *pd,const AnsiString &name)
|
||||
VABAccess *GetVAB(PrimitiveData *pd,const int index)
|
||||
{
|
||||
if(!pd)return(nullptr);
|
||||
if(name.IsEmpty())return(nullptr);
|
||||
|
||||
const int index=GetVABIndex(pd,name);
|
||||
|
||||
if(index==-1)
|
||||
return(nullptr);
|
||||
if(!pd->vil)return(nullptr);
|
||||
if(index<0||index>=pd->vil->GetCount())return(nullptr);
|
||||
|
||||
return pd->vab_access+index;
|
||||
}
|
||||
|
||||
VABAccess *SetVAB(PrimitiveData *pd,const AnsiString &name,VAB *vab,VkDeviceSize start=0)
|
||||
VABAccess *SetVAB(PrimitiveData *pd,const int index,VAB *vab,VkDeviceSize start,VkDeviceSize count)
|
||||
{
|
||||
if(!pd)return(nullptr);
|
||||
if(name.IsEmpty())return(nullptr);
|
||||
|
||||
const int index=GetVABIndex(pd,name);
|
||||
|
||||
if(index==-1)
|
||||
return(nullptr);
|
||||
if(!pd->vil)return(nullptr);
|
||||
if(index<0||index>=pd->vil->GetCount())return(nullptr);
|
||||
|
||||
VABAccess *vaba=pd->vab_access+index;
|
||||
|
||||
vaba->vab=vab;
|
||||
vaba->start=start;
|
||||
vaba->count=count;
|
||||
|
||||
//#ifdef _DEBUG
|
||||
// DebugUtils *du=device->GetDebugUtils();
|
||||
@ -66,4 +58,13 @@ VABAccess *SetVAB(PrimitiveData *pd,const AnsiString &name,VAB *vab,VkDeviceSize
|
||||
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;
|
||||
}
|
||||
|
||||
VK_NAMESPACE_END
|
Loading…
x
Reference in New Issue
Block a user