diff --git a/example/Vulkan/Cubemap.cpp b/example/Vulkan/Cubemap.cpp index e8bc80ca..1ed04756 100644 --- a/example/Vulkan/Cubemap.cpp +++ b/example/Vulkan/Cubemap.cpp @@ -98,17 +98,7 @@ private: sky_mi=db->CreateMaterialInstance(sky_material); if(!sky_mi)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(); - } + if(!sky_mi->BindSampler(DescriptorSetsType::Value,"tex" ,texture, sampler))return(false); sky_pipeline=CreatePipeline(sky_mi,InlinePipeline::Sky,Prim::Triangles); if(!sky_pipeline)return(false); @@ -121,17 +111,7 @@ private: envmap_mi=db->CreateMaterialInstance(envmap_material); if(!envmap_mi)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(); - } + if(!envmap_mi->BindSampler(DescriptorSetsType::Value,"EnvCubemap" ,texture, sampler))return(false); solid_pipeline=CreatePipeline(envmap_mi,InlinePipeline::Solid3D,Prim::Triangles); } diff --git a/example/Vulkan/DrawTile.cpp b/example/Vulkan/DrawTile.cpp index 4f26351e..1ad675c5 100644 --- a/example/Vulkan/DrawTile.cpp +++ b/example/Vulkan/DrawTile.cpp @@ -166,27 +166,8 @@ private: sampler=db->CreateSampler(); - { - 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(); - } - - { - 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(); - } + if(!material_instance->BindUBO(DescriptorSetsType::Global,"g_camera",ubo_camera_info))return(false); + if(!material_instance->BindSampler(DescriptorSetsType::Value,"tex",tile_data->GetTexture(),sampler))return(false); return(true); } diff --git a/example/Vulkan/EquirectangularMap.cpp b/example/Vulkan/EquirectangularMap.cpp index f9f462fa..e958047c 100644 --- a/example/Vulkan/EquirectangularMap.cpp +++ b/example/Vulkan/EquirectangularMap.cpp @@ -48,29 +48,7 @@ private: if(!texture) return(false); - VkSamplerCreateInfo sampler_create_info= - { - 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); + sampler =db->CreateSampler(); } { @@ -80,17 +58,7 @@ private: envmap_mi=db->CreateMaterialInstance(envmap_material); if(!envmap_mi)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(); - } + if(!envmap_mi->BindSampler(DescriptorSetsType::Value,"Envmap" ,texture, sampler))return(false); solid_pipeline=CreatePipeline(envmap_mi,InlinePipeline::Solid3D,Prim::Triangles); } diff --git a/example/Vulkan/FragCoordTest.cpp b/example/Vulkan/FragCoordTest.cpp index b957fcb9..867fea40 100644 --- a/example/Vulkan/FragCoordTest.cpp +++ b/example/Vulkan/FragCoordTest.cpp @@ -53,23 +53,15 @@ private: cam.vp_width=cam.width=extent.width; cam.vp_height=cam.height=extent.height; - cam.Refresh(); + cam.RefreshCameraInfo(); ubo_camera_info=db->CreateUBO(sizeof(CameraInfo),&cam.info); if(!ubo_camera_info) return(false); - { - MaterialParameters *mp_global=material_instance->GetMP(DescriptorSetsType::Global); - - if(!mp_global) - return(false); + if(!material_instance->BindUBO(DescriptorSetsType::Global,"g_camera",ubo_camera_info))return(false); - if(!mp_global->BindUBO("g_camera",ubo_camera_info))return(false); - - mp_global->Update(); - } return(true); } @@ -112,7 +104,7 @@ public: cam.vp_width=w; cam.vp_height=h; - cam.Refresh(); + cam.RefreshCameraInfo(); ubo_camera_info->Write(&cam.info); diff --git a/example/Vulkan/OffscreenRender.cpp b/example/Vulkan/OffscreenRender.cpp index d5a13ac7..fa62f461 100644 --- a/example/Vulkan/OffscreenRender.cpp +++ b/example/Vulkan/OffscreenRender.cpp @@ -64,7 +64,7 @@ public: ro->cam.width=extent.width; ro->cam.height=extent.height; - ro->cam.Refresh(); + ro->cam.RefreshCameraInfo(); ro->ubo_camera_info=db->CreateUBO(sizeof(CameraInfo),&ro->cam.info); diff --git a/example/Vulkan/RectanglePrimitive.cpp b/example/Vulkan/RectanglePrimitive.cpp index 0fe945e8..d9ee11c8 100644 --- a/example/Vulkan/RectanglePrimitive.cpp +++ b/example/Vulkan/RectanglePrimitive.cpp @@ -60,29 +60,9 @@ private: sampler=db->CreateSampler(); - { - MaterialParameters *mp_global=material_instance->GetMP(DescriptorSetsType::Global); - - if(!mp_global) - return(false); + if(!material_instance->BindUBO(DescriptorSetsType::Global,"g_camera",ubo_camera_info))return(false); + if(!material_instance->BindSampler(DescriptorSetsType::Value,"tex",texture,sampler))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); } diff --git a/example/Vulkan/SceneTree.cpp b/example/Vulkan/SceneTree.cpp index b94ecb8c..dc6f797d 100644 --- a/example/Vulkan/SceneTree.cpp +++ b/example/Vulkan/SceneTree.cpp @@ -28,7 +28,7 @@ private: double start_time; SceneNode render_root; - RenderList render_list; + RenderList *render_list; Material * material =nullptr; MaterialInstance * material_instance =nullptr; @@ -81,14 +81,11 @@ private: ubo_sun=device->CreateUBO(sizeof(sun_direction),&sun_direction); if(!ubo_sun)return(false); - material_instance->BindUBO("world",GetCameraMatrixBuffer()); material_instance->BindUBO("color_material",ubo_color); material_instance->BindUBO("sun",ubo_sun); material_instance->Update(); - db->Add(ubo_color); - db->Add(ubo_sun); return(true); } @@ -123,8 +120,7 @@ private: } render_root.RefreshMatrix(); - render_list.Clear(); - render_root.ExpendToList(&render_list); + render_list->Expend(camera->info,&render_root); return(true); } diff --git a/example/Vulkan/SkyColor.cpp b/example/Vulkan/SkyColor.cpp index 6c120e5b..4b8fdbd8 100644 --- a/example/Vulkan/SkyColor.cpp +++ b/example/Vulkan/SkyColor.cpp @@ -71,16 +71,8 @@ private: if(!ubo_sky_color) return(false); - { - MaterialParameters *mp=material_instance->GetMP(DescriptorSetsType::Value); - - if(!mp)return(false); - - if(!mp->BindUBO("sky_color",ubo_sky_color)) - return(false); - - mp->Update(); - } + if(!material_instance->BindUBO(DescriptorSetsType::Value,"sky_color",ubo_sky_color)) + return(false); return(true); } diff --git a/example/Vulkan/first_triangle.cpp b/example/Vulkan/first_triangle.cpp index f324ce6c..c41f2efe 100644 --- a/example/Vulkan/first_triangle.cpp +++ b/example/Vulkan/first_triangle.cpp @@ -67,16 +67,9 @@ private: if(!ubo_camera_info) return(false); - - { - MaterialParameters *mp_global=material_instance->GetMP(DescriptorSetsType::Global); - if(!mp_global) - return(false); + if(!material_instance->BindUBO(DescriptorSetsType::Global,"g_camera",ubo_camera_info))return(false); - mp_global->BindUBO("g_camera",ubo_camera_info); - mp_global->Update(); - } return(true); } diff --git a/example/Vulkan/indices_rect.cpp b/example/Vulkan/indices_rect.cpp index fece2f40..0cf598de 100644 --- a/example/Vulkan/indices_rect.cpp +++ b/example/Vulkan/indices_rect.cpp @@ -62,23 +62,15 @@ private: cam.vp_width=cam.width=extent.width; cam.vp_height=cam.height=extent.height; - cam.Refresh(); + cam.RefreshCameraInfo(); ubo_camera_info=db->CreateUBO(sizeof(CameraInfo),&cam.info); if(!ubo_camera_info) return(false); - { - MaterialParameters *mp_global=material_instance->GetMP(DescriptorSetsType::Global); - - if(!mp_global) - return(false); + if(!material_instance->BindUBO(DescriptorSetsType::Global,"g_camera",ubo_camera_info))return(false); - if(!mp_global->BindUBO("g_camera",ubo_camera_info))return(false); - - mp_global->Update(); - } return(true); } @@ -121,7 +113,7 @@ public: cam.vp_width=w; cam.vp_height=h; - cam.Refresh(); + cam.RefreshCameraInfo(); ubo_camera_info->Write(&cam.info); diff --git a/example/Vulkan/texture_rect.cpp b/example/Vulkan/texture_rect.cpp index fa26ae2f..733f3273 100644 --- a/example/Vulkan/texture_rect.cpp +++ b/example/Vulkan/texture_rect.cpp @@ -74,16 +74,7 @@ private: sampler=db->CreateSampler(); - { - 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(); - } + if(!material_instance->BindSampler(DescriptorSetsType::Value,"tex",texture,sampler))return(false); return(true); } @@ -95,23 +86,14 @@ private: cam.vp_width =cam.width =extent.width; cam.vp_height=cam.height=extent.height; - cam.Refresh(); + cam.RefreshCameraInfo(); ubo_camera_info=db->CreateUBO(sizeof(CameraInfo),&cam.info); if(!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(); - } + if(!material_instance->BindUBO(DescriptorSetsType::Global,"g_camera",ubo_camera_info))return(false); return(true); } @@ -156,7 +138,7 @@ public: cam.width=w; cam.height=h; - cam.Refresh(); + cam.RefreshCameraInfo(); ubo_camera_info->Write(&cam.info); diff --git a/example/Vulkan/two_triangle.cpp b/example/Vulkan/two_triangle.cpp index a0d4034d..082b624a 100644 --- a/example/Vulkan/two_triangle.cpp +++ b/example/Vulkan/two_triangle.cpp @@ -63,22 +63,15 @@ private: cam.width=extent.width; cam.height=extent.height; - cam.Refresh(); + cam.RefreshCameraInfo(); ubo_camera_info=db->CreateUBO(sizeof(CameraInfo),&cam.info); if(!ubo_camera_info) return(false); - { - MaterialParameters *mp_global=material_instance->GetMP(DescriptorSetsType::Global); - - if(!mp_global) - return(false); + if(!material_instance->BindUBO(DescriptorSetsType::Global,"g_camera",ubo_camera_info))return(false); - mp_global->BindUBO("g_camera",ubo_camera_info); - mp_global->Update(); - } return(true); } @@ -134,7 +127,7 @@ public: cam.width=w; cam.height=h; - cam.Refresh(); + cam.RefreshCameraInfo(); ubo_camera_info->Write(&cam.info); diff --git a/inc/hgl/graph/VKMaterialInstance.h b/inc/hgl/graph/VKMaterialInstance.h index b9483658..f6008c8f 100644 --- a/inc/hgl/graph/VKMaterialInstance.h +++ b/inc/hgl/graph/VKMaterialInstance.h @@ -27,6 +27,10 @@ public: const VAB *GetVAB()const{return vab;} MaterialParameters *GetMP(){return mp_value;} 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 VK_NAMESPACE_END #endif//HGL_GRAPH_VULKAN_MATERIAL_INSTANCE_INCLUDE diff --git a/src/SceneGraph/Vulkan/VKMaterialInstance.cpp b/src/SceneGraph/Vulkan/VKMaterialInstance.cpp index 9cee676b..d634ea17 100644 --- a/src/SceneGraph/Vulkan/VKMaterialInstance.cpp +++ b/src/SceneGraph/Vulkan/VKMaterialInstance.cpp @@ -44,4 +44,43 @@ MaterialParameters *MaterialInstance::GetMP(const DescriptorSetsType &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