Skip to content
This repository has been archived by the owner on Mar 30, 2019. It is now read-only.

Commit

Permalink
[Graphics] Fix #260. Force to recreate the full swapchain when going …
Browse files Browse the repository at this point in the history
…to fullscreen as It seems that DXGI is not updating correctly the refresh rate without.
  • Loading branch information
xoofx committed Feb 5, 2014
1 parent ada85b2 commit 90edaaa
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
Expand Up @@ -862,7 +862,7 @@ private void ChangeOrCreateDevice(bool forceCreate)
var newOutputIndex = graphicsDeviceInformation.PresentationParameters.PreferredFullScreenOutputIndex;

GraphicsDevice.Presenter.PrefferedFullScreenOutputIndex = newOutputIndex;
GraphicsDevice.Presenter.Resize(newWidth, newHeight, newFormat);
GraphicsDevice.Presenter.Resize(newWidth, newHeight, newFormat, graphicsDeviceInformation.PresentationParameters.RefreshRate);

// Change full screen if needed
GraphicsDevice.Presenter.IsFullScreen = graphicsDeviceInformation.PresentationParameters.IsFullScreen;
Expand Down
7 changes: 6 additions & 1 deletion Source/Toolkit/SharpDX.Toolkit.Graphics/GraphicsPresenter.cs
Expand Up @@ -134,8 +134,9 @@ public PresentInterval PresentInterval
/// <param name="width">New backbuffer width</param>
/// <param name="height">New backbuffer height</param>
/// <param name="format">Backbuffer display format.</param>
/// <param name="refreshRate"></param>
/// <returns><c>true</c> if the presenter was resized, <c>false</c> otherwise</returns>
public virtual bool Resize(int width, int height, DXGI.Format format)
public virtual bool Resize(int width, int height, Format format, Rational? refreshRate = null)
{
if (Description.BackBufferWidth == width && Description.BackBufferHeight == height && Description.BackBufferFormat == format)
{
Expand All @@ -150,6 +151,10 @@ public virtual bool Resize(int width, int height, DXGI.Format format)
Description.BackBufferWidth = width;
Description.BackBufferHeight = height;
Description.BackBufferFormat = format;
if(refreshRate.HasValue)
{
Description.RefreshRate = refreshRate.Value;
}

DefaultViewport = new ViewportF(0, 0, Description.BackBufferWidth, Description.BackBufferHeight);

Expand Down
Expand Up @@ -139,9 +139,9 @@ public override void Present()
#endif
}

public override bool Resize(int width, int height, Format format)
public override bool Resize(int width, int height, Format format, Rational? refreshRate)
{
if (!base.Resize(width, height, format)) return false;
if (!base.Resize(width, height, format, refreshRate)) return false;

// backbuffer was set externally, do not touch it
if (!allowRecreateBackBuffer) return false;
Expand Down
Expand Up @@ -110,16 +110,25 @@ public override bool IsFullScreen
bool switchToFullScreen = value;
// If going to fullscreen mode: call 1) SwapChain.ResizeTarget 2) SwapChain.IsFullScreen
var description = new ModeDescription(backBuffer.Width, backBuffer.Height, Description.RefreshRate, Description.BackBufferFormat);
if (switchToFullScreen)
if(switchToFullScreen)
{
swapChain.ResizeTarget(ref description);
swapChain.SetFullscreenState(true, output);
Description.IsFullScreen = true;
// Destroy and recreate the full swapchain in case of fullscreen switch
// It seems to be more reliable then trying to change the current swap-chain.
RemoveAndDispose(ref backBuffer);
RemoveAndDispose(ref swapChain);

swapChain = CreateSwapChain();
backBuffer = ToDispose(RenderTarget2D.New(GraphicsDevice, swapChain.GetBackBuffer<Direct3D11.Texture2D>(0)));
}
else
{
Description.IsFullScreen = false;
swapChain.IsFullScreen = false;

// call 1) SwapChain.IsFullScreen 2) SwapChain.Resize
Resize(backBuffer.Width, backBuffer.Height, backBuffer.Format);
// call 1) SwapChain.IsFullScreen 2) SwapChain.Resize
Resize(backBuffer.Width, backBuffer.Height, backBuffer.Format);
}

// If going to window mode:
if (!switchToFullScreen)
Expand Down Expand Up @@ -152,9 +161,9 @@ protected override void OnPropertyChanged(string propertyName)
}
}

public override bool Resize(int width, int height, Format format)
public override bool Resize(int width, int height, Format format, Rational? refreshRate = null)
{
if (!base.Resize(width, height, format)) return false;
if (!base.Resize(width, height, format, refreshRate)) return false;

RemoveAndDispose(ref backBuffer);

Expand Down

0 comments on commit 90edaaa

Please sign in to comment.