ULRE/inc/hgl/graph/PrimitiveCreater.h

99 lines
3.3 KiB
C
Raw Normal View History

#ifndef HGL_GRAPH_PRIMITIVE_CREATER_INCLUDE
#define HGL_GRAPH_PRIMITIVE_CREATER_INCLUDE
2020-10-21 12:39:22 +08:00
#include<hgl/graph/VKRenderResource.h>
#include<hgl/graph/VertexAttribDataAccess.h>
#include<hgl/graph/VKShaderModule.h>
#include<hgl/graph/VKIndexBuffer.h>
namespace hgl
{
namespace graph
{
class VertexDataManager;
/**
*
*/
class PrimitiveCreater
{
protected:
2024-04-17 20:22:31 +08:00
GPUDevice *device;
const GPUPhysicalDevice *phy_device;
VertexDataManager *vdm;
2020-10-21 12:47:06 +08:00
RenderResource *db;
const VIL *vil;
protected:
VkDeviceSize vertices_number;
VkDeviceSize index_number;
IndexBuffer * ibo;
void * ibo_map;
2024-04-24 01:38:55 +08:00
VABAccessMap vbo_map;
2024-04-02 22:15:44 +08:00
protected:
2024-04-24 01:38:55 +08:00
bool AcquirePVB(VABAccess *,const AnsiString &,const void *data); ///<请求一个顶点属性数据区
void ClearAllData();
2024-04-02 22:15:44 +08:00
public:
PrimitiveCreater(RenderResource *sdb,const VIL *);
PrimitiveCreater(VertexDataManager *);
virtual ~PrimitiveCreater();
virtual bool Init(const uint32 vertices_count,const uint32 index_count,IndexType it=IndexType::AUTO); ///<初始化,参数为顶点数量
template<typename T>
2024-04-24 01:38:55 +08:00
T * AccessVAB(const AnsiString &name) ///<创建一个顶点属性数据缓冲区以及访问器
{
const VkFormat format=vil->GetVulkanFormat(name);
if(format!=T::GetVulkanFormat())
return(nullptr);
2024-04-24 01:38:55 +08:00
VABAccess vad;
if(!this->AcquirePVB(&vad,name,nullptr))
return(nullptr);
T *access=T::Create(vertices_number,vad.map_ptr);
2023-05-29 21:43:39 +08:00
access->Begin();
2023-05-29 21:43:39 +08:00
return access;
}
2024-04-24 01:38:55 +08:00
bool WriteVAB(const AnsiString &name,const void *data,const uint32_t bytes); ///<直接写入顶点属性数据
const IndexType GetIndexType()const{return ibo?ibo->GetType():IndexType::ERR;} ///<取得索引数据类型
2024-04-24 01:38:55 +08:00
template<typename T> T *AccessIBO()
{
if(!ibo)return(nullptr);
if(ibo->GetStride()!=sizeof(T))return(nullptr);
return (T *)ibo_map;
}
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);
return(true);
}
2023-10-12 05:55:39 +08:00
virtual Primitive * Finish(const AnsiString &); ///<结束并创建可渲染对象
};//class PrimitiveCreater
}//namespace graph
}//namespace hgl
#endif//HGL_GRAPH_PRIMITIVE_CREATER_INCLUDE