2021-09-14 20:31:15 +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
|
2022-10-11 19:16:06 +08:00
|
|
|
|
MaterialInstance *GPUDevice::CreateMI(Material *mtl,const VILConfig *vil_cfg)
|
2021-06-16 21:03:52 +08:00
|
|
|
|
{
|
2021-09-14 20:31:15 +08:00
|
|
|
|
if(!mtl)return(nullptr);
|
2021-06-16 21:03:52 +08:00
|
|
|
|
|
2023-03-19 19:41:21 +08:00
|
|
|
|
VIL *vil=mtl->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-02-22 21:50:18 +08:00
|
|
|
|
return(new MaterialInstance(mtl,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-11-29 20:12:10 +08:00
|
|
|
|
|
2023-03-29 21:34:50 +08:00
|
|
|
|
mp_per_mi=
|
|
|
|
|
device->CreateMP(desc_manager,pld,(DescriptorSetType)dst);
|
|
|
|
|
PerMaterial<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ÿ<EFBFBD><EFBFBD>MaterialInstance<EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD><EFBFBD><EFBFBD>MP<EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼
|
|
|
|
|
mtl->GetMP(DescriptorSetType::PerMaterial);
|
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-02-22 21:50:18 +08:00
|
|
|
|
MaterialParameters *mp=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-02-22 21:50:18 +08:00
|
|
|
|
MaterialParameters *mp=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-02-22 21:50:18 +08:00
|
|
|
|
MaterialParameters *mp=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
|