used newly Bind series function.

This commit is contained in:
hyzboy 2022-03-09 20:33:26 +08:00
parent edbecbb86d
commit 15e80cbc5a
14 changed files with 70 additions and 178 deletions

View File

@ -98,17 +98,7 @@ private:
sky_mi=db->CreateMaterialInstance(sky_material); sky_mi=db->CreateMaterialInstance(sky_material);
if(!sky_mi)return(false); if(!sky_mi)return(false);
{ if(!sky_mi->BindSampler(DescriptorSetsType::Value,"tex" ,texture, sampler))return(false);
MaterialParameters *mp_texture=sky_mi->GetMP(DescriptorSetsType::Value);
if(!mp_texture)
return(false);
if(!mp_texture->BindSampler("tex" ,texture, sampler))
return(false);
mp_texture->Update();
}
sky_pipeline=CreatePipeline(sky_mi,InlinePipeline::Sky,Prim::Triangles); sky_pipeline=CreatePipeline(sky_mi,InlinePipeline::Sky,Prim::Triangles);
if(!sky_pipeline)return(false); if(!sky_pipeline)return(false);
@ -121,17 +111,7 @@ private:
envmap_mi=db->CreateMaterialInstance(envmap_material); envmap_mi=db->CreateMaterialInstance(envmap_material);
if(!envmap_mi)return(false); if(!envmap_mi)return(false);
{ if(!envmap_mi->BindSampler(DescriptorSetsType::Value,"EnvCubemap" ,texture, sampler))return(false);
MaterialParameters *mp_texture=envmap_mi->GetMP(DescriptorSetsType::Value);
if(!mp_texture)
return(false);
if(!mp_texture->BindSampler("EnvCubemap" ,texture, sampler))
return(false);
mp_texture->Update();
}
solid_pipeline=CreatePipeline(envmap_mi,InlinePipeline::Solid3D,Prim::Triangles); solid_pipeline=CreatePipeline(envmap_mi,InlinePipeline::Solid3D,Prim::Triangles);
} }

View File

@ -166,27 +166,8 @@ private:
sampler=db->CreateSampler(); sampler=db->CreateSampler();
{ if(!material_instance->BindUBO(DescriptorSetsType::Global,"g_camera",ubo_camera_info))return(false);
MaterialParameters *mp_global=material_instance->GetMP(DescriptorSetsType::Global); if(!material_instance->BindSampler(DescriptorSetsType::Value,"tex",tile_data->GetTexture(),sampler))return(false);
if(!mp_global)
return(false);
if(!mp_global->BindUBO("g_camera",ubo_camera_info))return(false);
mp_global->Update();
}
{
MaterialParameters *mp_texture=material_instance->GetMP(DescriptorSetsType::Value);
if(!mp_texture)
return(false);
if(!mp_texture->BindSampler("tex",tile_data->GetTexture(),sampler))return(false);
mp_texture->Update();
}
return(true); return(true);
} }

View File

@ -48,29 +48,7 @@ private:
if(!texture) if(!texture)
return(false); return(false);
VkSamplerCreateInfo sampler_create_info= sampler =db->CreateSampler();
{
VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO,
nullptr,
0,
VK_FILTER_LINEAR,
VK_FILTER_LINEAR,
VK_SAMPLER_MIPMAP_MODE_LINEAR,
VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
0.0f,
VK_FALSE,
0,
false,
VK_COMPARE_OP_NEVER,
0.0f,
0,
VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK,
false
};
sampler =db->CreateSampler(&sampler_create_info);
} }
{ {
@ -80,17 +58,7 @@ private:
envmap_mi=db->CreateMaterialInstance(envmap_material); envmap_mi=db->CreateMaterialInstance(envmap_material);
if(!envmap_mi)return(false); if(!envmap_mi)return(false);
{ if(!envmap_mi->BindSampler(DescriptorSetsType::Value,"Envmap" ,texture, sampler))return(false);
MaterialParameters *mp_texture=envmap_mi->GetMP(DescriptorSetsType::Value);
if(!mp_texture)
return(false);
if(!mp_texture->BindSampler("Envmap" ,texture, sampler))
return(false);
mp_texture->Update();
}
solid_pipeline=CreatePipeline(envmap_mi,InlinePipeline::Solid3D,Prim::Triangles); solid_pipeline=CreatePipeline(envmap_mi,InlinePipeline::Solid3D,Prim::Triangles);
} }

