Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="D3D11ShaderResourceViewDesc"/> struct.
        /// </summary>
        /// <param name="buffer">A buffer.</param>
        /// <param name="format">The viewing format.</param>
        /// <param name="firstElement">The number of bytes between the beginning of the buffer and the first element to access.</param>
        /// <param name="numElements">The total number of elements in the view.</param>
        /// <param name="options">The view options for a buffer.</param>
        public D3D11ShaderResourceViewDesc(
            D3D11Buffer buffer,
            DxgiFormat format,
            uint firstElement,
            uint numElements,
            D3D11BufferExSrvOptions options)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException("buffer");
            }

            this.buffer           = new D3D11BufferSrv();
            this.texture1D        = new D3D11Texture1DSrv();
            this.texture1DArray   = new D3D11Texture1DArraySrv();
            this.texture2D        = new D3D11Texture2DSrv();
            this.texture2DArray   = new D3D11Texture2DArraySrv();
            this.texture2DMs      = new D3D11Texture2DMsSrv();
            this.texture2DMsArray = new D3D11Texture2DMsArraySrv();
            this.texture3D        = new D3D11Texture3DSrv();
            this.textureCube      = new D3D11TextureCubeSrv();
            this.textureCubeArray = new D3D11TextureCubeArraySrv();
            this.bufferEx         = new D3D11BufferExSrv();

            this.format        = format;
            this.viewDimension = D3D11SrvDimension.BufferEx;
            this.bufferEx      = new D3D11BufferExSrv
            {
                FirstElement = firstElement,
                NumElements  = numElements,
                Options      = options
            };
        }
Example #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="D3D11ShaderResourceViewDesc"/> struct.
        /// </summary>
        /// <param name="texture">A 3D texture.</param>
        /// <param name="format">The viewing format.</param>
        /// <param name="mostDetailedMip">The index of the most detailed mipmap level to use.</param>
        /// <param name="mipLevels">The maximum number of mipmap levels for the view.</param>
        public D3D11ShaderResourceViewDesc(
            D3D11Texture3D texture,
            DxgiFormat format,
            uint mostDetailedMip,
            uint mipLevels)
        {
            if (texture == null)
            {
                throw new ArgumentNullException("texture");
            }

            this.buffer           = new D3D11BufferSrv();
            this.texture1D        = new D3D11Texture1DSrv();
            this.texture1DArray   = new D3D11Texture1DArraySrv();
            this.texture2D        = new D3D11Texture2DSrv();
            this.texture2DArray   = new D3D11Texture2DArraySrv();
            this.texture2DMs      = new D3D11Texture2DMsSrv();
            this.texture2DMsArray = new D3D11Texture2DMsArraySrv();
            this.texture3D        = new D3D11Texture3DSrv();
            this.textureCube      = new D3D11TextureCubeSrv();
            this.textureCubeArray = new D3D11TextureCubeArraySrv();
            this.bufferEx         = new D3D11BufferExSrv();

            this.viewDimension = D3D11SrvDimension.Texture3D;

            if (format == DxgiFormat.Unknown || mipLevels == uint.MaxValue)
            {
                var description = texture.Description;

                if (format == DxgiFormat.Unknown)
                {
                    format = description.Format;
                }

                if (mipLevels == uint.MaxValue)
                {
                    mipLevels = description.MipLevels - mostDetailedMip;
                }
            }

            this.format = format;

            this.texture3D = new D3D11Texture3DSrv
            {
                MostDetailedMip = mostDetailedMip,
                MipLevels       = mipLevels
            };
        }
