/// <summary>
        /// Function to create a <see cref="GorgonTexture1D"/> from a <see cref="GorgonImage"/>.
        /// </summary>
        /// <param name="image">The image used to create the texture.</param>
        /// <param name="graphics">The graphics interface used to create the texture.</param>
        /// <param name="options">[Optional] Options used to further define the texture.</param>
        /// <returns>A new <see cref="GorgonTexture1D"/> containing the data from the <paramref name="image"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when the <paramref name="image"/>, or the <paramref name="graphics"/> parameter is <b>null</b>.</exception>
        /// <remarks>
        /// <para>
        /// A <see cref="GorgonImage"/> is useful to holding image data in memory, but it cannot be sent to the GPU for use as a texture. This method allows an application to convert the
        /// <see cref="GorgonImage"/> into a <see cref="GorgonTexture1D"/>.
        /// </para>
        /// <para>
        /// If specified, the <paramref name="options"/>parameter will define how Gorgon and shaders should handle the texture.  The <see cref="GorgonTextureLoadOptions"/> type contains the following:
        /// <list type="bullet">
        ///		<item>
        ///			<term>Binding</term>
        ///			<description>When defined, will indicate the <see cref="TextureBinding"/> that defines how the texture will be bound to the graphics pipeline. If it is omitted, then the binding will be
        ///         <see cref="TextureBinding.ShaderResource"/>.</description>
        ///		</item>
        ///		<item>
        ///			<term>Usage</term>
        ///			<description>When defined, will indicate the preferred usage for the texture. If it is omitted, then the usage will be set to <see cref="ResourceUsage.Default"/>.</description>
        ///		</item>
        ///		<item>
        ///			<term>Multisample info</term>
        ///			<description>This is not available on 1D textures, and is ignored.</description>
        ///		</item>
        /// </list>
        /// </para>
        /// </remarks>
        public static GorgonTexture1D ToTexture1D(this IGorgonImage image,
                                                  GorgonGraphics graphics,
                                                  GorgonTextureLoadOptions options = null)
        {
            if (image == null)
            {
                throw new ArgumentNullException(nameof(image));
            }

            if (graphics == null)
            {
                throw new ArgumentNullException(nameof(graphics));
            }

            if (options == null)
            {
                options = _defaultLoadOptions;
            }

            if (string.IsNullOrEmpty(options.Name))
            {
                options.Name = GorgonGraphicsResource.GenerateName(GorgonTexture1D.NamePrefix);
            }

            return(new GorgonTexture1D(graphics, image, options));
        }
        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        public virtual void Dispose()
        {
            D3D11.ResourceView     view     = Interlocked.Exchange(ref _view, null);
            GorgonGraphicsResource resource = Interlocked.Exchange(ref _resource, null);

            if ((view == null) && (resource == null))
            {
                return;
            }

            if (resource != null)
            {
                Log.Print($"Resource View '{resource.Name}': Releasing D3D11 resource view.", LoggingLevel.Simple);

                if (OwnsResource)
                {
                    Log.Print($"Resource View '{resource.Name}': Releasing D3D11 Resource {resource.ResourceType} because it owns it.", LoggingLevel.Simple);
                    resource.Dispose();
                }
            }

            view?.Dispose();

            GC.SuppressFinalize(this);
        }
        /// <summary>
        /// Function to create a <see cref="GorgonTexture2D"/> from a GDI+ bitmap.
        /// </summary>
        /// <param name="gdiBitmap">The GDI+ bitmap used to create the texture.</param>
        /// <param name="graphics">The graphics interface used to create the texture.</param>
        /// <param name="options">[Optional] Options used to further define the texture.</param>
        /// <returns>A new <see cref="GorgonTexture2D"/> containing the data from the <paramref name="gdiBitmap"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when the <paramref name="gdiBitmap"/>, or the <paramref name="graphics"/> parameter is <b>null</b>.</exception>
        /// <remarks>
        /// <para>
        /// A GDI+ bitmap is useful to holding image data in memory, but it cannot be sent to the GPU for use as a texture. This method allows an application to convert the GDI+ bitmap into a
        /// <see cref="GorgonTexture2D"/>.
        /// </para>
        /// <para>
        /// The resulting <see cref="GorgonTexture2D"/> will only contain a single mip level, and single array level. The only image type available will be 2D (i.e. image with a width and height). The GDI+
        /// bitmap should have a 32bpp rgba format, or a 24bpp rgb format or else an exception will be thrown.
        /// </para>
        /// <para>
        /// The optional <paramref name="options"/>parameter will define how Gorgon and shaders should handle the texture.  The <see cref="GorgonTextureLoadOptions"/> type contains the following:
        /// <list type="bullet">
        ///		<item>
        ///			<term>Binding</term>
        ///			<description>When defined, will indicate the <see cref="TextureBinding"/> that defines how the texture will be bound to the graphics pipeline. If it is omitted, then the binding will be
        ///         <see cref="TextureBinding.ShaderResource"/>.</description>
        ///		</item>
        ///		<item>
        ///			<term>Usage</term>
        ///			<description>When defined, will indicate the preferred usage for the texture. If it is omitted, then the usage will be set to <see cref="ResourceUsage.Default"/>.</description>
        ///		</item>
        ///		<item>
        ///			<term>Multisample info</term>
        ///			<description>When defined (i.e. not <b>null</b>), defines the multisampling to apply to the texture. If omitted, then the default is <see cref="GorgonMultisampleInfo.NoMultiSampling"/>.</description>
        ///		</item>
        ///		<item>
        ///		    <term>ConvertToPremultipliedAlpha</term>
        ///		    <description>Converts the image to premultiplied alpha before uploading the image data to the texture.</description>
        ///		</item>
        /// </list>
        /// </para>
        /// </remarks>
        public static GorgonTexture2D ToTexture2D(this Bitmap gdiBitmap,
                                                  GorgonGraphics graphics,
                                                  GorgonTexture2DLoadOptions options = null)
        {
            if (gdiBitmap == null)
            {
                throw new ArgumentNullException(nameof(gdiBitmap));
            }

            if (graphics == null)
            {
                throw new ArgumentNullException(nameof(graphics));
            }

            if (options == null)
            {
                options = _defaultLoadOptions;
            }

            if (string.IsNullOrEmpty(options.Name))
            {
                options.Name = GorgonGraphicsResource.GenerateName(GorgonTexture2D.NamePrefix);
            }

            using (IGorgonImage image = gdiBitmap.ToGorgonImage())
            {
                if (options.ConvertToPremultipliedAlpha)
                {
                    image.ConvertToPremultipliedAlpha();
                }

                return(new GorgonTexture2D(graphics, image, options));
            }
        }
