Пример #1
0
        // Converts a bitmap to the specified pixel format.
        public static Bitmap ChangePixelFormat(Bitmap bitmap, PixelFormat format)
        {
            Rectangle bounds = new Rectangle(0, 0, bitmap.Width, bitmap.Height);

            return(bitmap.Clone(bounds, format));
        }
Пример #2
0
 /// <summary>
 /// Creates a new instance of a 2D <see cref="Image"/>.
 /// </summary>
 /// <param name="width">The width.</param>
 /// <param name="height">The height.</param>
 /// <param name="mipMapCount">The mip map count.</param>
 /// <param name="format">The format.</param>
 /// <param name="arraySize">Size of the array.</param>
 /// <returns>A new image.</returns>
 public static Image New2D(int width, int height, MipMapCount mipMapCount, PixelFormat format, int arraySize = 1)
 {
     return(New2D(width, height, mipMapCount, format, arraySize, IntPtr.Zero));
 }
Пример #3
0
        /// <summary>
        /// Creates a new texture description <see cref="RenderTarget2D" /> using multisampling.
        /// </summary>
        /// <param name="device">The <see cref="GraphicsDevice"/>.</param>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="format">Describes the format to use.</param>
        /// <param name="arraySize">Size of the texture 2D array, default to 1.</param>
        /// <param name="multiSampleCount">The multisample count.</param>
        /// <returns>A new instance of <see cref="RenderTarget2D" /> class.</returns>
        /// <msdn-id>ff476521</msdn-id>
        ///   <unmanaged>HRESULT ID3D11Device::CreateTexture2D([In] const D3D11_TEXTURE2D_DESC* pDesc,[In, Buffer, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Texture2D** ppTexture2D)</unmanaged>
        ///   <unmanaged-short>ID3D11Device::CreateTexture2D</unmanaged-short>
        public static Texture2DDescription CreateDescription(GraphicsDevice device, int width, int height, MSAALevel multiSampleCount, PixelFormat format, int arraySize = 1)
        {
            if (multiSampleCount == MSAALevel.None)
            {
                throw new ArgumentException("Cannot declare a MSAA RenderTarget with MSAALevel.None. Use other non-MSAA constructors", "multiSampleCount");
            }

            return(CreateDescription(device.MainDevice, width, height, format, TextureFlags.RenderTarget, 1, arraySize, multiSampleCount));
        }
Пример #4
0
        internal static Texture2DDescription CreateDescription(GraphicsDevice device, int width, int height, PixelFormat format, TextureFlags textureFlags, int mipCount, int arraySize, MSAALevel multiSampleCount)
        {
            // Make sure that the texture to create is a render target
            textureFlags |= TextureFlags.RenderTarget;
            var desc = Texture2DBase.NewDescription(width, height, format, textureFlags, mipCount, arraySize, ResourceUsage.Default);

            // Sets the MSAALevel
            int maximumMSAA = (int)device.Features[format].MSAALevelMax;

            desc.SampleDescription.Count = Math.Max(1, Math.Min((int)multiSampleCount, maximumMSAA));
            return(desc);
        }
Пример #5
0
 /// <summary>
 /// Creates a new instance of a 3D <see cref="Image"/>.
 /// </summary>
 /// <param name="width">The width.</param>
 /// <param name="height">The height.</param>
 /// <param name="depth">The depth.</param>
 /// <param name="mipMapCount">The mip map count.</param>
 /// <param name="format">The format.</param>
 /// <param name="dataPointer">Pointer to an existing buffer.</param>
 /// <returns>A new image.</returns>
 public static Image New3D(int width, int height, int depth, MipMapCount mipMapCount, PixelFormat format, IntPtr dataPointer)
 {
     return(new Image(CreateDescription(TextureDimension.Texture3D, width, width, depth, mipMapCount, format, 1), dataPointer, 0, null, false));
 }
