/// <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="GorgonTexture3DView"/>.</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="GorgonTexture3D"/> and a <see cref="GorgonTexture3DView"/> 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="GorgonTexture3D"/> created by this method is linked to the <see cref="GorgonTexture3DView"/> returned, disposal of either one will dispose of the other on your behalf. If /// the user created a <see cref="GorgonTexture3DView"/> from the <see cref="GorgonTexture3D.GetShaderResourceView"/> method on the <see cref="GorgonTexture3D"/>, 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="GorgonTexture3D"/> public static GorgonTexture3DView CreateTexture(GorgonGraphics graphics, IGorgonTexture3DInfo info, IGorgonImage initialData = null) { if (graphics == null) { throw new ArgumentNullException(nameof(graphics)); } if (info == null) { throw new ArgumentNullException(nameof(info)); } var newInfo = new GorgonTexture3DInfo(info) { Usage = info.Usage == ResourceUsage.Staging ? ResourceUsage.Default : info.Usage, Binding = (info.Binding & TextureBinding.ShaderResource) != TextureBinding.ShaderResource ? (info.Binding | TextureBinding.ShaderResource) : info.Binding }; if (initialData != null) { if ((initialData.Width < info.Width) || (initialData.Height < info.Height) || (initialData.Depth < info.Depth)) { initialData = initialData.Expand(info.Width, info.Height, info.Depth); } if ((initialData.Width > info.Width) || (initialData.Height > info.Height) || (initialData.Depth > info.Depth)) { initialData = initialData.Crop(new DX.Rectangle(0, 0, info.Width, info.Height), info.Depth); } } GorgonTexture3D texture = initialData == null ? new GorgonTexture3D(graphics, newInfo) : initialData.ToTexture3D(graphics, new GorgonTextureLoadOptions { Usage = newInfo.Usage, Binding = newInfo.Binding, Name = newInfo.Name }); GorgonTexture3DView 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="GorgonTexture2DReadWriteView"/>.</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="GorgonTexture2D"/> and a <see cref="GorgonTexture2DReadWriteView"/> 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="GorgonTexture2D"/> created by this method is linked to the <see cref="GorgonTexture2DReadWriteView"/> returned, disposal of either one will dispose of the other on your behalf. If /// the user created a <see cref="GorgonTexture2DReadWriteView"/> from the <see cref="GorgonTexture2D.GetReadWriteView"/> method on the <see cref="GorgonTexture2D"/>, 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="GorgonTexture2D"/> public static GorgonTexture2DReadWriteView CreateTexture(GorgonGraphics graphics, IGorgonTexture2DInfo info, IGorgonImage initialData = null) { if (graphics == null) { throw new ArgumentNullException(nameof(graphics)); } if (info == null) { throw new ArgumentNullException(nameof(info)); } var newInfo = new GorgonTexture2DInfo(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 }; if (initialData != null) { if ((initialData.Width > info.Width) || (initialData.Height > info.Height)) { initialData = initialData.Expand(info.Width, info.Height, 1); } if ((initialData.Width < info.Width) || (initialData.Height < info.Height)) { initialData = initialData.Crop(new DX.Rectangle(0, 0, info.Width, info.Height), 1); } } GorgonTexture2D texture = initialData == null ? new GorgonTexture2D(graphics, newInfo) : initialData.ToTexture2D(graphics, new GorgonTexture2DLoadOptions { Usage = newInfo.Usage, Binding = newInfo.Binding, MultisampleInfo = newInfo.MultisampleInfo, Name = newInfo.Name, IsTextureCube = newInfo.IsCubeMap }); GorgonTexture2DReadWriteView result = texture.GetReadWriteView(); 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="GorgonTexture3DReadWriteView"/>.</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="GorgonTexture3D"/> and a <see cref="GorgonTexture3DReadWriteView"/> 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="GorgonTexture3D"/> created by this method is linked to the <see cref="GorgonTexture3DReadWriteView"/> returned, disposal of either one will dispose of the other on your behalf. If /// the user created a <see cref="GorgonTexture3DReadWriteView"/> from the <see cref="GorgonTexture3D.GetReadWriteView"/> method on the <see cref="GorgonTexture3D"/>, 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="GorgonTexture3D"/> public static GorgonTexture3DReadWriteView CreateTexture(GorgonGraphics graphics, IGorgonTexture3DInfo info, IGorgonImage initialData = null) { if (graphics == null) { throw new ArgumentNullException(nameof(graphics)); } if (info == null) { throw new ArgumentNullException(nameof(info)); } var newInfo = new GorgonTexture3DInfo(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 // There's now way we can build a depth/stencil from this method. }; if (initialData != null) { if ((initialData.Width > info.Width) || (initialData.Height > info.Height) || (initialData.Depth > info.Depth)) { initialData = initialData.Expand(info.Width, info.Height, info.Depth); } if ((initialData.Width < info.Width) || (initialData.Height < info.Height) || (initialData.Depth < info.Depth)) { initialData = initialData.Crop(new DX.Rectangle(0, 0, info.Width, info.Height), info.Depth); } } GorgonTexture3D texture = initialData == null ? new GorgonTexture3D(graphics, newInfo) : initialData.ToTexture3D(graphics, new GorgonTextureLoadOptions { Usage = newInfo.Usage, Binding = newInfo.Binding, Name = newInfo.Name }); GorgonTexture3DReadWriteView result = texture.GetReadWriteView(); result.OwnsResource = true; return(result); }
/// <summary> /// Function to crop an image. /// </summary> /// <param name="cropImage">The image to crop.</param> /// <param name="destSize">The new size of the image.</param> /// <param name="alignment">The location to start cropping from.</param> public void CropTo(IGorgonImage cropImage, DX.Size2 destSize, Alignment alignment) { DX.Point startLoc = GetAnchorStart(new DX.Size2(cropImage.Width, cropImage.Height), ref destSize, alignment); cropImage.Crop(new DX.Rectangle(startLoc.X, startLoc.Y, destSize.Width, destSize.Height), cropImage.Depth); }