From 6c160f5c533546ca511539d0e06e72cc2b9b351d Mon Sep 17 00:00:00 2001 From: hyzboy Date: Thu, 12 Dec 2024 13:30:11 +0800 Subject: [PATCH] supported new Comparator<> and ItemComparator<> --- CMCore | 2 +- CMUtil | 2 +- inc/hgl/graph/MaterialRenderList.h | 6 ++--- inc/hgl/graph/RenderNode.h | 7 +++++- inc/hgl/graph/VKRenderable.h | 9 +++----- inc/hgl/graph/font/Font.h | 4 +--- src/SceneGraph/MaterialRenderList.cpp | 19 ++++++++------- src/SceneGraph/Vulkan/VKRenderable.cpp | 32 +++++++++++++++----------- 8 files changed, 41 insertions(+), 40 deletions(-) diff --git a/CMCore b/CMCore index ae1be856..7295d68a 160000 --- a/CMCore +++ b/CMCore @@ -1 +1 @@ -Subproject commit ae1be856b96aa3d26da8937cca416e8fe4360678 +Subproject commit 7295d68a5e6f2b9bc9ad08dc397375850af50bf7 diff --git a/CMUtil b/CMUtil index a7f4afab..6582b635 160000 --- a/CMUtil +++ b/CMUtil @@ -1 +1 @@ -Subproject commit a7f4afab8029f52dff43840062c8b6cb2008bd67 +Subproject commit 6582b635c9b93284c29dd7e1bc6dc5ecf59a8705 diff --git a/inc/hgl/graph/MaterialRenderList.h b/inc/hgl/graph/MaterialRenderList.h index c9da1c99..7784b3c6 100644 --- a/inc/hgl/graph/MaterialRenderList.h +++ b/inc/hgl/graph/MaterialRenderList.h @@ -8,14 +8,14 @@ class RenderAssignBuffer; class SceneNode; struct CameraInfo; -struct RenderPipelineIndex +struct RenderPipelineIndex:public Comparator { Material *material; Pipeline *pipeline; public: - const int Comp(const RenderPipelineIndex &rli)const + const int compare(const RenderPipelineIndex &rli)const override { if(materialrli.material)return(1); @@ -26,8 +26,6 @@ public: return(0); } - CompOperator(const RenderPipelineIndex &,Comp) - public: RenderPipelineIndex() diff --git a/inc/hgl/graph/RenderNode.h b/inc/hgl/graph/RenderNode.h index 319acf8c..1b990fe1 100644 --- a/inc/hgl/graph/RenderNode.h +++ b/inc/hgl/graph/RenderNode.h @@ -11,7 +11,7 @@ namespace hgl class MaterialInstance; class SceneNode; - struct RenderNode + struct RenderNode:public Comparator { uint index; ///<在MaterialRenderList中的索引 @@ -22,6 +22,11 @@ namespace hgl Vector3f world_position; float to_camera_distance; + + public: + + //该函数位于MaterialRenderList.cpp + const int compare(const RenderNode &)const override; }; using RenderNodeList=List; diff --git a/inc/hgl/graph/VKRenderable.h b/inc/hgl/graph/VKRenderable.h index 5a40e799..9d98b662 100644 --- a/inc/hgl/graph/VKRenderable.h +++ b/inc/hgl/graph/VKRenderable.h @@ -12,7 +12,7 @@ VK_NAMESPACE_BEGIN * 原始图元数据缓冲区
* 提供在渲染之前的数据绑定信息 */ -struct PrimitiveDataBuffer +struct PrimitiveDataBuffer:public Comparator { uint32_t vab_count; VkBuffer * vab_list; @@ -32,14 +32,14 @@ public: PrimitiveDataBuffer(const uint32_t,IndexBuffer *,VertexDataManager *_v=nullptr); ~PrimitiveDataBuffer(); - const bool Comp(const PrimitiveDataBuffer *pdb)const; + const int compare(const PrimitiveDataBuffer &pdb)const override; };//struct PrimitiveDataBuffer /** * 原始图元渲染数据
* 提供在渲染时的数据 */ -struct PrimitiveRenderData +struct PrimitiveRenderData:public ComparatorData { //因为要VAB是流式访问,所以我们这个结构会被用做排序依据 //也因此,把vertex_offset放在最前面 @@ -59,9 +59,6 @@ public: vertex_offset =vo; first_index =fi; } - - CompOperatorMemcmp(const PrimitiveRenderData &); - CompOperatorMemcmpPointer(PrimitiveRenderData); }; /** diff --git a/inc/hgl/graph/font/Font.h b/inc/hgl/graph/font/Font.h index c630996b..5a1395a3 100644 --- a/inc/hgl/graph/font/Font.h +++ b/inc/hgl/graph/font/Font.h @@ -12,7 +12,7 @@ namespace hgl /** * 字体信息 */ - struct Font + struct Font:public ComparatorData { os_char name[MAX_FONT_NAME_LENGTH]; ///<字体名称 @@ -28,8 +28,6 @@ namespace hgl Font(); Font(const os_char *,int,int,bool b=false,bool i=false,bool=true); - - CompOperatorMemcmp(const Font &); ///<比较操作符重载 };//struct Font }//namespace graph }//namespace hgl diff --git a/src/SceneGraph/MaterialRenderList.cpp b/src/SceneGraph/MaterialRenderList.cpp index 078697a7..4aee43b8 100644 --- a/src/SceneGraph/MaterialRenderList.cpp +++ b/src/SceneGraph/MaterialRenderList.cpp @@ -26,13 +26,13 @@ 这样就可以保证所有的渲染操作就算要切VBO,也不需要切换INDIRECT缓冲区,定位指令也很方便。 */ -template<> -int Comparator::compare(const hgl::graph::RenderNode &obj_one,const hgl::graph::RenderNode &obj_two) const +VK_NAMESPACE_BEGIN +const int RenderNode::compare(const RenderNode &other)const { hgl::int64 off; - hgl::graph::Renderable *ri_one=obj_one.scene_node->GetRenderable(); - hgl::graph::Renderable *ri_two=obj_two.scene_node->GetRenderable(); + hgl::graph::Renderable *ri_one=other.scene_node->GetRenderable(); + hgl::graph::Renderable *ri_two=scene_node->GetRenderable(); auto *prim_one=ri_one->GetPrimitive(); auto *prim_two=ri_two->GetPrimitive(); @@ -63,8 +63,8 @@ int Comparator::compare(const hgl::graph::RenderNode &ob //比较距离。。。。。。。。。。。。。。。。。。。。。还不知道这个是正了还是反了,等测出来确认后修改下面的返回值和这里的注释 - float foff=obj_one.to_camera_distance - -obj_two.to_camera_distance; + float foff=other.to_camera_distance + -to_camera_distance; if(foff>0) return 1; @@ -72,7 +72,6 @@ int Comparator::compare(const hgl::graph::RenderNode &ob return -1; } -VK_NAMESPACE_BEGIN MaterialRenderList::MaterialRenderList(GPUDevice *d,bool l2w,const RenderPipelineIndex &rpi) { device=d; @@ -280,8 +279,8 @@ void MaterialRenderList::Stat() { ro=rn->scene_node->GetRenderable(); - if(last_data_buffer->Comp(ro->GetDataBuffer())) - if(last_render_data->_Comp(ro->GetRenderData())==0) + if(*last_data_buffer!=*ro->GetDataBuffer()) + if(*last_render_data==*ro->GetRenderData()) { ++ri->instance_count; ++rn; @@ -399,7 +398,7 @@ void MaterialRenderList::ProcIndirectRender() void MaterialRenderList::Render(RenderItem *ri) { - if(!ri->pdb->Comp(last_data_buffer)) //换buf了 + if(*(ri->pdb)!=*last_data_buffer) //换buf了 { if(indirect_draw_count) //如果有间接绘制的数据,赶紧给画了 ProcIndirectRender(); diff --git a/src/SceneGraph/Vulkan/VKRenderable.cpp b/src/SceneGraph/Vulkan/VKRenderable.cpp index 24402039..0ed3831c 100644 --- a/src/SceneGraph/Vulkan/VKRenderable.cpp +++ b/src/SceneGraph/Vulkan/VKRenderable.cpp @@ -24,25 +24,29 @@ PrimitiveDataBuffer::~PrimitiveDataBuffer() delete[] vab_list; } -const bool PrimitiveDataBuffer::Comp(const PrimitiveDataBuffer *pdb)const +const int PrimitiveDataBuffer::compare(const PrimitiveDataBuffer &pdb)const { - if(!pdb)return(false); + ptrdiff_t off; - if(vdm&&pdb->vdm) - return (vdm==pdb->vdm); + off=&vdm-&pdb.vdm; + if(off) + return off; - if(vab_count!=pdb->vab_count)return(false); + off=vab_count-pdb.vab_count; + if(off) + return off; - for(uint32_t i=0;ivab_list[i])return(false); - if(vab_offset[i]!=pdb->vab_offset[i])return(false); - } + off=hgl_cmp(vab_list,pdb.vab_list,vab_count); + if(off) + return off; - if(ibo!=pdb->ibo) - return(false); + off=hgl_cmp(vab_offset,pdb.vab_offset,vab_count); + if(off) + return off; - return(true); + off=ibo-pdb.ibo; + + return off; } Renderable::Renderable(Primitive *r,MaterialInstance *mi,Pipeline *p,PrimitiveDataBuffer *pdb,PrimitiveRenderData *prd) @@ -61,7 +65,7 @@ Renderable *CreateRenderable(Primitive *prim,MaterialInstance *mi,Pipeline *p) const VIL *vil=mi->GetVIL(); - if(vil->Comp(p->GetVIL())) + if(*vil!=*p->GetVIL()) return(nullptr); const uint32_t input_count=vil->GetVertexAttribCount(VertexInputGroup::Basic); //不统计Bone/LocalToWorld组的