ULRE/src/SceneGraph/Vulkan/VKMaterial.cpp

114 lines
2.3 KiB
C++
Raw Normal View History

#include<hgl/graph/VKMaterial.h>
#include<hgl/graph/VKMaterialParameters.h>
#include<hgl/graph/VKMaterialDescriptorManager.h>
#include<hgl/graph/VKVertexInput.h>
2021-09-14 20:31:15 +08:00
#include"VKPipelineLayoutData.h"
#include<hgl/type/ActiveMemoryBlockManager.h>
2019-04-25 10:09:56 +08:00
VK_NAMESPACE_BEGIN
void ReleaseVertexInput(VertexInput *vi);
2023-06-14 18:20:23 +08:00
Material::Material(const AnsiString &n)
{
2023-06-14 16:49:19 +08:00
name=n;
vertex_input=nullptr;
shader_maps=new ShaderModuleMap;
desc_manager=nullptr;
pipeline_layout_data=nullptr;
hgl_zero(mp_array);
mi_data_bytes=0;
mi_data_manager=nullptr;
2023-06-14 16:49:19 +08:00
}
2023-06-14 18:20:23 +08:00
Material::~Material()
2023-06-14 16:49:19 +08:00
{
SAFE_CLEAR(mi_data_manager);
ReleaseVertexInput(vertex_input);
2023-06-14 16:49:19 +08:00
delete shader_maps; //不用SAFE_CLEAR是因为这个一定会有
2023-03-21 21:46:16 +08:00
SAFE_CLEAR(desc_manager);
2023-06-14 16:49:19 +08:00
SAFE_CLEAR(pipeline_layout_data);
2023-10-12 01:40:59 +08:00
for(auto &mp:mp_array)
SAFE_CLEAR(mp);
2019-04-25 10:09:56 +08:00
}
2021-09-14 20:31:15 +08:00
const VkPipelineLayout Material::GetPipelineLayout()const
2019-04-27 01:36:58 +08:00
{
2023-06-14 18:20:23 +08:00
return pipeline_layout_data->pipeline_layout;
2019-04-25 10:09:56 +08:00
}
2023-02-22 21:50:18 +08:00
const bool Material::hasSet(const DescriptorSetType &dst)const
2023-02-22 21:50:18 +08:00
{
2023-06-14 18:20:23 +08:00
return desc_manager->hasSet(dst);
2023-02-22 21:50:18 +08:00
}
const bool Material::hasAssign()const
{
return vertex_input->hasAssign();
}
const VIL *Material::GetDefaultVIL()const
{
return vertex_input->GetDefaultVIL();
}
VIL *Material::CreateVIL(const VILConfig *format_map)
{
2023-06-14 18:20:23 +08:00
return vertex_input->CreateVIL(format_map);
}
bool Material::Release(VIL *vil)
{
2023-06-14 18:20:23 +08:00
return vertex_input->Release(vil);
}
const uint Material::GetVILCount()
{
2023-06-14 18:20:23 +08:00
return vertex_input->GetInstanceCount();
}
2023-09-25 21:49:35 +08:00
bool Material::BindUBO(const DescriptorSetType &type,const AnsiString &name,DeviceBuffer *ubo,bool dynamic)
{
MaterialParameters *mp=GetMP(type);
if(!mp)
return(false);
2023-10-12 01:40:59 +08:00
return mp->BindUBO(name,ubo,dynamic);
2023-09-25 21:49:35 +08:00
}
bool Material::BindSSBO(const DescriptorSetType &type,const AnsiString &name,DeviceBuffer *ubo,bool dynamic)
{
MaterialParameters *mp=GetMP(type);
if(!mp)
return(false);
2023-10-12 01:40:59 +08:00
return mp->BindSSBO(name,ubo,dynamic);
2023-09-25 21:49:35 +08:00
}
bool Material::BindImageSampler(const DescriptorSetType &type,const AnsiString &name,Texture *tex,Sampler *sampler)
{
MaterialParameters *mp=GetMP(type);
if(!mp)
return(false);
2023-10-12 01:40:59 +08:00
return mp->BindImageSampler(name,tex,sampler);
}
2023-09-25 21:49:35 +08:00
2023-10-12 01:40:59 +08:00
void Material::Update()
{
for(auto &mp:mp_array)
{
if(mp)
mp->Update();
}
2023-09-25 21:49:35 +08:00
}
2019-04-25 10:09:56 +08:00
VK_NAMESPACE_END