/// <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) { List <int> contextAttribs = new List <int>(); if (Version >= Egl.Version_130) { contextAttribs.AddRange(new int[] { Egl.CONTEXT_CLIENT_VERSION, 2 }); } contextAttribs.Add(Egl.NONE); if ((_Context = Egl.CreateContext(_Display, _Config, IntPtr.Zero, contextAttribs.ToArray())) == IntPtr.Zero) { throw new InvalidOperationException("unable to create context"); } int[] surfaceAttribs = new int[1] { // Egl.RENDER_BUFFER, Egl.BACK_BUFFER, Egl.NONE }; if ((_EglSurface = Egl.CreateWindowSurface(_Display, _Config, _NativeWindow, surfaceAttribs)) == IntPtr.Zero) { throw new InvalidOperationException("unable to create window surface"); } return(_Context); }
/// <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); }
/// <summary> /// Create the native surface handle. /// </summary> /// <param name="configId"> /// A <see cref="IntPtr"/> that specifies the configuration ID. /// </param> /// <param name="attribs"> /// A <see cref="T:int[]"/> that lists the handle attributes. /// </param> /// <exception cref="InvalidOperationException"> /// Exception thrown if the handle is already created. /// </exception> public override void CreateHandle(IntPtr configId, int[] attribs) { if (_Handle != IntPtr.Zero) { throw new InvalidOperationException("handle already created"); } if (_WindowHandle == IntPtr.Zero && Egl.CurrentExtensions.SurfacelessContext_KHR == false) { throw new InvalidOperationException("null window handle"); } if (_WindowHandle != IntPtr.Zero) { if ((_Handle = Egl.CreateWindowSurface(_Display, configId, _WindowHandle, attribs)) == IntPtr.Zero) { throw new InvalidOperationException("unable to create window surface"); } } }