Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SKVertices: CreateCopy is missing overload to pass vertices' and indexes' offset + count #2432

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 * sizeof(SKPoint), t + vertexOffset * sizeof(SKPoint), (uint*)c + vertexOffset * sizeof(uint), indexCount, i + indexOffset * sizeof(ushort)));
}
}

Expand Down