Beispiel #1
0
            public static InnerResourceView Create(Resource resource, ShaderResourceViewDescription description)
            {
                switch (description.Dimension)
                {
                case ShaderResourceViewDimension.Texture1D:
                    throw new NotImplementedException();

                case ShaderResourceViewDimension.Texture1DArray:
                    throw new NotImplementedException();

                case ShaderResourceViewDimension.Texture2D:
                    return(new Texture2DView((Texture2D)resource, description.Texture2D));

                case ShaderResourceViewDimension.Texture2DArray:
                    return(new Texture2DArrayView((Texture2D)resource, description.Texture2DArray));

                case ShaderResourceViewDimension.Texture2DMultisampled:
                    throw new NotImplementedException();

                case ShaderResourceViewDimension.Texture2DMultisampledArray:
                    throw new NotImplementedException();

                case ShaderResourceViewDimension.Texture3D:
                    throw new NotImplementedException();

                case ShaderResourceViewDimension.TextureCube:
                    throw new NotImplementedException();

                case ShaderResourceViewDimension.TextureCubeArray:
                    throw new NotImplementedException();

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
			public static InnerResourceView Create(Resource resource, ShaderResourceViewDescription description)
			{
				switch (description.Dimension)
				{
					case ShaderResourceViewDimension.Texture1D:
						throw new NotImplementedException();
					case ShaderResourceViewDimension.Texture1DArray:
						throw new NotImplementedException();
					case ShaderResourceViewDimension.Texture2D:
						return new Texture2DView((Texture2D) resource, description.Texture2D);
					case ShaderResourceViewDimension.Texture2DArray:
                        return new Texture2DArrayView((Texture2D) resource, description.Texture2DArray);
					case ShaderResourceViewDimension.Texture2DMultisampled:
						throw new NotImplementedException();
					case ShaderResourceViewDimension.Texture2DMultisampledArray:
						throw new NotImplementedException();
					case ShaderResourceViewDimension.Texture3D:
						throw new NotImplementedException();
					case ShaderResourceViewDimension.TextureCube:
						throw new NotImplementedException();
					case ShaderResourceViewDimension.TextureCubeArray:
						throw new NotImplementedException();
					default:
						throw new ArgumentOutOfRangeException();
				}
			}
        internal static ShaderResourceViewDescription CreateDefault(Resource resource)
        {
            var result = new ShaderResourceViewDescription();

            switch (resource.ResourceType)
            {
            case ResourceType.Texture1D:
            {
                var texture = (Texture1D)resource;
                if (texture.Description.ArraySize > 1)
                {
                    result.Dimension = ShaderResourceViewDimension.Texture1DArray;
                    result.Texture1DArray.ArraySize       = texture.Description.ArraySize;
                    result.Texture1DArray.FirstArraySlice = 0;
                    result.Texture1DArray.MostDetailedMip = 0;
                    result.Texture1DArray.MipLevels       = texture.Description.MipLevels;
                }
                else
                {
                    result.Dimension = ShaderResourceViewDimension.Texture1D;
                    result.Texture1D.MostDetailedMip = 0;
                    result.Texture1D.MipLevels       = texture.Description.MipLevels;
                }
                break;
            }

            case ResourceType.Texture2D:
            {
                var texture = (Texture2D)resource;
                if (texture.Description.ArraySize > 1)
                {
                    result.Dimension = ShaderResourceViewDimension.Texture2DArray;
                    result.Texture2DArray.ArraySize       = texture.Description.ArraySize;
                    result.Texture2DArray.FirstArraySlice = 0;
                    result.Texture2DArray.MostDetailedMip = 0;
                    result.Texture2DArray.MipLevels       = texture.Description.MipLevels;
                }
                else
                {
                    result.Dimension = ShaderResourceViewDimension.Texture2D;
                    result.Texture2D.MostDetailedMip = 0;
                    result.Texture2D.MipLevels       = texture.Description.MipLevels;
                }
                break;
            }

            case ResourceType.Texture3D:
                result.Dimension = ShaderResourceViewDimension.Texture3D;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            return(result);
        }
            public Texture2DArrayView(Texture2D resource, ShaderResourceViewDescription.Texture2DArrayResource description)
            {
                _mipMapCount = description.MipLevels;
                _arraySize = description.ArraySize;

				_subresources = new Texture2D.Texture2DSubresource[description.MipLevels * description.ArraySize];

                int counter = 0;
                for (int i = description.FirstArraySlice; i < description.FirstArraySlice + description.ArraySize; i++)
				    for (int j = description.MostDetailedMip; j < description.MostDetailedMip + description.MipLevels; j++)
					    _subresources[counter++] = resource.GetSubresource(i, j);
			}
		internal static ShaderResourceViewDescription CreateDefault(Resource resource)
		{
			var result = new ShaderResourceViewDescription();
			switch (resource.ResourceType)
			{
				case ResourceType.Texture1D:
			    {
                    var texture = (Texture1D) resource;
                    if (texture.Description.ArraySize > 1)
                    {
                        result.Dimension = ShaderResourceViewDimension.Texture1DArray;
                        result.Texture1DArray.ArraySize = texture.Description.ArraySize;
                        result.Texture1DArray.FirstArraySlice = 0;
                        result.Texture1DArray.MostDetailedMip = 0;
                        result.Texture1DArray.MipLevels = texture.Description.MipLevels;
                    }
                    else
                    {
                        result.Dimension = ShaderResourceViewDimension.Texture1D;
                        result.Texture1D.MostDetailedMip = 0;
                        result.Texture1D.MipLevels = texture.Description.MipLevels;
                    }
                    break;
			    }
				case ResourceType.Texture2D:
			    {
			        var texture = (Texture2D) resource;
			        if (texture.Description.ArraySize > 1)
			        {
			            result.Dimension = ShaderResourceViewDimension.Texture2DArray;
			            result.Texture2DArray.ArraySize = texture.Description.ArraySize;
			            result.Texture2DArray.FirstArraySlice = 0;
			            result.Texture2DArray.MostDetailedMip = 0;
			            result.Texture2DArray.MipLevels = texture.Description.MipLevels;
			        }
			        else
			        {
			            result.Dimension = ShaderResourceViewDimension.Texture2D;
			            result.Texture2D.MostDetailedMip = 0;
			            result.Texture2D.MipLevels = texture.Description.MipLevels;
			        }
			        break;
			    }
			    case ResourceType.Texture3D:
					result.Dimension = ShaderResourceViewDimension.Texture3D;
					break;
				default:
					throw new ArgumentOutOfRangeException();
			}
			return result;
		}
		internal ShaderResourceView(Device device, Resource resource, ShaderResourceViewDescription? description)
			: base(device, resource)
		{
			_description = description.GetValueOrDefault(ShaderResourceViewDescription.CreateDefault(resource));
			_innerView = InnerResourceView.Create(resource, _description);
		}
			public Texture2DView(Texture2D resource, ShaderResourceViewDescription.Texture2DResource description)
			{
				_subresources = new Texture2D.Texture2DSubresource[description.MipLevels];
				for (int i = description.MostDetailedMip; i < description.MostDetailedMip + description.MipLevels; i++)
					_subresources[i] = resource.GetSubresource(0, i);
			}
 internal ShaderResourceView(Device device, Resource resource, ShaderResourceViewDescription?description)
     : base(device, resource)
 {
     _description = description.GetValueOrDefault(ShaderResourceViewDescription.CreateDefault(resource));
     _innerView   = InnerResourceView.Create(resource, _description);
 }