Пример #6
0
 /// <summary>
 /// Creates a new <see cref="Texture2D" /> with a single mipmap.
 /// </summary>
 /// <param name="device">The <see cref="GraphicsDevice"/>.</param>
 /// <param name="width">The width.</param>
 /// <param name="height">The height.</param>
 /// <param name="format">Describes the format to use.</param>
 /// <param name="flags">Sets the texture flags (for unordered access...etc.)</param>
 /// <param name="arraySize">Size of the texture 2D array, default to 1.</param>
 /// <param name="usage">The usage.</param>
 /// <returns>A new instance of <see cref="Texture2D" /> class.</returns>
 /// <msdn-id>ff476521</msdn-id>
 ///   <unmanaged>HRESULT ID3D11Device::CreateTexture2D([In] const D3D11_TEXTURE2D_DESC* pDesc,[In, Buffer, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Texture2D** ppTexture2D)</unmanaged>
 ///   <unmanaged-short>ID3D11Device::CreateTexture2D</unmanaged-short>
 public static Texture2D New(GraphicsDevice device, int width, int height, PixelFormat format, TextureFlags flags = TextureFlags.ShaderResource, int arraySize = 1, ResourceUsage usage = ResourceUsage.Default)
 {
     return(New(device, width, height, false, format, flags, arraySize, usage));
 }
Пример #7
0
 /// <summary>
 /// Creates a new <see cref="Texture3D"/> with a single mipmap.
 /// </summary>
 /// <param name="device">The <see cref="Direct3D11.Device"/>.</param>
 /// <param name="width">The width.</param>
 /// <param name="height">The height.</param>
 /// <param name="depth">The depth.</param>
 /// <param name="format">Describes the format to use.</param>
 /// <param name="usage">The usage.</param>
 /// <param name="flags">Sets the texture flags (for unordered access...etc.)</param>
 /// <returns>
 /// A new instance of <see cref="Texture3D"/> class.
 /// </returns>
 /// <msdn-id>ff476522</msdn-id>
 /// <unmanaged>HRESULT ID3D11Device::CreateTexture3D([In] const D3D11_TEXTURE3D_DESC* pDesc,[In, Buffer, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Texture3D** ppTexture3D)</unmanaged>
 /// <unmanaged-short>ID3D11Device::CreateTexture3D</unmanaged-short>
 public static Texture3D New(Device device, int width, int height, int depth, PixelFormat format, TextureFlags flags = TextureFlags.ShaderResource, ResourceUsage usage = ResourceUsage.Default)
 {
     return(New(device, width, height, depth, false, format, flags, usage));
 }
Пример #8
0
 /// <summary>
 /// Creates a new instance of a 2D <see cref="Image"/>.
 /// </summary>
 /// <param name="width">The width.</param>
 /// <param name="height">The height.</param>
 /// <param name="mipMapCount">The mip map count.</param>
 /// <param name="format">The format.</param>
 /// <param name="arraySize">Size of the array.</param>
 /// <param name="dataPointer">Pointer to an existing buffer.</param>
 /// <returns>A new image.</returns>
 public static Image New2D(int width, int height, MipMapCount mipMapCount, PixelFormat format, int arraySize, IntPtr dataPointer)
 {
     return(new Image(CreateDescription(TextureDimension.Texture2D, width, height, 1, mipMapCount, format, arraySize), dataPointer, 0, null, false));
 }
