Skip to content

Commit

Permalink
Merge pull request #150 from Doprez/add-vsync-enabler
Browse files Browse the repository at this point in the history
Add vsync enabler
  • Loading branch information
VaclavElias authored Jul 7, 2024
2 parents 86bb2cb + cf0a493 commit a27529e
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/Stride.CommunityToolkit/Games/GameExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,22 @@ public static void SetMaxFPS(this IGame game, int targetFPS)
var gameBase = (GameBase)game;
gameBase.WindowMinimumUpdateRate.MinimumElapsedTime = TimeSpan.FromMilliseconds(1000f / targetFPS);
}

/// <summary>
/// Enables vertical synchronization (VSync) to prevent screen tearing.
/// </summary>
/// <param name="game"></param>
public static void EnableVSync(this IGame game)
{
game.GraphicsDevice.Presenter.PresentInterval = Stride.Graphics.PresentInterval.Two;
}

/// <summary>
/// Disables vertical synchronization (VSync) to allow for uncapped frame rates.
/// </summary>
/// <param name="game"></param>
public static void DisableVSync(this IGame game)
{
game.GraphicsDevice.Presenter.PresentInterval = Stride.Graphics.PresentInterval.Immediate;
}
}

0 comments on commit a27529e

Please sign in to comment.