Example #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="D3D11ShaderResourceViewDesc"/> struct.
        /// </summary>
        /// <param name="texture">A 2D texture.</param>
        /// <param name="viewDimension">The resource type of the view.</param>
        /// <param name="format">The viewing format.</param>
        /// <param name="mostDetailedMip">The index of the most detailed mipmap level to use.</param>
        /// <param name="mipLevels">The maximum number of mipmap levels for the view.</param>
        /// <param name="firstArraySlice">The index of the first element to use in an array of elements.</param>
        /// <param name="arraySize">The number of elements in the array.</param>
        public D3D11ShaderResourceViewDesc(
            D3D11Texture2D texture,
            D3D11SrvDimension viewDimension,
            DxgiFormat format,
            uint mostDetailedMip,
            uint mipLevels,
            uint firstArraySlice,
            uint arraySize)
        {
            if (texture == null)
            {
                throw new ArgumentNullException("texture");
            }

            this.buffer           = new D3D11BufferSrv();
            this.texture1D        = new D3D11Texture1DSrv();
            this.texture1DArray   = new D3D11Texture1DArraySrv();
            this.texture2D        = new D3D11Texture2DSrv();
            this.texture2DArray   = new D3D11Texture2DArraySrv();
            this.texture2DMs      = new D3D11Texture2DMsSrv();
            this.texture2DMsArray = new D3D11Texture2DMsArraySrv();
            this.texture3D        = new D3D11Texture3DSrv();
            this.textureCube      = new D3D11TextureCubeSrv();
            this.textureCubeArray = new D3D11TextureCubeArraySrv();
            this.bufferEx         = new D3D11BufferExSrv();

            this.viewDimension = viewDimension;

            if (format == DxgiFormat.Unknown ||
                (mipLevels == uint.MaxValue &&
                 viewDimension != D3D11SrvDimension.Texture2DMs &&
                 viewDimension != D3D11SrvDimension.Texture2DMsArray) ||
                (arraySize == uint.MaxValue &&
                 viewDimension != D3D11SrvDimension.Texture2DArray &&
                 viewDimension != D3D11SrvDimension.Texture2DMsArray &&
                 viewDimension != D3D11SrvDimension.TextureCubeArray))
            {
                var description = texture.Description;

                if (format == DxgiFormat.Unknown)
                {
                    format = description.Format;
                }

                if (mipLevels == uint.MaxValue)
                {
                    mipLevels = description.MipLevels - mostDetailedMip;
                }

                if (arraySize == uint.MaxValue)
                {
                    arraySize = description.ArraySize - firstArraySlice;

                    if (viewDimension == D3D11SrvDimension.TextureCubeArray)
                    {
                        arraySize /= 6;
                    }
                }
            }

            this.format = format;

            switch (viewDimension)
            {
            case D3D11SrvDimension.Texture2D:
                this.texture2D = new D3D11Texture2DSrv
                {
                    MostDetailedMip = mostDetailedMip,
                    MipLevels       = mipLevels
                };
                break;

            case D3D11SrvDimension.Texture2DArray:
                this.texture2DArray = new D3D11Texture2DArraySrv
                {
                    MostDetailedMip = mostDetailedMip,
                    MipLevels       = mipLevels,
                    FirstArraySlice = firstArraySlice,
                    ArraySize       = arraySize
                };
                break;

            case D3D11SrvDimension.Texture2DMs:
                this.texture2DMs = new D3D11Texture2DMsSrv
                {
                };
                break;

            case D3D11SrvDimension.Texture2DMsArray:
                this.texture2DMsArray = new D3D11Texture2DMsArraySrv
                {
                    FirstArraySlice = firstArraySlice,
                    ArraySize       = arraySize
                };
                break;

            case D3D11SrvDimension.TextureCube:
                this.textureCube = new D3D11TextureCubeSrv
                {
                    MostDetailedMip = mostDetailedMip,
                    MipLevels       = mipLevels
                };
                break;

            case D3D11SrvDimension.TextureCubeArray:
                this.textureCubeArray = new D3D11TextureCubeArraySrv
                {
                    MostDetailedMip  = mostDetailedMip,
                    MipLevels        = mipLevels,
                    First2DArrayFace = firstArraySlice,
                    NumCubes         = arraySize
                };
                break;

            default:
                throw new ArgumentOutOfRangeException("viewDimension");
            }
        }
