fix: Error on window resize.
This commit is contained in:
parent
5d6ddbb158
commit
3dc6501246
|
|
@ -9,10 +9,31 @@
|
|||
|
||||
struct Size2D
|
||||
{
|
||||
u32 m_Width;
|
||||
u32 m_Height;
|
||||
u32 m_Width = 0;
|
||||
u32 m_Height = 0;
|
||||
|
||||
Size2D() = default;
|
||||
|
||||
Size2D(const u32 width, const u32 height)
|
||||
: m_Width{width}
|
||||
, m_Height{height}
|
||||
{
|
||||
}
|
||||
|
||||
Size2D(const vk::Extent2D extent)
|
||||
: m_Width{extent.width}
|
||||
, m_Height{extent.height}
|
||||
{
|
||||
}
|
||||
|
||||
Size2D &
|
||||
operator=(const vk::Extent2D other)
|
||||
{
|
||||
m_Height = other.height;
|
||||
m_Width = other.width;
|
||||
return *this;
|
||||
}
|
||||
|
||||
explicit
|
||||
operator vk::Extent2D() const
|
||||
{
|
||||
return {m_Width, m_Height};
|
||||
|
|
|
|||
|
|
@ -437,10 +437,11 @@ struct Frame
|
|||
// Transient
|
||||
vk::Image m_SwapchainImage;
|
||||
vk::ImageView m_SwapchainImageView;
|
||||
Size2D m_SwapchainSize;
|
||||
u32 m_ImageIdx;
|
||||
u32 m_CommandBuffersAllocated;
|
||||
|
||||
void Reset(u32 imageIdx, vk::Image swapchainImage, vk::ImageView swapchainImageView);
|
||||
void Reset(u32 imageIdx, vk::Image swapchainImage, vk::ImageView swapchainImageView, Size2D swapchainSize);
|
||||
GraphicsContext CreateGraphicsContext();
|
||||
void WaitUntilReady();
|
||||
};
|
||||
|
|
|
|||
|
|
@ -974,7 +974,8 @@ systems::Device::GetNextFrame()
|
|||
|
||||
// Reset frame here.
|
||||
// In case swapchain was out of date, we will reset the frame next time.
|
||||
currentFrame.Reset(imageIndex, m_Swapchain.m_Images[imageIndex], m_Swapchain.m_ImageViews[imageIndex]);
|
||||
currentFrame.Reset(imageIndex, m_Swapchain.m_Images[imageIndex], m_Swapchain.m_ImageViews[imageIndex],
|
||||
m_Swapchain.m_Extent);
|
||||
|
||||
return currentFrame;
|
||||
}
|
||||
|
|
@ -1027,7 +1028,7 @@ systems::Device::Present(Frame &frame)
|
|||
}
|
||||
|
||||
void
|
||||
systems::Frame::Reset(u32 imageIdx, vk::Image swapchainImage, vk::ImageView swapchainImageView)
|
||||
systems::Frame::Reset(u32 imageIdx, vk::Image swapchainImage, vk::ImageView swapchainImageView, Size2D swapchainSize)
|
||||
{
|
||||
AbortIfFailedMV(m_Device->m_Device.resetFences(1, &m_FrameAvailableFence), "Fence {} reset failed.", m_FrameIdx);
|
||||
|
||||
|
|
@ -1037,6 +1038,7 @@ systems::Frame::Reset(u32 imageIdx, vk::Image swapchainImage, vk::ImageView swap
|
|||
m_ImageIdx = imageIdx;
|
||||
m_SwapchainImage = swapchainImage;
|
||||
m_SwapchainImageView = swapchainImageView;
|
||||
m_SwapchainSize = swapchainSize;
|
||||
}
|
||||
|
||||
systems::GraphicsContext
|
||||
|
|
|
|||
|
|
@ -83,21 +83,8 @@ main(int, char **)
|
|||
auto vbo = device.CreateVertexBuffer(vertices.size() * sizeof vertices[0], "VBO");
|
||||
vbo->Write(0, vertices.size() * sizeof vertices[0], vertices.data());
|
||||
|
||||
Size2D swapchainSize = device.GetSwapchainSize();
|
||||
// Persistent variables
|
||||
vk::Viewport viewport = {
|
||||
.x = 0,
|
||||
.y = Cast<f32>(swapchainSize.m_Height),
|
||||
.width = Cast<f32>(swapchainSize.m_Width),
|
||||
.height = -Cast<f32>(swapchainSize.m_Height),
|
||||
.minDepth = 0.0,
|
||||
.maxDepth = 1.0,
|
||||
};
|
||||
|
||||
vk::Rect2D scissor = {
|
||||
.offset = {0, 0},
|
||||
.extent = Cast<vk::Extent2D>(swapchainSize),
|
||||
};
|
||||
// Persistent variables
|
||||
|
||||
vk::ImageSubresourceRange subresourceRange = {
|
||||
.aspectMask = vk::ImageAspectFlagBits::eColor,
|
||||
|
|
@ -142,6 +129,22 @@ main(int, char **)
|
|||
{
|
||||
systems::Frame ¤tFrame = device.GetNextFrame();
|
||||
|
||||
Size2D swapchainSize = currentFrame.m_SwapchainSize;
|
||||
|
||||
vk::Viewport viewport = {
|
||||
.x = 0,
|
||||
.y = Cast<f32>(swapchainSize.m_Height),
|
||||
.width = Cast<f32>(swapchainSize.m_Width),
|
||||
.height = -Cast<f32>(swapchainSize.m_Height),
|
||||
.minDepth = 0.0,
|
||||
.maxDepth = 1.0,
|
||||
};
|
||||
|
||||
vk::Rect2D scissor = {
|
||||
.offset = {0, 0},
|
||||
.extent = Cast<vk::Extent2D>(swapchainSize),
|
||||
};
|
||||
|
||||
auto context = currentFrame.CreateGraphicsContext();
|
||||
|
||||
topOfThePipeBarrier.image = currentFrame.m_SwapchainImage;
|
||||
|
|
|
|||
Loading…
Reference in New Issue