newly PrimitiveCreater and InlineGeometry, test two samples are OK!
This commit is contained in:
parent
8633a18e01
commit
0b1a0cadae
@ -35,9 +35,11 @@ namespace hgl
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
uint32 vertices_number;
|
VkDeviceSize vertices_number;
|
||||||
|
VkDeviceSize index_number;
|
||||||
|
|
||||||
IndexBuffer * ibo;
|
IndexBuffer * ibo;
|
||||||
|
void * ibo_map;
|
||||||
PVBMap vbo_map;
|
PVBMap vbo_map;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -50,9 +52,9 @@ namespace hgl
|
|||||||
|
|
||||||
PrimitiveCreater(RenderResource *sdb,const VIL *);
|
PrimitiveCreater(RenderResource *sdb,const VIL *);
|
||||||
PrimitiveCreater(VertexDataManager *);
|
PrimitiveCreater(VertexDataManager *);
|
||||||
virtual ~PrimitiveCreater()=default;
|
virtual ~PrimitiveCreater();
|
||||||
|
|
||||||
virtual bool Init(const uint32 vertices_count,const uint32 index_count,IndexType it=IndexType::ERR); ///<初始化,参数为顶点数量
|
virtual bool Init(const uint32 vertices_count,const uint32 index_count,IndexType it=IndexType::AUTO); ///<初始化,参数为顶点数量
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
T * AccessVBO(const AnsiString &name) ///<创建一个顶点属性数据缓冲区以及访问器
|
T * AccessVBO(const AnsiString &name) ///<创建一个顶点属性数据缓冲区以及访问器
|
||||||
@ -76,23 +78,42 @@ namespace hgl
|
|||||||
|
|
||||||
bool WriteVBO(const AnsiString &name,const void *data,const uint32_t bytes); ///<直接写入顶点属性数据
|
bool WriteVBO(const AnsiString &name,const void *data,const uint32_t bytes); ///<直接写入顶点属性数据
|
||||||
|
|
||||||
template<typename T,IndexType IT>
|
const IndexType GetIndexType()const{return ibo?ibo->GetType():IndexType::ERR;} ///<取得索引数据类型
|
||||||
T * CreateIBO(const uint count,const T *data=nullptr) ///<创建索引缓冲区
|
template<typename T> T *AccessIBO()
|
||||||
{
|
{
|
||||||
if(ibo)
|
if(!ibo)return(nullptr);
|
||||||
return(nullptr);
|
if(ibo->GetStride()!=sizeof(T))return(nullptr);
|
||||||
|
|
||||||
ibo=db->CreateIBO(IT,count,data);
|
|
||||||
|
|
||||||
if(!ibo)
|
return (T *)ibo_map;
|
||||||
return(nullptr);
|
|
||||||
|
|
||||||
return (T *)ibo->Map();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8 * CreateIBO8 (uint count,const uint8 *data=nullptr){return CreateIBO<uint8 ,IndexType::U8 >(count,data);} ///<创建8位的索引缓冲区
|
template<typename T> bool WriteIBO(const T *data)
|
||||||
uint16 * CreateIBO16(uint count,const uint16 *data=nullptr){return CreateIBO<uint16,IndexType::U16>(count,data);} ///<创建16位的索引缓冲区
|
{
|
||||||
uint32 * CreateIBO32(uint count,const uint32 *data=nullptr){return CreateIBO<uint32,IndexType::U32>(count,data);} ///<创建32位的索引缓冲区
|
if(!ibo)return(false);
|
||||||
|
if(ibo->GetStride()!=sizeof(T))return(false);
|
||||||
|
|
||||||
|
hgl_cpy<T>((T *)ibo_map,data,index_number);
|
||||||
|
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
//template<typename T,IndexType IT>
|
||||||
|
//T * CreateIBO(const uint count,const T *data=nullptr) ///<创建索引缓冲区
|
||||||
|
//{
|
||||||
|
// if(ibo)
|
||||||
|
// return(nullptr);
|
||||||
|
//
|
||||||
|
// ibo=db->CreateIBO(IT,count,data);
|
||||||
|
|
||||||
|
// if(!ibo)
|
||||||
|
// return(nullptr);
|
||||||
|
|
||||||
|
// return (T *)ibo->Map();
|
||||||
|
//}
|
||||||
|
|
||||||
|
//uint8 * CreateIBO8 (uint count,const uint8 *data=nullptr){return CreateIBO<uint8 ,IndexType::U8 >(count,data);} ///<创建8位的索引缓冲区
|
||||||
|
//uint16 * CreateIBO16(uint count,const uint16 *data=nullptr){return CreateIBO<uint16,IndexType::U16>(count,data);} ///<创建16位的索引缓冲区
|
||||||
|
//uint32 * CreateIBO32(uint count,const uint32 *data=nullptr){return CreateIBO<uint32,IndexType::U32>(count,data);} ///<创建32位的索引缓冲区
|
||||||
|
|
||||||
virtual Primitive * Finish(const AnsiString &); ///<结束并创建可渲染对象
|
virtual Primitive * Finish(const AnsiString &); ///<结束并创建可渲染对象
|
||||||
};//class PrimitiveCreater
|
};//class PrimitiveCreater
|
||||||
|
@ -9,8 +9,9 @@ namespace hgl
|
|||||||
{
|
{
|
||||||
class IndexBuffer:public DeviceBuffer
|
class IndexBuffer:public DeviceBuffer
|
||||||
{
|
{
|
||||||
IndexType index_type;
|
IndexType index_type;
|
||||||
uint32_t count;
|
uint stride;
|
||||||
|
uint32_t count;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
@ -20,14 +21,20 @@ namespace hgl
|
|||||||
{
|
{
|
||||||
index_type=it;
|
index_type=it;
|
||||||
count=_count;
|
count=_count;
|
||||||
|
|
||||||
|
if(index_type==IndexType::U16)stride=2;else
|
||||||
|
if(index_type==IndexType::U32)stride=4;else
|
||||||
|
if(index_type==IndexType::U8)stride=1;else
|
||||||
|
stride=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
~IndexBuffer()=default;
|
~IndexBuffer()=default;
|
||||||
|
|
||||||
const IndexType GetType ()const{return index_type;}
|
const IndexType GetType ()const{return index_type;}
|
||||||
const uint32 GetCount()const{return count;}
|
const uint GetStride ()const{return stride;}
|
||||||
|
const uint32 GetCount ()const{return count;}
|
||||||
};//class IndexBuffer:public DeviceBuffer
|
};//class IndexBuffer:public DeviceBuffer
|
||||||
}//namespace graph
|
}//namespace graph
|
||||||
}//namespace hgl
|
}//namespace hgl
|
||||||
|
@ -166,7 +166,7 @@ namespace hgl
|
|||||||
{
|
{
|
||||||
PrimitiveCreater rc(db,vil);
|
PrimitiveCreater rc(db,vil);
|
||||||
|
|
||||||
if(!rc.Init(((pgci->grid_size.Width()+1)+(pgci->grid_size.Height()+1))*2,8))
|
if(!rc.Init(((pgci->grid_size.Width()+1)+(pgci->grid_size.Height()+1))*2,0))
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
|
|
||||||
AutoDelete<VB3f> vertex=rc.AccessVBO<VB3f>(VAN::Position);
|
AutoDelete<VB3f> vertex=rc.AccessVBO<VB3f>(VAN::Position);
|
||||||
@ -303,7 +303,7 @@ namespace hgl
|
|||||||
|
|
||||||
PrimitiveCreater rc(db,vil);
|
PrimitiveCreater rc(db,vil);
|
||||||
|
|
||||||
if(!rc.Init(24,6*2*3))
|
if(!rc.Init(24,6*2*3,IndexType::U16))
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
|
|
||||||
rc.WriteVBO(VAN::Position,positions,sizeof(positions));
|
rc.WriteVBO(VAN::Position,positions,sizeof(positions));
|
||||||
@ -341,7 +341,8 @@ namespace hgl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rc.CreateIBO16(6*2*3,indices);
|
//rc.CreateIBO16(6*2*3,indices);
|
||||||
|
rc.WriteIBO(indices);
|
||||||
return rc.Finish("Cube");
|
return rc.Finish("Cube");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -508,10 +509,15 @@ namespace hgl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(numberVertices<=0xffff)
|
//索引
|
||||||
CreateSphereIndices<uint16>(rc.CreateIBO16(numberIndices),numberParallels,numberSlices);
|
{
|
||||||
else
|
const IndexType index_type=rc.GetIndexType();
|
||||||
CreateSphereIndices<uint32>(rc.CreateIBO32(numberIndices),numberParallels,numberSlices);
|
|
||||||
|
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
|
||||||
|
return(nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
return rc.Finish("Sphere");
|
return rc.Finish("Sphere");
|
||||||
}
|
}
|
||||||
@ -594,10 +600,15 @@ namespace hgl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(numberVertices<=0xffff)
|
//索引
|
||||||
CreateSphereIndices<uint16>(rc.CreateIBO16(numberIndices),numberParallels,numberSlices);
|
{
|
||||||
else
|
const IndexType index_type=rc.GetIndexType();
|
||||||
CreateSphereIndices<uint32>(rc.CreateIBO32(numberIndices),numberParallels,numberSlices);
|
|
||||||
|
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
|
||||||
|
return(nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
return rc.Finish("Dome");
|
return rc.Finish("Dome");
|
||||||
}
|
}
|
||||||
@ -735,11 +746,15 @@ namespace hgl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(numberVertices<=0xffff)
|
//索引
|
||||||
CreateTorusIndices<uint16>(rc.CreateIBO16(numberIndices),tci->numberSlices,tci->numberStacks);
|
{
|
||||||
else
|
const IndexType index_type=rc.GetIndexType();
|
||||||
CreateTorusIndices<uint32>(rc.CreateIBO32(numberIndices),tci->numberSlices,tci->numberStacks);
|
|
||||||
|
|
||||||
|
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
|
||||||
|
return(nullptr);
|
||||||
|
}
|
||||||
return rc.Finish("Torus");
|
return rc.Finish("Torus");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -964,10 +979,15 @@ namespace hgl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(numberVertices<=0xffff)
|
//索引
|
||||||
CreateCylinderIndices<uint16>(rc.CreateIBO16(numberIndices),cci->numberSlices);
|
{
|
||||||
else
|
const IndexType index_type=rc.GetIndexType();
|
||||||
CreateCylinderIndices<uint32>(rc.CreateIBO32(numberIndices),cci->numberSlices);
|
|
||||||
|
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
|
||||||
|
return(nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
return rc.Finish("Cylinder");
|
return rc.Finish("Cylinder");
|
||||||
}
|
}
|
||||||
@ -1130,10 +1150,15 @@ namespace hgl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(numberVertices<=0xffff)
|
//索引
|
||||||
CreateConeIndices<uint16>(rc.CreateIBO16(numberIndices),cci->numberSlices,cci->numberStacks);
|
{
|
||||||
else
|
const IndexType index_type=rc.GetIndexType();
|
||||||
CreateConeIndices<uint32>(rc.CreateIBO32(numberIndices),cci->numberSlices,cci->numberStacks);
|
|
||||||
|
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
|
||||||
|
return(nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
return rc.Finish("Cone");
|
return rc.Finish("Cone");
|
||||||
}
|
}
|
||||||
@ -1189,7 +1214,7 @@ namespace hgl
|
|||||||
|
|
||||||
PrimitiveCreater rc(db,vil);
|
PrimitiveCreater rc(db,vil);
|
||||||
|
|
||||||
if(!rc.Init(8,24))
|
if(!rc.Init(8,24,IndexType::U16))
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
|
|
||||||
AutoDelete<VB3f> vertex=rc.AccessVBO<VB3f>(VAN::Position);
|
AutoDelete<VB3f> vertex=rc.AccessVBO<VB3f>(VAN::Position);
|
||||||
@ -1214,7 +1239,7 @@ namespace hgl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rc.CreateIBO16(24,indices);
|
rc.WriteIBO<uint16>(indices);
|
||||||
|
|
||||||
return rc.Finish("BoundingBox");
|
return rc.Finish("BoundingBox");
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,9 @@ namespace hgl
|
|||||||
vil =v;
|
vil =v;
|
||||||
|
|
||||||
vertices_number =0;
|
vertices_number =0;
|
||||||
|
index_number =0;
|
||||||
ibo =nullptr;
|
ibo =nullptr;
|
||||||
|
ibo_map =nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
PrimitiveCreater::PrimitiveCreater(VertexDataManager *_vdm)
|
PrimitiveCreater::PrimitiveCreater(VertexDataManager *_vdm)
|
||||||
@ -30,7 +32,18 @@ namespace hgl
|
|||||||
vil =vdm->GetVIL();
|
vil =vdm->GetVIL();
|
||||||
|
|
||||||
vertices_number =0;
|
vertices_number =0;
|
||||||
|
index_number =0;
|
||||||
ibo =nullptr;
|
ibo =nullptr;
|
||||||
|
ibo_map =nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
PrimitiveCreater::~PrimitiveCreater()
|
||||||
|
{
|
||||||
|
if(ibo)
|
||||||
|
{
|
||||||
|
ibo->Unmap();
|
||||||
|
delete ibo;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PrimitiveCreater::Init(const uint32 vertex_count,const uint32 index_count,IndexType it)
|
bool PrimitiveCreater::Init(const uint32 vertex_count,const uint32 index_count,IndexType it)
|
||||||
@ -41,24 +54,20 @@ namespace hgl
|
|||||||
|
|
||||||
if(index_count>0)
|
if(index_count>0)
|
||||||
{
|
{
|
||||||
|
index_number=index_count;
|
||||||
|
|
||||||
if(vdm)
|
if(vdm)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(it==IndexType::ERR)
|
if(it==IndexType::AUTO)
|
||||||
{
|
{
|
||||||
if(vertex_count<=0xFF&&phy_device->SupportU8Index())
|
it=device->GetIndexType(vertex_count);
|
||||||
it=IndexType::U8;
|
|
||||||
else
|
if(!IsIndexType(it))
|
||||||
if(vertex_count<=0xFFFF)
|
return(false);
|
||||||
it=IndexType::U16;
|
|
||||||
else
|
|
||||||
if(phy_device->SupportU32Index())
|
|
||||||
it=IndexType::U32;
|
|
||||||
else
|
|
||||||
return(false);
|
|
||||||
}
|
}
|
||||||
else if(it==IndexType::U8)
|
else if(it==IndexType::U8)
|
||||||
{
|
{
|
||||||
@ -80,11 +89,12 @@ namespace hgl
|
|||||||
return(false);
|
return(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
ibo=db->CreateIBO(it,index_count);
|
ibo=device->CreateIBO(it,index_count);
|
||||||
|
//ibo=db->CreateIBO(it,index_count);
|
||||||
if(!ibo)return(false);
|
if(!ibo)return(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
ibo->Map();
|
ibo_map=ibo->Map();
|
||||||
}
|
}
|
||||||
|
|
||||||
return(true);
|
return(true);
|
||||||
@ -171,12 +181,6 @@ namespace hgl
|
|||||||
|
|
||||||
Primitive *primitive=db->CreatePrimitive(prim_name,vertices_number);
|
Primitive *primitive=db->CreatePrimitive(prim_name,vertices_number);
|
||||||
|
|
||||||
if(ibo)
|
|
||||||
{
|
|
||||||
ibo->Unmap();
|
|
||||||
primitive->Set(ibo);
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto *sp=vbo_map.GetDataList();
|
const auto *sp=vbo_map.GetDataList();
|
||||||
for(uint i=0;i<si_count;i++)
|
for(uint i=0;i<si_count;i++)
|
||||||
{
|
{
|
||||||
@ -196,6 +200,15 @@ namespace hgl
|
|||||||
++sp;
|
++sp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(ibo)
|
||||||
|
{
|
||||||
|
ibo->Unmap();
|
||||||
|
primitive->Set(ibo);
|
||||||
|
|
||||||
|
db->Add(ibo);
|
||||||
|
ibo=nullptr; //避免释构函数删除
|
||||||
|
}
|
||||||
|
|
||||||
db->Add(primitive);
|
db->Add(primitive);
|
||||||
|
|
||||||
return primitive;
|
return primitive;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user