Example #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="D3D11ShaderResourceViewDesc"/> struct.
        /// </summary>
        /// <param name="viewDimension">The resource type of the view.</param>
        /// <param name="format">The viewing format.</param>
        /// <param name="mostDetailedMip">Index of the most detailed mipmap level to use.</param>
        /// <param name="mipLevels">The maximum number of mipmap levels for the view.</param>
        /// <param name="firstArraySlice">The index of the first element to use in an array of elements.</param>
        /// <param name="arraySize">The number of elements in the array.</param>
        /// <param name="bufferExOptions">The view options for a buffer</param>
        public D3D11ShaderResourceViewDesc(
            D3D11SrvDimension viewDimension,
            DxgiFormat format,
            uint mostDetailedMip,
            uint mipLevels,
            uint firstArraySlice,
            uint arraySize,
            D3D11BufferExSrvOptions bufferExOptions)
        {
            this.buffer           = new D3D11BufferSrv();
            this.texture1D        = new D3D11Texture1DSrv();
            this.texture1DArray   = new D3D11Texture1DArraySrv();
            this.texture2D        = new D3D11Texture2DSrv();
            this.texture2DArray   = new D3D11Texture2DArraySrv();
            this.texture2DMs      = new D3D11Texture2DMsSrv();
            this.texture2DMsArray = new D3D11Texture2DMsArraySrv();
            this.texture3D        = new D3D11Texture3DSrv();
            this.textureCube      = new D3D11TextureCubeSrv();
            this.textureCubeArray = new D3D11TextureCubeArraySrv();
            this.bufferEx         = new D3D11BufferExSrv();

            this.format        = format;
            this.viewDimension = viewDimension;

            switch (viewDimension)
            {
            case D3D11SrvDimension.Buffer:
                this.buffer = new D3D11BufferSrv
                {
                    FirstElement = mostDetailedMip,
                    NumElements  = mipLevels
                };
                break;

            case D3D11SrvDimension.Texture1D:
                this.texture1D = new D3D11Texture1DSrv
                {
                    MostDetailedMip = mostDetailedMip,
                    MipLevels       = mipLevels
                };
                break;

            case D3D11SrvDimension.Texture1DArray:
                this.texture1DArray = new D3D11Texture1DArraySrv
                {
                    MostDetailedMip = mostDetailedMip,
                    MipLevels       = mipLevels,
                    FirstArraySlice = firstArraySlice,
                    ArraySize       = arraySize
                };
                break;

            case D3D11SrvDimension.Texture2D:
                this.texture2D = new D3D11Texture2DSrv
                {
                    MostDetailedMip = mostDetailedMip,
                    MipLevels       = mipLevels
                };
                break;

            case D3D11SrvDimension.Texture2DArray:
                this.texture2DArray = new D3D11Texture2DArraySrv
                {
                    MostDetailedMip = mostDetailedMip,
                    MipLevels       = mipLevels,
                    FirstArraySlice = firstArraySlice,
                    ArraySize       = arraySize
                };
                break;

            case D3D11SrvDimension.Texture2DMs:
                this.texture2DMs = new D3D11Texture2DMsSrv
                {
                };
                break;

            case D3D11SrvDimension.Texture2DMsArray:
                this.texture2DMsArray = new D3D11Texture2DMsArraySrv
                {
                    FirstArraySlice = firstArraySlice,
                    ArraySize       = arraySize
                };
                break;

            case D3D11SrvDimension.Texture3D:
                this.texture3D = new D3D11Texture3DSrv
                {
                    MostDetailedMip = mostDetailedMip,
                    MipLevels       = mipLevels
                };
                break;

            case D3D11SrvDimension.TextureCube:
                this.textureCube = new D3D11TextureCubeSrv
                {
                    MostDetailedMip = mostDetailedMip,
                    MipLevels       = mipLevels
                };
                break;

            case D3D11SrvDimension.TextureCubeArray:
                this.textureCubeArray = new D3D11TextureCubeArraySrv
                {
                    MostDetailedMip  = mostDetailedMip,
                    MipLevels        = mipLevels,
                    First2DArrayFace = firstArraySlice,
                    NumCubes         = arraySize
                };
                break;

            case D3D11SrvDimension.BufferEx:
                this.bufferEx = new D3D11BufferExSrv
                {
                    FirstElement = mostDetailedMip,
                    NumElements  = mipLevels,
                    Options      = bufferExOptions
                };
                break;

            default:
                throw new ArgumentOutOfRangeException("viewDimension");
            }
        }