Konstantin Koch f081f8632a two commits were missing, both by KorsarNek:
"Removed the SupportedPlatformsImpl classes and replaced them with a new SupportedPlatforms attribute on the assembly level.
Removed a few class constructors which could cause problems when loading a game.
Made ResetElapsedTime in the game class reset to 0 instead of TimeSpan.MinValue.
Removed the restriction in the InputDeviceFactory for which InputDevices are supported.
Added a Logger for Metro which works with the current Logger implementation.
Changed that when a platform is recognized that is higher than Windows 8, it gets treated like Windows 8, not like Windows 7.
Due to the SupportedPlatforms change, the assembly loader is now faster in finding out which assemblies contains addIns. For not Metro system, it's also added that a warning gets written if an AddIn references a different ANX version than that of the running assembly.
OpenGL and DirectX have been updated to the newest versions.
XAudio system uses now the same SharpDX version as all the other systems.
ParameterBuffer for WindowsMetro gets now correctly created by considering the size constraints for constant buffers.
Fixed an erroneous finalizer in the xaudio system.
Made the metro projects convert to Windows 8.1, as Windows 8.0 is not supported by the newer SharpDX versions. It's now also necessary to use at least Visual Studio 2013 to build the Metro versions.
Made the samples work again on Windows."

"Fixed the creation of the swap chain for windows metro and removed the dependency of the Metro Rendersystem onto the Metro Platformsytem.
All occurrences of WindowHandles have been replaced with a custom WindowHandle type which should work out of the box in most cases, but does still represent a breaking change to XNA.
The ProjectConverter for Metro was adjusted so that with just changing the way the application is initialized, most projects that worked with ANX before should now work under win rt. The sample SimpleNoContent does now work out of the box for win rt, after a project conversion.
The application name for win rt apps is now a guid, the display name stayed the same though. That's to be more compliant with the way win rt apps are normally created.
The default namespace and namespace of the classes for the Sample "SimpleNoContent" is renamed from "SimpleModernUI" to "SimpleNoContent".
With the new way win rt apps are initialized for ANX, it's necessary to first create the WindowsGameHost for WinRT with a handler how to create the game instance and give that to the CoreApplication object to run it.
Also took care of a few annoying bugs when working with win rt and ANX where no InputDevices could be created on the first frame (Issue #1164 ) and that it wasn't possible to use the localfolder of the application on the first update and all the other stuff for which an instance of the Application class was necessary."
2015-03-29 13:48:33 +02:00

222 lines
5.7 KiB
C#

using System;
using ANX.Framework.Graphics;
using SharpDX;
using SharpDX.Direct3D;
using Windows.Foundation;
using Dx11 = SharpDX.Direct3D11;
// This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license.
// For details see: http://anxframework.codeplex.com/license
namespace ANX.RenderSystem.Windows.Metro
{
public class NativeDxDevice : IDisposable
{
#region Private
private PresentationParameters presentationParameters;
private FeatureLevel featureLevel;
private Dx11.RenderTargetView renderTargetView;
private Dx11.DepthStencilView depthStencilView;
private SwapChainMetro swapChain;
private Dx11.Device nativeDevice;
private Dx11.DeviceContext nativeContext;
private SharpDX.ViewportF viewport;
internal Dx11.Device NativeDevice
{
get
{
return nativeDevice;
}
}
internal Dx11.DeviceContext NativeContext
{
get
{
return nativeContext;
}
}
internal Dx11.OutputMergerStage OutputMerger
{
get
{
return nativeContext.OutputMerger;
}
}
internal static NativeDxDevice Current
{
get;
private set;
}
#endregion
#region Public
public Rect RenderTargetBounds
{
get;
protected set;
}
#endregion
#region Constructor
public NativeDxDevice(PresentationParameters presentationParameters)
{
Current = this;
this.presentationParameters = presentationParameters;
swapChain = new SwapChainMetro(this, presentationParameters);
var creationFlags = Dx11.DeviceCreationFlags.VideoSupport | Dx11.DeviceCreationFlags.BgraSupport;
#if DEBUG
creationFlags |= Dx11.DeviceCreationFlags.Debug;
#endif
using (var defaultDevice = new Dx11.Device(DriverType.Hardware, creationFlags))
{
nativeDevice = defaultDevice.QueryInterface<Dx11.Device>();
}
featureLevel = NativeDevice.FeatureLevel;
nativeContext = NativeDevice.ImmediateContext.QueryInterface<Dx11.DeviceContext>();
}
#endregion
#region Resize
public void Resize(PresentationParameters presentationParameters)
{
DisposeScreenBuffers();
swapChain.ResizeOrCreate(presentationParameters);
using (var backBuffer = swapChain.CreateTexture())
{
renderTargetView = new Dx11.RenderTargetView(NativeDevice, backBuffer);
var backBufferDesc = backBuffer.Description;
RenderTargetBounds = new Rect(0, 0, backBufferDesc.Width, backBufferDesc.Height);
}
using (var depthBuffer = new Dx11.Texture2D(NativeDevice, new Dx11.Texture2DDescription()
{
Format = FormatConverter.Translate(presentationParameters.DepthStencilFormat),
ArraySize = 1,
MipLevels = 1,
Width = (int)RenderTargetBounds.Width,
Height = (int)RenderTargetBounds.Height,
SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0),
BindFlags = Dx11.BindFlags.DepthStencil,
}))
{
depthStencilView = new Dx11.DepthStencilView(NativeDevice, depthBuffer, new Dx11.DepthStencilViewDescription()
{
Dimension = Dx11.DepthStencilViewDimension.Texture2D
});
}
viewport = new SharpDX.ViewportF((float)RenderTargetBounds.X, (float)RenderTargetBounds.Y,
(float)RenderTargetBounds.Width, (float)RenderTargetBounds.Height, 0.0f, 1.0f);
SetDefaultTargets();
}
#endregion
#region ClearDepthAndStencil
public void ClearDepthAndStencil(Dx11.DepthStencilClearFlags flags, float depth, byte stencil)
{
// TODO: find better solution to lazy init the swapChain from the coreWindow!!
EnsureScreenBuffersAvailable();
nativeContext.ClearDepthStencilView(depthStencilView, flags, depth, stencil);
}
#endregion
#region SetDefaultTargets
public void SetDefaultTargets()
{
nativeContext.Rasterizer.SetViewport(viewport);
nativeContext.OutputMerger.SetTargets(depthStencilView, renderTargetView);
}
#endregion
#region Clear
public void Clear(Color4 color)
{
// TODO: find better solution to lazy init the swapChain from the coreWindow!!
EnsureScreenBuffersAvailable();
nativeContext.ClearRenderTargetView(renderTargetView, color);
}
#endregion
#region EnsureScreenBuffersAvailable
private void EnsureScreenBuffersAvailable()
{
if (renderTargetView == null)
{
Resize(presentationParameters);
}
}
#endregion
#region Present
public void Present(int interval)
{
swapChain.Present(interval);
}
#endregion
#region MapSubresource
public SharpDX.DataStream MapSubresource(Dx11.Buffer resource)
{
SharpDX.DataStream result;
nativeContext.MapSubresource(resource, Dx11.MapMode.WriteDiscard,
Dx11.MapFlags.None, out result);
return result;
}
public SharpDX.DataBox MapSubresource(Dx11.Resource resource, int subresource)
{
return nativeContext.MapSubresource(resource, subresource,
Dx11.MapMode.WriteDiscard, Dx11.MapFlags.None);
}
#endregion
#region UnmapSubresource
public void UnmapSubresource(Dx11.Resource resource, int subresource)
{
nativeContext.UnmapSubresource(resource, subresource);
}
#endregion
#region Dispose
public void Dispose()
{
DisposeScreenBuffers();
SafeDispose(ref swapChain);
SafeDispose(ref nativeDevice);
SafeDispose(ref nativeContext);
}
private void DisposeScreenBuffers()
{
SafeDispose(ref renderTargetView);
SafeDispose(ref depthStencilView);
}
private void SafeDispose<T>(ref T disposable)
where T : class, IDisposable
{
if (disposable != null)
{
disposable.Dispose();
disposable = null;
}
}
#endregion
}
}