Example #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="DirectX.DirectXException">
        /// An error occured creating device dependent resources.
        /// </exception>
        public void Resize(int width, int height)
        {
            this.ThrowIfDisposed();
            if (width < 0)
            {
                throw new ArgumentOutOfRangeException("width", "Value must be positive.");
            }
            if (height < 0)
            {
                throw new ArgumentOutOfRangeException("height", "Value must be positive.");
            }
            if (this.device == null)
            {
                throw new InvalidOperationException("CreateResources has not been called.");
            }

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

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

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

            // Destroy and recreate any dependent resources declared in a
            // derived class only (i.e don't destroy our resources).
            this.OnFreeResources();
            this.OnCreateResources();
        }
Example #2
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="DirectX.DirectXException">
        /// An error occured creating device dependent resources.
        /// </exception>
        public void Resize(int width, int height)
        {
            this.ThrowIfDisposed();
            if (width < 0)
            {
                throw new ArgumentOutOfRangeException("width", "Value must be positive.");
            }
            if (height < 0)
            {
                throw new ArgumentOutOfRangeException("height", "Value must be positive.");
            }
            if (this.device == null)
            {
                throw new InvalidOperationException("CreateResources has not been called.");
            }

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

            // Resize our viewport
            var viewport = new D3D10.Viewport();
            viewport.Height = (uint)height;
            viewport.MaxDepth = 1;
            viewport.MinDepth = 0;
            viewport.TopLeftX = 0;
            viewport.TopLeftY = 0;
            viewport.Width = (uint)width;
            this.device.RS.Viewports = new D3D10.Viewport[] { viewport };

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