81 lines
2.1 KiB
C++
81 lines
2.1 KiB
C++
//
|
|
// Created by kj16609 on 9/23/25.
|
|
//
|
|
#include "Swapchain.hpp"
|
|
|
|
#include "assets/image/Image.hpp"
|
|
#include "assets/image/ImageView.hpp"
|
|
#include "assets/texture/Texture.hpp"
|
|
#include "constants.hpp"
|
|
#include "rendering/devices/Device.hpp"
|
|
#include "slang.h"
|
|
|
|
namespace fgl::engine
|
|
{
|
|
|
|
vk::Format SwapchainImageInfo::pickBestFormat() const
|
|
{
|
|
return Device::getInstance()
|
|
.findSupportedFormat( m_format.m_canidates, vk::ImageTiling::eOptimal, m_format.m_features );
|
|
}
|
|
|
|
SwapchainImageSet::SwapchainImageSet( const SwapchainImageInfo& info )
|
|
{
|
|
for ( int i = 0; i < constants::MAX_FRAMES_IN_FLIGHT; ++i )
|
|
{
|
|
auto image_itter { m_image.emplace_back(
|
|
std::make_shared< Image >(
|
|
info.m_extent,
|
|
info.pickBestFormat(),
|
|
info.m_format.m_usage,
|
|
info.m_inital_layout,
|
|
info.m_final_layout ) ) };
|
|
auto view_itter { m_view.emplace_back( image_itter->getView() ) };
|
|
|
|
image_itter->setName( std::format( "Swapchain image {}:{}", info.m_name, i ) );
|
|
}
|
|
}
|
|
|
|
std::shared_ptr< Texture > SwapchainImageSet::getTexture( const FrameIndex frame_index ) const
|
|
{
|
|
if ( m_texture.empty() ) m_texture.resize( constants::MAX_FRAMES_IN_FLIGHT );
|
|
|
|
if ( !m_texture[ frame_index ] )
|
|
{
|
|
Sampler default_sampler {};
|
|
m_texture[ frame_index ] =
|
|
std::make_shared< Texture >( m_image[ frame_index ], std::move( default_sampler ) );
|
|
}
|
|
|
|
return m_texture[ frame_index ];
|
|
}
|
|
|
|
std::shared_ptr< ImageView > Swapchain::depthView( const FrameIndex frame_index ) const
|
|
{
|
|
const SwapchainImageSet& set { m_depth.value() };
|
|
|
|
return set.m_view[ frame_index ];
|
|
}
|
|
|
|
std::shared_ptr< Image > Swapchain::depthImage( const FrameIndex frame_index ) const
|
|
{
|
|
return m_depth.value().m_image[ frame_index ];
|
|
}
|
|
|
|
std::shared_ptr< Texture > Swapchain::depthTexture( const FrameIndex frame_index ) const
|
|
{
|
|
return m_depth.value().getTexture( frame_index );
|
|
}
|
|
|
|
Swapchain::Swapchain( const std::vector< SwapchainImageInfo >& in )
|
|
{
|
|
for ( const SwapchainImageInfo& info : in )
|
|
{
|
|
if ( info.m_format.m_usage & vk::ImageUsageFlagBits::eDepthStencilAttachment )
|
|
m_depth.emplace( info );
|
|
else
|
|
m_swapchain_images.emplace_back( info );
|
|
}
|
|
}
|
|
} // namespace fgl::engine
|