Exemple #1
0
        public override void MakeCurrent(IWindowInfo window)
        {
            // Ignore 'window', unless it actually is an EGL window. In other words,
            // trying to make the EglContext current on a non-EGL window will do,
            // nothing (the EglContext will remain current on the previous EGL window
            // or the window it was constructed on (which may not be EGL)).
            if (window != null)
            {
                if (window is EglWindowInfo)
                {
                    WindowInfo = (EglWindowInfo)window;
                }
#if !ANDROID
                else if (window is IAngleWindowInfoInternal)
                {
                    WindowInfo = ((IAngleWindowInfoInternal)window).EglWindowInfo;
                }
#endif

                if (!Egl.MakeCurrent(WindowInfo.Display, WindowInfo.Surface, WindowInfo.Surface, HandleAsEGLContext))
                {
                    throw new GraphicsContextException(string.Format("Failed to make context {0} current. Error: {1}", Handle, Egl.GetError()));
                }
            }
            else
            {
                Egl.MakeCurrent(WindowInfo.Display, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
            }
        }
Exemple #2
0
        private int swap_interval = 1; // Default interval is defined as 1 in EGL.

        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");
            }

            EglContext shared = GetSharedEglContext(sharedContext);

            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());
            }

            bool offscreen = (flags & GraphicsContextFlags.Offscreen) != 0;

            SurfaceType surfaceType = offscreen
                ? SurfaceType.PBUFFER_BIT
                : SurfaceType.WINDOW_BIT;

            Mode = new EglGraphicsMode().SelectGraphicsMode(surfaceType,
                                                            window.Display, 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)
            {
                if (!offscreen)
                {
                    window.CreateWindowSurface(config);
                }
                else
                {
                    window.CreatePbufferSurface(config);
                }
            }

            int[] attribList   = { Egl.CONTEXT_CLIENT_VERSION, major, Egl.NONE };
            var   shareContext = shared?.HandleAsEGLContext ?? IntPtr.Zero;

            HandleAsEGLContext = Egl.CreateContext(window.Display, config, shareContext, attribList);

            GraphicsContextFlags = flags;
        }
Exemple #3
0
 public void MakeCurrent(EGLSurface surface)
 {
     Egl.MakeCurrent(Display, surface, surface, EglContext.HandleAsEGLContext);
 }
Exemple #4
0
 public override void SwapBuffers()
 {
     if (!Egl.SwapBuffers(WindowInfo.Display, WindowInfo.Surface))
     {
         throw new GraphicsContextException(string.Format("Failed to swap buffers for context {0} current. Error: {1}", Handle, Egl.GetError()));
     }
 }
Exemple #5
0
        public override IGraphicsContext CreateGLContext(ContextHandle handle, IWindowInfo window, IGraphicsContext shareContext, bool directRendering, int major, int minor, GraphicsContextFlags flags)
        {
            X11WindowInfo x11_win = (X11WindowInfo)window;
            EglWindowInfo egl_win = new osuTK.Platform.Egl.EglWindowInfo(x11_win.Handle, Egl.GetDisplay(x11_win.Display));

            return(new EglUnixContext(handle, egl_win, shareContext, major, minor, flags));
        }
