Ejemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of <see cref="BufferDescription"/> struct.
 /// </summary>
 /// <param name="sizeInBytes">Size of the buffer in bytes.</param>
 /// <param name="bufferFlags">Buffer flags describing the type of buffer.</param>
 /// <param name="usage">Usage of this buffer.</param>
 /// <param name="structureByteStride">The size of the structure (in bytes) when it represents a structured/typed buffer. Default = 0.</param>
 public BufferDescription(int sizeInBytes, BufferFlags bufferFlags, GraphicsResourceUsage usage, int structureByteStride = 0)
 {
     SizeInBytes = sizeInBytes;
     BufferFlags = bufferFlags;
     Usage = usage;
     StructureByteStride = structureByteStride;
 }
 private static TextureDescription New1D(int width, PixelFormat format, TextureFlags flags, int mipCount, int arraySize, GraphicsResourceUsage usage)
 {
     usage = (flags & TextureFlags.UnorderedAccess) != 0 ? GraphicsResourceUsage.Default : usage;
     var desc = new TextureDescription()
     {
         Dimension = TextureDimension.Texture1D,
         Width = width,
         Height = 1,
         Depth = 1,
         ArraySize = arraySize,
         Flags = flags,
         Format = format,
         MipLevels = Texture.CalculateMipMapCount(mipCount, width),
         Usage = Texture.GetUsageWithFlags(usage, flags),
     };
     return desc;
 }
        private static TextureDescription New3D(int width, int height, int depth, PixelFormat format, TextureFlags flags, int mipCount, GraphicsResourceUsage usage)
        {
            var desc = new TextureDescription()
            {
                Width = width,
                Height = height,
                Depth = depth,
                Flags = flags,
                Format = format,
                MipLevels = Texture.CalculateMipMapCount(mipCount, width, height, depth),
                Usage = Texture.GetUsageWithFlags(usage, flags),
                ArraySize = 1,
                Dimension = TextureDimension.Texture3D,
                MultiSampleLevel = MSAALevel.None
            };

            return desc;
        } 
