Skip to content

Commit

Permalink
SKVertices: CreateCopy is missing overload to pass vertices' and …
Browse files Browse the repository at this point in the history
…indexes' offset + count
  • Loading branch information
seclerp committed Mar 29, 2023
1 parent b8efe44 commit 1091ce1
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions binding/Binding/SKVertices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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, t + vertexOffset, (uint*)c + vertexOffset, indexCount, i + indexOffset));
}
}

Expand Down

0 comments on commit 1091ce1

Please sign in to comment.