From 5718b1795fc76906e5e05c8cc3d312a0c0a50b09 Mon Sep 17 00:00:00 2001 From: "HuYingzhuo(hugo/hyzboy)" Date: Mon, 8 May 2023 18:18:34 +0800 Subject: [PATCH] supported material group at MaterialRenderList::Bind --- .../{RenderNode2D.cpp => RenderNode.cpp} | 57 ++++++++++++------- 1 file changed, 35 insertions(+), 22 deletions(-) rename src/SceneGraph/{RenderNode2D.cpp => RenderNode.cpp} (84%) diff --git a/src/SceneGraph/RenderNode2D.cpp b/src/SceneGraph/RenderNode.cpp similarity index 84% rename from src/SceneGraph/RenderNode2D.cpp rename to src/SceneGraph/RenderNode.cpp index d7c6df83..e0c2cd30 100644 --- a/src/SceneGraph/RenderNode2D.cpp +++ b/src/SceneGraph/RenderNode.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -17,7 +17,7 @@ */ template<> -int Comparator::compare(const hgl::graph::RenderNode2D &obj_one,const hgl::graph::RenderNode2D &obj_two) const +int Comparator::compare(const hgl::graph::RenderNode &obj_one,const hgl::graph::RenderNode &obj_two) const { int off; @@ -61,7 +61,7 @@ namespace hgl /* * 2D渲染节点额外提供的VBO数据 */ - struct RenderNode2DExtraBuffer + struct RenderNodeExtraBuffer { uint count; @@ -70,12 +70,12 @@ namespace hgl public: - RenderNode2DExtraBuffer() + RenderNodeExtraBuffer() { hgl_zero(*this); } - ~RenderNode2DExtraBuffer() + ~RenderNodeExtraBuffer() { Clear(); } @@ -101,9 +101,9 @@ namespace hgl } } - void WriteData(RenderNode2D *render_node,const uint count) + void WriteData(RenderNode *render_node,const uint count) { - RenderNode2D *rn; + RenderNode *rn; glm::vec4 *tp; for(uint col=0;col<4;col++) @@ -122,9 +122,9 @@ namespace hgl l2w_vbo[col]->Unmap(); } } - };//struct RenderNode2DExtraBuffer + };//struct RenderNodeExtraBuffer - MaterialRenderList2D::MaterialRenderList2D(GPUDevice *d,Material *m) + MaterialRenderList::MaterialRenderList(GPUDevice *d,Material *m) { device=d; cmd_buf=nullptr; @@ -138,7 +138,7 @@ namespace hgl buffer_offset=new VkDeviceSize[binding_count]; } - MaterialRenderList2D::~MaterialRenderList2D() + MaterialRenderList::~MaterialRenderList() { delete[] buffer_offset; delete[] buffer_list; @@ -146,9 +146,9 @@ namespace hgl SAFE_CLEAR(extra_buffer) } - void MaterialRenderList2D::Add(Renderable *ri,const Matrix4f &mat) + void MaterialRenderList::Add(Renderable *ri,const Matrix4f &mat) { - RenderNode2D rn; + RenderNode rn; rn.local_to_world=mat; rn.ri=ri; @@ -156,11 +156,11 @@ namespace hgl rn_list.Add(rn); } - void MaterialRenderList2D::End() + void MaterialRenderList::End() { //排序 { - Comparator rnc; + Comparator rnc; Sort(rn_list,&rnc); } @@ -172,7 +172,7 @@ namespace hgl if(count<=0)return; if(!extra_buffer) - extra_buffer=new RenderNode2DExtraBuffer; + extra_buffer=new RenderNodeExtraBuffer; if(extra_buffer->countAlloc(device,count); @@ -182,17 +182,17 @@ namespace hgl } } - void MaterialRenderList2D::RenderItem::Set(Renderable *ri) + void MaterialRenderList::RenderItem::Set(Renderable *ri) { pipeline =ri->GetPipeline(); mi =ri->GetMaterialInstance(); vid =ri->GetVertexInputData(); } - void MaterialRenderList2D::Stat() + void MaterialRenderList::Stat() { const uint count=rn_list.GetCount(); - RenderNode2D *rn=rn_list.GetData(); + RenderNode *rn=rn_list.GetData(); ri_list.ClearData(); ri_list.PreMalloc(count); @@ -237,11 +237,11 @@ namespace hgl } } - void MaterialRenderList2D::Bind(MaterialInstance *mi) + void MaterialRenderList::Bind(MaterialInstance *mi) { } - bool MaterialRenderList2D::Bind(const VertexInputData *vid,const uint first) + bool MaterialRenderList::Bind(const VertexInputData *vid,const uint first) { //binding号都是在VertexInput::CreateVIL时连续紧密排列生成的,所以bind时first_binding写0就行了。 @@ -260,6 +260,19 @@ namespace hgl count=vid->binding_count; } + if(countGetCount(VertexInputGroup::Material); + + if(mtl_binding_count>0) + { + if(mtl_binding_count!=1) //只有MaterialID + return(false); + + count+=mtl_binding_count; + } + } + if(countGetCount(VertexInputGroup::Bone); @@ -303,7 +316,7 @@ namespace hgl return(true); } - void MaterialRenderList2D::Render(RenderItem *ri) + void MaterialRenderList::Render(RenderItem *ri) { if(last_pipeline!=ri->pipeline) { @@ -344,7 +357,7 @@ namespace hgl } } - void MaterialRenderList2D::Render(RenderCmdBuffer *rcb) + void MaterialRenderList::Render(RenderCmdBuffer *rcb) { if(!rcb)return; const uint count=rn_list.GetCount();