From 39ca447b331bc73b9079eba1088a6254d3f95497 Mon Sep 17 00:00:00 2001 From: Alex <12881812+xezno@users.noreply.github.com> Date: Sun, 7 Jul 2024 19:10:11 +0100 Subject: [PATCH] Handle window minimize --- .../Generic/RenderStatus.cs | 21 ++++++++++--------- .../Vulkan/VulkanRenderContext.cs | 18 ++++++++++++++++ 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/Source/Mocha.Framework.Rendering/Generic/RenderStatus.cs b/Source/Mocha.Framework.Rendering/Generic/RenderStatus.cs index 89d7ee9..17a0f3b 100644 --- a/Source/Mocha.Framework.Rendering/Generic/RenderStatus.cs +++ b/Source/Mocha.Framework.Rendering/Generic/RenderStatus.cs @@ -2,14 +2,15 @@ public enum RenderStatus { - Ok, - NotInitialized, - AlreadyInitialized, - BeginEndMismatch, - NoPipelineBound, - NoVertexBufferBound, - NoIndexBufferBound, - InvalidHandle, - ShaderCompileFailed, - WindowSizeInvalid + NotInitialized = -9, + AlreadyInitialized = -8, + BeginEndMismatch = -7, + NoPipelineBound = -6, + NoVertexBufferBound = -5, + NoIndexBufferBound = -4, + InvalidHandle = -3, + ShaderCompileFailed = -2, + WindowSizeInvalid = -1, + Ok = 0, + WindowMinimized = 1, } diff --git a/Source/Mocha.Framework.Rendering/Vulkan/VulkanRenderContext.cs b/Source/Mocha.Framework.Rendering/Vulkan/VulkanRenderContext.cs index 67eaef0..b363171 100644 --- a/Source/Mocha.Framework.Rendering/Vulkan/VulkanRenderContext.cs +++ b/Source/Mocha.Framework.Rendering/Vulkan/VulkanRenderContext.cs @@ -104,6 +104,8 @@ private void RecreatePipelines() } } + private bool IsMinimized => _window.FramebufferSize?.X == 0 || _window.FramebufferSize?.Y == 0; + private uint SwapchainImageIndex = 0; private VulkanRenderTexture SwapchainTarget = null!; @@ -115,6 +117,11 @@ public RenderStatus BeginRendering() return RenderStatus.BeginEndMismatch; } + if ( IsMinimized ) + { + return RenderStatus.WindowMinimized; + } + if ( _swapchainIsDirty ) { var newSize = _window.FramebufferSize ?? new Vector2Int( 1, 1 ); @@ -193,6 +200,11 @@ public RenderStatus EndRendering() return RenderStatus.BeginEndMismatch; } + if ( IsMinimized ) + { + return RenderStatus.WindowMinimized; + } + var cmd = _mainContext.CommandBuffer; if ( IsRenderPassActive ) @@ -946,6 +958,9 @@ public RenderStatus BindIndexBuffer( IndexBuffer ib ) public RenderStatus Draw( int vertexCount, int indexCount, int instanceCount ) { + if ( IsMinimized ) + return RenderStatus.WindowMinimized; + Vk.CmdDrawIndexed( _mainContext.CommandBuffer, (uint)indexCount, (uint)instanceCount, 0, 0, 0 ); return RenderStatus.Ok; @@ -953,6 +968,9 @@ public RenderStatus Draw( int vertexCount, int indexCount, int instanceCount ) public RenderStatus BindRenderTarget( RenderTexture rt ) { + if ( IsMinimized ) + return RenderStatus.WindowMinimized; + if ( IsRenderPassActive ) { Vk.CmdEndRendering( _mainContext.CommandBuffer );