ULRE/inc/hgl/graph/RenderNode.h

128 lines
2.9 KiB
C
Raw Normal View History

#ifndef HGL_GRAPH_RENDER_NODE_INCLUDE
2021-06-10 18:56:23 +08:00
#define HGL_GRAPH_RENDER_NODE_INCLUDE
2023-05-07 01:07:26 +08:00
#include<hgl/math/Math.h>
#include<hgl/type/Map.h>
#include<hgl/type/SortedSets.h>
2023-05-07 01:07:26 +08:00
#include<hgl/graph/VK.h>
2021-06-10 18:56:23 +08:00
namespace hgl
{
namespace graph
{
class Renderable;
2023-05-07 01:07:26 +08:00
class Material;
class GPUDevice;
struct VertexInputData;
struct IndexBufferData;
2021-06-10 18:56:23 +08:00
2023-04-25 18:08:26 +08:00
struct RenderNode
{
2023-05-07 01:07:26 +08:00
Matrix4f local_to_world;
Renderable *ri;
2023-04-25 18:08:26 +08:00
};
2023-05-07 01:07:26 +08:00
using RenderNodeList=List<RenderNode>;
struct RenderNodeExtraBuffer;
2023-04-25 18:08:26 +08:00
2023-05-07 01:07:26 +08:00
/**
*
*/
class MaterialRenderList
2023-04-25 18:08:26 +08:00
{
2023-05-07 01:07:26 +08:00
GPUDevice *device;
RenderCmdBuffer *cmd_buf;
2023-04-25 18:08:26 +08:00
2023-05-07 01:07:26 +08:00
Material *mtl;
2023-04-25 18:08:26 +08:00
2023-05-07 01:07:26 +08:00
RenderNodeList rn_list;
2023-03-23 21:43:10 +08:00
2023-05-07 01:07:26 +08:00
private:
2023-05-07 01:07:26 +08:00
RenderNodeExtraBuffer *extra_buffer;
2021-06-10 18:56:23 +08:00
2023-05-07 01:07:26 +08:00
struct RenderItem
{
uint32_t first;
uint32_t count;
2023-03-23 21:43:10 +08:00
2023-05-07 01:07:26 +08:00
Pipeline * pipeline;
MaterialInstance * mi;
const VertexInputData * vid;
2021-06-10 18:56:23 +08:00
2023-05-07 01:07:26 +08:00
public:
2021-06-10 18:56:23 +08:00
2023-05-07 01:07:26 +08:00
void Set(Renderable *);
};
SortedSets<MaterialInstance *> mi_set;
2023-05-07 01:07:26 +08:00
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:
2023-05-07 01:07:26 +08:00
MaterialRenderList(GPUDevice *d,Material *m);
~MaterialRenderList();
2023-04-25 18:08:26 +08:00
2023-05-07 01:07:26 +08:00
void Add(Renderable *ri,const Matrix4f &mat);
2023-04-25 18:08:26 +08:00
2023-05-07 01:07:26 +08:00
void ClearData()
{
rn_list.ClearData();
}
void End();
void Render(RenderCmdBuffer *);
};
class MaterialRenderMap:public ObjectMap<Material *,MaterialRenderList>
{
public:
MaterialRenderMap()=default;
virtual ~MaterialRenderMap()=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
2021-06-10 18:56:23 +08:00
#endif//HGL_GRAPH_RENDER_NODE_INCLUDE