ULRE/inc/hgl/graph/RenderNode2D.h

126 lines
2.9 KiB
C
Raw Normal View History

2023-03-23 21:43:10 +08:00
#ifndef HGL_GRAPH_RENDER_NODE_2D_INCLUDE
#define HGL_GRAPH_RENDER_NODE_2D_INCLUDE
2023-03-24 22:14:43 +08:00
#include<hgl/math/Math.h>
2023-04-25 18:08:26 +08:00
#include<hgl/type/Map.h>
#include<hgl/graph/VK.h>
2023-03-23 21:43:10 +08:00
namespace hgl
{
namespace graph
{
class Renderable;
2023-04-25 18:08:26 +08:00
class Material;
class GPUDevice;
struct VertexInputData;
struct IndexBufferData;
2023-03-23 21:43:10 +08:00
struct RenderNode2D
{
Matrix4f local_to_world;
2023-03-23 21:43:10 +08:00
Renderable *ri;
};
2023-04-26 20:52:31 +08:00
using RenderNode2DList=List<RenderNode2D>;
2023-04-25 18:08:26 +08:00
struct RenderNode2DExtraBuffer;
2023-04-25 18:08:26 +08:00
/**
*
*/
2023-04-26 20:52:31 +08:00
class MaterialRenderList2D
2023-04-25 18:08:26 +08:00
{
GPUDevice *device;
RenderCmdBuffer *cmd_buf;
2023-04-25 18:08:26 +08:00
Material *mtl;
RenderNode2DList rn_list;
2023-04-26 20:52:31 +08:00
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 *);
2023-04-26 20:52:31 +08:00
public:
MaterialRenderList2D(GPUDevice *d,Material *m);
~MaterialRenderList2D();
2023-04-26 20:52:31 +08:00
void Add(Renderable *ri,const Matrix4f &mat);
2023-04-26 20:52:31 +08:00
void ClearData()
{
rn_list.ClearData();
}
void End();
void Render(RenderCmdBuffer *);
2023-04-25 18:08:26 +08:00
};
class MaterialRenderMap2D:public ObjectMap<Material *,MaterialRenderList2D>
{
public:
MaterialRenderMap2D()=default;
virtual ~MaterialRenderMap2D()=default;
2023-04-26 20:52:31 +08:00
void Begin()
{
for(auto *it:data_list)
it->value->ClearData();
}
void End()
2023-04-25 18:08:26 +08:00
{
for(auto *it:data_list)
2023-04-26 20:52:31 +08:00
it->value->End();
2023-04-25 18:08:26 +08:00
}
void Render(RenderCmdBuffer *rcb)
{
if(!rcb)return;
for(auto *it:data_list)
it->value->Render(rcb);
}
2023-04-25 18:08:26 +08:00
};
2023-03-23 21:43:10 +08:00
}//namespace graph
}//namespace hgl
#endif//HGL_GRAPH_RENDER_NODE_2D_INCLUDE