Skip to content

Commit

Permalink
Inline ApplyChanges() (#2231)
Browse files Browse the repository at this point in the history
* ApplyChanges block

* inline ApplyChanges()

* remove duplicate code

* place an assert, to test CreateDevice() from ApplyChanges()
  • Loading branch information
nkast authored Feb 22, 2025
1 parent 9a2e7ea commit d644c6b
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 6 deletions.
25 changes: 23 additions & 2 deletions Platforms/Game/.Android/ConcreteGraphicsDeviceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,27 @@ public override void CreateDevice()

this.GraphicsDevice = new GraphicsDevice(GraphicsAdapter.DefaultAdapter, GraphicsProfile, this.PreferHalfPixelOffset, pp);

this.ApplyChanges();
// ApplyChanges
{
// Trigger a change in orientation in case the supported orientations have changed
androidGameWindow.SetOrientation(base.Game.Window.CurrentOrientation, false);

base.GraphicsDevice.PresentationParameters.DisplayOrientation = base.Game.Window.CurrentOrientation;

// TODO: check if the PreferredBackBufferWidth/Hight is supported and throw an error similar to fullscreen Windows Desktop
base.GraphicsDevice.PresentationParameters.BackBufferWidth = surfaceView.Width;
base.GraphicsDevice.PresentationParameters.BackBufferHeight = surfaceView.Height;

if (!((IPlatformGraphicsContext)((IPlatformGraphicsDevice)base.GraphicsDevice).Strategy.MainContext).Strategy.IsRenderTargetBound)
{
PresentationParameters pp2 = this.GraphicsDevice.PresentationParameters;
base.GraphicsDevice.Viewport = new Viewport(0, 0, pp2.BackBufferWidth, pp2.BackBufferHeight);
base.GraphicsDevice.ScissorRectangle = new Rectangle(0, 0, pp2.BackBufferWidth, pp2.BackBufferHeight);
}

TouchPanel.DisplayWidth = base.GraphicsDevice.PresentationParameters.BackBufferWidth;
TouchPanel.DisplayHeight = base.GraphicsDevice.PresentationParameters.BackBufferHeight;
}

// TODO: In XNA this seems to be done as part of the GraphicsDevice.DeviceReset event...
// we need to get those working.
Expand Down Expand Up @@ -141,7 +161,8 @@ public override void ApplyChanges()
{
if (base.GraphicsDevice == null)
{
// TODO: Calling ApplyChanges() before Game Initialize should create the device.
// TODO: Calling ApplyChanges() before Game.Initialize() should create the device.
System.Diagnostics.Debug.Assert(false);
//this.CreateDevice();
return;
}
Expand Down
25 changes: 23 additions & 2 deletions Platforms/Game/.CardboardLegacy/ConcreteGraphicsDeviceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,27 @@ public override void CreateDevice()

this.GraphicsDevice = new GraphicsDevice(GraphicsAdapter.DefaultAdapter, GraphicsProfile, this.PreferHalfPixelOffset, pp);

this.ApplyChanges();
// ApplyChanges
{
// Trigger a change in orientation in case the supported orientations have changed
androidGameWindow.SetOrientation(base.Game.Window.CurrentOrientation, false);

base.GraphicsDevice.PresentationParameters.DisplayOrientation = base.Game.Window.CurrentOrientation;

// TODO: check if the PreferredBackBufferWidth/Hight is supported and throw an error similar to fullscreen Windows Desktop
base.GraphicsDevice.PresentationParameters.BackBufferWidth = surfaceView.Width;
base.GraphicsDevice.PresentationParameters.BackBufferHeight = surfaceView.Height;

if (!((IPlatformGraphicsContext)((IPlatformGraphicsDevice)base.GraphicsDevice).Strategy.MainContext).Strategy.IsRenderTargetBound)
{
PresentationParameters pp2 = this.GraphicsDevice.PresentationParameters;
base.GraphicsDevice.Viewport = new Viewport(0, 0, pp2.BackBufferWidth, pp2.BackBufferHeight);
base.GraphicsDevice.ScissorRectangle = new Rectangle(0, 0, pp2.BackBufferWidth, pp2.BackBufferHeight);
}

TouchPanel.DisplayWidth = base.GraphicsDevice.PresentationParameters.BackBufferWidth;
TouchPanel.DisplayHeight = base.GraphicsDevice.PresentationParameters.BackBufferHeight;
}

// TODO: In XNA this seems to be done as part of the GraphicsDevice.DeviceReset event...
// we need to get those working.
Expand Down Expand Up @@ -141,7 +161,8 @@ public override void ApplyChanges()
{
if (base.GraphicsDevice == null)
{
// TODO: Calling ApplyChanges() before Game Initialize should create the device.
// TODO: Calling ApplyChanges() before Game.Initialize() should create the device.
System.Diagnostics.Debug.Assert(false);
//this.CreateDevice();
return;
}
Expand Down
15 changes: 13 additions & 2 deletions Platforms/Game/.iOS/ConcreteGraphicsDeviceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,17 @@ public override void CreateDevice()

this.GraphicsDevice = new GraphicsDevice(GraphicsAdapter.DefaultAdapter, GraphicsProfile, this.PreferHalfPixelOffset, pp);

this.ApplyChanges();
// ApplyChanges
{
base.GraphicsDevice.PresentationParameters.DisplayOrientation = base.Game.Window.CurrentOrientation;

bool isLandscape = ((base.Game.Window.CurrentOrientation & (DisplayOrientation.LandscapeLeft | DisplayOrientation.LandscapeRight)) != 0);
int w = PreferredBackBufferWidth;
int h = PreferredBackBufferHeight;

base.GraphicsDevice.PresentationParameters.BackBufferWidth = isLandscape ? Math.Max(w, h) : Math.Min(w, h);
base.GraphicsDevice.PresentationParameters.BackBufferHeight = isLandscape ? Math.Min(w, h) : Math.Max(w, h);
}

// TODO: In XNA this seems to be done as part of the GraphicsDevice.DeviceReset event...
// we need to get those working.
Expand All @@ -130,7 +140,8 @@ public override void ApplyChanges()
{
if (base.GraphicsDevice == null)
{
// TODO: Calling ApplyChanges() before Game Initialize should create the device.
// TODO: Calling ApplyChanges() before Game.Initialize() should create the device.
System.Diagnostics.Debug.Assert(false);
//this.CreateDevice();
return;
}
Expand Down

0 comments on commit d644c6b

Please sign in to comment.