2020-09-02 18:16:15 +08:00
|
|
|
|
#ifndef HGL_GRAPH_VULKAN_DATABASE_INCLUDE
|
|
|
|
|
#define HGL_GRAPH_VULKAN_DATABASE_INCLUDE
|
|
|
|
|
|
2020-10-21 11:43:18 +08:00
|
|
|
|
#include<hgl/graph/VKMaterial.h>
|
|
|
|
|
#include<hgl/graph/VKPipeline.h>
|
|
|
|
|
#include<hgl/graph/VKDescriptorSets.h>
|
|
|
|
|
#include<hgl/graph/VKRenderable.h>
|
|
|
|
|
#include<hgl/graph/VKBuffer.h>
|
|
|
|
|
#include<hgl/graph/VKSampler.h>
|
|
|
|
|
#include<hgl/graph/VKTexture.h>
|
|
|
|
|
#include<hgl/graph/VKMaterialInstance.h>
|
2020-09-02 18:16:15 +08:00
|
|
|
|
#include<hgl/graph/VertexAttribData.h>
|
2020-10-21 11:43:18 +08:00
|
|
|
|
#include<hgl/graph/VKRenderableInstance.h>
|
2020-09-02 18:16:15 +08:00
|
|
|
|
#include<hgl/graph/font/TextRenderable.h>
|
|
|
|
|
#include<hgl/type/ResManage.h>
|
|
|
|
|
VK_NAMESPACE_BEGIN
|
|
|
|
|
using MaterialID =int;
|
|
|
|
|
using MaterialInstanceID =int;
|
|
|
|
|
using BufferID =int;
|
|
|
|
|
using DescriptorSetsID =int;
|
|
|
|
|
using RenderableID =int;
|
|
|
|
|
using RenderableInstanceID =int;
|
|
|
|
|
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;
|
2020-09-19 23:49:32 +08:00
|
|
|
|
|
|
|
|
|
MapObject<OSString,ShaderModule> shader_module_by_name;
|
|
|
|
|
Map<OSString,Material *> material_by_name;
|
2020-10-22 12:22:10 +08:00
|
|
|
|
Map<OSString,Texture *> texture_by_name;
|
2020-09-19 23:49:32 +08:00
|
|
|
|
|
2020-09-02 18:16:15 +08:00
|
|
|
|
IDResManage<MaterialID, Material> rm_material; ///<材质合集
|
2021-06-16 10:41:04 +08:00
|
|
|
|
IDResManage<MaterialInstanceID, MaterialParameters> rm_material_instance; ///<材质实例合集
|
2020-09-02 18:16:15 +08:00
|
|
|
|
IDResManage<DescriptorSetsID, DescriptorSets> rm_desc_sets; ///<描述符合集
|
|
|
|
|
IDResManage<RenderableID, Renderable> rm_renderables; ///<可渲染对象合集
|
2020-10-21 12:39:22 +08:00
|
|
|
|
IDResManage<BufferID, GPUBuffer> rm_buffers; ///<顶点缓冲区合集
|
2020-09-02 18:16:15 +08:00
|
|
|
|
IDResManage<SamplerID, Sampler> rm_samplers; ///<采样器合集
|
|
|
|
|
IDResManage<TextureID, Texture> rm_textures; ///<纹理合集
|
|
|
|
|
IDResManage<RenderableInstanceID, RenderableInstance> rm_renderable_instances; ///<渲染实例集合集
|
|
|
|
|
|
|
|
|
|
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 10:41:04 +08:00
|
|
|
|
MaterialInstanceID Add(MaterialParameters * mi ){return rm_material_instance.Add(mi);}
|
2020-09-02 18:16:15 +08:00
|
|
|
|
DescriptorSetsID Add(DescriptorSets * ds ){return rm_desc_sets.Add(ds);}
|
|
|
|
|
RenderableID Add(Renderable * r ){return rm_renderables.Add(r);}
|
2020-10-22 12:22:10 +08:00
|
|
|
|
BufferID Add(GPUBuffer * 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);}
|
|
|
|
|
RenderableInstanceID Add(RenderableInstance *ri ){return rm_renderable_instances.Add(ri);}
|
|
|
|
|
|
2020-09-19 23:49:32 +08:00
|
|
|
|
public: // VBO/VAO
|
2020-09-02 18:16:15 +08:00
|
|
|
|
|
2020-09-02 18:36:24 +08:00
|
|
|
|
VAB *CreateVAB(VkFormat format,uint32_t count,const void *data,SharingMode sm=SharingMode::Exclusive);
|
|
|
|
|
VAB *CreateVAB(VkFormat format,uint32_t count,SharingMode sm=SharingMode::Exclusive){return CreateVAB(format,count,nullptr,sm);}
|
|
|
|
|
VAB *CreateVAB(const VAD *vad,SharingMode sm=SharingMode::Exclusive){return CreateVAB(vad->GetVulkanFormat(),vad->GetCount(),vad->GetData(),sm);}
|
2020-09-02 18:16:15 +08:00
|
|
|
|
|
2020-12-10 14:52:58 +08:00
|
|
|
|
#define SCENE_DB_CREATE_FUNC(name) GPUBuffer *Create##name(VkDeviceSize size,void *data,SharingMode sm=SharingMode::Exclusive); \
|
|
|
|
|
GPUBuffer *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
|
|
|
|
|
2020-09-02 19:06:12 +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
|
|
|
|
|
2020-09-19 23:49:32 +08:00
|
|
|
|
public: //Material
|
|
|
|
|
|
|
|
|
|
const ShaderModule *CreateShaderModule(const OSString &filename,ShaderResource *shader_resource);
|
|
|
|
|
const ShaderModule *CreateShaderModule(const OSString &filename);
|
|
|
|
|
|
2021-05-10 15:19:16 +08:00
|
|
|
|
Material * CreateMaterial(const UTF8String &mtl_name,const OSString &vertex_shader_filename,const OSString &fragment_shader_filename);
|
|
|
|
|
Material * CreateMaterial(const UTF8String &mtl_name,const OSString &vertex_shader_filename,const OSString &geometry_shader_filename,const OSString &fragment_shader_filename);
|
2020-09-19 23:49:32 +08:00
|
|
|
|
|
|
|
|
|
Material * CreateMaterial(const OSString &);
|
2021-06-16 10:41:04 +08:00
|
|
|
|
MaterialParameters * CreateMaterialInstance(Material *);
|
|
|
|
|
MaterialParameters * CreateMaterialInstance(const OSString &);
|
2020-09-19 23:49:32 +08:00
|
|
|
|
|
2020-09-21 19:05:25 +08:00
|
|
|
|
Renderable * CreateRenderable(const uint32_t vertex_count=0);
|
2020-09-02 18:16:15 +08:00
|
|
|
|
TextRenderable * CreateTextRenderable(Material *);
|
|
|
|
|
|
2021-06-16 10:41:04 +08:00
|
|
|
|
RenderableInstance *CreateRenderableInstance(Renderable *r,MaterialParameters *mi,Pipeline *p);
|
2020-09-02 18:16:15 +08:00
|
|
|
|
|
|
|
|
|
Sampler * CreateSampler(VkSamplerCreateInfo *sci=nullptr);
|
|
|
|
|
|
2020-10-22 12:22:10 +08:00
|
|
|
|
public: //texture
|
|
|
|
|
|
2020-10-24 21:50:36 +08:00
|
|
|
|
Texture2D * LoadTexture2D(const OSString &,bool auto_mipmaps=false);
|
2020-10-22 12:22:10 +08:00
|
|
|
|
|
2020-09-02 18:16:15 +08:00
|
|
|
|
public: //Get
|
|
|
|
|
|
|
|
|
|
Material * GetMaterial (const MaterialID &id){return rm_material.Get(id);}
|
2021-06-16 10:41:04 +08:00
|
|
|
|
MaterialParameters * GetMaterialInstance (const MaterialInstanceID &id){return rm_material_instance.Get(id);}
|
2020-09-02 18:16:15 +08:00
|
|
|
|
DescriptorSets * GetDescSets (const DescriptorSetsID &id){return rm_desc_sets.Get(id);}
|
|
|
|
|
Renderable * GetRenderable (const RenderableID &id){return rm_renderables.Get(id);}
|
2020-10-22 01:29:09 +08:00
|
|
|
|
GPUBuffer * 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);}
|
|
|
|
|
RenderableInstance *GetRenderableInstance (const RenderableInstanceID &id){return rm_renderable_instances.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
|