From f00cb0b8158ca5c0b94655f73ed46a1f3cc86523 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Wed, 17 Apr 2024 01:20:52 +0800 Subject: [PATCH] split VertexDataManager.h/.cpp --- inc/hgl/graph/VertexDataManager.h | 57 +++------------------- src/SceneGraph/CMakeLists.txt | 3 +- src/SceneGraph/VertexDataManager.cpp | 73 ++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+), 52 deletions(-) create mode 100644 src/SceneGraph/VertexDataManager.cpp diff --git a/inc/hgl/graph/VertexDataManager.h b/inc/hgl/graph/VertexDataManager.h index aeb3a1ec..a5cedca9 100644 --- a/inc/hgl/graph/VertexDataManager.h +++ b/inc/hgl/graph/VertexDataManager.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include namespace hgl @@ -25,30 +26,13 @@ namespace hgl protected: - DataChain data_chain; ///<数据链 + DataChain vbo_data_chain; ///<数据链 + DataChain ibo_data_chain; ///<数据链 public: - VertexDataManager(GPUDevice *dev,const VIL *_vil) - { - device=dev; - - vi_count=_vil->GetCount(); - vif_list=_vil->GetVIFList(); //来自于Material,不会被释放,所以指针有效 - - vbo_max_size=0; - vbo_cur_size=0; - vbo=hgl_zero_new(vi_count); - - ibo_cur_size=0; - ibo=nullptr; - } - - ~VertexDataManager() - { - SAFE_CLEAR_OBJECT_ARRAY(vbo,vi_count); - SAFE_CLEAR(ibo); - } + VertexDataManager(GPUDevice *dev,const VIL *_vil); + ~VertexDataManager(); const VkDeviceSize GetVBOMaxCount ()const{return vbo_max_size;} ///<取得顶点缓冲区分配的空间最大数量 const VkDeviceSize GetVBOCurCount ()const{return vbo_cur_size;} ///<取得顶点缓冲区当前数量 @@ -59,36 +43,7 @@ namespace hgl public: - bool Init(const VkDeviceSize vbo_size,const VkDeviceSize ibo_size,const IndexType index_type) - { - if(vbo[0]||ibo) //已经初始化过了 - return(false); - - if(vbo_size<=0) - return(false); - - vbo_max_size=vbo_size; - ibo_cur_size=ibo_size; - - vbo_cur_size=0; - ibo_cur_size=0; - - for(uint i=0;iCreateVBO(vif_list[i].format,vbo_max_size); - if(!vbo[i]) - return(false); - } - - if(ibo_size>0) - { - ibo=device->CreateIBO(index_type,ibo_size); - if(!ibo) - return(false); - } - - return(true); - } + bool Init(const VkDeviceSize vbo_size,const VkDeviceSize ibo_size,const IndexType index_type); };//class VertexDataManager }//namespace graph }//namespace hgl diff --git a/src/SceneGraph/CMakeLists.txt b/src/SceneGraph/CMakeLists.txt index 4e8a5a28..db3a82c0 100644 --- a/src/SceneGraph/CMakeLists.txt +++ b/src/SceneGraph/CMakeLists.txt @@ -8,7 +8,8 @@ SET(SG_TEXTURE_SOURCE ${SG_INCLUDE_PATH}/TextureLoader.h SOURCE_GROUP("Texture" FILES ${SG_TEXTURE_SOURCE}) SET(SG_VDM_SOURCE ${SG_INCLUDE_PATH}/VertexAttribDataAccess.h - ${SG_INCLUDE_PATH}/VertexDataManager.h) + ${SG_INCLUDE_PATH}/VertexDataManager.h + VertexDataManager.cpp) SOURCE_GROUP("VertexDataManager" FILES ${SG_VDM_SOURCE}) diff --git a/src/SceneGraph/VertexDataManager.cpp b/src/SceneGraph/VertexDataManager.cpp new file mode 100644 index 00000000..3527cb95 --- /dev/null +++ b/src/SceneGraph/VertexDataManager.cpp @@ -0,0 +1,73 @@ +#include +#include +#include +#include +#include + +namespace hgl +{ + namespace graph + { + VertexDataManager::VertexDataManager(GPUDevice *dev,const VIL *_vil) + { + device=dev; + + vi_count=_vil->GetCount(); + vif_list=_vil->GetVIFList(); //MaterialᱻͷţָЧ + + vbo_max_size=0; + vbo_cur_size=0; + vbo=hgl_zero_new(vi_count); + + ibo_cur_size=0; + ibo=nullptr; + } + + VertexDataManager::~VertexDataManager() + { + SAFE_CLEAR_OBJECT_ARRAY(vbo,vi_count); + SAFE_CLEAR(ibo); + } + + /** + * ʼݹ + * @param vbo_size VBOС + * @param ibo_size IBOС + * @param index_type + */ + bool VertexDataManager::Init(const VkDeviceSize vbo_size,const VkDeviceSize ibo_size,const IndexType index_type) + { + if(vbo[0]||ibo) //Ѿʼ + return(false); + + if(vbo_size<=0) + return(false); + + vbo_max_size=vbo_size; + ibo_cur_size=ibo_size; + + vbo_cur_size=0; + ibo_cur_size=0; + + for(uint i=0;iCreateVBO(vif_list[i].format,vbo_max_size); + if(!vbo[i]) + return(false); + } + + vbo_data_chain.Init(vbo_max_size); + + if(ibo_size>0) + { + ibo=device->CreateIBO(index_type,ibo_size); + if(!ibo) + return(false); + + ibo_data_chain.Init(ibo_size); + } + + return(true); + } + }//namespace graph +}//namespace hgl