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.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}'"); } } } } }
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}'"); } } } } } }
public static extern IntPtr glXCreateContext(IntPtr dpy, XVisualInfo *vis, IntPtr shareList, bool direct);
internal static extern unsafe GLXCONTEXT glXCreateContext(PDISPLAY dpy, XVisualInfo *vis, GLXCONTEXT shareList, BOOL direct);
public partial IntPtr CreateContext(IntPtr dpy, XVisualInfo *vis, IntPtr shareList, bool direct);
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_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 = GlxChooseFBConfig(_x11.Display, x11.DefaultScreen, attribs, out var count); for (var c = 0; c < count; c++) { var visual = GlxGetVisualFromFBConfig(_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 (GlxGetFBConfigAttrib(_x11.Display, _fbconfig, GLX_SAMPLES, out var samples) == 0) { SampleCount = samples; } if (GlxGetFBConfigAttrib(_x11.Display, _fbconfig, GLX_STENCIL_SIZE, out var stencil) == 0) { StencilSize = stencil; } ImmediateContext = CreateContext(null); DeferredContext = CreateContext(ImmediateContext); ImmediateContext.MakeCurrent(); GlInterface = GlInterface.FromNativeUtf8GetProcAddress(p => GlxGetProcAddress(p)); }
public unsafe FBConfigs(IWindow pWindow, GameContextConfig pConfig) { m_pConfigs = new List <INativContextConfig>(); int[] visual_attribs = { (int)GLX.X_RENDERABLE, (int)GL.TRUE, (int)GLX.DRAWABLE_TYPE, (int)GLX.WINDOW_BIT, (int)GLX.DOUBLEBUFFER, (int)GL.TRUE, (int)GLX.RENDER_TYPE, (int)GLX.RGBA_BIT, (int)GLX.X_VISUAL_TYPE, (int)GLX.TRUE_COLOR, (int)GLX.BUFFER_SIZE, pConfig.Color, (int)GLX.DEPTH_SIZE, pConfig.Depth, (int)GLX.STENCIL_SIZE, pConfig.Stencil, (int)GLX.DOUBLEBUFFER, (int)GL.TRUE, (int)GLX.SAMPLE_BUFFERS, pConfig.EnableSample ? (int)GL.TRUE : (int)GL.FALSE, 0 }; int best_fbc = -1, worst_fbc = -1, best_num_samp = -1, worst_num_samp = 999; int fbcount; IntPtr *fbc = glxNativeContext.glXChooseFBConfig(pWindow.Display.RawHandle, pWindow.Display.Screen.ScreenNumber, visual_attribs, out fbcount); for (int i = 0; i < fbcount; i++) { IntPtr _config = fbc[i]; XVisualInfo *vi = glxNativeContext.glXGetVisualFromFBConfig(pWindow.Display.RawHandle, _config); if (vi != null) { int samp_buf = 0, samples = 0; glxNativeContext.glXGetFBConfigAttrib(pWindow.Display.RawHandle, fbc[i], (int)GLX.SAMPLE_BUFFERS, ref samp_buf); glxNativeContext.glXGetFBConfigAttrib(pWindow.Display.RawHandle, fbc[i], (int)GLX.SAMPLES, ref samples); if (vi->Depth == pConfig.Depth && ((pConfig.EnableSample && samp_buf >= 1) || (!pConfig.EnableSample && samp_buf == 0))) { //int iID, IntPtr pConfig, int iSampleBuf, int iSamples m_pConfigs.Add(new FBConfig(i, fbc[i], samp_buf, samples, *vi)); if (best_fbc < 0 || samp_buf == 1 && samples > best_num_samp) { best_fbc = i; best_num_samp = samples; } if (worst_fbc < 0 || samp_buf == 0 || samples < worst_num_samp) { worst_fbc = i; worst_num_samp = samples; } } } //X11._internal.Lib.XFree( vi ); } if (m_pConfigs.Count == 0) { throw new System.Exception("No Configs found"); } #if DEBUG m_pBest = this[best_fbc]; ((FBConfig)m_pBest).Typ = NativContextConfigTyp.Best; m_pWorst = this[worst_fbc]; ((FBConfig)m_pWorst).Typ = NativContextConfigTyp.Worst; ConsoleColor oldForground = Console.ForegroundColor; foreach (var item in m_pConfigs) { if (item.Typ == NativContextConfigTyp.Best) { Console.ForegroundColor = ConsoleColor.Green; } else if (item.Typ == NativContextConfigTyp.Worst) { Console.ForegroundColor = ConsoleColor.Blue; } else { Console.ForegroundColor = oldForground; } Console.WriteLine(item.ToString()); } Console.ForegroundColor = oldForground; #endif }
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"); } }
public static extern XVisualInfo *XGetVisualInfo(Display *param0, [NativeTypeName("long")] nint param1, XVisualInfo *param2, int *param3);
public static extern int XMatchVisualInfo(Display *param0, int param1, int param2, int param3, XVisualInfo *param4);