removed PushConstants at SceneNode/RenderList

This commit is contained in:
hyzboy 2020-11-26 17:51:59 +08:00
parent f57a7afb74
commit 4bd4a9b898
5 changed files with 73 additions and 33 deletions

View File

@ -9,15 +9,44 @@ namespace hgl
{
namespace graph
{
template<typename T> struct GPUArray
{
List<T> 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<Matrix4f> LocalToWorld;
List<SceneNode *> 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

View File

@ -18,7 +18,7 @@ namespace hgl
using FilterSceneNodeFunc=bool (*)(const SceneNode *,void *); ///<场景节点过滤函数重定义
bool FrustumClipFilter(const SceneNode *,void *); ///<平截头截减过滤函数
bool FrustumClipFilter(const SceneNode *,void *); ///<平截头截函数
/**
* <br>
@ -40,7 +40,7 @@ namespace hgl
ObjectList<SceneNode> SubNode; ///<子节点
List<RenderableInstance *> renderable_instances; ///<可渲染实例
List<RenderableInstance *> 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)
{

View File

@ -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

View File

@ -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();

View File

@ -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;
}