eglCreateContext function

Pointer<Void> eglCreateContext(
  1. Pointer<Void> display,
  2. Pointer<Void> config, {
  3. int contextClientVersion = 3,
  4. Pointer<Void>? shareContext,
  5. bool isDebugContext = false,
})

Implementation

Pointer<Void> eglCreateContext(
  Pointer<Void> display,
  Pointer<Void> config, {
  int contextClientVersion = 3,
  Pointer<Void>? shareContext,
  bool isDebugContext = false,
}) {
  final attributeList = allocate<Int32>(count: 5);
  attributeList[0] = EGL_CONTEXT_CLIENT_VERSION;
  attributeList[1] = contextClientVersion;
  if (isDebugContext) {
    attributeList[2] = EglValue.none.toIntValue();
  } else {
    attributeList[2] = EGL_CONTEXT_OPENGL_DEBUG;
    attributeList[3] = EGL_TRUE;
    attributeList[4] = EglValue.none.toIntValue();
  }

  final nativeCallResult = _libEGL.eglCreateContext(
      display, config, shareContext ?? nullptr, attributeList);
  late Pointer<Void> result;

  if (nativeCallResult != nullptr) {
    result = nativeCallResult;
  }

  free(attributeList);

  if (nativeCallResult == nullptr) {
    throw EglException(
        'Failed to create context for display [$display], config [$config], context client version $contextClientVersion, share context [$shareContext].');
  }

  return result;
}