Only expose the image view for textures in the scene data

This commit is contained in:
Guillaume Meunier
2024-01-28 11:33:34 +01:00
parent 9132e3040e
commit 11b5d501b8
3 changed files with 11 additions and 5 deletions
+4 -1
View File
@@ -557,7 +557,10 @@ public:
if (gltf_texture.imageIndex)
{
texture_ref.image_ = images.at(*gltf_texture.imageIndex);
std::shared_ptr<scene_data::image> image = images.at(*gltf_texture.imageIndex);
// Use the aliasing constructor so that the image_view has the same lifetime as the image
texture_ref.image_view = std::shared_ptr<vk::raii::ImageView>(image, &image->image_view);
}
// else if (gltf_texture.basisuImageIndex)
// {
+2 -1
View File
@@ -65,7 +65,7 @@ struct scene_data
struct texture
{
std::shared_ptr<image> image_{};
std::shared_ptr<vk::raii::ImageView> image_view;
sampler_info sampler;
};
@@ -108,6 +108,7 @@ struct scene_data
std::shared_ptr<buffer_allocation> buffer;
size_t offset;
// The descriptor set is managed by the scene renderer, it is updated whenever ds_dirty is true
// Bindings 0-4: textures
// Binding 5: uniform buffer
std::shared_ptr<vk::raii::DescriptorSet> ds;
+5 -3
View File
@@ -97,10 +97,12 @@ std::shared_ptr<scene_data::texture> scene_renderer::create_default_texture(vk::
image_loader loader(device, cb, pixel2, vk::Extent3D{1, 1, 1}, format);
auto base_color_image = std::make_shared<scene_data::image>(std::move(loader.image), std::move(loader.image_view));
auto image = std::make_shared<scene_data::image>(std::move(loader.image), std::move(loader.image_view));
std::shared_ptr<vk::raii::ImageView> image_view(image, &image->image_view);
staging_buffers.push_back(std::move(loader.staging_buffer));
return std::make_shared<scene_data::texture>(base_color_image, sampler_info{});
return std::make_shared<scene_data::texture>(image_view, sampler_info{});
}
std::shared_ptr<scene_data::material> scene_renderer::create_default_material(vk::raii::CommandPool & cb_pool)
@@ -478,7 +480,7 @@ void scene_renderer::update_material_descriptor_set(scene_data::material& materi
auto f = [&](std::shared_ptr<scene_data::texture>& texture){
return vk::DescriptorImageInfo{
.sampler = get_sampler(texture->sampler),
.imageView = *texture->image_->image_view,
.imageView = **texture->image_view,
.imageLayout = vk::ImageLayout::eShaderReadOnlyOptimal,
};
};