ResetDevice() public method

Resets the graphics device to whichever is bigger out of the specified resolution or its current size. This behavior means the device will demand-grow to the largest of all its GraphicsDeviceControl clients.
public ResetDevice ( int width, int height ) : void
width int
height int
return void
Beispiel #1
0
        void CompositionTarget_Rendering(object sender, EventArgs e)
        {
            // If we've captured the mouse, reset the cursor back to the captured position
            if (isMouseCaptured &&
                (int)mouseState.Position.X != capturedMouseX &&
                (int)mouseState.Position.Y != capturedMouseY)
            {
                NativeMethods.SetCursorPos(capturedMouseX, capturedMouseY);

                mouseState.Position = mouseState.PreviousPosition = new Point(capturedMouseClientX, capturedMouseClientY);
            }

            // If we have no graphics service, we can't draw
            if (graphicsService == null)
            {
                return;
            }

            // Get the current width and height of the control
            int width  = (int)ActualWidth;
            int height = (int)ActualHeight;

            // If the control has no width or no height, skip drawing since it's not visible
            if (width < 1 || height < 1)
            {
                return;
            }

            // Create the active viewport to which we'll render our content
            Viewport viewport = new Viewport(0, 0, width, height);

            graphicsService.GraphicsDevice.Viewport = viewport;

            // Invoke the event to render this control
            if (RenderXna != null)
            {
                RenderXna(this, new GraphicsDeviceEventArgs(graphicsService.GraphicsDevice));
            }

            // If lost control of graphics device, skip rendering
            if (graphicsService.GraphicsDevice.GraphicsDeviceStatus == GraphicsDeviceStatus.Lost)
            {
                graphicsService.ResetDevice(width, height);
                return;
            }

            if (graphicsService.GraphicsDevice.GraphicsDeviceStatus == GraphicsDeviceStatus.NotReset)
            {
                graphicsService.ResetDevice(width, height);
                return;
            }

            // Present to the screen, but only use the visible area of the back buffer
            if (graphicsService.GraphicsDevice.GraphicsDeviceStatus == GraphicsDeviceStatus.Normal)
            {
                GraphicsService.GraphicsDevice.Present();
            }
            //graphicsService.GraphicsDevice.Present(viewport.Bounds, null, hWnd);
        }