2023-09-05 20:48:47 +08:00
|
|
|
|
#pragma once
|
2023-06-01 15:08:45 +08:00
|
|
|
|
#include<hgl/graph/RenderNode.h>
|
2024-05-25 22:57:29 +08:00
|
|
|
|
#include<hgl/graph/VKVABList.h>
|
2024-05-30 13:14:13 +08:00
|
|
|
|
#include<hgl/graph/VKIndirectCommandBuffer.h>
|
2023-06-01 15:08:45 +08:00
|
|
|
|
|
|
|
|
|
VK_NAMESPACE_BEGIN
|
2024-05-25 17:58:39 +08:00
|
|
|
|
class RenderAssignBuffer;
|
2024-07-18 01:53:23 +08:00
|
|
|
|
class SceneNode;
|
2024-08-02 23:17:07 +08:00
|
|
|
|
struct CameraInfo;
|
2023-06-01 15:08:45 +08:00
|
|
|
|
|
2025-01-15 02:42:04 +08:00
|
|
|
|
struct RenderPipelineIndex:public Comparator<RenderPipelineIndex>
|
|
|
|
|
{
|
|
|
|
|
Material *material;
|
|
|
|
|
Pipeline *pipeline;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
const int compare(const RenderPipelineIndex &rli)const override
|
|
|
|
|
{
|
|
|
|
|
if(material<rli.material)return(-1);
|
|
|
|
|
if(material>rli.material)return(1);
|
|
|
|
|
|
|
|
|
|
if(pipeline<rli.pipeline)return(-1);
|
|
|
|
|
if(pipeline>rli.pipeline)return(1);
|
|
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
RenderPipelineIndex()
|
|
|
|
|
{
|
|
|
|
|
material=nullptr;
|
|
|
|
|
pipeline=nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RenderPipelineIndex(Material *m,Pipeline *p)
|
|
|
|
|
{
|
|
|
|
|
material=m;
|
|
|
|
|
pipeline=p;
|
|
|
|
|
}
|
|
|
|
|
};//struct RenderPipelineIndex
|
|
|
|
|
|
2023-06-01 15:08:45 +08:00
|
|
|
|
/**
|
2025-01-15 02:42:04 +08:00
|
|
|
|
* 同一材质与管线的渲染列表
|
2023-06-01 15:08:45 +08:00
|
|
|
|
*/
|
|
|
|
|
class MaterialRenderList
|
|
|
|
|
{
|
2025-05-17 20:26:36 +08:00
|
|
|
|
VulkanDevice *device;
|
2023-06-01 15:08:45 +08:00
|
|
|
|
RenderCmdBuffer *cmd_buf;
|
|
|
|
|
|
2025-01-15 02:42:04 +08:00
|
|
|
|
RenderPipelineIndex rp_index;
|
2023-06-01 15:08:45 +08:00
|
|
|
|
|
2024-08-02 23:17:07 +08:00
|
|
|
|
CameraInfo *camera_info;
|
|
|
|
|
|
2023-06-01 15:08:45 +08:00
|
|
|
|
RenderNodeList rn_list;
|
|
|
|
|
|
2024-08-04 22:35:31 +08:00
|
|
|
|
RenderNodePointerList rn_update_l2w_list;
|
|
|
|
|
|
2023-06-01 15:08:45 +08:00
|
|
|
|
private:
|
|
|
|
|
|
2024-05-25 17:58:39 +08:00
|
|
|
|
RenderAssignBuffer *assign_buffer;
|
2023-06-01 15:08:45 +08:00
|
|
|
|
|
|
|
|
|
struct RenderItem
|
|
|
|
|
{
|
2024-05-30 13:39:16 +08:00
|
|
|
|
uint32_t first_instance; ///<第一个绘制实例(和instance渲染无关,对应InstanceRate的VAB)
|
2024-05-28 23:10:50 +08:00
|
|
|
|
uint32_t instance_count;
|
2023-06-01 15:08:45 +08:00
|
|
|
|
|
2024-05-27 01:42:10 +08:00
|
|
|
|
MaterialInstance * mi;
|
2024-05-28 23:49:28 +08:00
|
|
|
|
|
2025-05-18 02:07:10 +08:00
|
|
|
|
const MeshDataBuffer * pdb;
|
|
|
|
|
const MeshRenderData * prd;
|
2023-06-01 15:08:45 +08:00
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
2025-05-18 02:03:16 +08:00
|
|
|
|
void Set(Mesh *);
|
2023-06-01 15:08:45 +08:00
|
|
|
|
};
|
|
|
|
|
|
2024-05-30 13:14:13 +08:00
|
|
|
|
IndirectDrawBuffer *icb_draw;
|
|
|
|
|
IndirectDrawIndexedBuffer *icb_draw_indexed;
|
|
|
|
|
|
|
|
|
|
void ReallocICB();
|
2024-05-30 13:39:16 +08:00
|
|
|
|
void WriteICB(VkDrawIndirectCommand *,RenderItem *ri);
|
|
|
|
|
void WriteICB(VkDrawIndexedIndirectCommand *,RenderItem *ri);
|
2024-05-30 01:14:27 +08:00
|
|
|
|
|
2023-09-05 10:28:03 +08:00
|
|
|
|
DataArray<RenderItem> ri_array;
|
2023-06-01 15:08:45 +08:00
|
|
|
|
uint ri_count;
|
|
|
|
|
|
|
|
|
|
void Stat();
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
2024-05-28 23:10:50 +08:00
|
|
|
|
VABList * vab_list;
|
2023-06-01 15:08:45 +08:00
|
|
|
|
|
2025-05-18 22:56:38 +08:00
|
|
|
|
const MeshDataBuffer * last_data_buffer;
|
2024-05-30 01:14:27 +08:00
|
|
|
|
const VDM * last_vdm;
|
2025-05-18 22:56:38 +08:00
|
|
|
|
const MeshRenderData * last_render_data;
|
2023-06-01 15:08:45 +08:00
|
|
|
|
|
2025-05-18 22:56:38 +08:00
|
|
|
|
int first_indirect_draw_index;
|
|
|
|
|
uint indirect_draw_count;
|
2024-05-30 13:39:16 +08:00
|
|
|
|
|
2025-05-18 02:07:10 +08:00
|
|
|
|
bool BindVAB(const MeshDataBuffer *,const uint);
|
2023-06-01 15:08:45 +08:00
|
|
|
|
|
2024-05-30 13:39:16 +08:00
|
|
|
|
void ProcIndirectRender();
|
2023-06-01 15:08:45 +08:00
|
|
|
|
void Render(RenderItem *);
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
2025-05-17 20:26:36 +08:00
|
|
|
|
MaterialRenderList(VulkanDevice *d,bool l2w,const RenderPipelineIndex &rpi);
|
2023-06-01 15:08:45 +08:00
|
|
|
|
~MaterialRenderList();
|
|
|
|
|
|
2024-07-18 01:53:23 +08:00
|
|
|
|
void Add(SceneNode *);
|
2023-06-01 15:08:45 +08:00
|
|
|
|
|
2025-01-15 02:42:04 +08:00
|
|
|
|
void SetCameraInfo(CameraInfo *ci){camera_info=ci;}
|
2024-08-02 23:17:07 +08:00
|
|
|
|
|
2025-01-15 02:42:04 +08:00
|
|
|
|
void Clear(){rn_list.Clear();}
|
2023-06-01 15:08:45 +08:00
|
|
|
|
|
|
|
|
|
void End();
|
|
|
|
|
|
|
|
|
|
void Render(RenderCmdBuffer *);
|
2024-08-04 22:35:31 +08:00
|
|
|
|
|
2024-08-27 01:27:53 +08:00
|
|
|
|
void UpdateLocalToWorld(); //刷新所有对象的LocalToWorld矩阵
|
2024-08-30 03:36:01 +08:00
|
|
|
|
void UpdateMaterialInstance(SceneNode *);
|
2023-06-01 15:08:45 +08:00
|
|
|
|
};//class MaterialRenderList
|
|
|
|
|
VK_NAMESPACE_END
|