bufferData method
Creates and initializes a buffer object's data store
Parameters
-
target
Specifies the target buffer object. The symbolic constant must be
- GL_ARRAY_BUFFER, GL_ATOMIC_COUNTER_BUFFER, GL_COPY_READ_BUFFER,
- GL_COPY_WRITE_BUFFER, GL_DRAW_INDIRECT_BUFFER,
- GL_DISPATCH_INDIRECT_BUFFER, GL_ELEMENT_ARRAY_BUFFER,
- GL_PIXEL_PACK_BUFFER, GL_PIXEL_UNPACK_BUFFER,
- GL_SHADER_STORAGE_BUFFER, GL_TRANSFORM_FEEDBACK_BUFFER, or
- GL_UNIFORM_BUFFER.
-
data
Specifies a pointer to data that will be copied into the data store for initialization, or NULL if no data is to be copied.
-
usage
Specifies the expected usage pattern of the data store. The symbolic constant must be GL_STREAM_DRAW, GL_STREAM_READ, GL_STREAM_COPY, GL_STATIC_DRAW, GL_STATIC_READ, GL_STATIC_COPY, GL_DYNAMIC_DRAW, GL_DYNAMIC_READ, or GL_DYNAMIC_COPY.
Implementation
void bufferData(int target, dynamic 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 Uint8List) {
nativeData = uint8ListToArrayPointer(data).cast();
size = data.length * sizeOf<Uint8>();
} 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);
}