From 32b43c2a82723458b205c0b81d6c5c89e049df0a Mon Sep 17 00:00:00 2001 From: Konstantin Koch Date: Sat, 24 Oct 2015 19:26:27 +0200 Subject: [PATCH] Added INativeGraphicsAdapter --- ANX.Framework/ANX.Framework.csproj | 1 + ANX.Framework/Graphics/GraphicsAdapter.cs | 128 +++++++++++---- .../RenderSystem/INativeGraphicsAdapter.cs | 35 ++++ .../RenderSystem/IRenderSystemCreator.cs | 2 +- .../ANX.RenderSystem.GL3.csproj | 1 + RenderSystems/ANX.Framework.GL3/Creator.cs | 53 ++---- .../ANX.Framework.GL3/GraphicsAdapterGL3.cs | 102 ++++++++++++ .../SharedGraphicsAdapter.cs | 155 ++++++++++++++++++ .../ANX.RenderSystem.Windows.DX10.csproj | 3 + .../ANX.RenderSystem.Windows.DX10/Creator.cs | 49 ++---- .../ANX.RenderSystem.Windows.DX11.csproj | 3 + .../ANX.RenderSystem.Windows.DX11/Creator.cs | 49 ++---- 12 files changed, 435 insertions(+), 146 deletions(-) create mode 100644 ANX.Framework/NonXNA/RenderSystem/INativeGraphicsAdapter.cs create mode 100644 RenderSystems/ANX.Framework.GL3/GraphicsAdapterGL3.cs create mode 100644 RenderSystems/ANX.RenderSystem.DX.SharedSources/SharedGraphicsAdapter.cs diff --git a/ANX.Framework/ANX.Framework.csproj b/ANX.Framework/ANX.Framework.csproj index 0f52a02a..092be467 100644 --- a/ANX.Framework/ANX.Framework.csproj +++ b/ANX.Framework/ANX.Framework.csproj @@ -449,6 +449,7 @@ + diff --git a/ANX.Framework/Graphics/GraphicsAdapter.cs b/ANX.Framework/Graphics/GraphicsAdapter.cs index 85927a28..3ac2358f 100644 --- a/ANX.Framework/Graphics/GraphicsAdapter.cs +++ b/ANX.Framework/Graphics/GraphicsAdapter.cs @@ -11,12 +11,25 @@ using ANX.Framework.NonXNA.Development; namespace ANX.Framework.Graphics { - [PercentageComplete(50)] - [Developer("Glatzemann")] + [PercentageComplete(100)] + [Developer("Glatzemann, KorsarNek")] [TestState(TestStateAttribute.TestState.Untested)] public sealed class GraphicsAdapter { - public static ReadOnlyCollection Adapters { get; private set; } + private static ReadOnlyCollection _adapters; + + public static ReadOnlyCollection Adapters + { + get + { + if (_adapters == null) + { + var creator = AddInSystemFactory.Instance.GetDefaultCreator(); + _adapters = new ReadOnlyCollection(creator.GetAdapterList().Select((x) => new GraphicsAdapter(x)).ToArray()); + } + return _adapters; + } + } public static GraphicsAdapter DefaultAdapter { @@ -24,49 +37,100 @@ namespace ANX.Framework.Graphics } public static bool UseNullDevice { get; set; } - public static bool UseReferenceDevice { get; set; } - public int DeviceId { get; set; } - public string DeviceName { get; set; } - public bool IsDefaultAdapter { get; set; } - public int Revision { get; set; } - public int SubSystemId { get; set; } - public int VendorId { get; set; } - public string Description { get; set; } - public DisplayMode CurrentDisplayMode { get; set; } - public DisplayModeCollection SupportedDisplayModes { get; set; } - public IntPtr MonitorHandle { get; set; } + public static bool UseReferenceDevice { get; set; } - public bool IsWideScreen - { - get - { - throw new NotImplementedException(); - } - } + private INativeGraphicsAdapter nativeAdapter; - static GraphicsAdapter() - { - var creator = AddInSystemFactory.Instance.GetDefaultCreator(); - Adapters = new ReadOnlyCollection(creator.GetAdapterList()); + #region Public + public int DeviceId + { + get { return nativeAdapter.DeviceId; } + } + + public string DeviceName + { + get { return nativeAdapter.DeviceName; } + } + + public bool IsDefaultAdapter + { + get { return nativeAdapter.IsDefaultAdapter; } + } + + public int Revision + { + get { return nativeAdapter.Revision; } + } + + public int SubSystemId + { + get { return nativeAdapter.SubSystemId; } + } + + public int VendorId + { + get { return nativeAdapter.VendorId; } + } + + public string Description + { + get { return nativeAdapter.Description; } + } + + public DisplayMode CurrentDisplayMode + { + get { return nativeAdapter.CurrentDisplayMode; } + } + + public DisplayModeCollection SupportedDisplayModes + { + get { return nativeAdapter.SupportedDisplayModes; } + } + + public IntPtr MonitorHandle + { + get { return nativeAdapter.MonitorHandle; } + } + + public bool IsWideScreen + { + get + { + return this.CurrentDisplayMode.AspectRatio > (16 / 10); + } + } + #endregion + + internal INativeGraphicsAdapter NativeAdapter + { + get { return nativeAdapter; } + } + + internal GraphicsAdapter(INativeGraphicsAdapter nativeAdapter) + { + if (nativeAdapter == null) + throw new ArgumentNullException("nativeAdapter"); + + this.nativeAdapter = nativeAdapter; } public bool IsProfileSupported(GraphicsProfile graphicsProfile) { - throw new NotImplementedException(); + return nativeAdapter.IsProfileSupported(graphicsProfile); } public bool QueryBackBufferFormat(GraphicsProfile graphicsProfile, SurfaceFormat format, DepthFormat depthFormat, - int multiSampleCount, out SurfaceFormat selectedFormat, out DepthFormat selectedDepthFormat, - out int selectedMultiSampleCount) + int multiSampleCount, out SurfaceFormat selectedFormat, out DepthFormat selectedDepthFormat, + out int selectedMultiSampleCount) { - throw new NotImplementedException(); + return nativeAdapter.QueryBackBufferFormat(graphicsProfile, format, depthFormat, multiSampleCount, out selectedFormat, out selectedDepthFormat, out selectedMultiSampleCount); } public bool QueryRenderTargetFormat(GraphicsProfile graphicsProfile, SurfaceFormat format, DepthFormat depthFormat, - int multiSampleCount, out SurfaceFormat selectedFormat, out DepthFormat selectedDepthFormat, - out int selectedMultiSampleCount) + int multiSampleCount, out SurfaceFormat selectedFormat, out DepthFormat selectedDepthFormat, + out int selectedMultiSampleCount) { - throw new NotImplementedException(); + return nativeAdapter.QueryRenderTargetFormat(graphicsProfile, format, depthFormat, multiSampleCount, out selectedFormat, out selectedDepthFormat, out selectedMultiSampleCount); } } } diff --git a/ANX.Framework/NonXNA/RenderSystem/INativeGraphicsAdapter.cs b/ANX.Framework/NonXNA/RenderSystem/INativeGraphicsAdapter.cs new file mode 100644 index 00000000..7ec8f889 --- /dev/null +++ b/ANX.Framework/NonXNA/RenderSystem/INativeGraphicsAdapter.cs @@ -0,0 +1,35 @@ +#region Using Statements +using ANX.Framework.Graphics; +using System; +#endregion + +// 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.Framework.NonXNA +{ + public interface INativeGraphicsAdapter + { + IntPtr MonitorHandle { get; } + bool IsDefaultAdapter { get; } + int Revision { get; } + int SubSystemId { get; } + int DeviceId { get; } + int VendorId { get; } + string DeviceName { get; } + string Description { get; } + DisplayMode CurrentDisplayMode { get; } + DisplayModeCollection SupportedDisplayModes { get; } + + bool IsProfileSupported(GraphicsProfile graphicsProfile); + + bool QueryBackBufferFormat(GraphicsProfile graphicsProfile, SurfaceFormat format, DepthFormat depthFormat, + int multiSampleCount, out SurfaceFormat selectedFormat, out DepthFormat selectedDepthFormat, + out int selectedMultiSampleCount); + + bool QueryRenderTargetFormat(GraphicsProfile graphicsProfile, SurfaceFormat format, DepthFormat depthFormat, + int multiSampleCount, out SurfaceFormat selectedFormat, out DepthFormat selectedDepthFormat, + out int selectedMultiSampleCount); + } +} diff --git a/ANX.Framework/NonXNA/RenderSystem/IRenderSystemCreator.cs b/ANX.Framework/NonXNA/RenderSystem/IRenderSystemCreator.cs index 449ac4c2..ce4040f0 100644 --- a/ANX.Framework/NonXNA/RenderSystem/IRenderSystemCreator.cs +++ b/ANX.Framework/NonXNA/RenderSystem/IRenderSystemCreator.cs @@ -47,7 +47,7 @@ namespace ANX.Framework.NonXNA byte[] GetShaderByteCode(PreDefinedShader type); EffectSourceLanguage GetStockShaderSourceLanguage { get; } - ReadOnlyCollection GetAdapterList(); + ReadOnlyCollection GetAdapterList(); void SetTextureSampler(int index, Texture value); } diff --git a/RenderSystems/ANX.Framework.GL3/ANX.RenderSystem.GL3.csproj b/RenderSystems/ANX.Framework.GL3/ANX.RenderSystem.GL3.csproj index d3a55066..5fd6e6c2 100644 --- a/RenderSystems/ANX.Framework.GL3/ANX.RenderSystem.GL3.csproj +++ b/RenderSystems/ANX.Framework.GL3/ANX.RenderSystem.GL3.csproj @@ -43,6 +43,7 @@ + diff --git a/RenderSystems/ANX.Framework.GL3/Creator.cs b/RenderSystems/ANX.Framework.GL3/Creator.cs index 58b092ae..075271a7 100644 --- a/RenderSystems/ANX.Framework.GL3/Creator.cs +++ b/RenderSystems/ANX.Framework.GL3/Creator.cs @@ -262,48 +262,31 @@ namespace ANX.RenderSystem.GL3 /// Get a list of available graphics adapter information. /// /// List of graphics adapters. - public ReadOnlyCollection GetAdapterList() + public ReadOnlyCollection GetAdapterList() { - AddInSystemFactory.Instance.PreventSystemChange(AddInType.RenderSystem); - - var result = new List(); - foreach (DisplayDevice device in DisplayDevice.AvailableDisplays) + AddInSystemFactory.Instance.PreventSystemChange(AddInType.RenderSystem); + + var result = new List(); + foreach (DisplayDevice device in DisplayDevice.AvailableDisplays) { var resultingModes = new List(); - foreach (string format in Enum.GetNames(typeof(SurfaceFormat))) - { - SurfaceFormat surfaceFormat = (SurfaceFormat)Enum.Parse(typeof(SurfaceFormat), format); + foreach (string format in Enum.GetNames(typeof(SurfaceFormat))) + { + SurfaceFormat surfaceFormat = (SurfaceFormat)Enum.Parse(typeof(SurfaceFormat), format); - // TODO: device.BitsPerPixel - if (surfaceFormat != SurfaceFormat.Color)//adapter.Supports(surfaceFormat) == false) - { - continue; - } + // TODO: device.BitsPerPixel + if (surfaceFormat != SurfaceFormat.Color)//adapter.Supports(surfaceFormat) == false) + { + continue; + } + } - foreach (DisplayResolution res in device.AvailableResolutions) - resultingModes.Add(new DisplayMode(res.Width, res.Height, surfaceFormat)); - } + var newAdapter = new GraphicsAdapterGL3(device, SurfaceFormat.Color); - DisplayDevice dev = DisplayDevice.GetDisplay(DisplayIndex.Default); + result.Add(newAdapter); + } - var newAdapter = new GraphicsAdapter - { - SupportedDisplayModes = new DisplayModeCollection(resultingModes), - IsDefaultAdapter = device.IsPrimary, - - // TODO: - DeviceId = 0, - DeviceName = "", - Revision = 0, - SubSystemId = 0, - VendorId = 0, - CurrentDisplayMode = new DisplayMode(dev.Width, dev.Height, SurfaceFormat.Color) - }; - - result.Add(newAdapter); - } - - return new ReadOnlyCollection(result); + return new ReadOnlyCollection(result); } #endregion diff --git a/RenderSystems/ANX.Framework.GL3/GraphicsAdapterGL3.cs b/RenderSystems/ANX.Framework.GL3/GraphicsAdapterGL3.cs new file mode 100644 index 00000000..5ac62c65 --- /dev/null +++ b/RenderSystems/ANX.Framework.GL3/GraphicsAdapterGL3.cs @@ -0,0 +1,102 @@ +using ANX.Framework.Graphics; +using ANX.Framework.NonXNA; +using OpenTK; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace ANX.RenderSystem.GL3 +{ + public class GraphicsAdapterGL3 : INativeGraphicsAdapter + { + SurfaceFormat surfaceFormat; + + public IntPtr MonitorHandle + { + get { throw new NotImplementedException(); } + } + + public bool IsDefaultAdapter + { + get { return this.DisplayDevice.IsPrimary; } + } + + public int Revision + { + get { throw new NotImplementedException(); } + } + + public int SubSystemId + { + get { throw new NotImplementedException(); } + } + + public int DeviceId + { + get { throw new NotImplementedException(); } + } + + public int VendorId + { + get { throw new NotImplementedException(); } + } + + public string DeviceName + { + get { throw new NotImplementedException(); } + } + + public string Description + { + get { throw new NotImplementedException(); } + } + + public DisplayDevice DisplayDevice + { + get; + private set; + } + + public GraphicsAdapterGL3(DisplayDevice device, SurfaceFormat surfaceFormat) + { + this.DisplayDevice = device; + this.surfaceFormat = surfaceFormat; + + List modes = new List(); + foreach (DisplayResolution res in device.AvailableResolutions) + modes.Add(new DisplayMode(res.Width, res.Height, surfaceFormat)); + + this.SupportedDisplayModes = new DisplayModeCollection(modes); + } + + public Framework.Graphics.DisplayMode CurrentDisplayMode + { + get + { + return new DisplayMode(this.DisplayDevice.Width, this.DisplayDevice.Height, surfaceFormat); + } + } + + public Framework.Graphics.DisplayModeCollection SupportedDisplayModes + { + get; + private set; + } + + public bool IsProfileSupported(Framework.Graphics.GraphicsProfile graphicsProfile) + { + throw new NotImplementedException(); + } + + public bool QueryBackBufferFormat(Framework.Graphics.GraphicsProfile graphicsProfile, Framework.Graphics.SurfaceFormat format, Framework.Graphics.DepthFormat depthFormat, int multiSampleCount, out Framework.Graphics.SurfaceFormat selectedFormat, out Framework.Graphics.DepthFormat selectedDepthFormat, out int selectedMultiSampleCount) + { + throw new NotImplementedException(); + } + + public bool QueryRenderTargetFormat(Framework.Graphics.GraphicsProfile graphicsProfile, Framework.Graphics.SurfaceFormat format, Framework.Graphics.DepthFormat depthFormat, int multiSampleCount, out Framework.Graphics.SurfaceFormat selectedFormat, out Framework.Graphics.DepthFormat selectedDepthFormat, out int selectedMultiSampleCount) + { + throw new NotImplementedException(); + } + } +} diff --git a/RenderSystems/ANX.RenderSystem.DX.SharedSources/SharedGraphicsAdapter.cs b/RenderSystems/ANX.RenderSystem.DX.SharedSources/SharedGraphicsAdapter.cs new file mode 100644 index 00000000..ca214a83 --- /dev/null +++ b/RenderSystems/ANX.RenderSystem.DX.SharedSources/SharedGraphicsAdapter.cs @@ -0,0 +1,155 @@ +using System; +using SharpDX.D3DCompiler; +using System.IO; +using System.Linq; +using ANX.Framework.Graphics; +using ANX.Framework.NonXNA; +using SharpDX.DXGI; +using System.Collections.Generic; + +#if DX10 +using Dx = SharpDX.Direct3D10; +#elif DX11 +using Dx = SharpDX.Direct3D11; +#endif + +// 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 + +#if DX10 +namespace ANX.RenderSystem.Windows.DX10 +#elif DX11 +namespace ANX.RenderSystem.Windows.DX11 +#endif +{ + public partial class DirectXGraphicsAdapter : INativeGraphicsAdapter + { + Output _output; + Adapter _adapter; + bool _isDefaultAdapter; + + #region Public + public IntPtr MonitorHandle + { + get { return _output.Description.MonitorHandle; } + } + + public bool IsDefaultAdapter + { + get { return _isDefaultAdapter; } + } + + public int Revision + { + get { return _adapter.Description.Revision; } + } + + public int SubSystemId + { + get { return _adapter.Description.SubsystemId; } + } + + public int DeviceId + { + get { return _adapter.Description.DeviceId; } + } + + public int VendorId + { + get { return _adapter.Description.VendorId; } + } + + public string DeviceName + { + get { return _output.Description.DeviceName; } + } + + public string Description + { + get { return _adapter.Description.Description; } + } + + public DisplayMode CurrentDisplayMode + { + get + { + //Display mode can change when changing resolutions. + //The output description will be automatically updated it seems, we only have the return the correct display mode. + return new DisplayMode(_output.Description.DesktopBounds.Width, _output.Description.DesktopBounds.Height, SurfaceFormat.Color); + } + } + + public DisplayModeCollection SupportedDisplayModes + { + get; + private set; + } + + public Output Output + { + get { return _output; } + } + + public Adapter Adapter + { + get { return _adapter; } + } + + public ModeDescription CurrentModeDescription + { + get + { + return _output.GetDisplayModeList(Format.R8G8B8A8_UNorm, DisplayModeEnumerationFlags.Interlaced).Where( + (x) => + { + var bounds = _output.Description.DesktopBounds; + return x.Width == bounds.Width && x.Height == bounds.Height; //TODO: Check refreshRate too. + }).FirstOrDefault(); + } + } + #endregion + + #region Constructors + public DirectXGraphicsAdapter(Adapter adapter, Output output, bool isDefaultAdapter) + { + this._adapter = adapter; + this._output = output; + this._isDefaultAdapter = isDefaultAdapter; + + List supportedModes = new List(); + var modeList = output.GetDisplayModeList(Format.R8G8B8A8_UNorm, DisplayModeEnumerationFlags.Interlaced); + foreach (ModeDescription modeDescription in modeList) + { + var displayMode = new DisplayMode(modeDescription.Width, modeDescription.Height, DxFormatConverter.Translate(modeDescription.Format)); + supportedModes.Add(displayMode); + } + + this.SupportedDisplayModes = new DisplayModeCollection(supportedModes); + } + #endregion + + public ModeDescription GetClosestMatchingMode(Dx.Device device, int width, int height) + { + ModeDescription closestMatch; + _output.GetClosestMatchingMode(device, new ModeDescription(width, height, new Rational(0, 0), Format.R8G8B8A8_UNorm), out closestMatch); + + return closestMatch; + } + + public bool IsProfileSupported(GraphicsProfile graphicsProfile) + { + throw new NotImplementedException(); + } + + public bool QueryBackBufferFormat(GraphicsProfile graphicsProfile, SurfaceFormat format, DepthFormat depthFormat, int multiSampleCount, out SurfaceFormat selectedFormat, out DepthFormat selectedDepthFormat, out int selectedMultiSampleCount) + { + throw new NotImplementedException(); + } + + public bool QueryRenderTargetFormat(GraphicsProfile graphicsProfile, SurfaceFormat format, DepthFormat depthFormat, int multiSampleCount, out SurfaceFormat selectedFormat, out DepthFormat selectedDepthFormat, out int selectedMultiSampleCount) + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/RenderSystems/ANX.RenderSystem.Windows.DX10/ANX.RenderSystem.Windows.DX10.csproj b/RenderSystems/ANX.RenderSystem.Windows.DX10/ANX.RenderSystem.Windows.DX10.csproj index 4e12c2c9..9efedd1c 100644 --- a/RenderSystems/ANX.RenderSystem.Windows.DX10/ANX.RenderSystem.Windows.DX10.csproj +++ b/RenderSystems/ANX.RenderSystem.Windows.DX10/ANX.RenderSystem.Windows.DX10.csproj @@ -66,6 +66,9 @@ ResourceMapping.cs + + SharedGraphicsAdapter.cs + diff --git a/RenderSystems/ANX.RenderSystem.Windows.DX10/Creator.cs b/RenderSystems/ANX.RenderSystem.Windows.DX10/Creator.cs index 30399f34..cc60baf2 100644 --- a/RenderSystems/ANX.RenderSystem.Windows.DX10/Creator.cs +++ b/RenderSystems/ANX.RenderSystem.Windows.DX10/Creator.cs @@ -182,56 +182,27 @@ namespace ANX.RenderSystem.Windows.DX10 #endregion #region GetAdapterList - public ReadOnlyCollection GetAdapterList() + public ReadOnlyCollection GetAdapterList() { - PreventSystemChange(); + PreventSystemChange(); - var adapterList = new List(); - var resultingModes = new List(); + var adapterList = new List(); + bool firstOutput = true; using (Factory factory = new Factory()) { - for (int i = 0; i < factory.GetAdapterCount(); i++) + foreach (Adapter adapter in factory.Adapters) { - using (Adapter adapter = factory.GetAdapter(i)) + foreach (Output output in adapter.Outputs) { - var ga = new GraphicsAdapter(); - ga.Description = adapter.Description.Description; - ga.DeviceId = adapter.Description.DeviceId; - ga.DeviceName = adapter.Description.Description; - ga.IsDefaultAdapter = i == 0; //TODO: how to set default adapter? - //ga.IsWideScreen = ; - ga.Revision = adapter.Description.Revision; - ga.SubSystemId = adapter.Description.SubsystemId; - ga.VendorId = adapter.Description.VendorId; - - resultingModes.Clear(); - - if (adapter.Outputs.Length >= 1) - { - using (Output adapterOutput = adapter.Outputs[0]) - { - var modeList = adapterOutput.GetDisplayModeList(Format.R8G8B8A8_UNorm, DisplayModeEnumerationFlags.Interlaced); - - foreach (ModeDescription modeDescription in modeList) - { - var displayMode = new DisplayMode(modeDescription.Width, modeDescription.Height, DxFormatConverter.Translate(modeDescription.Format)); - resultingModes.Add(displayMode); - } - - ga.CurrentDisplayMode = new DisplayMode(adapterOutput.Description.DesktopBounds.Width, adapterOutput.Description.DesktopBounds.Height, SurfaceFormat.Color); - ga.MonitorHandle = adapterOutput.Description.MonitorHandle; - } - } - - ga.SupportedDisplayModes = new DisplayModeCollection(resultingModes); - - adapterList.Add(ga); + //By definition, the first returned output is always the default adapter. + adapterList.Add(new DirectXGraphicsAdapter(adapter, output, firstOutput)); + firstOutput = false; } } } - return new ReadOnlyCollection(adapterList); + return new ReadOnlyCollection(adapterList); } #endregion diff --git a/RenderSystems/ANX.RenderSystem.Windows.DX11/ANX.RenderSystem.Windows.DX11.csproj b/RenderSystems/ANX.RenderSystem.Windows.DX11/ANX.RenderSystem.Windows.DX11.csproj index 2e81fc19..5c293d67 100644 --- a/RenderSystems/ANX.RenderSystem.Windows.DX11/ANX.RenderSystem.Windows.DX11.csproj +++ b/RenderSystems/ANX.RenderSystem.Windows.DX11/ANX.RenderSystem.Windows.DX11.csproj @@ -79,6 +79,9 @@ ResourceMapping.cs + + SharedGraphicsAdapter.cs + diff --git a/RenderSystems/ANX.RenderSystem.Windows.DX11/Creator.cs b/RenderSystems/ANX.RenderSystem.Windows.DX11/Creator.cs index 93f1a109..9cb957c7 100644 --- a/RenderSystems/ANX.RenderSystem.Windows.DX11/Creator.cs +++ b/RenderSystems/ANX.RenderSystem.Windows.DX11/Creator.cs @@ -187,56 +187,27 @@ namespace ANX.RenderSystem.Windows.DX11 #endregion #region GetAdapterList - public ReadOnlyCollection GetAdapterList() + public ReadOnlyCollection GetAdapterList() { - PreventSystemChange(); + PreventSystemChange(); - var adapterList = new List(); - var resultingModes = new List(); + var adapterList = new List(); + bool firstOutput = true; using (Factory factory = new Factory()) { - for (int i = 0; i < factory.GetAdapterCount(); i++) + foreach (Adapter adapter in factory.Adapters) { - using (Adapter adapter = factory.GetAdapter(i)) + foreach (Output output in adapter.Outputs) { - GraphicsAdapter ga = new GraphicsAdapter(); - ga.Description = adapter.Description.Description; - ga.DeviceId = adapter.Description.DeviceId; - ga.DeviceName = adapter.Description.Description; - ga.IsDefaultAdapter = i == 0; //TODO: how to set default adapter? - //ga.IsWideScreen = ; - ga.Revision = adapter.Description.Revision; - ga.SubSystemId = adapter.Description.SubsystemId; - ga.VendorId = adapter.Description.VendorId; - - resultingModes.Clear(); - - if (adapter.Outputs.Length >= 1) - { - using (Output adapterOutput = adapter.Outputs[0]) - { - var modeList = adapterOutput.GetDisplayModeList(Format.R8G8B8A8_UNorm, DisplayModeEnumerationFlags.Interlaced); - - foreach (ModeDescription modeDescription in modeList) - { - var displayMode = new DisplayMode(modeDescription.Width, modeDescription.Height, DxFormatConverter.Translate(modeDescription.Format)); - resultingModes.Add(displayMode); - } - - ga.CurrentDisplayMode = new DisplayMode(adapterOutput.Description.DesktopBounds.Width, adapterOutput.Description.DesktopBounds.Height, SurfaceFormat.Color); - ga.MonitorHandle = adapterOutput.Description.MonitorHandle; - } - } - - ga.SupportedDisplayModes = new DisplayModeCollection(resultingModes); - - adapterList.Add(ga); + //By definition, the first returned output is always the default adapter. + adapterList.Add(new DirectXGraphicsAdapter(adapter, output, firstOutput)); + firstOutput = false; } } } - return new System.Collections.ObjectModel.ReadOnlyCollection(adapterList); + return new ReadOnlyCollection(adapterList); } #endregion