2023-04-20 21:49:48 +08:00
|
|
|
|
#include<hgl/graph/VKDevice.h>
|
2021-06-16 21:03:52 +08:00
|
|
|
|
#include<hgl/graph/VKMaterialInstance.h>
|
|
|
|
|
#include<hgl/graph/VKMaterialParameters.h>
|
2021-11-29 20:12:10 +08:00
|
|
|
|
#include<hgl/graph/VKShaderModule.h>
|
2021-06-16 21:03:52 +08:00
|
|
|
|
|
|
|
|
|
VK_NAMESPACE_BEGIN
|
2023-06-05 20:17:16 +08:00
|
|
|
|
MaterialInstance *Material::CreateMI(const VILConfig *vil_cfg)
|
2021-06-16 21:03:52 +08:00
|
|
|
|
{
|
2023-06-05 20:17:16 +08:00
|
|
|
|
VIL *vil=CreateVIL(vil_cfg);
|
2021-11-29 20:12:10 +08:00
|
|
|
|
|
2022-10-11 19:16:06 +08:00
|
|
|
|
if(!vil)return(nullptr);
|
2021-11-29 20:12:10 +08:00
|
|
|
|
|
2023-06-05 20:17:16 +08:00
|
|
|
|
return(new MaterialInstance(this,vil));
|
2021-06-16 21:03:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-22 21:50:18 +08:00
|
|
|
|
MaterialInstance::MaterialInstance(Material *mtl,VIL *v)
|
2021-06-16 21:03:52 +08:00
|
|
|
|
{
|
|
|
|
|
material=mtl;
|
|
|
|
|
|
2022-10-11 19:16:06 +08:00
|
|
|
|
vil=v;
|
2021-06-16 21:03:52 +08:00
|
|
|
|
}
|
2022-03-09 20:33:26 +08:00
|
|
|
|
|
2023-02-22 21:53:51 +08:00
|
|
|
|
bool MaterialInstance::BindUBO(const DescriptorSetType &type,const AnsiString &name,DeviceBuffer *ubo,bool dynamic)
|
2022-03-09 20:33:26 +08:00
|
|
|
|
{
|
2023-06-05 21:39:12 +08:00
|
|
|
|
MaterialParameters *mp=material->GetMP(type);
|
2022-03-09 20:33:26 +08:00
|
|
|
|
|
2023-02-22 21:50:18 +08:00
|
|
|
|
if(!mp)
|
2022-03-09 20:33:26 +08:00
|
|
|
|
return(false);
|
|
|
|
|
|
2023-02-22 21:50:18 +08:00
|
|
|
|
if(!mp->BindUBO(name,ubo,dynamic))return(false);
|
2022-03-09 20:33:26 +08:00
|
|
|
|
|
2023-02-22 21:50:18 +08:00
|
|
|
|
mp->Update();
|
2022-03-09 20:33:26 +08:00
|
|
|
|
return(true);
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-22 21:53:51 +08:00
|
|
|
|
bool MaterialInstance::BindSSBO(const DescriptorSetType &type,const AnsiString &name,DeviceBuffer *ubo,bool dynamic)
|
2022-03-09 20:33:26 +08:00
|
|
|
|
{
|
2023-06-05 21:39:12 +08:00
|
|
|
|
MaterialParameters *mp=material->GetMP(type);
|
2022-03-09 20:33:26 +08:00
|
|
|
|
|
2023-02-22 21:50:18 +08:00
|
|
|
|
if(!mp)
|
2022-03-09 20:33:26 +08:00
|
|
|
|
return(false);
|
|
|
|
|
|
2023-02-22 21:50:18 +08:00
|
|
|
|
if(!mp->BindSSBO(name,ubo,dynamic))return(false);
|
2022-03-09 20:33:26 +08:00
|
|
|
|
|
2023-02-22 21:50:18 +08:00
|
|
|
|
mp->Update();
|
2022-03-09 20:33:26 +08:00
|
|
|
|
return(true);
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-23 13:25:05 +08:00
|
|
|
|
bool MaterialInstance::BindImageSampler(const DescriptorSetType &type,const AnsiString &name,Texture *tex,Sampler *sampler)
|
2022-03-09 20:33:26 +08:00
|
|
|
|
{
|
2023-06-05 21:39:12 +08:00
|
|
|
|
MaterialParameters *mp=material->GetMP(type);
|
2022-03-09 20:33:26 +08:00
|
|
|
|
|
2023-02-22 21:50:18 +08:00
|
|
|
|
if(!mp)
|
2022-03-09 20:33:26 +08:00
|
|
|
|
return(false);
|
|
|
|
|
|
2023-02-23 13:25:05 +08:00
|
|
|
|
if(!mp->BindImageSampler(name,tex,sampler))return(false);
|
2022-03-09 20:33:26 +08:00
|
|
|
|
|
2023-02-22 21:50:18 +08:00
|
|
|
|
mp->Update();
|
2022-03-09 20:33:26 +08:00
|
|
|
|
return(true);
|
|
|
|
|
}
|
2021-06-16 21:03:52 +08:00
|
|
|
|
VK_NAMESPACE_END
|