ULRE/inc/hgl/graph/VKRenderResource.h

121 lines
6.3 KiB
C
Raw Normal View History

2020-09-02 18:16:15 +08:00
#ifndef HGL_GRAPH_VULKAN_DATABASE_INCLUDE
#define HGL_GRAPH_VULKAN_DATABASE_INCLUDE
#include<hgl/graph/VKMaterial.h>
#include<hgl/graph/VKPipeline.h>
#include<hgl/graph/VKDescriptorSet.h>
2022-06-24 17:51:05 +08:00
#include<hgl/graph/VKPrimitive.h>
#include<hgl/graph/VKBuffer.h>
#include<hgl/graph/VKSampler.h>
#include<hgl/graph/VKTexture.h>
#include<hgl/graph/VKMaterialParameters.h>
2021-06-16 20:29:25 +08:00
#include<hgl/graph/VKMaterialInstance.h>
2020-09-02 18:16:15 +08:00
#include<hgl/graph/VertexAttribData.h>
#include<hgl/graph/VKRenderable.h>
2022-06-24 17:51:05 +08:00
#include<hgl/graph/font/TextPrimitive.h>
2020-09-02 18:16:15 +08:00
#include<hgl/type/ResManage.h>
VK_NAMESPACE_BEGIN
using MaterialID =int;
using MaterialInstanceID =int;
using BufferID =int;
using DescriptorSetID =int;
2022-06-24 17:51:05 +08:00
using PrimitiveID =int;
using RenderableID =int;
2020-09-02 18:16:15 +08:00
using SamplerID =int;
using TextureID =int;
class VertexAttribData;
/**
2020-09-02 18:18:57 +08:00
*
2020-09-02 18:16:15 +08:00
*/
2020-10-21 12:39:22 +08:00
class RenderResource
2020-09-02 18:16:15 +08:00
{
2020-10-21 12:39:22 +08:00
GPUDevice *device;
ObjectMap<OSString,ShaderModule> shader_module_by_name;
Map<OSString,Material *> material_by_name;
Map<OSString,Texture *> texture_by_name;
2020-09-02 18:16:15 +08:00
IDResManage<MaterialID, Material> rm_material; ///<材质合集
2021-06-16 20:29:25 +08:00
IDResManage<MaterialInstanceID, MaterialInstance> rm_material_instance; ///<材质实例合集
2023-02-23 19:01:01 +08:00
IDResManage<DescriptorSetID, DescriptorSet> rm_desc_sets; ///<描述符合集
2022-06-24 17:51:05 +08:00
IDResManage<PrimitiveID, Primitive> rm_primitives; ///<图元合集
2023-02-23 19:01:01 +08:00
IDResManage<BufferID, DeviceBuffer> rm_buffers; ///<顶点缓冲区合集
2020-09-02 18:16:15 +08:00
IDResManage<SamplerID, Sampler> rm_samplers; ///<采样器合集
IDResManage<TextureID, Texture> rm_textures; ///<纹理合集
IDResManage<RenderableID, Renderable> rm_renderables; ///<渲染实例集合集
2020-09-02 18:16:15 +08:00
public:
2020-10-21 12:39:22 +08:00
RenderResource(GPUDevice *dev):device(dev){}
virtual ~RenderResource()=default;
2020-09-02 18:16:15 +08:00
public: //Add
MaterialID Add(Material * mtl ){return rm_material.Add(mtl);}
2021-06-16 20:29:25 +08:00
MaterialInstanceID Add(MaterialInstance * mi ){return rm_material_instance.Add(mi);}
DescriptorSetID Add(DescriptorSet * ds ){return rm_desc_sets.Add(ds);}
2022-06-24 17:51:05 +08:00
PrimitiveID Add(Primitive * p ){return rm_primitives.Add(p);}
BufferID Add(DeviceBuffer * buf ){return rm_buffers.Add(buf);}
2020-09-02 18:16:15 +08:00
SamplerID Add(Sampler * s ){return rm_samplers.Add(s);}
TextureID Add(Texture * t ){return rm_textures.Add(t);}
RenderableID Add(Renderable * r ){return rm_renderables.Add(r);}
2020-09-02 18:16:15 +08:00
public: // VBO/VAO
2020-09-02 18:16:15 +08:00
2021-11-29 15:58:48 +08:00
VBO *CreateVBO(VkFormat format,uint32_t count,const void *data,SharingMode sm=SharingMode::Exclusive);
VBO *CreateVBO(VkFormat format,uint32_t count,SharingMode sm=SharingMode::Exclusive){return CreateVBO(format,count,nullptr,sm);}
VBO *CreateVBO(const VAD *vad,SharingMode sm=SharingMode::Exclusive){return CreateVBO(vad->GetVulkanFormat(),vad->GetCount(),vad->GetData(),sm);}
2020-09-02 18:16:15 +08:00
#define SCENE_DB_CREATE_FUNC(name) DeviceBuffer *Create##name(VkDeviceSize size,void *data,SharingMode sm=SharingMode::Exclusive); \
DeviceBuffer *Create##name(VkDeviceSize size,SharingMode sm=SharingMode::Exclusive);
2020-09-02 18:16:15 +08:00
SCENE_DB_CREATE_FUNC(UBO)
SCENE_DB_CREATE_FUNC(SSBO)
SCENE_DB_CREATE_FUNC(INBO)
#undef SCENE_DB_CREATE_FUNC
2020-10-14 21:05:12 +08:00
IndexBuffer *CreateIBO(IndexType index_type,uint32_t count,const void * data, SharingMode sm=SharingMode::Exclusive);
IndexBuffer *CreateIBO16( uint32_t count,const uint16 *data, SharingMode sm=SharingMode::Exclusive){return CreateIBO(IndexType::U16,count,(void *)data,sm);}
IndexBuffer *CreateIBO32( uint32_t count,const uint32 *data, SharingMode sm=SharingMode::Exclusive){return CreateIBO(IndexType::U32,count,(void *)data,sm);}
2020-09-02 18:16:15 +08:00
IndexBuffer *CreateIBO(IndexType index_type,uint32_t count,SharingMode sm=SharingMode::Exclusive){return CreateIBO(index_type,count,nullptr,sm);}
2020-10-14 21:05:12 +08:00
IndexBuffer *CreateIBO16( uint32_t count,SharingMode sm=SharingMode::Exclusive){return CreateIBO(IndexType::U16,count,nullptr,sm);}
IndexBuffer *CreateIBO32( uint32_t count,SharingMode sm=SharingMode::Exclusive){return CreateIBO(IndexType::U32,count,nullptr,sm);}
2020-09-02 18:16:15 +08:00
public: //Material
const ShaderModule *CreateShaderModule(const OSString &filename,ShaderResource *shader_resource);
Material * CreateMaterial(const OSString &);
MaterialInstance * CreateMaterialInstance(Material *,const VILConfig *vil_cfg=nullptr);
MaterialInstance * CreateMaterialInstance(const OSString &,const VILConfig *vil_cfg=nullptr);
2022-06-24 17:51:05 +08:00
Primitive * CreatePrimitive(const uint32_t vertex_count=0);
2020-09-02 18:16:15 +08:00
Renderable * CreateRenderable(Primitive *r,MaterialInstance *mi,Pipeline *p);
2020-09-02 18:16:15 +08:00
Sampler * CreateSampler(VkSamplerCreateInfo *sci=nullptr);
Sampler * CreateSampler(Texture *);
2020-09-02 18:16:15 +08:00
public: //texture
2020-10-24 21:50:36 +08:00
Texture2D * LoadTexture2D(const OSString &,bool auto_mipmaps=false);
TextureCube * LoadTextureCube(const OSString &,bool auto_mipmaps=false);
2020-09-02 18:16:15 +08:00
public: //Get
Material * GetMaterial (const MaterialID &id){return rm_material.Get(id);}
2021-06-16 20:29:25 +08:00
MaterialInstance * GetMaterialInstance (const MaterialInstanceID &id){return rm_material_instance.Get(id);}
DescriptorSet * GetDescSets (const DescriptorSetID &id){return rm_desc_sets.Get(id);}
Primitive * GetPrimitive (const PrimitiveID &id){return rm_primitives.Get(id);}
DeviceBuffer * GetBuffer (const BufferID &id){return rm_buffers.Get(id);}
2020-09-02 18:16:15 +08:00
Sampler * GetSampler (const SamplerID &id){return rm_samplers.Get(id);}
Texture * GetTexture (const TextureID &id){return rm_textures.Get(id);}
Renderable * GetRenderable (const RenderableID &id){return rm_renderables.Get(id);}
2020-10-21 12:39:22 +08:00
};//class RenderResource
2020-09-02 18:16:15 +08:00
VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_DATABASE_INCLUDE