Skip to content

Commit 1091ce1

Browse files
committed
SKVertices: CreateCopy is missing overload to pass vertices' and indexes' offset + count
1 parent b8efe44 commit 1091ce1

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

binding/Binding/SKVertices.cs

+25-3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,19 @@ public static SKVertices CreateCopy (SKVertexMode vmode, SKPoint[] positions, SK
3131
}
3232

3333
public static SKVertices CreateCopy (SKVertexMode vmode, SKPoint[] positions, SKPoint[] texs, SKColor[] colors, UInt16[] indices)
34+
{
35+
var vertexCount = positions.Length;
36+
var indexCount = indices?.Length ?? 0;
37+
38+
return CreateCopy (vmode, vertexCount, positions, texs, colors, indexCount, indices);
39+
}
40+
41+
public static SKVertices CreateCopy (SKVertexMode vmode, int vertexCount, SKPoint[] positions, SKPoint[] texs, SKColor[] colors, int indexCount, UInt16[] indices)
42+
{
43+
return CreateCopy (vmode, 0, vertexCount, positions, texs, colors, 0, indexCount, indices);
44+
}
45+
46+
public static SKVertices CreateCopy (SKVertexMode vmode, int vertexOffset, int vertexCount, SKPoint[] positions, SKPoint[] texs, SKColor[] colors, int indexOffset, int indexCount, UInt16[] indices)
3447
{
3548
if (positions == null)
3649
throw new ArgumentNullException (nameof (positions));
@@ -40,14 +53,23 @@ public static SKVertices CreateCopy (SKVertexMode vmode, SKPoint[] positions, SK
4053
if (colors != null && positions.Length != colors.Length)
4154
throw new ArgumentException ("The number of colors must match the number of vertices.", nameof (colors));
4255

43-
var vertexCount = positions.Length;
44-
var indexCount = indices?.Length ?? 0;
56+
if (vertexOffset >= positions.Length)
57+
throw new ArgumentException ("The vertex offset should be in bounds of vertex array.", nameof (vertexOffset));
58+
59+
if (vertexOffset + vertexCount >= positions.Length)
60+
throw new ArgumentException ("The vertex count should be in bounds of vertex array.", nameof (vertexOffset));
61+
62+
if (indexOffset >= indices.Length)
63+
throw new ArgumentException ("The index offset should be in bounds of index array.", nameof (vertexOffset));
64+
65+
if (indexOffset + indexCount >= indices.Length)
66+
throw new ArgumentException ("The vertex count should be in bounds of vertex array.", nameof (vertexOffset));
4567

4668
fixed (SKPoint* p = positions)
4769
fixed (SKPoint* t = texs)
4870
fixed (SKColor* c = colors)
4971
fixed (UInt16* i = indices) {
50-
return GetObject (SkiaApi.sk_vertices_make_copy (vmode, vertexCount, p, t, (uint*)c, indexCount, i));
72+
return GetObject (SkiaApi.sk_vertices_make_copy (vmode, vertexCount, p + vertexOffset, t + vertexOffset, (uint*)c + vertexOffset, indexCount, i + indexOffset));
5173
}
5274
}
5375

0 commit comments

Comments
 (0)