(3dc4135ce) v0.9.5.1
This commit is contained in:
+50
-84
@@ -520,8 +520,9 @@ namespace Microsoft.Xna.Framework.Graphics
|
||||
if (_d3dContext != null)
|
||||
_d3dContext.Dispose();
|
||||
|
||||
// Windows requires BGRA support out of DX.
|
||||
var creationFlags = SharpDX.Direct3D11.DeviceCreationFlags.BgraSupport;
|
||||
// Windows requires BGRA support out of DX. (...what)
|
||||
// Barotrauma doesn't tho
|
||||
var creationFlags = SharpDX.Direct3D11.DeviceCreationFlags.None;//.BgraSupport;
|
||||
|
||||
if (GraphicsAdapter.UseDebugLayers)
|
||||
{
|
||||
@@ -545,14 +546,14 @@ namespace Microsoft.Xna.Framework.Graphics
|
||||
{
|
||||
featureLevels = new[]
|
||||
{
|
||||
// For the Reach profile, first try use the highest supported 9_X feature level
|
||||
FeatureLevel.Level_9_3,
|
||||
FeatureLevel.Level_9_2,
|
||||
FeatureLevel.Level_9_1,
|
||||
// If level 9 is not supported, then just use the highest supported level
|
||||
// Try using the highest supported level
|
||||
FeatureLevel.Level_11_0,
|
||||
FeatureLevel.Level_10_1,
|
||||
FeatureLevel.Level_10_0,
|
||||
// Then try using the highest supported 9_X feature level
|
||||
FeatureLevel.Level_9_3,
|
||||
FeatureLevel.Level_9_2,
|
||||
FeatureLevel.Level_9_1,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -583,7 +584,7 @@ namespace Microsoft.Xna.Framework.Graphics
|
||||
_d3dDevice = defaultDevice.QueryInterface<SharpDX.Direct3D11.Device>();
|
||||
}
|
||||
|
||||
// Get Direct3D 11.1 context
|
||||
// Get Direct3D 11 context
|
||||
_d3dContext = _d3dDevice.ImmediateContext.QueryInterface<SharpDX.Direct3D11.DeviceContext>();
|
||||
|
||||
// Create a new instance of GraphicsDebug because we support it on Windows platforms.
|
||||
@@ -600,24 +601,6 @@ namespace Microsoft.Xna.Framework.Graphics
|
||||
_swapChain.SetFullscreenState(false, null);
|
||||
}
|
||||
|
||||
internal void ResizeTargets()
|
||||
{
|
||||
var format = SharpDXHelper.ToFormat(PresentationParameters.BackBufferFormat);
|
||||
var descr = new ModeDescription
|
||||
{
|
||||
Format = format,
|
||||
#if WINRT
|
||||
Scaling = DisplayModeScaling.Stretched,
|
||||
#else
|
||||
Scaling = DisplayModeScaling.Unspecified,
|
||||
#endif
|
||||
Width = PresentationParameters.BackBufferWidth,
|
||||
Height = PresentationParameters.BackBufferHeight,
|
||||
};
|
||||
|
||||
_swapChain.ResizeTarget(ref descr);
|
||||
}
|
||||
|
||||
internal void GetModeSwitchedSize(out int width, out int height)
|
||||
{
|
||||
Output output = null;
|
||||
@@ -717,76 +700,59 @@ namespace Microsoft.Xna.Framework.Graphics
|
||||
format,
|
||||
PresentationParameters.MultiSampleCount);
|
||||
|
||||
// If the swap chain already exists... update it.
|
||||
if (false && _swapChain != null
|
||||
// check if multisampling hasn't changed
|
||||
&& _swapChain.Description.SampleDescription.Count == multisampleDesc.Count
|
||||
&& _swapChain.Description.SampleDescription.Quality == multisampleDesc.Quality)
|
||||
// Create a new swap chain.
|
||||
var wasFullScreen = false;
|
||||
// Dispose of old swap chain if exists
|
||||
if (_swapChain != null)
|
||||
{
|
||||
_swapChain.ResizeBuffers(2,
|
||||
PresentationParameters.BackBufferWidth,
|
||||
PresentationParameters.BackBufferHeight,
|
||||
format,
|
||||
SwapChainFlags.AllowModeSwitch);
|
||||
wasFullScreen = _swapChain.IsFullScreen;
|
||||
// Before releasing a swap chain, first switch to windowed mode
|
||||
_swapChain.SetFullscreenState(false, null);
|
||||
_swapChain.Dispose();
|
||||
}
|
||||
|
||||
// Otherwise, create a new swap chain.
|
||||
else
|
||||
// SwapChain description
|
||||
var desc = new SharpDX.DXGI.SwapChainDescription()
|
||||
{
|
||||
var wasFullScreen = false;
|
||||
// Dispose of old swap chain if exists
|
||||
if (_swapChain != null)
|
||||
ModeDescription =
|
||||
{
|
||||
wasFullScreen = _swapChain.IsFullScreen;
|
||||
// Before releasing a swap chain, first switch to windowed mode
|
||||
_swapChain.SetFullscreenState(false, null);
|
||||
_swapChain.Dispose();
|
||||
}
|
||||
|
||||
// SwapChain description
|
||||
var desc = new SharpDX.DXGI.SwapChainDescription()
|
||||
{
|
||||
ModeDescription =
|
||||
{
|
||||
Format = format,
|
||||
Format = format,
|
||||
#if WINDOWS_UAP
|
||||
Scaling = DisplayModeScaling.Stretched,
|
||||
Scaling = DisplayModeScaling.Stretched,
|
||||
#else
|
||||
Scaling = DisplayModeScaling.Unspecified,
|
||||
Scaling = DisplayModeScaling.Unspecified,
|
||||
#endif
|
||||
Width = PresentationParameters.BackBufferWidth,
|
||||
Height = PresentationParameters.BackBufferHeight,
|
||||
},
|
||||
Width = PresentationParameters.BackBufferWidth,
|
||||
Height = PresentationParameters.BackBufferHeight,
|
||||
},
|
||||
|
||||
OutputHandle = PresentationParameters.DeviceWindowHandle,
|
||||
SampleDescription = multisampleDesc,
|
||||
Usage = SharpDX.DXGI.Usage.RenderTargetOutput,
|
||||
BufferCount = 2,
|
||||
SwapEffect = SharpDXHelper.ToSwapEffect(PresentationParameters.PresentationInterval),
|
||||
IsWindowed = true,
|
||||
Flags = SwapChainFlags.AllowModeSwitch
|
||||
};
|
||||
OutputHandle = PresentationParameters.DeviceWindowHandle,
|
||||
SampleDescription = multisampleDesc,
|
||||
Usage = SharpDX.DXGI.Usage.RenderTargetOutput,
|
||||
BufferCount = 2,
|
||||
SwapEffect = SharpDXHelper.ToSwapEffect(PresentationParameters.PresentationInterval),
|
||||
IsWindowed = true
|
||||
};
|
||||
|
||||
// Once the desired swap chain description is configured, it must be created on the same adapter as our D3D Device
|
||||
// Once the desired swap chain description is configured, it must be created on the same adapter as our D3D Device
|
||||
|
||||
// First, retrieve the underlying DXGI Device from the D3D Device.
|
||||
// Creates the swap chain
|
||||
using (var dxgiDevice = _d3dDevice.QueryInterface<SharpDX.DXGI.Device1>())
|
||||
using (var dxgiAdapter = dxgiDevice.Adapter)
|
||||
using (var dxgiFactory = dxgiAdapter.GetParent<SharpDX.DXGI.Factory1>())
|
||||
{
|
||||
_swapChain = new SwapChain(dxgiFactory, dxgiDevice, desc);
|
||||
RefreshAdapter();
|
||||
dxgiFactory.MakeWindowAssociation(PresentationParameters.DeviceWindowHandle, WindowAssociationFlags.IgnoreAll);
|
||||
// To reduce latency, ensure that DXGI does not queue more than one frame at a time.
|
||||
// Docs: https://msdn.microsoft.com/en-us/library/windows/desktop/ff471334(v=vs.85).aspx
|
||||
dxgiDevice.MaximumFrameLatency = 1;
|
||||
}
|
||||
// Preserve full screen state, after swap chain is re-created
|
||||
if (PresentationParameters.HardwareModeSwitch
|
||||
&& wasFullScreen)
|
||||
SetHardwareFullscreen();
|
||||
// First, retrieve the underlying DXGI Device from the D3D Device.
|
||||
// Creates the swap chain
|
||||
using (var dxgiDevice = _d3dDevice.QueryInterface<SharpDX.DXGI.Device1>())
|
||||
using (var dxgiAdapter = dxgiDevice.Adapter)
|
||||
using (var dxgiFactory = dxgiAdapter.GetParent<SharpDX.DXGI.Factory1>())
|
||||
{
|
||||
_swapChain = new SwapChain(dxgiFactory, dxgiDevice, desc);
|
||||
RefreshAdapter();
|
||||
dxgiFactory.MakeWindowAssociation(PresentationParameters.DeviceWindowHandle, WindowAssociationFlags.IgnoreAll);
|
||||
// To reduce latency, ensure that DXGI does not queue more than one frame at a time.
|
||||
// Docs: https://msdn.microsoft.com/en-us/library/windows/desktop/ff471334(v=vs.85).aspx
|
||||
dxgiDevice.MaximumFrameLatency = 1;
|
||||
}
|
||||
// Preserve full screen state, after swap chain is re-created
|
||||
if (PresentationParameters.HardwareModeSwitch
|
||||
&& wasFullScreen)
|
||||
SetHardwareFullscreen();
|
||||
|
||||
// Obtain the backbuffer for this window which will be the final 3D rendertarget.
|
||||
Point targetSize;
|
||||
|
||||
@@ -72,7 +72,10 @@ namespace Microsoft.Xna.Framework.Graphics
|
||||
var subresourceIndex = CalculateSubresourceIndex(0, level);
|
||||
var d3dContext = GraphicsDevice._d3dContext;
|
||||
lock (d3dContext)
|
||||
{
|
||||
d3dContext.UpdateSubresource(GetTexture(), subresourceIndex, region, dataPtr, GetPitch(w), 0);
|
||||
d3dContext.GenerateMips(GetShaderResourceView());
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -390,6 +393,12 @@ namespace Microsoft.Xna.Framework.Graphics
|
||||
if (_shared)
|
||||
desc.OptionFlags |= ResourceOptionFlags.Shared;
|
||||
|
||||
if (_mipmap)
|
||||
{
|
||||
desc.OptionFlags |= ResourceOptionFlags.GenerateMipMaps;
|
||||
desc.BindFlags |= BindFlags.RenderTarget;
|
||||
}
|
||||
|
||||
return desc;
|
||||
}
|
||||
internal override Resource CreateTexture()
|
||||
@@ -403,6 +412,30 @@ namespace Microsoft.Xna.Framework.Graphics
|
||||
return new SharpDX.Direct3D11.Texture2D(GraphicsDevice._d3dDevice, desc);
|
||||
}
|
||||
|
||||
protected override ShaderResourceView CreateShaderResourceView()
|
||||
{
|
||||
var texDesc = GetTexture2DDescription();
|
||||
if (_mipmap)
|
||||
{
|
||||
ShaderResourceViewDescription resViewDesc = new ShaderResourceViewDescription()
|
||||
{
|
||||
Format = texDesc.Format,
|
||||
Dimension = SharpDX.Direct3D.ShaderResourceViewDimension.Texture2D,
|
||||
Texture2D = new ShaderResourceViewDescription.Texture2DResource()
|
||||
{
|
||||
MostDetailedMip = 0,
|
||||
MipLevels = texDesc.MipLevels
|
||||
}
|
||||
};
|
||||
|
||||
return new SharpDX.Direct3D11.ShaderResourceView(GraphicsDevice._d3dDevice, GetTexture(), resViewDesc);
|
||||
}
|
||||
else
|
||||
{
|
||||
return base.CreateShaderResourceView();
|
||||
}
|
||||
}
|
||||
|
||||
protected internal virtual SampleDescription CreateSampleDescription()
|
||||
{
|
||||
return new SampleDescription(1, 0);
|
||||
|
||||
@@ -118,6 +118,12 @@ namespace Microsoft.Xna.Framework.Graphics
|
||||
}
|
||||
GraphicsExtensions.CheckGLError();
|
||||
|
||||
if (CurrentPlatform.OS != OS.MacOSX)
|
||||
{
|
||||
GL.GenerateMipmap(GenerateMipmapTarget.Texture2D);
|
||||
GraphicsExtensions.CheckGLError();
|
||||
}
|
||||
|
||||
#if !ANDROID
|
||||
// Required to make sure that any texture uploads on a thread are completed
|
||||
// before the main thread tries to use the texture.
|
||||
|
||||
Reference in New Issue
Block a user