MCPcopy Create free account
hub / github.com/SFML/SFML / selectBestVisual

Method selectBestVisual

src/SFML/Window/Unix/GlxContext.cpp:294–387  ·  view source on GitHub ↗

///////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

292
293////////////////////////////////////////////////////////////
294XVisualInfo GlxContext::selectBestVisual(::Display* display, unsigned int bitsPerPixel, const ContextSettings& settings)
295{
296 // Make sure that extensions are initialized
297 ensureExtensionsInit(display, DefaultScreen(display));
298
299 const int screen = DefaultScreen(display);
300
301 // Retrieve all the visuals
302 int count = 0;
303 // NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,modernize-avoid-c-arrays)
304 if (const auto visuals = X11Ptr<XVisualInfo[]>(XGetVisualInfo(display, 0, nullptr, &count)))
305 {
306 // Evaluate all the returned visuals, and pick the best one
307 int bestScore = 0x7FFFFFFF;
308 XVisualInfo bestVisual = XVisualInfo();
309 for (std::size_t i = 0; i < static_cast<std::size_t>(count); ++i)
310 {
311 // Filter by screen
312 if (visuals[i].screen != screen)
313 continue;
314
315 // Check mandatory attributes
316 int doubleBuffer = 0;
317 glXGetConfig(display, &visuals[i], GLX_DOUBLEBUFFER, &doubleBuffer);
318 if (!doubleBuffer)
319 continue;
320
321 // Extract the components of the current visual
322 int red = 0;
323 int green = 0;
324 int blue = 0;
325 int alpha = 0;
326 int depth = 0;
327 int stencil = 0;
328 int multiSampling = 0;
329 int samples = 0;
330 int sRgb = 0;
331 glXGetConfig(display, &visuals[i], GLX_RED_SIZE, &red);
332 glXGetConfig(display, &visuals[i], GLX_GREEN_SIZE, &green);
333 glXGetConfig(display, &visuals[i], GLX_BLUE_SIZE, &blue);
334 glXGetConfig(display, &visuals[i], GLX_ALPHA_SIZE, &alpha);
335 glXGetConfig(display, &visuals[i], GLX_DEPTH_SIZE, &depth);
336 glXGetConfig(display, &visuals[i], GLX_STENCIL_SIZE, &stencil);
337
338 if (SF_GLAD_GLX_ARB_multisample)
339 {
340 glXGetConfig(display, &visuals[i], GLX_SAMPLE_BUFFERS_ARB, &multiSampling);
341 glXGetConfig(display, &visuals[i], GLX_SAMPLES_ARB, &samples);
342 }
343 else
344 {
345 multiSampling = 0;
346 samples = 0;
347 }
348
349 if (SF_GLAD_GLX_EXT_framebuffer_sRGB || SF_GLAD_GLX_ARB_framebuffer_sRGB)
350 {
351 glXGetConfig(display, &visuals[i], GLX_FRAMEBUFFER_SRGB_CAPABLE_ARB, &sRgb);

Callers

nothing calls this directly

Calls 1

ensureExtensionsInitFunction · 0.70

Tested by

no test coverage detected