removed old RenderList

This commit is contained in:
2023-05-07 01:07:26 +08:00
parent 9781e6a9b3
commit 9535a4486e
11 changed files with 168 additions and 629 deletions

View File

@@ -2,69 +2,41 @@
#define HGL_GRAPH_RENDER_LIST_INCLUDE
#include<hgl/graph/VK.h>
#include<hgl/graph/Camera.h>
#include<hgl/graph/SceneNode.h>
#include<hgl/graph/RenderNode.h>
#include<hgl/graph/VKArrayBuffer.h>
#include<hgl/graph/SceneInfo.h>
#include<hgl/color/Color4f.h>
#include<hgl/graph/VKMaterial.h>
namespace hgl
{
namespace graph
{
/**
* 渲染对象列表<br>
* 已经展开的渲染对象列表最终创建RenderCommandBuffer
* 该类会长期保存使用过的材质信息避重新分配造成的时间和空间浪费。如需彻底清空列表请使用Clear()函数
*/
class RenderList
{
protected:
protected:
GPUDevice * device;
RenderCmdBuffer * cmd_buf;
private:
CameraInfo camera_info;
MaterialRenderMap mrl_map;
RenderNodeComparator *render_node_comparator;
private:
List<Renderable *> ri_list;
VkDescriptorSet ds_list[DESCRIPTOR_SET_TYPE_COUNT];
DescriptorSet *renderable_desc_sets;
uint32_t ubo_offset;
uint32_t ubo_align;
uint renderable_count; ///<可渲染对象数量
MaterialRenderMap mrl_map; ///<按材质分类的渲染列表
protected:
virtual bool Begin();
virtual bool Expend(SceneNode *);
virtual void End();
private:
Pipeline * last_pipeline;
MaterialParameters *last_mp[DESCRIPTOR_SET_TYPE_COUNT];
uint32_t last_vbo;
void Render(Renderable *);
virtual bool ExpendNode(SceneNode *);
public:
RenderList(GPUDevice *);
virtual ~RenderList();
virtual bool Expend(SceneNode *); ///<展开场景树到渲染列表
virtual bool Expend(const CameraInfo &,SceneNode *);
virtual bool Render(RenderCmdBuffer *); ///<渲染所有对象
virtual bool Render(RenderCmdBuffer *);
virtual void Clear(); ///<彻底清理
};//class RenderList
}//namespace graph
}//namespace hgl

View File

@@ -1,43 +0,0 @@
#ifndef HGL_GRAPH_RENDER_LIST_2D_INCLUDE
#define HGL_GRAPH_RENDER_LIST_2D_INCLUDE
#include<hgl/graph/VK.h>
#include<hgl/graph/SceneNode.h>
#include<hgl/graph/RenderNode2D.h>
#include<hgl/graph/VKArrayBuffer.h>
#include<hgl/graph/VKMaterial.h>
namespace hgl
{
namespace graph
{
/**
* 渲染对象列表<br>
* 该类会长期保存使用过的材质信息避重新分配造成的时间和空间浪费。如需彻底清空列表请使用Clear()函数
*/
class RenderList2D
{
protected:
GPUDevice * device;
uint renderable_count; ///<可渲染对象数量
MaterialRenderMap2D mrl_map; ///<按材质分类的渲染列表
protected:
virtual bool ExpendNode(SceneNode *);
public:
RenderList2D(GPUDevice *);
virtual ~RenderList2D();
virtual bool Expend(SceneNode *); ///<展开场景树到渲染列表
virtual bool Render(RenderCmdBuffer *); ///<渲染所有对象
virtual void Clear(); ///<彻底清理
};//class RenderList2D
}//namespace graph
}//namespace hgl
#endif//HGL_GRAPH_RENDER_LIST_2D_INCLUDE

View File

