/// <summary> /// Creates an OpenGL context from a Unix/Linux platform. /// </summary> /// <returns> /// A <see cref="IDeviceContext"/> that specify the device context. /// </returns> private static IntPtr CreateEglSimpleContext(IDeviceContext rDevice) { NativeDeviceContext eglDeviceCtx = (NativeDeviceContext)rDevice; IntPtr ctx; List <int> configAttribs = new List <int>(); if (eglDeviceCtx.Version >= Egl.Version_120) { configAttribs.AddRange(new int[] { Egl.RENDERABLE_TYPE, Egl.OPENGL_ES2_BIT }); } configAttribs.AddRange(new int[] { Egl.RED_SIZE, 8, Egl.GREEN_SIZE, 8, Egl.BLUE_SIZE, 8, }); configAttribs.Add(Egl.NONE); int[] configCount = new int[1]; IntPtr[] configs = new IntPtr[8]; if (Egl.BindAPI(Egl.OPENGL_ES_API) == false) { throw new InvalidOperationException("no ES API"); } if (Egl.ChooseConfig(eglDeviceCtx.Display, configAttribs.ToArray(), configs, configs.Length, configCount) == false) { throw new InvalidOperationException("unable to choose configuration"); } if (configCount[0] == 0) { throw new InvalidOperationException("no available configuration"); } List <int> contextAttribs = new List <int>(); if (eglDeviceCtx.Version >= Egl.Version_130) { contextAttribs.AddRange(new int[] { Egl.CONTEXT_CLIENT_VERSION, 2 }); } contextAttribs.Add(Egl.NONE); if ((ctx = Egl.CreateContext(eglDeviceCtx.Display, configs[configs.Length - 1], IntPtr.Zero, contextAttribs.ToArray())) == IntPtr.Zero) { throw new InvalidOperationException("unable to create context"); } List <int> surfaceAttribs = new List <int>(); surfaceAttribs.Add(Egl.NONE); // Egl.RENDER_BUFFER, Egl.BACK_BUFFER, eglDeviceCtx.Surface = Egl.CreateWindowSurface(eglDeviceCtx.Display, configs[configs.Length - 1], eglDeviceCtx.NativeWindow, surfaceAttribs.ToArray()); return(ctx); }