How to use IGraphicsDeviceManager in XNA


In this mini-article I will be talking about how to implement IGraphicsDeviceManager.

You can implement IGraphicsDeviceManager interface:

1.gif
 
With this way.After you implemented there will be some functions and events added automatically:

#region IGraphicsDeviceManager Members

public new bool BeginDraw()
{
  throw new NotImplementedException();
}

public void CreateDevice()
{
  throw new NotImplementedException();
}

public new void EndDraw()
{
  throw new NotImplementedException();
}

#endregion

BeginDraw function runs after Draw and before EndDraw.

CreateDevice is the most important function in this interface.

If you have experience on Managed DirectX or Native C++ and DirectX then you will know that before working with DirectX we must create a device and register it.

In generally CreateDevice function isnt implemented but you should know that before Draw Function CreateDevice works so that we can work with Graphics Processes.

CreateDevice function called to ensure that the device manager has created a valid device.

If you get an error while running just like one of these exceptions:

NoSuitableGraphicsDeviceException  
InvalidOperationException
ArgumentException

Know that you got problem registering a device.To solve these problems:

NoSuitableGraphicsDeviceException

One of the following conditions has occurred:
  • Could not find a Direct3D device that has a Direct3D9-level driver and supports a minimum of Pixel Shader Model 1.1.
  • Could not find a Direct3D device compatible with the current device preferences.
  • The process of ranking devices removed all compatible devices.
  • Direct3D hardware acceleration is not available or has been disabled. Verify that a Direct3D-enabled graphics device is installed, and check the display properties to verify that Hardware acceleration is set to Full.
  • Remote Desktop is in use. Direct3D is not available when you are using Remote Desktop.
InvalidOperationException

This graphics device manager has not been added to "Services" and registered as the graphics device manager for the application. Device settings cannot be changed or committed unless the device has been registered.

ArgumentException

Invalid arguments have been requested for the creation of the graphics device.

Invalid back buffer options have been requested:
  • BackBufferFormat is not valid. Try SurfaceFormat.Bgr565, SurfaceFormat.Bgr555, SurfaceFormat.Bgra5551, SurfaceFormat.Bgr32, SurfaceFormat.Color, SurfaceFormat.Bgra1010102. 
  • The selected BackBufferFormat and IsFullScreen values are not valid for the selected adapter format and device type. 
  • The BackBufferWidth and BackBufferHeight values do not correspond to a valid display mode. 
Invalid PresentationParameters.PresentationInterval option has been requested: 
  • On Xbox 360, PresentationParameters.PresentationInterval has been assigned the invalid value PresentInterval.Four. 
Invalid depth stencil options have been requested:
  • Multiple PresentationParameters have been specified but BackBufferFormat, BackBufferWidth, and BackBufferHeight are not the same for all adapters. 
IsFullScreen is true, but:
  • BackBufferWidth and BackBufferHeight are not nonzero. 
  • PresentationInterval is not one of the following: PresentInterval.Default, PresentInterval.Immediate, PresentInterval.One, PresentInterval.TwoPresentInterval.Three, or PresentInterval.Four. 
  • The selected adapter does not support the selected full screen PresentationInterval. 
IsFullScreen is false, but:
  • PresentationInterval is not one of the following: PresentInterval.Default, PresentInterval.Immediate, or PresentInterval.One. 


Similar Articles