ULRE/inc/hgl/graph/VKRenderable.h

113 lines
3.8 KiB
C
Raw Normal View History

#ifndef HGL_GRAPH_RENDERABLE_INCLUDE
#define HGL_GRAPH_RENDERABLE_INCLUDE
2022-06-24 17:51:05 +08:00
#include<hgl/graph/VKPrimitive.h>
#include<hgl/graph/VKPipeline.h>
#include<hgl/graph/VKDescriptorSet.h>
2021-06-16 20:29:25 +08:00
#include<hgl/graph/VKMaterial.h>
#include<hgl/graph/VKMaterialParameters.h>
2021-06-16 20:29:25 +08:00
#include<hgl/graph/VKMaterialInstance.h>
#include<hgl/graph/VertexAttrib.h>
VK_NAMESPACE_BEGIN
2024-05-28 02:21:33 +08:00
/**
* <Br>
*
*/
struct PrimitiveDataBuffer
{
2024-05-27 01:42:10 +08:00
uint32_t vab_count;
VkBuffer * vab_list;
2024-05-28 02:21:33 +08:00
// 理论上讲每个VAB绑定时都是可以指定byte offsets的。但是随后Draw时又可以指定vertexOffset。
// 在我们支持的两种draw模式中一种是每个模型一批VAB所有VAB的offset都是0。
// 另一种是使用VDM为了批量渲染所有的VAB又必须对齐所以每个VAB单独指定offset也不可行。
// 所以干脆不支持VAB的offset只支持vertexOffset。
// uint32_t * vab_offset; //注意这里的offset是相对于vertex的代表第几个顶点不是字节偏移
// IndexBuffer 同理也不再支持buffer的offset
2024-05-27 01:42:10 +08:00
IndexBuffer * ibo;
public:
PrimitiveDataBuffer(const uint32_t,IndexBuffer *);
2024-05-28 02:21:33 +08:00
~PrimitiveDataBuffer();
const bool Comp(const PrimitiveDataBuffer *pdb)const;
2024-05-28 02:21:33 +08:00
};//struct PrimitiveDataBuffer
2024-05-28 02:21:33 +08:00
/**
* <Br>
*
*/
2024-05-27 01:42:10 +08:00
struct PrimitiveRenderData
{
//因为要VAB是流式访问所以我们这个结构会被用做排序依据
//也因此把vertex_offset放在最前面
2024-05-28 02:21:33 +08:00
int32_t vertex_offset; //注意这里的offset是相对于vertex的代表第几个顶点不是字节偏移
uint32_t first_index;
uint32_t vertex_count;
uint32_t index_count;
public:
PrimitiveRenderData(const uint32_t vc,const uint32_t ic,const int32_t vo=0,const uint32_t fi=0)
{
vertex_count =vc;
index_count =ic;
vertex_offset =vo;
first_index =fi;
}
CompOperatorMemcmp(const PrimitiveRenderData &);
CompOperatorMemcmpPointer(PrimitiveRenderData);
};
/**
* <br>
*/
class Renderable ///可渲染对象实例
{
Pipeline * pipeline;
2021-06-16 20:29:25 +08:00
MaterialInstance * mat_inst;
2022-06-24 18:00:22 +08:00
Primitive * primitive;
2024-05-28 02:21:33 +08:00
PrimitiveDataBuffer * primitive_data_buffer;
PrimitiveRenderData * primitive_render_data;
private:
friend Renderable *CreateRenderable(Primitive *,MaterialInstance *,Pipeline *);
2024-05-28 02:21:33 +08:00
Renderable(Primitive *,MaterialInstance *,Pipeline *,PrimitiveDataBuffer *,PrimitiveRenderData *);
public:
virtual ~Renderable()
{
//需要在这里添加删除pipeline/desc_sets/primitive引用计数的代码
2024-05-28 02:21:33 +08:00
SAFE_CLEAR(primitive_data_buffer);
2024-05-27 01:42:10 +08:00
SAFE_CLEAR(primitive_render_data);
}
void UpdatePipeline (Pipeline *p){pipeline=p;}
Pipeline * GetPipeline (){return pipeline;}
2021-06-16 20:29:25 +08:00
VkPipelineLayout GetPipelineLayout (){return mat_inst->GetMaterial()->GetPipelineLayout();}
Material * GetMaterial (){return mat_inst->GetMaterial();}
2021-06-16 20:29:25 +08:00
MaterialInstance * GetMaterialInstance (){return mat_inst;}
2022-06-24 18:00:22 +08:00
Primitive * GetPrimitive (){return primitive;}
const AABB & GetBoundingBox ()const{return primitive->GetBoundingBox();}
const PrimitiveDataBuffer *GetRenderBuffer ()const{return primitive_data_buffer;}
const PrimitiveRenderData *GetRenderData ()const{return primitive_render_data;}
};//class Renderable
Renderable *CreateRenderable(Primitive *,MaterialInstance *,Pipeline *);
VK_NAMESPACE_END
#endif//HGL_GRAPH_RENDERABLE_INCLUDE