summaryrefslogtreecommitdiff
path: root/Extensions.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Extensions.cs')
-rw-r--r--Extensions.cs29
1 files changed, 27 insertions, 2 deletions
diff --git a/Extensions.cs b/Extensions.cs
index e6368c3..80a8e2f 100644
--- a/Extensions.cs
+++ b/Extensions.cs
@@ -1,8 +1,9 @@
using System.Numerics;
+using Raylib_cs;
namespace OnekoOnline;
-static class MathExtensions
+static class MathExt
{
public static Vector2 LimitLength(this Vector2 toLimit, float lengthLimit)
{
@@ -17,7 +18,7 @@ static class MathExtensions
}
}
-static class StringExtensions
+static class StringExt
{
public static string LimitLength(this string value, int maxLength)
{
@@ -26,6 +27,30 @@ static class StringExtensions
}
}
+static class RaylibExt
+{
+ public static int TextureLength(int width, int height, PixelFormat format, int mipmaps)
+ {
+ int size = 0;
+
+ for (int i = 0; i < mipmaps; i++) {
+ size += Raylib.GetPixelDataSize(width, height, format);
+
+ //Max is a security check for NPOT textures
+ width = Math.Max(width/2, 1);
+ height = Math.Max(height/2, 1);
+ }
+
+ return size;
+ }
+
+ public static int DataLength(this Image img) => TextureLength(img.Width, img.Height, img.Format, img.Mipmaps);
+
+ public static int DataLength(this Texture2D tex) => TextureLength(tex.Width, tex.Height, tex.Format, tex.Mipmaps);
+
+ public unsafe static Span<byte> DataSpan(this Image img) => new(img.Data, img.DataLength());
+}
+
public static class Directions
{
public static readonly Vector2 Up = new(0,-1);