@@ -1,53 +1,125 @@
#ifndef HGL_GRAPH_RENDER_NODE_INCLUDE
#define HGL_GRAPH_RENDER_NODE_INCLUDE
#include<hgl/math/Vector.h>
#include<hgl/type/List.h>
#include<hgl/graph/SceneInfo.h>
#include<hgl/math/Math.h>
#include<hgl/type/Map.h>
#include<hgl/graph/VK.h>
namespace hgl
{
namespace graph
{
class Renderable;
class Material;
class GPUDevice;
struct VertexInputData;
struct IndexBufferData;
struct RenderNode
{
Renderable *render_obj;
Matrix4f local_to_world;
Renderable *ri;
};
using RenderNodeList=List<RenderNode *>;
using RenderNodeList=List<RenderNode>;
struct RenderNode2D:public RenderNode
struct RenderNodeExtraBuffer;
/**
* 同一材质的对象渲染列表
*/
class MaterialRenderList
{
Matrix3x4f local_to_world;
GPUDevice *device;
RenderCmdBuffer *cmd_buf;
Material *mtl;
RenderNodeList rn_list;
private:
RenderNodeExtraBuffer *extra_buffer;
struct RenderItem
{
uint32_t first;
uint32_t count;
Pipeline * pipeline;
MaterialInstance * mi;
const VertexInputData * vid;
public:
void Set(Renderable *);
};
List<RenderItem> ri_list;
uint ri_count;
void Stat();
protected:
uint32_t binding_count;
VkBuffer *buffer_list;
VkDeviceSize *buffer_offset;
MaterialInstance * last_mi;
Pipeline * last_pipeline;
const VertexInputData * last_vid;
uint last_index;
void Bind(MaterialInstance *);
bool Bind(const VertexInputData *,const uint);
void Render(RenderItem *);
public:
MaterialRenderList(GPUDevice *d,Material *m);
~MaterialRenderList();
void Add(Renderable *ri,const Matrix4f &mat);
void ClearData()
{
rn_list.ClearData();
}
void End();
void Render(RenderCmdBuffer *);
};
using RenderNode2DList=List<RenderNode2D *>;
constexpr double RenderNode3DDistanceFactor=100.0;
struct RenderNode3D:public RenderNode
class MaterialRenderMap:public ObjectMap<Material *,MaterialRenderList>
{
MVPMatrix matrix;
public:
Vector3f WorldCenter;
MaterialRenderMap()=default;
virtual ~MaterialRenderMap()=default;
double distance_to_camera_square;
void Begin()
{
for(auto *it:data_list)
it->value->ClearData();
}
double distance_to_camera;
void End()
{
for(auto *it:data_list)
it->value->End();
}
};//struct RenderNode
void Render(RenderCmdBuffer *rcb)
{
if(!rcb)return;
using RenderNode3DList=List<RenderNode3D *>;
for(auto *it:data_list)
it->value->Render(rcb);
}
};
}//namespace graph
}//namespace hgl
using RenderNodePointer=hgl::graph::RenderNode *;
using RenderNodeComparator=Comparator<RenderNodePointer>;
using RenderNode2DPointer=hgl::graph::RenderNode2D *;
using RenderNode2DComparator=Comparator<RenderNode2DPointer>;
using RenderNode3DPointer=hgl::graph::RenderNode3D *;
using RenderNode3DComparator=Comparator<RenderNode3DPointer>;
#endif//HGL_GRAPH_RENDER_NODE_INCLUDE

View File

@@ -1,125 +0,0 @@
#ifndef HGL_GRAPH_RENDER_NODE_2D_INCLUDE
#define HGL_GRAPH_RENDER_NODE_2D_INCLUDE
#include<hgl/math/Math.h>
#include<hgl/type/Map.h>
#include<hgl/graph/VK.h>
namespace hgl
{
namespace graph
{
class Renderable;
class Material;
class GPUDevice;
struct VertexInputData;
struct IndexBufferData;
struct RenderNode2D
{
Matrix4f local_to_world;
Renderable *ri;
};
using RenderNode2DList=List<RenderNode2D>;
struct RenderNode2DExtraBuffer;
/**
* 同一材质的对象渲染列表
*/
class MaterialRenderList2D
{
GPUDevice *device;
RenderCmdBuffer *cmd_buf;
Material *mtl;
RenderNode2DList rn_list;
private:
RenderNode2DExtraBuffer *extra_buffer;
struct RenderItem
{
uint32_t first;
uint32_t count;
Pipeline * pipeline;
MaterialInstance * mi;
const VertexInputData * vid;
public:
void Set(Renderable *);
};
List<RenderItem> ri_list;
uint ri_count;
void Stat();
protected:
uint32_t binding_count;
VkBuffer *buffer_list;
VkDeviceSize *buffer_offset;
MaterialInstance * last_mi;
Pipeline * last_pipeline;
const VertexInputData * last_vid;
uint last_index;
void Bind(MaterialInstance *);
bool Bind(const VertexInputData *,const uint);
void Render(RenderItem *);
public:
MaterialRenderList2D(GPUDevice *d,Material *m);
~MaterialRenderList2D();
void Add(Renderable *ri,const Matrix4f &mat);
void ClearData()
{
rn_list.ClearData();
}
void End();
void Render(RenderCmdBuffer *);
};
class MaterialRenderMap2D:public ObjectMap<Material *,MaterialRenderList2D>
{
public:
MaterialRenderMap2D()=default;
virtual ~MaterialRenderMap2D()=default;
void Begin()
{
for(auto *it:data_list)
it->value->ClearData();
}
void End()
{
for(auto *it:data_list)
it->value->End();
}
void Render(RenderCmdBuffer *rcb)
{
if(!rcb)return;
for(auto *it:data_list)
it->value->Render(rcb);
}
};
}//namespace graph
}//namespace hgl
#endif//HGL_GRAPH_RENDER_NODE_2D_INCLUDE