/// <summary> /// Function to create a new texture that is bindable to the GPU. /// </summary> /// <param name="graphics">The graphics interface to use when creating the target.</param> /// <param name="info">The information about the texture.</param> /// <param name="initialData">[Optional] Initial data used to populate the texture.</param> /// <returns>A new <see cref="GorgonTexture1DView"/>.</returns> /// <exception cref="ArgumentNullException">Thrown when the <paramref name="graphics"/>, or <paramref name="info"/> parameter is <b>null</b>.</exception> /// <remarks> /// <para> /// This is a convenience method that will create a <see cref="GorgonTexture1D"/> and a <see cref="GorgonTexture1DView"/> as a single object that users can use to apply a texture as a shader /// resource. This helps simplify creation of a texture by executing some prerequisite steps on behalf of the user. /// </para> /// <para> /// Since the <see cref="GorgonTexture1D"/> created by this method is linked to the <see cref="GorgonTexture1DView"/> returned, disposal of either one will dispose of the other on your behalf. If /// the user created a <see cref="GorgonTexture1DView"/> from the <see cref="GorgonTexture1D.GetShaderResourceView"/> method on the <see cref="GorgonTexture1D"/>, then it's assumed the user knows /// what they are doing and will handle the disposal of the texture and view on their own. /// </para> /// <para> /// If an <paramref name="initialData"/> image is provided, and the width/height/depth is not the same as the values in the <paramref name="info"/> parameter, then the image data will be cropped to /// match the values in the <paramref name="info"/> parameter. Things like array count, and mip levels will still be taken from the <paramref name="initialData"/> image parameter. /// </para> /// </remarks> /// <seealso cref="GorgonTexture1D"/> public static GorgonTexture1DView CreateTexture(GorgonGraphics graphics, IGorgonTexture1DInfo info, IGorgonImage initialData = null) { if (graphics == null) { throw new ArgumentNullException(nameof(graphics)); } if (info == null) { throw new ArgumentNullException(nameof(info)); } var newInfo = new GorgonTexture1DInfo(info) { Usage = info.Usage == ResourceUsage.Staging ? ResourceUsage.Default : info.Usage, Binding = ((info.Binding & TextureBinding.ShaderResource) != TextureBinding.ShaderResource ? (info.Binding | TextureBinding.ShaderResource) : info.Binding) & ~(TextureBinding.DepthStencil | TextureBinding.RenderTarget) }; if (initialData != null) { if (initialData.Width < info.Width) { initialData = initialData.Expand(info.Width, 1, 1); } if (initialData.Width > info.Width) { initialData = initialData.Crop(new DX.Rectangle(0, 0, info.Width, 1), 1); } } GorgonTexture1D texture = initialData == null ? new GorgonTexture1D(graphics, newInfo) : initialData.ToTexture1D(graphics, new GorgonTextureLoadOptions { Usage = newInfo.Usage, Binding = newInfo.Binding, Name = newInfo.Name }); GorgonTexture1DView result = texture.GetShaderResourceView(); result.OwnsResource = true; return(result); }
/// <summary> /// Function to create a new texture that is bindable to the GPU as an unordered access resource. /// </summary> /// <param name="graphics">The graphics interface to use when creating the target.</param> /// <param name="info">The information about the texture.</param> /// <param name="initialData">[Optional] Initial data used to populate the texture.</param> /// <returns>A new <see cref="GorgonTexture1DReadWriteView"/>.</returns> /// <exception cref="ArgumentNullException">Thrown when the <paramref name="graphics"/>, or <paramref name="info"/> parameter is <b>null</b>.</exception> /// <remarks> /// <para> /// This is a convenience method that will create a <see cref="GorgonTexture1D"/> and a <see cref="GorgonTexture1DReadWriteView"/> as a single object that users can use to apply a texture as an unordered /// access resource. This helps simplify creation of a texture by executing some prerequisite steps on behalf of the user. /// </para> /// <para> /// Since the <see cref="GorgonTexture1D"/> created by this method is linked to the <see cref="GorgonTexture1DReadWriteView"/> returned, disposal of either one will dispose of the other on your behalf. If /// the user created a <see cref="GorgonTexture1DReadWriteView"/> from the <see cref="GorgonTexture1D.GetReadWriteView"/> method on the <see cref="GorgonTexture1D"/>, then it's assumed the user knows /// what they are doing and will handle the disposal of the texture and view on their own. /// </para> /// <para> /// If an <paramref name="initialData"/> image is provided, and the width/height/depth is not the same as the values in the <paramref name="info"/> parameter, then the image data will be cropped to /// match the values in the <paramref name="info"/> parameter. Things like array count, and mip levels will still be taken from the <paramref name="initialData"/> image parameter. /// </para> /// </remarks> /// <seealso cref="GorgonTexture1D"/> public static GorgonTexture1DReadWriteView CreateTexture(GorgonGraphics graphics, IGorgonTexture1DInfo info, IGorgonImage initialData = null) { if (graphics == null) { throw new ArgumentNullException(nameof(graphics)); } if (info == null) { throw new ArgumentNullException(nameof(info)); } var newInfo = new GorgonTexture1DInfo(info) { Usage = info.Usage == ResourceUsage.Staging ? ResourceUsage.Default : info.Usage, Binding = (((info.Binding & TextureBinding.ReadWriteView) != TextureBinding.ReadWriteView) ? (info.Binding | TextureBinding.ReadWriteView) : info.Binding) & ~(TextureBinding.DepthStencil | TextureBinding.RenderTarget) }; GorgonTexture1D texture = initialData == null ? new GorgonTexture1D(graphics, newInfo) : initialData.ToTexture1D(graphics, new GorgonTextureLoadOptions { Usage = newInfo.Usage, Binding = newInfo.Binding, Name = newInfo.Name }); GorgonTexture1DReadWriteView result = texture.GetReadWriteView(); result.OwnsResource = true; return(result); }