Ejemplo n.º 1
0
        /// <summary>
        /// Creates a new <see cref="DeviceTexture2D"/>.
        /// </summary>
        /// <param name="pixelData">An array of pixel information.</param>
        /// <param name="width">The width of the texture</param>
        /// <param name="height">The height of the texture</param>
        /// <param name="pixelSizeInBytes">The total size in bytes of the pixel data.</param>
        /// <param name="format">The format of pixel information.</param>
        /// <returns>A new <see cref="DeviceTexture2D"/> containing the given pixel data.</returns>
        public DeviceTexture2D CreateTexture(IntPtr pixelData, int width, int height, PixelFormat format)
        {
            int             pixelSizeInBytes = FormatHelpers.GetPixelSizeInBytes(format);
            DeviceTexture2D tex = CreateTexture(1, width, height, format);

            tex.SetTextureData(0, 0, 0, width, height, pixelData, pixelSizeInBytes * width * height);
            return(tex);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a new <see cref="DeviceTexture2D"/>.
        /// </summary>
        /// <typeparam name="T">The type of pixel data; must be a value type.</typeparam>
        /// <param name="pixelData">An array of pixel information.</param>
        /// <param name="width">The width of the texture</param>
        /// <param name="height">The height of the texture</param>
        /// <param name="pixelSizeInBytes">The total size in bytes of the pixel data.</param>
        /// <param name="format">The format of pixel information.</param>
        /// <returns>A new <see cref="DeviceTexture2D"/> containing the given pixel data.</returns>
        public DeviceTexture2D CreateTexture <T>(T[] pixelData, int width, int height, PixelFormat format) where T : struct
        {
            int             pixelSizeInBytes = FormatHelpers.GetPixelSizeInBytes(format);
            DeviceTexture2D tex    = CreateTexture(1, width, height, format);
            GCHandle        handle = GCHandle.Alloc(pixelData, GCHandleType.Pinned);

            tex.SetTextureData(0, 0, 0, width, height, handle.AddrOfPinnedObject(), pixelSizeInBytes * width * height);
            handle.Free();
            return(tex);
        }
Ejemplo n.º 3
0
        public ConstantBuffer CreateConstantBuffer(ShaderConstantType type)
        {
            if (!FormatHelpers.GetShaderConstantTypeByteSize(type, out int sizeInBytes))
            {
                throw new VeldridException(
                          $"ShaderConstantType passed to CreateConstantBuffer must have a defined size. {type} does not.");
            }

            return(CreateConstantBuffer(sizeInBytes));
        }