Layout codes.
This commit is contained in:
parent
40094a7529
commit
03491dbed8
@ -1,98 +1,92 @@
|
||||
#ifndef HGL_GRAPH_PRIMITIVE_CREATER_INCLUDE
|
||||
#define HGL_GRAPH_PRIMITIVE_CREATER_INCLUDE
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
#include<hgl/graph/VertexAttribDataAccess.h>
|
||||
#include<hgl/graph/VKShaderModule.h>
|
||||
#include<hgl/graph/VKIndexBuffer.h>
|
||||
|
||||
namespace hgl
|
||||
VK_NAMESPACE_BEGIN
|
||||
class VertexDataManager;
|
||||
|
||||
/**
|
||||
* 可绘制图元创建器
|
||||
*/
|
||||
class PrimitiveCreater
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
class VertexDataManager;
|
||||
protected:
|
||||
|
||||
/**
|
||||
* 可绘制图元创建器
|
||||
*/
|
||||
class PrimitiveCreater
|
||||
{
|
||||
protected:
|
||||
GPUDevice *device;
|
||||
const GPUPhysicalDevice *phy_device;
|
||||
|
||||
GPUDevice *device;
|
||||
const GPUPhysicalDevice *phy_device;
|
||||
VertexDataManager *vdm;
|
||||
RenderResource *db;
|
||||
|
||||
VertexDataManager *vdm;
|
||||
RenderResource *db;
|
||||
const VIL *vil;
|
||||
|
||||
const VIL *vil;
|
||||
protected:
|
||||
|
||||
protected:
|
||||
VkDeviceSize vertices_number;
|
||||
VkDeviceSize index_number;
|
||||
|
||||
VkDeviceSize vertices_number;
|
||||
VkDeviceSize index_number;
|
||||
IndexBuffer * ibo;
|
||||
void * ibo_map;
|
||||
VABAccessMap vab_map;
|
||||
|
||||
IndexBuffer * ibo;
|
||||
void * ibo_map;
|
||||
VABAccessMap vab_map;
|
||||
protected:
|
||||
|
||||
protected:
|
||||
bool AcquirePVB(VABAccess *,const AnsiString &,const void *data); ///<请求一个顶点属性数据区
|
||||
|
||||
bool AcquirePVB(VABAccess *,const AnsiString &,const void *data); ///<请求一个顶点属性数据区
|
||||
void ClearAllData();
|
||||
|
||||
void ClearAllData();
|
||||
public:
|
||||
|
||||
public:
|
||||
PrimitiveCreater(RenderResource *sdb,const VIL *);
|
||||
PrimitiveCreater(VertexDataManager *);
|
||||
virtual ~PrimitiveCreater();
|
||||
|
||||
PrimitiveCreater(RenderResource *sdb,const VIL *);
|
||||
PrimitiveCreater(VertexDataManager *);
|
||||
virtual ~PrimitiveCreater();
|
||||
virtual bool Init(const uint32 vertices_count,const uint32 index_count,IndexType it=IndexType::AUTO); ///<初始化,参数为顶点数量
|
||||
|
||||
virtual bool Init(const uint32 vertices_count,const uint32 index_count,IndexType it=IndexType::AUTO); ///<初始化,参数为顶点数量
|
||||
template<typename T>
|
||||
T * AccessVAB(const AnsiString &name) ///<创建一个顶点属性数据缓冲区以及访问器
|
||||
{
|
||||
const VkFormat format=vil->GetVulkanFormat(name);
|
||||
|
||||
template<typename T>
|
||||
T * AccessVAB(const AnsiString &name) ///<创建一个顶点属性数据缓冲区以及访问器
|
||||
{
|
||||
const VkFormat format=vil->GetVulkanFormat(name);
|
||||
if(format!=T::GetVulkanFormat())
|
||||
return(nullptr);
|
||||
|
||||
if(format!=T::GetVulkanFormat())
|
||||
return(nullptr);
|
||||
VABAccess vad;
|
||||
if(!this->AcquirePVB(&vad,name,nullptr))
|
||||
return(nullptr);
|
||||
|
||||
VABAccess vad;
|
||||
if(!this->AcquirePVB(&vad,name,nullptr))
|
||||
return(nullptr);
|
||||
T *access=T::Create(vertices_number,vad.map_ptr);
|
||||
|
||||
T *access=T::Create(vertices_number,vad.map_ptr);
|
||||
access->Begin();
|
||||
|
||||
access->Begin();
|
||||
return access;
|
||||
}
|
||||
|
||||
return access;
|
||||
}
|
||||
bool WriteVAB(const AnsiString &name,const void *data,const uint32_t bytes); ///<直接写入顶点属性数据
|
||||
|
||||
bool WriteVAB(const AnsiString &name,const void *data,const uint32_t bytes); ///<直接写入顶点属性数据
|
||||
const IndexType GetIndexType()const{return ibo?ibo->GetType():IndexType::ERR;} ///<取得索引数据类型
|
||||
|
||||
const IndexType GetIndexType()const{return ibo?ibo->GetType():IndexType::ERR;} ///<取得索引数据类型
|
||||
template<typename T> T *AccessIBO()
|
||||
{
|
||||
if(!ibo)return(nullptr);
|
||||
if(ibo->GetStride()!=sizeof(T))return(nullptr);
|
||||
|
||||
template<typename T> T *AccessIBO()
|
||||
{
|
||||
if(!ibo)return(nullptr);
|
||||
if(ibo->GetStride()!=sizeof(T))return(nullptr);
|
||||
return (T *)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);
|
||||
|
||||
template<typename T> bool WriteIBO(const T *data)
|
||||
{
|
||||
if(!ibo)return(false);
|
||||
if(ibo->GetStride()!=sizeof(T))return(false);
|
||||
hgl_cpy<T>((T *)ibo_map,data,index_number);
|
||||
|
||||
hgl_cpy<T>((T *)ibo_map,data,index_number);
|
||||
return(true);
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
virtual Primitive * Finish(const AnsiString &); ///<结束并创建可渲染对象
|
||||
};//class PrimitiveCreater
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
#endif//HGL_GRAPH_PRIMITIVE_CREATER_INCLUDE
|
||||
virtual Primitive * Finish(const AnsiString &); ///<结束并创建可渲染对象
|
||||
};//class PrimitiveCreater
|
||||
VK_NAMESPACE_END
|
@ -4,199 +4,195 @@
|
||||
#include<hgl/graph/VKPrimitive.h>
|
||||
#include<hgl/graph/VertexDataManager.h>
|
||||
|
||||
namespace hgl
|
||||
VK_NAMESPACE_BEGIN
|
||||
PrimitiveCreater::PrimitiveCreater(RenderResource *sdb,const VIL *v)
|
||||
{
|
||||
namespace graph
|
||||
device =sdb->GetDevice();
|
||||
phy_device =device->GetPhysicalDevice();
|
||||
|
||||
vdm =nullptr;
|
||||
db =sdb;
|
||||
vil =v;
|
||||
|
||||
vertices_number =0;
|
||||
index_number =0;
|
||||
ibo =nullptr;
|
||||
ibo_map =nullptr;
|
||||
}
|
||||
|
||||
PrimitiveCreater::PrimitiveCreater(VertexDataManager *_vdm)
|
||||
{
|
||||
device =_vdm->GetDevice();
|
||||
phy_device =device->GetPhysicalDevice();
|
||||
|
||||
vdm =_vdm;
|
||||
db =nullptr;
|
||||
vil =vdm->GetVIL();
|
||||
|
||||
vertices_number =0;
|
||||
index_number =0;
|
||||
ibo =nullptr;
|
||||
ibo_map =nullptr;
|
||||
}
|
||||
|
||||
PrimitiveCreater::~PrimitiveCreater()
|
||||
{
|
||||
if(ibo)
|
||||
{
|
||||
PrimitiveCreater::PrimitiveCreater(RenderResource *sdb,const VIL *v)
|
||||
ibo->Unmap();
|
||||
delete ibo;
|
||||
}
|
||||
}
|
||||
|
||||
bool PrimitiveCreater::Init(const uint32 vertex_count,const uint32 index_count,IndexType it)
|
||||
{
|
||||
if(vertex_count<=0)return(false);
|
||||
|
||||
vertices_number=vertex_count;
|
||||
|
||||
if(index_count>0)
|
||||
{
|
||||
index_number=index_count;
|
||||
|
||||
if(vdm)
|
||||
{
|
||||
device =sdb->GetDevice();
|
||||
phy_device =device->GetPhysicalDevice();
|
||||
|
||||
vdm =nullptr;
|
||||
db =sdb;
|
||||
vil =v;
|
||||
|
||||
vertices_number =0;
|
||||
index_number =0;
|
||||
ibo =nullptr;
|
||||
ibo_map =nullptr;
|
||||
}
|
||||
|
||||
PrimitiveCreater::PrimitiveCreater(VertexDataManager *_vdm)
|
||||
else
|
||||
{
|
||||
device =_vdm->GetDevice();
|
||||
phy_device =device->GetPhysicalDevice();
|
||||
|
||||
vdm =_vdm;
|
||||
db =nullptr;
|
||||
vil =vdm->GetVIL();
|
||||
|
||||
vertices_number =0;
|
||||
index_number =0;
|
||||
ibo =nullptr;
|
||||
ibo_map =nullptr;
|
||||
}
|
||||
|
||||
PrimitiveCreater::~PrimitiveCreater()
|
||||
{
|
||||
if(ibo)
|
||||
if(it==IndexType::AUTO)
|
||||
{
|
||||
ibo->Unmap();
|
||||
delete ibo;
|
||||
it=device->ChooseIndexType(vertex_count);
|
||||
|
||||
if(!IsIndexType(it))
|
||||
return(false);
|
||||
}
|
||||
}
|
||||
|
||||
bool PrimitiveCreater::Init(const uint32 vertex_count,const uint32 index_count,IndexType it)
|
||||
{
|
||||
if(vertex_count<=0)return(false);
|
||||
|
||||
vertices_number=vertex_count;
|
||||
|
||||
if(index_count>0)
|
||||
{
|
||||
index_number=index_count;
|
||||
|
||||
if(vdm)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
if(it==IndexType::AUTO)
|
||||
{
|
||||
it=device->ChooseIndexType(vertex_count);
|
||||
|
||||
if(!IsIndexType(it))
|
||||
return(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!device->CheckIndexType(it,vertex_count))
|
||||
return(false);
|
||||
}
|
||||
|
||||
ibo=device->CreateIBO(it,index_count);
|
||||
//ibo=db->CreateIBO(it,index_count);
|
||||
if(!ibo)return(false);
|
||||
}
|
||||
|
||||
ibo_map=ibo->Map();
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool PrimitiveCreater::AcquirePVB(VABAccess *vad,const AnsiString &name,const void *data)
|
||||
{
|
||||
if(!vad)return(false);
|
||||
if(!vil)return(false);
|
||||
if(name.IsEmpty())return(false);
|
||||
|
||||
const VertexInputFormat *vif=vil->GetConfig(name);
|
||||
|
||||
if(!vif)
|
||||
return(false);
|
||||
|
||||
if(vab_map.Get(name,*vad))
|
||||
return true;
|
||||
|
||||
vad->vab =db->CreateVAB(vif->format,vertices_number,data);
|
||||
|
||||
if(!data)
|
||||
vad->map_ptr=vad->vab->Map();
|
||||
else
|
||||
vad->map_ptr=nullptr;
|
||||
{
|
||||
if(!device->CheckIndexType(it,vertex_count))
|
||||
return(false);
|
||||
}
|
||||
|
||||
vab_map.Add(name,*vad);
|
||||
|
||||
return true;
|
||||
ibo=device->CreateIBO(it,index_count);
|
||||
//ibo=db->CreateIBO(it,index_count);
|
||||
if(!ibo)return(false);
|
||||
}
|
||||
|
||||
bool PrimitiveCreater::WriteVAB(const AnsiString &name,const void *data,const uint32_t bytes)
|
||||
{
|
||||
if(!vil)return(false);
|
||||
if(name.IsEmpty())return(false);
|
||||
if(!data)return(false);
|
||||
if(!bytes)return(false);
|
||||
ibo_map=ibo->Map();
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool PrimitiveCreater::AcquirePVB(VABAccess *vad,const AnsiString &name,const void *data)
|
||||
{
|
||||
if(!vad)return(false);
|
||||
if(!vil)return(false);
|
||||
if(name.IsEmpty())return(false);
|
||||
|
||||
const VertexInputFormat *vif=vil->GetConfig(name);
|
||||
const VertexInputFormat *vif=vil->GetConfig(name);
|
||||
|
||||
if(!vif)
|
||||
return(false);
|
||||
if(!vif)
|
||||
return(false);
|
||||
|
||||
if(vif->stride*vertices_number!=bytes)
|
||||
return(false);
|
||||
if(vab_map.Get(name,*vad))
|
||||
return true;
|
||||
|
||||
VABAccess vad;
|
||||
vad->vab =db->CreateVAB(vif->format,vertices_number,data);
|
||||
|
||||
return AcquirePVB(&vad,name,data);
|
||||
}
|
||||
if(!data)
|
||||
vad->map_ptr=vad->vab->Map();
|
||||
else
|
||||
vad->map_ptr=nullptr;
|
||||
|
||||
void PrimitiveCreater::ClearAllData()
|
||||
vab_map.Add(name,*vad);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PrimitiveCreater::WriteVAB(const AnsiString &name,const void *data,const uint32_t bytes)
|
||||
{
|
||||
if(!vil)return(false);
|
||||
if(name.IsEmpty())return(false);
|
||||
if(!data)return(false);
|
||||
if(!bytes)return(false);
|
||||
|
||||
const VertexInputFormat *vif=vil->GetConfig(name);
|
||||
|
||||
if(!vif)
|
||||
return(false);
|
||||
|
||||
if(vif->stride*vertices_number!=bytes)
|
||||
return(false);
|
||||
|
||||
VABAccess vad;
|
||||
|
||||
return AcquirePVB(&vad,name,data);
|
||||
}
|
||||
|
||||
void PrimitiveCreater::ClearAllData()
|
||||
{
|
||||
if(vab_map.GetCount()>0)
|
||||
{
|
||||
const auto *sp=vab_map.GetDataList();
|
||||
for(int i=0;i<vab_map.GetCount();i++)
|
||||
{
|
||||
if(vab_map.GetCount()>0)
|
||||
if((*sp)->value.vab)
|
||||
{
|
||||
const auto *sp=vab_map.GetDataList();
|
||||
for(int i=0;i<vab_map.GetCount();i++)
|
||||
{
|
||||
if((*sp)->value.vab)
|
||||
{
|
||||
(*sp)->value.vab->Unmap();
|
||||
delete (*sp)->value.vab;
|
||||
}
|
||||
(*sp)->value.vab->Unmap();
|
||||
delete (*sp)->value.vab;
|
||||
}
|
||||
|
||||
++sp;
|
||||
}
|
||||
}
|
||||
|
||||
if(ibo)
|
||||
{
|
||||
ibo->Unmap();
|
||||
delete ibo;
|
||||
ibo=nullptr;
|
||||
}
|
||||
++sp;
|
||||
}
|
||||
}
|
||||
|
||||
Primitive *PrimitiveCreater::Finish(const AnsiString &prim_name)
|
||||
if(ibo)
|
||||
{
|
||||
ibo->Unmap();
|
||||
delete ibo;
|
||||
ibo=nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
Primitive *PrimitiveCreater::Finish(const AnsiString &prim_name)
|
||||
{
|
||||
const uint si_count=vil->GetCount(VertexInputGroup::Basic);
|
||||
|
||||
if(vab_map.GetCount()!=si_count)
|
||||
return(nullptr);
|
||||
|
||||
Primitive *primitive=db->CreatePrimitive(prim_name,vertices_number);
|
||||
|
||||
const auto *sp=vab_map.GetDataList();
|
||||
for(uint i=0;i<si_count;i++)
|
||||
{
|
||||
if((*sp)->value.vab)
|
||||
{
|
||||
const uint si_count=vil->GetCount(VertexInputGroup::Basic);
|
||||
if((*sp)->value.map_ptr)
|
||||
(*sp)->value.vab->Unmap();
|
||||
|
||||
if(vab_map.GetCount()!=si_count)
|
||||
return(nullptr);
|
||||
|
||||
Primitive *primitive=db->CreatePrimitive(prim_name,vertices_number);
|
||||
|
||||
const auto *sp=vab_map.GetDataList();
|
||||
for(uint i=0;i<si_count;i++)
|
||||
{
|
||||
if((*sp)->value.vab)
|
||||
{
|
||||
if((*sp)->value.map_ptr)
|
||||
(*sp)->value.vab->Unmap();
|
||||
|
||||
primitive->SetVAB((*sp)->key,(*sp)->value.vab);
|
||||
}
|
||||
else
|
||||
{
|
||||
//ClearAllData();
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
++sp;
|
||||
}
|
||||
|
||||
if(ibo)
|
||||
{
|
||||
ibo->Unmap();
|
||||
primitive->SetIndex(ibo,0,index_number);
|
||||
|
||||
db->Add(ibo);
|
||||
ibo=nullptr; //避免释构函数删除
|
||||
}
|
||||
|
||||
db->Add(primitive);
|
||||
|
||||
return primitive;
|
||||
primitive->SetVAB((*sp)->key,(*sp)->value.vab);
|
||||
}
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
else
|
||||
{
|
||||
//ClearAllData();
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
++sp;
|
||||
}
|
||||
|
||||
if(ibo)
|
||||
{
|
||||
ibo->Unmap();
|
||||
primitive->SetIndex(ibo,0,index_number);
|
||||
|
||||
db->Add(ibo);
|
||||
ibo=nullptr; //避免释构函数删除
|
||||
}
|
||||
|
||||
db->Add(primitive);
|
||||
|
||||
return primitive;
|
||||
}
|
||||
VK_NAMESPACE_END
|
Loading…
x
Reference in New Issue
Block a user