Table of Contents

Class GraphicsDeviceManager

Namespace
Microsoft.Xna.Framework
Assembly
MonoGame.Framework.dll

Used to initialize and control the presentation of the graphics device.

public class GraphicsDeviceManager : IGraphicsDeviceService, IDisposable, IGraphicsDeviceManager
Inheritance
GraphicsDeviceManager
Implements
Inherited Members

Constructors

GraphicsDeviceManager(Game)

Associates this graphics device manager to a game instances.

public GraphicsDeviceManager(Game game)

Parameters

game Game

The game instance to attach.

Fields

DefaultBackBufferHeight

The default back buffer height.

public static readonly int DefaultBackBufferHeight

Field Value

int

DefaultBackBufferWidth

The default back buffer width.

public static readonly int DefaultBackBufferWidth

Field Value

int

Properties

GraphicsDevice

Returns the graphics device for this manager.

public GraphicsDevice GraphicsDevice { get; }

Property Value

GraphicsDevice

GraphicsProfile

The profile which determines the graphics feature level.

public GraphicsProfile GraphicsProfile { get; set; }

Property Value

GraphicsProfile

HardwareModeSwitch

Gets or sets the boolean which defines how window switches from windowed to fullscreen state. "Hard" mode(true) is slow to switch, but more effecient for performance, while "soft" mode(false) is vice versa. The default value is true.

public bool HardwareModeSwitch { get; set; }

Property Value

bool

IsFullScreen

Indicates the desire to switch into fullscreen mode.

public bool IsFullScreen { get; set; }

Property Value

bool

Remarks

When called at startup this will automatically set fullscreen mode during initialization. If set after startup you must call ApplyChanges() for the fullscreen mode to be changed. Note that for some platforms that do not support windowed modes this property has no affect.

PreferHalfPixelOffset

Indicates if DX9 style pixel addressing or current standard pixel addressing should be used. This flag is set to false by default. It should be set to true for XNA compatibility. It is recommended to leave this flag set to false for projects that are not ported from XNA. This value is passed to UseHalfPixelOffset.

public bool PreferHalfPixelOffset { get; set; }

Property Value

bool

Remarks

XNA uses DirectX9 for its graphics. DirectX9 interprets UV coordinates differently from other graphics API's. This is typically referred to as the half-pixel offset. MonoGame replicates XNA behavior if this flag is set to true.

PreferMultiSampling

Indicates the desire for a multisampled back buffer.

public bool PreferMultiSampling { get; set; }

Property Value

bool

Remarks

When called at startup this will automatically set the MSAA mode during initialization. If set after startup you must call ApplyChanges() for the MSAA mode to be changed.

PreferredBackBufferFormat

Indicates the desired back buffer color format.

public SurfaceFormat PreferredBackBufferFormat { get; set; }

Property Value

SurfaceFormat

Remarks

When called at startup this will automatically set the format during initialization. If set after startup you must call ApplyChanges() for the format to be changed.

PreferredBackBufferHeight

Indicates the desired back buffer height in pixels.

public int PreferredBackBufferHeight { get; set; }

Property Value

int

Remarks

When called at startup this will automatically set the height during initialization. If set after startup you must call ApplyChanges() for the height to be changed.

PreferredBackBufferWidth

Indicates the desired back buffer width in pixels.

public int PreferredBackBufferWidth { get; set; }

Property Value

int

Remarks

When called at startup this will automatically set the width during initialization. If set after startup you must call ApplyChanges() for the width to be changed.

PreferredDepthStencilFormat

Indicates the desired depth-stencil buffer format.

public DepthFormat PreferredDepthStencilFormat { get; set; }

Property Value

DepthFormat

Remarks

The depth-stencil buffer format defines the scene depth precision and stencil bits available for effects during rendering. When called at startup this will automatically set the format during initialization. If set after startup you must call ApplyChanges() for the format to be changed.

SupportedOrientations

Indicates the desired allowable display orientations when the device is rotated.

public DisplayOrientation SupportedOrientations { get; set; }

Property Value

DisplayOrientation

Remarks

This property only applies to mobile platforms with automatic display rotation. When called at startup this will automatically apply the supported orientations during initialization. If set after startup you must call ApplyChanges() for the supported orientations to be changed.

SynchronizeWithVerticalRetrace

Indicates the desire for vsync when presenting the back buffer.

public bool SynchronizeWithVerticalRetrace { get; set; }

Property Value

bool

Remarks

Vsync limits the frame rate of the game to the monitor referesh rate to prevent screen tearing. When called at startup this will automatically set the vsync mode during initialization. If set after startup you must call ApplyChanges() for the vsync mode to be changed. Depending on a user's video card settings, vsync settings can be ignored and cause unexpected behaviour in frame rate.

Methods

ApplyChanges()

Applies any pending property changes to the graphics device.

public void ApplyChanges()

BeginDraw()

Begins the drawing process.

public bool BeginDraw()

Returns

bool

true if the drawing process begins successfully; false otherwise.

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

Dispose(bool)

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

EndDraw()

Ends the drawing process and calls Present() for the current graphics device.

public void EndDraw()

~GraphicsDeviceManager()

protected ~GraphicsDeviceManager()

OnDeviceCreated(EventArgs)

Called when a GraphicsDevice is created. Raises the DeviceCreated event.

protected void OnDeviceCreated(EventArgs e)

Parameters

e EventArgs

OnDeviceDisposing(EventArgs)

Called when a GraphicsDevice is disposed. Raises the DeviceDisposing event.

protected void OnDeviceDisposing(EventArgs e)

Parameters

e EventArgs

OnDeviceReset(EventArgs)

Called after a GraphicsDevice is reset. Raises the DeviceReset event.

protected void OnDeviceReset(EventArgs e)

Parameters

e EventArgs

OnDeviceResetting(EventArgs)

Called before a GraphicsDevice is reset. Raises the DeviceResetting event.

protected void OnDeviceResetting(EventArgs e)

Parameters

e EventArgs

ToggleFullScreen()

Toggles between windowed and fullscreen modes.

public void ToggleFullScreen()

Remarks

Note that on platforms that do not support windowed modes this has no affect.

Events

DeviceCreated

Raised when a new GraphicsDevice has been created.

public event EventHandler<EventArgs> DeviceCreated

Event Type

EventHandler<EventArgs>

DeviceDisposing

Raised when the GraphicsDevice is disposed.

public event EventHandler<EventArgs> DeviceDisposing

Event Type

EventHandler<EventArgs>

DeviceReset

Raised when the GraphicsDevice has reset.

public event EventHandler<EventArgs> DeviceReset

Event Type

EventHandler<EventArgs>
See Also

DeviceResetting

Raised before the GraphicsDevice is resetting.

public event EventHandler<EventArgs> DeviceResetting

Event Type

EventHandler<EventArgs>

Disposed

Raised when this GraphicsDeviceManager is disposed.

public event EventHandler<EventArgs> Disposed

Event Type

EventHandler<EventArgs>

PreparingDeviceSettings

Raised by ApplyChanges(). Allows users to override the PresentationParameters to pass to the GraphicsDevice.

public event EventHandler<PreparingDeviceSettingsEventArgs> PreparingDeviceSettings

Event Type

EventHandler<PreparingDeviceSettingsEventArgs>