Skip to content
This repository has been archived by the owner on Sep 7, 2024. It is now read-only.

Commit

Permalink
Handle window minimize
Browse files Browse the repository at this point in the history
  • Loading branch information
xezno committed Jul 7, 2024
1 parent ee68026 commit 39ca447
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
21 changes: 11 additions & 10 deletions Source/Mocha.Framework.Rendering/Generic/RenderStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
18 changes: 18 additions & 0 deletions Source/Mocha.Framework.Rendering/Vulkan/VulkanRenderContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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!;

Expand All @@ -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 );
Expand Down Expand Up @@ -193,6 +200,11 @@ public RenderStatus EndRendering()
return RenderStatus.BeginEndMismatch;
}

if ( IsMinimized )
{
return RenderStatus.WindowMinimized;
}

var cmd = _mainContext.CommandBuffer;

if ( IsRenderPassActive )
Expand Down Expand Up @@ -946,13 +958,19 @@ 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;
}

public RenderStatus BindRenderTarget( RenderTexture rt )
{
if ( IsMinimized )
return RenderStatus.WindowMinimized;

if ( IsRenderPassActive )
{
Vk.CmdEndRendering( _mainContext.CommandBuffer );
Expand Down

0 comments on commit 39ca447

Please sign in to comment.