Helper class responsible for creating and managing the GraphicsDevice. All GraphicsDeviceControl instances share the same GraphicsDeviceService, so even though there can be many controls, there will only ever be a single underlying GraphicsDevice. This implements the standard IGraphicsDeviceService interface, which provides notification events for when the device is reset or disposed.
상속: IGraphicsDeviceService
예제 #1
0
        private void OnUnloaded(object sender, RoutedEventArgs e)
        {
            if (_graphicsDeviceService != null)
            {
                RemoveBackBufferReference();

                CompositionTarget.Rendering -= OnCompositionTargetRendering;

                _graphicsDeviceService.DeviceResetting -= OnGraphicsDeviceServiceDeviceResetting;
                _graphicsDeviceService = null;

                DeviceService.EndD3D();
            }
        }
예제 #2
0
        /// <summary>
        /// Unload the DrawingSurface's content.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DrawingSurface_Unloaded(Object sender, System.Windows.RoutedEventArgs e)
        {
            if (IsInDesignMode)
                return;

            if (this.graphicsDeviceService != null)
            {
                // Remove back buffer references by disposing it
                this.DisposeBackBuffer();
                CompositionTarget.Rendering -= this.RenderSurface;

                // Remove events from graphics device service
                this.graphicsDeviceService.DeviceResetting -= this.GraphicsDeviceService_DeviceResetting;
                this.graphicsDeviceService = null;

                DeviceService.EndD3D();
            }
        }
예제 #3
0
        private void OnLoaded(object sender, RoutedEventArgs e)
        {
            if (_graphicsDeviceService == null)
            {
                DeviceService.StartD3D(Window.GetWindow(this));

                // We use a render target, so the back buffer dimensions don't matter.
                _graphicsDeviceService = GraphicsDeviceService.AddRef(1, 1);
                _graphicsDeviceService.DeviceResetting += OnGraphicsDeviceServiceDeviceResetting;

                // Invoke the LoadContent event
                RaiseLoadContent(new GraphicsDeviceEventArgs(_graphicsDeviceService.GraphicsDevice));

                EnsureRenderTarget();

                CompositionTarget.Rendering += OnCompositionTargetRendering;

                _contentNeedsRefresh = true;
            }
        }
예제 #4
0
        /// <summary>
        /// Load the DrawingSurface's content.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DrawingSurface_Loaded(Object sender, System.Windows.RoutedEventArgs e)
        {
            if (IsInDesignMode)
                return;

            if (this.graphicsDeviceService == null)
            {
                DeviceService.StartD3D(Window.GetWindow(this));

                this.graphicsDeviceService = GraphicsDeviceService.AddRef(new WindowInteropHelper(Application.Current.MainWindow).Handle, 1, 1);
                this.graphicsDeviceService.DeviceResetting += GraphicsDeviceService_DeviceResetting;

                if (this.LoadContent != null)
                    this.LoadContent(this, new GraphicsDeviceEventArgs(this.GraphicsDevice));

                this.CreateRenderTarget();

                CompositionTarget.Rendering += this.RenderSurface;

                this.needsRefresh = true;
            }
        }