/// <summary> /// Creates a context, specifying attributes. /// </summary> /// <param name="sharedContext"> /// A <see cref="IntPtr"/> that specify a context that will share objects with the returned one. If /// it is IntPtr.Zero, no sharing is performed. /// </param> /// <param name="attribsList"> /// A <see cref="T:Int32[]"/> that specifies the attributes list. /// </param> /// <param name="api"> /// A <see cref="KhronosVersion"/> that specifies the API to be implemented by the returned context. It can be null indicating the /// default API for this DeviceContext implementation. If it is possible, try to determine the API version also. /// </param> /// <returns> /// A <see cref="IntPtr"/> that represents the handle of the created context. If the context cannot be /// created, it returns IntPtr.Zero. /// </returns> /// <exception cref="ArgumentNullException"> /// Exception thrown if <see cref="attribsList"/> is null. /// </exception> /// <exception cref="ArgumentException"> /// Exception thrown if <paramref name="attribsList"/> length is zero or if the last item of <paramref name="attribsList"/> /// is not zero. /// </exception> public override IntPtr CreateContextAttrib(IntPtr sharedContext, int[] attribsList, KhronosVersion api) { if (attribsList == null) { throw new ArgumentNullException("attribsList"); } if (attribsList.Length == 0) { throw new ArgumentException("zero length array", "attribsList"); } if (attribsList[attribsList.Length - 1] != Egl.NONE) { throw new ArgumentException("not EGL_NONE-terminated array", "attribsList"); } IntPtr context; // Select surface pixel format automatically if (_NativeSurface.Handle != IntPtr.Zero) { int[] configId = new int[1]; if (Egl.QuerySurface(Display, EglSurface, Egl.CONFIG_ID, configId) == false) { throw new InvalidOperationException("unable to query EGL surface config ID"); } _Config = ChoosePixelFormat(Display, configId[0]); } // Bind API if (Version >= Egl.Version_120) { uint apiEnum; switch (api.Api) { case KhronosVersion.ApiGles2: case KhronosVersion.ApiGles1: case null: // Default apiEnum = Egl.OPENGL_ES_API; break; case KhronosVersion.ApiGl: apiEnum = Egl.OPENGL_API; break; case KhronosVersion.ApiVg: apiEnum = Egl.OPENVG_API; break; default: throw new InvalidOperationException(String.Format("'{0}' API not available", api)); } if (Egl.BindAPI(apiEnum) == false) { throw new InvalidOperationException("no ES API"); } } else if (api != null && api.Api != KhronosVersion.ApiGles2 && api.Api != KhronosVersion.ApiGles1) { throw new InvalidOperationException(String.Format("'{0}' API not available", api)); } // Create context if ((context = Egl.CreateContext(Display, _Config, sharedContext, attribsList)) == IntPtr.Zero) { throw new InvalidOperationException("unable to create context"); } // Create native surface (pixel format pending) // @todo Back-buffer? if (_NativeSurface.Handle == IntPtr.Zero) { _NativeSurface.CreateHandle(_Config, new int[] { Egl.NONE }); } return(context); }
/// <summary> /// Creates a context. /// </summary> /// <param name="sharedContext"> /// A <see cref="IntPtr"/> that specify a context that will share objects with the returned one. If /// it is IntPtr.Zero, no sharing is performed. /// </param> /// <returns> /// A <see cref="IntPtr"/> that represents the handle of the created context. If the context cannot be /// created, it returns IntPtr.Zero. /// </returns> /// <exception cref="InvalidOperationException"> /// Exception thrown in the case <paramref name="sharedContext"/> is different from IntPtr.Zero, and the objects /// cannot be shared with it. /// </exception> public override IntPtr CreateContext(IntPtr sharedContext) { return(Egl.CreateContext(_Display, _Config, sharedContext, null)); }