Inheritance: IWindowInfo
Ejemplo n.º 1
0
 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 eglContext = (EglContext) sharedContext;
       int major1;
       int minor1;
       if (!Egl.Initialize(window.Display, out major1, out minor1))
     throw new GraphicsContextException(string.Format("Failed to initialize EGL, error {0}.", (object) Egl.GetError()));
       this.WindowInfo = window;
       this.Mode = new EglGraphicsMode().SelectGraphicsMode(mode.ColorFormat, mode.Depth, mode.Stencil, mode.Samples, mode.AccumulatorFormat, mode.Buffers, mode.Stereo, major > 1 ? RenderableFlags.ES2 : RenderableFlags.ES);
       if (!this.Mode.Index.HasValue)
     throw new GraphicsModeException("Invalid or unsupported GraphicsMode.");
       IntPtr config = this.Mode.Index.Value;
       if (window.Surface == IntPtr.Zero)
     window.CreateWindowSurface(config);
       int[] attrib_list = new int[3]
       {
     12440,
     major,
     12344
       };
       this.HandleAsEGLContext = Egl.CreateContext(window.Display, config, eglContext != null ? eglContext.HandleAsEGLContext : IntPtr.Zero, attrib_list);
       this.MakeCurrent((IWindowInfo) window);
 }
Ejemplo n.º 2
0
        bool vsync = true;   // Default vsync value is defined as 1 (true) 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");

            EglContext shared = (EglContext)sharedContext;

            int dummy_major, dummy_minor;
            if (!Egl.Initialize(window.Display, out dummy_major, out dummy_minor))
                throw new GraphicsContextException(String.Format("Failed to initialize EGL, error {0}.", Egl.GetError()));

            WindowInfo = window;

            Mode = new EglGraphicsMode().SelectGraphicsMode(mode.ColorFormat, mode.Depth, mode.Stencil, mode.Samples, mode.AccumulatorFormat, mode.Buffers, mode.Stereo);
            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, shared != null ? shared.HandleAsEGLContext : IntPtr.Zero, attrib_list);

            MakeCurrent(window);
        }
Ejemplo n.º 3
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");

            EglContext shared = (EglContext)sharedContext;

            int dummy_major, dummy_minor;
            if (!Egl.Initialize(window.Display, out dummy_major, out dummy_minor))
                throw new GraphicsContextException(String.Format("Failed to initialize EGL, error {0}.", Egl.GetError()));

            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.
            Mode = new EglGraphicsMode().SelectGraphicsMode(mode.ColorFormat,
                mode.Depth, mode.Stencil, mode.Samples, mode.AccumulatorFormat,
                mode.Buffers, mode.Stereo,
                major > 1 ? RenderableFlags.ES2 : RenderableFlags.ES);
            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, shared != null ? shared.HandleAsEGLContext : IntPtr.Zero, attrib_list);

            MakeCurrent(window);
        }
Ejemplo n.º 4
0
 public override IGraphicsContext CreateGLContext(ContextHandle handle, IWindowInfo window, IGraphicsContext shareContext, bool directRendering, int major, int minor, GraphicsContextFlags flags)
 {
     WinWindowInfo winWindowInfo = (WinWindowInfo) window;
       IntPtr display = this.GetDisplay(winWindowInfo.DeviceContext);
       EglWindowInfo window1 = new EglWindowInfo(winWindowInfo.WindowHandle, display);
       return (IGraphicsContext) new EglContext(handle, window1, shareContext, major, minor, flags);
 }
Ejemplo n.º 5
0
 public GraphicsMode SelectGraphicsMode(EglWindowInfo window,
     GraphicsMode mode, RenderableFlags flags)
 {
     return SelectGraphicsMode(window,
         mode.ColorFormat, mode.Depth, mode.Stencil,
         mode.Samples, mode.AccumulatorFormat, mode.Buffers, mode.Stereo,
         flags);
 }
Ejemplo n.º 6
0
 public EglContext(ContextHandle handle, EglWindowInfo window, IGraphicsContext sharedContext, int major, int minor, GraphicsContextFlags flags)
 {
     if (handle == ContextHandle.Zero)
     throw new ArgumentException("handle");
       if (window == null)
     throw new ArgumentNullException("window");
       this.Handle = handle;
 }
