Skip to content

Commit

Permalink
[Engine] Game: read from RenderingSettings only during PrepareContext()
Browse files Browse the repository at this point in the history
  • Loading branch information
xen2 committed Jun 15, 2020
1 parent 521c5d6 commit ecfdcdc
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions sources/engine/Stride.Engine/Engine/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -303,29 +303,22 @@ public override void ConfirmRenderingSettings(bool gameCreation)
if (!AutoLoadDefaultSettings) return;

var renderingSettings = Settings?.Configurations.Get<RenderingSettings>();
if (renderingSettings == null) return;

var deviceManager = (GraphicsDeviceManager)graphicsDeviceManager;

if (gameCreation)
{
//execute the following steps only when the game is still at creation stage

deviceManager.PreferredGraphicsProfile = Context.RequestedGraphicsProfile = new[] { renderingSettings.DefaultGraphicsProfile };

//if our device height is actually smaller then requested we use the device one
deviceManager.PreferredBackBufferHeight = Context.RequestedHeight = Math.Min(renderingSettings.DefaultBackBufferHeight, Window.ClientBounds.Height);
//if our device width is actually smaller then requested we use the device one
deviceManager.PreferredBackBufferWidth = Context.RequestedWidth = Math.Min(renderingSettings.DefaultBackBufferWidth, Window.ClientBounds.Width);
//if our device width or height is actually smaller then requested we use the device one
deviceManager.PreferredBackBufferWidth = Context.RequestedWidth = Math.Min(deviceManager.PreferredBackBufferWidth, Window.ClientBounds.Width);
deviceManager.PreferredBackBufferHeight = Context.RequestedHeight = Math.Min(deviceManager.PreferredBackBufferHeight, Window.ClientBounds.Height);
}

//these might get triggered even during game runtime, resize, orientation change

if (renderingSettings.AdaptBackBufferToScreen)
if (renderingSettings != null && renderingSettings.AdaptBackBufferToScreen)
{
var deviceAr = Window.ClientBounds.Width / (float)Window.ClientBounds.Height;

if (renderingSettings.DefaultBackBufferHeight > renderingSettings.DefaultBackBufferWidth)
if (deviceManager.PreferredBackBufferHeight > deviceManager.PreferredBackBufferWidth)
{
deviceManager.PreferredBackBufferWidth = Context.RequestedWidth = (int)(deviceManager.PreferredBackBufferHeight * deviceAr);
}
Expand Down

0 comments on commit ecfdcdc

Please sign in to comment.