(3dc4135ce) v0.9.5.1
This commit is contained in:
Binary file not shown.
Binary file not shown.
+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.
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Microsoft.Xna.Framework
|
||||
{
|
||||
public static class MessageBox
|
||||
{
|
||||
[Flags]
|
||||
public enum Flags : uint
|
||||
{
|
||||
Error = 0x00000010,
|
||||
Warning = 0x00000020,
|
||||
Information = 0x00000040
|
||||
}
|
||||
|
||||
public static void Show(Flags flags, string title, string message, GameWindow window = null)
|
||||
{
|
||||
Sdl.ShowSimpleMessageBox((uint)flags, title, message, window?.Handle ?? IntPtr.Zero);
|
||||
}
|
||||
|
||||
public static void ShowWrapped(Flags flags, string title, string message, int charsPerLine = 60, GameWindow window = null)
|
||||
{
|
||||
string[] split = message.Split(' ');
|
||||
if (split.Length > 0)
|
||||
{
|
||||
message = split[0];
|
||||
string currLine = message;
|
||||
for (int i = 1; i < split.Length; i++)
|
||||
{
|
||||
currLine += " " + split[i];
|
||||
if (currLine.Length > charsPerLine)
|
||||
{
|
||||
currLine = split[i];
|
||||
message += "\n" + split[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
message += " " + split[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Show(flags, title, message, window);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -30,7 +30,7 @@
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<Optimize>true</Optimize>
|
||||
<DebugType>none</DebugType>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<OutputPath>..\..\DesktopGL\</OutputPath>
|
||||
<IntermediateOutputPath>obj\Linux\AnyCPU\Release</IntermediateOutputPath>
|
||||
<DocumentationFile>..\..\DesktopGL\MonoGame.Framework.xml</DocumentationFile>
|
||||
@@ -38,6 +38,7 @@
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
@@ -45,6 +46,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Clipboard.cs" />
|
||||
<Compile Include="MessageBox.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.DesktopGL.cs">
|
||||
<Platforms>WindowsGL,Linux</Platforms>
|
||||
|
||||
@@ -81,6 +81,7 @@
|
||||
<Compile Include="Input\KeyboardUtil.SDL.cs" />
|
||||
<Compile Include="Input\Mouse.SDL.cs" />
|
||||
<Compile Include="Input\MouseCursor.SDL.cs" />
|
||||
<Compile Include="MessageBox.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.Windows.cs">
|
||||
<Platforms>Windows</Platforms>
|
||||
|
||||
@@ -255,12 +255,26 @@ internal static class Sdl
|
||||
|
||||
public static void SetClipboardText(string text)
|
||||
{
|
||||
byte[] bytes = Encoding.UTF8.GetBytes(text);
|
||||
byte[] bytes = Encoding.UTF8.GetBytes(text+"\0");
|
||||
GCHandle handle = GCHandle.Alloc(bytes, GCHandleType.Pinned);
|
||||
GetError(SDL_SetClipboardText(handle.AddrOfPinnedObject()));
|
||||
handle.Free();
|
||||
}
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
public delegate int d_sdl_showsimplemessagebox(uint flags, IntPtr title, IntPtr msg, IntPtr window);
|
||||
public static d_sdl_showsimplemessagebox SDL_ShowSimpleMessageBox = FuncLoader.LoadFunction<d_sdl_showsimplemessagebox>(NativeLibrary, "SDL_ShowSimpleMessageBox");
|
||||
public static void ShowSimpleMessageBox(uint flags, string title, string message, IntPtr window)
|
||||
{
|
||||
byte[] bytesTitle = Encoding.UTF8.GetBytes(title + "\0");
|
||||
GCHandle handleTitle = GCHandle.Alloc(bytesTitle, GCHandleType.Pinned);
|
||||
byte[] bytesMessage = Encoding.UTF8.GetBytes(message + "\0");
|
||||
GCHandle handleMessage = GCHandle.Alloc(bytesMessage, GCHandleType.Pinned);
|
||||
GetError(SDL_ShowSimpleMessageBox(flags, handleTitle.AddrOfPinnedObject(), handleMessage.AddrOfPinnedObject(), window));
|
||||
handleTitle.Free();
|
||||
handleMessage.Free();
|
||||
}
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
public delegate IntPtr d_sdl_gethint(string name);
|
||||
public static d_sdl_gethint SDL_GetHint = FuncLoader.LoadFunction<d_sdl_gethint>(NativeLibrary, "SDL_GetHint");
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user