Skip to content

Commit a6d74d0

Browse files
committed
optimized array transmissions
1 parent b9bb783 commit a6d74d0

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

lib/web_gl.dart

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,25 +1166,19 @@ class RenderingContext {
11661166

11671167
Pointer<Float> floatListToArrayPointer(List<double> list) {
11681168
final ptr = calloc<Float>(list.length);
1169-
for (var i = 0; i < list.length; i++) {
1170-
ptr.elementAt(i).value = list[i];
1171-
}
1169+
ptr.asTypedList(list.length).setAll(0, list);
11721170
return ptr;
11731171
}
11741172

11751173
Pointer<Int32> int32ListToArrayPointer(List<int> list) {
11761174
final ptr = calloc<Int32>(list.length);
1177-
for (var i = 0; i < list.length; i++) {
1178-
ptr.elementAt(i).value = list[i];
1179-
}
1175+
ptr.asTypedList(list.length).setAll(0, list);
11801176
return ptr;
11811177
}
11821178

11831179
Pointer<Uint16> uInt16ListToArrayPointer(List<int> list) {
11841180
final ptr = calloc<Uint16>(list.length);
1185-
for (var i = 0; i < list.length; i++) {
1186-
ptr.elementAt(i).value = list[i];
1187-
}
1181+
ptr.asTypedList(list.length).setAll(0, list);
11881182
return ptr;
11891183
}
11901184
// void bufferSubData(int target, int offset, data);
@@ -1493,10 +1487,7 @@ class RenderingContext {
14931487
Pointer<Int8>? nativeBuffer;
14941488
if (pixels != null) {
14951489
nativeBuffer = calloc<Int8>(pixels.lengthInBytes);
1496-
final dartData = pixels.buffer.asUint8List();
1497-
for (int i = 0; i < dartData.lengthInBytes; i++) {
1498-
nativeBuffer.elementAt(i).value = dartData[i];
1499-
}
1490+
nativeBuffer.asTypedList(pixels.lengthInBytes).setAll(0, pixels.buffer.asUint8List());
15001491
}
15011492
gl.glTexImage2D(target, level, internalformat, width, height, border, format, type,
15021493
nativeBuffer != null ? nativeBuffer.cast() : nullptr);

0 commit comments

Comments
 (0)