View File

@ -53,23 +53,15 @@ private:
cam.vp_width=cam.width=extent.width; cam.vp_width=cam.width=extent.width;
cam.vp_height=cam.height=extent.height; cam.vp_height=cam.height=extent.height;
cam.Refresh(); cam.RefreshCameraInfo();
ubo_camera_info=db->CreateUBO(sizeof(CameraInfo),&cam.info); ubo_camera_info=db->CreateUBO(sizeof(CameraInfo),&cam.info);
if(!ubo_camera_info) if(!ubo_camera_info)
return(false); return(false);
{ if(!material_instance->BindUBO(DescriptorSetsType::Global,"g_camera",ubo_camera_info))return(false);
MaterialParameters *mp_global=material_instance->GetMP(DescriptorSetsType::Global);
if(!mp_global)
return(false);
if(!mp_global->BindUBO("g_camera",ubo_camera_info))return(false);
mp_global->Update();
}
return(true); return(true);
} }
@ -112,7 +104,7 @@ public:
cam.vp_width=w; cam.vp_width=w;
cam.vp_height=h; cam.vp_height=h;
cam.Refresh(); cam.RefreshCameraInfo();
ubo_camera_info->Write(&cam.info); ubo_camera_info->Write(&cam.info);

View File

@ -64,7 +64,7 @@ public:
ro->cam.width=extent.width; ro->cam.width=extent.width;
ro->cam.height=extent.height; ro->cam.height=extent.height;
ro->cam.Refresh(); ro->cam.RefreshCameraInfo();
ro->ubo_camera_info=db->CreateUBO(sizeof(CameraInfo),&ro->cam.info); ro->ubo_camera_info=db->CreateUBO(sizeof(CameraInfo),&ro->cam.info);

View File

@ -60,29 +60,9 @@ private:
sampler=db->CreateSampler(); sampler=db->CreateSampler();
{ if(!material_instance->BindUBO(DescriptorSetsType::Global,"g_camera",ubo_camera_info))return(false);
MaterialParameters *mp_global=material_instance->GetMP(DescriptorSetsType::Global); if(!material_instance->BindSampler(DescriptorSetsType::Value,"tex",texture,sampler))return(false);
if(!mp_global)
return(false);
if(!mp_global->BindUBO("g_camera",ubo_camera_info))return(false);
mp_global->Update();
}
{
MaterialParameters *mp_texture=material_instance->GetMP(DescriptorSetsType::Value);
if(!mp_texture)
return(false);
if(!mp_texture->BindSampler("tex",texture,sampler))return(false);
mp_texture->Update();
}
db->Add(texture);
return(true); return(true);
} }

View File

@ -28,7 +28,7 @@ private:
double start_time; double start_time;
SceneNode render_root; SceneNode render_root;
RenderList render_list; RenderList *render_list;
Material * material =nullptr; Material * material =nullptr;
MaterialInstance * material_instance =nullptr; MaterialInstance * material_instance =nullptr;
@ -81,14 +81,11 @@ private:
ubo_sun=device->CreateUBO(sizeof(sun_direction),&sun_direction); ubo_sun=device->CreateUBO(sizeof(sun_direction),&sun_direction);
if(!ubo_sun)return(false); if(!ubo_sun)return(false);
material_instance->BindUBO("world",GetCameraMatrixBuffer());
material_instance->BindUBO("color_material",ubo_color); material_instance->BindUBO("color_material",ubo_color);
material_instance->BindUBO("sun",ubo_sun); material_instance->BindUBO("sun",ubo_sun);
material_instance->Update(); material_instance->Update();
db->Add(ubo_color);
db->Add(ubo_sun);
return(true); return(true);
} }
@ -123,8 +120,7 @@ private:
} }
render_root.RefreshMatrix(); render_root.RefreshMatrix();
render_list.Clear(); render_list->Expend(camera->info,&render_root);
render_root.ExpendToList(&render_list);
return(true); return(true);
} }