Ejemplo n.º 4
0
        private static TextureDescription New2D(int width, int height, PixelFormat format, TextureFlags textureFlags, int mipCount, int arraySize, GraphicsResourceUsage usage)
        {
            if ((textureFlags & TextureFlags.UnorderedAccess) != 0)
                usage = GraphicsResourceUsage.Default;

            var desc = new TextureDescription()
            {
                Dimension = TextureDimension.Texture2D,
                Width = width,
                Height = height,
                Depth = 1,
                ArraySize = arraySize,
                MultiSampleLevel = MSAALevel.None,
                Flags = textureFlags,
                Format = format,
                MipLevels = Texture.CalculateMipMapCount(mipCount, width, height),
                Usage = Texture.GetUsageWithFlags(usage, textureFlags),
            };
            return desc;
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Creates a new Argument buffer with <see cref="GraphicsResourceUsage.Default"/> uasge by default.
 /// </summary>
 /// <param name="device">The <see cref="GraphicsDevice"/>.</param>
 /// <param name="size">The size in bytes.</param>
 /// <param name="usage">The usage.</param>
 /// <returns>A Argument buffer</returns>
 public static Buffer New(GraphicsDevice device, int size, GraphicsResourceUsage usage = GraphicsResourceUsage.Default)
 {
     return(Buffer.New(device, size, BufferFlags.ArgumentBuffer, usage));
 }
 /// <summary>
 /// Creates a new 1D <see cref="Texture" /> with a single level of mipmap.
 /// </summary>
 /// <param name="device">The <see cref="GraphicsDevice" />.</param>
 /// <param name="width">The width.</param>
 /// <param name="format">Describes the format to use.</param>
 /// <param name="dataPtr">Data ptr</param>
 /// <param name="textureFlags">true if the texture needs to support unordered read write.</param>
 /// <param name="usage">The usage.</param>
 /// <returns>A new instance of 1D <see cref="Texture" /> class.</returns>
 /// <remarks>The first dimension of mipMapTextures describes the number of array (Texture Array), second dimension is the mipmap, the third is the texture data for a particular mipmap.</remarks>
 public static Texture New1D(GraphicsDevice device, int width, PixelFormat format, IntPtr dataPtr, TextureFlags textureFlags = TextureFlags.ShaderResource, GraphicsResourceUsage usage = GraphicsResourceUsage.Immutable)
 {
     return(New(device, TextureDescription.New1D(width, format, textureFlags, usage), new[] { new DataBox(dataPtr, 0, 0), }));
 }
 /// <summary>
 /// Creates a new 1D <see cref="Texture"/>.
 /// </summary>
 /// <param name="device">The <see cref="GraphicsDevice"/>.</param>
 /// <param name="width">The width.</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="textureFlags">true if the texture needs to support unordered read write.</param>
 /// <param name="arraySize">Size of the texture 2D array, default to 1.</param>
 /// <returns>
 /// A new instance of 1D <see cref="Texture"/> class.
 /// </returns>
 public static Texture New1D(GraphicsDevice device, int width, MipMapCount mipCount, PixelFormat format, TextureFlags textureFlags = TextureFlags.ShaderResource, int arraySize = 1, GraphicsResourceUsage usage = GraphicsResourceUsage.Default)
 {
     return(New(device, TextureDescription.New1D(width, mipCount, format, textureFlags, arraySize, usage)));
 }
Ejemplo n.º 8
0
 private static BufferDescription NewDescription(int bufferSize, int elementSize, BufferFlags bufferFlags, GraphicsResourceUsage usage)
 {
     return(new BufferDescription()
     {
         SizeInBytes = bufferSize,
         StructureByteStride = (bufferFlags & BufferFlags.StructuredBuffer) != 0 ? elementSize : 0,
         BufferFlags = bufferFlags,
         Usage = usage,
     });
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Creates a new <see cref="Buffer" /> instance.
 /// </summary>
 /// <typeparam name="T">Type of the buffer, to get the sizeof from.</typeparam>
 /// <param name="device">The <see cref="GraphicsDevice"/>.</param>
 /// <param name="initialValue">The initial value of this buffer.</param>
 /// <param name="bufferFlags">The buffer flags to specify the type of buffer.</param>
 /// <param name="usage">The usage.</param>
 /// <returns>An instance of a new <see cref="Buffer" /></returns>
 public static Buffer <T> New <T>(GraphicsDevice device, T[] initialValue, BufferFlags bufferFlags, GraphicsResourceUsage usage = GraphicsResourceUsage.Default) where T : struct
 {
     return(New(device, initialValue, bufferFlags, PixelFormat.None, usage));
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Creates a new <see cref="Buffer" /> instance.
        /// </summary>
        /// <param name="device">The <see cref="GraphicsDevice"/>.</param>
        /// <param name="elementCount">Number of T elment in this buffer.</param>
        /// <param name="bufferFlags">The buffer flags to specify the type of buffer.</param>
        /// <param name="usage">The usage.</param>
        /// <returns>An instance of a new <see cref="Buffer" /></returns>
        public static Buffer <T> New <T>(GraphicsDevice device, int elementCount, BufferFlags bufferFlags, GraphicsResourceUsage usage = GraphicsResourceUsage.Default) where T : struct
        {
            int bufferSize  = Utilities.SizeOf <T>() * elementCount;
            int elementSize = Utilities.SizeOf <T>();

            var description = NewDescription(bufferSize, elementSize, bufferFlags, usage);

            return(new Buffer <T>(device, description, bufferFlags, PixelFormat.None, IntPtr.Zero));
        }
Ejemplo n.º 11
0
        public void TestGetData(GraphicsProfile profile, GraphicsResourceUsage usage)
        {
            var testArray = profile >= GraphicsProfile.Level_10_0; // TODO modify this when when supported on openGL
            var mipmaps = GraphicsDevice.Platform == GraphicsPlatform.OpenGLES && profile < GraphicsProfile.Level_10_0 ? 1 : 3; // TODO remove this limitation when GetData is fixed on OpenGl ES for mipmap levels other than 0

            PerformTest(
                game =>
                {
                    const int width = 16;
                    const int height = width;
                    var arraySize = testArray ? 2 : 1;
                    var flags = usage == GraphicsResourceUsage.Default?
                        new[] { TextureFlags.ShaderResource, TextureFlags.RenderTarget, TextureFlags.RenderTarget | TextureFlags.ShaderResource }:
                        new[] { TextureFlags.None };

                    var pixelFormat = PixelFormat.R8G8B8A8_UNorm;
                    var data = CreateDebugTextureData(width, height, mipmaps, arraySize, pixelFormat, DefaultColorComputer);

                    foreach (var flag in flags)
                    {
                        using (var texture = CreateDebugTexture(game.GraphicsDevice, data, width, height, mipmaps, arraySize, pixelFormat, flag, usage))
                            CheckDebugTextureData(game.GraphicsContext, texture, width, height, mipmaps, arraySize, pixelFormat, flag, usage, DefaultColorComputer);
                    }
                },
                profile);
        }
 /// <summary>
 /// Creates a new 1D <see cref="TextureDescription" /> with a single level of mipmap.
 /// </summary>
 /// <param name="width">The width.</param>
 /// <param name="format">Describes the format to use.</param>
 /// <param name="textureFlags">true if the texture needs to support unordered read write.</param>
 /// <param name="usage">The usage.</param>
 /// <returns>A new instance of 1D <see cref="TextureDescription" /> class.</returns>
 /// <remarks>The first dimension of mipMapTextures describes the number of array (Texture1D Array), second dimension is the mipmap, the third is the texture data for a particular mipmap.</remarks>
 public static TextureDescription New1D(int width, PixelFormat format, TextureFlags textureFlags = TextureFlags.ShaderResource, GraphicsResourceUsage usage = GraphicsResourceUsage.Immutable)
 {
     return New1D(width, format, textureFlags, 1, 1, usage);
 }
 /// <summary>
 /// Creates a new 1D <see cref="TextureDescription" />.
 /// </summary>
 /// <param name="width">The width.</param>
 /// <param name="mipCount">Number of mipmaps, set to true to have all mipmaps, set to an int &gt;=1 for a particular mipmap count.</param>
 /// <param name="format">Describes the format to use.</param>
 /// <param name="textureFlags">true if the texture needs to support unordered read write.</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 1D <see cref="TextureDescription" /> class.</returns>
 public static TextureDescription New1D(int width, MipMapCount mipCount, PixelFormat format, TextureFlags textureFlags = TextureFlags.ShaderResource, int arraySize = 1, GraphicsResourceUsage usage = GraphicsResourceUsage.Default)
 {
     return New1D(width, format, textureFlags, mipCount, arraySize, usage);
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Creates a new <see cref="TextureDescription" /> with a single mipmap.
 /// </summary>
 /// <param name="width">The width.</param>
 /// <param name="height">The height.</param>
 /// <param name="format">Describes the format to use.</param>
 /// <param name="textureFlags">true if the texture needs to support unordered read write.</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="TextureDescription" /> class.</returns>
 public static TextureDescription New2D(int width, int height, PixelFormat format, TextureFlags textureFlags = TextureFlags.ShaderResource, int arraySize = 1, GraphicsResourceUsage usage = GraphicsResourceUsage.Default)
 {
     return New2D(width, height, false, format, textureFlags, arraySize, usage);
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Creates a new Vertex buffer with <see cref="GraphicsResourceUsage.Default"/> uasge by default.
 /// </summary>
 /// <param name="device">The <see cref="GraphicsDevice"/>.</param>
 /// <param name="size">The size in bytes.</param>
 /// <param name="usage">The usage.</param>
 /// <param name="bindFlags">The bind flags, can be combined with <see cref="BufferFlags.StreamOutput"/> to use the buffer as a stream output target.</param>
 /// <returns>
 /// A Vertex buffer
 /// </returns>
 public static Buffer New(GraphicsDevice device, int size, GraphicsResourceUsage usage = GraphicsResourceUsage.Default, BufferFlags bindFlags = BufferFlags.VertexBuffer)
 {
     return(Buffer.New(device, size, bindFlags, usage));
 }
Ejemplo n.º 16
0
        public void TestCopy(GraphicsProfile profile, GraphicsResourceUsage usageSource)
        {
            var testArray = profile >= GraphicsProfile.Level_10_0; // TODO modify this when when supported on openGL
            var mipmaps = GraphicsDevice.Platform == GraphicsPlatform.OpenGLES && profile < GraphicsProfile.Level_10_0 ? 1 : 3; // TODO remove this limitation when GetData is fixed on OpenGl ES for mipmap levels other than 0

            PerformTest(
                game =>
                {
                    const int width = 16;
                    const int height = width;
                    var arraySize = testArray ? 2 : 1;

                    var destinationIsStaged = new[] { true, false };

                    foreach (var destinationStaged in destinationIsStaged)
                    {
                        var pixelFormats = new List<PixelFormat> { PixelFormat.R8G8B8A8_UNorm, PixelFormat.R8G8B8A8_UNorm_SRgb, PixelFormat.R8_UNorm };
#if SILICONSTUDIO_XENKO_GRAPHICS_API_OPENGLES
                        if(!game.GraphicsDevice.HasTextureRG)
                            pixelFormats.Remove(PixelFormat.R8_UNorm);
#endif

                        foreach (var pixelFormat in pixelFormats)
                        {
                            var computer = pixelFormat.SizeInBytes() == 1 ? (Func<int, int, int, int, int, byte>)ColorComputerR8 : DefaultColorComputer;
                            var data = CreateDebugTextureData(width, height, mipmaps, arraySize, pixelFormat, computer);

                            var sourceFlags = usageSource == GraphicsResourceUsage.Default ?
                                new[] { TextureFlags.ShaderResource, TextureFlags.RenderTarget, TextureFlags.RenderTarget | TextureFlags.ShaderResource } :
                                new[] { TextureFlags.None };

                            foreach (var flag in sourceFlags)
                            {
                                using (var texture = CreateDebugTexture(game.GraphicsDevice, data, width, height, mipmaps, arraySize, pixelFormat, flag, usageSource))
                                using (var copyTexture = destinationStaged ? texture.ToStaging(): texture.Clone())
                                {
                                    game.GraphicsContext.CommandList.Copy(texture, copyTexture);

                                    CheckDebugTextureData(game.GraphicsContext, copyTexture, width, height, mipmaps, arraySize, pixelFormat, flag, usageSource, computer);
                                }
                            }
                        }
                    }
                },
                profile);
        }
Ejemplo n.º 17
0
 /// <summary>
 /// Creates a new Vertex buffer with <see cref="GraphicsResourceUsage.Default"/> usage by default.
 /// </summary>
 /// <typeparam name="T">Type of the Vertex buffer to get the sizeof from</typeparam>
 /// <param name="device">The <see cref="GraphicsDevice"/>.</param>
 /// <param name="vertexBufferCount">Number of vertex in this buffer with the sizeof(T).</param>
 /// <param name="usage">The usage.</param>
 /// <returns>A Vertex buffer</returns>
 public static Buffer <T> New <T>(GraphicsDevice device, int vertexBufferCount, GraphicsResourceUsage usage = GraphicsResourceUsage.Default) where T : struct
 {
     return(Buffer.New <T>(device, vertexBufferCount, BufferFlags.VertexBuffer, usage));
 }
Ejemplo n.º 18
0
        private unsafe Texture CreateDebugTexture(GraphicsDevice device, byte[] data, int width, int height, int mipmaps, int arraySize, PixelFormat format, TextureFlags flags, GraphicsResourceUsage usage)
        {
            fixed (byte* pData = data)
            {
                var sizeInBytes = format.SizeInBytes();

                var offset = 0;
                var dataBoxes = new DataBox[arraySize * mipmaps];
                for (int array = 0; array < arraySize; array++)
                {
                    for (int mip = 0; mip < mipmaps; mip++)
                    {
                        var w = width >> mip;
                        var h = height >> mip;
                        var rowStride = w * sizeInBytes;
                        var sliceStride = rowStride * h;

                        dataBoxes[array * mipmaps + mip] = new DataBox((IntPtr)pData + offset, rowStride, sliceStride);

                        offset += sliceStride;
                    }
                }

                return Texture.New2D(device, width, height, mipmaps, format, dataBoxes, flags, arraySize, usage);
            }
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Creates a new <see cref="Buffer" /> instance.
        /// </summary>
        /// <param name="device">The <see cref="GraphicsDevice"/>.</param>
        /// <param name="bufferSize">Size of the buffer in bytes.</param>
        /// <param name="elementSize">Size of an element in the buffer.</param>
        /// <param name="bufferFlags">The buffer flags to specify the type of buffer.</param>
        /// <param name="viewFormat">The view format must be specified if the buffer is declared as a shared resource view.</param>
        /// <param name="usage">The usage.</param>
        /// <returns>An instance of a new <see cref="Buffer" /></returns>
        public static Buffer New(GraphicsDevice device, int bufferSize, int elementSize, BufferFlags bufferFlags, PixelFormat viewFormat, GraphicsResourceUsage usage = GraphicsResourceUsage.Default)
        {
            viewFormat = CheckPixelFormat(bufferFlags, elementSize, viewFormat);
            var description = NewDescription(bufferSize, elementSize, bufferFlags, usage);

            return(new Buffer(device).InitializeFromImpl(description, bufferFlags, viewFormat, IntPtr.Zero));
        }
Ejemplo n.º 20
0
        private void CheckDebugTextureData(GraphicsContext graphicsContext, Texture debugTexture, int width, int height, int mipmaps, int arraySize,
            PixelFormat format, TextureFlags flags, GraphicsResourceUsage usage, Func<int, int, int, int, int, byte> dataComputer)
        {
            var pixelSize = format.SizeInBytes();

            for (int arraySlice = 0; arraySlice < arraySize; arraySlice++)
            {
                for (int mipSlice = 0; mipSlice < mipmaps; mipSlice++)
                {
                    var w = width >> mipSlice;
                    var h = height >> mipSlice;

                    var readData = debugTexture.GetData<byte>(graphicsContext.CommandList, arraySlice, mipSlice);

                    for (int r = 0; r < h; r++)
                    {
                        for (int c = 0; c < w; c++)
                        {
                            for (int i = 0; i < pixelSize; i++)
                            {
                                var value = readData[(r * w + c) * pixelSize + i];
                                var expectedValue = dataComputer(c, r, mipSlice, arraySlice, i);

                                if (!expectedValue.Equals(value))
                                    Assert.Fail("The texture data get at [{0}, {1}] for mipmap level '{2}' and slice '{3}' with flags '{4}', usage '{5}' and format '{6}' is not valid. " +
                                                "Expected '{7}' but was '{8}' at index '{9}'",
                                                c, r, mipSlice, arraySlice, flags, usage, format, expectedValue, value, i);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 21
0
 /// <summary>
 /// Creates a new <see cref="Buffer" /> instance from a byte array.
 /// </summary>
 /// <param name="device">The <see cref="GraphicsDevice"/>.</param>
 /// <param name="initialValue">The initial value of this buffer.</param>
 /// <param name="elementSize">Size of an element. Must be equal to 2 or 4 for an index buffer, or to the size of a struct for a structured/typed buffer. Can be set to 0 for other buffers.</param>
 /// <param name="bufferFlags">The buffer flags to specify the type of buffer.</param>
 /// <param name="viewFormat">The view format must be specified if the buffer is declared as a shared resource view.</param>
 /// <param name="usage">The usage.</param>
 /// <returns>An instance of a new <see cref="Buffer" /></returns>
 public static Buffer New(GraphicsDevice device, byte[] initialValue, int elementSize, BufferFlags bufferFlags, PixelFormat viewFormat = PixelFormat.None, GraphicsResourceUsage usage = GraphicsResourceUsage.Immutable)
 {
     return(new Buffer(device).InitializeFrom(initialValue, elementSize, bufferFlags, viewFormat, usage));
 }
 /// <summary>
 /// Creates a new Cube <see cref="TextureDescription"/>.
 /// </summary>
 /// <param name="size">The size (in pixels) of the top-level faces of the cube texture.</param>
 /// <param name="mipCount">Number of mipmaps, set to true to have all mipmaps, set to an int &gt;=1 for a particular mipmap count.</param>
 /// <param name="format">Describes the format to use.</param>
 /// <param name="textureFlags">The texture flags.</param>
 /// <param name="usage">The usage.</param>
 /// <returns>A new instance of <see cref="TextureDescription"/> class.</returns>
 public static TextureDescription NewCube(int size, MipMapCount mipCount, PixelFormat format, TextureFlags textureFlags = TextureFlags.ShaderResource, GraphicsResourceUsage usage = GraphicsResourceUsage.Default)
 {
     return NewCube(size, format, textureFlags, mipCount, usage);
 }
Ejemplo n.º 23
0
        internal unsafe Buffer InitializeFrom(byte[] initialValue, int elementSize, BufferFlags bufferFlags, PixelFormat viewFormat = PixelFormat.None, GraphicsResourceUsage usage = GraphicsResourceUsage.Immutable)
        {
            int bufferSize = initialValue.Length;

            viewFormat = CheckPixelFormat(bufferFlags, elementSize, viewFormat);

            var description = NewDescription(bufferSize, elementSize, bufferFlags, usage);

            return(InitializeFromImpl(description, bufferFlags, viewFormat, (IntPtr)Interop.Fixed(initialValue)));
        }
 private static TextureDescription NewCube(int size, PixelFormat format, TextureFlags textureFlags, int mipCount, GraphicsResourceUsage usage)
 {
     var desc = New2D(size, size, format, textureFlags, mipCount, 6, usage);
     desc.Dimension = TextureDimension.TextureCube;
     return desc;
 }
 /// <summary>
 /// Creates a new 1D <see cref="Texture"/> with a single mipmap.
 /// </summary>
 /// <param name="device">The <see cref="GraphicsDevice"/>.</param>
 /// <param name="width">The width.</param>
 /// <param name="format">Describes the format to use.</param>
 /// <param name="usage">The usage.</param>
 /// <param name="textureFlags">true if the texture needs to support unordered read write.</param>
 /// <param name="arraySize">Size of the texture 2D array, default to 1.</param>
 /// <returns>
 /// A new instance of 1D <see cref="Texture"/> class.
 /// </returns>
 public static Texture New1D(GraphicsDevice device, int width, PixelFormat format, TextureFlags textureFlags = TextureFlags.ShaderResource, int arraySize = 1, GraphicsResourceUsage usage = GraphicsResourceUsage.Default)
 {
     return(New1D(device, width, false, format, textureFlags, arraySize, usage));
 }
Ejemplo n.º 26
0
 /// <summary>
 /// Creates a new Raw buffer with <see cref="GraphicsResourceUsage.Default"/> uasge by default.
 /// </summary>
 /// <param name="device">The <see cref="GraphicsDevice"/>.</param>
 /// <param name="value">The value to initialize the Raw buffer.</param>
 /// <param name="additionalBindings">The additional bindings (for example, to create a combined raw/index buffer, pass <see cref="BufferFlags.IndexBuffer" />)</param>
 /// <param name="usage">The usage of this resource.</param>
 /// <returns>A Raw buffer</returns>
 public static Buffer New(GraphicsDevice device, DataPointer value, BufferFlags additionalBindings = BufferFlags.None, GraphicsResourceUsage usage = GraphicsResourceUsage.Default)
 {
     return(Buffer.New(device, value, 0, BufferFlags.RawBuffer | additionalBindings, usage));
 }
 /// <summary>
 /// Creates a new 1D <see cref="Texture" /> with a single level of mipmap.
 /// </summary>
 /// <typeparam name="T">Type of the initial data to upload to the texture</typeparam>
 /// <param name="device">The <see cref="GraphicsDevice"/>.</param>
 /// <param name="width">The width.</param>
 /// <param name="format">Describes the format to use.</param>
 /// <param name="usage">The usage.</param>
 /// <param name="textureData">Texture data. Size of must be equal to sizeof(Format) * width </param>
 /// <param name="textureFlags">true if the texture needs to support unordered read write.</param>
 /// <returns>A new instance of <see cref="Texture" /> class.</returns>
 /// <remarks>
 /// The first dimension of mipMapTextures describes the number of array (Texture Array), second dimension is the mipmap, the third is the texture data for a particular mipmap.
 /// </remarks>
 public unsafe static Texture New1D <T>(GraphicsDevice device, int width, PixelFormat format, T[] textureData, TextureFlags textureFlags = TextureFlags.ShaderResource, GraphicsResourceUsage usage = GraphicsResourceUsage.Immutable) where T : struct
 {
     return(New(device, TextureDescription.New1D(width, format, textureFlags, usage), new[] { GetDataBox(format, width, 1, 1, textureData, (IntPtr)Interop.Fixed(textureData)) }));
 }
Ejemplo n.º 28
0
 /// <summary>
 /// Creates a new 3D <see cref="Texture"/> 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="depth">The depth.</param>
 /// <param name="format">Describes the format to use.</param>
 /// <param name="usage">The usage.</param>
 /// <param name="textureFlags">true if the texture needs to support unordered read write.</param>
 /// <returns>
 /// A new instance of 3D <see cref="Texture"/> class.
 /// </returns>
 public static Texture New3D(GraphicsDevice device, int width, int height, int depth, PixelFormat format, TextureFlags textureFlags = TextureFlags.ShaderResource, GraphicsResourceUsage usage = GraphicsResourceUsage.Default)
 {
     return(New3D(device, width, height, depth, false, format, textureFlags, usage));
 }
Ejemplo n.º 29
0
 /// <summary>
 /// Creates a new description from another description but overrides <see cref="Flags"/> and <see cref="Usage"/>.
 /// </summary>
 /// <param name="desc">The desc.</param>
 /// <param name="textureFlags">The texture flags.</param>
 /// <param name="usage">The usage.</param>
 /// <returns>TextureDescription.</returns>
 public static TextureDescription FromDescription(TextureDescription desc, TextureFlags textureFlags, GraphicsResourceUsage usage)
 {
     desc.Flags = textureFlags;
     desc.Usage = usage;
     if ((textureFlags & TextureFlags.UnorderedAccess) != 0)
     {
         desc.Usage = GraphicsResourceUsage.Default;
     }
     return(desc);
 }
Ejemplo n.º 30
0
 /// <summary>
 /// Creates a new 3D <see cref="Texture"/>.
 /// </summary>
 /// <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="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="textureFlags">true if the texture needs to support unordered read write.</param>
 /// <returns>
 /// A new instance of 3D <see cref="Texture"/> class.
 /// </returns>
 public static Texture New3D(GraphicsDevice device, int width, int height, int depth, MipMapCount mipCount, PixelFormat format, TextureFlags textureFlags = TextureFlags.ShaderResource, GraphicsResourceUsage usage = GraphicsResourceUsage.Default)
 {
     return(new Texture(device).InitializeFrom(TextureDescription.New3D(width, height, depth, mipCount, format, textureFlags, usage)));
 }
Ejemplo n.º 31
0
 /// <summary>
 /// Creates a new Argument buffer with <see cref="GraphicsResourceUsage.Default"/> uasge by default.
 /// </summary>
 /// <typeparam name="T">Type of the Argument buffer to get the sizeof from</typeparam>
 /// <param name="device">The <see cref="GraphicsDevice"/>.</param>
 /// <param name="value">The value to initialize the Argument buffer.</param>
 /// <param name="usage">The usage of this resource.</param>
 /// <returns>A Argument buffer</returns>
 public static Buffer <T> New <T>(GraphicsDevice device, ref T value, GraphicsResourceUsage usage = GraphicsResourceUsage.Default) where T : struct
 {
     return(Buffer.New(device, ref value, BufferFlags.ArgumentBuffer, usage));
 }
Ejemplo n.º 32
0
 /// <summary>
 /// Creates a new 3D <see cref="Texture" /> 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="textureFlags">true if the texture needs to support unordered read write.</param>
 /// <returns>A new instance of 3D <see cref="Texture" /> class.</returns>
 /// <remarks>
 /// The first dimension of mipMapTextures describes the number of is an array ot Texture3D Array
 /// </remarks>
 public static unsafe Texture New3D <T>(GraphicsDevice device, int width, int height, int depth, PixelFormat format, T[] textureData, TextureFlags textureFlags = TextureFlags.ShaderResource, GraphicsResourceUsage usage = GraphicsResourceUsage.Immutable) where T : struct
 {
     return(New3D(device, width, height, depth, 1, format, new[] { GetDataBox(format, width, height, depth, textureData, (IntPtr)Interop.Fixed(textureData)) }, textureFlags, usage));
 }
Ejemplo n.º 33
0
 /// <summary>
 /// Creates a new Vertex buffer with <see cref="GraphicsResourceUsage.Immutable"/> uasge by default.
 /// </summary>
 /// <typeparam name="T">Type of the Vertex buffer to get the sizeof from</typeparam>
 /// <param name="device">The <see cref="GraphicsDevice"/>.</param>
 /// <param name="value">The value to initialize the Vertex buffer.</param>
 /// <param name="usage">The usage of this resource.</param>
 /// <returns>A Vertex buffer</returns>
 public static Buffer <T> New <T>(GraphicsDevice device, T[] value, GraphicsResourceUsage usage = GraphicsResourceUsage.Immutable) where T : struct
 {
     return(Buffer.New(device, value, BufferFlags.VertexBuffer, usage));
 }
Ejemplo n.º 34
0
 /// <summary>
 /// Creates a new index buffer with <see cref="GraphicsResourceUsage.Default"/> uasge by default.
 /// </summary>
 /// <typeparam name="T">Type of the index buffer to get the sizeof from</typeparam>
 /// <param name="device">The <see cref="GraphicsDevice"/>.</param>
 /// <param name="usage">The usage.</param>
 /// <returns>A index buffer</returns>
 public static Buffer <T> New <T>(GraphicsDevice device, GraphicsResourceUsage usage = GraphicsResourceUsage.Default) where T : struct
 {
     return(Buffer.New <T>(device, 1, BufferFlags.IndexBuffer, usage));
 }
Ejemplo n.º 35
0
 /// <summary>
 /// Creates a new Vertex buffer with <see cref="GraphicsResourceUsage.Immutable"/> uasge by default.
 /// </summary>
 /// <param name="device">The <see cref="GraphicsDevice"/>.</param>
 /// <param name="value">The value to initialize the Vertex buffer.</param>
 /// <param name="usage">The usage of this resource.</param>
 /// <returns>A Vertex buffer</returns>
 public static Buffer New(GraphicsDevice device, DataPointer value, GraphicsResourceUsage usage = GraphicsResourceUsage.Immutable)
 {
     return(Buffer.New(device, value, 0, BufferFlags.VertexBuffer, usage));
 }
Ejemplo n.º 36
0
 /// <summary>
 /// Creates a new index buffer with <see cref="GraphicsResourceUsage.Immutable"/> uasge by default.
 /// </summary>
 /// <param name="device">The <see cref="GraphicsDevice"/>.</param>
 /// <param name="value">The value to initialize the index buffer.</param>
 /// <param name="is32BitIndex">Set to true if the buffer is using a 32 bit index or false for 16 bit index.</param>
 /// <param name="usage">The usage of this resource.</param>
 /// <returns>A index buffer</returns>
 public static Buffer New(GraphicsDevice device, byte[] value, bool is32BitIndex, GraphicsResourceUsage usage = GraphicsResourceUsage.Immutable)
 {
     return(Buffer.New(device, value, is32BitIndex ? 4 : 2, BufferFlags.IndexBuffer, PixelFormat.None, usage));
 }
Ejemplo n.º 37
0
 /// <summary>
 /// Creates a new <see cref="Buffer" /> instance.
 /// </summary>
 /// <param name="device">The <see cref="GraphicsDevice"/>.</param>
 /// <param name="bufferSize">Size of the buffer in bytes.</param>
 /// <param name="bufferFlags">The buffer flags to specify the type of buffer.</param>
 /// <param name="viewFormat">The view format must be specified if the buffer is declared as a shared resource view.</param>
 /// <param name="usage">The usage.</param>
 /// <returns>An instance of a new <see cref="Buffer" /></returns>
 public static Buffer New(GraphicsDevice device, int bufferSize, BufferFlags bufferFlags, PixelFormat viewFormat, GraphicsResourceUsage usage = GraphicsResourceUsage.Default)
 {
     return(New(device, bufferSize, 0, bufferFlags, viewFormat, usage));
 }
Ejemplo n.º 38
0
 /// <summary>
 /// Creates a new constant buffer with a default <see cref="GraphicsResourceUsage.Dynamic"/> usage.
 /// </summary>
 /// <param name="device">The <see cref="GraphicsDevice"/>.</param>
 /// <param name="size">The size in bytes.</param>
 /// <param name="usage">The usage.</param>
 /// <returns>A constant buffer</returns>
 public static Buffer New(GraphicsDevice device, int size, GraphicsResourceUsage usage = GraphicsResourceUsage.Dynamic)
 {
     return(Buffer.New(device, size, BufferFlags.ConstantBuffer, usage));
 }
Ejemplo n.º 39
0
        /// <summary>
        /// Creates a new <see cref="Buffer" /> instance.
        /// </summary>
        /// <param name="device">The <see cref="GraphicsDevice"/>.</param>
        /// <typeparam name="T">Type of the buffer, to get the sizeof from.</typeparam>
        /// <param name="value">The initial value of this buffer.</param>
        /// <param name="bufferFlags">The buffer flags to specify the type of buffer.</param>
        /// <param name="viewFormat">The view format must be specified if the buffer is declared as a shared resource view.</param>
        /// <param name="usage">The usage.</param>
        /// <returns>An instance of a new <see cref="Buffer" /></returns>
        public static unsafe Buffer <T> New <T>(GraphicsDevice device, ref T value, BufferFlags bufferFlags, PixelFormat viewFormat, GraphicsResourceUsage usage = GraphicsResourceUsage.Default) where T : struct
        {
            int bufferSize  = Utilities.SizeOf <T>();
            int elementSize = ((bufferFlags & BufferFlags.StructuredBuffer) != 0) ? Utilities.SizeOf <T>() : 0;

            viewFormat = CheckPixelFormat(bufferFlags, elementSize, viewFormat);

            var description = NewDescription(bufferSize, elementSize, bufferFlags, usage);

            return(new Buffer <T>(device, description, bufferFlags, viewFormat, (IntPtr)Interop.Fixed(ref value)));
        }
Ejemplo n.º 40
0
 /// <summary>
 /// Creates a new constant buffer with <see cref="GraphicsResourceUsage.Dynamic"/> usage.
 /// </summary>
 /// <typeparam name="T">Type of the constant buffer to get the sizeof from</typeparam>
 /// <param name="device">The <see cref="GraphicsDevice"/>.</param>
 /// <param name="value">The value to initialize the constant buffer.</param>
 /// <param name="usage">The usage of this resource.</param>
 /// <returns>A constant buffer</returns>
 public static Buffer <T> New <T>(GraphicsDevice device, T[] value, GraphicsResourceUsage usage = GraphicsResourceUsage.Dynamic) where T : struct
 {
     return(Buffer.New(device, value, BufferFlags.ConstantBuffer, usage));
 }
Ejemplo n.º 41
0
        /// <summary>
        /// Creates a new <see cref="Buffer" /> instance.
        /// </summary>
        /// <typeparam name="T">Type of the buffer, to get the sizeof from.</typeparam>
        /// <param name="device">The <see cref="GraphicsDevice"/>.</param>
        /// <param name="initialValue">The initial value of this buffer.</param>
        /// <param name="bufferFlags">The buffer flags to specify the type of buffer.</param>
        /// <param name="viewFormat">The view format must be specified if the buffer is declared as a shared resource view.</param>
        /// <param name="usage">The usage.</param>
        /// <returns>An instance of a new <see cref="Buffer" /></returns>
        public static unsafe Buffer <T> New <T>(GraphicsDevice device, T[] initialValue, BufferFlags bufferFlags, PixelFormat viewFormat, GraphicsResourceUsage usage = GraphicsResourceUsage.Default) where T : struct
        {
            int bufferSize  = Utilities.SizeOf <T>() * initialValue.Length;
            int elementSize = Utilities.SizeOf <T>();

            viewFormat = CheckPixelFormat(bufferFlags, elementSize, viewFormat);

            var description = NewDescription(bufferSize, elementSize, bufferFlags, usage);

            return(new Buffer <T>(device, description, bufferFlags, viewFormat, (IntPtr)Interop.Fixed(initialValue)));
        }
Ejemplo n.º 42
0
 /// <summary>
 /// Creates a new constant buffer with <see cref="GraphicsResourceUsage.Dynamic"/> usage.
 /// </summary>
 /// <param name="device">The <see cref="GraphicsDevice"/>.</param>
 /// <param name="value">The value to initialize the constant buffer.</param>
 /// <param name="usage">The usage of this resource.</param>
 /// <returns>A constant buffer</returns>
 public static Buffer New(GraphicsDevice device, DataPointer value, GraphicsResourceUsage usage = GraphicsResourceUsage.Dynamic)
 {
     return(Buffer.New(device, value, 0, BufferFlags.ConstantBuffer, usage));
 }
Ejemplo n.º 43
0
 /// <summary>
 /// Creates a new <see cref="Buffer" /> instance.
 /// </summary>
 /// <param name="device">The <see cref="GraphicsDevice"/>.</param>
 /// <param name="dataPointer">The data pointer.</param>
 /// <param name="elementSize">Size of the element.</param>
 /// <param name="bufferFlags">The buffer flags to specify the type of buffer.</param>
 /// <param name="usage">The usage.</param>
 /// <returns>An instance of a new <see cref="Buffer" /></returns>
 public static Buffer New(GraphicsDevice device, DataPointer dataPointer, int elementSize, BufferFlags bufferFlags, GraphicsResourceUsage usage = GraphicsResourceUsage.Default)
 {
     return(New(device, dataPointer, elementSize, bufferFlags, PixelFormat.None, usage));
 }
 /// <summary>
 /// Creates a new <see cref="TextureDescription" />.
 /// </summary>
 /// <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 &gt;=1 for a particular mipmap count.</param>
 /// <param name="format">Describes the format to use.</param>
 /// <param name="textureFlags">true if the texture needs to support unordered read write.</param>
 /// <param name="usage">The usage.</param>
 /// <returns>A new instance of <see cref="TextureDescription" /> class.</returns>
 public static TextureDescription New3D(int width, int height, int depth, MipMapCount mipCount, PixelFormat format, TextureFlags textureFlags = TextureFlags.ShaderResource, GraphicsResourceUsage usage = GraphicsResourceUsage.Default)
 {
     return New3D(width, height, depth, format, textureFlags, mipCount, usage);
 }