Ejemplo n.º 7
0
        public GraphicsMode SelectGraphicsMode(EglWindowInfo window,
            ColorFormat color, int depth, int stencil,
            int samples, ColorFormat accum, int buffers, bool stereo,
            RenderableFlags renderable_flags)
        {
            IntPtr[] configs = new IntPtr[1];
            int[] attribList = new int[] 
            { 
                Egl.SURFACE_TYPE, Egl.WINDOW_BIT,
                Egl.RENDERABLE_TYPE, (int)renderable_flags,

                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,
            };

            IntPtr display = window.Display;

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

            // See what we really got
            IntPtr active_config = configs[0];
            int r, g, b, a;
            Egl.GetConfigAttrib(display, active_config, Egl.RED_SIZE, out r);
            Egl.GetConfigAttrib(display, active_config, Egl.GREEN_SIZE, out g);
            Egl.GetConfigAttrib(display, active_config, Egl.BLUE_SIZE, out b);
            Egl.GetConfigAttrib(display, active_config, Egl.ALPHA_SIZE, out a);
            int d, s;
            Egl.GetConfigAttrib(display, active_config, Egl.DEPTH_SIZE, out d);
            Egl.GetConfigAttrib(display, active_config, Egl.STENCIL_SIZE, out s);
            int sample_buffers;
            Egl.GetConfigAttrib(display, active_config, Egl.SAMPLES, out sample_buffers);
            Egl.GetConfigAttrib(display, active_config, Egl.SAMPLES, out samples);

            return new GraphicsMode(active_config, new ColorFormat(r, g, b, a), d, s, sample_buffers > 0 ? samples : 0, 0, 2, false);
        }
Ejemplo n.º 8
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");

            EglContext shared = (EglContext)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)
            {
                Renderable = major > 1 ? RenderableFlags.ES2 : RenderableFlags.ES;
            }

            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, shared != null ? shared.HandleAsEGLContext : IntPtr.Zero, attrib_list);

            MakeCurrent(window);
        }
Ejemplo n.º 9
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 is EglWindowInfo)
         WindowInfo = (EglWindowInfo)window;
     Egl.MakeCurrent(WindowInfo.Display, WindowInfo.Surface, WindowInfo.Surface, HandleAsEGLContext);
 }
Ejemplo n.º 10
0
 public override IGraphicsContext CreateGLContext(ContextHandle handle, IWindowInfo window, IGraphicsContext shareContext, bool directRendering, int major, int minor, GraphicsContextFlags flags)
 {
     X11WindowInfo x11WindowInfo = (X11WindowInfo) window;
       EglWindowInfo window1 = new EglWindowInfo(x11WindowInfo.WindowHandle, Egl.GetDisplay(x11WindowInfo.Display));
       return (IGraphicsContext) new EglContext(handle, window1, shareContext, major, minor, flags);
 }
Ejemplo n.º 11
0
 public override void MakeCurrent(IWindowInfo window)
 {
     if (window is EglWindowInfo)
     this.WindowInfo = (EglWindowInfo) window;
       Egl.MakeCurrent(this.WindowInfo.Display, this.WindowInfo.Surface, this.WindowInfo.Surface, this.HandleAsEGLContext);
 }
Ejemplo n.º 12
0
 public EglUnixContext(GraphicsMode mode, EglWindowInfo window, IGraphicsContext sharedContext,
                       int major, int minor, GraphicsContextFlags flags)
     : base(mode, window, sharedContext, major, minor, flags)
 {
 }
Ejemplo n.º 13
0
 public EglWinContext(ContextHandle handle, EglWindowInfo window, IGraphicsContext sharedContext,
                      int major, int minor, GraphicsContextFlags flags)
     : base(handle, window, sharedContext, major, minor, flags)
 {
 }
Ejemplo n.º 14
0
 public EglWinContext(GraphicsMode mode, EglWindowInfo window, IGraphicsContext sharedContext,
                      int major, int minor, GraphicsContextFlags flags)
     : base(mode, window, sharedContext, 3, 0, flags | GraphicsContextFlags.Embedded | GraphicsContextFlags.AngleD3D11 | GraphicsContextFlags.Angle)
 {
 }
Ejemplo n.º 15
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;
        }
Ejemplo n.º 16
0
 public EglUnixContext(GraphicsMode mode, EglWindowInfo window, IGraphicsContext sharedContext,
     int major, int minor, GraphicsContextFlags flags)
     : base(mode, window, sharedContext, major, minor, flags)
 {
 }
Ejemplo n.º 17
0
 public EglUnixContext(ContextHandle handle, EglWindowInfo window, IGraphicsContext sharedContext,
     int major, int minor, GraphicsContextFlags flags)
     : base(handle, window, sharedContext, major, minor, flags)
 {
 }
Ejemplo n.º 18
0
 public void DestroySurface(ref EGLSurface surface)
 {
     EglWindowInfo.DestroySurface(ref surface);
 }