Пример #9
0
        /// <summary>
        /// Creates a new <see cref="Texture3D" /> with texture data for the firs map.
        /// </summary>
        /// <typeparam name="T">Type of the data to upload to the texture</typeparam>
        /// <param name="device">The <see cref="Direct3D11.Device"/>.</param>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="depth">The depth.</param>
        /// <param name="format">Describes the format to use.</param>
        /// <param name="usage">The usage.</param>
        /// <param name="textureData">The texture data, width * height * depth data </param>
        /// <param name="flags">Sets the texture flags (for unordered access...etc.)</param>
        /// <returns>A new instance of <see cref="Texture3D" /> class.</returns>
        /// <remarks>
        /// The first dimension of mipMapTextures describes the number of is an array ot Texture3D Array
        /// </remarks>
        /// <msdn-id>ff476522</msdn-id>
        /// <unmanaged>HRESULT ID3D11Device::CreateTexture3D([In] const D3D11_TEXTURE3D_DESC* pDesc,[In, Buffer, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Texture3D** ppTexture3D)</unmanaged>
        /// <unmanaged-short>ID3D11Device::CreateTexture3D</unmanaged-short>
        public unsafe static Texture3D New <T>(Device device, int width, int height, int depth, PixelFormat format, T[] textureData, TextureFlags flags = TextureFlags.ShaderResource, ResourceUsage usage = ResourceUsage.Immutable) where T : unmanaged
        {
            Texture3D texture = null;

            Utilities.Pin(textureData, ptr =>
            {
                texture = New(device, width, height, depth, 1, format, new[] { GetDataBox(format, width, height, depth, textureData, ptr) }, flags, usage);
            });
            return(texture);
        }
Пример #10
0
 /// <summary>
 /// Creates a new <see cref="Texture3D"/>.
 /// </summary>
 /// <param name="device">The <see cref="Direct3D11.Device"/>.</param>
 /// <param name="width">The width.</param>
 /// <param name="height">The height.</param>
 /// <param name="depth">The depth.</param>
 /// <param name="mipCount">Number of mipmaps, set to true to have all mipmaps, set to an int >=1 for a particular mipmap count.</param>
 /// <param name="format">Describes the format to use.</param>
 /// <param name="usage">The usage.</param>
 /// <param name="textureData">DataBox used to fill texture data.</param>
 /// <param name="flags">Sets the texture flags (for unordered access...etc.)</param>
 /// <returns>
 /// A new instance of <see cref="Texture3D"/> class.
 /// </returns>
 /// <msdn-id>ff476522</msdn-id>
 /// <unmanaged>HRESULT ID3D11Device::CreateTexture3D([In] const D3D11_TEXTURE3D_DESC* pDesc,[In, Buffer, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Texture3D** ppTexture3D)</unmanaged>
 /// <unmanaged-short>ID3D11Device::CreateTexture3D</unmanaged-short>
 public static Texture3D New(Device device, int width, int height, int depth, MipMapCount mipCount, PixelFormat format, DataBox[] textureData, TextureFlags flags = TextureFlags.ShaderResource, ResourceUsage usage = ResourceUsage.Default)
 {
     // TODO Add check for number of texture data according to width/height/depth/mipCount.
     return(new Texture3D(device, NewDescription(width, height, depth, format, flags, mipCount, usage), textureData));
 }
Пример #11
0
 /// <summary>
 /// Creates a new <see cref="Texture3D"/>.
 /// </summary>
 /// <param name="device">The <see cref="Direct3D11.Device"/>.</param>
 /// <param name="width">The width.</param>
 /// <param name="height">The height.</param>
 /// <param name="depth">The depth.</param>
 /// <param name="mipCount">Number of mipmaps, set to true to have all mipmaps, set to an int >=1 for a particular mipmap count.</param>
 /// <param name="format">Describes the format to use.</param>
 /// <param name="usage">The usage.</param>
 /// <param name="flags">Sets the texture flags (for unordered access...etc.)</param>
 /// <returns>
 /// A new instance of <see cref="Texture3D"/> class.
 /// </returns>
 /// <msdn-id>ff476522</msdn-id>
 /// <unmanaged>HRESULT ID3D11Device::CreateTexture3D([In] const D3D11_TEXTURE3D_DESC* pDesc,[In, Buffer, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Texture3D** ppTexture3D)</unmanaged>
 /// <unmanaged-short>ID3D11Device::CreateTexture3D</unmanaged-short>
 public static Texture3D New(Device device, int width, int height, int depth, MipMapCount mipCount, PixelFormat format, TextureFlags flags = TextureFlags.ShaderResource, ResourceUsage usage = ResourceUsage.Default)
 {
     return(new Texture3D(device, NewDescription(width, height, depth, format, flags, mipCount, usage)));
 }
