Files
doom-dm/Engine/Renderer/Texture/IConstTexture.cs
2024-12-04 22:35:04 +03:00

37 lines
1.3 KiB
C#

using Engine.Asset;
using Engine.Renderer.Pixel;
namespace Engine.Renderer.Texture;
public interface IConstTexture<T> where T : struct, IPixel
{
public int Width { get; }
public int Height { get; }
public void ReadPixels(int x, int y, int width, int height, T[,] pixels);
}
public static class ConstTextureExtensions
{
public static T[,] ReadPixels<T>(this IConstTexture<T> texture) where T : struct, IPixel
=> texture.ReadPixels(0, 0, texture.Width, texture.Height);
public static T[,] ReadPixels<T>(this IConstTexture<T> texture, int x, int y, int width, int height)
where T : struct, IPixel
{
var pixels = new T[width, height];
texture.ReadPixels(x, y, width, height, pixels);
return pixels;
}
public static void ReadPixels<T>(this IConstTexture<T> texture, Image<T> image) where T : struct, IPixel
=> texture.ReadPixels(0, 0, image);
public static void ReadPixels<T>(this IConstTexture<T> texture, int x, int y, Image<T> image)
where T : struct, IPixel =>
texture.ReadPixels(x, y, image.Width, image.Height, image.Pixels);
public static void ReadPixels<T>(this IConstTexture<T> texture, T[,] pixels) where T : struct, IPixel
=> texture.ReadPixels(0, 0, texture.Width, texture.Height, pixels);
}