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