Пример #12
0
 /// <summary>
 /// Creates a new <see cref="Texture2D" />.
 /// </summary>
 /// <param name="device">The <see cref="GraphicsDevice"/>.</param>
 /// <param name="width">The width.</param>
 /// <param name="height">The height.</param>
 /// <param name="format">Describes the format to use.</param>
 /// <param name="mipCount">Number of mipmaps, set to true to have all mipmaps, set to an int >=1 for a particular mipmap count.</param>
 /// <param name="textureData">Texture data through an array of <see cref="DataBox"/> </param>
 /// <param name="flags">Sets the texture flags (for unordered access...etc.)</param>
 /// <param name="arraySize">Size of the texture 2D array, default to 1.</param>
 /// <param name="usage">The usage.</param>
 /// <returns>A new instance of <see cref="Texture2D" /> class.</returns>
 /// <msdn-id>ff476521</msdn-id>
 ///   <unmanaged>HRESULT ID3D11Device::CreateTexture2D([In] const D3D11_TEXTURE2D_DESC* pDesc,[In, Buffer, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Texture2D** ppTexture2D)</unmanaged>
 ///   <unmanaged-short>ID3D11Device::CreateTexture2D</unmanaged-short>
 public static Texture2D New(GraphicsDevice device, int width, int height, MipMapCount mipCount, PixelFormat format, DataBox[] textureData, TextureFlags flags = TextureFlags.ShaderResource, int arraySize = 1, ResourceUsage usage = ResourceUsage.Default)
 {
     return(new Texture2D(device, NewDescription(width, height, format, flags, mipCount, arraySize, usage), textureData));
 }
Пример #13
0
        /// <summary>
        /// Creates a new <see cref="Texture2D" /> with a single level of mipmap.
        /// </summary>
        /// <typeparam name="T">Type of the pixel data to upload to the texture.</typeparam>
        /// <param name="device">The <see cref="GraphicsDevice"/>.</param>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="format">Describes the format to use.</param>
        /// <param name="usage">The usage.</param>
        /// <param name="flags">Sets the texture flags (for unordered access...etc.)</param>
        /// <param name="textureData">The texture data for a single mipmap and a single array slice. See remarks</param>
        /// <returns>A new instance of <see cref="Texture2D" /> class.</returns>
        /// <msdn-id>ff476521</msdn-id>
        ///   <unmanaged>HRESULT ID3D11Device::CreateTexture2D([In] const D3D11_TEXTURE2D_DESC* pDesc,[In, Buffer, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Texture2D** ppTexture2D)</unmanaged>
        ///   <unmanaged-short>ID3D11Device::CreateTexture2D</unmanaged-short>
        /// <remarks>
        /// Each value in textureData is a pixel in the destination texture.
        /// </remarks>
        public unsafe static Texture2D New <T>(GraphicsDevice device, int width, int height, PixelFormat format, T[] textureData, TextureFlags flags = TextureFlags.ShaderResource, ResourceUsage usage = ResourceUsage.Immutable) where T : struct
        {
            Texture2D tex = null;

            Utilities.Pin(textureData, ptr =>
            {
                tex = New(device, width, height, 1, format, new[] { GetDataBox(format, width, height, 1, textureData, ptr) }, flags, 1, usage);
            });

            return(tex);
        }
Пример #14
0
 /// <summary>
 /// Creates a new instance of a Cube <see cref="Image"/>.
 /// </summary>
 /// <param name="width">The width.</param>
 /// <param name="mipMapCount">The mip map count.</param>
 /// <param name="format">The format.</param>
 /// <returns>A new image.</returns>
 public static Image NewCube(int width, MipMapCount mipMapCount, PixelFormat format)
 {
     return(NewCube(width, mipMapCount, format, IntPtr.Zero));
 }
