ULRE/inc/hgl/graph/PrimitiveCreater.h

235 lines
6.6 KiB
C
Raw Normal View History

2024-05-05 04:37:04 +08:00
#pragma once
#include<hgl/graph/VertexAttribDataAccess.h>
#include<hgl/graph/VKShaderModule.h>
#include<hgl/graph/VKVertexAttribBuffer.h>
2024-05-05 04:37:04 +08:00
VK_NAMESPACE_BEGIN
2024-05-05 04:37:04 +08:00
/**
*
2024-05-05 04:37:04 +08:00
*/
class PrimitiveCreater
{
protected:
GPUDevice * device;
VertexDataManager * vdm;
2024-04-17 20:22:31 +08:00
const VIL * vil;
protected:
AnsiString prim_name;
PrimitiveData * prim_data;
uint32_t vertices_number; ///<顶点数量
2024-04-02 22:15:44 +08:00
void_pointer *map_ptr_list; ///<映射指针列表
uint32_t index_number; ///<索引数量
IndexType index_type; ///<索引类型
2024-05-28 02:21:33 +08:00
IndexBuffer * ibo; ///<索引缓冲区
2024-04-02 22:15:44 +08:00
2024-05-05 04:37:04 +08:00
public:
PrimitiveCreater(GPUDevice *,const VIL *);
PrimitiveCreater(VertexDataManager *);
virtual ~PrimitiveCreater();
/**
*
* @parama name
* @parama vertices_count
* @parama index_count
* @parama it (使VDM时)
*/
bool Init(const AnsiString &name,
const uint32_t vertices_count,
const uint32_t index_count=0,IndexType it=IndexType::AUTO);
void Clear(); ///<清除创建器数据
public: //顶点缓冲区
const uint32_t GetVertexCount()const{ return vertices_number; } ///<取得顶点数量
2024-05-28 02:21:33 +08:00
const int GetVABIndex (const AnsiString &name,const VkFormat &format); ///<取得顶点属性索引
void * MapVAB (const int vab_index); ///<映射一个顶点属性数据区
void UnmapVAB (const int vab_index); ///<取消映射
bool WriteVAB (const AnsiString &name,const VkFormat &format,const void *data); ///<直接写入顶点属性数据
public: //索引缓冲区
const IndexType GetIndexType()const{return index_type;} ///<取得索引类型
const uint32_t GetIndexCount()const{return index_number;} ///<取得索引数量
void * MapIBO();
void UnmapIBO();
bool WriteIBO(const void *data,const uint32_t count);
template<typename T>
bool WriteIBO(const T *data){return WriteIBO(data,index_number);}
public: //创建可渲染对象
Primitive * Create(); ///<创建一个可渲染对象,并清除创建器数据
2024-05-05 04:37:04 +08:00
};//class PrimitiveCreater
/**
* VAB原生数据访问映射
*/
template<typename T> class VABRawMap
{
2024-05-28 02:21:33 +08:00
PrimitiveCreater *pc;
int vab_index;
T *map_ptr;
public:
2024-05-28 02:21:33 +08:00
VABRawMap(PrimitiveCreater *c,const VkFormat &format,const AnsiString &name)
{
2024-05-28 02:21:33 +08:00
pc=c;
vab_index=pc->GetVABIndex(name,format);
map_ptr=(T *)(pc->MapVAB(vab_index));
}
~VABRawMap()
{
2024-05-28 02:21:33 +08:00
if(map_ptr)
pc->UnmapVAB(vab_index);
}
2024-05-28 02:21:33 +08:00
const bool IsValid()const{ return map_ptr; }
operator T *(){ 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
{
2024-05-28 02:21:33 +08:00
PrimitiveCreater *pc;
int vab_index;
T *vb;
public:
VABMap(PrimitiveCreater *c,const AnsiString &name)
{
2024-05-28 02:21:33 +08:00
pc=c;
vab_index=pc->GetVABIndex(name,T::GetVulkanFormat());
2024-05-28 02:21:33 +08:00
void *map_ptr=(T *)(pc->MapVAB(vab_index));
2024-05-28 02:21:33 +08:00
if(map_ptr)
{
vb=T::Create(pc->GetVertexCount(),map_ptr);
vb->Begin();
}
else
{
vb=nullptr;
}
}
~VABMap()
{
if(pc&&vab_index>=0)
2024-05-28 02:21:33 +08:00
pc->UnmapVAB(vab_index);
}
void Restart()
{
if(vb)
vb->Begin();
}
const bool IsValid()const{ return vb; }
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;
2024-05-23 14:00:23 +08:00
/**
* 访
*/
template<typename T> class IBMap
{
PrimitiveCreater *pc;
2024-05-23 14:00:23 +08:00
T *map_ptr;
public:
IBMap(PrimitiveCreater *c)
2024-05-23 14:00:23 +08:00
{
pc=c;
2024-05-23 14:00:23 +08:00
if(pc)
map_ptr=(T *)(pc->MapIBO());
2024-05-23 14:00:23 +08:00
else
map_ptr=nullptr;
}
~IBMap()
{
if(map_ptr&&pc)
pc->UnmapIBO();
2024-05-23 14:00:23 +08:00
}
const bool IsValid()const{ return map_ptr; }
2024-05-23 14:00:23 +08:00
operator T *(){ return map_ptr; }
};//template<typename T> class IBMap
using IBMapU8=IBMap<uint8>;
using IBMapU16=IBMap<uint16>;
using IBMapU32=IBMap<uint32>;
2024-05-05 04:37:04 +08:00
VK_NAMESPACE_END