コード例 #1
0
        private DxgiSampleDesc CheckMultisamplingSupport()
        {
            DxgiSampleDesc sampleDesc = new DxgiSampleDesc(1, 0);

            D3D11FormatSupport formatSupport;

            if (this.d3dDevice.CheckFormatSupport(DxgiFormat.B8G8R8A8UNorm, out formatSupport))
            {
                return(sampleDesc);
            }

            if (!formatSupport.HasFlag(D3D11FormatSupport.MultisampleResolve | D3D11FormatSupport.MultisampleRenderTarget))
            {
                return(sampleDesc);
            }

            for (uint i = 2; i <= D3D11Constants.MaxMultisampleSampleCount; i *= 2)
            {
                uint numQualityLevels;

                if (!this.d3dDevice.CheckMultisampleQualityLevels(DxgiFormat.B8G8R8A8UNorm, i, out numQualityLevels))
                {
                    if (numQualityLevels > 0)
                    {
                        sampleDesc.Count   = i;
                        sampleDesc.Quality = numQualityLevels - 1;
                    }
                }
            }

            return(sampleDesc);
        }
コード例 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="D3D11Texture2DDesc"/> struct.
 /// </summary>
 /// <param name="format">The texture format.</param>
 /// <param name="width">The texture width (in texels).</param>
 /// <param name="height">The texture height (in texels).</param>
 /// <param name="arraySize">The number of textures in the texture array.</param>
 public D3D11Texture2DDesc(DxgiFormat format, uint width, uint height, uint arraySize)
 {
     this.width            = width;
     this.height           = height;
     this.mipLevels        = 0;
     this.arraySize        = arraySize;
     this.format           = format;
     this.sampleDesc       = new DxgiSampleDesc(1, 0);
     this.usage            = D3D11Usage.Default;
     this.bindOptions      = D3D11BindOptions.ShaderResource;
     this.cpuAccessOptions = 0;
     this.miscOptions      = 0;
 }
コード例 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="D3D11Texture2DDesc"/> struct.
 /// </summary>
 /// <param name="format">The texture format.</param>
 /// <param name="width">The texture width (in texels).</param>
 /// <param name="height">The texture height (in texels).</param>
 /// <param name="arraySize">The number of textures in the texture array.</param>
 /// <param name="mipLevels">The maximum number of mipmap levels in the texture.</param>
 /// <param name="bindOptions">Options for binding to pipeline stages.</param>
 /// <param name="usage">Identifies how the texture is to be read from and written to.</param>
 public D3D11Texture2DDesc(
     DxgiFormat format,
     uint width,
     uint height,
     uint arraySize,
     uint mipLevels,
     D3D11BindOptions bindOptions,
     D3D11Usage usage)
 {
     this.width            = width;
     this.height           = height;
     this.mipLevels        = mipLevels;
     this.arraySize        = arraySize;
     this.format           = format;
     this.sampleDesc       = new DxgiSampleDesc(1, 0);
     this.usage            = usage;
     this.bindOptions      = bindOptions;
     this.cpuAccessOptions = 0;
     this.miscOptions      = 0;
 }
コード例 #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="D3D11Texture2DDesc"/> struct.
 /// </summary>
 /// <param name="format">The texture format.</param>
 /// <param name="width">The texture width (in texels).</param>
 /// <param name="height">The texture height (in texels).</param>
 /// <param name="arraySize">The number of textures in the texture array.</param>
 /// <param name="mipLevels">The maximum number of mipmap levels in the texture.</param>
 /// <param name="bindOptions">Options for binding to pipeline stages.</param>
 /// <param name="usage">Identifies how the texture is to be read from and written to.</param>
 /// <param name="cpuAccessOptions">Options to specify the types of CPU access allowed.</param>
 /// <param name="sampleCount">The sample count.</param>
 /// <param name="sampleQuality">The sample quality.</param>
 /// <param name="miscOptions">Options that identify other, less common resource options.</param>
 public D3D11Texture2DDesc(
     DxgiFormat format,
     uint width,
     uint height,
     uint arraySize,
     uint mipLevels,
     D3D11BindOptions bindOptions,
     D3D11Usage usage,
     D3D11CpuAccessOptions cpuAccessOptions,
     uint sampleCount,
     uint sampleQuality,
     D3D11ResourceMiscOptions miscOptions)
 {
     this.width            = width;
     this.height           = height;
     this.mipLevels        = mipLevels;
     this.arraySize        = arraySize;
     this.format           = format;
     this.sampleDesc       = new DxgiSampleDesc(sampleCount, sampleQuality);
     this.usage            = usage;
     this.bindOptions      = bindOptions;
     this.cpuAccessOptions = cpuAccessOptions;
     this.miscOptions      = miscOptions;
 }
コード例 #5
0
        private void CreateDeviceResources()
        {
            D3D11FeatureLevel[] featureLevels;

            if (this.useHighestFeatureLevel)
            {
                if (this.d3dFeatureLevel == D3D11FeatureLevel.FeatureLevel91)
                {
                    featureLevels = new D3D11FeatureLevel[]
                    {
                        D3D11FeatureLevel.FeatureLevel111,
                        D3D11FeatureLevel.FeatureLevel110,
                        D3D11FeatureLevel.FeatureLevel101,
                        D3D11FeatureLevel.FeatureLevel100,
                        D3D11FeatureLevel.FeatureLevel93,
                        D3D11FeatureLevel.FeatureLevel92,
                        D3D11FeatureLevel.FeatureLevel91
                    };
                }
                else
                {
                    featureLevels = Enum.GetValues(typeof(D3D11FeatureLevel))
                                    .Cast <D3D11FeatureLevel>()
                                    .Where(t => t >= this.d3dFeatureLevel)
                                    .OrderByDescending(t => t)
                                    .ToArray();
                }
            }
            else
            {
                featureLevels = new D3D11FeatureLevel[]
                {
                    this.d3dFeatureLevel
                };
            }

            D3D11CreateDeviceOptions options = D3D11CreateDeviceOptions.BgraSupport;

            try
            {
                this.d3dDriverType = D3D11DriverType.Hardware;

                D3D11Device.CreateDevice(
                    null,
                    this.d3dDriverType,
                    options,
                    featureLevels,
                    out this.d3dDevice,
                    out this.d3dFeatureLevel,
                    out this.d3dContext);
            }
            catch (Exception ex)
            {
                if (ex.HResult == DxgiError.Unsupported)
                {
                    this.d3dDriverType = D3D11DriverType.Warp;

                    D3D11Device.CreateDevice(
                        null,
                        this.d3dDriverType,
                        options,
                        featureLevels,
                        out this.d3dDevice,
                        out this.d3dFeatureLevel,
                        out this.d3dContext);
                }
                else
                {
                    throw;
                }
            }

            if (this.preferMultisampling)
            {
                this.d3dSampleDesc = this.CheckMultisamplingSupport();
            }
            else
            {
                this.d3dSampleDesc = new DxgiSampleDesc(1, 0);
            }
        }