View File

@ -71,16 +71,8 @@ private:
if(!ubo_sky_color) if(!ubo_sky_color)
return(false); return(false);
{ if(!material_instance->BindUBO(DescriptorSetsType::Value,"sky_color",ubo_sky_color))
MaterialParameters *mp=material_instance->GetMP(DescriptorSetsType::Value); return(false);
if(!mp)return(false);
if(!mp->BindUBO("sky_color",ubo_sky_color))
return(false);
mp->Update();
}
return(true); return(true);
} }

View File

@ -67,16 +67,9 @@ private:
if(!ubo_camera_info) if(!ubo_camera_info)
return(false); return(false);
{
MaterialParameters *mp_global=material_instance->GetMP(DescriptorSetsType::Global);
if(!mp_global) if(!material_instance->BindUBO(DescriptorSetsType::Global,"g_camera",ubo_camera_info))return(false);
return(false);
mp_global->BindUBO("g_camera",ubo_camera_info);
mp_global->Update();
}
return(true); return(true);
} }

View File

@ -62,23 +62,15 @@ private:
cam.vp_width=cam.width=extent.width; cam.vp_width=cam.width=extent.width;
cam.vp_height=cam.height=extent.height; cam.vp_height=cam.height=extent.height;
cam.Refresh(); cam.RefreshCameraInfo();
ubo_camera_info=db->CreateUBO(sizeof(CameraInfo),&cam.info); ubo_camera_info=db->CreateUBO(sizeof(CameraInfo),&cam.info);
if(!ubo_camera_info) if(!ubo_camera_info)
return(false); return(false);
{ if(!material_instance->BindUBO(DescriptorSetsType::Global,"g_camera",ubo_camera_info))return(false);
MaterialParameters *mp_global=material_instance->GetMP(DescriptorSetsType::Global);
if(!mp_global)
return(false);
if(!mp_global->BindUBO("g_camera",ubo_camera_info))return(false);
mp_global->Update();
}
return(true); return(true);
} }
@ -121,7 +113,7 @@ public:
cam.vp_width=w; cam.vp_width=w;
cam.vp_height=h; cam.vp_height=h;
cam.Refresh(); cam.RefreshCameraInfo();
ubo_camera_info->Write(&cam.info); ubo_camera_info->Write(&cam.info);

View File

@ -74,16 +74,7 @@ private:
sampler=db->CreateSampler(); sampler=db->CreateSampler();
{ if(!material_instance->BindSampler(DescriptorSetsType::Value,"tex",texture,sampler))return(false);
MaterialParameters *mp_texture=material_instance->GetMP(DescriptorSetsType::Value);
if(!mp_texture)
return(false);
if(!mp_texture->BindSampler("tex",texture,sampler))return(false);
mp_texture->Update();
}
return(true); return(true);
} }
@ -95,23 +86,14 @@ private:
cam.vp_width =cam.width =extent.width; cam.vp_width =cam.width =extent.width;
cam.vp_height=cam.height=extent.height; cam.vp_height=cam.height=extent.height;
cam.Refresh(); cam.RefreshCameraInfo();
ubo_camera_info=db->CreateUBO(sizeof(CameraInfo),&cam.info); ubo_camera_info=db->CreateUBO(sizeof(CameraInfo),&cam.info);
if(!ubo_camera_info) if(!ubo_camera_info)
return(false); return(false);
{ if(!material_instance->BindUBO(DescriptorSetsType::Global,"g_camera",ubo_camera_info))return(false);
MaterialParameters *mp_global=material_instance->GetMP(DescriptorSetsType::Global);
if(!mp_global)
return(false);
if(!mp_global->BindUBO("g_camera",ubo_camera_info))return(false);
mp_global->Update();
}
return(true); return(true);
} }
@ -156,7 +138,7 @@ public:
cam.width=w; cam.width=w;
cam.height=h; cam.height=h;
cam.Refresh(); cam.RefreshCameraInfo();
ubo_camera_info->Write(&cam.info); ubo_camera_info->Write(&cam.info);

