public GraphicsDeviceService() { System.Windows.Forms.Control control = new System.Windows.Forms.Panel(); deviceInformation = new GraphicsDeviceInformation() { GraphicsProfile = FeatureLevel.Level_11_0, DeviceCreationFlags = SharpDX.Direct3D11.DeviceCreationFlags.Debug, PresentationParameters = new PresentationParameters() { BackBufferFormat = SharpDX.DXGI.Format.R8G8B8A8_UNorm, DepthStencilFormat = DepthFormat.Depth32, DepthBufferShaderResource = true, BackBufferWidth = 1920, BackBufferHeight = 1080, IsFullScreen = false, RenderTargetUsage = SharpDX.DXGI.Usage.RenderTargetOutput, MultiSampleCount = MSAALevel.None, DeviceWindowHandle = control } }; FindAdapter(); graphicsDevice = GraphicsDevice.New(deviceInformation.Adapter, deviceInformation.DeviceCreationFlags); renderTarget = RenderTarget2D.New(graphicsDevice, 1920, 1080, PixelFormat.B8G8R8A8.UNorm); graphicsDevice.Presenter = new RenderTargetGraphicsPresenter(graphicsDevice, renderTarget, DepthFormat.Depth32, false); dxDevice = (Device)typeof(GraphicsDevice).GetField("Device", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(GraphicsDevice); dxContext = (DeviceContext)typeof(GraphicsDevice).GetField("Context", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(GraphicsDevice); if (DeviceCreated != null) DeviceCreated(this, EventArgs.Empty); }
public override GraphicsDevice CreateDevice(GraphicsDeviceInformation deviceInformation) { var gameWindowBackgroundXaml = gameWindow as GameWindowWindowsPhoneBackgroundXaml; if (gameWindowBackgroundXaml != null) { // We don't have anything else than the GraphicsDevice created for the XAML so return it directly. return gameWindowBackgroundXaml.GraphicsDevice; } return base.CreateDevice(deviceInformation); }
public override GraphicsDevice CreateDevice(GraphicsDeviceInformation deviceInformation) { var gameWindowBackgroundXaml = gameWindow as GameWindowPhoneBackgroundXaml; if (gameWindowBackgroundXaml != null) { // We don't have anything else than the GraphicsDevice created for the XAML so return it directly. return gameWindowBackgroundXaml.EnsureDevice(); } // Else this is a DrawingSruface var device = GraphicsDevice.New(deviceInformation.Adapter, deviceInformation.DeviceCreationFlags, deviceInformation.GraphicsProfile); CreatePresenter(device, deviceInformation.PresentationParameters); return device; }
public virtual GraphicsDevice CreateDevice(GraphicsDeviceInformation deviceInformation) { var device = GraphicsDevice.New(deviceInformation.Adapter, deviceInformation.DeviceCreationFlags, deviceInformation.GraphicsProfile); var parameters = deviceInformation.PresentationParameters; // Give a chance to gameWindow to create desired graphics presenter, otherwise - create our own. var presenter = gameWindow.CreateGraphicsPresenter(device, parameters) ?? new SwapChainGraphicsPresenter(device, parameters); device.Presenter = presenter; // Force to resize the gameWindow gameWindow.Resize(parameters.BackBufferWidth, parameters.BackBufferHeight); return(device); }
public override GraphicsDevice CreateDevice(GraphicsDeviceInformation deviceInformation) { var gameWindowBackgroundXaml = gameWindow as GameWindowPhoneBackgroundXaml; if (gameWindowBackgroundXaml != null) { // We don't have anything else than the GraphicsDevice created for the XAML so return it directly. return(gameWindowBackgroundXaml.EnsureDevice()); } // Else this is a DrawingSruface var device = GraphicsDevice.New(deviceInformation.Adapter, deviceInformation.DeviceCreationFlags, deviceInformation.GraphicsProfile); CreatePresenter(device, deviceInformation.PresentationParameters); return(device); }
private void CreateDevice(GraphicsDeviceInformation newInfo) { Utilities.Dispose(ref graphicsDevice); newInfo.PresentationParameters.IsFullScreen = isFullScreen; newInfo.PresentationParameters.PresentationInterval = SynchronizeWithVerticalRetrace ? PresentInterval.One : PresentInterval.Immediate; newInfo.DeviceCreationFlags = DeviceCreationFlags; OnPreparingDeviceSettings(this, new PreparingDeviceSettingsEventArgs(newInfo)); // this.ValidateGraphicsDeviceInformation(newInfo); GraphicsDevice = graphicsDeviceFactory.CreateDevice(newInfo); GraphicsDevice.Disposing += GraphicsDevice_Disposing; OnDeviceCreated(this, EventArgs.Empty); }
public override List<GraphicsDeviceInformation> FindBestDevices(GameGraphicsParameters prefferedParameters) { var graphicsDeviceInfos = base.FindBestDevices(prefferedParameters); // Special case where the default FindBestDevices is not working if (graphicsDeviceInfos.Count == 0) { var graphicsAdapter = GraphicsAdapter.Adapters[0]; // Iterate on each preferred graphics profile foreach (var featureLevel in prefferedParameters.PreferredGraphicsProfile) { // Check if this profile is supported. if (graphicsAdapter.IsProfileSupported(featureLevel)) { var deviceInfo = new GraphicsDeviceInformation { Adapter = graphicsAdapter, GraphicsProfile = featureLevel, PresentationParameters = { MultiSampleCount = MSAALevel.None, IsFullScreen = prefferedParameters.IsFullScreen, PresentationInterval = prefferedParameters.SynchronizeWithVerticalRetrace ? PresentInterval.One : PresentInterval.Immediate, DeviceWindowHandle = MainWindow.NativeWindow, RenderTargetUsage = Usage.BackBuffer | Usage.RenderTargetOutput } }; // Hardcoded format and refresh rate... // This is a workaround to allow this code to work inside the emulator // but this is not really robust // TODO: Check how to handle this case properly var displayMode = new DisplayMode(DXGI.Format.B8G8R8A8_UNorm, gameWindow.ClientBounds.Width, gameWindow.ClientBounds.Height, new Rational(60, 1)); AddDevice(graphicsAdapter, displayMode, deviceInfo, prefferedParameters, graphicsDeviceInfos); // If the profile is supported, we are just using the first best one break; } } } return graphicsDeviceInfos; }
private void TryAddDeviceFromOutput(GameGraphicsParameters prefferedParameters, GraphicsOutput output, GraphicsDeviceInformation deviceInfo, List <GraphicsDeviceInformation> graphicsDeviceInfos) { if (output.CurrentDisplayMode != null) { AddDevice(output.CurrentDisplayMode, deviceInfo, prefferedParameters, graphicsDeviceInfos); } if (prefferedParameters.IsFullScreen) { // Get display mode for the particular width, height, pixelformat foreach (var displayMode in output.SupportedDisplayModes) { AddDevice(displayMode, deviceInfo, prefferedParameters, graphicsDeviceInfos); } } }
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); } } }
private void TryAddDeviceFromOutput(GameGraphicsParameters prefferedParameters, GraphicsOutput output, GraphicsDeviceInformation deviceInfo, List <GraphicsDeviceInformation> graphicsDeviceInfos) { var preferredMode = new DisplayMode(prefferedParameters.PreferredBackBufferFormat, prefferedParameters.PreferredBackBufferWidth, prefferedParameters.PreferredBackBufferHeight, prefferedParameters.PreferredRefreshRate); if (prefferedParameters.IsFullScreen) { var displayMode = output.FindClosestMatchingDisplayMode(prefferedParameters.PreferredGraphicsProfile, preferredMode); AddDevice(displayMode, deviceInfo, prefferedParameters, graphicsDeviceInfos); } else { AddDevice(preferredMode, deviceInfo, prefferedParameters, graphicsDeviceInfos); } }
public override List<GraphicsDeviceInformation> FindBestDevices(GameGraphicsParameters prefferedParameters) { var gameWindowBackgroundXaml = gameWindow as GameWindowWindowsPhoneBackgroundXaml; if (gameWindowBackgroundXaml != null) { // Unlike Desktop and WinRT, the list of best devices are completely fixed in WP8 XAML // So we return a single element var deviceInfo = new GraphicsDeviceInformation { Adapter = gameWindowBackgroundXaml.GraphicsDevice.Adapter, GraphicsProfile = gameWindowBackgroundXaml.GraphicsDevice.Features.Level, PresentationParameters = gameWindowBackgroundXaml.GraphicsDevice.Presenter.Description }; return new List<GraphicsDeviceInformation>() {deviceInfo}; } return base.FindBestDevices(prefferedParameters); }
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 override GraphicsDevice CreateDevice(GraphicsDeviceInformation deviceInformation) { var gameWindowBackgroundXaml = gameWindow as GameWindowPhoneBackgroundXaml; if (gameWindowBackgroundXaml != null) { // We don't have anything else than the GraphicsDevice created for the XAML so return it directly. return(gameWindowBackgroundXaml.EnsureDevice()); } // Else this is a DrawingSruface var device = GraphicsDevice.New(deviceInformation.Adapter, deviceInformation.DeviceCreationFlags, deviceInformation.GraphicsProfile); var renderTargetDesc = new Texture2DDescription { Format = Format.B8G8R8A8_UNorm, Width = (int)deviceInformation.PresentationParameters.BackBufferWidth, Height = (int)deviceInformation.PresentationParameters.BackBufferHeight, ArraySize = 1, MipLevels = 1, BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource, Usage = ResourceUsage.Default, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.SharedKeyedmutex | ResourceOptionFlags.SharedNthandle, SampleDescription = new DXGI.SampleDescription(1, 0) }; var backBuffer = RenderTarget2D.New(device, renderTargetDesc); var graphicsPresenter = new RenderTargetGraphicsPresenter(device, backBuffer, deviceInformation.PresentationParameters.DepthStencilFormat, true); device.Presenter = graphicsPresenter; var gameWindowXaml = (GameWindowPhoneXaml)gameWindow; gameWindowXaml.CreateSynchronizedTexture(backBuffer); return(device); }
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); } } }
public override List<GraphicsDeviceInformation> FindBestDevices(GameGraphicsParameters prefferedParameters) { var gameWindowBackgroundXaml = gameWindow as GameWindowPhoneBackgroundXaml; if (gameWindowBackgroundXaml != null) { // Make sure that we have the single graphics device created by the BackgroundXaml gameWindowBackgroundXaml.RequestDepthFormat = prefferedParameters.PreferredDepthStencilFormat; var graphicsDevice = gameWindowBackgroundXaml.EnsureDevice(); // Unlike Desktop and WinRT, the list of best devices are completely fixed in WP8 XAML // So we return a single element var deviceInfo = new GraphicsDeviceInformation { Adapter = graphicsDevice.Adapter, GraphicsProfile = graphicsDevice.Features.Level, PresentationParameters = graphicsDevice.Presenter.Description }; return new List<GraphicsDeviceInformation>() { deviceInfo }; } return base.FindBestDevices(prefferedParameters); }
public override GraphicsDevice CreateDevice(GraphicsDeviceInformation deviceInformation) { var gameWindowBackgroundXaml = gameWindow as GameWindowPhoneBackgroundXaml; if (gameWindowBackgroundXaml != null) { // We don't have anything else than the GraphicsDevice created for the XAML so return it directly. return gameWindowBackgroundXaml.EnsureDevice(); } // Else this is a DrawingSruface var device = GraphicsDevice.New(deviceInformation.Adapter, deviceInformation.DeviceCreationFlags, deviceInformation.GraphicsProfile); var renderTargetDesc = new Texture2DDescription { Format = Format.B8G8R8A8_UNorm, Width = (int)deviceInformation.PresentationParameters.BackBufferWidth, Height = (int)deviceInformation.PresentationParameters.BackBufferHeight, ArraySize = 1, MipLevels = 1, BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource, Usage = ResourceUsage.Default, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.SharedKeyedmutex | ResourceOptionFlags.SharedNthandle, SampleDescription = new DXGI.SampleDescription(1, 0) }; var backBuffer = RenderTarget2D.New(device, renderTargetDesc); var graphicsPresenter = new RenderTargetGraphicsPresenter(device, backBuffer, deviceInformation.PresentationParameters.DepthStencilFormat, true); device.Presenter = graphicsPresenter; var gameWindowXaml = (GameWindowPhoneXaml)gameWindow; gameWindowXaml.CreateSynchronizedTexture(backBuffer); return device; }
public virtual GraphicsDevice CreateDevice(GraphicsDeviceInformation deviceInformation) { var device = GraphicsDevice.New(deviceInformation.Adapter, deviceInformation.DeviceCreationFlags); device.Presenter = new SwapChainGraphicsPresenter(device, deviceInformation.PresentationParameters); // Force to resize the gameWindow gameWindow.Resize(deviceInformation.PresentationParameters.BackBufferWidth, deviceInformation.PresentationParameters.BackBufferHeight); return device; }
public GraphicsDeviceService(System.Windows.Forms.Form form) { var ad = GraphicsAdapter.Default; deviceInformation = new GraphicsDeviceInformation() { GraphicsProfile = FeatureLevel.Level_11_0, DeviceCreationFlags = SharpDX.Direct3D11.DeviceCreationFlags.Debug, PresentationParameters = new PresentationParameters() { BackBufferFormat = SharpDX.DXGI.Format.R8G8B8A8_UNorm, DepthStencilFormat = DepthFormat.Depth32, DepthBufferShaderResource = true, BackBufferWidth = form.Width, BackBufferHeight = form.Height, IsFullScreen = false, RenderTargetUsage = SharpDX.DXGI.Usage.RenderTargetOutput, MultiSampleCount = MSAALevel.None, DeviceWindowHandle = form } }; FindAdapter(); graphicsDevice = GraphicsDevice.New(deviceInformation.Adapter, deviceInformation.DeviceCreationFlags); graphicsDevice.Presenter = new SwapChainGraphicsPresenter(graphicsDevice, deviceInformation.PresentationParameters); dxDevice = (Device)typeof(GraphicsDevice).GetField("Device", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(GraphicsDevice); dxContext = (DeviceContext)typeof(GraphicsDevice).GetField("Context", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(GraphicsDevice); this.Form = form; if (DeviceCreated != null) DeviceCreated(this, EventArgs.Empty); }
/// <summary> /// Initializes a new instance of the <see cref="PreparingDeviceSettingsEventArgs" /> class. /// </summary> /// <param name="graphicsDeviceInformation">The graphics device information.</param> public PreparingDeviceSettingsEventArgs(GraphicsDeviceInformation graphicsDeviceInformation) { GraphicsDeviceInformation = graphicsDeviceInformation; }
public virtual GraphicsDevice CreateDevice(GraphicsDeviceInformation deviceInformation) { var device = GraphicsDevice.New(deviceInformation.Adapter, deviceInformation.DeviceCreationFlags, deviceInformation.GraphicsProfile); var parameters = deviceInformation.PresentationParameters; CreatePresenter(device, parameters); // Force to resize the gameWindow gameWindow.Resize(parameters.BackBufferWidth, parameters.BackBufferHeight); return device; }
private void CreateDevice(GraphicsDeviceInformation newInfo) { if (GraphicsDevice != null) { try { GraphicsDevice.Dispose(); } catch { } GraphicsDevice = null; } // newInfo.PresentationParameters.Windowed = !isFullScreen; // newInfo.PresentationParameters.PresentationInterval = SynchronizeWithVerticalRetrace ? PresentInterval.One : PresentInterval.Immediate; newInfo.DeviceCreationFlags = DeviceCreationFlags; OnPreparingDeviceSettings(this, new PreparingDeviceSettingsEventArgs(newInfo)); // this.ValidateGraphicsDeviceInformation(newInfo); GraphicsDevice = game.GamePlatform.CreateDevice(newInfo); GraphicsAdapter = newInfo.Adapter; GraphicsDevice.Viewport = new Viewport(0, 0, newInfo.PresentationParameters.BackBufferWidth, newInfo.PresentationParameters.BackBufferHeight); /* GraphicsDevice.DeviceResetting += GraphicsDevice_DeviceResetting; GraphicsDevice.DeviceReset += GraphicsDevice_DeviceReset; GraphicsDevice.DeviceLost += GraphicsDevice_DeviceLost; */ GraphicsDevice.Disposing += GraphicsDevice_Disposing; OnDeviceCreated(this, EventArgs.Empty); }
public virtual GraphicsDevice CreateDevice(GraphicsDeviceInformation deviceInformation) { var device = GraphicsDevice.New(deviceInformation.Adapter, deviceInformation.DeviceCreationFlags); device.Presenter = new SwapChainGraphicsPresenter(device, deviceInformation.PresentationParameters); return device; }
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); } }
/// <summary> /// Determines whether this instance is compatible with the the specified new <see cref="GraphicsDeviceInformation"/>. /// </summary> /// <param name="newDeviceInfo">The new device info.</param> /// <returns><c>true</c> if this instance this instance is compatible with the the specified new <see cref="GraphicsDeviceInformation"/>; otherwise, <c>false</c>.</returns> protected virtual bool CanResetDevice(GraphicsDeviceInformation newDeviceInfo) { // By default, a reset is compatible when we stay under the same graphics profile. return(GraphicsDevice.Features.Level == newDeviceInfo.GraphicsProfile); }
/// <summary> /// Determines whether this instance is compatible with the the specified new <see cref="GraphicsDeviceInformation"/>. /// </summary> /// <param name="newDeviceInfo">The new device info.</param> /// <returns><c>true</c> if this instance this instance is compatible with the the specified new <see cref="GraphicsDeviceInformation"/>; otherwise, <c>false</c>.</returns> protected virtual bool CanResetDevice(GraphicsDeviceInformation newDeviceInfo) { // By default, a reset is compatible when we stay under the same graphics profile. return GraphicsDevice.Features.Level == newDeviceInfo.GraphicsProfile; }
private void TryAddDeviceFromOutput(GameGraphicsParameters prefferedParameters, GraphicsOutput output, GraphicsDeviceInformation deviceInfo, List<GraphicsDeviceInformation> graphicsDeviceInfos) { var preferredMode = new DisplayMode(prefferedParameters.PreferredBackBufferFormat, prefferedParameters.PreferredBackBufferWidth, prefferedParameters.PreferredBackBufferHeight, prefferedParameters.PreferredRefreshRate); if (prefferedParameters.IsFullScreen) { var displayMode = output.FindClosestMatchingDisplayMode(prefferedParameters.PreferredGraphicsProfile, preferredMode); AddDevice(displayMode, deviceInfo, prefferedParameters, graphicsDeviceInfos); } else { AddDevice(preferredMode, deviceInfo, prefferedParameters, graphicsDeviceInfos); } }
/// <summary> /// Initializes a new instance of the <see cref="PreparingDeviceSettingsEventArgs" /> class. /// </summary> /// <param name="graphicsDeviceInformation">The graphics device information.</param> public PreparingDeviceSettingsEventArgs(GraphicsDeviceInformation graphicsDeviceInformation) { GraphicsDeviceInformation = graphicsDeviceInformation; }
public GraphicsDevice CreateDevice(GraphicsDeviceInformation deviceInformation) { gameWindowDesktop.Control.ClientSize = new System.Drawing.Size(deviceInformation.PresentationParameters.BackBufferWidth, deviceInformation.PresentationParameters.BackBufferHeight); return base.CreateDevice(deviceInformation); }
//private void CreateDevice() //{ // _dxDevice = new Device(DriverType.Hardware, DeviceCreationFlags.BgraSupport, FeatureLevel.Level_10_0); // GraphicsDevice = GraphicsDevice.New(_dxDevice); // if (DeviceCreated != null) DeviceCreated(this, EventArgs.Empty); //} private void CreateDevice(System.Windows.Forms.Control control) { _deviceInformation = new GraphicsDeviceInformation() { GraphicsProfile = FeatureLevel.Level_11_0, DeviceCreationFlags = SharpDX.Direct3D11.DeviceCreationFlags.Debug, PresentationParameters = new PresentationParameters() { BackBufferFormat = SharpDX.DXGI.Format.R8G8B8A8_UNorm, DepthStencilFormat = DepthFormat.Depth24Stencil8, BackBufferWidth = 0, BackBufferHeight = 0, IsFullScreen = false, RenderTargetUsage = SharpDX.DXGI.Usage.RenderTargetOutput, MultiSampleCount = MSAALevel.None, DeviceWindowHandle = control } }; FindAdapter(); GraphicsDevice = GraphicsDevice.New(_deviceInformation.Adapter, _deviceInformation.DeviceCreationFlags); //GraphicsDevice.Presenter = new SwapChainGraphicsPresenter(GraphicsDevice, _deviceInformation.PresentationParameters); _dxDevice = (Device) typeof(GraphicsDevice).GetField("Device",BindingFlags.Instance | BindingFlags.NonPublic).GetValue(GraphicsDevice); if (DeviceCreated != null) DeviceCreated(this, EventArgs.Empty); }
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); } }
public virtual SharpDX.Direct3D9.Device CreateDevice(GraphicsDeviceInformation deviceInformation) { //var device = //GraphicsDevice.New(deviceInformation.Adapter, deviceInformation.DeviceCreationFlags); // Create Device //SharpDX.Direct3D9.Direct3D direct3D = new SharpDX.Direct3D9.Direct3D(); PresentParameters p = deviceInformation.PresentationParameters; p.DeviceWindowHandle = MainWindow.NativeWindow.Handle; deviceInformation.PresentationParameters = p; SharpDX.Direct3D9.Device device = null; //try { device = new SharpDX.Direct3D9.Device(GraphicsAdapter.D3D, deviceInformation.Adapter.AdapterOrdinal, DeviceType.Hardware, p.DeviceWindowHandle, CreateFlags.HardwareVertexProcessing | CreateFlags.Multithreaded, deviceInformation.PresentationParameters); } /*catch { } */ //device.Presenter = new SwapChainGraphicsPresenter(device, deviceInformation.PresentationParameters); return device; }
public virtual List<GraphicsDeviceInformation> FindBestDevices(GameGraphicsParameters prefferedParameters) { var graphicsDeviceInfos = new List<GraphicsDeviceInformation>(); // Iterate on each adapter foreach (var graphicsAdapter in GraphicsAdapter.Adapters) { // Iterate on each preferred graphics profile foreach (var featureLevel in prefferedParameters.PreferredGraphicsProfile) { // Check if this profile is supported. if (graphicsAdapter.IsProfileSupported(featureLevel)) { var deviceInfo = new GraphicsDeviceInformation { Adapter = graphicsAdapter, GraphicsProfile = featureLevel, PresentationParameters = new PresentParameters() { MultiSampleQuality = 0, Windowed = !prefferedParameters.IsFullScreen, PresentationInterval = prefferedParameters.SynchronizeWithVerticalRetrace ? PresentInterval.One : PresentInterval.Immediate, DeviceWindowHandle = MainWindow.NativeWindow.Handle, } }; if (graphicsAdapter.CurrentDisplayMode.Format != Format.Unknown) { 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); } } // If the profile is supported, we are just using the first best one break; } } } return graphicsDeviceInfos; }
public virtual List<GraphicsDeviceInformation> FindBestDevices(GameGraphicsParameters prefferedParameters) { var graphicsDeviceInfos = new List<GraphicsDeviceInformation>(); // Iterate on each adapter foreach (var graphicsAdapter in GraphicsAdapter.Adapters) { // Iterate on each preferred graphics profile foreach (var featureLevel in prefferedParameters.PreferredGraphicsProfile) { // Check if this profile is supported. if (graphicsAdapter.IsProfileSupported(featureLevel)) { var deviceInfo = new GraphicsDeviceInformation { Adapter = graphicsAdapter, GraphicsProfile = featureLevel, PresentationParameters = { MultiSampleCount = MSAALevel.None, IsFullScreen = prefferedParameters.IsFullScreen, PresentationInterval = prefferedParameters.SynchronizeWithVerticalRetrace ? PresentInterval.One : PresentInterval.Immediate, DeviceWindowHandle = Window.NativeWindow, RenderTargetUsage = Usage.BackBuffer | Usage.RenderTargetOutput } }; 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); } } // If the profile is supported, we are just using the first best one break; } } } return graphicsDeviceInfos; }
private void TryAddDeviceFromOutput(GameGraphicsParameters prefferedParameters, GraphicsOutput output, GraphicsDeviceInformation deviceInfo, List<GraphicsDeviceInformation> graphicsDeviceInfos) { if (output.CurrentDisplayMode != null) AddDevice(output.CurrentDisplayMode, deviceInfo, prefferedParameters, graphicsDeviceInfos); if (prefferedParameters.IsFullScreen) { // Get display mode for the particular width, height, pixelformat foreach (var displayMode in output.SupportedDisplayModes) AddDevice(displayMode, deviceInfo, prefferedParameters, graphicsDeviceInfos); } }
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); }
/// <summary> /// Determines whether this instance is compatible with the the specified new <see cref="GraphicsDeviceInformation"/>. /// </summary> /// <param name="newDeviceInfo">The new device info.</param> /// <returns><c>true</c> if this instance this instance is compatible with the the specified new <see cref="GraphicsDeviceInformation"/>; otherwise, <c>false</c>.</returns> protected virtual bool CanResetDevice(GraphicsDeviceInformation newDeviceInfo) { return GraphicsAdapter.AdapterOrdinal == newDeviceInfo.Adapter.AdapterOrdinal; // By default, a reset is compatible when we stay under the same graphics profile. //return GraphicsDevice.Features.Level == newDeviceInfo.GraphicsProfile; //return true; }
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); }
public virtual GraphicsDevice CreateDevice(GraphicsDeviceInformation deviceInformation) { var device = GraphicsDevice.New(deviceInformation.Adapter, deviceInformation.DeviceCreationFlags, deviceInformation.GraphicsProfile); var parameters = deviceInformation.PresentationParameters; // Give a chance to gameWindow to create desired graphics presenter, otherwise - create our own. var presenter = gameWindow.CreateGraphicsPresenter(device, parameters) ?? new SwapChainGraphicsPresenter(device, parameters); device.Presenter = presenter; // Force to resize the gameWindow gameWindow.Resize(parameters.BackBufferWidth, parameters.BackBufferHeight); return device; }
private void CreateDevice(GraphicsDeviceInformation newInfo) { Utilities.Dispose(ref graphicsDevice); newInfo.PresentationParameters.IsFullScreen = isFullScreen; newInfo.PresentationParameters.PresentationInterval = SynchronizeWithVerticalRetrace ? PresentInterval.One : PresentInterval.Immediate; newInfo.DeviceCreationFlags = DeviceCreationFlags; OnPreparingDeviceSettings(this, new PreparingDeviceSettingsEventArgs(newInfo)); // this.ValidateGraphicsDeviceInformation(newInfo); GraphicsDevice = graphicsDeviceFactory.CreateDevice(newInfo); GraphicsDevice.Disposing += GraphicsDevice_Disposing; OnDeviceCreated(this, EventArgs.Empty); }
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); } } }
public override GraphicsDevice CreateDevice(GraphicsDeviceInformation deviceInformation) { // We don't have anything else than the GraphicsDevice created for the XAML so return it directly. return gameWindowWP8.GraphicsDevice; }
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); } }