OpenTK.Platform.Egl.Egl.CreateContext C# (CSharp) Метод

CreateContext() публичный статический Метод

public static CreateContext ( OpenTK.Platform.Egl.EGLDisplay dpy, OpenTK.Platform.Egl.EGLConfig config, OpenTK.Platform.Egl.EGLContext share_context, int attrib_list ) : OpenTK.Platform.Egl.EGLContext
dpy OpenTK.Platform.Egl.EGLDisplay
config OpenTK.Platform.Egl.EGLConfig
share_context OpenTK.Platform.Egl.EGLContext
attrib_list int
Результат OpenTK.Platform.Egl.EGLContext
        public static EGLContext CreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_context, int[] attrib_list)
        {
            IntPtr ptr = eglCreateContext(dpy, config, share_context, attrib_list);
            if (ptr == IntPtr.Zero)
                throw new GraphicsContextException(String.Format("Failed to create EGL context, error: {0}.", Egl.GetError()));
            return ptr;
        }

Usage Example

Пример #1
0
        int swap_interval = 1; // Default interval is defined as 1 in EGL.

        #endregion

        #region Constructors

        public EglContext(GraphicsMode mode, EglWindowInfo window, IGraphicsContext sharedContext,
                          int major, int minor, GraphicsContextFlags flags)
        {
            if (mode == null)
            {
                throw new ArgumentNullException("mode");
            }
            if (window == null)
            {
                throw new ArgumentNullException("window");
            }

            WindowInfo = window;

            // Select an EGLConfig that matches the desired mode. We cannot use the 'mode'
            // parameter directly, since it may have originated on a different system (e.g. GLX)
            // and it may not support the desired renderer.

            Renderable = RenderableFlags.GL;
            if ((flags & GraphicsContextFlags.Embedded) != 0)
            {
                switch (major)
                {
                case 3:
                    Renderable = RenderableFlags.ES3;
                    break;

                case 2:
                    Renderable = RenderableFlags.ES2;
                    break;

                default:
                    Renderable = RenderableFlags.ES;
                    break;
                }
            }

            RenderApi api = (Renderable & RenderableFlags.GL) != 0 ? RenderApi.GL : RenderApi.ES;

            Debug.Print("[EGL] Binding {0} rendering API.", api);
            if (!Egl.BindAPI(api))
            {
                Debug.Print("[EGL] Failed to bind rendering API. Error: {0}", Egl.GetError());
            }

            Mode = new EglGraphicsMode().SelectGraphicsMode(window,
                                                            mode.ColorFormat, mode.Depth, mode.Stencil, mode.Samples,
                                                            mode.AccumulatorFormat, mode.Buffers, mode.Stereo,
                                                            Renderable);
            if (!Mode.Index.HasValue)
            {
                throw new GraphicsModeException("Invalid or unsupported GraphicsMode.");
            }
            IntPtr config = Mode.Index.Value;

            if (window.Surface == IntPtr.Zero)
            {
                window.CreateWindowSurface(config);
            }

            int[] attrib_list = new int[] { Egl.CONTEXT_CLIENT_VERSION, major, Egl.NONE };
            HandleAsEGLContext = Egl.CreateContext(window.Display, config, sharedContext != null ? (sharedContext as IGraphicsContextInternal).Context.Handle : IntPtr.Zero, attrib_list);
        }