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

Method createSurface

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

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

Source from the content-addressed store, hash-verified

454
455////////////////////////////////////////////////////////////
456void GlxContext::createSurface(GlxContext* shared, Vector2u size, unsigned int bitsPerPixel)
457{
458 // Choose the visual according to the context settings
459 XVisualInfo visualInfo = selectBestVisual(m_display.get(), bitsPerPixel, m_settings);
460
461 // Check if the shared context already exists and pbuffers are supported
462 if (shared && SF_GLAD_GLX_SGIX_pbuffer)
463 {
464 // There are no GLX versions prior to 1.0
465 int major = 0;
466 int minor = 0;
467
468 glXQueryVersion(m_display.get(), &major, &minor);
469
470 // Check if glXCreatePbuffer is available (requires GLX 1.3 or greater)
471 const bool hasCreatePbuffer = ((major > 1) || (minor >= 3));
472
473 if (hasCreatePbuffer)
474 {
475 // Get a GLXFBConfig that matches the visual
476 GLXFBConfig* config = nullptr;
477
478 // We don't supply attributes to match against, since
479 // the visual we are matching against was already
480 // deemed suitable in selectBestVisual()
481 int nbConfigs = 0;
482 // NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,modernize-avoid-c-arrays)
483 const auto configs = X11Ptr<GLXFBConfig[]>(
484 glXChooseFBConfig(m_display.get(), DefaultScreen(m_display.get()), nullptr, &nbConfigs));
485
486 for (std::size_t i = 0; configs && (i < static_cast<std::size_t>(nbConfigs)); ++i)
487 {
488 const auto visual = X11Ptr<XVisualInfo>(glXGetVisualFromFBConfig(m_display.get(), configs[i]));
489
490 if (!visual)
491 continue;
492
493 if (visual->visualid == visualInfo.visualid)
494 {
495 config = &configs[i];
496 break;
497 }
498 }
499
500 if (config)
501 {
502 const std::array attributes =
503 {GLX_PBUFFER_WIDTH, static_cast<int>(size.x), GLX_PBUFFER_HEIGHT, static_cast<int>(size.y), 0, 0};
504
505 m_pbuffer = glXCreatePbuffer(m_display.get(), *config, attributes.data());
506
507 updateSettingsFromVisualInfo(&visualInfo);
508
509 return;
510 }
511 }
512 }
513

Callers

nothing calls this directly

Calls 1

getMethod · 0.80

Tested by

no test coverage detected