Example #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GorgonTexture3DInfo"/> class.
 /// </summary>
 /// <param name="name">[Optional] The name of the texture.</param>
 public GorgonTexture3DInfo(string name = null)
 {
     Name      = string.IsNullOrEmpty(name) ? GorgonGraphicsResource.GenerateName(GorgonTexture3D.NamePrefix) : name;
     Binding   = TextureBinding.ShaderResource;
     Usage     = ResourceUsage.Default;
     MipLevels = 1;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="GorgonTexture2DInfo"/> class.
 /// </summary>
 /// <param name="name">[Optional] The name of the texture.</param>
 public GorgonTexture2DInfo(string name = null)
 {
     Name            = string.IsNullOrEmpty(name) ? GorgonGraphicsResource.GenerateName(GorgonTexture2D.NamePrefix) : name;
     Binding         = TextureBinding.ShaderResource;
     Usage           = ResourceUsage.Default;
     MultisampleInfo = GorgonMultisampleInfo.NoMultiSampling;
     MipLevels       = 1;
     ArrayCount      = 1;
 }
Example #6
0
        /// <summary>
        /// Function to find the index of the resource in the array.
        /// </summary>
        /// <param name="resource">The resource to look up.</param>
        /// <returns>The index, if found. -1 if not.</returns>
        internal int IndexOf(GorgonGraphicsResource resource)
        {
            (int start, int count) = GetDirtyItems(true);

            for (int i = 0; i < count; ++i)
            {
                GorgonConstantBuffer buffer = BackingArray[i + start]?.Buffer;

                if (buffer == resource)
                {
                    return(i + start);
                }
            }

            return(-1);
        }
Example #7
0
        /// <summary>
        /// Function to find the index of a <see cref="GorgonStreamOutBinding"/> with the specified buffer.
        /// </summary>
        /// <param name="buffer">The buffer to look up.</param>
        /// <returns>The index of the <see cref="GorgonStreamOutBinding"/>, or -1 if not found.</returns>
        /// <remarks>
        /// <para>
        /// For the sake of efficiency, this checks the dirty items in the list only.
        /// </para>
        /// </remarks>
        internal int IndexOf(GorgonGraphicsResource buffer)
        {
            (int start, int count) = GetDirtyItems(true);

            for (int i = 0; i < count; ++i)
            {
                GorgonVertexBufferBinding binding = BackingArray[i + start];

                if (binding.VertexBuffer != buffer)
                {
                    continue;
                }

                return(i + start);
            }

            return(-1);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="GorgonConstantBufferInfo"/> class.
 /// </summary>
 /// <param name="name">[Optional] The name of the constant buffer.</param>
 public GorgonConstantBufferInfo(string name = null)
 {
     Name  = string.IsNullOrEmpty(name) ? GorgonGraphicsResource.GenerateName(GorgonConstantBuffer.NamePrefix) : name;
     Usage = ResourceUsage.Default;
 }
Example #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GorgonShaderResourceView"/> class.
 /// </summary>
 /// <param name="resource">The resource to bind to the view.</param>
 /// <exception cref="ArgumentNullException">Thrown when the <paramref name="resource"/> parameter is <b>null</b>.</exception>
 protected GorgonReadWriteView(GorgonGraphicsResource resource)
     : base(resource)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="GorgonResourceView"/> class.
 /// </summary>
 /// <param name="resource">The resource to view.</param>
 /// <exception cref="ArgumentNullException">Thrown when the <paramref name="resource"/> parameter is <b>null</b>.</exception>
 protected GorgonResourceView(GorgonGraphicsResource resource)
 {
     _resource = resource ?? throw new ArgumentNullException(nameof(resource));
     Graphics  = _resource.Graphics;
 }
Example #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GorgonShaderResourceView"/> class.
 /// </summary>
 /// <param name="resource">The resource to bind to the view.</param>
 /// <exception cref="ArgumentNullException">Thrown when the <paramref name="resource"/> parameter is <b>null</b>.</exception>
 protected GorgonShaderResourceView(GorgonGraphicsResource resource)
     : base(resource)
 {
 }
Example #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GorgonRenderTarget2DView"/> class.
 /// </summary>
 /// <param name="resource">The resource to bind.</param>
 /// <param name="format">The format of the render target view.</param>
 /// <param name="formatInfo">Information about the format.</param>
 /// <exception cref="ArgumentNullException">Thrown when the <paramref name="resource"/>, or the <paramref name="formatInfo"/> parameter is <b>null</b>.</exception>
 protected GorgonRenderTargetView(GorgonGraphicsResource resource, BufferFormat format, GorgonFormatInfo formatInfo)
     : base(resource)
 {
     FormatInformation = formatInfo ?? throw new ArgumentNullException(nameof(formatInfo));
     Format            = format;
 }
Example #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GorgonIndexBufferInfo"/> class.
 /// </summary>
 /// <param name="name">[Optional] The name of the buffer.</param>
 public GorgonIndexBufferInfo(string name = null)
 {
     Name            = string.IsNullOrEmpty(name) ? GorgonGraphicsResource.GenerateName(GorgonIndexBuffer.NamePrefix) : name;
     Usage           = ResourceUsage.Default;
     Use16BitIndices = true;
 }