Exemple #6
0
        public GraphicsMode SelectGraphicsMode(SurfaceType surfaceType,
                                               IntPtr display, ColorFormat color, int depth, int stencil,
                                               int samples, ColorFormat accum, int buffers, bool stereo,
                                               RenderableFlags renderableFlags)
        {
            IntPtr[] configs    = new IntPtr[1];
            int[]    attribList = new int[]
            {
                Egl.SURFACE_TYPE, (int)surfaceType,
                Egl.RENDERABLE_TYPE, (int)renderableFlags,

                Egl.RED_SIZE, color.Red,
                Egl.GREEN_SIZE, color.Green,
                Egl.BLUE_SIZE, color.Blue,
                Egl.ALPHA_SIZE, color.Alpha,

                Egl.DEPTH_SIZE, depth > 0 ? depth : 0,
                Egl.STENCIL_SIZE, stencil > 0 ? stencil : 0,

                Egl.SAMPLE_BUFFERS, samples > 0 ? 1 : 0,
                Egl.SAMPLES, samples > 0 ? samples : 0,

                Egl.NONE,
            };

            int numConfigs;

            if (!Egl.ChooseConfig(display, attribList, configs, configs.Length, out numConfigs) || numConfigs == 0)
            {
                throw new GraphicsModeException(String.Format("Failed to retrieve GraphicsMode, error {0}", Egl.GetError()));
            }

            // See what we really got
            IntPtr activeConfig = configs[0];
            int    r, g, b, a;

            Egl.GetConfigAttrib(display, activeConfig, Egl.RED_SIZE, out r);
            Egl.GetConfigAttrib(display, activeConfig, Egl.GREEN_SIZE, out g);
            Egl.GetConfigAttrib(display, activeConfig, Egl.BLUE_SIZE, out b);
            Egl.GetConfigAttrib(display, activeConfig, Egl.ALPHA_SIZE, out a);
            int d, s;

            Egl.GetConfigAttrib(display, activeConfig, Egl.DEPTH_SIZE, out d);
            Egl.GetConfigAttrib(display, activeConfig, Egl.STENCIL_SIZE, out s);
            int sampleBuffers;

            Egl.GetConfigAttrib(display, activeConfig, Egl.SAMPLES, out sampleBuffers);
            Egl.GetConfigAttrib(display, activeConfig, Egl.SAMPLES, out samples);

            return(new GraphicsMode(activeConfig, new ColorFormat(r, g, b, a), d, s, sampleBuffers > 0 ? samples : 0, 0, 2, false));
        }
Exemple #7
0
        //public void CreatePixmapSurface(EGLConfig config)
        //{
        //    Surface = Egl.CreatePixmapSurface(Display, config, Handle, null);
        //}

        public void CreatePbufferSurface(IntPtr config)
        {
            int[] attribs = new int[] { Egl.NONE };
            Surface = Egl.CreatePbufferSurface(Display, config, attribs);
            if (Surface == IntPtr.Zero)
            {
                throw new GraphicsContextException(String.Format(
                                                       "[EGL] Failed to create pbuffer surface, error {0}.", Egl.GetError()));
            }
        }
Exemple #8
0
 public void CreateWindowSurface(IntPtr config)
 {
     Surface = Egl.CreateWindowSurface(Display, config, Handle, IntPtr.Zero);
     if (Surface == IntPtr.Zero)
     {
         throw new GraphicsContextException(String.Format(
                                                "[EGL] Failed to create window surface, error {0}.", Egl.GetError()));
     }
 }
Exemple #9
0
        public EglWindowInfo(IntPtr handle, IntPtr display, IntPtr surface)
        {
            Handle  = handle;
            Surface = surface;

            if (display == IntPtr.Zero)
            {
                display = Egl.GetDisplay(IntPtr.Zero);
            }

            Display = display;

            int dummyMajor, dummyMinor;

            if (!Egl.Initialize(Display, out dummyMajor, out dummyMinor))
            {
                throw new GraphicsContextException(String.Format("Failed to initialize EGL, error {0}.", Egl.GetError()));
            }
        }
Exemple #10
0
 public void CreatePbufferSurface(IntPtr config, int width, int height, out IntPtr bufferSurface)
 {
     int[] attribs = new int[]
     {
         Egl.WIDTH, width,
         Egl.HEIGHT, height,
         Egl.TEXTURE_TARGET, Egl.TEXTURE_2D,
         Egl.TEXTURE_FORMAT, Egl.TEXTURE_RGBA,
         Egl.NONE
     };
     bufferSurface = Egl.CreatePbufferSurface(Display, config, attribs);
     if (bufferSurface == IntPtr.Zero)
     {
         throw new GraphicsContextException(String.Format(
                                                "[EGL] Failed to create pbuffer surface, error {0}.", Egl.GetError()));
     }
 }
Exemple #11
0
        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);
        }