Пример #15
0
 /// <summary>
 /// Creates a new <see cref="RenderTarget2D" /> with a single mipmap.
 /// </summary>
 /// <param name="device">The <see cref="GraphicsDevice"/>.</param>
 /// <param name="width">The width.</param>
 /// <param name="height">The height.</param>
 /// <param name="format">Describes the format to use.</param>
 /// <param name="flags">Sets the texture flags (for unordered access...etc.)</param>
 /// <param name="arraySize">Size of the texture 2D array, default to 1.</param>
 /// <returns>A new instance of <see cref="RenderTarget2D" /> class.</returns>
 /// <msdn-id>ff476521</msdn-id>
 ///   <unmanaged>HRESULT ID3D11Device::CreateTexture2D([In] const D3D11_TEXTURE2D_DESC* pDesc,[In, Buffer, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Texture2D** ppTexture2D)</unmanaged>
 ///   <unmanaged-short>ID3D11Device::CreateTexture2D</unmanaged-short>
 public static RenderTarget2D New(GraphicsDevice device, int width, int height, PixelFormat format, TextureFlags flags = TextureFlags.RenderTarget | TextureFlags.ShaderResource, int arraySize = 1)
 {
     return(New(device, width, height, false, format, flags, arraySize));
 }
Пример #16
0
 /// <summary>
 /// Creates a new instance of a 3D <see cref="Image"/>.
 /// </summary>
 /// <param name="width">The width.</param>
 /// <param name="height">The height.</param>
 /// <param name="depth">The depth.</param>
 /// <param name="mipMapCount">The mip map count.</param>
 /// <param name="format">The format.</param>
 /// <returns>A new image.</returns>
 public static Image New3D(int width, int height, int depth, MipMapCount mipMapCount, PixelFormat format)
 {
     return(New3D(width, height, depth, mipMapCount, format, IntPtr.Zero));
 }
Пример #17
0
 /// <summary>
 /// Creates a new texture description for a <see cref="RenderTarget2D" /> with a single mipmap.
 /// </summary>
 /// <param name="device">The <see cref="GraphicsDevice"/>.</param>
 /// <param name="width">The width.</param>
 /// <param name="height">The height.</param>
 /// <param name="format">Describes the format to use.</param>
 /// <param name="flags">Sets the texture flags (for unordered access...etc.)</param>
 /// <param name="arraySize">Size of the texture 2D array, default to 1.</param>
 /// <returns>A new instance of <see cref="RenderTarget2D" /> class.</returns>
 /// <msdn-id>ff476521</msdn-id>
 ///   <unmanaged>HRESULT ID3D11Device::CreateTexture2D([In] const D3D11_TEXTURE2D_DESC* pDesc,[In, Buffer, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Texture2D** ppTexture2D)</unmanaged>
 ///   <unmanaged-short>ID3D11Device::CreateTexture2D</unmanaged-short>
 public static Texture2DDescription CreateDescription(GraphicsDevice device, int width, int height, PixelFormat format, TextureFlags flags = TextureFlags.RenderTarget | TextureFlags.ShaderResource, int arraySize = 1)
 {
     return(CreateDescription(device, width, height, false, format, flags, arraySize));
 }
Пример #18
0
 /// <summary>
 /// Creates a new instance of a Cube <see cref="Image"/>.
 /// </summary>
 /// <param name="width">The width.</param>
 /// <param name="mipMapCount">The mip map count.</param>
 /// <param name="format">The format.</param>
 /// <param name="dataPointer">Pointer to an existing buffer.</param>
 /// <returns>A new image.</returns>
 public static Image NewCube(int width, MipMapCount mipMapCount, PixelFormat format, IntPtr dataPointer)
 {
     return(new Image(CreateDescription(TextureDimension.TextureCube, width, width, 1, mipMapCount, format, 6), dataPointer, 0, null, false));
 }
