예제 #1
0
        public GlxDisplay(X11Info x11, IList <GlVersion> probeProfiles)
        {
            _x11               = x11;
            _probeProfiles     = probeProfiles.ToArray();
            _displayExtensions = Glx.GetExtensions(_x11.Display);

            var baseAttribs = new[]
            {
                GLX_X_RENDERABLE, 1,
                GLX_RENDER_TYPE, GLX_RGBA_BIT,
                GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT | GLX_PBUFFER_BIT,
                GLX_DOUBLEBUFFER, 1,
                GLX_RED_SIZE, 8,
                GLX_GREEN_SIZE, 8,
                GLX_BLUE_SIZE, 8,
                GLX_ALPHA_SIZE, 8,
                GLX_DEPTH_SIZE, 1,
                GLX_STENCIL_SIZE, 8,
            };
            int sampleCount = 0;
            int stencilSize = 0;

            foreach (var attribs in new[]
            {
                //baseAttribs.Concat(multiattribs),
                baseAttribs,
            })
            {
                var ptr = Glx.ChooseFBConfig(_x11.Display, x11.DefaultScreen,
                                             attribs, out var count);
                for (var c = 0; c < count; c++)
                {
                    var visual = Glx.GetVisualFromFBConfig(_x11.Display, ptr[c]);
                    // We prefer 32 bit visuals
                    if (_fbconfig == IntPtr.Zero || visual->depth == 32)
                    {
                        _fbconfig = ptr[c];
                        _visual   = visual;
                        if (visual->depth == 32)
                        {
                            break;
                        }
                    }
                }

                if (_fbconfig != IntPtr.Zero)
                {
                    break;
                }
            }

            if (_fbconfig == IntPtr.Zero)
            {
                throw new OpenGlException("Unable to choose FBConfig");
            }

            if (_visual == null)
            {
                throw new OpenGlException("Unable to get visual info from FBConfig");
            }
            if (Glx.GetFBConfigAttrib(_x11.Display, _fbconfig, GLX_SAMPLES, out var samples) == 0)
            {
                sampleCount = samples;
            }
            if (Glx.GetFBConfigAttrib(_x11.Display, _fbconfig, GLX_STENCIL_SIZE, out var stencil) == 0)
            {
                stencilSize = stencil;
            }

            var attributes = new[] { GLX_PBUFFER_WIDTH, 1, GLX_PBUFFER_HEIGHT, 1, 0 };

            Glx.CreatePbuffer(_x11.Display, _fbconfig, attributes);
            Glx.CreatePbuffer(_x11.Display, _fbconfig, attributes);

            XLib.XFlush(_x11.Display);

            DeferredContext = CreateContext(CreatePBuffer(), null,
                                            sampleCount, stencilSize, true);
            using (DeferredContext.MakeCurrent())
            {
                var glInterface = DeferredContext.GlInterface;
                if (glInterface.Version == null)
                {
                    throw new OpenGlException("GL version string is null, aborting");
                }
                if (glInterface.Renderer == null)
                {
                    throw new OpenGlException("GL renderer string is null, aborting");
                }

                if (Environment.GetEnvironmentVariable("AVALONIA_GLX_IGNORE_RENDERER_BLACKLIST") != "1")
                {
                    var opts      = AvaloniaLocator.Current.GetService <X11PlatformOptions>() ?? new X11PlatformOptions();
                    var blacklist = opts.GlxRendererBlacklist;
                    if (blacklist != null)
                    {
                        foreach (var item in blacklist)
                        {
                            if (glInterface.Renderer.Contains(item))
                            {
                                throw new OpenGlException(
                                          $"Renderer '{glInterface.Renderer}' is blacklisted by '{item}'");
                            }
                        }
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GlxDisplay" /> class.
        /// </summary>
        /// <param name="x11">The X11.</param>
        /// <exception cref="OpenGlException">Unable to choose FBConfig
        /// or
        /// Unable to get visual info from FBConfig
        /// or
        /// GL version string is null, aborting
        /// or
        /// GL renderer string is null, aborting
        /// or
        /// Renderer '{GlInterface.Renderer}' is blacklisted by '{item}'</exception>
        public GlxDisplay(X11Info x11)
        {
            _x11 = x11;

            var baseAttribs = new[]
            {
                GLX_X_RENDERABLE, 1,
                GLX_RENDER_TYPE, GLX_RGBA_BIT,
                GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT | GLX_PBUFFER_BIT,
                GLX_DOUBLEBUFFER, 1,
                GLX_RED_SIZE, 8,
                GLX_GREEN_SIZE, 8,
                GLX_BLUE_SIZE, 8,
                GLX_ALPHA_SIZE, 8,
                GLX_DEPTH_SIZE, 1,
                GLX_STENCIL_SIZE, 8,
            };

            foreach (var attribs in new[]
            {
                //baseAttribs.Concat(multiattribs),
                baseAttribs,
            })
            {
                var ptr = Glx.ChooseFBConfig(_x11.Display, x11.DefaultScreen,
                                             attribs, out var count);
                for (var c = 0; c < count; c++)
                {
                    var visual = Glx.GetVisualFromFBConfig(_x11.Display, ptr[c]);
                    // We prefer 32 bit visuals
                    if (_fbconfig == IntPtr.Zero || visual->depth == 32)
                    {
                        _fbconfig  = ptr[c];
                        VisualInfo = visual;
                        if (visual->depth == 32)
                        {
                            break;
                        }
                    }
                }

                if (_fbconfig != IntPtr.Zero)
                {
                    break;
                }
            }

            if (_fbconfig == IntPtr.Zero)
            {
                throw new OpenGlException("Unable to choose FBConfig");
            }

            if (VisualInfo == null)
            {
                throw new OpenGlException("Unable to get visual info from FBConfig");
            }
            if (Glx.GetFBConfigAttrib(_x11.Display, _fbconfig, GLX_SAMPLES, out var samples) == 0)
            {
                SampleCount = samples;
            }
            if (Glx.GetFBConfigAttrib(_x11.Display, _fbconfig, GLX_STENCIL_SIZE, out var stencil) == 0)
            {
                StencilSize = stencil;
            }

            var pbuffers = Enumerable.Range(0, 2).Select(_ => Glx.CreatePbuffer(_x11.Display, _fbconfig, new[]
            {
                GLX_PBUFFER_WIDTH, 1, GLX_PBUFFER_HEIGHT, 1, 0
            })).ToList();

            XLib.XFlush(_x11.Display);

            ImmediateContext = CreateContext(pbuffers[0], null);
            DeferredContext  = CreateContext(pbuffers[1], ImmediateContext);
            ImmediateContext.MakeCurrent();
            var err = Glx.GetError();

            GlInterface = new GlInterface(GlxInterface.SafeGetProcAddress);
            if (GlInterface.Version == null)
            {
                throw new OpenGlException("GL version string is null, aborting");
            }
            if (GlInterface.Renderer == null)
            {
                throw new OpenGlException("GL renderer string is null, aborting");
            }

            if (Environment.GetEnvironmentVariable("AVALONIA_GLX_IGNORE_RENDERER_BLACKLIST") != "1")
            {
                var blacklist = AvaloniaLocator.Current.GetService <X11PlatformOptions>()
                                ?.GlxRendererBlacklist;
                if (blacklist != null)
                {
                    foreach (var item in blacklist)
                    {
                        if (GlInterface.Renderer.Contains(item))
                        {
                            throw new OpenGlException($"Renderer '{GlInterface.Renderer}' is blacklisted by '{item}'");
                        }
                    }
                }
            }
        }
예제 #3
0
        public GlxDisplay(X11Info x11)
        {
            _x11 = x11;

            var baseAttribs = new[]
            {
                GLX_X_RENDERABLE, 1,
                GLX_RENDER_TYPE, GLX_RGBA_BIT,
                GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT | GLX_PBUFFER_BIT,
                GLX_DOUBLEBUFFER, 1,
                GLX_RED_SIZE, 8,
                GLX_GREEN_SIZE, 8,
                GLX_BLUE_SIZE, 8,
                GLX_ALPHA_SIZE, 8,
                GLX_DEPTH_SIZE, 1,
                GLX_STENCIL_SIZE, 8,
            };

            foreach (var attribs in new[]
            {
                //baseAttribs.Concat(multiattribs),
                baseAttribs,
            })
            {
                var ptr = Glx.ChooseFBConfig(_x11.Display, x11.DefaultScreen,
                                             attribs, out var count);
                for (var c = 0; c < count; c++)
                {
                    var visual = Glx.GetVisualFromFBConfig(_x11.Display, ptr[c]);
                    // We prefer 32 bit visuals
                    if (_fbconfig == IntPtr.Zero || visual->depth == 32)
                    {
                        _fbconfig = ptr[c];
                        _visual   = visual;
                        if (visual->depth == 32)
                        {
                            break;
                        }
                    }
                }

                if (_fbconfig != IntPtr.Zero)
                {
                    break;
                }
            }

            if (_fbconfig == IntPtr.Zero)
            {
                throw new OpenGlException("Unable to choose FBConfig");
            }

            if (_visual == null)
            {
                throw new OpenGlException("Unable to get visual info from FBConfig");
            }
            if (Glx.GetFBConfigAttrib(_x11.Display, _fbconfig, GLX_SAMPLES, out var samples) == 0)
            {
                SampleCount = samples;
            }
            if (Glx.GetFBConfigAttrib(_x11.Display, _fbconfig, GLX_STENCIL_SIZE, out var stencil) == 0)
            {
                StencilSize = stencil;
            }

            var pbuffers = Enumerable.Range(0, 2).Select(_ => Glx.CreatePbuffer(_x11.Display, _fbconfig, new[]
            {
                GLX_PBUFFER_WIDTH, 1, GLX_PBUFFER_HEIGHT, 1, 0
            })).ToList();

            XLib.XFlush(_x11.Display);

            ImmediateContext = CreateContext(pbuffers[0], null);
            DeferredContext  = CreateContext(pbuffers[1], ImmediateContext);
            ImmediateContext.MakeCurrent();
            var err = Glx.GetError();

            GlInterface = new GlInterface(GlxInterface.GlxGetProcAddress);
            if (GlInterface.Version == null)
            {
                throw new OpenGlException("GL version string is null, aborting");
            }
        }