eglChooseConfig function
Implementation
List<Pointer<Void>> eglChooseConfig(
Pointer<Void> display, {
Map<EglConfigAttribute, int>? attributes,
int maxConfigs = 1,
}) {
final attributeCount = attributes == null ? 1 : attributes.length * 2 + 1;
final attributeList = allocate<Int32>(count: attributeCount);
if (attributes != null) {
final attributeEntries = attributes.entries.toList(growable: false);
for (var i = 0; i < attributeEntries.length; ++i) {
attributeList[i * 2] = attributeEntries[i].key.toIntValue();
attributeList[i * 2 + 1] = attributeEntries[i].value;
}
}
// The list must be terminated with EGL_NONE.
attributeList[attributeCount - 1] = EglValue.none.toIntValue();
final configs = allocate<IntPtr>(count: maxConfigs);
final numConfigs = allocate<Int32>();
final nativeCallSucceeded = _libEGL.eglChooseConfig(
display,
attributeList,
configs.cast<Pointer<Void>>(),
maxConfigs,
numConfigs,
) ==
1;
List<Pointer<Void>> result = <Pointer<Void>>[];
if (nativeCallSucceeded) {
for (var i = 0; i < numConfigs.value; ++i) {
result.add(Pointer.fromAddress(configs[i]));
}
}
free(attributeList);
free(configs);
free(numConfigs);
if (!nativeCallSucceeded) {
throw EglException(
'Failed to choose config for display [$display], attributes $attributes, max configs $maxConfigs.');
}
return result;
}