[very strong] deleted class VertexAttribData

This commit is contained in:
hyzboy 2024-04-02 22:51:14 +08:00
parent c1183d351d
commit 8c51d3a52b
7 changed files with 62 additions and 145 deletions

View File

@ -4,6 +4,7 @@
#include<hgl/graph/VKRenderResource.h> #include<hgl/graph/VKRenderResource.h>
#include<hgl/graph/VertexAttribDataAccess.h> #include<hgl/graph/VertexAttribDataAccess.h>
#include<hgl/graph/VKShaderModule.h> #include<hgl/graph/VKShaderModule.h>
#include<hgl/graph/VKVertexAttribBuffer.h>
namespace hgl namespace hgl
{ {
namespace graph namespace graph
@ -16,16 +17,9 @@ namespace hgl
struct PrimitiveVertexBuffer struct PrimitiveVertexBuffer
{ {
AnsiString name; AnsiString name;
uint binding; int binding;
VAD * vad =nullptr; VBO * vbo;
VBO * vbo =nullptr; void * map_data;
public:
~PrimitiveVertexBuffer()
{
SAFE_CLEAR(vad);
}
};//struct PrimitiveVertexBuffer };//struct PrimitiveVertexBuffer
using PVBMap=ObjectMap<AnsiString,PrimitiveVertexBuffer>; using PVBMap=ObjectMap<AnsiString,PrimitiveVertexBuffer>;
@ -45,7 +39,9 @@ namespace hgl
protected: protected:
VAD * CreateVAD(const AnsiString &name); ///<创建一个顶点属性缓冲区 PrimitiveVertexBuffer *CreatePVB(const AnsiString &,const void *data); ///<创建一个顶点属性数据区
void ClearAllData();
public: public:
@ -62,12 +58,12 @@ namespace hgl
if(format!=T::GetVulkanFormat()) if(format!=T::GetVulkanFormat())
return(nullptr); return(nullptr);
VAD *vad=this->CreateVAD(name); PrimitiveVertexBuffer *pvb=this->CreatePVB(name,nullptr);
if(!vad) if(!pvb)
return(nullptr); return(nullptr);
T *access=T::Create(vad); T *access=T::Create(vertices_number,pvb->map_data);
access->Begin(); access->Begin();

View File

@ -13,7 +13,6 @@
#include<hgl/graph/VKDeviceAttribute.h> #include<hgl/graph/VKDeviceAttribute.h>
#include<hgl/graph/VKSwapchain.h> #include<hgl/graph/VKSwapchain.h>
#include<hgl/graph/VKRenderTarget.h> #include<hgl/graph/VKRenderTarget.h>
#include<hgl/graph/VertexAttribData.h>
#include<hgl/graph/VKShaderModuleMap.h> #include<hgl/graph/VKShaderModuleMap.h>
#include<hgl/graph/VKArrayBuffer.h> #include<hgl/graph/VKArrayBuffer.h>
#include<hgl/graph/VKDescriptorSetType.h> #include<hgl/graph/VKDescriptorSetType.h>
@ -117,7 +116,6 @@ public: //Buffer相关
VBO * CreateVBO (VkFormat format, uint32_t count,const void *data, SharingMode sm=SharingMode::Exclusive); VBO * CreateVBO (VkFormat format, uint32_t count,const void *data, SharingMode sm=SharingMode::Exclusive);
VBO * CreateVBO (VkFormat format, uint32_t count, SharingMode sm=SharingMode::Exclusive){return CreateVBO(format,count,nullptr,sm);} VBO * CreateVBO (VkFormat format, uint32_t count, SharingMode sm=SharingMode::Exclusive){return CreateVBO(format,count,nullptr,sm);}
VBO * CreateVBO (const VAD *vad, SharingMode sm=SharingMode::Exclusive){return CreateVBO(vad->GetFormat(),vad->GetCount(),vad->GetData(),sm);}
IndexBuffer * CreateIBO (IndexType type, uint32_t count,const void * data, SharingMode sm=SharingMode::Exclusive); IndexBuffer * CreateIBO (IndexType type, uint32_t count,const void * data, SharingMode sm=SharingMode::Exclusive);
IndexBuffer * CreateIBO8 ( uint32_t count,const void * data, SharingMode sm=SharingMode::Exclusive){return CreateIBO(IndexType::U8, count,(void *)data,sm);} IndexBuffer * CreateIBO8 ( uint32_t count,const void * data, SharingMode sm=SharingMode::Exclusive){return CreateIBO(IndexType::U8, count,(void *)data,sm);}

View File

@ -10,7 +10,6 @@
#include<hgl/graph/VKTexture.h> #include<hgl/graph/VKTexture.h>
#include<hgl/graph/VKMaterialParameters.h> #include<hgl/graph/VKMaterialParameters.h>
#include<hgl/graph/VKMaterialInstance.h> #include<hgl/graph/VKMaterialInstance.h>
#include<hgl/graph/VertexAttribData.h>
#include<hgl/graph/VKRenderable.h> #include<hgl/graph/VKRenderable.h>
#include<hgl/graph/font/TextPrimitive.h> #include<hgl/graph/font/TextPrimitive.h>
#include<hgl/type/ObjectManage.h> #include<hgl/type/ObjectManage.h>
@ -106,7 +105,6 @@ public: // VBO/VAO
VBO *CreateVBO(VkFormat format,uint32_t count,const void *data, SharingMode sm=SharingMode::Exclusive); VBO *CreateVBO(VkFormat format,uint32_t count,const void *data, SharingMode sm=SharingMode::Exclusive);
VBO *CreateVBO(VkFormat format,uint32_t count, SharingMode sm=SharingMode::Exclusive){return CreateVBO(format, count, nullptr, sm);} VBO *CreateVBO(VkFormat format,uint32_t count, SharingMode sm=SharingMode::Exclusive){return CreateVBO(format, count, nullptr, sm);}
VBO *CreateVBO(const VAD *vad, SharingMode sm=SharingMode::Exclusive){return CreateVBO(vad->GetFormat(), vad->GetCount(),vad->GetData(), sm);}
#define SCENE_DB_CREATE_FUNC(name) DeviceBuffer *Create##name(const AnsiString &buf_name,VkDeviceSize size,void *data,SharingMode sm=SharingMode::Exclusive); \ #define SCENE_DB_CREATE_FUNC(name) DeviceBuffer *Create##name(const AnsiString &buf_name,VkDeviceSize size,void *data,SharingMode sm=SharingMode::Exclusive); \
DeviceBuffer *Create##name(const AnsiString &buf_name,VkDeviceSize size,SharingMode sm=SharingMode::Exclusive){return Create##name(buf_name,size,nullptr,sm);} DeviceBuffer *Create##name(const AnsiString &buf_name,VkDeviceSize size,SharingMode sm=SharingMode::Exclusive){return Create##name(buf_name,size,nullptr,sm);}

View File

@ -1,49 +0,0 @@
#ifndef HGL_GRAPH_VERTEX_ATTRIB_DATA_INCLUDE
#define HGL_GRAPH_VERTEX_ATTRIB_DATA_INCLUDE
#include<hgl/graph/VK.h>
namespace hgl
{
namespace graph
{
/**
*
*/
class VertexAttribData ///顶点属性数据
{
void *mem_data; ///<内存中的数据
protected:
VkFormat format;
uint32_t count; ///<数据个数
uint32_t total_bytes; ///<字节数
public:
VertexAttribData(uint32_t c,const VkFormat vf,const uint32_t t)
{
count=c;
format=vf;
total_bytes=t;
mem_data = hgl_malloc(total_bytes); //在很多情况下hgl_malloc分配的内存是对齐的这样有效率上的提升
}
virtual ~VertexAttribData()
{
if(mem_data)
hgl_free(mem_data);
}
const VkFormat GetFormat ()const{return format;} ///<取得数据类型
const uint32_t GetCount ()const{return count;} ///<取得数据数量
void * GetData ()const{return mem_data;} ///<取得数据指针
const uint32_t GetTotalBytes ()const{return total_bytes;} ///<取得数据字节数
};//class VertexAttribData
using VAD=VertexAttribData;
}//namespace graph
}//namespace hgl
#endif//HGL_GRAPH_VERTEX_ATTRIB_DATA_INCLUDE

View File

@ -5,7 +5,6 @@
#include<hgl/color/Color4f.h> #include<hgl/color/Color4f.h>
#include<hgl/type/RectScope.h> #include<hgl/type/RectScope.h>
#include<hgl/type/String.h> #include<hgl/type/String.h>
#include<hgl/graph/VertexAttribData.h>
#include<hgl/log/LogInfo.h> #include<hgl/log/LogInfo.h>
namespace hgl namespace hgl
{ {
@ -130,14 +129,9 @@ namespace hgl
static VkFormat GetVulkanFormat(){return VKFMT;} static VkFormat GetVulkanFormat(){return VKFMT;}
static VertexAttribDataAccess1<T,VKFMT> * Create(VAD *vad) static VertexAttribDataAccess1<T,VKFMT> * Create(const VkDeviceSize vertices_number,void *vbo_data)
{ {
if(!vad)return(nullptr); return(new VertexAttribDataAccess1<T,VKFMT>(vertices_number,(T *)vbo_data));
if(vad->GetFormat()!=VKFMT)
return(nullptr);
return(new VertexAttribDataAccess1<T,VKFMT>(vad->GetCount(),(T *)vad->GetData()));
} }
/** /**
@ -223,14 +217,9 @@ namespace hgl
static VkFormat GetVulkanFormat(){return VKFMT;} static VkFormat GetVulkanFormat(){return VKFMT;}
static VertexAttribDataAccess2<T,VKFMT> * Create(VAD *vad) static VertexAttribDataAccess2<T,VKFMT> * Create(const VkDeviceSize vertices_number,void *vbo_data)
{ {
if(!vad)return(nullptr); return(new VertexAttribDataAccess2<T,VKFMT>(vertices_number,(T *)vbo_data));
if(vad->GetFormat()!=VKFMT)
return(nullptr);
return(new VertexAttribDataAccess2<T,VKFMT>(vad->GetCount(),(T *)vad->GetData()));
} }
/** /**
@ -539,14 +528,9 @@ namespace hgl
static VkFormat GetVulkanFormat(){return VKFMT;} static VkFormat GetVulkanFormat(){return VKFMT;}
static VertexAttribDataAccess3<T,VKFMT> * Create(VAD *vad) static VertexAttribDataAccess3<T,VKFMT> * Create(const VkDeviceSize vertices_number,void *vbo_data)
{ {
if(!vad)return(nullptr); return(new VertexAttribDataAccess3<T,VKFMT>(vertices_number,(T *)vbo_data));
if(vad->GetFormat()!=VKFMT)
return(nullptr);
return(new VertexAttribDataAccess3<T,VKFMT>(vad->GetCount(),(T *)vad->GetData()));
} }
/** /**
@ -811,14 +795,9 @@ namespace hgl
static VkFormat GetVulkanFormat(){return VKFMT;} static VkFormat GetVulkanFormat(){return VKFMT;}
static VertexAttribDataAccess4<T,VKFMT> * Create(VAD *vad) static VertexAttribDataAccess4<T,VKFMT> * Create(const VkDeviceSize vertices_number,void *vbo_data)
{ {
if(!vad)return(nullptr); return(new VertexAttribDataAccess4<T,VKFMT>(vertices_number,(T *)vbo_data));
if(vad->GetFormat()!=VKFMT)
return(nullptr);
return(new VertexAttribDataAccess4<T,VKFMT>(vad->GetCount(),(T *)vad->GetData()));
} }
/** /**

View File

@ -7,12 +7,8 @@ SET(SG_TEXTURE_SOURCE ${SG_INCLUDE_PATH}/TextureLoader.h
SOURCE_GROUP("Texture" FILES ${SG_TEXTURE_SOURCE}) SOURCE_GROUP("Texture" FILES ${SG_TEXTURE_SOURCE})
SET(SG_VAD_SOURCE ${SG_INCLUDE_PATH}/VertexAttribData.h SET(SG_VDM_SOURCE ${SG_INCLUDE_PATH}/VertexAttribDataAccess.h
${SG_INCLUDE_PATH}/VertexAttribDataAccess.h) ${SG_INCLUDE_PATH}/VertexDataManager.h)
SOURCE_GROUP("VertexAttribData" FILES ${SG_VAD_SOURCE})
SET(SG_VDM_SOURCE ${SG_INCLUDE_PATH}/VertexDataManager.h)
SOURCE_GROUP("VertexDataManager" FILES ${SG_VDM_SOURCE}) SOURCE_GROUP("VertexDataManager" FILES ${SG_VDM_SOURCE})
@ -305,7 +301,6 @@ add_cm_library(ULRE.SceneGraph "ULRE" ${SCENE_GRAPH_HEADER}
${SG_TEXTURE_SOURCE} ${SG_TEXTURE_SOURCE}
${TILE_SOURCE} ${TILE_SOURCE}
${SG_VAD_SOURCE}
${SG_VDM_SOURCE} ${SG_VDM_SOURCE}
# ${FONT_MANAGE_SOURCE} # ${FONT_MANAGE_SOURCE}

View File

@ -5,22 +5,6 @@ namespace hgl
{ {
namespace graph namespace graph
{ {
/**
* (VAD)
* @param vertex_count
* @param vif
*/
VAD *CreateVertexAttribData(const uint32_t vertex_count,const VertexInputFormat *vif)
{
if(vertex_count<=0
||vif->vec_size<1||vif->vec_size>4
||vif->stride<1||vif->stride>8*4
||!CheckVulkanFormat(vif->format))
return(nullptr);
return(new VertexAttribData(vertex_count,vif->format,vif->stride*vertex_count));
}
PrimitiveCreater::PrimitiveCreater(RenderResource *sdb,const VIL *v) PrimitiveCreater::PrimitiveCreater(RenderResource *sdb,const VIL *v)
{ {
db =sdb; db =sdb;
@ -39,7 +23,7 @@ namespace hgl
return(true); return(true);
} }
VAD *PrimitiveCreater::CreateVAD(const AnsiString &name) PrimitiveCreater::PrimitiveVertexBuffer *PrimitiveCreater::CreatePVB(const AnsiString &name,const void *data)
{ {
if(!vil)return(nullptr); if(!vil)return(nullptr);
if(name.IsEmpty())return(nullptr); if(name.IsEmpty())return(nullptr);
@ -52,24 +36,22 @@ namespace hgl
PrimitiveVertexBuffer *pvb; PrimitiveVertexBuffer *pvb;
if(vbo_map.Get(name,pvb)) if(vbo_map.Get(name,pvb))
return pvb->vad; return pvb;
VAD *vad=hgl::graph::CreateVertexAttribData(vertices_number,vif);
if(!vad)
return(nullptr);
pvb=new PrimitiveVertexBuffer; pvb=new PrimitiveVertexBuffer;
pvb->vad =vad;
pvb->name =name; pvb->name =name;
pvb->binding=vif->binding; pvb->binding=vif->binding;
pvb->vbo =db->CreateVBO(vif->format,vertices_number,data);
pvb->vbo =nullptr; if(!data)
pvb->map_data=pvb->vbo->Map();
else
pvb->map_data=nullptr;
vbo_map.Add(name,pvb); vbo_map.Add(name,pvb);
return pvb->vad; return pvb;
} }
bool PrimitiveCreater::WriteVAD(const AnsiString &name,const void *data,const uint32_t bytes) bool PrimitiveCreater::WriteVAD(const AnsiString &name,const void *data,const uint32_t bytes)
@ -79,11 +61,6 @@ namespace hgl
if(!data)return(false); if(!data)return(false);
if(!bytes)return(false); if(!bytes)return(false);
PrimitiveVertexBuffer *pvb;
if(vbo_map.Get(name,pvb))
return false;
const VertexInputFormat *vif=vil->GetConfig(name); const VertexInputFormat *vif=vil->GetConfig(name);
if(!vif) if(!vif)
@ -92,17 +69,32 @@ namespace hgl
if(vif->stride*vertices_number!=bytes) if(vif->stride*vertices_number!=bytes)
return(false); return(false);
pvb=new PrimitiveVertexBuffer; return CreatePVB(name,data);
}
pvb->vad =nullptr; void PrimitiveCreater::ClearAllData()
pvb->name =name; {
pvb->binding=vif->binding; if(vbo_map.GetCount()>0)
{
const auto *sp=vbo_map.GetDataList();
for(uint i=0;i<vbo_map.GetCount();i++)
{
if((*sp)->value->vbo)
{
(*sp)->value->vbo->Unmap();
delete (*sp)->value->vbo;
}
pvb->vbo =db->CreateVBO(vif->format,vertices_number,data); ++sp;
}
}
vbo_map.Add(name,pvb); if(ibo)
{
return true; ibo->Unmap();
delete ibo;
ibo=nullptr;
}
} }
Primitive *PrimitiveCreater::Finish(const AnsiString &prim_name) Primitive *PrimitiveCreater::Finish(const AnsiString &prim_name)
@ -118,9 +110,17 @@ namespace hgl
for(uint i=0;i<si_count;i++) for(uint i=0;i<si_count;i++)
{ {
if((*sp)->value->vbo) if((*sp)->value->vbo)
{
if((*sp)->value->map_data)
(*sp)->value->vbo->Unmap();
primitive->Set((*sp)->key,(*sp)->value->vbo); primitive->Set((*sp)->key,(*sp)->value->vbo);
}
else else
primitive->Set((*sp)->key,db->CreateVBO((*sp)->value->vad)); {
//ClearAllData();
return(nullptr);
}
++sp; ++sp;
} }