Пример #19
0
 /// <summary>
 /// Creates a new texture description <see cref="RenderTarget2D" />.
 /// </summary>
 /// <param name="device">The <see cref="GraphicsDevice"/>.</param>
 /// <param name="width">The width.</param>
 /// <param name="height">The height.</param>
 /// <param name="mipCount">Number of mipmaps, set to true to have all mipmaps, set to an int >=1 for a particular mipmap count.</param>
 /// <param name="format">Describes the format to use.</param>
 /// <param name="flags">Sets the texture flags (for unordered access...etc.)</param>
 /// <param name="arraySize">Size of the texture 2D array, default to 1.</param>
 /// <returns>A new instance of <see cref="RenderTarget2D" /> class.</returns>
 /// <msdn-id>ff476521</msdn-id>
 ///   <unmanaged>HRESULT ID3D11Device::CreateTexture2D([In] const D3D11_TEXTURE2D_DESC* pDesc,[In, Buffer, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Texture2D** ppTexture2D)</unmanaged>
 ///   <unmanaged-short>ID3D11Device::CreateTexture2D</unmanaged-short>
 public static Texture2DDescription CreateDescription(GraphicsDevice device, int width, int height, MipMapCount mipCount, PixelFormat format, TextureFlags flags = TextureFlags.RenderTarget | TextureFlags.ShaderResource, int arraySize = 1)
 {
     return(CreateDescription(device.MainDevice, width, height, format, flags, mipCount, arraySize, MSAALevel.None));
 }
Пример #20
0
 private static ImageDescription CreateDescription(TextureDimension dimension, int width, int height, int depth, MipMapCount mipMapCount, PixelFormat format, int arraySize)
 {
     return(new ImageDescription()
     {
         Width = width,
         Height = height,
         Depth = depth,
         ArraySize = arraySize,
         Dimension = dimension,
         Format = format,
         MipLevels = mipMapCount,
     });
 }
Пример #21
0
 /// <summary>
 /// Creates a new <see cref="Texture3D" /> with texture data for the firs map.
 /// </summary>
 /// <typeparam name="T">Type of the data to upload to the texture</typeparam>
 /// <param name="device">The <see cref="GraphicsDevice"/>.</param>
 /// <param name="width">The width.</param>
 /// <param name="height">The height.</param>
 /// <param name="depth">The depth.</param>
 /// <param name="format">Describes the format to use.</param>
 /// <param name="usage">The usage.</param>
 /// <param name="textureData">The texture data, width * height * depth datas </param>
 /// <param name="flags">Sets the texture flags (for unordered access...etc.)</param>
 /// <returns>A new instance of <see cref="Texture3D" /> class.</returns>
 /// <remarks>
 /// The first dimension of mipMapTextures describes the number of is an array ot Texture3D Array
 /// </remarks>
 /// <msdn-id>ff476522</msdn-id>
 /// <unmanaged>HRESULT ID3D11Device::CreateTexture3D([In] const D3D11_TEXTURE3D_DESC* pDesc,[In, Buffer, Optional] const D3D11_SUBRESOURCE_DATA* pInitialData,[Out, Fast] ID3D11Texture3D** ppTexture3D)</unmanaged>
 /// <unmanaged-short>ID3D11Device::CreateTexture3D</unmanaged-short>
 public unsafe static Texture3D New <T>(GraphicsDevice device, int width, int height, int depth, PixelFormat format, T[] textureData, TextureFlags flags = TextureFlags.ShaderResource, ResourceUsage usage = ResourceUsage.Immutable) where T : struct
 {
     return(New(device, width, height, depth, 1, format, new[] { GetDataBox(format, width, height, depth, textureData, (IntPtr)Interop.Fixed(textureData)) }, flags, usage));
 }