/// <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) { if (XVisualInfo == null) { throw new InvalidOperationException("no visual information"); } using (Glx.XLock displayLock = new Glx.XLock(Display)) { return(Glx.CreateContext(Display, XVisualInfo, sharedContext, true)); } }
/// <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) { if (Glx.CurrentExtensions == null || Glx.CurrentExtensions.CreateContext_ARB == false) { using (Glx.XLock displayLock = new Glx.XLock(Display)) { // Get the corresponding X visual info Glx.XVisualInfo xVisualInfo = _XVisualInfo != null ? _XVisualInfo : GetVisualInfoFromXWindow(_WindowHandle); Debug.Assert(xVisualInfo != null, "SetPixelFormat not executed or undetected XVisualInfo"); return(Glx.CreateContext(Display, xVisualInfo, sharedContext, true)); } } else { return(CreateContextAttrib(sharedContext, new int[] { Gl.NONE })); } }
/// <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 CreateX11SimpleContext(IDeviceContext rDevice) { XServerDeviceContext x11DeviceCtx = (XServerDeviceContext)rDevice; IntPtr rContext; using (Glx.XLock xLock = new Glx.XLock(x11DeviceCtx.Display)) { int[] attributes = new int[] { Glx.RENDER_TYPE, (int)Glx.RGBA_BIT, 0 }; // Get basic visual unsafe { int[] choosenConfigCount = new int[1]; IntPtr *choosenConfigs = Glx.ChooseFBConfig(x11DeviceCtx.Display, x11DeviceCtx.Screen, attributes, choosenConfigCount); if (choosenConfigCount[0] == 0) { throw new InvalidOperationException("unable to find basic visual"); } IntPtr choosenConfig = *choosenConfigs; x11DeviceCtx.XVisualInfo = Glx.GetVisualFromFBConfig(x11DeviceCtx.Display, choosenConfig); x11DeviceCtx.FBConfig = choosenConfig; Glx.UnsafeNativeMethods.XFree((IntPtr)choosenConfigs); } // Create direct context rContext = x11DeviceCtx.CreateContext(IntPtr.Zero); if (rContext == IntPtr.Zero) { // Fallback to not direct context rContext = Glx.CreateContext(x11DeviceCtx.Display, x11DeviceCtx.XVisualInfo, IntPtr.Zero, false); } if (rContext == IntPtr.Zero) { throw new InvalidOperationException("unable to create context"); } return(rContext); } }