/// <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> /// <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) { if (attribsList == null) { throw new ArgumentNullException("attribsList"); } if (attribsList.Length == 0) { throw new ArgumentException("zero length array", "attribsList"); } if (attribsList[attribsList.Length - 1] != 0) { throw new ArgumentException("not zero-terminated array", "attribsList"); } using (Glx.XLock displayLock = new Glx.XLock(Display)) { return(Glx.CreateContextAttribsARB(Display, FBConfig, sharedContext, true, attribsList)); } }
/// <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 (api != null && api.Api != KhronosVersion.ApiGl) { List <int> adulteredAttribs = new List <int>(attribsList); // Support check switch (api.Api) { case KhronosVersion.ApiGles1: case KhronosVersion.ApiGles2: if (Glx.CurrentExtensions.CreateContextEsProfile_EXT == false) { throw new NotSupportedException("OpenGL ES API not supported"); } break; default: throw new NotSupportedException(String.Format("'{0}' API not supported", api.Api)); } // Remove trailing 0 if (adulteredAttribs.Count > 0 && adulteredAttribs[adulteredAttribs.Count - 1] == Gl.NONE) { adulteredAttribs.RemoveAt(adulteredAttribs.Count - 1); } // Add required attributes int majorVersionIndex = adulteredAttribs.FindIndex(delegate(int item) { return(item == Gl.MAJOR_VERSION); }); int minorVersionIndex = adulteredAttribs.FindIndex(delegate(int item) { return(item == Gl.MINOR_VERSION); }); int profileMaskIndex = adulteredAttribs.FindIndex(delegate(int item) { return(item == Gl.CONTEXT_PROFILE_MASK); }); if (majorVersionIndex < 0) { adulteredAttribs.AddRange(new int[] { Gl.MAJOR_VERSION, api.Major }); majorVersionIndex = adulteredAttribs.Count - 2; } if (minorVersionIndex < 0) { adulteredAttribs.AddRange(new int[] { Gl.MINOR_VERSION, api.Minor }); minorVersionIndex = adulteredAttribs.Count - 2; } if (profileMaskIndex < 0) { adulteredAttribs.AddRange(new int[] { Gl.CONTEXT_PROFILE_MASK, 0 }); profileMaskIndex = adulteredAttribs.Count - 2; } switch (api.Api) { case KhronosVersion.ApiGles1: // Ignore API version: force always to 1.0 adulteredAttribs[majorVersionIndex + 1] = 1; adulteredAttribs[minorVersionIndex + 1] = 1; adulteredAttribs[profileMaskIndex + 1] |= (int)Glx.CONTEXT_ES_PROFILE_BIT_EXT; break; case KhronosVersion.ApiGles2: // Uses API version: it may be greater than 2.0(?) adulteredAttribs[majorVersionIndex + 1] = api.Major; adulteredAttribs[minorVersionIndex + 1] = api.Minor; adulteredAttribs[profileMaskIndex + 1] |= (int)Glx.CONTEXT_ES_PROFILE_BIT_EXT; break; default: throw new NotSupportedException(String.Format("'{0}' API not supported", api.Api)); } // Restore trailing 0 adulteredAttribs.Add(Gl.NONE); using (Glx.XLock displayLock = new Glx.XLock(Display)) { Debug.Assert(_FBConfig != IntPtr.Zero, "SetPixelFormat not executed"); return(Glx.CreateContextAttribsARB(Display, _FBConfig, sharedContext, true, adulteredAttribs.ToArray())); } } else { using (Glx.XLock displayLock = new Glx.XLock(Display)) { Debug.Assert(_FBConfig != IntPtr.Zero, "SetPixelFormat not executed"); return(Glx.CreateContextAttribsARB(Display, _FBConfig, sharedContext, true, attribsList)); } } }