createBuffer method
Implementation
Map<String, dynamic> createBuffer(var attribute, int bufferType, {String? name}) {
final array = attribute.array;
var usage = attribute.usage;
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;
}
return {
"buffer": buffer,
"type": type,
"bytesPerElement": bytesPerElement,
"array": array,
"version": attribute.version
};
}