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

View File

@ -13,7 +13,6 @@
#include<hgl/graph/VKDeviceAttribute.h>
#include<hgl/graph/VKSwapchain.h>
#include<hgl/graph/VKRenderTarget.h>
#include<hgl/graph/VertexAttribData.h>
#include<hgl/graph/VKShaderModuleMap.h>
#include<hgl/graph/VKArrayBuffer.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, 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 * 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/VKMaterialParameters.h>
#include<hgl/graph/VKMaterialInstance.h>
#include<hgl/graph/VertexAttribData.h>
#include<hgl/graph/VKRenderable.h>
#include<hgl/graph/font/TextPrimitive.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, 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); \
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/type/RectScope.h>
#include<hgl/type/String.h>
#include<hgl/graph/VertexAttribData.h>
#include<hgl/log/LogInfo.h>
namespace hgl
{
@ -130,14 +129,9 @@ namespace hgl
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);
if(vad->GetFormat()!=VKFMT)
return(nullptr);
return(new VertexAttribDataAccess1<T,VKFMT>(vad->GetCount(),(T *)vad->GetData()));
return(new VertexAttribDataAccess1<T,VKFMT>(vertices_number,(T *)vbo_data));
}
/**
@ -223,14 +217,9 @@ namespace hgl
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);
if(vad->GetFormat()!=VKFMT)
return(nullptr);
return(new VertexAttribDataAccess2<T,VKFMT>(vad->GetCount(),(T *)vad->GetData()));
return(new VertexAttribDataAccess2<T,VKFMT>(vertices_number,(T *)vbo_data));
}
/**
@ -539,14 +528,9 @@ namespace hgl
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);
if(vad->GetFormat()!=VKFMT)
return(nullptr);
return(new VertexAttribDataAccess3<T,VKFMT>(vad->GetCount(),(T *)vad->GetData()));
return(new VertexAttribDataAccess3<T,VKFMT>(vertices_number,(T *)vbo_data));
}
/**
@ -811,14 +795,9 @@ namespace hgl
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);
if(vad->GetFormat()!=VKFMT)
return(nullptr);
return(new VertexAttribDataAccess4<T,VKFMT>(vad->GetCount(),(T *)vad->GetData()));
return(new VertexAttribDataAccess4<T,VKFMT>(vertices_number,(T *)vbo_data));
}
/**

View File

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

View File

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