diff --git a/inc/hgl/graph/RenderList.h b/inc/hgl/graph/RenderList.h index eef2a2da..50f52f25 100644 --- a/inc/hgl/graph/RenderList.h +++ b/inc/hgl/graph/RenderList.h @@ -9,15 +9,44 @@ namespace hgl { namespace graph { + template struct GPUArray + { + List list; + GPUBuffer *buffer; + + public: + + GPUArray() + { + buffer=nullptr; + } + + ~GPUArray() + { + SAFE_CLEAR(buffer); + } + + void Clear() + { + list.ClearData(); + } + + void Add(const T &data) + { + list.Add(data); + } + };// + class RenderList { RenderCmdBuffer *cmd_buf; private: + GPUArray LocalToWorld; + List scene_node_list; - PushConstant * last_pc; Pipeline * last_pipeline; MaterialInstance * last_mat_inst; RenderableInstance *last_ri; @@ -27,19 +56,12 @@ namespace hgl public: - RenderList() - { - cmd_buf=nullptr; - last_pc=nullptr; - last_pipeline=nullptr; - last_mat_inst=nullptr; - last_ri=nullptr; - } - + RenderList(); ~RenderList()=default; - - void Add (SceneNode *node) {if(node)scene_node_list.Add(node);} - void Clear () {scene_node_list.ClearData();} + + void Begin (); + void Add (SceneNode *); + void End (); bool Render (RenderCmdBuffer *); };//class RenderList diff --git a/inc/hgl/graph/SceneNode.h b/inc/hgl/graph/SceneNode.h index 707cc978..4ef33a23 100644 --- a/inc/hgl/graph/SceneNode.h +++ b/inc/hgl/graph/SceneNode.h @@ -18,7 +18,7 @@ namespace hgl using FilterSceneNodeFunc=bool (*)(const SceneNode *,void *); ///<场景节点过滤函数重定义 - bool FrustumClipFilter(const SceneNode *,void *); ///<平截头截减过滤函数 + bool FrustumClipFilter(const SceneNode *,void *); ///<平截头截剪函数 /** * 场景节点数据类
@@ -40,7 +40,7 @@ namespace hgl ObjectList SubNode; ///<子节点 - List renderable_instances; ///<可渲染实例 + List renderable_instances; ///<可渲染实例 public: @@ -74,7 +74,7 @@ namespace hgl void Add(SceneNode *n){if(n)SubNode.Add(n);} ///<增加一个子节点 void ClearSubNode(){SubNode.ClearData();} ///<清除子节点 - void Add(RenderableInstance *ri){if(ri)renderable_instances.Add(ri);} ///<增加渲染实例 + void Add(RenderableInstance *ri){if(ri)renderable_instances.Add(ri);} ///<增加渲染实例 void Add(RenderableInstance *ri,const Matrix4f &mat) { diff --git a/inc/hgl/graph/SceneOrient.h b/inc/hgl/graph/SceneOrient.h index 033a1c77..50a7b04b 100644 --- a/inc/hgl/graph/SceneOrient.h +++ b/inc/hgl/graph/SceneOrient.h @@ -24,15 +24,11 @@ namespace hgl Matrix4f InverseLocalMatrix; ///<反向当前矩阵 Matrix4f InverseLocalToWorldMatrix; ///<反向当前到世界矩阵 - PushConstant pc; - public: SceneOrient(); virtual ~SceneOrient()=default; - PushConstant *GetPushConstant(){return &pc;} - Matrix4f & SetLocalMatrix (const Matrix4f &); ///<设定当前节点矩阵 Matrix4f & SetLocalToWorldMatrix (const Matrix4f &); ///<设定当前节点到世界矩阵 @@ -42,7 +38,9 @@ namespace hgl const Matrix4f & GetInverseLocalMatrix ()const {return InverseLocalMatrix;} const Matrix4f & GetInverseLocalToWorldMatrix()const {return InverseLocalToWorldMatrix;} - void RefreshLocalToWorldMatrix (const Matrix4f *); ///<刷新到世界空间矩阵 + public: + + virtual void RefreshLocalToWorldMatrix (const Matrix4f *); ///<刷新到世界空间矩阵 };//class SceneOrient }//namespace graph }//namespace hgl diff --git a/src/SceneGraph/RenderList.cpp b/src/SceneGraph/RenderList.cpp index 5f15c699..effcb760 100644 --- a/src/SceneGraph/RenderList.cpp +++ b/src/SceneGraph/RenderList.cpp @@ -27,6 +27,38 @@ namespace hgl // return (((Frustum *)fc)->BoxIn(node->GetWorldBoundingBox())!=Frustum::OUTSIDE); //} + RenderList::RenderList() + { + cmd_buf =nullptr; + + last_pipeline =nullptr; + last_mat_inst =nullptr; + last_ri =nullptr; + } + + void RenderList::Begin() + { + LocalToWorld.Clear(); + scene_node_list.ClearData(); + + last_pipeline =nullptr; + last_mat_inst =nullptr; + last_ri =nullptr; + } + + void RenderList::Add(SceneNode *node) + { + if(!node)return; + + LocalToWorld.Add(node->GetLocalToWorldMatrix()); + + scene_node_list.Add(node); + } + + void RenderList::End() + { + } + void RenderList::Render(SceneNode *node,RenderableInstance *ri) { if(last_pipeline!=ri->GetPipeline()) @@ -45,13 +77,6 @@ namespace hgl cmd_buf->BindDescriptorSets(last_mat_inst->GetDescriptorSets()); } - if(last_pc!=node->GetPushConstant()) - { - last_pc=node->GetPushConstant(); - - cmd_buf->PushConstants(last_pc,sizeof(PushConstant)); - } - //更新fin_mvp if(ri!=last_ri) @@ -95,7 +120,6 @@ namespace hgl last_pipeline=nullptr; last_mat_inst=nullptr; last_ri=nullptr; - last_pc=nullptr; const int count=scene_node_list.GetCount(); SceneNode **node=scene_node_list.GetData(); diff --git a/src/SceneGraph/SceneOrient.cpp b/src/SceneGraph/SceneOrient.cpp index 4cc3d302..98047ce1 100644 --- a/src/SceneGraph/SceneOrient.cpp +++ b/src/SceneGraph/SceneOrient.cpp @@ -7,7 +7,6 @@ namespace hgl SceneOrient::SceneOrient() { - pc.local_to_world =Matrix4f::identity; LocalMatrix =Matrix4f::identity; LocalToWorldMatrix =Matrix4f::identity; InverseLocalMatrix =Matrix4f::identity; @@ -29,9 +28,6 @@ namespace hgl InverseLocalToWorldMatrix=inverse(LocalToWorldMatrix); - pc.local_to_world =LocalToWorldMatrix; - pc.normal =InverseLocalToWorldMatrix.Transposed(); - return LocalToWorldMatrix; }