1 #region Using Statements
3 using System.Threading;
4 using Microsoft.Xna.Framework;
5 using Microsoft.Xna.Framework.Graphics;
8 #pragma warning disable 67
24 static int referenceCount;
28 PresentationParameters parameters;
32 public event EventHandler<EventArgs> DeviceCreated;
33 public event EventHandler<EventArgs> DeviceDisposing;
34 public event EventHandler<EventArgs> DeviceReset;
35 public event EventHandler<EventArgs> DeviceResetting;
45 get {
return graphicsDevice; }
55 parameters =
new PresentationParameters();
57 parameters.BackBufferWidth = Math.Max(width, 1);
58 parameters.BackBufferHeight = Math.Max(height, 1);
59 parameters.BackBufferFormat = SurfaceFormat.Rgba64;
60 parameters.DepthStencilFormat = DepthFormat.Depth24;
61 parameters.DeviceWindowHandle = windowHandle;
63 parameters.PresentationInterval = PresentInterval.Default;
64 parameters.IsFullScreen =
false;
65 parameters.MultiSampleCount = 0;
67 graphicsDevice =
new GraphicsDevice(GraphicsAdapter.DefaultAdapter,
68 GraphicsProfile.HiDef,
81 if (Interlocked.Increment(ref referenceCount) == 1)
96 if (Interlocked.Decrement(ref referenceCount) == 0)
101 if (DeviceDisposing != null)
102 DeviceDisposing(
this, EventArgs.Empty);
104 graphicsDevice.Dispose();
107 graphicsDevice = null;
119 if (DeviceResetting != null)
120 DeviceResetting(
this, EventArgs.Empty);
122 parameters.BackBufferWidth = Math.Max(parameters.BackBufferWidth, width);
123 parameters.BackBufferHeight = Math.Max(parameters.BackBufferHeight, height);
125 graphicsDevice.Reset(parameters);
127 if (DeviceReset != null)
128 DeviceReset(
this, EventArgs.Empty);