diff --git a/inc/hgl/graph/PrimitiveCreater.h b/inc/hgl/graph/PrimitiveCreater.h index f85a09f5..70670e87 100644 --- a/inc/hgl/graph/PrimitiveCreater.h +++ b/inc/hgl/graph/PrimitiveCreater.h @@ -25,6 +25,9 @@ namespace hgl protected: + GPUDevice *device; + const GPUPhysicalDevice *phy_device; + VertexDataManager *vdm; RenderResource *db; @@ -49,7 +52,7 @@ namespace hgl PrimitiveCreater(VertexDataManager *); virtual ~PrimitiveCreater()=default; - virtual bool Init(const uint32 vertices_count); ///<初始化,参数为顶点数量 + virtual bool Init(const uint32 vertices_count,const uint32 index_count,IndexType it=IndexType::ERR); ///<初始化,参数为顶点数量 template T * AccessVBO(const AnsiString &name) ///<创建一个顶点属性数据缓冲区以及访问器 diff --git a/inc/hgl/graph/VertexDataManager.h b/inc/hgl/graph/VertexDataManager.h index e486e250..bd4f42d4 100644 --- a/inc/hgl/graph/VertexDataManager.h +++ b/inc/hgl/graph/VertexDataManager.h @@ -14,8 +14,8 @@ namespace hgl protected: - VIL * vil; ///<顶点输入格式列表 - uint vi_count; ///<顶点输入流数量 + const VIL * vil; ///<顶点输入格式列表 + uint vi_count; ///<顶点输入流数量 const VIF * vif_list; ///<顶点输入格式列表 VkDeviceSize vbo_max_size; ///<顶点缓冲区分配空间大小 @@ -35,6 +35,8 @@ namespace hgl VertexDataManager(GPUDevice *dev,const VIL *_vil); ~VertexDataManager(); + GPUDevice * GetDevice ()const{return device;} ///<取得GPU设备 + const VIL * GetVIL ()const{return vil;} ///<取得顶点输入格式列表 const VkDeviceSize GetVBOMaxCount ()const{return vbo_max_size;} ///<取得顶点缓冲区分配的空间最大数量 diff --git a/src/SceneGraph/InlineGeometry.cpp b/src/SceneGraph/InlineGeometry.cpp index 5e9a3865..141dd8a8 100644 --- a/src/SceneGraph/InlineGeometry.cpp +++ b/src/SceneGraph/InlineGeometry.cpp @@ -18,7 +18,7 @@ namespace hgl { PrimitiveCreater rc(db,vil); - if(!rc.Init(4)) + if(!rc.Init(4,0)) return(nullptr); AutoDelete vertex=rc.AccessVBO(VAN::Position); @@ -46,7 +46,7 @@ namespace hgl if(rci->radius==0||rci->round_per<=1) //这是要画矩形 { - if(!rc.Init(4)) + if(!rc.Init(4,0)) return(nullptr); AutoDelete vertex=rc.AccessVBO(VAN::Position); @@ -60,7 +60,7 @@ namespace hgl if(radius>rci->scope.GetWidth()/2.0f)radius=rci->scope.GetWidth()/2.0f; if(radius>rci->scope.GetHeight()/2.0f)radius=rci->scope.GetHeight()/2.0f; - if(!rc.Init(rci->round_per*4)) + if(!rc.Init(rci->round_per*4,8)) return(nullptr); AutoDelete vertex=rc.AccessVBO(VAN::Position); @@ -123,12 +123,12 @@ namespace hgl if(cci->has_color) { edge=cci->field_count+1; - if(!rc.Init(cci->field_count+2))return(nullptr); + if(!rc.Init(cci->field_count+2,0))return(nullptr); } else { edge=cci->field_count; - if(!rc.Init(cci->field_count))return(nullptr); + if(!rc.Init(cci->field_count,0))return(nullptr); } AutoDelete vertex=rc.AccessVBO(VAN::Position); @@ -166,7 +166,7 @@ namespace hgl { PrimitiveCreater rc(db,vil); - if(!rc.Init(((pgci->grid_size.Width()+1)+(pgci->grid_size.Height()+1))*2)) + if(!rc.Init(((pgci->grid_size.Width()+1)+(pgci->grid_size.Height()+1))*2,8)) return(nullptr); AutoDelete vertex=rc.AccessVBO(VAN::Position); @@ -221,7 +221,7 @@ namespace hgl PrimitiveCreater rc(db,vil); - if(!rc.Init(4)) + if(!rc.Init(4,8)) return(nullptr); rc.WriteVBO(VAN::Position,xy_vertices,sizeof(xy_vertices)); diff --git a/src/SceneGraph/PrimitiveCreater.cpp b/src/SceneGraph/PrimitiveCreater.cpp index 8ca07e4d..898f42bc 100644 --- a/src/SceneGraph/PrimitiveCreater.cpp +++ b/src/SceneGraph/PrimitiveCreater.cpp @@ -9,6 +9,9 @@ namespace hgl { PrimitiveCreater::PrimitiveCreater(RenderResource *sdb,const VIL *v) { + device=sdb->GetDevice(); + phy_device=device->GetPhysicalDevice(); + db =sdb; vil =v; @@ -18,18 +21,39 @@ namespace hgl PrimitiveCreater::PrimitiveCreater(VertexDataManager *_vdm) { + device=_vdm->GetDevice(); + phy_device=device->GetPhysicalDevice(); + vdm=_vdm; vil=vdm->GetVIL(); vertices_number =0; ibo =nullptr; + + } - bool PrimitiveCreater::Init(const uint32 count) + bool PrimitiveCreater::Init(const uint32 vertex_count,const uint32 index_count,IndexType it) { - if(count<=0)return(false); + if(vertex_count<=0)return(false); - vertices_number=count; + vertices_number=vertex_count; + + if(index_count>0) + { + if(it==IndexType::ERR) + { + if(vertex_count<=0xFFFF) + it=IndexType::U16; + else + it=IndexType::U32; + } + + ibo=db->CreateIBO(it,index_count); + if(!ibo)return(false); + + ibo->Map(); + } return(true); } diff --git a/src/SceneGraph/Vulkan/VKDeviceCreater.cpp b/src/SceneGraph/Vulkan/VKDeviceCreater.cpp index d3b0cb63..f2050b10 100644 --- a/src/SceneGraph/Vulkan/VKDeviceCreater.cpp +++ b/src/SceneGraph/Vulkan/VKDeviceCreater.cpp @@ -70,6 +70,9 @@ namespace // VK_EXT_SAMPLER_FILTER_MINMAX_EXTENSION_NAME, + VK_EXT_INDEX_TYPE_UINT8_EXTENSION_NAME, + VK_KHR_INDEX_TYPE_UINT8_EXTENSION_NAME, + VK_KHR_SPIRV_1_4_EXTENSION_NAME, };