Esempio n. 1
0
        /// <summary>
        /// Attempts to begin drawing the control. Returns false if this was not possible.
        /// </summary>
        private bool BeginDraw()
        {
            // Make sure the graphics device is big enough, and is not lost.
            if (HandleDeviceResetAndSizeChanged() != ResizeResetResult.OK)
            {
                return(false);
            }

            // Multiple DirectImage instances can share the same device. The viewport is adjusted
            // for when a smaller DirectImage is rendering.
            if (surfaceType == SurfaceType.DirectX9)
            {
                Viewport viewport = new Viewport();
                viewport.X              = 0;
                viewport.Y              = 0;
                viewport.Width          = viewportWidth;
                viewport.Height         = viewportHeight;
                viewport.MinZ           = 0;
                viewport.MaxZ           = 1;
                GraphicsDevice.Viewport = viewport;
            }

            if (surfaceType == SurfaceType.Direct2D)
            {
                var viewport2D = new SharpDX.Direct3D10.Viewport();
                viewport2D.Height   = viewportHeight;
                viewport2D.MaxDepth = 1;
                viewport2D.MinDepth = 0;
                viewport2D.TopLeftX = 0;
                viewport2D.TopLeftY = 0;
                viewport2D.Width    = viewportWidth;
                graphicsDeviceService10.SetViewport(viewport2D);
            }
            return(true);
        }
Esempio n. 2
0
        /// <summary>
        /// Attempts to begin drawing the control. Returns false if this was not possible.
        /// </summary>
        private bool BeginDraw()
        {
            // Make sure the graphics device is big enough, and is not lost.
            if (HandleDeviceResetAndSizeChanged() != ResizeResetResult.OK) return false;

            // Multiple DirectImage instances can share the same device. The viewport is adjusted
            // for when a smaller DirectImage is rendering.
            if (surfaceType == SurfaceType.DirectX9)
            {
                Viewport viewport = new Viewport();
                viewport.X = 0;
                viewport.Y = 0;
                viewport.Width = viewportWidth;
                viewport.Height = viewportHeight;
                viewport.MinZ = 0;
                viewport.MaxZ = 1;
                GraphicsDevice.Viewport = viewport;
            }

            if (surfaceType == SurfaceType.Direct2D)
            {
                var viewport2D = new SharpDX.Direct3D10.Viewport();
                viewport2D.Height = viewportHeight;
                viewport2D.MaxDepth = 1;
                viewport2D.MinDepth = 0;
                viewport2D.TopLeftX = 0;
                viewport2D.TopLeftY = 0;
                viewport2D.Width = viewportWidth;
                graphicsDeviceService10.SetViewport(viewport2D);
            }
            return true;
        }