A game framework written with osu! in mind.
at master 45 lines 1.5 kB view raw
1// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. 2// See the LICENCE file in the repository root for full licence text. 3 4using System; 5using System.Buffers; 6using osu.Framework.Graphics.Primitives; 7using osuTK.Graphics.ES30; 8using SixLabors.ImageSharp.PixelFormats; 9 10namespace osu.Framework.Graphics.Textures 11{ 12 public class ArrayPoolTextureUpload : ITextureUpload 13 { 14 private readonly ArrayPool<Rgba32> arrayPool; 15 16 private readonly Rgba32[] data; 17 18 /// <summary> 19 /// Create an empty raw texture with an efficient shared memory backing. 20 /// </summary> 21 /// <param name="width">The width of the texture.</param> 22 /// <param name="height">The height of the texture.</param> 23 /// <param name="arrayPool">The source pool to retrieve memory from. Shared default is used if null.</param> 24 public ArrayPoolTextureUpload(int width, int height, ArrayPool<Rgba32> arrayPool = null) 25 { 26 this.arrayPool = arrayPool ?? ArrayPool<Rgba32>.Shared; 27 data = this.arrayPool.Rent(width * height); 28 } 29 30 public void Dispose() 31 { 32 arrayPool.Return(data); 33 } 34 35 public Span<Rgba32> RawData => data; 36 37 public ReadOnlySpan<Rgba32> Data => data; 38 39 public int Level { get; set; } 40 41 public virtual PixelFormat Format => PixelFormat.Rgba; 42 43 public RectangleI Bounds { get; set; } 44 } 45}