Пример #1
0
        /// <summary>
        ///         Creates a DirectX 10 device and related device specific resources.
        /// </summary>
        /// <exception cref="InvalidOperationException">
        ///         A previous call to CreateResources has not been followed by a call to
        ///         <see cref="FreeResources" />.
        /// </exception>
        /// <exception cref="ObjectDisposedException">
        ///         <see cref="Dispose()" /> has been called on this instance.
        /// </exception>
        /// <exception cref="Microsoft.WindowsAPICodePack.DirectX.DirectXException">
        ///         Unable to create a DirectX 10 device or an error occured creating
        ///         device dependent resources.
        /// </exception>
        public void CreateResources()
        {
            MustNotDisposed();
            if (_device != null)
            {
                throw new InvalidOperationException(
                          "A previous call to CreateResources has not been followed by a call to FreeResources.");
            }

            // Try to create a hardware device first and fall back to a
            // software (WARP doens't let us share resources)
            D3DDevice1 device1 = TryCreateDevice1(DriverType.Hardware);

            if (device1 == null)
            {
                device1 = TryCreateDevice1(DriverType.Software);
                if (device1 == null)
                {
                    throw new DirectXException("Unable to create a DirectX 10 device.");
                }
            }
            _device = device1.QueryInterface <D3DDevice>();
            device1.Dispose();
        }