Beispiel #1
0
        /// <summary>Resizes the scene.</summary>
        /// <param name="width">The new width for the scene.</param>
        /// <param name="height">The new height for the scene.</param>
        /// <exception cref="ArgumentOutOfRangeException">
        ///         width/height is less than zero.
        /// </exception>
        /// <exception cref="InvalidOperationException">
        ///         <see cref="CreateResources" /> has not been called.
        /// </exception>
        /// <exception cref="ObjectDisposedException">
        ///         <see cref="Dispose()" /> has been called on this instance.
        /// </exception>
        /// <exception cref="Microsoft.WindowsAPICodePack.DirectX.DirectXException">
        ///         An error occured creating device dependent resources.
        /// </exception>
        public void Resize(int width, int height)
        {
            MustNotDisposed();
            width.MustGreaterThan(0);
            height.MustGreaterThan(0);
            _device.MustNotNull("CreateResources方法未调用");

            // Recreate the render target
            CreateTexture(width, height);
            using (var surface = _texture.QueryInterface <Surface>())
            {
                CreateRenderTarget(surface);
            }

            // Resize our viewport
            var viewport = new Viewport();

            viewport.Height      = (uint)height;
            viewport.MaxDepth    = 1;
            viewport.MinDepth    = 0;
            viewport.TopLeftX    = 0;
            viewport.TopLeftY    = 0;
            viewport.Width       = (uint)width;
            _device.RS.Viewports = new[] { viewport };

            // Destroy and recreate any dependent resources declared in a
            // derived class only (i.e don't destroy our resources).
            OnFreeResources();
            OnCreateResources(_renderTarget);
        }