prepare refactor SceneTreeToRenderList

This commit is contained in:
hyzboy 2021-05-31 19:10:17 +08:00
parent da15630ac9
commit 9e7698cf0c
5 changed files with 48 additions and 57 deletions

View File

@ -4,6 +4,7 @@
#include"VulkanAppFramework.h" #include"VulkanAppFramework.h"
#include<hgl/math/Math.h> #include<hgl/math/Math.h>
#include<hgl/filesystem/FileSystem.h> #include<hgl/filesystem/FileSystem.h>
#include<hgl/graph/SceneTreeToRenderList.h>
using namespace hgl; using namespace hgl;
using namespace hgl::graph; using namespace hgl::graph;
@ -85,9 +86,17 @@ private:
render_instance=db->CreateRenderableInstance(render_obj,material_instance,pipeline); render_instance=db->CreateRenderableInstance(render_obj,material_instance,pipeline);
render_root.Add(render_instance,scale(0.5,0.5)); {
SceneNode *sn=render_root.CreateSubNode(scale(0.5,0.5));
sn->RIList.Add(render_instance);
}
render_root.RefreshMatrix(); render_root.RefreshMatrix();
render_root.ExpendToList(&render_list);
SceneTreeToRenderList st2rl(device);
st2rl.Expend(&render_list,&render_root,&cam);
return(true); return(true);
} }

View File

@ -29,19 +29,14 @@ namespace hgl
ObjectList<SceneNode> SubNode; ///<子节点 ObjectList<SceneNode> SubNode; ///<子节点
RenderableInstance *renderable_instances; ///<可渲染实例 List<RenderableInstance *> RIList; ///<可渲染实例
public: public:
SceneNode() SceneNode()=default;
{ SceneNode(const Matrix4f &mat)
renderable_instances=nullptr;
}
SceneNode(const Matrix4f &mat,RenderableInstance *ri=nullptr)
{ {
SetLocalMatrix(mat); SetLocalMatrix(mat);
renderable_instances=ri;
} }
virtual ~SceneNode() virtual ~SceneNode()
@ -68,15 +63,6 @@ namespace hgl
void AddSubNode(SceneNode *n){if(n)SubNode.Add(n);} ///<增加一个子节点 void AddSubNode(SceneNode *n){if(n)SubNode.Add(n);} ///<增加一个子节点
void ClearSubNode(){SubNode.ClearData();} ///<清除子节点 void ClearSubNode(){SubNode.ClearData();} ///<清除子节点
void Set(RenderableInstance *ri){renderable_instances=ri;} ///<增加渲染实例
void Set(const Matrix4f &mat,RenderableInstance *ri)
{
SetLocalMatrix(mat);
renderable_instances=ri;
}
public: //坐标相关方法 public: //坐标相关方法
virtual void SetBoundingBox (const AABB &bb){BoundingBox=bb;} ///<设置绑定盒 virtual void SetBoundingBox (const AABB &bb){BoundingBox=bb;} ///<设置绑定盒

View File

@ -43,7 +43,7 @@ namespace hgl
virtual float CameraLength(SceneNode *,SceneNode *); ///<摄像机距离比较函数 virtual float CameraLength(SceneNode *,SceneNode *); ///<摄像机距离比较函数
virtual bool InFrustum(const SceneNode *,void *); ///<平截头截剪函数 // virtual bool InFrustum(const SceneNode *,void *); ///<平截头截剪函数
virtual bool Begin(); virtual bool Begin();
virtual bool Expend(SceneNode *); virtual bool Expend(SceneNode *);

View File

@ -152,14 +152,8 @@ namespace hgl
last_pipeline=nullptr; last_pipeline=nullptr;
last_ri=nullptr; last_ri=nullptr;
const int count=scene_node_list.GetCount(); for(SceneNode *sn:scene_node_list)
SceneNode **node=scene_node_list.GetData(); Render(sn,sn->RIList);
for(int i=0;i<count;i++)
{
Render(*node,(*node)->renderable_instances);
++node;
}
return(true); return(true);
} }

View File

@ -27,25 +27,25 @@ namespace hgl
length_squared(obj_two->GetCenter(),camera_info.pos)); length_squared(obj_two->GetCenter(),camera_info.pos));
} }
bool SceneTreeToRenderList::InFrustum(const SceneNode *,void *) //bool SceneTreeToRenderList::InFrustum(const SceneNode *,void *)
{
return(true);
}
//bool SceneTreeToRenderList::Begin()
//{ //{
// if(!scene_node_list)
// scene_node_list=new SceneNodeList;
// scene_node_list->ClearData();
// pipeline_sets.ClearData();
// material_sets.ClearData();
// mat_instance_sets.ClearData();
// return(true); // return(true);
//} //}
bool SceneTreeToRenderList::Begin()
{
if(!scene_node_list)
scene_node_list=new SceneNodeList;
scene_node_list->ClearData();
pipeline_sets.ClearData();
material_sets.ClearData();
mat_inst_sets.ClearData();
return(true);
}
/** /**
* *
* *
@ -56,22 +56,22 @@ namespace hgl
* for(distance) * for(distance)
*/ */
//bool SceneTreeToRenderList::End() bool SceneTreeToRenderList::End()
//{ {
//} }
//bool SceneTreeToRenderList::Expend(SceneNode *sn) bool SceneTreeToRenderList::Expend(SceneNode *sn)
//{ {
// if(!sn)return(false); if(!sn)return(false);
// if(sn->renderable_instances) if(sn->RIList.GetCount()>0)
// scene_node_list->Add(sn); scene_node_list->Add(sn);
// for(SceneNode *sub:sn->SubNode) for(SceneNode *sub:sn->SubNode)
// Expend(sub); Expend(sub);
// return(true); return(true);
//} }
bool SceneTreeToRenderList::Expend(RenderList *rl,const CameraInfo &ci,SceneNode *sn) bool SceneTreeToRenderList::Expend(RenderList *rl,const CameraInfo &ci,SceneNode *sn)
{ {
@ -87,6 +87,8 @@ namespace hgl
Begin(); Begin();
Expend(sn); Expend(sn);
End(); End();
return(true);
} }
}//namespace graph }//namespace graph
}//namespace hgl }//namespace hgl