2020-09-02 18:16:15 +08:00
|
|
|
|
#include<hgl/graph/vulkan/VKDatabase.h>
|
|
|
|
|
#include<hgl/graph/vulkan/VKDevice.h>
|
|
|
|
|
#include<hgl/graph/RenderableInstance.h>
|
|
|
|
|
|
|
|
|
|
VK_NAMESPACE_BEGIN
|
2020-09-02 18:36:24 +08:00
|
|
|
|
VAB *Database::CreateVAB(VkFormat format,uint32_t count,const void *data,SharingMode sharing_mode)
|
2020-09-02 18:16:15 +08:00
|
|
|
|
{
|
|
|
|
|
VAB *vb=device->CreateVAB(format,count,data,sharing_mode);
|
|
|
|
|
|
|
|
|
|
if(!vb)
|
|
|
|
|
return(nullptr);
|
|
|
|
|
|
|
|
|
|
rm_buffers.Add(vb);
|
|
|
|
|
|
|
|
|
|
return vb;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-02 18:36:24 +08:00
|
|
|
|
#define SCENE_DB_CREATE_BUFFER(name) Buffer *Database::Create##name(VkDeviceSize size,void *data,SharingMode sharing_mode) \
|
2020-09-02 18:16:15 +08:00
|
|
|
|
{ \
|
|
|
|
|
Buffer *buf=device->Create##name(size,data,sharing_mode); \
|
|
|
|
|
\
|
|
|
|
|
if(!buf)return(nullptr); \
|
|
|
|
|
rm_buffers.Add(buf); \
|
|
|
|
|
return(buf); \
|
|
|
|
|
} \
|
|
|
|
|
\
|
2020-09-02 18:36:24 +08:00
|
|
|
|
Buffer *Database::Create##name(VkDeviceSize size,SharingMode sharing_mode) \
|
2020-09-02 18:16:15 +08:00
|
|
|
|
{ \
|
|
|
|
|
Buffer *buf=device->Create##name(size,sharing_mode); \
|
|
|
|
|
\
|
|
|
|
|
if(!buf)return(nullptr); \
|
|
|
|
|
rm_buffers.Add(buf); \
|
|
|
|
|
return(buf); \
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SCENE_DB_CREATE_BUFFER(UBO)
|
|
|
|
|
SCENE_DB_CREATE_BUFFER(SSBO)
|
|
|
|
|
SCENE_DB_CREATE_BUFFER(INBO)
|
|
|
|
|
|
|
|
|
|
#undef SCENE_DB_CREATE_BUFFER
|
|
|
|
|
|
2020-09-02 18:36:24 +08:00
|
|
|
|
IndexBuffer *Database::CreateIBO(VkIndexType index_type,uint32_t count,const void *data,SharingMode sharing_mode)
|
2020-09-02 18:16:15 +08:00
|
|
|
|
{
|
|
|
|
|
IndexBuffer *buf=device->CreateIBO(index_type,count,data,sharing_mode);
|
|
|
|
|
|
|
|
|
|
if(!buf)return(nullptr);
|
|
|
|
|
rm_buffers.Add(buf);
|
|
|
|
|
return(buf);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-02 18:18:57 +08:00
|
|
|
|
MaterialInstance *Database::CreateMaterialInstance(Material *mtl)
|
2020-09-02 18:16:15 +08:00
|
|
|
|
{
|
|
|
|
|
if(!mtl)return(nullptr);
|
|
|
|
|
|
|
|
|
|
MaterialInstance *mi=mtl->CreateInstance();
|
|
|
|
|
|
|
|
|
|
if(mi)
|
|
|
|
|
Add(mi);
|
|
|
|
|
|
|
|
|
|
return mi;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-02 18:18:57 +08:00
|
|
|
|
Renderable *Database::CreateRenderable(Material *mtl,const uint32_t vertex_count)
|
2020-09-02 18:16:15 +08:00
|
|
|
|
{
|
|
|
|
|
if(!mtl)return(nullptr);
|
|
|
|
|
|
|
|
|
|
Renderable *ro=mtl->CreateRenderable(vertex_count);
|
|
|
|
|
|
|
|
|
|
if(ro)
|
|
|
|
|
Add(ro);
|
|
|
|
|
|
|
|
|
|
return ro;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-02 18:18:57 +08:00
|
|
|
|
TextRenderable *Database::CreateTextRenderable(Material *mtl)
|
2020-09-02 18:16:15 +08:00
|
|
|
|
{
|
|
|
|
|
if(!mtl)return(nullptr);
|
|
|
|
|
|
|
|
|
|
TextRenderable *tr=new TextRenderable(device,mtl);
|
|
|
|
|
|
|
|
|
|
if(tr)
|
|
|
|
|
Add(tr);
|
|
|
|
|
|
|
|
|
|
return tr;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-02 18:18:57 +08:00
|
|
|
|
RenderableInstance *Database::CreateRenderableInstance(Pipeline *p,MaterialInstance *mi,Renderable *r)
|
2020-09-02 18:16:15 +08:00
|
|
|
|
{
|
|
|
|
|
if(!p||!mi||!r)
|
|
|
|
|
return(nullptr);
|
|
|
|
|
|
|
|
|
|
RenderableInstance *ri=new RenderableInstance(p,mi,r);
|
|
|
|
|
|
|
|
|
|
if(ri)
|
|
|
|
|
Add(ri);
|
|
|
|
|
|
|
|
|
|
return ri;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-02 18:18:57 +08:00
|
|
|
|
Sampler *Database::CreateSampler(VkSamplerCreateInfo *sci)
|
2020-09-02 18:16:15 +08:00
|
|
|
|
{
|
|
|
|
|
Sampler *s=device->CreateSampler(sci);
|
|
|
|
|
|
|
|
|
|
if(s)
|
|
|
|
|
Add(s);
|
|
|
|
|
|
|
|
|
|
return s;
|
|
|
|
|
}
|
|
|
|
|
VK_NAMESPACE_END
|