diff --git a/binding/Binding/SKVertices.cs b/binding/Binding/SKVertices.cs index b45366d1ec..a074fdf4d6 100644 --- a/binding/Binding/SKVertices.cs +++ b/binding/Binding/SKVertices.cs @@ -31,6 +31,19 @@ public static SKVertices CreateCopy (SKVertexMode vmode, SKPoint[] positions, SK } public static SKVertices CreateCopy (SKVertexMode vmode, SKPoint[] positions, SKPoint[] texs, SKColor[] colors, UInt16[] indices) + { + var vertexCount = positions.Length; + var indexCount = indices?.Length ?? 0; + + return CreateCopy (vmode, vertexCount, positions, texs, colors, indexCount, indices); + } + + public static SKVertices CreateCopy (SKVertexMode vmode, int vertexCount, SKPoint[] positions, SKPoint[] texs, SKColor[] colors, int indexCount, UInt16[] indices) + { + return CreateCopy (vmode, 0, vertexCount, positions, texs, colors, 0, indexCount, indices); + } + + public static SKVertices CreateCopy (SKVertexMode vmode, int vertexOffset, int vertexCount, SKPoint[] positions, SKPoint[] texs, SKColor[] colors, int indexOffset, int indexCount, UInt16[] indices) { if (positions == null) throw new ArgumentNullException (nameof (positions)); @@ -40,14 +53,23 @@ public static SKVertices CreateCopy (SKVertexMode vmode, SKPoint[] positions, SK if (colors != null && positions.Length != colors.Length) throw new ArgumentException ("The number of colors must match the number of vertices.", nameof (colors)); - var vertexCount = positions.Length; - var indexCount = indices?.Length ?? 0; + if (vertexOffset >= positions.Length) + throw new ArgumentException ("The vertex offset should be in bounds of vertex array.", nameof (vertexOffset)); + + if (vertexOffset + vertexCount > positions.Length) + throw new ArgumentException ("The vertex count should be in bounds of vertex array.", nameof (vertexOffset)); + + if (indexOffset >= indices.Length) + throw new ArgumentException ("The index offset should be in bounds of index array.", nameof (vertexOffset)); + + if (indexOffset + indexCount > indices.Length) + throw new ArgumentException ("The vertex count should be in bounds of vertex array.", nameof (vertexOffset)); fixed (SKPoint* p = positions) fixed (SKPoint* t = texs) fixed (SKColor* c = colors) fixed (UInt16* i = indices) { - return GetObject (SkiaApi.sk_vertices_make_copy (vmode, vertexCount, p, t, (uint*)c, indexCount, i)); + return GetObject (SkiaApi.sk_vertices_make_copy (vmode, vertexCount, p + vertexOffset * sizeof(SKPoint), t + vertexOffset * sizeof(SKPoint), (uint*)c + vertexOffset * sizeof(uint), indexCount, i + indexOffset * sizeof(ushort))); } }