ULRE/inc/hgl/graph/PrimitiveCreater.h

92 lines
2.7 KiB
C
Raw Normal View History

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