View File

@ -63,22 +63,15 @@ private:
cam.width=extent.width; cam.width=extent.width;
cam.height=extent.height; cam.height=extent.height;
cam.Refresh(); cam.RefreshCameraInfo();
ubo_camera_info=db->CreateUBO(sizeof(CameraInfo),&cam.info); ubo_camera_info=db->CreateUBO(sizeof(CameraInfo),&cam.info);
if(!ubo_camera_info) if(!ubo_camera_info)
return(false); return(false);
{ if(!material_instance->BindUBO(DescriptorSetsType::Global,"g_camera",ubo_camera_info))return(false);
MaterialParameters *mp_global=material_instance->GetMP(DescriptorSetsType::Global);
if(!mp_global)
return(false);
mp_global->BindUBO("g_camera",ubo_camera_info);
mp_global->Update();
}
return(true); return(true);
} }
@ -134,7 +127,7 @@ public:
cam.width=w; cam.width=w;
cam.height=h; cam.height=h;
cam.Refresh(); cam.RefreshCameraInfo();
ubo_camera_info->Write(&cam.info); ubo_camera_info->Write(&cam.info);

View File

@ -27,6 +27,10 @@ public:
const VAB *GetVAB()const{return vab;} const VAB *GetVAB()const{return vab;}
MaterialParameters *GetMP(){return mp_value;} MaterialParameters *GetMP(){return mp_value;}
MaterialParameters *GetMP(const DescriptorSetsType &type); MaterialParameters *GetMP(const DescriptorSetsType &type);
bool BindUBO(const DescriptorSetsType &type,const AnsiString &name,GPUBuffer *ubo,bool dynamic=false);
bool BindSSBO(const DescriptorSetsType &type,const AnsiString &name,GPUBuffer *ubo,bool dynamic=false);
bool BindSampler(const DescriptorSetsType &type,const AnsiString &name,Texture *tex,Sampler *sampler);
};//class MaterialInstance };//class MaterialInstance
VK_NAMESPACE_END VK_NAMESPACE_END
#endif//HGL_GRAPH_VULKAN_MATERIAL_INSTANCE_INCLUDE #endif//HGL_GRAPH_VULKAN_MATERIAL_INSTANCE_INCLUDE

View File

@ -44,4 +44,43 @@ MaterialParameters *MaterialInstance::GetMP(const DescriptorSetsType &type)
return material->GetMP(type); return material->GetMP(type);
} }
bool MaterialInstance::BindUBO(const DescriptorSetsType &type,const AnsiString &name,GPUBuffer *ubo,bool dynamic)
{
MaterialParameters *mp_global=GetMP(type);
if(!mp_global)
return(false);
if(!mp_global->BindUBO(name,ubo,dynamic))return(false);
mp_global->Update();
return(true);
}
bool MaterialInstance::BindSSBO(const DescriptorSetsType &type,const AnsiString &name,GPUBuffer *ubo,bool dynamic)
{
MaterialParameters *mp_global=GetMP(type);
if(!mp_global)
return(false);
if(!mp_global->BindSSBO(name,ubo,dynamic))return(false);
mp_global->Update();
return(true);
}
bool MaterialInstance::BindSampler(const DescriptorSetsType &type,const AnsiString &name,Texture *tex,Sampler *sampler)
{
MaterialParameters *mp_global=GetMP(type);
if(!mp_global)
return(false);
if(!mp_global->BindSampler(name,tex,sampler))return(false);
mp_global->Update();
return(true);
}
VK_NAMESPACE_END VK_NAMESPACE_END