createBuffer method
Implementation
Map<String, dynamic> createBuffer(var attribute, int bufferType,
{String? name}) {
final array = attribute.array;
var usage = attribute.usage;
// dynamic arrayType = attribute.runtimeType;
// print(" WebGLAttributes.createBuffer attribute: ${attribute.runtimeType} arrayType: ${attribute.runtimeType} array: ${array.length} ${array.runtimeType} name: ${name} ");
// print(array.toDartList());
var type = gl.FLOAT;
int bytesPerElement = 4;
var buffer = gl.createBuffer();
gl.bindBuffer(bufferType, buffer);
gl.bufferData(bufferType, array.lengthInBytes, array, usage);
if (attribute.onUploadCallback != null) {
attribute.onUploadCallback!();
}
if (attribute is Float32BufferAttribute) {
type = gl.FLOAT;
bytesPerElement = Float32List.bytesPerElement;
} else if (attribute is Float64BufferAttribute) {
print(
'THREE.WebGLAttributes: Unsupported data buffer format: Float64Array.');
} else if (attribute is Float16BufferAttribute) {
if (isWebGL2) {
bytesPerElement = 2;
type = gl.HALF_FLOAT;
} else {
print(
'THREE.WebGLAttributes: Usage of Float16BufferAttribute requires WebGL2.');
}
} else if (attribute is Uint16BufferAttribute) {
bytesPerElement = Uint16List.bytesPerElement;
type = gl.UNSIGNED_SHORT;
} else if (attribute is Int16BufferAttribute) {
bytesPerElement = Int16List.bytesPerElement;
type = gl.SHORT;
} else if (attribute is Uint32BufferAttribute) {
bytesPerElement = Uint32List.bytesPerElement;
type = gl.UNSIGNED_INT;
} else if (attribute is Int32BufferAttribute) {
bytesPerElement = Int32List.bytesPerElement;
type = gl.INT;
} else if (attribute is Int8BufferAttribute) {
bytesPerElement = Int8List.bytesPerElement;
type = gl.BYTE;
} else if (attribute is Uint8BufferAttribute) {
bytesPerElement = Uint8List.bytesPerElement;
type = gl.UNSIGNED_BYTE;
}
final _v = {
"buffer": buffer,
"type": type,
"bytesPerElement": bytesPerElement,
"array": array,
"version": attribute.version
};
return _v;
}