/// <summary> /// Initializes all adapters with the specified factory. /// </summary> /// <param name="factory1">The factory1.</param> internal static void Initialize() { if (staticCollector != null) { staticCollector.Dispose(); } else staticCollector = new DisposeCollector(); if (D3D != null) { D3D.Dispose(); D3D = null; } D3D = new Direct3D9.Direct3D(); var adapters = new List<GraphicsAdapter>(); for (int i = 0; i < D3D.AdapterCount; i++) { var adapter = new GraphicsAdapter(i); staticCollector.Collect(adapter); adapters.Add(adapter); } Default = adapters[0]; Adapters = adapters.ToArray(); }
public ModeInfo(GraphicsAdapter adapter, int outputIndex, bool isFullScreen, int width, int height) { Adapter = adapter; OutputIndex = outputIndex; IsFullScreen = isFullScreen; Width = width; Height = height; }
/// <summary> /// Initializes a new instance of <see cref="GraphicsOutput" />. /// </summary> /// <param name="adapter">The adapter.</param> /// <param name="output">The DXGI <see cref="Output" /> counterpart of this instance.</param> /// <exception cref="System.ArgumentNullException">output</exception> /// <exception cref="ArgumentOutOfRangeException">Is thrown when <paramref name="outputOrdinal" /> is less than zero.</exception> /// <exception cref="ArgumentNullException">Is thrown when <paramref name="output" /> is null.</exception> internal GraphicsOutput(GraphicsAdapter adapter, Output output) { if(adapter == null) throw new ArgumentNullException("adapter"); if (output == null) throw new ArgumentNullException("output"); this.adapter = adapter; this.output = ToDispose(output); outputDescription = output.Description; }
/// <summary> /// Initializes all adapters with the specified factory. /// </summary> /// <param name="factory1">The factory1.</param> internal static void Initialize(Factory1 factory1) { if (staticCollector != null) { staticCollector.Dispose(); } staticCollector = new DisposeCollector(); Factory = factory1; staticCollector.Collect(Factory); int countAdapters = Factory.GetAdapterCount1(); var adapters = new List<GraphicsAdapter>(); for (int i = 0; i < countAdapters; i++) { var adapter = new GraphicsAdapter(i); staticCollector.Collect(adapter); adapters.Add(adapter); } Default = adapters[0]; Adapters = adapters.ToArray(); }
protected void AddDevice(GraphicsAdapter graphicsAdapter, DisplayMode mode, GraphicsDeviceInformation deviceBaseInfo, GameGraphicsParameters prefferedParameters, List<GraphicsDeviceInformation> graphicsDeviceInfos) { var deviceInfo = deviceBaseInfo.Clone(); deviceInfo.PresentationParameters.RefreshRate = mode.RefreshRate; if (prefferedParameters.IsFullScreen) { deviceInfo.PresentationParameters.BackBufferWidth = mode.Width; deviceInfo.PresentationParameters.BackBufferHeight = mode.Height; } else { deviceInfo.PresentationParameters.BackBufferWidth = prefferedParameters.PreferredBackBufferWidth; deviceInfo.PresentationParameters.BackBufferHeight = prefferedParameters.PreferredBackBufferHeight; } // TODO: Handle BackBufferFormat / multisampling / depthstencil format deviceInfo.PresentationParameters.BackBufferFormat = prefferedParameters.PreferredBackBufferFormat; deviceInfo.PresentationParameters.DepthStencilFormat = prefferedParameters.PreferredDepthStencilFormat; deviceInfo.PresentationParameters.MultiSampleCount = MSAALevel.None; if (!graphicsDeviceInfos.Contains(deviceInfo)) { graphicsDeviceInfos.Add(deviceInfo); } }
protected void AddDeviceWithDefaultDisplayMode(GameGraphicsParameters prefferedParameters, GraphicsAdapter graphicsAdapter, GraphicsDeviceInformation deviceInfo, List<GraphicsDeviceInformation> graphicsDeviceInfos) { var displayMode = new DisplayMode(DXGI.Format.B8G8R8A8_UNorm, gameWindow.ClientBounds.Width, gameWindow.ClientBounds.Height, new Rational(60, 1)); AddDevice(displayMode, deviceInfo, prefferedParameters, graphicsDeviceInfos); }
private void TryAddDeviceWithDisplayMode(GameGraphicsParameters prefferedParameters, GraphicsAdapter graphicsAdapter, GraphicsDeviceInformation deviceInfo, List<GraphicsDeviceInformation> graphicsDeviceInfos) { // if we want to switch to fullscreen, try to find only needed output, otherwise check them all if (prefferedParameters.IsFullScreen) { if (prefferedParameters.PreferredFullScreenOutputIndex < graphicsAdapter.OutputsCount) { var output = graphicsAdapter.GetOutputAt(prefferedParameters.PreferredFullScreenOutputIndex); TryAddDeviceFromOutput(prefferedParameters, output, deviceInfo, graphicsDeviceInfos); } } else { for (var i = 0; i < graphicsAdapter.OutputsCount; i++) { var output = graphicsAdapter.GetOutputAt(i); TryAddDeviceFromOutput(prefferedParameters, output, deviceInfo, graphicsDeviceInfos); } } }
private GraphicsDeviceInformation CreateGraphicsDeviceInformation(GameGraphicsParameters prefferedParameters, GraphicsAdapter graphicsAdapter, FeatureLevel featureLevel) { return new GraphicsDeviceInformation { Adapter = graphicsAdapter, GraphicsProfile = featureLevel, PresentationParameters = { MultiSampleCount = MSAALevel.None, IsFullScreen = prefferedParameters.IsFullScreen, PreferredFullScreenOutputIndex = prefferedParameters.PreferredFullScreenOutputIndex, DepthBufferShaderResource = prefferedParameters.DepthBufferShaderResource, PresentationInterval = prefferedParameters.SynchronizeWithVerticalRetrace ? PresentInterval.One : PresentInterval.Immediate, DeviceWindowHandle = MainWindow.NativeWindow, RenderTargetUsage = Usage.BackBuffer | Usage.RenderTargetOutput } }; }
protected void TryFindSupportedFeatureLevel(GameGraphicsParameters prefferedParameters, GraphicsAdapter graphicsAdapter, List<GraphicsDeviceInformation> graphicsDeviceInfos, AddDeviceToListDelegate addDelegate) { // Check if the adapter has an output with the preffered index if (prefferedParameters.IsFullScreen && graphicsAdapter.OutputsCount <= prefferedParameters.PreferredFullScreenOutputIndex) return; // Iterate on each preferred graphics profile foreach (var featureLevel in prefferedParameters.PreferredGraphicsProfile) { // Check if this profile is supported. if (graphicsAdapter.IsProfileSupported(featureLevel)) { var deviceInfo = CreateGraphicsDeviceInformation(prefferedParameters, graphicsAdapter, featureLevel); addDelegate(prefferedParameters, graphicsAdapter, deviceInfo, graphicsDeviceInfos); // If the profile is supported, we are just using the first best one break; } } }
/// <summary> /// Appends the information about current graphics adapter and its output and adds it to the list of available graphics modes /// </summary> /// <param name="sb">Where to write the information</param> /// <param name="adapter">The adapter whose information needs to be analyzed</param> private void AppendAdapterInfo(StringBuilder sb, GraphicsAdapter adapter) { var adapterDescription = adapter.Description; // general adapter information sb.AppendLine(adapterDescription.Description); // onboard video RAM sb.AppendFormat("VRAM : {0}MiB{1}", ToMB(adapterDescription.DedicatedVideoMemory), Environment.NewLine); // OS RAM dedicated to the adapter (typical for integrated GPUs) sb.AppendFormat("Dedicated OS RAM : {0}MiB{1}", ToMB(adapterDescription.DedicatedSystemMemory), Environment.NewLine); // OS RAM that can be shared with the adapter (for example, 'Turbo Cache' for NVidia GPUs) sb.AppendFormat("Shared OS RAM : {0}MiB{1}", ToMB(adapterDescription.SharedSystemMemory), Environment.NewLine); // iterate trough all outputs attached to this adapter for (var i = 0; i < adapter.OutputsCount; i++) { // write its information var output = adapter.GetOutputAt(i); sb.AppendFormat("Output {0}; ", i); var description = ((Output)output).Description; var desktopBounds = description.DesktopBounds; sb.AppendFormat("{0}; Attached to desktop: {1}; Desktop bounds: ({2},{3}; {4},{5}); ", description.DeviceName, description.IsAttachedToDesktop, desktopBounds.Left, desktopBounds.Top, desktopBounds.Right, desktopBounds.Bottom); sb.AppendLine(); sb.Append("\tCurrent display mode: "); // if there is a display mode - write its information and add it in the list of available modes var currentDisplayMode = output.CurrentDisplayMode; if (currentDisplayMode != null) { if (availableModes.Count < 10) { var modeInfo = new ModeInfo(adapter, i, true, desktopBounds.Width, desktopBounds.Height); availableModes.Add(modeInfo); } sb.AppendFormat("{0}x{1}@{2}, {3}", currentDisplayMode.Width, currentDisplayMode.Height, currentDisplayMode.RefreshRate.Numerator / currentDisplayMode.RefreshRate.Denominator, currentDisplayMode.Format); } else { sb.Append("null"); } sb.AppendLine(); } }
/// <summary> /// Dispose all statically cached value by this instance. /// </summary> public new static void Dispose() { lock(staticLock) { Utilities.Dispose(ref staticCollector); adapters = null; defaultAdapter = null; isInitialized = false; } }
/// <summary> /// Initializes all adapters with the specified factory. /// </summary> /// <param name="factory1">The factory1.</param> internal static void Initialize(Factory1 factory1) { if (staticCollector != null) { staticCollector.Dispose(); } staticCollector = new DisposeCollector(); defaultFactory = factory1; staticCollector.Collect(defaultFactory); int countAdapters = defaultFactory.GetAdapterCount1(); var adapterList = new List<GraphicsAdapter>(); for (int i = 0; i < countAdapters; i++) { var adapter = new GraphicsAdapter(i); staticCollector.Collect(adapter); adapterList.Add(adapter); } defaultAdapter = adapterList.Count > 0 ? adapterList[0] : null; adapters = adapterList.ToArray(); }
protected void AddDevice(GraphicsAdapter graphicsAdapter, DisplayMode mode, GraphicsDeviceInformation deviceBaseInfo, GameGraphicsParameters prefferedParameters, List<GraphicsDeviceInformation> graphicsDeviceInfos) { var deviceInfo = deviceBaseInfo.Clone(); PresentParameters p = new PresentParameters(); p.InitDefaults(); p.FullScreenRefreshRateInHz = mode.RefreshRate; if (prefferedParameters.IsFullScreen) { p.BackBufferWidth = prefferedParameters.PreferredBackBufferWidth; p.BackBufferHeight = prefferedParameters.PreferredBackBufferHeight; p.Windowed = false; } else { p.BackBufferWidth = prefferedParameters.PreferredBackBufferWidth; p.BackBufferHeight = prefferedParameters.PreferredBackBufferHeight; p.Windowed = true; p.FullScreenRefreshRateInHz = 0; } p.DeviceWindowHandle = MainWindow.NativeWindow.Handle; p.AutoDepthStencilFormat = prefferedParameters.PreferredDepthStencilFormat; p.MultiSampleQuality = 0; p.PresentationInterval = prefferedParameters.SynchronizeWithVerticalRetrace ? PresentInterval.One : PresentInterval.Immediate; p.SwapEffect = SwapEffect.Discard; p.PresentFlags = PresentFlags.Video; deviceInfo.PresentationParameters = p; deviceInfo.Adapter = GraphicsAdapter.Adapters[prefferedParameters.PreferredVideoAdapter]; if (!graphicsDeviceInfos.Contains(deviceInfo)) { graphicsDeviceInfos.Add(deviceInfo); } }
public GenericGraphicsDevice(Device existingDevice, GraphicsAdapter adapter = null) : base(existingDevice, adapter) { }
public GenericGraphicsDevice(GraphicsAdapter adapter, DeviceCreationFlags flags = DeviceCreationFlags.None, params FeatureLevel[] featureLevels) : base(adapter, flags, featureLevels) { }
private void TryAddDeviceWithDisplayMode(GameGraphicsParameters prefferedParameters, GraphicsAdapter graphicsAdapter, GraphicsDeviceInformation deviceInfo, List<GraphicsDeviceInformation> graphicsDeviceInfos) { if (graphicsAdapter.CurrentDisplayMode != null) AddDevice(graphicsAdapter, graphicsAdapter.CurrentDisplayMode, deviceInfo, prefferedParameters, graphicsDeviceInfos); if (prefferedParameters.IsFullScreen) { // Get display mode for the particular width, height, pixelformat foreach (var displayMode in graphicsAdapter.SupportedDisplayModes) AddDevice(graphicsAdapter, displayMode, deviceInfo, prefferedParameters, graphicsDeviceInfos); } }