/// <summary> /// Disposes the control. /// </summary> protected override void Dispose(bool disposing) { if (graphicsDeviceService != null) { graphicsDeviceService.Release(disposing); graphicsDeviceService = null; } base.Dispose(disposing); }
/// <summary> /// Gets a reference to the singleton instance. /// </summary> public static XNAService AddRef(IntPtr windowHandle, int width, int height) { // Increment the "how many controls sharing the device" reference count. if (Interlocked.Increment(ref referenceCount) == 1) { // If this is the first control to start using the // device, we must create the singleton instance. singletonInstance = new XNAService(windowHandle, width, height); } return(singletonInstance); }
/// <summary> /// Initializes the control. /// </summary> protected override void OnCreateControl() { // Don't initialize the graphics device if we are running in the designer. if (!DesignMode) { graphicsDeviceService = XNAService.AddRef(Handle, Resolution.Width, Resolution.Height); // Register the service, so components like ContentManager can find it. services.AddService <IGraphicsDeviceService>(graphicsDeviceService); // Give derived classes a chance to initialize themselves. Initialize(); } base.OnCreateControl(); }