I have updated the flutter_gl
package from 0.0.3
to 0.0.5
and I notice an issue
I have a code that sets the colors with buffer data but the lib complains about adding one more parameter in gl.bufferData
.
Code to reproduce
This is the code that worked before the update.
setColors(gl) {
Float32List data = Float32List.fromList([
Random().nextDouble(), Random().nextDouble(), Random().nextDouble(), 1, //
Random().nextDouble(), Random().nextDouble(), Random().nextDouble(), 1, //
Random().nextDouble(), Random().nextDouble(), Random().nextDouble(), 1, //
Random().nextDouble(), Random().nextDouble(), Random().nextDouble(), 1, //
Random().nextDouble(), Random().nextDouble(), Random().nextDouble(), 1, //
Random().nextDouble(), Random().nextDouble(), Random().nextDouble(), 1, //
]);
gl.bufferData(gl.ARRAY_BUFFER, data, gl.STATIC_DRAW);
}
and I get this error
OpenGLContextWeb
{gl: [object WebGL2RenderingContext]}
Error: NoSuchMethodError: 'bufferData'
Dynamic call with too few arguments. Expected: 4 Actual: 3
In your example, ExampleDemoTest.dart
I saw that you provide 4 arguments
var vertices = new Float32List.fromList([
0.0, 0.5, 0.0, // Vertice #1
-0.5, -0.5, 0.0, // Vertice #2
0.5, -0.5, 0.0 // Vertice #3
]);
final verticesPtr = calloc<Float>(vertices.length);
verticesPtr.asTypedList(vertices.length).setAll(0, vertices);
gl.bufferData(gl.ARRAY_BUFFER, vertices.length * Float32List.bytesPerElement, verticesPtr, gl.STATIC_DRAW);
What do you think we need to provide the size parameter? or it will be better to have it like it was before with only 3 params
now you have this method
bufferData(int target, int size, data, int usage) {
gl.glBufferData(target, size, data.cast<Void>(), usage);
}
after the change
bufferData(int target, data, int usage) {
late Pointer<Void> nativeData;
late int size;
if (data is List<double> || data is Float32List) {
nativeData = floatListToArrayPointer(data as List<double>).cast();
size = data.length * sizeOf<Float>();
} else if (data is Int32List) {
nativeData = int32ListToArrayPointer(data).cast();
size = data.length * sizeOf<Int32>();
} else if (data is Uint16List) {
nativeData = uInt16ListToArrayPointer(data).cast();
size = data.length * sizeOf<Uint16>();
} else if (data is Uint32List) {
nativeData = uInt32ListToArrayPointer(data).cast();
size = data.length * sizeOf<Uint32>();
} else {
throw ('bufferData: unsupported native type ${data.runtimeType}');
}
gl.glBufferData(target, size, nativeData, usage);
calloc.free(nativeData);
}
I think is better for the user to provide the Float32List and handle all the native code inside the OpenGLContextES.dart
file as you did before.
Also notice by importing the dart:ffi
package breaks the web version of the app.
and I get all these errors.
flutter run
Multiple devices found:
Chrome (web) • chrome • web-javascript • Google Chrome 93.0.4577.82
Edge (web) • edge • web-javascript • Microsoft Edge 93.0.961.52
[1]: Chrome (chrome)
[2]: Edge (edge)
Please choose one (To quit, press "q/Q"): 1
Launching lib\main.dart on Chrome in debug mode...
lib/engine.dart:6:8: Error: Not found: 'dart:ffi'
import 'dart:ffi';
^
/G:/Programs/flutter/.pub-cache/hosted/pub.dartlang.org/ffi-1.1.2/lib/src/allocation.dart:5:8: Error: Not found: 'dart:ffi'
import 'dart:ffi';
^
/G:/Programs/flutter/.pub-cache/hosted/pub.dartlang.org/ffi-1.1.2/lib/src/arena.dart:8:8: Error: Not found: 'dart:ffi'
import 'dart:ffi';
^
/G:/Programs/flutter/.pub-cache/hosted/pub.dartlang.org/ffi-1.1.2/lib/src/utf8.dart:6:8: Error: Not found: 'dart:ffi'
import 'dart:ffi';
^
/G:/Programs/flutter/.pub-cache/hosted/pub.dartlang.org/ffi-1.1.2/lib/src/utf16.dart:5:8: Error: Not found: 'dart:ffi'
import 'dart:ffi';
^
/G:/Programs/flutter/.pub-cache/hosted/pub.dartlang.org/ffi-1.1.2/lib/src/allocation.dart:9:7: Error: Type 'DynamicLibrary' not found.
final DynamicLibrary stdlib = Platform.isWindows
also when try to run the app into an android device I get this errors
flutter run
Launching lib\main.dart on Lenovo TB J606F in debug mode...
FAILURE: Build failed with an exception.
Execution failed for task ':app:checkDebugAarMetadata'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
> Could not find :threeegl:.
Searched in the following locations:
Required by:
project :app > project :flutter_gl
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 4s
Thanks